summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2019-01-22 11:37:35 +0100
committerKarel Zak2019-01-22 11:37:35 +0100
commit75d239ffd89b93f79059928e436f1068f402452e (patch)
treeb6e9935ec7b9e5be8dacc39cbebd40586cadfe94 /lib
parentlib/loopdev: differentiate between setter()s and ioctl calls (diff)
downloadkernel-qcow2-util-linux-75d239ffd89b93f79059928e436f1068f402452e.tar.gz
kernel-qcow2-util-linux-75d239ffd89b93f79059928e436f1068f402452e.tar.xz
kernel-qcow2-util-linux-75d239ffd89b93f79059928e436f1068f402452e.zip
lib/loopdev: set blocksize when create a new device
The partition scanner in kernel depends on blocksize. We need to set the blocksize before we call LOOP_SET_STATUS64 (this ioctl triggers the scanner). This patch extends the internal API to save blocksize into loopdev context to be usable later for loopcxt_setup_device(). Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/loopdev.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/loopdev.c b/lib/loopdev.c
index 556c4df26..a57650cb5 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -96,6 +96,7 @@ int loopcxt_set_device(struct loopdev_cxt *lc, const char *device)
}
lc->fd = -1;
lc->mode = 0;
+ lc->blocksize = 0;
lc->has_info = 0;
lc->info_failed = 0;
*lc->device = '\0';
@@ -1107,6 +1108,22 @@ int loopcxt_set_sizelimit(struct loopdev_cxt *lc, uint64_t sizelimit)
}
/*
+ * The blocksize will be used by loopcxt_set_device(). For already exiting
+ * devices use loopcxt_ioctl_blocksize().
+ *
+ * The setting is removed by loopcxt_set_device() loopcxt_next()!
+ */
+int loopcxt_set_blocksize(struct loopdev_cxt *lc, uint64_t blocksize)
+{
+ if (!lc)
+ return -EINVAL;
+ lc->blocksize = blocksize;
+
+ DBG(CXT, ul_debugobj(lc, "set blocksize=%jd", blocksize));
+ return 0;
+}
+
+/*
* @lc: context
* @flags: kernel LO_FLAGS_{READ_ONLY,USE_AOPS,AUTOCLEAR} flags
*
@@ -1331,6 +1348,12 @@ int loopcxt_setup_device(struct loopdev_cxt *lc)
DBG(SETUP, ul_debugobj(lc, "LOOP_SET_FD: OK"));
+ if (lc->blocksize > 0
+ && (rc = loopcxt_ioctl_blocksize(lc, lc->blocksize)) < 0) {
+ errsv = -rc;
+ goto err;
+ }
+
if (ioctl(dev_fd, LOOP_SET_STATUS64, &lc->info)) {
rc = -errno;
errsv = errno;