summaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorKarel Zak2019-01-22 11:50:20 +0100
committerKarel Zak2019-01-22 11:50:20 +0100
commit422f0e9f206a145c59a71333dad20d38cbbfc0c4 (patch)
tree3f63202271f075dc36b6a7582d633beb39f354f5 /sys-utils
parentlib/loopdev: set blocksize when create a new device (diff)
downloadkernel-qcow2-util-linux-422f0e9f206a145c59a71333dad20d38cbbfc0c4.tar.gz
kernel-qcow2-util-linux-422f0e9f206a145c59a71333dad20d38cbbfc0c4.tar.xz
kernel-qcow2-util-linux-422f0e9f206a145c59a71333dad20d38cbbfc0c4.zip
losetup: properly use --sector-size when create a new device
The --partscan functionality depends on sector size. Make sure sector size is set before we force kernel to scan the device for partitions. For example: losetup -f loopfile --sector-size 4KiB --partscan --show where 'loopfile' contains GPT with 4096 sectors. Reported-by: Jeffrey Ferreira <jeffpferreira@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/losetup.84
-rw-r--r--sys-utils/losetup.c36
2 files changed, 22 insertions, 18 deletions
diff --git a/sys-utils/losetup.8 b/sys-utils/losetup.8
index c31d7475f..1195c697e 100644
--- a/sys-utils/losetup.8
+++ b/sys-utils/losetup.8
@@ -124,7 +124,9 @@ Force the loop driver to reread the size of the file associated with the
specified loop device.
.TP
.BR \-P , " \-\-partscan"
-Force the kernel to scan the partition table on a newly created loop device.
+Force the kernel to scan the partition table on a newly created loop device. Note that the
+partition table parsing depends on sector sizes. The default is sector size is 512 bytes,
+otherwise you need to use use the option \fB\-\-sector\-size\fR together with \fB\-\-partscan\fR.
.TP
.BR \-r , " \-\-read\-only"
Set up a read-only loop device.
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 06feb8377..6fc5d51cd 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -472,7 +472,8 @@ static void warn_size(const char *filename, uint64_t size, uint64_t offset, int
static int create_loop(struct loopdev_cxt *lc,
int nooverlap, int lo_flags, int flags,
- const char *file, uint64_t offset, uint64_t sizelimit)
+ const char *file, uint64_t offset, uint64_t sizelimit,
+ uint64_t blocksize)
{
int hasdev = loopcxt_has_device(lc);
int rc = 0;
@@ -560,6 +561,9 @@ static int create_loop(struct loopdev_cxt *lc,
loopcxt_set_sizelimit(lc, sizelimit);
if (lo_flags)
loopcxt_set_flags(lc, lo_flags);
+ if (blocksize > 0)
+ loopcxt_set_blocksize(lc, blocksize);
+
if ((rc = loopcxt_set_backing_file(lc, file))) {
warn(_("%s: failed to use backing file"), file);
break;
@@ -834,13 +838,14 @@ 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));
warn_size(file, sizelimit, offset, flags);
- if (set_dio || set_blocksize)
- goto lo_set_post;
+ if (set_dio)
+ goto lo_set_dio;
}
break;
case A_DELETE:
@@ -893,20 +898,17 @@ int main(int argc, char **argv)
loopcxt_get_device(&lc));
break;
case A_SET_DIRECT_IO:
+lo_set_dio:
+ res = loopcxt_ioctl_dio(&lc, use_dio);
+ if (res)
+ warn(_("%s: set direct io failed"),
+ loopcxt_get_device(&lc));
+ break;
case A_SET_BLOCKSIZE:
- lo_set_post:
- if (set_dio) {
- res = loopcxt_ioctl_dio(&lc, use_dio);
- if (res)
- warn(_("%s: set direct io failed"),
- loopcxt_get_device(&lc));
- }
- if (set_blocksize) {
- res = loopcxt_ioctl_blocksize(&lc, blocksize);
- if (res)
- warn(_("%s: set logical block size failed"),
- loopcxt_get_device(&lc));
- }
+ res = loopcxt_ioctl_blocksize(&lc, blocksize);
+ if (res)
+ warn(_("%s: set logical block size failed"),
+ loopcxt_get_device(&lc));
break;
default:
warnx(_("bad usage"));