Skip to contentSkip to conversation

migration: Skip only empty block devices

PATCH Applied Cédric Le Goater 5 participants 9 messages Mar 12, 2024 – Mar 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migration: Skip only empty block devices

The block .save_setup() handler calls a helper routine init_blk_migration() which builds a list of block devices to take into account for migration. When one device is found to be empty (sectors == 0), the loop exits and all the remaining devices are ignored. This is a regression introduced when bdrv_iterate() was removed.

Change that by skipping only empty devices.

Cc: Markus Armbruster <[email protected]>
Suggested: Kevin Wolf <[email protected]>

Fixes fea68bb6e9fa ("block: Eliminate bdrv_iterate(), use bdrv_next()")
---
 migration/block.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
migration/block.c +4 -1
index 8c6ebafacc1ffe930d1d4f19d968817b14852c69..2b9054889ad2ba739828594c50cf047703757e96 100644
@@ -402,7 +402,10 @@ static int init_blk_migration(QEMUFile *f)
         }
 
         sectors = bdrv_nb_sectors(bs);
-        if (sectors <= 0) {
+        if (sectors == 0) {
+            continue;
+        }
+        if (sectors < 0) {
             ret = sectors;
             bdrv_next_cleanup(&it);
             goto out;
Signature · 1 line
2.44.0
#1 lore raw
Quoted 10 lines · Cédric Le Goater

The block .save_setup() handler calls a helper routine init_blk_migration() which builds a list of block devices to take into account for migration. When one device is found to be empty (sectors == 0), the loop exits and all the remaining devices are ignored. This is a regression introduced when bdrv_iterate() was removed.

Change that by skipping only empty devices.

Cc: Markus Armbruster <[email protected]>
Suggested: Kevin Wolf <[email protected]>

That's better :

Sorry for the noise,

C.

Quoted 22 lines
Fixes fea68bb6e9fa ("block: Eliminate bdrv_iterate(), use bdrv_next()")
---
  migration/block.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
migration/block.c +4 -1
index 8c6ebafacc1ffe930d1d4f19d968817b14852c69..2b9054889ad2ba739828594c50cf047703757e96 100644
@@ -402,7 +402,10 @@ static int init_blk_migration(QEMUFile *f)
          }
 
          sectors = bdrv_nb_sectors(bs);
-        if (sectors <= 0) {
+        if (sectors == 0) {
+            continue;
+        }
+        if (sectors < 0) {
              ret = sectors;
              bdrv_next_cleanup(&it);
              goto out;
#2 lore raw
In reply to Cédric Le Goater
Quoted 10 lines · Cédric Le Goater

The block .save_setup() handler calls a helper routine init_blk_migration() which builds a list of block devices to take into account for migration. When one device is found to be empty (sectors == 0), the loop exits and all the remaining devices are ignored. This is a regression introduced when bdrv_iterate() was removed.

Change that by skipping only empty devices.

Cc: Markus Armbruster <[email protected]>
Suggested: Kevin Wolf <[email protected]>

This should be:

I think the missed "by" caused Kevin not in the cc list, I added Kevin in.

I'll hold a bit for Kevin to ACK, no repost needed just for above; I can fix it.

Thanks,

Quoted 26 lines
Fixes fea68bb6e9fa ("block: Eliminate bdrv_iterate(), use bdrv_next()")
---
 migration/block.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
migration/block.c +4 -1
index 8c6ebafacc1ffe930d1d4f19d968817b14852c69..2b9054889ad2ba739828594c50cf047703757e96 100644
@@ -402,7 +402,10 @@ static int init_blk_migration(QEMUFile *f)
         }
 
         sectors = bdrv_nb_sectors(bs);
-        if (sectors <= 0) {
+        if (sectors == 0) {
+            continue;
+        }
+        if (sectors < 0) {
             ret = sectors;
             bdrv_next_cleanup(&it);
             goto out;
Signature · 1 line
2.44.0
Signature · 1 line
Peter Xu
Reviewed-by
#3 lore raw

Am 12.03.2024 um 13:27 hat Peter Xu geschrieben:

Quoted 12 lines · Cédric Le Goater
Quoted 10 lines

The block .save_setup() handler calls a helper routine init_blk_migration() which builds a list of block devices to take into account for migration. When one device is found to be empty (sectors == 0), the loop exits and all the remaining devices are ignored. This is a regression introduced when bdrv_iterate() was removed.

Change that by skipping only empty devices.

Cc: Markus Armbruster <[email protected]>
Suggested: Kevin Wolf <[email protected]>

Quoted 8 lines

This should be:

I think the missed "by" caused Kevin not in the cc list, I added Kevin in.

I'll hold a bit for Kevin to ACK, no repost needed just for above; I can fix it.

Thanks.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Cédric Le Goater
Quoted 11 lines · Cédric Le Goater

The block .save_setup() handler calls a helper routine init_blk_migration() which builds a list of block devices to take into account for migration. When one device is found to be empty (sectors == 0), the loop exits and all the remaining devices are ignored. This is a regression introduced when bdrv_iterate() was removed.

Change that by skipping only empty devices.

Cc: Markus Armbruster <[email protected]>
Suggested: Kevin Wolf <[email protected]>

Fixes fea68bb6e9fa ("block: Eliminate bdrv_iterate(), use bdrv_next()")

It's not clear to me that fea68bb6e9fa introduced the bug. The code is still <= 0 there and I don't see anything else that skips empty devices. Can you explain the bug in fea68bb6e9fa?

Otherwise:

#5 lore raw
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Cédric Le Goater

The block .save_setup() handler calls a helper routine init_blk_migration() which builds a list of block devices to take into account for migration. When one device is found to be empty (sectors == 0), the loop exits and all the remaining devices are ignored. This is a regression introduced when bdrv_iterate() was removed.

Change that by skipping only empty devices.

Quoted 7 lines
Quoted 3 lines

Cc: Markus Armbruster <[email protected]>
Suggested: Kevin Wolf <[email protected]>

Fixes fea68bb6e9fa ("block: Eliminate bdrv_iterate(), use bdrv_next()")

It's not clear to me that fea68bb6e9fa introduced the bug. The code is still <= 0 there and I don't see anything else that skips empty devices. Can you explain the bug in fea68bb6e9fa?

Let me try. Initially, the code was :

    static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
    {
        BlockDriverState *bs;
        BlkMigDevState *bmds;
        int64_t sectors;
     
        if (!bdrv_is_read_only(bs)) {
             sectors = bdrv_nb_sectors(bs);
             if (sectors <= 0) {
                 return;
        ...
    }
    	
    static void init_blk_migration(QEMUFile *f)
    {
        block_mig_state.submitted = 0;
        block_mig_state.read_done = 0;
        block_mig_state.transferred = 0;
        block_mig_state.total_sector_sum = 0;
        block_mig_state.prev_progress = -1;
        block_mig_state.bulk_completed = 0;
        block_mig_state.zero_blocks = migrate_zero_blocks();
    
        bdrv_iterate(init_blk_migration_it, NULL);
    }

bdrv_iterate() was iterating on all devices and exiting one iteration early if the device was empty or an error detected. The loop applied on all devices always, only empty devices and the ones with a failure were skipped.

It was replaced by :

    static void init_blk_migration(QEMUFile *f)
    {
         BlockDriverState *bs;
         BlkMigDevState *bmds;
         int64_t sectors;
     
         block_mig_state.submitted = 0;
         block_mig_state.read_done = 0;
         block_mig_state.transferred = 0;
         block_mig_state.total_sector_sum = 0;
         block_mig_state.prev_progress = -1;
         block_mig_state.bulk_completed = 0;
         block_mig_state.zero_blocks = migrate_zero_blocks();
         
         for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
             if (bdrv_is_read_only(bs)) {
                 continue;
             }
    
             sectors = bdrv_nb_sectors(bs);
             if (sectors <= 0) {
                 return;
		
           ...
      }

The loop and function exit at first failure or first empty device, skipping the remaining devices. This is a different behavior.

What we would want today is ignore empty devices, as it done for the read only ones, return at first failure and let the caller of init_blk_migration() report.

This is a short term fix for 9.0 because the block migration code is deprecated and should be removed in 9.1.

Thanks,

C.

#6 lore raw
Quoted 75 lines · Cédric Le Goater
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Cédric Le Goater

The block .save_setup() handler calls a helper routine init_blk_migration() which builds a list of block devices to take into account for migration. When one device is found to be empty (sectors == 0), the loop exits and all the remaining devices are ignored. This is a regression introduced when bdrv_iterate() was removed.

Change that by skipping only empty devices.

Quoted 7 lines
Quoted 3 lines

Cc: Markus Armbruster <[email protected]>
Suggested: Kevin Wolf <[email protected]>

Fixes fea68bb6e9fa ("block: Eliminate bdrv_iterate(), use bdrv_next()")

It's not clear to me that fea68bb6e9fa introduced the bug. The code is still <= 0 there and I don't see anything else that skips empty devices. Can you explain the bug in fea68bb6e9fa?

Let me try. Initially, the code was :

    static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
    {
        BlockDriverState *bs;
        BlkMigDevState *bmds;
        int64_t sectors;
        if (!bdrv_is_read_only(bs)) {
             sectors = bdrv_nb_sectors(bs);
             if (sectors <= 0) {
                 return;
        ...
    }
    	
    static void init_blk_migration(QEMUFile *f)
    {
        block_mig_state.submitted = 0;
        block_mig_state.read_done = 0;
        block_mig_state.transferred = 0;
        block_mig_state.total_sector_sum = 0;
        block_mig_state.prev_progress = -1;
        block_mig_state.bulk_completed = 0;
        block_mig_state.zero_blocks = migrate_zero_blocks();
        bdrv_iterate(init_blk_migration_it, NULL);
    }

bdrv_iterate() was iterating on all devices and exiting one iteration early if the device was empty or an error detected. The loop applied on all devices always, only empty devices and the ones with a failure were skipped.
It was replaced by :

    static void init_blk_migration(QEMUFile *f)
    {
         BlockDriverState *bs;
         BlkMigDevState *bmds;
         int64_t sectors;
         block_mig_state.submitted = 0;
         block_mig_state.read_done = 0;
         block_mig_state.transferred = 0;
         block_mig_state.total_sector_sum = 0;
         block_mig_state.prev_progress = -1;
         block_mig_state.bulk_completed = 0;
         block_mig_state.zero_blocks = migrate_zero_blocks();
         for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
             if (bdrv_is_read_only(bs)) {
                 continue;
             }
             sectors = bdrv_nb_sectors(bs);
             if (sectors <= 0) {
                 return;
		
           ...
      }

The loop and function exit at first failure or first empty device, skipping the remaining devices. This is a different behavior.

Quoted 6 lines

What we would want today is ignore empty devices, as it done for the read only ones, return at first failure and let the caller of init_blk_migration() report.

This is a short term fix for 9.0 because the block migration code is deprecated and should be removed in 9.1.

I understand now. I missed that returning from init_blk_migration_it() did not abort iteration. Thank you!

Stefan

Applied
#7 lore raw
Quoted 2 lines · Stefan Hajnoczi

I understand now. I missed that returning from init_blk_migration_it() did not abort iteration. Thank you!

I queued it, thanks both!

Signature · 1 line
Peter Xu
#8 lore raw
Quoted 5 lines · Peter Xu
Quoted 2 lines · Stefan Hajnoczi

I understand now. I missed that returning from init_blk_migration_it() did not abort iteration. Thank you!

I queued it, thanks both!

Thanks for cleaning up the mess I made!