qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, den@virtuozzo.com,
	andrey.drobyshev@virtuozzo.com, jsnow@redhat.com,
	vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com
Subject: Re: [PATCH v2] block: Use LVM tools for LV block device truncation
Date: Thu, 14 Mar 2024 17:28:13 +0000	[thread overview]
Message-ID: <ZfMzrdzbOQfTQZ5Y@redhat.com> (raw)
In-Reply-To: <46f8e6c4-3a93-43cd-8652-bf574ea26a1a@virtuozzo.com>

On Thu, Mar 14, 2024 at 06:25:00PM +0100, Alexander Ivanov wrote:
> 
> 
> On 3/14/24 13:44, Daniel P. Berrangé wrote:
> > On Wed, Mar 13, 2024 at 11:43:27AM +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(+)
> > > 
> > > diff --git a/block/file-posix.c b/block/file-posix.c
> > > index 35684f7e21..5f07d98aa5 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 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;
> > > +            g_autofree char *size_str = g_strdup_printf("%ldB", offset);
> > offset is 64-bit, but '%ld' is not guaranteed to be 64-bit. I expect
> > this will break on 32-bit platforms. Try PRId64 instead.
> > 
> > > +            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 && WEXITSTATUS(status) == 0) {
> > > +                return 0;
> > > +            }
> > We should probably check  'g_spawn_check_wait_status' rather than
> > WEXITSTATUS, as this then gives us further eror message details
> > that....
> Thank you.
> I think it would be better to use 'g_spawn_check_exit_status' because there
> is no
> 'g_spawn_check_wait_status' in glib before 2.70 and even in 2.78 it leads to
> 'g_spawn_check_wait_status is deprecated: Not available before 2.70' error.

Ah yes, well spotted.


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 :|



      reply	other threads:[~2024-03-14 17:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 10:43 [PATCH v2] block: Use LVM tools for LV block device truncation Alexander Ivanov
2024-03-14 12:44 ` Daniel P. Berrangé
2024-03-14 17:25   ` Alexander Ivanov
2024-03-14 17:28     ` Daniel P. Berrangé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZfMzrdzbOQfTQZ5Y@redhat.com \
    --to=berrange@redhat.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=den@virtuozzo.com \
    --cc=hreitz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).