From: Stanislav Brabec <sbrabec@suse.cz>
To: util-linux@vger.kernel.org
Subject: [PATCH 1/3] libmount: Re-organize is_mounted_same_loopfile()
Date: Tue, 12 Apr 2016 20:22:36 +0200 [thread overview]
Message-ID: <570D3CEC.4030606@suse.cz> (raw)
First parse options, then initialize context.
No change in function.
The change is needed for loop device reuse.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
---
libmount/src/context_loopdev.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/libmount/src/context_loopdev.c b/libmount/src/context_loopdev.c
index a1ff971..47d6294 100644
--- a/libmount/src/context_loopdev.c
+++ b/libmount/src/context_loopdev.c
@@ -137,7 +137,7 @@ is_mounted_same_loopfile(struct libmnt_context *cxt,
int mnt_context_setup_loopdev(struct libmnt_context *cxt)
{
const char *backing_file, *optstr, *loopdev = NULL;
- char *val = NULL;
+ char *val = NULL, *loopval = NULL;
size_t len;
struct loopdev_cxt lc;
int rc = 0, lo_flags = 0;
@@ -158,10 +158,6 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt)
lo_flags |= LO_FLAGS_READ_ONLY;
}
- rc = loopcxt_init(&lc, 0);
- if (rc)
- return rc;
-
optstr = mnt_fs_get_user_options(cxt->fs);
/*
@@ -169,13 +165,8 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt)
*/
if (rc == 0 && (cxt->user_mountflags & MNT_MS_LOOP) &&
mnt_optstr_get_option(optstr, "loop", &val, &len) == 0 && val) {
-
- val = strndup(val, len);
- rc = val ? loopcxt_set_device(&lc, val) : -ENOMEM;
- free(val);
-
- if (rc == 0)
- loopdev = loopcxt_get_device(&lc);
+ loopval = strndup(val, len);
+ rc = loopval ? 0 : -ENOMEM;
}
/*
@@ -217,6 +208,15 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt)
rc = -EBUSY;
if (rc)
+ goto done_no_deinit;
+
+ rc = loopcxt_init(&lc, 0);
+ if (rc == 0 && loopval) {
+ rc = loopcxt_set_device(&lc, loopval);
+ if (rc == 0)
+ loopdev = loopcxt_get_device(&lc);
+ }
+ if (rc)
goto done;
/* since 2.6.37 we don't have to store backing filename to mtab
@@ -301,6 +301,8 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt)
}
done:
loopcxt_deinit(&lc);
+done_no_deinit:
+ free(loopval);
return rc;
}
--
2.8.1
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.com
Lihovarská 1060/12 tel: +49 911 7405384547
190 00 Praha 9 fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
reply other threads:[~2016-04-12 18:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=570D3CEC.4030606@suse.cz \
--to=sbrabec@suse.cz \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.