diff options
author | Stanislav Brabec | 2016-08-02 19:57:56 +0200 |
---|---|---|
committer | Karel Zak | 2016-08-17 12:49:06 +0200 |
commit | bfd4e1f75898510f93779766688cc5086404c23b (patch) | |
tree | 9a0e5a7adc270bb9dd2bb06fdda8bd2ffd36823b /lib/loopdev.c | |
parent | losetup: add --nooverlap options (diff) | |
download | kernel-qcow2-util-linux-bfd4e1f75898510f93779766688cc5086404c23b.tar.gz kernel-qcow2-util-linux-bfd4e1f75898510f93779766688cc5086404c23b.tar.xz kernel-qcow2-util-linux-bfd4e1f75898510f93779766688cc5086404c23b.zip |
loopdev: Implememt loopcxt_set_status()
Implement stand-alone loopcxt_set_status(). It allows manipulation with some
loop device parameters even if it is initialized.
Its function is limited by the kernel implementation, and only a small subset of
changes is allowed.
For more see linux/drivers/block/loop.c:loop_set_status()
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Diffstat (limited to 'lib/loopdev.c')
-rw-r--r-- | lib/loopdev.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/loopdev.c b/lib/loopdev.c index 8bbde0425..b3941dd14 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -1204,7 +1204,7 @@ static int loopcxt_check_size(struct loopdev_cxt *lc, int file_fd) } /* - * @cl: context + * @lc: context * * Associate the current device (see loopcxt_{set,get}_device()) with * a file (see loopcxt_set_backing_file()). @@ -1328,6 +1328,40 @@ err: return rc; } +/* + * @lc: context + * + * Update status of the current device (see loopcxt_{set,get}_device()). + * + * Note that once initialized, kernel accepts only selected changes: + * LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN + * For more see linux/drivers/block/loop.c:loop_set_status() + * + * Returns: <0 on error, 0 on success. + */ +int loopcxt_set_status(struct loopdev_cxt *lc) +{ + int dev_fd, rc = -1; + + errno = 0; + dev_fd = loopcxt_get_fd(lc); + + if (dev_fd < 0) { + rc = -errno; + return rc; + } + DBG(SETUP, ul_debugobj(lc, "device open: OK")); + + if (ioctl(dev_fd, LOOP_SET_STATUS64, &lc->info)) { + rc = -errno; + DBG(SETUP, ul_debugobj(lc, "LOOP_SET_STATUS64 failed: %m")); + return rc; + } + + DBG(SETUP, ul_debugobj(lc, "LOOP_SET_STATUS64: OK")); + return 0; +} + int loopcxt_set_capacity(struct loopdev_cxt *lc) { int fd = loopcxt_get_fd(lc); |