All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: Use LVM tools for LV block device truncation
@ 2024-03-11 17:40 Alexander Ivanov
  2024-03-11 18:24 ` Daniel P. Berrangé
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Ivanov @ 2024-03-11 17:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-block, den, andrey.drobyshev, jsnow, vsementsov, kwolf,
	hreitz

If a block device is an LVM logical volume we can resize it using
standard LVM tools.

In raw_co_truncate() check if the block device is a LV using lvdisplay
and resize it executing lvresize.

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 block/file-posix.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index 35684f7e21..cf8a04e6f7 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2670,6 +2670,33 @@ static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
     if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
         int64_t cur_length = raw_getlength(bs);
 
+        /*
+         * Check if the device is an LVM logical volume and try to resize
+         * it using LVM tools.
+         */
+        if (S_ISBLK(st.st_mode) && offset > 0) {
+            char cmd[PATH_MAX + 32];
+
+            snprintf(cmd, sizeof(cmd), "lvdisplay %s > /dev/null",
+                     bs->filename);
+            ret = system(cmd);
+            if (ret != 0) {
+                error_setg(errp, "lvdisplay returned %d error for '%s'",
+                           ret, bs->filename);
+                return ret;
+            }
+
+            snprintf(cmd, sizeof(cmd), "lvresize -f -L %ldB %s > /dev/null",
+                     offset, bs->filename);
+            ret = system(cmd);
+            if (ret != 0) {
+                error_setg(errp, "lvresize returned %d error for '%s'",
+                           ret, bs->filename);
+            }
+
+            return ret;
+        }
+
         if (offset != cur_length && exact) {
             error_setg(errp, "Cannot resize device files");
             return -ENOTSUP;
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-12 17:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-11 17:40 [PATCH] block: Use LVM tools for LV block device truncation Alexander Ivanov
2024-03-11 18:24 ` Daniel P. Berrangé
2024-03-12 17:04   ` Alexander Ivanov
2024-03-12 17:13     ` Daniel P. Berrangé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.