Block patches
Subsystems (2)
The following changes since commit 0bfe006c5380c5f8a485a55ded3329fbbc224396:
multiboot: Fix upper memory size in multiboot info (2011-01-23 22:44:13 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.git for-anthony
Aurelien Jarno (1):
qcow2: fix unaligned access
Christoph Hellwig (3):
ide: factor dma handling helpers
ide: also reset io_buffer_index for writes
ide: kill ide_dma_submit_check
Jes Sorensen (2):
do_snapshot_blkdev() error on missing snapshot_file argument Make strtosz() return int64_t instead of ssize_t
Kevin Wolf (5):
qemu-img snapshot: Use writeback caching
qcow2: Add QcowCache
qcow2: Use QcowCache
qcow2: Batch flushes for COW
Documentation: Add qemu-img check/rebase
Markus Armbruster (3):
blockdev: Fix error message for invalid -drive CHS
blockdev: Make drive_init() use error_report()
blockdev: Fix drive_del not to crash when drive is not in use
Pierre Riteau (2):
Avoid divide by zero when there is no block device to migrate Fix block migration when the device size is not a multiple of 1 MB
Stefan Hajnoczi (6):
qed: Refuse to create images on block devices
block: Use backing format driver during image creation
scsi-disk: Allow overriding SCSI INQUIRY removable bit
scsi: Allow scsi_bus_legacy_add_drive() to set removable bit
usb-msd: Propagate removable bit to SCSI device
docs: Document scsi-disk and usb-storage removable parameter
Stefan Weil (1):
ide: Remove unneeded null pointer check
Makefile.objs | 2 +- block-migration.c | 29 ++++- block.c | 8 +- block/qcow2-cache.c | 314 ++++++++++++++++++++++++++++++++++++++++++++++ block/qcow2-cluster.c | 210 +++++++++++-------------------- block/qcow2-refcount.c | 260 ++++++++++++++++---------------------- block/qcow2.c | 48 +++++++- block/qcow2.h | 32 ++++- block/qed.c | 6 + blockdev.c | 81 +++++++------ cutils.c | 8 +- docs/qdev-device-use.txt | 13 ++- hw/ide/core.c | 113 ++++++----------- hw/ide/internal.h | 4 +- hw/ide/pci.c | 13 +-- hw/pci-hotplug.c | 2 +- hw/scsi-bus.c | 8 +- hw/scsi-disk.c | 3 + hw/scsi.h | 3 +- hw/usb-msd.c | 4 +- monitor.c | 2 +- qemu-common.h | 4 +- qemu-img.c | 4 +- qemu-img.texi | 41 ++++++ vl.c | 4 +- 25 files changed, 764 insertions(+), 452 deletions(-) create mode 100644 block/qcow2-cache.c
PATCH 1/23 qcow2: fix unaligned access
From: Aurelien Jarno <[email protected]>
cpu_to_be64w() is called with an obviously non-aligned pointer. Use cpu_to_be64wu() instead. It fixes unaligned accesses errors on IA64 hosts.
--- block/qcow2-cluster.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
block/qcow2-cluster.c +1 -1
@@ -81,7 +81,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size)/* set new table */ BLKDBG_EVENT (bs->file,BLKDBG_L1_GROW_ACTIVATE_TABLE );cpu_to_be32w ((uint32_t *)data, new_l1_size); -cpu_to_be64w ((uint64_t *)(data +4 ), new_l1_table_offset); +cpu_to_be64wu ((uint64_t *)(data +4 ), new_l1_table_offset); ret =bdrv_pwrite_sync (bs->file, offsetof(QCowHeader , l1_size), data,sizeof (data));if (ret <0 ) { goto fail;
Signature · 1 line
1.7.2.3
PATCH 2/23 qemu-img snapshot: Use writeback caching
In reply to Kevin WolfNone of the other qemu-img subcommands uses writethrough, and there's no reason why snapshot should be special.
--- qemu-img.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
qemu-img.c +1 -1
@@ -1068,7 +1068,7 @@ static int img_snapshot(int argc, char **argv)int action =0 ;qemu_timeval tv; - bdrv_oflags =BDRV_O_RDWR ; + bdrv_oflags =BDRV_O_FLAGS |BDRV_O_RDWR ;/* Parse commandline parameters */ for (;;) { c =getopt (argc, argv,"la:c:d:h" );
Signature · 1 line
1.7.2.3
PATCH 3/23 do_snapshot_blkdev() error on missing snapshot_file argument
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
Current code does not support snapshot internally to the running image. Error in case no snapshot_file is specified.
--- blockdev.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
blockdev.c +6 -0
@@ -526,6 +526,12 @@ int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data)int ret =0 ;int flags; +if (!filename) { +qerror_report (QERR_MISSING_PARAMETER ,"snapshot_file" ); + ret =-1 ; + goto out; + } + bs =bdrv_find (device);if (!bs) {qerror_report (QERR_DEVICE_NOT_FOUND , device);
Signature · 1 line
1.7.2.3
PATCH 4/23 Make strtosz() return int64_t instead of ssize_t
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
strtosz() needs to return a 64 bit type even on 32 bit architectures. Otherwise qemu-img will fail to create disk images >= 2GB
--- cutils.c | 8 ++++---- monitor.c | 2 +- qemu-common.h | 4 ++-- qemu-img.c | 2 +- vl.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-)
cutils.c +4 -4
@@ -291,9 +291,9 @@ int fcntl_setfl(int fd, int flag)* value must be terminated by whitespace, ',' or '\0'. Return -1 on * error. */ -ssize_t strtosz_suffix (const char *nptr,char **end,const char default_suffix) +int64_t strtosz_suffix (const char *nptr,char **end,const char default_suffix) { -ssize_t retval =-1 ; +int64_t retval =-1 ;char *endptr, c, d;int mul_required =0 ;double val, mul, integral, fraction;
@@ -365,7 +365,7 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) goto fail; } } -if ((val * mul >= ~(size_t )0 ) || val <0 ) { +if ((val * mul >=INT64_MAX ) || val <0 ) { goto fail; } retval = val * mul;
@@ -378,7 +378,7 @@ fail:return retval; } -ssize_t strtosz (const char *nptr,char **end) +int64_t strtosz (const char *nptr,char **end) {return strtosz_suffix (nptr, end,STRTOSZ_DEFSUFFIX_MB ); }
monitor.c +1 -1
@@ -4162,7 +4162,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,break ;case 'o' : { -ssize_t val; +int64_t val;char *end;while (qemu_isspace (*p)) {
qemu-common.h +2 -2
@@ -158,8 +158,8 @@ int fcntl_setfl(int fd, int flag);#define STRTOSZ_DEFSUFFIX_MB 'M'#define STRTOSZ_DEFSUFFIX_KB 'K'#define STRTOSZ_DEFSUFFIX_B 'B' -ssize_t strtosz (const char *nptr,char **end); -ssize_t strtosz_suffix (const char *nptr,char **end,const char default_suffix); +int64_t strtosz (const char *nptr,char **end); +int64_t strtosz_suffix (const char *nptr,char **end,const char default_suffix);/* path.c */ void init_paths (const char *prefix);
qemu-img.c +1 -1
@@ -320,7 +320,7 @@ static int img_create(int argc, char **argv)/* Get image size, if specified */ if (optind < argc) { -ssize_t sval; +int64_t sval; sval =strtosz_suffix (argv[optind++],NULL ,STRTOSZ_DEFSUFFIX_B );if (sval <0 ) { error_report("Invalid image size specified! You may use k, M, G or "
vl.c +2 -2
@@ -804,7 +804,7 @@ static void numa_add(const char *optarg)if (get_param_value (option,128 ,"mem" , optarg) ==0 ) { node_mem[nodenr] =0 ; }else { -ssize_t sval; +int64_t sval; sval =strtosz (option,NULL );if (sval <0 ) {fprintf (stderr,"qemu: invalid numa mem size: %s\n" , optarg);
@@ -2245,7 +2245,7 @@ int main(int argc, char **argv, char **envp)exit (0 );break ;case QEMU_OPTION_m: { -ssize_t value; +int64_t value; value =strtosz (optarg,NULL );if (value <0 ) {
Signature · 1 line
1.7.2.3
PATCH 5/23 Avoid divide by zero when there is no block device to migrate
In reply to Kevin WolfFrom: Pierre Riteau <[email protected]>
When block migration is requested and no read-write block device is present, a divide by zero exception is triggered because total_sector_sum equals zero.
--- block-migration.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
block-migration.c +6 -1
@@ -350,7 +350,12 @@ static int blk_mig_save_bulked_block(Monitor *mon, QEMUFile *f) } } - progress = completed_sector_sum *100 / block_mig_state.total_sector_sum; +if (block_mig_state.total_sector_sum !=0 ) { + progress = completed_sector_sum *100 / + block_mig_state.total_sector_sum; + }else { + progress =100 ; + }if (progress != block_mig_state.prev_progress) { block_mig_state.prev_progress = progress; qemu_put_be64(f, (progress << BDRV_SECTOR_BITS)
Signature · 1 line
1.7.2.3
PATCH 6/23 ide: factor dma handling helpers
In reply to Kevin WolfFrom: Christoph Hellwig <[email protected]>
Factor the DMA I/O path that is duplicated between read and write commands, into common helpers using the s->is_read flag added for the macio ATA controller.
--- hw/ide/core.c | 103 +++++++++++++++++------------------------------------ hw/ide/internal.h | 4 +-- hw/ide/pci.c | 9 +---- 3 files changed, 36 insertions(+), 80 deletions(-)
hw/ide/core.c +33 -70
@@ -487,16 +487,18 @@ static int ide_handle_rw_error(IDEState *s, int error, int op)return 1 ; } -void ide_read_dma_cb (void *opaque,int ret) +void ide_dma_cb (void *opaque,int ret) {IDEState *s = opaque;int n;int64_t sector_num;if (ret <0 ) { -if (ide_handle_rw_error (s, -ret, -BM_STATUS_DMA_RETRY |BM_STATUS_RETRY_READ )) - { +int op =BM_STATUS_DMA_RETRY ; + +if (s->is_read) + op |=BM_STATUS_RETRY_READ ; +if (ide_handle_rw_error (s, -ret, op)) {return ; } }
@@ -504,7 +506,7 @@ void ide_read_dma_cb(void *opaque, int ret) n = s->io_buffer_size >>9 ; sector_num =ide_get_sector (s);if (n >0 ) { -dma_buf_commit (s,1 ); +dma_buf_commit (s, s->is_read); sector_num += n;ide_set_sector (s, sector_num); s->nsector -= n;
@@ -514,32 +516,44 @@ void ide_read_dma_cb(void *opaque, int ret)if (s->nsector ==0 ) { s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus); - eot: - s->bus->dma->ops->add_status (s->bus->dma,BM_STATUS_INT ); -ide_set_inactive (s); -return ; + goto eot; }/* launch next transfer */ n = s->nsector; - s->io_buffer_index =0 ; +if (s->is_read) + s->io_buffer_index =0 ; s->io_buffer_size = n *512 ; -if (s->bus->dma->ops->prepare_buf (s->bus->dma,1 ) ==0 ) +if (s->bus->dma->ops->prepare_buf (s->bus->dma, s->is_read) ==0 ) goto eot; +#ifdef DEBUG_AIO -printf ("aio_read: sector_num=%" PRId64" n=%d\n" , sector_num, n); +printf ("ide_dma_cb: sector_num=%" PRId64" n=%d, is_read=%d\n" , + sector_num, n, s->is_read);#endif - s->bus->dma->aiocb =dma_bdrv_read (s->bs, &s->sg, sector_num, ide_read_dma_cb, s); -ide_dma_submit_check (s, ide_read_dma_cb); + +if (s->is_read) { + s->bus->dma->aiocb =dma_bdrv_read (s->bs, &s->sg, sector_num, + ide_dma_cb, s); + }else { + s->bus->dma->aiocb =dma_bdrv_write (s->bs, &s->sg, sector_num, + ide_dma_cb, s); + } +ide_dma_submit_check (s, ide_dma_cb); +return ; + +eot: + s->bus->dma->ops->add_status (s->bus->dma,BM_STATUS_INT ); +ide_set_inactive (s); } -static void ide_sector_read_dma (IDEState *s) +static void ide_sector_start_dma (IDEState *s,int is_read) { s->status =READY_STAT |SEEK_STAT |DRQ_STAT |BUSY_STAT ; s->io_buffer_index =0 ; s->io_buffer_size =0 ; - s->is_read =1 ; - s->bus->dma->ops->start_dma (s->bus->dma, s, ide_read_dma_cb); + s->is_read = is_read; + s->bus->dma->ops->start_dma (s->bus->dma, s, ide_dma_cb); }static void ide_sector_write_timer_cb (void *opaque)
@@ -594,57 +608,6 @@ void ide_sector_write(IDEState *s) } } -void ide_write_dma_cb (void *opaque,int ret) -{ -IDEState *s = opaque; -int n; -int64_t sector_num; - -if (ret <0 ) { -if (ide_handle_rw_error (s, -ret,BM_STATUS_DMA_RETRY )) -return ; - } - - n = s->io_buffer_size >>9 ; - sector_num =ide_get_sector (s); -if (n >0 ) { -dma_buf_commit (s,0 ); - sector_num += n; -ide_set_sector (s, sector_num); - s->nsector -= n; - } - -/* end of transfer ? */ -if (s->nsector ==0 ) { - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); - eot: - s->bus->dma->ops->add_status (s->bus->dma,BM_STATUS_INT ); -ide_set_inactive (s); -return ; - } - - n = s->nsector; - s->io_buffer_size = n *512 ; -/* launch next transfer */ -if (s->bus->dma->ops->prepare_buf (s->bus->dma,0 ) ==0 ) - goto eot; -#ifdef DEBUG_AIO -printf ("aio_write: sector_num=%" PRId64" n=%d\n" , sector_num, n); -#endif - s->bus->dma->aiocb =dma_bdrv_write (s->bs, &s->sg, sector_num, ide_write_dma_cb, s); -ide_dma_submit_check (s, ide_write_dma_cb); -} - -static void ide_sector_write_dma (IDEState *s) -{ - s->status =READY_STAT |SEEK_STAT |DRQ_STAT |BUSY_STAT ; - s->io_buffer_index =0 ; - s->io_buffer_size =0 ; - s->is_read =0 ; - s->bus->dma->ops->start_dma (s->bus->dma, s, ide_write_dma_cb); -} -void ide_atapi_cmd_ok (IDEState *s) { s->error =0 ;
@@ -1858,7 +1821,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)if (!s->bs) goto abort_cmd;ide_cmd_lba48_transform (s, lba48); -ide_sector_read_dma (s); +ide_sector_start_dma (s,1 );break ;case WIN_WRITEDMA_EXT : lba48 =1 ;
@@ -1867,7 +1830,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)if (!s->bs) goto abort_cmd;ide_cmd_lba48_transform (s, lba48); -ide_sector_write_dma (s); +ide_sector_start_dma (s,0 ); s->media_changed =1 ;break ;case WIN_READ_NATIVE_MAX_EXT :
hw/ide/internal.h +1 -3
@@ -439,7 +439,6 @@ struct IDEState {uint32_t mdata_size;uint8_t *mdata_storage;int media_changed; -/* for pmac */ int is_read;/* SMART */ uint8_t smart_enabled;
@@ -560,8 +559,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,void ide_init_ioport (IDEBus *bus,int iobase,int iobase2);void ide_exec_cmd (IDEBus *bus,uint32_t val); -void ide_read_dma_cb (void *opaque,int ret); -void ide_write_dma_cb (void *opaque,int ret); +void ide_dma_cb (void *opaque,int ret);void ide_sector_write (IDEState *s);void ide_sector_read (IDEState *s);void ide_flush_cache (IDEState *s);
hw/ide/pci.c +2 -7
@@ -178,14 +178,9 @@ static void bmdma_restart_dma(BMDMAState *bm, int is_read) s->io_buffer_index =0 ; s->io_buffer_size =0 ; s->nsector = bm->nsector; + s->is_read = is_read; bm->cur_addr = bm->addr; - -if (is_read) { - bm->dma_cb = ide_read_dma_cb; - }else { - bm->dma_cb = ide_write_dma_cb; - } - + bm->dma_cb = ide_dma_cb;bmdma_start_dma (&bm->dma, s, bm->dma_cb); }
Signature · 1 line
1.7.2.3
PATCH 7/23 ide: also reset io_buffer_index for writes
In reply to Kevin WolfFrom: Christoph Hellwig <[email protected]>
Currenly the code only resets the io_buffer_index field for reads, but the code seems to expect this for all types of I/O. I guess we simply don't hit large enough transfers that would require this often enough.
--- hw/ide/core.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
hw/ide/core.c +1 -2
@@ -521,8 +521,7 @@ void ide_dma_cb(void *opaque, int ret)/* launch next transfer */ n = s->nsector; -if (s->is_read) - s->io_buffer_index =0 ; + s->io_buffer_index =0 ; s->io_buffer_size = n *512 ;if (s->bus->dma->ops->prepare_buf (s->bus->dma, s->is_read) ==0 ) goto eot;
Signature · 1 line
1.7.2.3
PATCH 8/23 ide: kill ide_dma_submit_check
In reply to Kevin WolfFrom: Christoph Hellwig <[email protected]>
Merge ide_dma_submit_check into it's only caller. Also use tail recursion using a goto instead of a real recursion - this avoid overflowing the stack in the pathological situation of an recurring error that is ignored. We'll still be busy looping in ide_dma_cb, but at least won't eat up all stack space after this.
--- hw/ide/core.c | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-)
hw/ide/core.c +6 -9
@@ -321,14 +321,6 @@ static inline void ide_abort_command(IDEState *s) s->error =ABRT_ERR ; } -static inline void ide_dma_submit_check (IDEState *s, -BlockDriverCompletionFunc *dma_cb) -{ -if (s->bus->dma->aiocb) -return ; -dma_cb (s,-1 ); -} -/* prepare data transfer and tell what to do after */ static void ide_transfer_start (IDEState *s,uint8_t *buf,int size,EndTransferFunc *end_transfer_func)
@@ -493,6 +485,7 @@ void ide_dma_cb(void *opaque, int ret)int n;int64_t sector_num; +handle_rw_error:if (ret <0 ) {int op =BM_STATUS_DMA_RETRY ;
@@ -538,7 +531,11 @@ void ide_dma_cb(void *opaque, int ret) s->bus->dma->aiocb =dma_bdrv_write (s->bs, &s->sg, sector_num, ide_dma_cb, s); } -ide_dma_submit_check (s, ide_dma_cb); + +if (!s->bus->dma->aiocb) { + ret =-1 ; + goto handle_rw_error; + }return ; eot:
Signature · 1 line
1.7.2.3
PATCH 9/23 qcow2: Add QcowCache
In reply to Kevin WolfThis adds some new cache functions to qcow2 which can be used for caching refcount blocks and L2 tables. When used with cache=writethrough they work like the old caching code which is spread all over qcow2, so for this case we have merely a cleanup.
The interesting case is with writeback caching (this includes cache=none) where data isn't written to disk immediately but only kept in cache initially. This leads to some form of metadata write batching which avoids the current "write to refcount block, flush, write to L2 table" pattern for each single request when a lot of cluster allocations happen. Instead, cache entries are only written out if its required to maintain the right order. In the pure cluster allocation case this means that all metadata updates for requests are done in memory initially and on sync, first the refcount blocks are written to disk, then fsync, then L2 tables.
This improves performance of scenarios with lots of cluster allocations noticably (e.g. installation or after taking a snapshot).
--- Makefile.objs | 2 +- block/qcow2-cache.c | 290 +++++++++++++++++++++++++++++++++++++++++++++++++++ block/qcow2.h | 19 ++++ 3 files changed, 310 insertions(+), 1 deletions(-) create mode 100644 block/qcow2-cache.c
Makefile.objs +1 -1
@@ -19,7 +19,7 @@ block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.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 += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-nested-y += qed-check.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
block/qcow2-cache.c new file +290 -0
290 lines not on this page · raw message
block/qcow2.h +19 -0
@@ -78,6 +78,9 @@ typedef struct QCowSnapshot {uint64_t vm_clock_nsec; } QCowSnapshot; +struct Qcow2Cache ; +typedef struct Qcow2Cache Qcow2Cache ; + typedef struct BDRVQcowState { int cluster_bits; int cluster_size;
@@ -215,4 +218,20 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name);void qcow2_free_snapshots (BlockDriverState *bs);int qcow2_read_snapshots (BlockDriverState *bs); +/* qcow2-cache.c functions */ +Qcow2Cache *qcow2_cache_create (BlockDriverState *bs,int num_tables, +bool writethrough); +int qcow2_cache_destroy (BlockDriverState * bs,Qcow2Cache *c); + +void qcow2_cache_entry_mark_dirty (Qcow2Cache *c,void *table); +int qcow2_cache_flush (BlockDriverState *bs,Qcow2Cache *c); +int qcow2_cache_set_dependency (BlockDriverState *bs,Qcow2Cache *c, +Qcow2Cache *dependency); + +int qcow2_cache_get (BlockDriverState *bs,Qcow2Cache *c,uint64_t offset, +void **table); +int qcow2_cache_get_empty (BlockDriverState *bs,Qcow2Cache *c,uint64_t offset, +void **table); +int qcow2_cache_put (BlockDriverState *bs,Qcow2Cache *c,void **table); +#endif
Signature · 1 line
1.7.2.3
PATCH 11/23 qcow2: Batch flushes for COW
In reply to Kevin Wolfqcow2 calls bdrv_flush() after performing COW in order to ensure that the L2 table change is never written before the copy is safe on disk. Now that the L2 table is cached, we can wait with flushing until we write out the next L2 table.
--- block/qcow2-cache.c | 20 +++++++++++++++++--- block/qcow2-cluster.c | 2 +- block/qcow2.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-)
block/qcow2-cache.c +17 -3
@@ -38,6 +38,7 @@ struct Qcow2Cache {int size;Qcow2CachedTable * entries;struct Qcow2Cache * depends; +bool depends_on_flush;bool writethrough; };
@@ -85,13 +86,15 @@ static int qcow2_cache_flush_dependency(BlockDriverState *bs, Qcow2Cache *c) } c->depends =NULL ; + c->depends_on_flush = false; +return 0 ; }static int qcow2_cache_entry_flush (BlockDriverState *bs,Qcow2Cache *c,int i) {BDRVQcowState *s = bs->opaque; -int ret; +int ret =0 ;if (!c->entries[i].dirty || !c->entries[i].offset) {return 0 ;
@@ -99,11 +102,17 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)if (c->depends) { ret =qcow2_cache_flush_dependency (bs, c); -if (ret <0 ) { -return ret; + }else if (c->depends_on_flush) { + ret =bdrv_flush (bs->file); +if (ret >=0 ) { + c->depends_on_flush = false; } } +if (ret <0 ) { +return ret; + } +if (c == s->refcount_block_cache) {BLKDBG_EVENT (bs->file,BLKDBG_REFBLOCK_UPDATE_PART ); }else if (c == s->l2_table_cache) {
@@ -167,6 +176,11 @@ int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,return 0 ; } +void qcow2_cache_depends_on_flush (Qcow2Cache *c) +{ + c->depends_on_flush = true; +} +static int qcow2_cache_find_entry_to_replace (Qcow2Cache *c) {int i;
block/qcow2-cluster.c +1 -1
@@ -637,7 +637,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)* handled. */ if (cow) { -bdrv_flush (bs->file); +qcow2_cache_depends_on_flush (s->l2_table_cache); }qcow2_cache_set_dependency (bs, s->l2_table_cache, s->refcount_block_cache);
block/qcow2.h +1 -0
@@ -229,6 +229,7 @@ void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);int qcow2_cache_flush (BlockDriverState *bs,Qcow2Cache *c);int qcow2_cache_set_dependency (BlockDriverState *bs,Qcow2Cache *c,Qcow2Cache *dependency); +void qcow2_cache_depends_on_flush (Qcow2Cache *c);int qcow2_cache_get (BlockDriverState *bs,Qcow2Cache *c,uint64_t offset,void **table);
Signature · 1 line
1.7.2.3
PATCH 10/23 qcow2: Use QcowCache
In reply to Kevin WolfUse the new functions of qcow2-cache.c for everything that works on refcount block and L2 tables.
--- block/qcow2-cache.c | 10 ++ block/qcow2-cluster.c | 208 +++++++++++++------------------------- block/qcow2-refcount.c | 260 ++++++++++++++++++++---------------------------- block/qcow2.c | 48 ++++++++- block/qcow2.h | 12 ++- 5 files changed, 240 insertions(+), 298 deletions(-)
block/qcow2-cache.c +10 -0
@@ -104,6 +104,12 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i) } } +if (c == s->refcount_block_cache) { +BLKDBG_EVENT (bs->file,BLKDBG_REFBLOCK_UPDATE_PART ); + }else if (c == s->l2_table_cache) { +BLKDBG_EVENT (bs->file,BLKDBG_L2_UPDATE ); + } + ret =bdrv_pwrite (bs->file, c->entries[i].offset, c->entries[i].table, s->cluster_size);if (ret <0 ) {
@@ -218,6 +224,10 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c, c->entries[i].offset =0 ;if (read_from_disk) { +if (c == s->l2_table_cache) { +BLKDBG_EVENT (bs->file,BLKDBG_L2_LOAD ); + } + ret =bdrv_pread (bs->file, offset, c->entries[i].table, s->cluster_size);if (ret <0 ) {return ret;
block/qcow2-cluster.c +72 -136
362 lines not on this page · raw message
block/qcow2-refcount.c +107 -153
446 lines not on this page · raw message
block/qcow2.c +44 -4
84 lines not on this page · raw message
block/qcow2.h +7 -5
@@ -51,6 +51,9 @@#define L2_CACHE_SIZE 16 +/* Must be at least 4 to cover all cases of refcount table growth */ +#define REFCOUNT_CACHE_SIZE 4 + typedef struct QCowHeader { uint32_t magic; uint32_t version;
@@ -94,9 +97,10 @@ typedef struct BDRVQcowState {uint64_t cluster_offset_mask;uint64_t l1_table_offset;uint64_t *l1_table; -uint64_t *l2_cache; -uint64_t l2_cache_offsets[L2_CACHE_SIZE ]; -uint32_t l2_cache_counts[L2_CACHE_SIZE ]; + +Qcow2Cache * l2_table_cache; +Qcow2Cache * refcount_block_cache; +uint8_t *cluster_cache;uint8_t *cluster_data;uint64_t cluster_cache_offset;
@@ -105,8 +109,6 @@ typedef struct BDRVQcowState {uint64_t *refcount_table;uint64_t refcount_table_offset;uint32_t refcount_table_size; -uint64_t refcount_block_cache_offset; -uint16_t *refcount_block_cache;int64_t free_cluster_index;int64_t free_byte_offset;
Signature · 1 line
1.7.2.3
PATCH 12/23 ide: Remove unneeded null pointer check
In reply to Kevin WolfFrom: Stefan Weil <[email protected]>
With bm == NULL, other code in the same function would crash.
This bug was reported by cppcheck:hw/ide/pci.c:280: error: Possible null pointer dereference: bm
--- hw/ide/pci.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
hw/ide/pci.c +1 -3
@@ -267,9 +267,7 @@ static void bmdma_irq(void *opaque, int n, int level)return ; } -if (bm) { - bm->status |=BM_STATUS_INT ; - } + bm->status |=BM_STATUS_INT ;/* trigger the real irq */ qemu_set_irq (bm->irq, level);
Signature · 1 line
1.7.2.3
PATCH 13/23 Documentation: Add qemu-img check/rebase
In reply to Kevin Wolf--- qemu-img.texi | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-)
qemu-img.texi +41 -0
@@ -59,6 +59,13 @@ lists all snapshots in the given image Command description: @table @option +@item check [-f @var{fmt}] @var{filename} + +Perform a consistency check on the disk image @var{filename}. + +Only the formats @code{qcow2}, @code{qed} and @code{vdi} support +consistency checks. + @item create [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}] Create the new disk image @var{filename} of size @var{size} and format
@@ -107,6 +114,40 @@ they are displayed too. List, apply, create or delete snapshots in image @var{filename}. +@item rebase [-f @var{fmt}] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename} + +Changes the backing file of an image. Only the formats @code{qcow2} and +@code{qed} support changing the backing file. + +The backing file is changed to @var{backing_file} and (if the image format of +@var{filename} supports this) the backing file format is changed to +@var{backing_fmt}. + +There are two different modes in which @code{rebase} can operate: +@table @option +@item Safe mode +This is the default mode and performs a real rebase operation. The new backing +file may differ from the old one and qemu-img rebase will take care of keeping +the guest-visible content of @var{filename} unchanged. + +In order to achieve this, any clusters that differ between @var{backing_file} +and the old backing file of @var{filename} are merged into @var{filename} +before actually changing the backing file. + +Note that the safe mode is an expensive operation, comparable to converting +an image. It only works if the old backing file still exists. + +@item Unsafe mode +qemu-img uses the unsafe mode if @code{-u} is specified. In this mode, only the +backing file name and format of @var{filename} is changed without any checks +on the file contents. The user must take care of specifying the correct new +backing file, or the guest-visible content of the image will be corrupted. + +This mode is useful for renaming or moving the backing file to somewhere else. +It can be used without an accessible old backing file, i.e. you can use it to +fix an image whose backing file has already been moved/renamed. +@end table + @item resize @var{filename} [+ | -]@var{size} Change the disk image as if it had been created with @var{size}.
Signature · 1 line
1.7.2.3
PATCH 14/23 qed: Refuse to create images on block devices
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
QED relies on the underlying filesystem to extend the file and maintain its size. Check that images are not created on a block device.
--- block/qed.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
block/qed.c +6 -0
@@ -469,6 +469,12 @@ static int qed_create(const char *filename, uint32_t cluster_size,return ret; } +/* File must start empty and grow, check truncate is supported */ + ret =bdrv_truncate (bs,0 ); +if (ret <0 ) { + goto out; + } +if (backing_file) { header.features |=QED_F_BACKING_FILE ; header.backing_filename_offset =sizeof (le_header);
Signature · 1 line
1.7.2.3
PATCH 15/23 Fix block migration when the device size is not a multiple of 1 MB
In reply to Kevin WolfFrom: Pierre Riteau <[email protected]>
b02bea3a85cc939f09aa674a3f1e4f36d418c007 added a check on the return value of bdrv_write and aborts migration when it fails. However, if the size of the block device to migrate is not a multiple of BLOCK_SIZE (currently 1 MB), the last bdrv_write will fail with -EIO.
Fixed by calling bdrv_write with the correct size of the last block.
--- block-migration.c | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-)
block-migration.c +20 -2
@@ -638,8 +638,10 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)int len, flags;char device_name[256 ];int64_t addr; -BlockDriverState *bs; +BlockDriverState *bs, *bs_prev =NULL ;uint8_t *buf; +int64_t total_sectors =0 ; +int nr_sectors; do { addr = qemu_get_be64(f);
@@ -661,10 +663,26 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; } +if (bs != bs_prev) { + bs_prev = bs; + total_sectors =bdrv_getlength (bs) >>BDRV_SECTOR_BITS ; +if (total_sectors <=0 ) { +error_report ("Error getting length of block device %s\n" , + device_name); +return -EINVAL ; + } + } + +if (total_sectors - addr <BDRV_SECTORS_PER_DIRTY_CHUNK ) { + nr_sectors = total_sectors - addr; + }else { + nr_sectors =BDRV_SECTORS_PER_DIRTY_CHUNK ; + } + buf =qemu_malloc (BLOCK_SIZE );qemu_get_buffer (f, buf,BLOCK_SIZE ); - ret =bdrv_write (bs, addr, buf,BDRV_SECTORS_PER_DIRTY_CHUNK ); + ret =bdrv_write (bs, addr, buf, nr_sectors);qemu_free (buf);if (ret <0 ) {
Signature · 1 line
1.7.2.3
PATCH 16/23 blockdev: Fix error message for invalid -drive CHS
In reply to Kevin WolfFrom: Markus Armbruster <[email protected]>
When cyls, heads or secs are out of range, the error message prints buf, which points to the value of option "if". Bogus, may even be null. Drop that.
--- blockdev.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
blockdev.c +3 -3
@@ -224,15 +224,15 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)if (cyls || heads || secs) {if (cyls <1 || (type ==IF_IDE && cyls >16383 )) { -fprintf (stderr,"qemu: '%s' invalid physical cyls number\n" , buf); +fprintf (stderr,"qemu: invalid physical cyls number\n" );return NULL ; }if (heads <1 || (type ==IF_IDE && heads >16 )) { -fprintf (stderr,"qemu: '%s' invalid physical heads number\n" , buf); +fprintf (stderr,"qemu: invalid physical heads number\n" );return NULL ; }if (secs <1 || (type ==IF_IDE && secs >63 )) { -fprintf (stderr,"qemu: '%s' invalid physical secs number\n" , buf); +fprintf (stderr,"qemu: invalid physical secs number\n" );return NULL ; } }
Signature · 1 line
1.7.2.3
PATCH 17/23 blockdev: Make drive_init() use error_report()
In reply to Kevin WolfFrom: Markus Armbruster <[email protected]>
This makes the errors point to the error location, and fixes drive_add to report errors in the monitor instead of stderr.
While there, tweak a few error messages for consistency.
--- blockdev.c | 59 ++++++++++++++++++++++++++++------------------------------- 1 files changed, 28 insertions(+), 31 deletions(-)
blockdev.c +28 -31
@@ -107,7 +107,7 @@ DriveInfo *drive_get_by_blockdev(BlockDriverState *bs)static void bdrv_format_print (void *opaque,const char *name) { -fprintf (stderr," %s" , name); +error_printf (" %s" , name); }void drive_uninit (DriveInfo *dinfo)
@@ -129,8 +129,8 @@ static int parse_block_error_action(const char *buf, int is_read) }else if (!strcmp (buf,"report" )) {return BLOCK_ERR_REPORT ; }else { -fprintf (stderr,"qemu: '%s' invalid %s error action\n" , - buf, is_read ?"read" :"write" ); +error_report ("'%s' invalid %s error action" , + buf, is_read ?"read" :"write" );return -1 ; } }
@@ -217,31 +217,30 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) type =IF_NONE ; max_devs =0 ; }else { -fprintf (stderr,"qemu: unsupported bus type '%s'\n" , buf); +error_report ("unsupported bus type '%s'" , buf);return NULL ; } }if (cyls || heads || secs) {if (cyls <1 || (type ==IF_IDE && cyls >16383 )) { -fprintf (stderr,"qemu: invalid physical cyls number\n" ); +error_report ("invalid physical cyls number" );return NULL ; }if (heads <1 || (type ==IF_IDE && heads >16 )) { -fprintf (stderr,"qemu: invalid physical heads number\n" ); +error_report ("invalid physical heads number" );return NULL ; }if (secs <1 || (type ==IF_IDE && secs >63 )) { -fprintf (stderr,"qemu: invalid physical secs number\n" ); +error_report ("invalid physical secs number" );return NULL ; } }if ((buf =qemu_opt_get (opts,"trans" )) !=NULL ) {if (!cyls) { -fprintf (stderr, -"qemu: '%s' trans must be used with cyls,heads and secs\n" , - buf); +error_report ("'%s' trans must be used with cyls,heads and secs" , + buf);return NULL ; }if (!strcmp (buf,"none" ))
@@ -251,7 +250,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)else if (!strcmp (buf,"auto" )) translation =BIOS_ATA_TRANSLATION_AUTO ;else { -fprintf (stderr,"qemu: '%s' invalid translation type\n" , buf); +error_report ("'%s' invalid translation type" , buf);return NULL ; } }
@@ -261,13 +260,12 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) media =MEDIA_DISK ; }else if (!strcmp (buf,"cdrom" )) {if (cyls || secs || heads) { -fprintf (stderr, -"qemu: '%s' invalid physical CHS format\n" , buf); +error_report ("'%s' invalid physical CHS format" , buf);return NULL ; } media =MEDIA_CDROM ; }else { -fprintf (stderr,"qemu: '%s' invalid media\n" , buf); +error_report ("'%s' invalid media" , buf);return NULL ; } }
@@ -283,7 +281,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) }else if (!strcmp (buf,"writethrough" )) {/* this is the default */ }else { -fprintf (stderr,"qemu: invalid cache option\n" ); +error_report ("invalid cache option" );return NULL ; } }
@@ -295,7 +293,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) }else if (!strcmp (buf,"threads" )) {/* this is the default */ }else { -fprintf (stderr,"qemu: invalid aio option\n" ); +error_report ("invalid aio option" );return NULL ; } }
@@ -303,14 +301,14 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)if ((buf =qemu_opt_get (opts,"format" )) !=NULL ) {if (strcmp (buf,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported formats:" ); -bdrv_iterate_format (bdrv_format_print,NULL ); -fprintf (stderr,"\n" ); -return NULL ; +error_printf ("Supported formats:" ); +bdrv_iterate_format (bdrv_format_print,NULL ); +error_printf ("\n" ); +return NULL ; } drv =bdrv_find_whitelisted_format (buf);if (!drv) { -fprintf (stderr,"qemu: '%s' invalid format\n" , buf); +error_report ("'%s' invalid format" , buf);return NULL ; } }
@@ -318,7 +316,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) on_write_error =BLOCK_ERR_STOP_ENOSPC ;if ((buf =qemu_opt_get (opts,"werror" )) !=NULL ) {if (type !=IF_IDE && type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_NONE ) { -fprintf (stderr,"werror is not supported by this format\n" ); +error_report ("werror is not supported by this bus type" );return NULL ; }
@@ -331,7 +329,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) on_read_error =BLOCK_ERR_REPORT ;if ((buf =qemu_opt_get (opts,"rerror" )) !=NULL ) {if (type !=IF_IDE && type !=IF_VIRTIO && type !=IF_SCSI && type !=IF_NONE ) { -fprintf (stderr,"rerror is not supported by this format\n" ); +error_report ("rerror is not supported by this bus type" );return NULL ; }
@@ -343,7 +341,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)if ((devaddr =qemu_opt_get (opts,"addr" )) !=NULL ) {if (type !=IF_VIRTIO ) { -fprintf (stderr,"addr is not supported\n" ); +error_report ("addr is not supported by this bus type" );return NULL ; } }
@@ -352,8 +350,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)if (index !=-1 ) {if (bus_id !=0 || unit_id !=-1 ) { -fprintf (stderr, -"qemu: index cannot be used with bus and unit\n" ); +error_report ("index cannot be used with bus and unit" );return NULL ; }if (max_devs ==0 )
@@ -384,8 +381,8 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)/* check unit id */ if (max_devs && unit_id >= max_devs) { -fprintf (stderr,"qemu: unit %d too big (max is %d)\n" , - unit_id, max_devs -1 ); +error_report ("unit %d too big (max is %d)" , + unit_id, max_devs -1 );return NULL ; }
@@ -479,7 +476,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) ro =1 ; }else if (ro ==1 ) {if (type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_FLOPPY && type !=IF_NONE ) { -fprintf (stderr,"qemu: readonly flag not supported for drive with this interface\n" ); +error_report ("readonly not supported by this bus type" );return NULL ; } }
@@ -488,8 +485,8 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) ret =bdrv_open (dinfo->bdrv, file, bdrv_flags, drv);if (ret <0 ) { -fprintf (stderr,"qemu: could not open disk image %s: %s\n" , - file,strerror (-ret)); +error_report ("could not open disk image %s: %s" , + file,strerror (-ret));return NULL ; }
Signature · 1 line
1.7.2.3
PATCH 18/23 blockdev: Fix drive_del not to crash when drive is not in use
In reply to Kevin WolfFrom: Markus Armbruster <[email protected]>
Watch this:
(qemu) drive_add 0 if=none,file=tmp.img
OK
(qemu) info block
none0: type=hd removable=0 file=tmp.img ro=0 drv=raw encrypted=0 (qemu) drive_del none0
Segmentation fault (core dumped)
do_drive_del()'s code to clean up the pointer from a qdev using the drive back to the drive needs to check whether such a device exists.
--- blockdev.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
blockdev.c +9 -7
@@ -687,13 +687,15 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)/* clean up guest state from pointing to host resource by * finding and removing DeviceState "drive" property */ -for (prop = bs->peer->info->props; prop && prop->name; prop++) { -if (prop->info->type ==PROP_TYPE_DRIVE ) { - ptr =qdev_get_prop_ptr (bs->peer, prop); -if ((*ptr) == bs) { -bdrv_detach (bs, bs->peer); - *ptr =NULL ; -break ; +if (bs->peer) { +for (prop = bs->peer->info->props; prop && prop->name; prop++) { +if (prop->info->type ==PROP_TYPE_DRIVE ) { + ptr =qdev_get_prop_ptr (bs->peer, prop); +if (*ptr == bs) { +bdrv_detach (bs, bs->peer); + *ptr =NULL ; +break ; + } } } }
Signature · 1 line
1.7.2.3
PATCH 19/23 block: Use backing format driver during image creation
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
The backing format should be honored during image creation. For some reason we currently use the image format to open the backing file. This fails when the backing file has a different format than the image being created. Keep the image and backing format drivers completely separate.
Also print the backing filename if there is an error opening the backing file instead of the image filename.
--- block.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
block.c +5 -3
@@ -2778,6 +2778,7 @@ int bdrv_img_create(const char *filename, const char *fmt,QEMUOptionParameter *backing_fmt, *backing_file;BlockDriverState *bs =NULL ;BlockDriver *drv, *proto_drv; +BlockDriver *backing_drv =NULL ;int ret =0 ;/* Find driver and parse its options */
@@ -2846,7 +2847,8 @@ int bdrv_img_create(const char *filename, const char *fmt, backing_fmt =get_option_parameter (param,BLOCK_OPT_BACKING_FMT );if (backing_fmt && backing_fmt->value.s) { -if (!bdrv_find_format (backing_fmt->value.s)) { + backing_drv =bdrv_find_format (backing_fmt->value.s); +if (!backing_drv) {error_report ("Unknown backing file format '%s'" , backing_fmt->value.s); ret = -EINVAL ;
@@ -2863,9 +2865,9 @@ int bdrv_img_create(const char *filename, const char *fmt, bs =bdrv_new ("" ); - ret =bdrv_open (bs, backing_file->value.s, flags, drv); + ret =bdrv_open (bs, backing_file->value.s, flags, backing_drv);if (ret <0 ) { -error_report ("Could not open '%s'" , filename); +error_report ("Could not open '%s'" , backing_file->value.s); goto out; }bdrv_get_geometry (bs, &size);
Signature · 1 line
1.7.2.3
PATCH 22/23 usb-msd: Propagate removable bit to SCSI device
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
USB Mass Storage Devices sometimes have the RMB (removable) bit set in the SCSI INQUIRY response. Thumbdrives tend to have the bit set whereas hard disks do not.
Operating systems differentiate between removable devices and fixed devices. Under Linux, the anaconda installer looks for removable devices. Under Windows, only fixed devices may have more than one partition and AutoRun is also affected by the removable bit.
For these reasons, allow USB Mass Storage Devices to override the removable bit:
qemu -usb
-drive if=none,file=test.img,cache=none,id=disk0 -device usb-storage,drive=disk0,removable=on
The default is off.
--- hw/usb-msd.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
hw/usb-msd.c +3 -1
@@ -51,6 +51,7 @@ typedef struct {SCSIBus bus;BlockConf conf;SCSIDevice *scsi_dev; +uint32_t removable;int result;/* For async completion. */ USBPacket *packet;
@@ -515,7 +516,7 @@ static int usb_msd_initfn(USBDevice *dev)usb_desc_init (dev);scsi_bus_new (&s->bus, &s->dev.qdev,0 ,1 , usb_msd_command_complete); - s->scsi_dev =scsi_bus_legacy_add_drive (&s->bus, bs,0 , false); + s->scsi_dev =scsi_bus_legacy_add_drive (&s->bus, bs,0 , !!s->removable);if (!s->scsi_dev) {return -1 ; }
@@ -607,6 +608,7 @@ static struct USBDeviceInfo msd_info = { .usbdevice_init = usb_msd_init, .qdev.props = (Property []) {DEFINE_BLOCK_PROPERTIES (MSDState, conf), +DEFINE_PROP_BIT ("removable" , MSDState, removable,0 , false),DEFINE_PROP_END_OF_LIST (), }, };
Signature · 1 line
1.7.2.3
PATCH 20/23 scsi-disk: Allow overriding SCSI INQUIRY removable bit
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
Provide the "removable" qdev property bit to override the SCSI INQUIRY removable (RMB) bit for non-CDROM devices. This will be used by USB Mass Storage Devices, which sometimes have this guest-visible bit set and sometimes do not. They therefore requires a means for user configuration.
--- hw/scsi-disk.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
hw/scsi-disk.c +3 -0
@@ -72,6 +72,7 @@ struct SCSIDiskState/* The qemu block layer uses a fixed 512 byte sector size. This is the number of 512 byte blocks in a single scsi sector. */ int cluster_size; +uint32_t removable;uint64_t max_lba;QEMUBH *bh;char *version;
@@ -552,6 +553,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)memcpy (&outbuf[16 ],"QEMU CD-ROM " ,16 ); }else { outbuf[0 ] =0 ; + outbuf[1 ] = s->removable ?0x80 :0 ;memcpy (&outbuf[16 ],"QEMU HARDDISK " ,16 ); }memcpy (&outbuf[8 ],"QEMU " ,8 );
@@ -1295,6 +1297,7 @@ static SCSIDeviceInfo scsi_disk_info = { DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf), DEFINE_PROP_STRING("ver", SCSIDiskState, version), DEFINE_PROP_STRING("serial", SCSIDiskState, serial), + DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false), DEFINE_PROP_END_OF_LIST(), }, };
Signature · 1 line
1.7.2.3
PATCH 23/23 docs: Document scsi-disk and usb-storage removable parameter
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
--- docs/qdev-device-use.txt | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-)
docs/qdev-device-use.txt +11 -2
@@ -80,7 +80,11 @@ The -device argument differs in detail for each kind of drive: This SCSI controller a single SCSI bus, named ID.0. Put a disk on it: - -device scsi-disk,drive=DRIVE-ID,bus=ID.0,scsi-id=SCSI-ID + -device scsi-disk,drive=DRIVE-ID,bus=ID.0,scsi-id=SCSI-ID,removable=RMB + + The (optional) removable parameter lets you override the SCSI INQUIRY + removable (RMB) bit for non CD-ROM devices. It is ignored for CD-ROM devices + which are always removable. RMB is "on" or "off". * if=floppy
@@ -116,7 +120,12 @@ For USB devices, the old way is actually different: Provides much less control than -drive's HOST-OPTS... The new way fixes that: - -device usb-storage,drive=DRIVE-ID + -device usb-storage,drive=DRIVE-ID,removable=RMB + +The removable parameter gives control over the SCSI INQUIRY removable (RMB) +bit. USB thumbdrives usually set removable=on, while USB hard disks set +removable=off. See the if=scsi description above for details on the removable +parameter, which applies only to scsi-disk devices and not to scsi-generic. === Character Devices ===
Signature · 1 line
1.7.2.3
PATCH 21/23 scsi: Allow scsi_bus_legacy_add_drive() to set removable bit
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
scsi-disk devices may wish to override the removable bit. Add support for a qdev property on SCSI devices. This is will be used by usb-msd.
--- hw/pci-hotplug.c | 2 +- hw/scsi-bus.c | 8 ++++++-- hw/scsi.h | 3 ++- hw/usb-msd.c | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-)
hw/pci-hotplug.c +1 -1
@@ -90,7 +90,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,* specified). */ dinfo->unit =qemu_opt_get_number (dinfo->opts,"unit" ,-1 ); - scsidev =scsi_bus_legacy_add_drive (scsibus, dinfo->bdrv, dinfo->unit); + scsidev =scsi_bus_legacy_add_drive (scsibus, dinfo->bdrv, dinfo->unit, false);if (!scsidev) {return -1 ; }
hw/scsi-bus.c +6 -2
@@ -87,7 +87,8 @@ void scsi_qdev_register(SCSIDeviceInfo *info) }/* handle legacy '-drive if=scsi,...' cmd line args */ -SCSIDevice *scsi_bus_legacy_add_drive (SCSIBus *bus,BlockDriverState *bdrv,int unit) +SCSIDevice *scsi_bus_legacy_add_drive (SCSIBus *bus,BlockDriverState *bdrv, +int unit,bool removable) {const char *driver;DeviceState *dev;
@@ -95,6 +96,9 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int driver =bdrv_is_sg (bdrv) ?"scsi-generic" :"scsi-disk" ; dev =qdev_create (&bus->qbus, driver);qdev_prop_set_uint32 (dev,"scsi-id" , unit); +if (qdev_prop_exists (dev,"removable" )) { +qdev_prop_set_bit (dev,"removable" , removable); + }if (qdev_prop_set_drive (dev,"drive" , bdrv) <0 ) {qdev_free (dev);return NULL ;
@@ -117,7 +121,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)continue ; }qemu_opts_loc_restore (dinfo->opts); -if (!scsi_bus_legacy_add_drive (bus, dinfo->bdrv, unit)) { +if (!scsi_bus_legacy_add_drive (bus, dinfo->bdrv, unit, false)) { res =-1 ;break ; }
hw/scsi.h +2 -1
@@ -94,7 +94,8 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)return DO_UPCAST (SCSIBus, qbus, d->qdev.parent_bus); } -SCSIDevice *scsi_bus_legacy_add_drive (SCSIBus *bus,BlockDriverState *bdrv,int unit); +SCSIDevice *scsi_bus_legacy_add_drive (SCSIBus *bus,BlockDriverState *bdrv, +int unit,bool removable);int scsi_bus_legacy_handle_cmdline (SCSIBus *bus);SCSIRequest *scsi_req_alloc (size_t size,SCSIDevice *d,uint32_t tag,uint32_t lun);
hw/usb-msd.c +1 -1
@@ -515,7 +515,7 @@ static int usb_msd_initfn(USBDevice *dev)usb_desc_init (dev);scsi_bus_new (&s->bus, &s->dev.qdev,0 ,1 , usb_msd_command_complete); - s->scsi_dev =scsi_bus_legacy_add_drive (&s->bus, bs,0 ); + s->scsi_dev =scsi_bus_legacy_add_drive (&s->bus, bs,0 , false);if (!s->scsi_dev) {return -1 ; }
Signature · 1 line
1.7.2.3
Quoted 7 lines · Kevin Wolf
The following changes since commit
0bfe006c5380c5f8a485a55ded3329fbbc224396:multiboot: Fix upper memory size in multiboot info (2011-01-23 22:44:13 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.gitfor-anthony
Pulled. Thanks.
Regards,
Anthony Liguori
Quoted 67 lines
Aurelien Jarno (1):
qcow2: fix unaligned accessChristoph Hellwig (3):
ide: factor dma handling helpers
ide: also resetio_buffer_indexfor writes
ide: killide_dma_submit_checkJes Sorensen (2):
do_snapshot_blkdev()error on missingsnapshot_fileargument Makestrtosz()returnint64_tinstead ofssize_tKevin Wolf (5):
qemu-img snapshot: Use writeback caching
qcow2: Add QcowCache
qcow2: Use QcowCache
qcow2: Batch flushes for COW
Documentation: Add qemu-img check/rebaseMarkus Armbruster (3):
blockdev: Fix error message for invalid -drive CHS
blockdev: Makedrive_init()useerror_report()
blockdev: Fixdrive_delnot to crash when drive is not in usePierre Riteau (2):
Avoid divide by zero when there is no block device to migrate Fix block migration when the device size is not a multiple of 1 MBStefan Hajnoczi (6):
qed: Refuse to create images on block devices
block: Use backing format driver during image creation
scsi-disk: Allow overriding SCSI INQUIRY removable bit
scsi: Allowscsi_bus_legacy_add_drive()to set removable bit
usb-msd: Propagate removable bit to SCSI device
docs: Document scsi-disk and usb-storage removable parameterStefan Weil (1):
ide: Remove unneeded null pointer checkMakefile.objs | 2 +- block-migration.c | 29 ++++- block.c | 8 +- block/qcow2-cache.c | 314 ++++++++++++++++++++++++++++++++++++++++++++++ block/qcow2-cluster.c | 210 +++++++++++-------------------- block/qcow2-refcount.c | 260 ++++++++++++++++---------------------- block/qcow2.c | 48 +++++++- block/qcow2.h | 32 ++++- block/qed.c | 6 + blockdev.c | 81 +++++++------ cutils.c | 8 +- docs/qdev-device-use.txt | 13 ++- hw/ide/core.c | 113 ++++++----------- hw/ide/internal.h | 4 +- hw/ide/pci.c | 13 +-- hw/pci-hotplug.c | 2 +- hw/scsi-bus.c | 8 +- hw/scsi-disk.c | 3 + hw/scsi.h | 3 +- hw/usb-msd.c | 4 +- monitor.c | 2 +- qemu-common.h | 4 +- qemu-img.c | 4 +- qemu-img.texi | 41 ++++++ vl.c | 4 +- 25 files changed, 764 insertions(+), 452 deletions(-)create mode 100644
block/qcow2-cache.c