block: Format/protocol split
Subsystems (2)
cover block: Format/protocol split
This is the next version of the format/protocol split RFC that Christoph posted on Monday. I did fix image creation in his original patch and added some additional patches for more cleanup and to fix the no_zero_init bug that is mentioned in the commit log of this first patch.
One point that still needs to be done is converting all the random format drivers that noone uses to use block.c functions instead of POSIX functions. In some points they look like protocol drivers rather than format drivers otherwise.
If there are no other important issues left, I'm going to merge this into the block branch soon.
Christoph Hellwig (1):
block: separate raw images from the file protocol
Kevin Wolf (4):
block: Split bdrv_open
block: Avoid forward declaration of bdrv_open_common
block: Open the underlying image file in generic code
block: bdrv_has_zero_init
Makefile.objs | 2 +- block.c | 266 ++++++++++++++++++++++++++++++++---------------- block.h | 2 + block/blkdebug.c | 17 +-- block/bochs.c | 2 +- block/cloop.c | 2 +- block/cow.c | 2 +- block/curl.c | 10 +- block/dmg.c | 2 +- block/nbd.c | 2 +- block/parallels.c | 2 +- block/qcow.c | 69 ++++++------- block/qcow2-cluster.c | 64 ++++++------ block/qcow2-refcount.c | 80 +++++++------- block/qcow2-snapshot.c | 22 ++-- block/qcow2.c | 67 +++++------- block/qcow2.h | 2 +- block/raw-posix.c | 25 +++-- block/raw-win32.c | 16 ++-- block/raw.c | 144 ++++++++++++++++++++++++++ block/vdi.c | 30 ++---- block/vmdk.c | 2 +- block/vpc.c | 34 +++---- block/vvfat.c | 2 +- block_int.h | 5 +- qemu-img.c | 6 +- 26 files changed, 544 insertions(+), 333 deletions(-) create mode 100644 block/raw.c
RFC PATCH 1/5 block: separate raw images from the file protocol
From: Christoph Hellwig <[email protected]>
We're running into various problems because the "raw" file access, which is used internally by the various image formats is entangled with the "raw" image format, which maps the VM view 1:1 to a file system.
This patch renames the raw file backends to the file protocol which is treated like other protocols (e.g. nbd and http) and adds a new "raw" image format which is just a wrapper around calls to the underlying protocol.
The patch is surprisingly simple, besides changing the probing logical in block.c to only look for image formats when using bdrv_open and renaming of the old raw protocols to file there's almost nothing in there.
For creating images, a new bdrv_create_file is introduced which guesses the protocol to use. This allows using qemu-img create -f raw (or just using the default) for both files and host devices. Converting the other format drivers to use this function to create their images is left for later patches.
The only issues still open are in the handling of the host devices. Firstly in current qemu we can specifiy the host* format names on various command line acceping images, but the new code can't do that without adding some translation. Second the layering breaks the no_zero_init flag in the BlockDriver used by qemu-img. I'm not happy how this is done per-driver instead of per-state so I'll prepare a separate patch to clean this up.
There's some more cleanup opportunity after this patch, e.g. using separate lists and registration functions for image formats vs protocols and maybe even host drivers, but this can be done at a later stage.
Also there's a check for protocol in bdrv_open for the BDRV_O_SNAPSHOT case that I don't quite understand, but which I fear won't work as expected - possibly even before this patch.
Note that this patch requires various recent block patches from Kevin and me, which should all be in his block queue.
--- Makefile.objs | 2 +- block.c | 74 ++++++++++++++--------- block.h | 1 + block/raw-posix.c | 15 +++-- block/raw-win32.c | 12 ++-- block/raw.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 235 insertions(+), 40 deletions(-) create mode 100644 block/raw.c
Makefile.objs +1 -1
@@ -12,7 +12,7 @@ block-obj-y += nbd.o block.o aio.o aes.o osdep.o qemu-config.o block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o -block-nested-y += cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o +block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o block-nested-y += parallels.o nbd.o blkdebug.o block-nested-$(CONFIG_WIN32) += raw-win32.o
block.c +45 -29
118 lines not on this page · raw message
block.h +1 -0
@@ -57,6 +57,7 @@ BlockDriver *bdrv_find_format(const char *format_name);BlockDriver *bdrv_find_whitelisted_format (const char *format_name);int bdrv_create (BlockDriver *drv,const char * filename,QEMUOptionParameter *options); +int bdrv_create_file (const char * filename,QEMUOptionParameter *options);BlockDriverState *bdrv_new (const char *device_name);void bdrv_delete (BlockDriverState *bs);int bdrv_file_open (BlockDriverState **pbs,const char *filename,int flags);
block/raw-posix.c +10 -5
@@ -768,8 +768,9 @@ static QEMUOptionParameter raw_create_options[] = { { NULL } }; -static BlockDriver bdrv_raw = { - .format_name ="raw" , +static BlockDriver bdrv_file = { + .format_name ="file" , + .protocol_name ="file" , .instance_size =sizeof (BDRVRawState), .bdrv_probe =NULL ,/* no probe for protocols */ .bdrv_open = raw_open,
@@ -1026,6 +1027,7 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options)static BlockDriver bdrv_host_device = { .format_name ="host_device" , + .protocol_name ="host_device" , .instance_size =sizeof (BDRVRawState), .bdrv_probe_device = hdev_probe_device, .bdrv_open = hdev_open,
@@ -1140,6 +1142,7 @@ static int floppy_eject(BlockDriverState *bs, int eject_flag)static BlockDriver bdrv_host_floppy = { .format_name ="host_floppy" , + .protocol_name ="host_floppy" , .instance_size =sizeof (BDRVRawState), .bdrv_probe_device = floppy_probe_device, .bdrv_open = floppy_open,
@@ -1239,6 +1242,7 @@ static int cdrom_set_locked(BlockDriverState *bs, int locked)static BlockDriver bdrv_host_cdrom = { .format_name ="host_cdrom" , + .protocol_name ="host_cdrom" , .instance_size =sizeof (BDRVRawState), .bdrv_probe_device = cdrom_probe_device, .bdrv_open = cdrom_open,
@@ -1361,6 +1365,7 @@ static int cdrom_set_locked(BlockDriverState *bs, int locked)static BlockDriver bdrv_host_cdrom = { .format_name ="host_cdrom" , + .protocol_name ="host_cdrom" , .instance_size =sizeof (BDRVRawState), .bdrv_probe_device = cdrom_probe_device, .bdrv_open = cdrom_open,
@@ -1385,13 +1390,13 @@ static BlockDriver bdrv_host_cdrom = { };#endif /* __FreeBSD__ */ -static void bdrv_raw_init (void ) +static void bdrv_file_init (void ) {/* * Register all the drivers. Note that order is important, the driver * registered last will get probed first. */ -bdrv_register (&bdrv_raw); +bdrv_register (&bdrv_file);bdrv_register (&bdrv_host_device);#ifdef __linux__bdrv_register (&bdrv_host_floppy);
@@ -1402,4 +1407,4 @@ static void bdrv_raw_init(void)#endif } -block_init (bdrv_raw_init); +block_init (bdrv_file_init);
block/raw-win32.c +7 -5
@@ -238,8 +238,9 @@ static QEMUOptionParameter raw_create_options[] = { { NULL } }; -static BlockDriver bdrv_raw = { - .format_name ="raw" , +static BlockDriver bdrv_file = { + .format_name ="file" , + .protocol_name ="file" , .instance_size =sizeof (BDRVRawState), .bdrv_open = raw_open, .bdrv_close = raw_close,
@@ -395,6 +396,7 @@ static int raw_set_locked(BlockDriverState *bs, int locked)static BlockDriver bdrv_host_device = { .format_name ="host_device" , + .protocol_name ="host_device" , .instance_size =sizeof (BDRVRawState), .bdrv_probe_device = hdev_probe_device, .bdrv_open = hdev_open,
@@ -406,10 +408,10 @@ static BlockDriver bdrv_host_device = { .bdrv_getlength = raw_getlength, }; -static void bdrv_raw_init (void ) +static void bdrv_file_init (void ) { -bdrv_register (&bdrv_raw); +bdrv_register (&bdrv_file);bdrv_register (&bdrv_host_device); } -block_init (bdrv_raw_init); +block_init (bdrv_file_init);
block/raw.c new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RFC PATCH 1/5] block: separate raw images from the file protocol
block/raw.c line 108
Quoted 6 lines · Kevin Wolf
block/raw.c new file +6
-0+static int raw_set_locked (BlockDriverState *bs,int locked) +{ + RAWState *s = bs->opaque; + bdrv_set_locked(s->hd, locked); + return 0; +}
Not something for this patch, but it's odd that BlockDriver->bdrv_set_locked() has a return value but global bdrv_set_locked() doesn't.
Stefan
RFC PATCH 2/5 block: Split bdrv_open
In reply to Kevin Wolfbdrv_open contains quite some code that is only useful for opening images (as opposed to opening files by a protocol), for example snapshots.
This patch splits the code so that we have bdrv_open_file() for files (uses protocols), bdrv_open() for images (uses format drivers) and bdrv_open_common() for the code common for opening both images and files.
--- block.c | 135 ++++++++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 86 insertions(+), 49 deletions(-)
block.c +86 -49
@@ -42,6 +42,9 @@#include <windows.h> #endif +static int bdrv_open_common (BlockDriverState *bs,const char *filename, +int flags,BlockDriver *drv); +static BlockDriverAIOCB *bdrv_aio_readv_em (BlockDriverState *bs,int64_t sector_num,QEMUIOVector *qiov,int nb_sectors,BlockDriverCompletionFunc *cb,void *opaque);
@@ -350,6 +353,9 @@ static BlockDriver *find_image_format(const char *filename)return drv; } +/* +* Opens a file using a protocol (file, host_device, nbd, ...) +*/ int bdrv_file_open (BlockDriverState **pbs,const char *filename,int flags) {BlockDriverState *bs;
@@ -362,7 +368,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags) } bs =bdrv_new ("" ); - ret =bdrv_open (bs, filename, flags, drv); + ret =bdrv_open_common (bs, filename, flags, drv);if (ret <0 ) {bdrv_delete (bs);return ret;
@@ -372,19 +378,13 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags)return 0 ; } +/* +* Opens a disk image (raw, qcow2, vmdk, ...) +*/ int bdrv_open (BlockDriverState *bs,const char *filename,int flags,BlockDriver *drv) { -int ret, open_flags; -char tmp_filename[PATH_MAX ]; -char backing_filename[PATH_MAX ]; - - bs->is_temporary =0 ; - bs->encrypted =0 ; - bs->valid_key =0 ; - bs->open_flags = flags; -/* buffer_alignment defaulted to 512, drivers can change this value */ - bs->buffer_alignment =512 ; +int ret;if (flags &BDRV_O_SNAPSHOT ) {BlockDriverState *bs1;
@@ -392,6 +392,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,int is_protocol =0 ;BlockDriver *bdrv_qcow2;QEMUOptionParameter *options; +char tmp_filename[PATH_MAX ]; +char backing_filename[PATH_MAX ];/* if snapshot, we create a temporary backing file and open it instead of opening 'filename' directly */
@@ -439,8 +441,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, bs->is_temporary =1 ; } -pstrcpy (bs->filename,sizeof (bs->filename), filename); - +/* Find the right image format driver */ if (!drv) { drv =find_image_format (filename); }
@@ -449,11 +450,81 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, ret = -ENOENT ; goto unlink_and_fail; } -if (use_bdrv_whitelist && !bdrv_is_whitelisted (drv)) { - ret = -ENOTSUP ; + +/* Open the image */ + ret =bdrv_open_common (bs, filename, flags, drv); +if (ret <0 ) { goto unlink_and_fail; } +/* If there is a backing file, use it */ +if ((flags &BDRV_O_NO_BACKING ) ==0 && bs->backing_file[0 ] !='\0' ) { +char backing_filename[PATH_MAX ]; +int back_flags; +BlockDriver *back_drv =NULL ; + + bs->backing_hd =bdrv_new ("" ); +path_combine (backing_filename,sizeof (backing_filename), + filename, bs->backing_file); +if (bs->backing_format[0 ] !='\0' ) + back_drv =bdrv_find_format (bs->backing_format); + +/* backing files always opened read-only */ + back_flags = + flags & ~(BDRV_O_RDWR |BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING ); + + ret =bdrv_open (bs->backing_hd, backing_filename, back_flags, back_drv); +if (ret <0 ) { +bdrv_close (bs); +return ret; + } +if (bs->is_temporary) { + bs->backing_hd->keep_read_only = !(flags &BDRV_O_RDWR ); + }else { +/* base image inherits from "parent" */ + bs->backing_hd->keep_read_only = bs->keep_read_only; + } + } + +if (!bdrv_key_required (bs)) { +/* call the change callback */ + bs->media_changed =1 ; +if (bs->change_cb) + bs->change_cb (bs->change_opaque); + } + +return 0 ; + +unlink_and_fail: +if (bs->is_temporary) { +unlink (filename); + } +return ret; +} + +/* +* Common part for opening disk images and files +*/ +static int bdrv_open_common (BlockDriverState *bs,const char *filename, +int flags,BlockDriver *drv) +{ +int ret, open_flags; + +assert (drv !=NULL ); + + bs->is_temporary =0 ; + bs->encrypted =0 ; + bs->valid_key =0 ; + bs->open_flags = flags; +/* buffer_alignment defaulted to 512, drivers can change this value */ + bs->buffer_alignment =512 ; + +pstrcpy (bs->filename,sizeof (bs->filename), filename); + +if (use_bdrv_whitelist && !bdrv_is_whitelisted (drv)) { +return -ENOTSUP ; + } + bs->drv = drv; bs->opaque =qemu_mallocz (drv->instance_size);
@@ -493,46 +564,12 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, unlink(filename); }#endif -if ((flags &BDRV_O_NO_BACKING ) ==0 && bs->backing_file[0 ] !='\0' ) { -/* if there is a backing file, use it */ -BlockDriver *back_drv =NULL ; - bs->backing_hd =bdrv_new ("" ); -path_combine (backing_filename,sizeof (backing_filename), - filename, bs->backing_file); -if (bs->backing_format[0 ] !='\0' ) - back_drv =bdrv_find_format (bs->backing_format); - -/* backing files always opened read-only */ - open_flags &= ~BDRV_O_RDWR ; - - ret =bdrv_open (bs->backing_hd, backing_filename, open_flags, back_drv); -if (ret <0 ) { -bdrv_close (bs); -return ret; - } -if (bs->is_temporary) { - bs->backing_hd->keep_read_only = !(flags &BDRV_O_RDWR ); - }else { -/* base image inherits from "parent" */ - bs->backing_hd->keep_read_only = bs->keep_read_only; - } - } - -if (!bdrv_key_required (bs)) { -/* call the change callback */ - bs->media_changed =1 ; -if (bs->change_cb) - bs->change_cb (bs->change_opaque); - }return 0 ; free_and_fail:qemu_free (bs->opaque); bs->opaque =NULL ; bs->drv =NULL ; -unlink_and_fail: -if (bs->is_temporary) -unlink (filename);return ret; }
Signature · 1 line
1.6.6.1
RFC PATCH 3/5 block: Avoid forward declaration of bdrv_open_common
In reply to Kevin WolfMove bdrv_open_common so it's defined before its callers and remove the forward declaration.
--- block.c | 145 +++++++++++++++++++++++++++++++-------------------------------- 1 files changed, 71 insertions(+), 74 deletions(-)
block.c +71 -74
@@ -42,9 +42,6 @@#include <windows.h> #endif -static int bdrv_open_common (BlockDriverState *bs,const char *filename, -int flags,BlockDriver *drv); -static BlockDriverAIOCB *bdrv_aio_readv_em (BlockDriverState *bs,int64_t sector_num,QEMUIOVector *qiov,int nb_sectors,BlockDriverCompletionFunc *cb,void *opaque);
@@ -354,6 +351,77 @@ static BlockDriver *find_image_format(const char *filename) }/* +* Common part for opening disk images and files +*/ +static int bdrv_open_common (BlockDriverState *bs,const char *filename, +int flags,BlockDriver *drv) +{ +int ret, open_flags; + +assert (drv !=NULL ); + + bs->is_temporary =0 ; + bs->encrypted =0 ; + bs->valid_key =0 ; + bs->open_flags = flags; +/* buffer_alignment defaulted to 512, drivers can change this value */ + bs->buffer_alignment =512 ; + +pstrcpy (bs->filename,sizeof (bs->filename), filename); + +if (use_bdrv_whitelist && !bdrv_is_whitelisted (drv)) { +return -ENOTSUP ; + } + + bs->drv = drv; + bs->opaque =qemu_mallocz (drv->instance_size); + +/* +* Yes, BDRV_O_NOCACHE aka O_DIRECT means we have to present a +* write cache to the guest. We do need the fdatasync to flush +* out transactions for block allocations, and we maybe have a +* volatile write cache in our backing device to deal with. +*/ +if (flags & (BDRV_O_CACHE_WB |BDRV_O_NOCACHE )) + bs->enable_write_cache =1 ; + +/* +* Clear flags that are internal to the block layer before opening the +* image. +*/ + open_flags = flags & ~(BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING ); + +/* +* Snapshots should be writeable. +*/ +if (bs->is_temporary) { + open_flags |=BDRV_O_RDWR ; + } + + ret = drv->bdrv_open (bs, filename, open_flags); +if (ret <0 ) { + goto free_and_fail; + } + + bs->keep_read_only = bs->read_only = !(open_flags &BDRV_O_RDWR ); +if (drv->bdrv_getlength) { + bs->total_sectors =bdrv_getlength (bs) >>BDRV_SECTOR_BITS ; + } +#ifndef _WIN32 +if (bs->is_temporary) { +unlink (filename); + } +#endif +return 0 ; + +free_and_fail: +qemu_free (bs->opaque); + bs->opaque =NULL ; + bs->drv =NULL ; +return ret; +} + +/* * Opens a file using a protocol (file, host_device, nbd, ...) */ int bdrv_file_open (BlockDriverState **pbs,const char *filename,int flags)
@@ -502,77 +570,6 @@ unlink_and_fail:return ret; } -/* -* Common part for opening disk images and files -*/ -static int bdrv_open_common (BlockDriverState *bs,const char *filename, -int flags,BlockDriver *drv) -{ -int ret, open_flags; - -assert (drv !=NULL ); - - bs->is_temporary =0 ; - bs->encrypted =0 ; - bs->valid_key =0 ; - bs->open_flags = flags; -/* buffer_alignment defaulted to 512, drivers can change this value */ - bs->buffer_alignment =512 ; - -pstrcpy (bs->filename,sizeof (bs->filename), filename); - -if (use_bdrv_whitelist && !bdrv_is_whitelisted (drv)) { -return -ENOTSUP ; - } - - bs->drv = drv; - bs->opaque =qemu_mallocz (drv->instance_size); - -/* -* Yes, BDRV_O_NOCACHE aka O_DIRECT means we have to present a -* write cache to the guest. We do need the fdatasync to flush -* out transactions for block allocations, and we maybe have a -* volatile write cache in our backing device to deal with. -*/ -if (flags & (BDRV_O_CACHE_WB |BDRV_O_NOCACHE )) - bs->enable_write_cache =1 ; - -/* -* Clear flags that are internal to the block layer before opening the -* image. -*/ - open_flags = flags & ~(BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING ); - -/* -* Snapshots should be writeable. -*/ -if (bs->is_temporary) { - open_flags |=BDRV_O_RDWR ; - } - - ret = drv->bdrv_open (bs, filename, open_flags); -if (ret <0 ) { - goto free_and_fail; - } - - bs->keep_read_only = bs->read_only = !(open_flags &BDRV_O_RDWR ); -if (drv->bdrv_getlength) { - bs->total_sectors =bdrv_getlength (bs) >>BDRV_SECTOR_BITS ; - } -#ifndef _WIN32 -if (bs->is_temporary) { -unlink (filename); - } -#endif -return 0 ; - -free_and_fail: -qemu_free (bs->opaque); - bs->opaque =NULL ; - bs->drv =NULL ; -return ret; -} -void bdrv_close (BlockDriverState *bs) {if (bs->drv) {
Signature · 1 line
1.6.6.1
RFC PATCH 4/5 block: Open the underlying image file in generic code
In reply to Kevin WolfFormat drivers shouldn't need to bother with things like file names, but rather just get an open BlockDriverState for the underlying protocol. This patch introduces this behaviour for bdrv_open implementation. For protocols which need to access the filename to open their file/device/connection/... a new callback bdrv_file_open is introduced which doesn't get an underlying file opened.
For now, also some of the more obscure formats use bdrv_file_open because they open() the file themselves instead of using the block.c functions. They need to be fixed in later patches.
--- block.c | 25 ++++++++++++++- block/blkdebug.c | 17 +++------ block/bochs.c | 2 +- block/cloop.c | 2 +- block/cow.c | 2 +- block/curl.c | 10 +++--- block/dmg.c | 2 +- block/nbd.c | 2 +- block/parallels.c | 2 +- block/qcow.c | 69 +++++++++++++++++++---------------------- block/qcow2-cluster.c | 64 ++++++++++++++++++++------------------ block/qcow2-refcount.c | 80 ++++++++++++++++++++++++------------------------ block/qcow2-snapshot.c | 22 ++++++------ block/qcow2.c | 67 +++++++++++++++++----------------------- block/qcow2.h | 2 +- block/raw-posix.c | 10 +++--- block/raw-win32.c | 4 +- block/raw.c | 63 +++++++++++--------------------------- block/vdi.c | 30 ++++++------------ block/vmdk.c | 2 +- block/vpc.c | 34 ++++++++------------ block/vvfat.c | 2 +- block_int.h | 5 ++- 23 files changed, 242 insertions(+), 276 deletions(-)
block.c +24 -1
@@ -288,6 +288,8 @@ static BlockDriver *find_protocol(const char *filename)int len;const char *p; +/* TODO Drivers without bdrv_file_open must be specified explicitly */ +#ifdef _WIN32if (is_windows_drive (filename) ||is_windows_drive_prefix (filename))
@@ -398,7 +400,16 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, open_flags |=BDRV_O_RDWR ; } - ret = drv->bdrv_open (bs, filename, open_flags); +/* Open the image, either directly or using a protocol */ +if (drv->bdrv_file_open) { + ret = drv->bdrv_file_open (bs, filename, open_flags); + }else { + ret =bdrv_file_open (&bs->file, filename, open_flags); +if (ret >=0 ) { + ret = drv->bdrv_open (bs, open_flags); + } + } +if (ret <0 ) { goto free_and_fail; }
@@ -415,6 +426,10 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,return 0 ; free_and_fail: +if (bs->file) { +bdrv_delete (bs->file); + bs->file =NULL ; + }qemu_free (bs->opaque); bs->opaque =NULL ; bs->drv =NULL ;
@@ -585,6 +600,10 @@ void bdrv_close(BlockDriverState *bs) bs->opaque =NULL ; bs->drv =NULL ; +if (bs->file !=NULL ) { +bdrv_close (bs->file); + } +/* call the change callback */ bs->media_changed =1 ;if (bs->change_cb)
@@ -600,6 +619,10 @@ void bdrv_delete(BlockDriverState *bs) }bdrv_close (bs); +if (bs->file !=NULL ) { +bdrv_delete (bs->file); + } +qemu_free (bs); }
block/blkdebug.c +6 -11
@@ -44,7 +44,6 @@ typedef struct BlkdebugVars { } BlkdebugVars;typedef struct BDRVBlkdebugState { -BlockDriverState *hd;BlkdebugVars vars; QLIST_HEAD(list, BlkdebugRule) rules[BLKDBG_EVENT_MAX]; }BDRVBlkdebugState ;
@@ -303,7 +302,7 @@ static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags) filename = c +1 ;/* Open the backing file */ - ret =bdrv_file_open (&s->hd, filename, flags); + ret =bdrv_file_open (&bs->file, filename, flags);if (ret <0 ) {return ret; }
@@ -362,7 +361,7 @@ static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs, }BlockDriverAIOCB *acb = -bdrv_aio_readv (s->hd, sector_num, qiov, nb_sectors, cb, opaque); +bdrv_aio_readv (bs->file, sector_num, qiov, nb_sectors, cb, opaque);return acb; }
@@ -377,7 +376,7 @@ static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs, }BlockDriverAIOCB *acb = -bdrv_aio_writev (s->hd, sector_num, qiov, nb_sectors, cb, opaque); +bdrv_aio_writev (bs->file, sector_num, qiov, nb_sectors, cb, opaque);return acb; }
@@ -393,21 +392,17 @@ static void blkdebug_close(BlockDriverState *bs)qemu_free (rule); } } - -bdrv_delete (s->hd); }static void blkdebug_flush (BlockDriverState *bs) { -BDRVBlkdebugState *s = bs->opaque; -bdrv_flush (s->hd); +bdrv_flush (bs->file); }static BlockDriverAIOCB *blkdebug_aio_flush (BlockDriverState *bs,BlockDriverCompletionFunc *cb,void *opaque) { -BDRVBlkdebugState *s = bs->opaque; -return bdrv_aio_flush (s->hd, cb, opaque); +return bdrv_aio_flush (bs->file, cb, opaque); } static void process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
@@ -456,7 +451,7 @@ static BlockDriver bdrv_blkdebug = { .instance_size = sizeof(BDRVBlkdebugState), - .bdrv_open = blkdebug_open, + .bdrv_file_open = blkdebug_open, .bdrv_close = blkdebug_close, .bdrv_flush = blkdebug_flush,
block/bochs.c +1 -1
@@ -254,7 +254,7 @@ static BlockDriver bdrv_bochs = { .format_name = "bochs", .instance_size = sizeof(BDRVBochsState), .bdrv_probe = bochs_probe, - .bdrv_open = bochs_open, + .bdrv_file_open = bochs_open, .bdrv_read = bochs_read, .bdrv_close = bochs_close, };
block/cloop.c +1 -1
@@ -161,7 +161,7 @@ static BlockDriver bdrv_cloop = { .format_name = "cloop", .instance_size = sizeof(BDRVCloopState), .bdrv_probe = cloop_probe, - .bdrv_open = cloop_open, + .bdrv_file_open = cloop_open, .bdrv_read = cloop_read, .bdrv_close = cloop_close, };
block/cow.c +1 -1
@@ -291,7 +291,7 @@ static BlockDriver bdrv_cow = { .format_name = "cow", .instance_size = sizeof(BDRVCowState), .bdrv_probe = cow_probe, - .bdrv_open = cow_open, + .bdrv_file_open = cow_open, .bdrv_read = cow_read, .bdrv_write = cow_write, .bdrv_close = cow_close,
block/curl.c +5 -5
@@ -495,7 +495,7 @@ static BlockDriver bdrv_http = { .protocol_name = "http", .instance_size = sizeof(BDRVCURLState), - .bdrv_open = curl_open, + .bdrv_file_open = curl_open, .bdrv_close = curl_close, .bdrv_getlength = curl_getlength,
@@ -507,7 +507,7 @@ static BlockDriver bdrv_https = { .protocol_name = "https", .instance_size = sizeof(BDRVCURLState), - .bdrv_open = curl_open, + .bdrv_file_open = curl_open, .bdrv_close = curl_close, .bdrv_getlength = curl_getlength,
@@ -519,7 +519,7 @@ static BlockDriver bdrv_ftp = { .protocol_name = "ftp", .instance_size = sizeof(BDRVCURLState), - .bdrv_open = curl_open, + .bdrv_file_open = curl_open, .bdrv_close = curl_close, .bdrv_getlength = curl_getlength,
@@ -531,7 +531,7 @@ static BlockDriver bdrv_ftps = { .protocol_name = "ftps", .instance_size = sizeof(BDRVCURLState), - .bdrv_open = curl_open, + .bdrv_file_open = curl_open, .bdrv_close = curl_close, .bdrv_getlength = curl_getlength,
@@ -543,7 +543,7 @@ static BlockDriver bdrv_tftp = { .protocol_name = "tftp", .instance_size = sizeof(BDRVCURLState), - .bdrv_open = curl_open, + .bdrv_file_open = curl_open, .bdrv_close = curl_close, .bdrv_getlength = curl_getlength,
block/dmg.c +1 -1
@@ -291,7 +291,7 @@ static BlockDriver bdrv_dmg = { .format_name = "dmg", .instance_size = sizeof(BDRVDMGState), .bdrv_probe = dmg_probe, - .bdrv_open = dmg_open, + .bdrv_file_open = dmg_open, .bdrv_read = dmg_read, .bdrv_close = dmg_close, };
block/nbd.c +1 -1
@@ -177,7 +177,7 @@ static int64_t nbd_getlength(BlockDriverState *bs)static BlockDriver bdrv_nbd = { .format_name ="nbd" , .instance_size =sizeof (BDRVNBDState), - .bdrv_open = nbd_open, + .bdrv_file_open = nbd_open, .bdrv_read = nbd_read, .bdrv_write = nbd_write, .bdrv_close = nbd_close,
block/parallels.c +1 -1
@@ -169,7 +169,7 @@ static BlockDriver bdrv_parallels = { .format_name = "parallels", .instance_size = sizeof(BDRVParallelsState), .bdrv_probe = parallels_probe, - .bdrv_open = parallels_open, + .bdrv_file_open = parallels_open, .bdrv_read = parallels_read, .bdrv_close = parallels_close, };
block/qcow.c +32 -37
222 lines not on this page · raw message
block/qcow2-cluster.c +33 -31
188 lines not on this page · raw message
block/qcow2-refcount.c +40 -40
258 lines not on this page · raw message
block/qcow2-snapshot.c +11 -11
@@ -79,7 +79,7 @@ int qcow2_read_snapshots(BlockDriverState *bs) s->snapshots =qemu_mallocz (s->nb_snapshots *sizeof (QCowSnapshot));for (i =0 ; i < s->nb_snapshots; i++) { offset =align_offset (offset,8 ); -if (bdrv_pread (s->hd, offset, &h,sizeof (h)) !=sizeof (h)) +if (bdrv_pread (bs->file, offset, &h,sizeof (h)) !=sizeof (h)) goto fail; offset +=sizeof (h); sn = s->snapshots + i;
@@ -97,13 +97,13 @@ int qcow2_read_snapshots(BlockDriverState *bs) offset += extra_data_size; sn->id_str =qemu_malloc (id_str_size +1 ); -if (bdrv_pread (s->hd, offset, sn->id_str, id_str_size) != id_str_size) +if (bdrv_pread (bs->file, offset, sn->id_str, id_str_size) != id_str_size) goto fail; offset += id_str_size; sn->id_str[id_str_size] ='\0' ; sn->name =qemu_malloc (name_size +1 ); -if (bdrv_pread (s->hd, offset, sn->name, name_size) != name_size) +if (bdrv_pread (bs->file, offset, sn->name, name_size) != name_size) goto fail; offset += name_size; sn->name[name_size] ='\0' ;
@@ -158,24 +158,24 @@ static int qcow_write_snapshots(BlockDriverState *bs) h.id_str_size =cpu_to_be16 (id_str_size); h.name_size =cpu_to_be16 (name_size); offset =align_offset (offset,8 ); -if (bdrv_pwrite (s->hd, offset, &h,sizeof (h)) !=sizeof (h)) +if (bdrv_pwrite (bs->file, offset, &h,sizeof (h)) !=sizeof (h)) goto fail; offset +=sizeof (h); -if (bdrv_pwrite (s->hd, offset, sn->id_str, id_str_size) != id_str_size) +if (bdrv_pwrite (bs->file, offset, sn->id_str, id_str_size) != id_str_size) goto fail; offset += id_str_size; -if (bdrv_pwrite (s->hd, offset, sn->name, name_size) != name_size) +if (bdrv_pwrite (bs->file, offset, sn->name, name_size) != name_size) goto fail; offset += name_size; }/* update the various header fields */ data64 =cpu_to_be64 (snapshots_offset); -if (bdrv_pwrite (s->hd, offsetof(QCowHeader , snapshots_offset), +if (bdrv_pwrite (bs->file, offsetof(QCowHeader , snapshots_offset), &data64,sizeof (data64)) !=sizeof (data64)) goto fail; data32 =cpu_to_be32 (s->nb_snapshots); -if (bdrv_pwrite (s->hd, offsetof(QCowHeader , nb_snapshots), +if (bdrv_pwrite (bs->file, offsetof(QCowHeader , nb_snapshots), &data32,sizeof (data32)) !=sizeof (data32)) goto fail;
@@ -284,7 +284,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)for (i =0 ; i < s->l1_size; i++) { l1_table[i] =cpu_to_be64 (s->l1_table[i]); } -if (bdrv_pwrite (s->hd, sn->l1_table_offset, +if (bdrv_pwrite (bs->file, sn->l1_table_offset, l1_table, s->l1_size *sizeof (uint64_t )) != (s->l1_size *sizeof (uint64_t ))) goto fail;
@@ -332,10 +332,10 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) s->l1_size = sn->l1_size; l1_size2 = s->l1_size *sizeof (uint64_t );/* copy the snapshot l1 table to the current l1 table */ -if (bdrv_pread (s->hd, sn->l1_table_offset, +if (bdrv_pread (bs->file, sn->l1_table_offset, s->l1_table, l1_size2) != l1_size2) goto fail; -if (bdrv_pwrite (s->hd, s->l1_table_offset, +if (bdrv_pwrite (bs->file, s->l1_table_offset, s->l1_table, l1_size2) != l1_size2) goto fail;for (i =0 ;i < s->l1_size; i++) {
block/qcow2.c +29 -38
222 lines not on this page · raw message
block/qcow2.h +1 -1
@@ -184,7 +184,7 @@ int qcow2_check_refcounts(BlockDriverState *bs);/* qcow2-cluster.c functions */ int qcow2_grow_l1_table (BlockDriverState *bs,int min_size);void qcow2_l2_cache_reset (BlockDriverState *bs); -int qcow2_decompress_cluster (BDRVQcowState *s,uint64_t cluster_offset); +int qcow2_decompress_cluster (BlockDriverState *bs,uint64_t cluster_offset); void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num, uint8_t *out_buf, const uint8_t *in_buf, int nb_sectors, int enc,
block/raw-posix.c +5 -5
@@ -773,7 +773,7 @@ static BlockDriver bdrv_file = { .protocol_name = "file", .instance_size = sizeof(BDRVRawState), .bdrv_probe = NULL, /* no probe for protocols */ - .bdrv_open = raw_open, + .bdrv_file_open = raw_open, .bdrv_read = raw_read, .bdrv_write = raw_write, .bdrv_close = raw_close,
@@ -1030,7 +1030,7 @@ static BlockDriver bdrv_host_device = { .protocol_name = "host_device", .instance_size = sizeof(BDRVRawState), .bdrv_probe_device = hdev_probe_device, - .bdrv_open = hdev_open, + .bdrv_file_open = hdev_open, .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options,
@@ -1145,7 +1145,7 @@ static BlockDriver bdrv_host_floppy = { .protocol_name = "host_floppy", .instance_size = sizeof(BDRVRawState), .bdrv_probe_device = floppy_probe_device, - .bdrv_open = floppy_open, + .bdrv_file_open = floppy_open, .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options,
@@ -1245,7 +1245,7 @@ static BlockDriver bdrv_host_cdrom = { .protocol_name = "host_cdrom", .instance_size = sizeof(BDRVRawState), .bdrv_probe_device = cdrom_probe_device, - .bdrv_open = cdrom_open, + .bdrv_file_open = cdrom_open, .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options,
@@ -1368,7 +1368,7 @@ static BlockDriver bdrv_host_cdrom = { .protocol_name = "host_cdrom", .instance_size = sizeof(BDRVRawState), .bdrv_probe_device = cdrom_probe_device, - .bdrv_open = cdrom_open, + .bdrv_file_open = cdrom_open, .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options,
block/raw-win32.c +2 -2
@@ -242,7 +242,7 @@ static BlockDriver bdrv_file = { .format_name = "file", .protocol_name = "file", .instance_size = sizeof(BDRVRawState), - .bdrv_open = raw_open, + .bdrv_file_open = raw_open, .bdrv_close = raw_close, .bdrv_create = raw_create, .bdrv_flush = raw_flush,
@@ -399,7 +399,7 @@ static BlockDriver bdrv_host_device = { .protocol_name = "host_device", .instance_size = sizeof(BDRVRawState), .bdrv_probe_device = hdev_probe_device, - .bdrv_open = hdev_open, + .bdrv_file_open = hdev_open, .bdrv_close = raw_close, .bdrv_flush = raw_flush,
block/raw.c +18 -45
144 lines not on this page · raw message
block/vdi.c +10 -20
@@ -376,21 +376,15 @@ static int vdi_probe(const uint8_t *buf, int buf_size, const char *filename)return result; } -static int vdi_open (BlockDriverState *bs,const char *filename,int flags) +static int vdi_open (BlockDriverState *bs,int flags) {BDRVVdiState *s = bs->opaque;VdiHeader header;size_t bmap_size; -int ret;logout ("\n" ); - ret =bdrv_file_open (&s->hd, filename, flags); -if (ret <0 ) { -return ret; - } - -if (bdrv_read (s->hd,0 , (uint8_t *)&header,1 ) <0 ) { +if (bdrv_read (bs->file,0 , (uint8_t *)&header,1 ) <0 ) { goto fail; }
@@ -442,7 +436,7 @@ static int vdi_open(BlockDriverState *bs, const char *filename, int flags) bmap_size = header.blocks_in_image *sizeof (uint32_t ); bmap_size = (bmap_size +SECTOR_SIZE -1 ) /SECTOR_SIZE ; s->bmap =qemu_malloc (bmap_size *SECTOR_SIZE ); -if (bdrv_read (s->hd, s->bmap_sector, (uint8_t *)s->bmap, bmap_size) <0 ) { +if (bdrv_read (bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size) <0 ) { goto fail_free_bmap; }
@@ -452,7 +446,7 @@ static int vdi_open(BlockDriverState *bs, const char *filename, int flags)qemu_free (s->bmap); fail: -bdrv_delete (s->hd); +bdrv_delete (bs->file);return -1 ; }
@@ -607,7 +601,7 @@ static void vdi_aio_read_cb(void *opaque, int ret) acb->hd_iov.iov_base = (void *)acb->buf; acb->hd_iov.iov_len = n_sectors *SECTOR_SIZE ;qemu_iovec_init_external (&acb->hd_qiov, &acb->hd_iov,1 ); - acb->hd_aiocb =bdrv_aio_readv (s->hd, offset, &acb->hd_qiov, + acb->hd_aiocb =bdrv_aio_readv (bs->file, offset, &acb->hd_qiov, n_sectors, vdi_aio_read_cb, acb);if (acb->hd_aiocb ==NULL ) { goto done;
@@ -670,7 +664,7 @@ static void vdi_aio_write_cb(void *opaque, int ret) acb->hd_iov.iov_base = acb->block_buffer; acb->hd_iov.iov_len =SECTOR_SIZE ;qemu_iovec_init_external (&acb->hd_qiov, &acb->hd_iov,1 ); - acb->hd_aiocb =bdrv_aio_writev (s->hd,0 , &acb->hd_qiov,1 , + acb->hd_aiocb =bdrv_aio_writev (bs->file,0 , &acb->hd_qiov,1 , vdi_aio_write_cb, acb);if (acb->hd_aiocb ==NULL ) { goto done;
@@ -699,7 +693,7 @@ static void vdi_aio_write_cb(void *opaque, int ret)qemu_iovec_init_external (&acb->hd_qiov, &acb->hd_iov,1 );logout ("will write %u block map sectors starting from entry %u\n" , n_sectors, bmap_first); - acb->hd_aiocb =bdrv_aio_writev (s->hd, offset, &acb->hd_qiov, + acb->hd_aiocb =bdrv_aio_writev (bs->file, offset, &acb->hd_qiov, n_sectors, vdi_aio_write_cb, acb);if (acb->hd_aiocb ==NULL ) { goto done;
@@ -748,7 +742,7 @@ static void vdi_aio_write_cb(void *opaque, int ret) acb->hd_iov.iov_base = (void *)block; acb->hd_iov.iov_len = s->block_size;qemu_iovec_init_external (&acb->hd_qiov, &acb->hd_iov,1 ); - acb->hd_aiocb =bdrv_aio_writev (s->hd, offset, + acb->hd_aiocb =bdrv_aio_writev (bs->file, offset, &acb->hd_qiov, s->block_sectors, vdi_aio_write_cb, acb);if (acb->hd_aiocb ==NULL ) {
@@ -761,7 +755,7 @@ static void vdi_aio_write_cb(void *opaque, int ret) acb->hd_iov.iov_base = (void *)acb->buf; acb->hd_iov.iov_len = n_sectors *SECTOR_SIZE ;qemu_iovec_init_external (&acb->hd_qiov, &acb->hd_iov,1 ); - acb->hd_aiocb =bdrv_aio_writev (s->hd, offset, &acb->hd_qiov, + acb->hd_aiocb =bdrv_aio_writev (bs->file, offset, &acb->hd_qiov, n_sectors, vdi_aio_write_cb, acb);if (acb->hd_aiocb ==NULL ) { goto done;
@@ -891,16 +885,12 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)static void vdi_close (BlockDriverState *bs) { -BDRVVdiState *s = bs->opaque; -logout ("\n" ); -bdrv_delete (s->hd); }static void vdi_flush (BlockDriverState *bs) { -BDRVVdiState *s = bs->opaque;logout ("\n" ); -bdrv_flush (s->hd); +bdrv_flush (bs->file); }
block/vmdk.c +1 -1
@@ -914,7 +914,7 @@ static BlockDriver bdrv_vmdk = { .format_name = "vmdk", .instance_size = sizeof(BDRVVmdkState), .bdrv_probe = vmdk_probe, - .bdrv_open = vmdk_open, + .bdrv_file_open = vmdk_open, .bdrv_read = vmdk_read, .bdrv_write = vmdk_write, .bdrv_close = vmdk_close,
block/vpc.c +14 -20
@@ -150,20 +150,16 @@ static int vpc_probe(const uint8_t *buf, int buf_size, const char *filename)return 0 ; } -static int vpc_open (BlockDriverState *bs,const char *filename,int flags) +static int vpc_open (BlockDriverState *bs,int flags) {BDRVVPCState *s = bs->opaque; -int ret, i; +int i;struct vhd_footer * footer;struct vhd_dyndisk_header * dyndisk_header;uint8_t buf[HEADER_SIZE ];uint32_t checksum; - ret =bdrv_file_open (&s->hd, filename, flags); -if (ret <0 ) -return ret; - -if (bdrv_pread (s->hd,0 , s->footer_buf,HEADER_SIZE ) !=HEADER_SIZE ) +if (bdrv_pread (bs->file,0 , s->footer_buf,HEADER_SIZE ) !=HEADER_SIZE ) goto fail; footer = (struct vhd_footer *) s->footer_buf;
@@ -174,7 +170,7 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags) footer->checksum =0 ;if (vpc_checksum (s->footer_buf,HEADER_SIZE ) != checksum)fprintf (stderr,"block-vpc: The header checksum of '%s' is " -"incorrect.\n" , filename); +"incorrect.\n" , bs->filename);// The visible size of a image in Virtual PC depends on the geometry // rather than on the size stored in the footer (the size in the footer
@@ -182,7 +178,7 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags) bs->total_sectors = (int64_t )be16_to_cpu (footer->cyls) * footer->heads * footer->secs_per_cyl; -if (bdrv_pread (s->hd,be64_to_cpu (footer->data_offset), buf,HEADER_SIZE ) +if (bdrv_pread (bs->file,be64_to_cpu (footer->data_offset), buf,HEADER_SIZE ) !=HEADER_SIZE ) goto fail;
@@ -199,7 +195,7 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags) s->pagetable =qemu_malloc (s->max_table_entries *4 ); s->bat_offset =be64_to_cpu (dyndisk_header->table_offset); -if (bdrv_pread (s->hd, s->bat_offset, s->pagetable, +if (bdrv_pread (bs->file, s->bat_offset, s->pagetable, s->max_table_entries *4 ) != s->max_table_entries *4 ) goto fail;
@@ -228,7 +224,7 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)return 0 ; fail: -bdrv_delete (s->hd); +bdrv_delete (bs->file);return -1 ; }
@@ -266,7 +262,7 @@ static inline int64_t get_sector_offset(BlockDriverState *bs, s->last_bitmap_offset = bitmap_offset;memset (bitmap,0xff , s->bitmap_size); -bdrv_pwrite (s->hd, bitmap_offset, bitmap, s->bitmap_size); +bdrv_pwrite (bs->file, bitmap_offset, bitmap, s->bitmap_size); }// printf("sector: %" PRIx64 ", index: %x, offset: %x, bioff: %" PRIx64 ", bloff: %" PRIx64 "\n",
@@ -316,7 +312,7 @@ static int rewrite_footer(BlockDriverState* bs)BDRVVPCState *s = bs->opaque;int64_t offset = s->free_data_block_offset; - ret =bdrv_pwrite (s->hd, offset, s->footer_buf,HEADER_SIZE ); + ret =bdrv_pwrite (bs->file, offset, s->footer_buf,HEADER_SIZE );if (ret <0 )return ret;
@@ -351,7 +347,7 @@ static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num)// Initialize the block's bitmap memset (bitmap,0xff , s->bitmap_size); -bdrv_pwrite (s->hd, s->free_data_block_offset, bitmap, s->bitmap_size); +bdrv_pwrite (bs->file, s->free_data_block_offset, bitmap, s->bitmap_size);// Write new footer (the old one will be overwritten) s->free_data_block_offset += s->block_size + s->bitmap_size;
@@ -362,7 +358,7 @@ static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num)// Write BAT entry to disk bat_offset = s->bat_offset + (4 * index); bat_value =be32_to_cpu (s->pagetable[index]); - ret =bdrv_pwrite (s->hd, bat_offset, &bat_value,4 ); + ret =bdrv_pwrite (bs->file, bat_offset, &bat_value,4 );if (ret <0 ) goto fail;
@@ -376,7 +372,6 @@ fail:static int vpc_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors) { -BDRVVPCState *s = bs->opaque;int ret;int64_t offset;
@@ -386,7 +381,7 @@ static int vpc_read(BlockDriverState *bs, int64_t sector_num,if (offset ==-1 ) {memset (buf,0 ,512 ); }else { - ret =bdrv_pread (s->hd, offset, buf,512 ); + ret =bdrv_pread (bs->file, offset, buf,512 );if (ret !=512 )return -1 ; }
@@ -401,7 +396,6 @@ static int vpc_read(BlockDriverState *bs, int64_t sector_num,static int vpc_write (BlockDriverState *bs,int64_t sector_num,const uint8_t *buf,int nb_sectors) { -BDRVVPCState *s = bs->opaque;int64_t offset;int ret;
@@ -414,7 +408,7 @@ static int vpc_write(BlockDriverState *bs, int64_t sector_num,return -1 ; } - ret =bdrv_pwrite (s->hd, offset, buf,512 ); + ret =bdrv_pwrite (bs->file, offset, buf,512 );if (ret !=512 )return -1 ;
@@ -590,7 +584,7 @@ static void vpc_close(BlockDriverState *bs)#ifdef CACHE qemu_free (s->pageentry_u8);#endif -bdrv_delete (s->hd); +bdrv_delete (bs->file); }static QEMUOptionParameter vpc_create_options[] = {
block/vvfat.c +1 -1
@@ -2827,7 +2827,7 @@ static void vvfat_close(BlockDriverState *bs)static BlockDriver bdrv_vvfat = { .format_name ="vvfat" , .instance_size =sizeof (BDRVVVFATState), - .bdrv_open = vvfat_open, + .bdrv_file_open = vvfat_open, .bdrv_read = vvfat_read, .bdrv_write = vvfat_write, .bdrv_close = vvfat_close,
block_int.h +4 -1
@@ -51,7 +51,8 @@ struct BlockDriver {int instance_size;int (*bdrv_probe)(const uint8_t *buf,int buf_size,const char *filename);int (*bdrv_probe_device)(const char *filename); -int (*bdrv_open)(BlockDriverState *bs,const char *filename,int flags); +int (*bdrv_open)(BlockDriverState *bs,int flags); +int (*bdrv_file_open)(BlockDriverState *bs,const char *filename,int flags);int (*bdrv_read)(BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors); int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
@@ -155,6 +156,8 @@ struct BlockDriverState {int media_changed;BlockDriverState *backing_hd; +BlockDriverState *file; +/* async read/write emulation */ void *sync_aiocb;
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RFC PATCH 4/5] block: Open the underlying image file in generic code
Quoted 4 lines · Kevin Wolf
block/qcow.c +0
-0
[..]
block/qcow.c static int qcow_open(BlockDriverState *bs, const char *filename, int flags) · line 171
Quoted 8 lines
block/qcow.c +1
-1@@ -169,7 +166,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) qemu_free(s->l2_cache); qemu_free(s->cluster_cache); qemu_free(s->cluster_data); - bdrv_delete(s->hd); + bdrv_delete(bs->file); return -1; }
qcow.c does not need to delete bs->file anymore because block.c does that when BlockDriver->bdrv_open() fails. Also since we're not setting bs->file to NULL after bdrv_delete() here, block.c will double delete it.
block/qcow.c static void qcow_close(BlockDriverState *bs) · line 743
Quoted 9 lines
block/qcow.c +1
-1@@ -739,7 +737,7 @@ static void qcow_close(BlockDriverState *bs) qemu_free(s->l2_cache); qemu_free(s->cluster_cache); qemu_free(s->cluster_data); - bdrv_delete(s->hd); + bdrv_delete(bs->file); } static int qcow_create(const char *filename, QEMUOptionParameter *options)
block.c will bdrv_close(bs->file) for us, so I think this is not needed. Double delete.
Quoted 4 lines
block/qcow2.c +0
-0
[...]
block/qcow2.c static int qcow_open(BlockDriverState *bs, const char *filename, int flags) · line 255
Quoted 8 lines
block/qcow2.c +1
-1@@ -254,7 +250,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) qemu_free(s->l2_cache); qemu_free(s->cluster_cache); qemu_free(s->cluster_data); - bdrv_delete(s->hd); + bdrv_delete(bs->file); return -1; }
Same as above.
Quoted 4 lines
block/vdi.c +0
-0
[...]
Quoted 8 lines
block/vdi.c +0
-0@@ -452,7 +446,7 @@ static int vdi_open(BlockDriverState *bs, const char *filename, int flags) qemu_free(s->bmap);fail:
- bdrv_delete(s->hd);
+ bdrv_delete(bs->file);
return -1;
}
Same as above.
Quoted 4 lines
block/vpc.c +0
-0
[...]
Quoted 8 lines
block/vpc.c +0
-0@@ -228,7 +224,7 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags) return 0;fail:
- bdrv_delete(s->hd);
+ bdrv_delete(bs->file);
return -1;
}
Same as above.
block/vpc.c static void vpc_close(BlockDriverState *bs) · line 590
Quoted 9 lines
block/vpc.c +1
-1@@ -590,7 +584,7 @@ static void vpc_close(BlockDriverState *bs) #ifdef CACHE qemu_free(s->pageentry_u8); #endif - bdrv_delete(s->hd); + bdrv_delete(bs->file); } static QEMUOptionParameter vpc_create_options[] = {
Same as above.
Stefan
RFC PATCH 5/5 block: bdrv_has_zero_init
In reply to Kevin WolfThis fixes the problem that qemu-img's use of no_zero_init only considered the no_zero_init flag of the format driver, but not of the underlying protocols.
Between the raw/file split and this fix, converting to host devices is broken.
--- block.c | 13 +++++++++++++ block.h | 1 + qemu-img.c | 6 ++++-- 3 files changed, 18 insertions(+), 2 deletions(-)
block.c +13 -0
@@ -1281,6 +1281,19 @@ void bdrv_flush_all(void) } } +int bdrv_has_zero_init (BlockDriverState *bs) +{ +assert (bs->drv); + +if (bs->drv->no_zero_init) { +return 0 ; + }else if (bs->file) { +return bdrv_has_zero_init (bs->file); + } + +return 1 ; +} +/* * Returns true iff the specified sector is present in the disk image. Drivers * not implementing the functionality are assumed to not support backing files,
block.h +1 -0
@@ -122,6 +122,7 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,void bdrv_flush (BlockDriverState *bs);void bdrv_flush_all (void ); +int bdrv_has_zero_init (BlockDriverState *bs);int bdrv_is_allocated (BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum);
qemu-img.c +4 -2
@@ -732,6 +732,8 @@ static int img_convert(int argc, char **argv)/* signal EOF to align */ bdrv_write_compressed (out_bs,0 ,NULL ,0 ); }else { +int has_zero_init =bdrv_has_zero_init (out_bs); + sector_num =0 ;// total number of sectors converted so far for (;;) { nb_sectors = total_sectors - sector_num;
@@ -755,7 +757,7 @@ static int img_convert(int argc, char **argv)if (n > bs_offset + bs_sectors - sector_num) n = bs_offset + bs_sectors - sector_num; -if (!drv->no_zero_init) { +if (has_zero_init) {/* If the output image is being created as a copy on write image, assume that sectors which are unallocated in the input image are present in both the output's and input's base images (no
@@ -788,7 +790,7 @@ static int img_convert(int argc, char **argv)If the output is to a host device, we also write out sectors that are entirely 0, since whatever data was already there is garbage, not 0s. */ -if (drv->no_zero_init || out_baseimg || +if (!has_zero_init || out_baseimg ||is_allocated_sectors (buf1, n, &n1)) {if (bdrv_write (out_bs, sector_num, buf1, n1) <0 )error ("error while writing" );
Signature · 1 line
1.6.6.1