From 75d239ffd89b93f79059928e436f1068f402452e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 22 Jan 2019 11:37:35 +0100 Subject: 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 --- lib/loopdev.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib') 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'; @@ -1106,6 +1107,22 @@ int loopcxt_set_sizelimit(struct loopdev_cxt *lc, uint64_t sizelimit) return 0; } +/* + * 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; -- cgit v1.2.3-55-g7522