From: Jeffrey Ferreira <jeffpferreira@gmail.com>
To: util-linux@vger.kernel.org
Subject: [PATCH] losetup: set blocksize before partition scan
Date: Thu, 10 Jan 2019 13:55:19 -0800 [thread overview]
Message-ID: <20190110215515.GA28589@jeffrey-Ubuntu-iMac> (raw)
When creating a loop device the user may use the --partscan option to
request that the kernel scan for partitions. To correctly scan for
partitions the kernel must first have the correct blocksize.
Also, update an error message to add --partscan to the list of options
only allowed during loop device setup.
Signed-off-by: Jeffrey Ferreira <jeffpferreira@gmail.com>
---
disk-utils/partx.c | 2 +-
include/loopdev.h | 2 +-
lib/loopdev.c | 13 ++++++++++++-
libmount/src/context_loopdev.c | 2 +-
sys-utils/losetup.c | 11 ++++++-----
5 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/disk-utils/partx.c b/disk-utils/partx.c
index e10efa96a..0cf7b3330 100644
--- a/disk-utils/partx.c
+++ b/disk-utils/partx.c
@@ -125,7 +125,7 @@ static void assoc_loopdev(const char *fname)
if (loopcxt_set_backing_file(&lc, fname))
err(EXIT_FAILURE, _("%s: failed to set backing file"), fname);
- rc = loopcxt_setup_device(&lc);
+ rc = loopcxt_setup_device(&lc, 0);
if (rc == -EBUSY)
err(EXIT_FAILURE, _("%s: failed to set up loop device"), fname);
diff --git a/include/loopdev.h b/include/loopdev.h
index 3f2cec5f5..b62df00b1 100644
--- a/include/loopdev.h
+++ b/include/loopdev.h
@@ -163,7 +163,7 @@ extern int loopcxt_init_iterator(struct loopdev_cxt *lc, int flags);
extern int loopcxt_deinit_iterator(struct loopdev_cxt *lc);
extern int loopcxt_next(struct loopdev_cxt *lc);
-extern int loopcxt_setup_device(struct loopdev_cxt *lc);
+extern int loopcxt_setup_device(struct loopdev_cxt *lc, uint64_t blocksize);
extern int loopcxt_set_status(struct loopdev_cxt *lc);
extern int loopcxt_delete_device(struct loopdev_cxt *lc);
extern int loopcxt_set_capacity(struct loopdev_cxt *lc);
diff --git a/lib/loopdev.c b/lib/loopdev.c
index de0d50ba2..ad56895f8 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -1256,7 +1256,7 @@ static int loopcxt_check_size(struct loopdev_cxt *lc, int file_fd)
*
* Returns: <0 on error, 0 on success.
*/
-int loopcxt_setup_device(struct loopdev_cxt *lc)
+int loopcxt_setup_device(struct loopdev_cxt *lc, uint64_t blocksize)
{
int file_fd, dev_fd, mode = O_RDWR, rc = -1, cnt = 0;
int errsv = 0;
@@ -1331,6 +1331,17 @@ int loopcxt_setup_device(struct loopdev_cxt *lc)
DBG(SETUP, ul_debugobj(lc, "LOOP_SET_FD: OK"));
+ if (blocksize > 0) {
+ if (ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, (unsigned long) blocksize) < 0) {
+ rc = -errno;
+ errsv = errno;
+ DBG(SETUP, ul_debugobj(lc, "LOOP_SET_BLOCK_SIZE failed: %m"));
+ goto err;
+ }
+
+ DBG(SETUP, ul_debugobj(lc, "LOOP_SET_BLOCK_SIZE: OK"));
+ }
+
if (ioctl(dev_fd, LOOP_SET_STATUS64, &lc->info)) {
rc = -errno;
errsv = errno;
diff --git a/libmount/src/context_loopdev.c b/libmount/src/context_loopdev.c
index c5fc80d77..b916d03b3 100644
--- a/libmount/src/context_loopdev.c
+++ b/libmount/src/context_loopdev.c
@@ -336,7 +336,7 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt)
}
/* setup the device */
- rc = loopcxt_setup_device(&lc);
+ rc = loopcxt_setup_device(&lc, 0);
if (!rc)
break; /* success */
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 7d14f566c..ae23b3507 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -468,8 +468,8 @@ static void warn_size(const char *filename, uint64_t size)
}
static int create_loop(struct loopdev_cxt *lc,
- int nooverlap, int lo_flags, int flags,
- const char *file, uint64_t offset, uint64_t sizelimit)
+ int nooverlap, int lo_flags, int flags, const char *file,
+ uint64_t offset, uint64_t sizelimit, uint64_t blocksize)
{
int hasdev = loopcxt_has_device(lc);
int rc = 0;
@@ -562,7 +562,7 @@ static int create_loop(struct loopdev_cxt *lc,
break;
}
errno = 0;
- rc = loopcxt_setup_device(lc);
+ rc = loopcxt_setup_device(lc, blocksize);
if (rc == 0)
break; /* success */
if (errno == EBUSY && !hasdev)
@@ -819,7 +819,7 @@ int main(int argc, char **argv)
(sizelimit || lo_flags || showdev))
errx(EXIT_FAILURE,
_("the options %s are allowed during loop device setup only"),
- "--{sizelimit,read-only,show}");
+ "--{sizelimit,partscan,read-only,show}");
if ((flags & LOOPDEV_FL_OFFSET) &&
act != A_CREATE && (act != A_SHOW || !file))
@@ -831,7 +831,8 @@ int main(int argc, char **argv)
switch (act) {
case A_CREATE:
- res = create_loop(&lc, no_overlap, lo_flags, flags, file, offset, sizelimit);
+ res = create_loop(&lc, no_overlap, lo_flags, flags, file,
+ offset, sizelimit, blocksize);
if (res == 0) {
if (showdev)
printf("%s\n", loopcxt_get_device(&lc));
--
2.17.1
next reply other threads:[~2019-01-10 21:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-10 21:55 Jeffrey Ferreira [this message]
2019-01-22 10:57 ` [PATCH] losetup: set blocksize before partition scan Karel Zak
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=20190110215515.GA28589@jeffrey-Ubuntu-iMac \
--to=jeffpferreira@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox