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>
This commit is contained in:
parent
9fcc893624
commit
75d239ffd8
2 changed files with 25 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue