qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@parallels.com>
To: John Snow <jsnow@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, den@openvz.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH 6/9] block-migration: tiny refactoring
Date: Wed, 14 Jan 2015 15:26:29 +0300	[thread overview]
Message-ID: <54B66075.5090109@parallels.com> (raw)
In-Reply-To: <54AEF543.5000303@redhat.com>

On 09.01.2015 00:23, John Snow wrote:
>
>
> On 12/11/2014 09:17 AM, Vladimir Sementsov-Ogievskiy wrote:
>> Add blk_create and blk_free to remove code duplicates. Otherwise,
>> duplicates will rise in the following patches because of BlkMigBlock
>> sturcture extendin.
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@parallels.com>
>> ---
>>   block-migration.c | 56 
>> +++++++++++++++++++++++++++++--------------------------
>>   1 file changed, 30 insertions(+), 26 deletions(-)
>>
>> diff --git a/block-migration.c b/block-migration.c
>> index 5b4aa0f..d0c825f 100644
>> --- a/block-migration.c
>> +++ b/block-migration.c
>> @@ -113,6 +113,30 @@ static void blk_mig_unlock(void)
>>       qemu_mutex_unlock(&block_mig_state.lock);
>>   }
>>
>> +/* Only allocating and initializing structure fields, not copying 
>> any data. */
>> +
>> +static BlkMigBlock *blk_create(BlkMigDevState *bmds, int64_t sector,
>> +                                int nr_sectors)
>> +{
>> +    BlkMigBlock *blk = g_new(BlkMigBlock, 1);
>> +    blk->buf = g_malloc(BLOCK_SIZE);
>> +    blk->bmds = bmds;
>> +    blk->sector = sector;
>> +    blk->nr_sectors = nr_sectors;
>> +
>> +    blk->iov.iov_base = blk->buf;
>> +    blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;
>> +    qemu_iovec_init_external(&blk->qiov, &blk->iov, 1);
>> +
>> +    return blk;
>> +}
>> +
>> +static void blk_free(BlkMigBlock *blk)
>> +{
>> +    g_free(blk->buf);
>> +    g_free(blk);
>> +}
>> +
>>   /* Must run outside of the iothread lock during the bulk phase,
>>    * or the VM will stall.
>>    */
>> @@ -285,15 +309,7 @@ static int mig_save_device_bulk(QEMUFile *f, 
>> BlkMigDevState *bmds)
>>           nr_sectors = total_sectors - cur_sector;
>>       }
>>
>> -    blk = g_new(BlkMigBlock, 1);
>> -    blk->buf = g_malloc(BLOCK_SIZE);
>> -    blk->bmds = bmds;
>> -    blk->sector = cur_sector;
>> -    blk->nr_sectors = nr_sectors;
>> -
>> -    blk->iov.iov_base = blk->buf;
>> -    blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;
>> -    qemu_iovec_init_external(&blk->qiov, &blk->iov, 1);
>> +    blk = blk_create(bmds, cur_sector, nr_sectors);
>>
>>       blk_mig_lock();
>>       block_mig_state.submitted++;
>> @@ -467,17 +483,9 @@ static int mig_save_device_dirty(QEMUFile *f, 
>> BlkMigDevState *bmds,
>>               } else {
>>                   nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
>>               }
>> -            blk = g_new(BlkMigBlock, 1);
>> -            blk->buf = g_malloc(BLOCK_SIZE);
>> -            blk->bmds = bmds;
>> -            blk->sector = sector;
>> -            blk->nr_sectors = nr_sectors;
>> +            blk = blk_create(bmds, sector, nr_sectors);
>>
>>               if (is_async) {
>> -                blk->iov.iov_base = blk->buf;
>> -                blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;
>> -                qemu_iovec_init_external(&blk->qiov, &blk->iov, 1);
>> -
>
> I suppose in the (!is_async) branch we don't reference iov/qiov again, 
> but the functional difference caught my eye. It used to only be called 
> under the "is_async" branch, but now is going to be executed 
> unconditionally.
>
> Is that fine?
It think it doesn't matter. I can add a parameter 'is_async' to 
blk_create(), but what is worse - excess parameter or excess 
initialization? And why not to initialize the whole structure in 
blk_create() unconditionally?

  reply	other threads:[~2015-01-14 12:26 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-11 14:17 [Qemu-devel] [PATCH 0/8] Dirty bitmaps migration Vladimir Sementsov-Ogievskiy
2014-12-11 14:17 ` [Qemu-devel] [PATCH 1/9] block: rename bdrv_reset_dirty_bitmap Vladimir Sementsov-Ogievskiy
2015-01-08 21:19   ` John Snow
2014-12-11 14:17 ` [Qemu-devel] [PATCH 2/9] block-migration: fix pending() return value Vladimir Sementsov-Ogievskiy
2015-01-08 21:20   ` John Snow
2015-01-09 19:01     ` Dr. David Alan Gilbert
2014-12-11 14:17 ` [Qemu-devel] [PATCH 3/9] block: fix spoiling all dirty bitmaps by mirror and migration Vladimir Sementsov-Ogievskiy
2015-01-08 21:20   ` John Snow
2014-12-11 14:17 ` [Qemu-devel] [PATCH 4/9] hbitmap: store / restore Vladimir Sementsov-Ogievskiy
2015-01-08 21:21   ` John Snow
2015-01-08 21:37     ` Paolo Bonzini
2015-01-13 12:59     ` Vladimir Sementsov-Ogievskiy
2015-01-13 17:08       ` John Snow
2015-01-14 10:29         ` Vladimir Sementsov-Ogievskiy
2014-12-11 14:17 ` [Qemu-devel] [PATCH 5/9] block: BdrvDirtyBitmap store/restore interface Vladimir Sementsov-Ogievskiy
2015-01-08 21:22   ` John Snow
2015-01-14 11:27   ` Vladimir Sementsov-Ogievskiy
2014-12-11 14:17 ` [Qemu-devel] [PATCH 6/9] block-migration: tiny refactoring Vladimir Sementsov-Ogievskiy
2015-01-08 21:23   ` John Snow
2015-01-14 12:26     ` Vladimir Sementsov-Ogievskiy [this message]
2015-01-14 16:53       ` John Snow
2014-12-11 14:17 ` [Qemu-devel] [PATCH 7/9] block-migration: remove not needed iothread lock Vladimir Sementsov-Ogievskiy
2015-01-08 21:24   ` John Snow
2015-01-16 12:54     ` Vladimir Sementsov-Ogievskiy
2015-01-08 22:28   ` Paolo Bonzini
2015-01-16 13:03     ` Vladimir Sementsov-Ogievskiy
2014-12-11 14:17 ` [Qemu-devel] [PATCH 8/9] migration: add dirty parameter Vladimir Sementsov-Ogievskiy
2014-12-11 15:18   ` Eric Blake
2014-12-15  8:33     ` Vladimir Sementsov-Ogievskiy
2015-01-08 21:51   ` John Snow
2015-01-08 22:29     ` Eric Blake
2015-01-08 22:31       ` John Snow
2015-01-08 22:37     ` Paolo Bonzini
2014-12-11 14:17 ` [Qemu-devel] [PATCH 9/9] block-migration: add named dirty bitmaps migration Vladimir Sementsov-Ogievskiy
2015-01-08 22:05   ` John Snow
2015-01-17 17:17     ` Vladimir Sementsov-Ogievskiy
2015-01-20 17:25       ` John Snow
2015-01-08 22:36   ` Paolo Bonzini
2015-01-08 22:45     ` Eric Blake
2015-01-08 22:49       ` Paolo Bonzini
2015-01-12 14:20     ` Vladimir Sementsov-Ogievskiy
2015-01-12 14:42       ` Paolo Bonzini
2015-01-12 16:48   ` Paolo Bonzini
2015-01-12 17:31     ` John Snow
2015-01-12 19:09       ` Paolo Bonzini
2015-01-13  9:16         ` Vladimir Sementsov-Ogievskiy
2015-01-13 16:35           ` John Snow

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=54B66075.5090109@parallels.com \
    --to=vsementsov@parallels.com \
    --cc=den@openvz.org \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).