* Re: [PATCH v3] block: Use LVM tools for LV block device truncation
2024-03-15 8:58 [PATCH v3] block: Use LVM tools for LV block device truncation Alexander Ivanov
@ 2024-03-15 9:18 ` Daniel P. Berrangé
2024-05-10 10:35 ` Alexander Ivanov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Daniel P. Berrangé @ 2024-03-15 9:18 UTC (permalink / raw)
To: Alexander Ivanov
Cc: qemu-devel, qemu-block, den, andrey.drobyshev, jsnow, vsementsov,
kwolf, hreitz
On Fri, Mar 15, 2024 at 09:58:38AM +0100, Alexander Ivanov wrote:
> If a block device is an LVM logical volume we can resize it using
> standard LVM tools.
>
> Add a helper to detect if a device is a DM device. In raw_co_truncate()
> check if the block device is DM and resize it executing lvresize.
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
> block/file-posix.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 61 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>
> diff --git a/block/file-posix.c b/block/file-posix.c
> index 35684f7e21..af17a43fe9 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -2642,6 +2642,38 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset,
> return raw_thread_pool_submit(handle_aiocb_truncate, &acb);
> }
>
> +static bool device_is_dm(struct stat *st)
> +{
> + unsigned int maj, maj2;
> + char line[32], devname[16];
> + bool ret = false;
> + FILE *f;
> +
> + if (!S_ISBLK(st->st_mode)) {
> + return false;
> + }
> +
> + f = fopen("/proc/devices", "r");
> + if (!f) {
> + return false;
> + }
> +
> + maj = major(st->st_rdev);
> +
> + while (fgets(line, sizeof(line), f)) {
> + if (sscanf(line, "%u %15s", &maj2, devname) != 2) {
> + continue;
> + }
> + if (strcmp(devname, "device-mapper") == 0) {
> + ret = (maj == maj2);
> + break;
> + }
> + }
> +
> + fclose(f);
> + return ret;
> +}
> +
> static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
> bool exact, PreallocMode prealloc,
> BdrvRequestFlags flags, Error **errp)
> @@ -2670,6 +2702,35 @@ 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);
>
> + /*
> + * Try to resize an LVM device using LVM tools.
> + */
> + if (device_is_dm(&st) && offset > 0) {
> + int spawn_flags = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL;
> + int status;
> + bool success;
> + char *err;
> + GError *gerr = NULL, *gerr_exit = NULL;
> + g_autofree char *size_str = g_strdup_printf("%" PRId64 "B", offset);
> + const char *cmd[] = {"lvresize", "-f", "-L",
> + size_str, bs->filename, NULL};
> +
> + success = g_spawn_sync(NULL, (gchar **)cmd, NULL, spawn_flags,
> + NULL, NULL, NULL, &err, &status, &gerr);
> +
> + if (success && g_spawn_check_exit_status(status, &gerr_exit)) {
> + return 0;
> + }
> +
> + if (success) {
> + error_setg(errp, "%s: %s", gerr_exit->message, err);
> + } else {
> + error_setg(errp, "lvresize execution error: %s", gerr->message);
> + }
> +
> + return -EINVAL;
> + }
> +
> if (offset != cur_length && exact) {
> error_setg(errp, "Cannot resize device files");
> return -ENOTSUP;
> --
> 2.40.1
>
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3] block: Use LVM tools for LV block device truncation
2024-03-15 8:58 [PATCH v3] block: Use LVM tools for LV block device truncation Alexander Ivanov
2024-03-15 9:18 ` Daniel P. Berrangé
@ 2024-05-10 10:35 ` Alexander Ivanov
2024-06-04 10:26 ` Alexander Ivanov
2024-06-28 10:17 ` Alexander Ivanov
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Ivanov @ 2024-05-10 10:35 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-block, den, andrey.drobyshev, jsnow, vsementsov, kwolf,
hreitz
ping
Is there any update of the patch status?
Thank you.
On 3/15/24 09:58, Alexander Ivanov wrote:
> If a block device is an LVM logical volume we can resize it using
> standard LVM tools.
>
> Add a helper to detect if a device is a DM device. In raw_co_truncate()
> check if the block device is DM and resize it executing lvresize.
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
> block/file-posix.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 61 insertions(+)
>
> diff --git a/block/file-posix.c b/block/file-posix.c
> index 35684f7e21..af17a43fe9 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -2642,6 +2642,38 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset,
> return raw_thread_pool_submit(handle_aiocb_truncate, &acb);
> }
>
> +static bool device_is_dm(struct stat *st)
> +{
> + unsigned int maj, maj2;
> + char line[32], devname[16];
> + bool ret = false;
> + FILE *f;
> +
> + if (!S_ISBLK(st->st_mode)) {
> + return false;
> + }
> +
> + f = fopen("/proc/devices", "r");
> + if (!f) {
> + return false;
> + }
> +
> + maj = major(st->st_rdev);
> +
> + while (fgets(line, sizeof(line), f)) {
> + if (sscanf(line, "%u %15s", &maj2, devname) != 2) {
> + continue;
> + }
> + if (strcmp(devname, "device-mapper") == 0) {
> + ret = (maj == maj2);
> + break;
> + }
> + }
> +
> + fclose(f);
> + return ret;
> +}
> +
> static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
> bool exact, PreallocMode prealloc,
> BdrvRequestFlags flags, Error **errp)
> @@ -2670,6 +2702,35 @@ 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);
>
> + /*
> + * Try to resize an LVM device using LVM tools.
> + */
> + if (device_is_dm(&st) && offset > 0) {
> + int spawn_flags = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL;
> + int status;
> + bool success;
> + char *err;
> + GError *gerr = NULL, *gerr_exit = NULL;
> + g_autofree char *size_str = g_strdup_printf("%" PRId64 "B", offset);
> + const char *cmd[] = {"lvresize", "-f", "-L",
> + size_str, bs->filename, NULL};
> +
> + success = g_spawn_sync(NULL, (gchar **)cmd, NULL, spawn_flags,
> + NULL, NULL, NULL, &err, &status, &gerr);
> +
> + if (success && g_spawn_check_exit_status(status, &gerr_exit)) {
> + return 0;
> + }
> +
> + if (success) {
> + error_setg(errp, "%s: %s", gerr_exit->message, err);
> + } else {
> + error_setg(errp, "lvresize execution error: %s", gerr->message);
> + }
> +
> + return -EINVAL;
> + }
> +
> if (offset != cur_length && exact) {
> error_setg(errp, "Cannot resize device files");
> return -ENOTSUP;
--
Best regards,
Alexander Ivanov
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3] block: Use LVM tools for LV block device truncation
2024-03-15 8:58 [PATCH v3] block: Use LVM tools for LV block device truncation Alexander Ivanov
2024-03-15 9:18 ` Daniel P. Berrangé
2024-05-10 10:35 ` Alexander Ivanov
@ 2024-06-04 10:26 ` Alexander Ivanov
2024-06-28 10:17 ` Alexander Ivanov
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Ivanov @ 2024-06-04 10:26 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-block, den, andrey.drobyshev, jsnow, vsementsov, kwolf,
hreitz
ping 2
On 3/15/24 09:58, Alexander Ivanov wrote:
> If a block device is an LVM logical volume we can resize it using
> standard LVM tools.
>
> Add a helper to detect if a device is a DM device. In raw_co_truncate()
> check if the block device is DM and resize it executing lvresize.
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
> block/file-posix.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 61 insertions(+)
>
> diff --git a/block/file-posix.c b/block/file-posix.c
> index 35684f7e21..af17a43fe9 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -2642,6 +2642,38 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset,
> return raw_thread_pool_submit(handle_aiocb_truncate, &acb);
> }
>
> +static bool device_is_dm(struct stat *st)
> +{
> + unsigned int maj, maj2;
> + char line[32], devname[16];
> + bool ret = false;
> + FILE *f;
> +
> + if (!S_ISBLK(st->st_mode)) {
> + return false;
> + }
> +
> + f = fopen("/proc/devices", "r");
> + if (!f) {
> + return false;
> + }
> +
> + maj = major(st->st_rdev);
> +
> + while (fgets(line, sizeof(line), f)) {
> + if (sscanf(line, "%u %15s", &maj2, devname) != 2) {
> + continue;
> + }
> + if (strcmp(devname, "device-mapper") == 0) {
> + ret = (maj == maj2);
> + break;
> + }
> + }
> +
> + fclose(f);
> + return ret;
> +}
> +
> static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
> bool exact, PreallocMode prealloc,
> BdrvRequestFlags flags, Error **errp)
> @@ -2670,6 +2702,35 @@ 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);
>
> + /*
> + * Try to resize an LVM device using LVM tools.
> + */
> + if (device_is_dm(&st) && offset > 0) {
> + int spawn_flags = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL;
> + int status;
> + bool success;
> + char *err;
> + GError *gerr = NULL, *gerr_exit = NULL;
> + g_autofree char *size_str = g_strdup_printf("%" PRId64 "B", offset);
> + const char *cmd[] = {"lvresize", "-f", "-L",
> + size_str, bs->filename, NULL};
> +
> + success = g_spawn_sync(NULL, (gchar **)cmd, NULL, spawn_flags,
> + NULL, NULL, NULL, &err, &status, &gerr);
> +
> + if (success && g_spawn_check_exit_status(status, &gerr_exit)) {
> + return 0;
> + }
> +
> + if (success) {
> + error_setg(errp, "%s: %s", gerr_exit->message, err);
> + } else {
> + error_setg(errp, "lvresize execution error: %s", gerr->message);
> + }
> +
> + return -EINVAL;
> + }
> +
> if (offset != cur_length && exact) {
> error_setg(errp, "Cannot resize device files");
> return -ENOTSUP;
--
Best regards,
Alexander Ivanov
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3] block: Use LVM tools for LV block device truncation
2024-03-15 8:58 [PATCH v3] block: Use LVM tools for LV block device truncation Alexander Ivanov
` (2 preceding siblings ...)
2024-06-04 10:26 ` Alexander Ivanov
@ 2024-06-28 10:17 ` Alexander Ivanov
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Ivanov @ 2024-06-28 10:17 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-block, den, andrey.drobyshev, jsnow, vsementsov, kwolf,
hreitz
One more ping...
On 3/15/24 09:58, Alexander Ivanov wrote:
> If a block device is an LVM logical volume we can resize it using
> standard LVM tools.
>
> Add a helper to detect if a device is a DM device. In raw_co_truncate()
> check if the block device is DM and resize it executing lvresize.
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
> block/file-posix.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 61 insertions(+)
>
> diff --git a/block/file-posix.c b/block/file-posix.c
> index 35684f7e21..af17a43fe9 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -2642,6 +2642,38 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset,
> return raw_thread_pool_submit(handle_aiocb_truncate, &acb);
> }
>
> +static bool device_is_dm(struct stat *st)
> +{
> + unsigned int maj, maj2;
> + char line[32], devname[16];
> + bool ret = false;
> + FILE *f;
> +
> + if (!S_ISBLK(st->st_mode)) {
> + return false;
> + }
> +
> + f = fopen("/proc/devices", "r");
> + if (!f) {
> + return false;
> + }
> +
> + maj = major(st->st_rdev);
> +
> + while (fgets(line, sizeof(line), f)) {
> + if (sscanf(line, "%u %15s", &maj2, devname) != 2) {
> + continue;
> + }
> + if (strcmp(devname, "device-mapper") == 0) {
> + ret = (maj == maj2);
> + break;
> + }
> + }
> +
> + fclose(f);
> + return ret;
> +}
> +
> static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
> bool exact, PreallocMode prealloc,
> BdrvRequestFlags flags, Error **errp)
> @@ -2670,6 +2702,35 @@ 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);
>
> + /*
> + * Try to resize an LVM device using LVM tools.
> + */
> + if (device_is_dm(&st) && offset > 0) {
> + int spawn_flags = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL;
> + int status;
> + bool success;
> + char *err;
> + GError *gerr = NULL, *gerr_exit = NULL;
> + g_autofree char *size_str = g_strdup_printf("%" PRId64 "B", offset);
> + const char *cmd[] = {"lvresize", "-f", "-L",
> + size_str, bs->filename, NULL};
> +
> + success = g_spawn_sync(NULL, (gchar **)cmd, NULL, spawn_flags,
> + NULL, NULL, NULL, &err, &status, &gerr);
> +
> + if (success && g_spawn_check_exit_status(status, &gerr_exit)) {
> + return 0;
> + }
> +
> + if (success) {
> + error_setg(errp, "%s: %s", gerr_exit->message, err);
> + } else {
> + error_setg(errp, "lvresize execution error: %s", gerr->message);
> + }
> +
> + return -EINVAL;
> + }
> +
> if (offset != cur_length && exact) {
> error_setg(errp, "Cannot resize device files");
> return -ENOTSUP;
--
Best regards,
Alexander Ivanov
^ permalink raw reply [flat|nested] 5+ messages in thread