block migration: Fix coding style and whitespaces
No functional changes. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
1302425d73
commit
a55eb92c22
@ -41,6 +41,16 @@
|
||||
do { } while (0)
|
||||
#endif
|
||||
|
||||
typedef struct BlkMigDevState {
|
||||
BlockDriverState *bs;
|
||||
int bulk_completed;
|
||||
int shared_base;
|
||||
struct BlkMigDevState *next;
|
||||
int64_t cur_sector;
|
||||
int64_t total_sectors;
|
||||
int64_t dirty;
|
||||
} BlkMigDevState;
|
||||
|
||||
typedef struct BlkMigBlock {
|
||||
uint8_t *buf;
|
||||
BlkMigDevState *bmds;
|
||||
@ -88,8 +98,6 @@ static void blk_mig_read_cb(void *opaque, int ret)
|
||||
block_mig_state->submitted--;
|
||||
block_mig_state->read_done++;
|
||||
assert(block_mig_state->submitted >= 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int mig_read_device_bulk(QEMUFile *f, BlkMigDevState *bms)
|
||||
@ -195,9 +203,7 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)
|
||||
|
||||
cur_sector &= ~((int64_t)block_mig_state->sectors_per_block -1);
|
||||
|
||||
/* we going to transfer
|
||||
BLOCK_SIZE
|
||||
any way even if it is not allocated */
|
||||
/* we going to transfer BLOCK_SIZE any way even if it is not allocated */
|
||||
nr_sectors = block_mig_state->sectors_per_block;
|
||||
|
||||
if (total_sectors - cur_sector < block_mig_state->sectors_per_block) {
|
||||
@ -210,15 +216,15 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)
|
||||
|
||||
bdrv_reset_dirty(bs, cur_sector, nr_sectors);
|
||||
|
||||
/* Device name */
|
||||
/* sector number and flags */
|
||||
qemu_put_be64(f, (cur_sector << SECTOR_BITS) | BLK_MIG_FLAG_DEVICE_BLOCK);
|
||||
|
||||
/* device name */
|
||||
len = strlen(bs->device_name);
|
||||
qemu_put_byte(f, len);
|
||||
qemu_put_buffer(f, (uint8_t *)bs->device_name, len);
|
||||
|
||||
qemu_put_buffer(f, tmp_buf,
|
||||
BLOCK_SIZE);
|
||||
qemu_put_buffer(f, tmp_buf, BLOCK_SIZE);
|
||||
|
||||
bmds->cur_sector = cur_sector + block_mig_state->sectors_per_block;
|
||||
|
||||
@ -231,17 +237,15 @@ static void send_blk(QEMUFile *f, BlkMigBlock * blk)
|
||||
{
|
||||
int len;
|
||||
|
||||
/* Device name */
|
||||
/* sector number and flags */
|
||||
qemu_put_be64(f, (blk->sector << SECTOR_BITS) | BLK_MIG_FLAG_DEVICE_BLOCK);
|
||||
|
||||
/* device name */
|
||||
len = strlen(blk->bmds->bs->device_name);
|
||||
qemu_put_byte(f, len);
|
||||
qemu_put_buffer(f, (uint8_t *)blk->bmds->bs->device_name, len);
|
||||
|
||||
qemu_put_buffer(f, blk->buf,
|
||||
BLOCK_SIZE);
|
||||
|
||||
return;
|
||||
qemu_put_buffer(f, blk->buf, BLOCK_SIZE);
|
||||
}
|
||||
|
||||
static void blk_mig_save_dev_info(QEMUFile *f, BlkMigDevState *bmds)
|
||||
@ -254,8 +258,6 @@ static void set_dirty_tracking(int enable)
|
||||
for (bmds = block_mig_state->bmds_first; bmds != NULL; bmds = bmds->next) {
|
||||
bdrv_set_dirty_tracking(bmds->bs, enable);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void init_blk_migration(QEMUFile *f)
|
||||
@ -280,18 +282,16 @@ static void init_blk_migration(QEMUFile *f)
|
||||
|
||||
/* insert at the end */
|
||||
pbmds = &block_mig_state->bmds_first;
|
||||
while (*pbmds != NULL)
|
||||
while (*pbmds != NULL) {
|
||||
pbmds = &(*pbmds)->next;
|
||||
}
|
||||
*pbmds = bmds;
|
||||
|
||||
blk_mig_save_dev_info(f, bmds);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
block_mig_state->sectors_per_block = bdrv_get_sectors_per_chunk();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int blk_mig_save_bulked_block(QEMUFile *f, int is_async)
|
||||
@ -319,7 +319,6 @@ static int blk_mig_save_bulked_block(QEMUFile *f, int is_async)
|
||||
block_mig_state->bulk_completed = 1;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#define MAX_NUM_BLOCKS 4
|
||||
@ -333,19 +332,18 @@ static void blk_mig_save_dirty_blocks(QEMUFile *f)
|
||||
|
||||
for (bmds = block_mig_state->bmds_first; bmds != NULL; bmds = bmds->next) {
|
||||
for (sector = 0; sector < bmds->cur_sector;) {
|
||||
|
||||
if (bdrv_get_dirty(bmds->bs, sector)) {
|
||||
|
||||
if (bdrv_read(bmds->bs, sector, buf,
|
||||
block_mig_state->sectors_per_block) < 0) {
|
||||
/* FIXME: add error handling */
|
||||
}
|
||||
|
||||
/* device name */
|
||||
/* sector number and flags */
|
||||
qemu_put_be64(f, (sector << SECTOR_BITS)
|
||||
| BLK_MIG_FLAG_DEVICE_BLOCK);
|
||||
|
||||
/* device name */
|
||||
len = strlen(bmds->bs->device_name);
|
||||
|
||||
qemu_put_byte(f, len);
|
||||
qemu_put_buffer(f, (uint8_t *)bmds->bs->device_name, len);
|
||||
|
||||
@ -355,30 +353,25 @@ static void blk_mig_save_dirty_blocks(QEMUFile *f)
|
||||
|
||||
bdrv_reset_dirty(bmds->bs, sector,
|
||||
block_mig_state->sectors_per_block);
|
||||
|
||||
sector += block_mig_state->sectors_per_block;
|
||||
} else {
|
||||
/* sector is clean */
|
||||
}
|
||||
sector += block_mig_state->sectors_per_block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void flush_blks(QEMUFile* f)
|
||||
{
|
||||
BlkMigBlock *blk, *tmp;
|
||||
BlkMigBlock *blk, *next;
|
||||
|
||||
dprintf("%s Enter submitted %d read_done %d transfered\n", __FUNCTION__,
|
||||
submitted, read_done, transfered);
|
||||
|
||||
for (blk = block_mig_state->first_blk;
|
||||
blk != NULL && !qemu_file_rate_limit(f); blk = tmp) {
|
||||
blk != NULL && !qemu_file_rate_limit(f);
|
||||
blk = next) {
|
||||
send_blk(f, blk);
|
||||
|
||||
tmp = blk->next;
|
||||
next = blk->next;
|
||||
qemu_free(blk->buf);
|
||||
qemu_free(blk);
|
||||
|
||||
@ -395,8 +388,6 @@ static void flush_blks(QEMUFile* f)
|
||||
dprintf("%s Exit submitted %d read_done %d transferred%d\n", __FUNCTION__,
|
||||
block_mig_state->submitted, block_mig_state->read_done,
|
||||
block_mig_state->transferred);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int is_stage2_completed(void)
|
||||
@ -418,14 +409,11 @@ static int is_stage2_completed(void)
|
||||
|
||||
static int block_save_live(QEMUFile *f, int stage, void *opaque)
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
dprintf("Enter save live stage %d submitted %d transferred %d\n", stage,
|
||||
submitted, transferred);
|
||||
|
||||
if (block_mig_state->blk_enable != 1) {
|
||||
/* no need to migrate storage */
|
||||
|
||||
qemu_put_be64(f, BLK_MIG_FLAG_EOS);
|
||||
return 1;
|
||||
}
|
||||
@ -435,32 +423,31 @@ static int block_save_live(QEMUFile *f, int stage, void *opaque)
|
||||
|
||||
/* start track dirty blocks */
|
||||
set_dirty_tracking(1);
|
||||
|
||||
}
|
||||
|
||||
flush_blks(f);
|
||||
|
||||
/* control the rate of transfer */
|
||||
while ((block_mig_state->submitted + block_mig_state->read_done) *
|
||||
(BLOCK_SIZE) <
|
||||
(qemu_file_get_rate_limit(f))) {
|
||||
|
||||
ret = blk_mig_save_bulked_block(f, 1);
|
||||
|
||||
if (ret == 0) /* no more bulk blocks for now*/
|
||||
while ((block_mig_state->submitted +
|
||||
block_mig_state->read_done) * BLOCK_SIZE <
|
||||
qemu_file_get_rate_limit(f)) {
|
||||
if (blk_mig_save_bulked_block(f, 1) == 0) {
|
||||
/* no more bulk blocks for now */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
flush_blks(f);
|
||||
|
||||
if (stage == 3) {
|
||||
|
||||
while(blk_mig_save_bulked_block(f, 0) != 0);
|
||||
while (blk_mig_save_bulked_block(f, 0) != 0) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
blk_mig_save_dirty_blocks(f);
|
||||
|
||||
/* stop track dirty blocks */
|
||||
set_dirty_tracking(0);;
|
||||
set_dirty_tracking(0);
|
||||
|
||||
printf("\nBlock migration completed\n");
|
||||
}
|
||||
@ -482,14 +469,12 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
|
||||
buf = qemu_malloc(BLOCK_SIZE);
|
||||
|
||||
do {
|
||||
|
||||
addr = qemu_get_be64(f);
|
||||
|
||||
flags = addr & ~SECTOR_MASK;
|
||||
addr &= SECTOR_MASK;
|
||||
|
||||
if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) {
|
||||
|
||||
/* get device name */
|
||||
len = qemu_get_byte(f);
|
||||
|
||||
@ -498,19 +483,17 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
|
||||
|
||||
bs = bdrv_find(device_name);
|
||||
|
||||
qemu_get_buffer(f, buf,
|
||||
BLOCK_SIZE);
|
||||
qemu_get_buffer(f, buf, BLOCK_SIZE);
|
||||
if (bs != NULL) {
|
||||
|
||||
bdrv_write(bs, (addr >> SECTOR_BITS),
|
||||
buf, block_mig_state->sectors_per_block);
|
||||
} else {
|
||||
printf("Error unknown block device %s\n", device_name);
|
||||
/* FIXME: add error handling */
|
||||
}
|
||||
} else if(flags & BLK_MIG_FLAG_EOS) {
|
||||
|
||||
} else {
|
||||
} else if (!(flags & BLK_MIG_FLAG_EOS)) {
|
||||
printf("Unknown flags\n");
|
||||
/* FIXME: add error handling */
|
||||
}
|
||||
} while (!(flags & BLK_MIG_FLAG_EOS));
|
||||
|
||||
@ -528,8 +511,6 @@ static void block_set_params(int blk_enable, int shared_base, void *opaque)
|
||||
|
||||
/* shared base means that blk_enable = 1 */
|
||||
block_mig_state->blk_enable |= shared_base;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void blk_mig_info(void)
|
||||
@ -547,11 +528,8 @@ void blk_mig_info(void)
|
||||
|
||||
void blk_mig_init(void)
|
||||
{
|
||||
|
||||
block_mig_state = qemu_mallocz(sizeof(BlkMigState));
|
||||
|
||||
register_savevm_live("block", 0, 1, block_set_params, block_save_live,
|
||||
NULL, block_load, block_mig_state);
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,16 +14,6 @@
|
||||
#ifndef BLOCK_MIGRATION_H
|
||||
#define BLOCK_MIGRATION_H
|
||||
|
||||
typedef struct BlkMigDevState {
|
||||
BlockDriverState *bs;
|
||||
int bulk_completed;
|
||||
int shared_base;
|
||||
struct BlkMigDevState *next;
|
||||
int64_t cur_sector;
|
||||
int64_t total_sectors;
|
||||
int64_t dirty;
|
||||
} BlkMigDevState;
|
||||
|
||||
void blk_mig_init(void);
|
||||
void blk_mig_info(void);
|
||||
#endif /* BLOCK_MIGRATION_H */
|
||||
|
3
block.c
3
block.c
@ -646,6 +646,7 @@ static void set_dirty_bitmap(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, int dirty)
|
||||
{
|
||||
int64_t start, end;
|
||||
|
||||
start = sector_num / SECTORS_PER_DIRTY_CHUNK;
|
||||
end = (sector_num + nb_sectors) / SECTORS_PER_DIRTY_CHUNK;
|
||||
|
||||
@ -1966,10 +1967,12 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size)
|
||||
void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable)
|
||||
{
|
||||
int64_t bitmap_size;
|
||||
|
||||
if (enable) {
|
||||
if (bs->dirty_tracking == 0) {
|
||||
int64_t i;
|
||||
uint8_t test;
|
||||
|
||||
bitmap_size = (bdrv_getlength(bs) >> SECTOR_BITS);
|
||||
bitmap_size /= SECTORS_PER_DIRTY_CHUNK;
|
||||
bitmap_size++;
|
||||
|
Loading…
Reference in New Issue
Block a user