Block patches
Subsystems (2)
The following changes since commit 9d861fa595c93f22d1d55b723a691531c36c9672:
Merge remote branch 'arm/for-anthony' into staging (2010-12-17 08:25:17 -0600)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.git for-anthony
Alexander Graf (10):
ide: split ide command interpretation off
ide: fix whitespace gap in ide_exec_cmd
ide: Split out BMDMA code from ATA core
ide: move transfer_start after variable modification
pci: add storage class for sata
pci: add ich9 pci id
ahci: add ahci emulation
config: move ide core and pci to pci.mak
config: add ahci for pci capable machines
ide: honor ncq for atapi
Christoph Hellwig (3):
block: add discard support
scsi-disk: support WRITE SAME (16) with unmap bit
raw-posix: add discard support
Jes Sorensen (9):
Introduce strtosz_suffix()
qemu-img.c: Clean up handling of image size in img_create() qemu-img.c: Re-factor img_create()
Introduce do_snapshot_blkdev() and monitor command to handle it. Prevent creating an image with the same filename as backing file bdrv_img_create() use proper errno return values qemu.img.c: Use error_report() instead of own error() implementation block/qcow2.c: rename qcow_ functions to qcow2_
Add proper -errno error return values to qcow2_open()
Kevin Wolf (3):
qemu-img: Call error_set_progname Remove NULL checks for bdrv_new return value
qemu-io: Fix typo in help texts
Roland Elek (1):
ide: add ncq identify data for ahci sata drives
Ryan Harper (1):
blockdev: check dinfo ptr before using
Sebastian Herbszt (1):
ahci: set SATA Mode Select
Stefan Hajnoczi (10):
block: Introduce path_has_protocol() function
block: Fix the use of protocols in backing files
ide: Register vm change state handler once only
qemu-io: Add discard command
docs: Add QED image format specification
qed: Add QEMU Enhanced Disk image format
qed: Table, L2 cache, and cluster functions
qed: Read/write support
qed: Consistency check support
docs: Fix missing carets in QED specification
Makefile.objs | 3 + block.c | 234 +++++- block.h | 5 + block/qcow2-cluster.c | 6 +- block/qcow2-snapshot.c | 6 +- block/qcow2.c | 248 +++--- block/qed-check.c | 210 +++++ block/qed-cluster.c | 154 ++++ block/qed-gencb.c | 32 + block/qed-l2-cache.c | 173 ++++ block/qed-table.c | 319 +++++++ block/qed.c | 1349 ++++++++++++++++++++++++++++++ block/qed.h | 301 +++++++ block/raw-posix.c | 45 + block/raw.c | 6 + block_int.h | 8 +- blockdev.c | 68 ++- blockdev.h | 1 + configure | 26 + cutils.c | 17 +- default-configs/arm-softmmu.mak | 1 - default-configs/i386-softmmu.mak | 3 - default-configs/mips-softmmu.mak | 3 - default-configs/mips64-softmmu.mak | 3 - default-configs/mips64el-softmmu.mak | 3 - default-configs/mipsel-softmmu.mak | 3 - default-configs/pci.mak | 4 + default-configs/ppc-softmmu.mak | 3 - default-configs/ppc64-softmmu.mak | 3 - default-configs/ppcemb-softmmu.mak | 3 - default-configs/sh4-softmmu.mak | 1 - default-configs/sh4eb-softmmu.mak | 1 - default-configs/sparc64-softmmu.mak | 3 - default-configs/x86_64-softmmu.mak | 3 - docs/specs/qed_spec.txt | 130 +++ hmp-commands.hx | 19 + hw/ide/ahci.c | 1527 ++++++++++++++++++++++++++++++++++ hw/ide/cmd646.c | 18 +- hw/ide/core.c | 1116 +++++++++++-------------- hw/ide/internal.h | 73 +- hw/ide/pci.c | 280 ++++++- hw/ide/pci.h | 30 + hw/ide/piix.c | 34 +- hw/ide/via.c | 34 +- hw/pci.h | 1 + hw/pci_ids.h | 1 + hw/scsi-defs.h | 1 + hw/scsi-disk.c | 53 ++- hw/xen_disk.c | 17 +- qemu-common.h | 7 + qemu-img.c | 250 ++---- qemu-io.c | 102 +++- qemu-nbd.c | 2 - trace-events | 21 + 54 files changed, 5892 insertions(+), 1072 deletions(-) create mode 100644 block/qed-check.c create mode 100644 block/qed-cluster.c create mode 100644 block/qed-gencb.c create mode 100644 block/qed-l2-cache.c create mode 100644 block/qed-table.c create mode 100644 block/qed.c create mode 100644 block/qed.h create mode 100644 docs/specs/qed_spec.txt create mode 100644 hw/ide/ahci.c
PATCH 1/38 blockdev: check dinfo ptr before using
From: Ryan Harper <[email protected]>
If a user decides to punish a guest by revoking its block device via drive_del, and subsequently also attempts to remove the pci device backing it, and the device is using blockdev_auto_del() then we get a segfault when we attempt to access dinfo->auto_del.[1]
The fix is to check if drive_get_by_blockdev() actually returns a valid dinfo pointer or not.
1. (qemu) pci_add auto storage file=images/test01.raw,if=virtio,id=block1,snapshot=on (qemu) drive_del block1
(qemu) pci_del 5
*segfault*
--- blockdev.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
blockdev.c +4 -2
@@ -30,14 +30,16 @@ void blockdev_mark_auto_del(BlockDriverState *bs) {DriveInfo *dinfo =drive_get_by_blockdev (bs); - dinfo->auto_del =1 ; +if (dinfo) { + dinfo->auto_del =1 ; + } }void blockdev_auto_del (BlockDriverState *bs) {DriveInfo *dinfo =drive_get_by_blockdev (bs); -if (dinfo->auto_del) { +if (dinfo && dinfo->auto_del) {drive_uninit (dinfo); } }
Signature · 1 line
1.7.2.3
PATCH 2/38 block: Introduce path_has_protocol() function
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
The bdrv_find_protocol() function returns NULL if an unknown protocol name is given. It returns the "file" protocol when the filename contains no protocol at all. This makes it difficult to distinguish between paths which contain a protocol and those which do not.
Factor out a helper function that tests whether or not a filename has a protocol. The next patch makes use of this function.
--- block.c | 64 +++++++++++++++++++++++++++++++++++--------------------------- 1 files changed, 36 insertions(+), 28 deletions(-)
block.c +36 -28
@@ -70,6 +70,39 @@ static BlockDriverState *bs_snapshots;/* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; +#ifdef _WIN32 +static int is_windows_drive_prefix (const char *filename) +{ +return (((filename[0 ] >='a' && filename[0 ] <='z' ) || + (filename[0 ] >='A' && filename[0 ] <='Z' )) && + filename[1 ] ==':' ); +} + +int is_windows_drive (const char *filename) +{ +if (is_windows_drive_prefix (filename) && + filename[2 ] =='\0' ) +return 1 ; +if (strstart (filename,"\\\\.\\" ,NULL ) || +strstart (filename,"//./" ,NULL )) +return 1 ; +return 0 ; +} +#endif + +/* check if the path starts with "<protocol>:" */ +static int path_has_protocol (const char *path) +{ +#ifdef _WIN32 +if (is_windows_drive (path) || +is_windows_drive_prefix (path)) { +return 0 ; + } +#endif + +return strchr (path,':' ) !=NULL ; +} +int path_is_absolute (const char *path) {const char *p;
@@ -244,26 +277,6 @@ void get_tmp_filename(char *filename, int size) }#endif -#ifdef _WIN32 -static int is_windows_drive_prefix (const char *filename) -{ -return (((filename[0 ] >='a' && filename[0 ] <='z' ) || - (filename[0 ] >='A' && filename[0 ] <='Z' )) && - filename[1 ] ==':' ); -} - -int is_windows_drive (const char *filename) -{ -if (is_windows_drive_prefix (filename) && - filename[2 ] =='\0' ) -return 1 ; -if (strstart (filename,"\\\\.\\" ,NULL ) || -strstart (filename,"//./" ,NULL )) -return 1 ; -return 0 ; -} -#endif -/* * Detect host devices. By convention, /dev/cdrom[N] is always * recognized as a host CDROM.
@@ -307,16 +320,11 @@ BlockDriver *bdrv_find_protocol(const char *filename)return drv1; } -#ifdef _WIN32 -if (is_windows_drive (filename) || -is_windows_drive_prefix (filename)) -return bdrv_find_format ("file" ); -#endif - - p =strchr (filename,':' ); -if (!p) { +if (!path_has_protocol (filename)) {return bdrv_find_format ("file" ); } + p =strchr (filename,':' ); +assert (p !=NULL ); len = p - filename;if (len >sizeof (protocol) -1 ) len =sizeof (protocol) -1 ;
Signature · 1 line
1.7.2.3
PATCH 3/38 block: Fix the use of protocols in backing files
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
Backing filenames may contain a protocol. The code currently doesn't consider this case and produces filenames that embed "<protocol>:". Don't combine filenames if the backing filename contains a protocol.
Based on an earlier patch by Anthony Liguori <[email protected]>.
--- block.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-)
block.c +11 -3
@@ -611,10 +611,18 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int 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' ) + +if (path_has_protocol (bs->backing_file)) { +pstrcpy (backing_filename,sizeof (backing_filename), + bs->backing_file); + }else { +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 =
Signature · 1 line
1.7.2.3
PATCH 4/38 Introduce strtosz_suffix()
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
This introduces strtosz_suffix() which allows the caller to specify a default suffix in case the non default of MB is wanted.
strtosz() is kept as a wrapper for strtosz_suffix() which keeps it's current default of MB.
--- cutils.c | 17 ++++++++++++++--- qemu-common.h | 7 +++++++ 2 files changed, 21 insertions(+), 3 deletions(-)
cutils.c +14 -3
@@ -291,10 +291,10 @@ int fcntl_setfl(int fd, int flag)* value must be terminated by whitespace, ',' or '\0'. Return -1 on * error. */ -ssize_t strtosz (const char *nptr,char **end) +ssize_t strtosz_suffix (const char *nptr,char **end,const char default_suffix) {ssize_t retval =-1 ; -char *endptr, c; +char *endptr, c, d;int mul_required =0 ;double val, mul, integral, fraction;
@@ -313,10 +313,16 @@ ssize_t strtosz(const char *nptr, char **end)* part of a multi token argument. */ c = *endptr; + d = c;if (isspace (c) || c =='\0' || c ==',' ) { c =0 ; +if (default_suffix) { + d = default_suffix; + }else { + d = c; + } } -switch (c) { +switch (d) {case 'B' :case 'b' : mul =1 ;
@@ -371,3 +377,8 @@ fail:return retval; } + +ssize_t strtosz (const char *nptr,char **end) +{ +return strtosz_suffix (nptr, end,STRTOSZ_DEFSUFFIX_MB ); +}
qemu-common.h +7 -0
@@ -149,7 +149,14 @@ time_t mktimegm(struct tm *tm);int qemu_fls (int i);int qemu_fdatasync (int fd);int fcntl_setfl (int fd,int flag); + +#define STRTOSZ_DEFSUFFIX_TB 'T' +#define STRTOSZ_DEFSUFFIX_GB 'G' +#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);/* path.c */ void init_paths (const char *prefix);
Signature · 1 line
1.7.2.3
PATCH 5/38 qemu-img.c: Clean up handling of image size in img_create()
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
This cleans up the handling of image size in img_create() by parsing the value early, and then only setting it once if a value has been added as the last argument to the command line.
--- qemu-img.c | 23 +++++++++++++++++------ 1 files changed, 17 insertions(+), 6 deletions(-)
qemu-img.c +17 -6
@@ -282,6 +282,7 @@ static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,static int img_create (int argc,char **argv) {int c, ret =0 ; +uint64_t img_size =-1 ;const char *fmt ="raw" ;const char *base_fmt =NULL ;const char *filename;
@@ -330,6 +331,20 @@ static int img_create(int argc, char **argv) } filename = argv[optind++]; +/* Get image size, if specified */ +if (optind < argc) { +ssize_t sval; + sval =strtosz_suffix (argv[optind++],NULL ,STRTOSZ_DEFSUFFIX_B ); +if (sval <0 ) { +error ("Invalid image size specified! You may use k, M, G or " +"T suffixes for " ); +error ("kilobytes, megabytes, gigabytes and terabytes." ); + ret =-1 ; + goto out; + } + img_size = (uint64_t )sval; + } +if (options && !strcmp (options,"?" )) { ret =print_block_option_help (filename, fmt); goto out;
@@ -357,7 +372,8 @@ static int img_create(int argc, char **argv)/* Create parameter list with default values */ param =parse_option_parameters ("" , create_options, param); -set_option_parameter_int (param,BLOCK_OPT_SIZE ,-1 ); + +set_option_parameter_int (param,BLOCK_OPT_SIZE , img_size);/* Parse -o options */ if (options) {
@@ -369,11 +385,6 @@ static int img_create(int argc, char **argv) } } -/* Add size to parameters */ -if (optind < argc) { -set_option_parameter (param,BLOCK_OPT_SIZE , argv[optind++]); - } -/* Add old-style options to parameters */ ret =add_old_style_options (fmt, param, base_filename, base_fmt);if (ret <0 ) {
Signature · 1 line
1.7.2.3
PATCH 6/38 ide: split ide command interpretation off
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
The ATA command interpretation code can be used for PATA and SATA interfaces alike. So let's split it out into a separate function.
--- hw/ide/core.c | 20 ++++++++++++++------ hw/ide/internal.h | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-)
hw/ide/core.c +14 -6
@@ -1791,9 +1791,6 @@ static void ide_clear_hob(IDEBus *bus)void ide_ioport_write (void *opaque,uint32_t addr,uint32_t val) {IDEBus *bus = opaque; -IDEState *s; -int n; -int lba48 =0 ;#ifdef DEBUG_IDE printf ("IDE: write addr=0x%x val=0x%02x\n" , addr, val);
@@ -1854,17 +1851,29 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)default :case 7 :/* command */ +ide_exec_cmd (bus, val); +break ; + } +} + + +void ide_exec_cmd (IDEBus *bus,uint32_t val) +{ +IDEState *s; +int n; +int lba48 =0 ; +#if defined(DEBUG_IDE )printf ("ide: CMD=%02x\n" , val);#endif s =idebus_active_if (bus);/* ignore commands to non existant slave */ if (s != bus->ifs && !s->bs) -break ; +return ;/* Only DEVICE RESET is allowed while BSY or/and DRQ are set */ if ((s->status & (BUSY_STAT |DRQ_STAT )) && val !=WIN_DEVICE_RESET ) -break ; +return ;switch (val) {case WIN_IDENTIFY :
@@ -2355,7 +2364,6 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)ide_set_irq (s->bus);break ; } - } }uint32_t ide_ioport_read (void *opaque,uint32_t addr1)
hw/ide/internal.h +2 -0
@@ -567,6 +567,8 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1, qemu_irq irq);void ide_init_ioport (IDEBus *bus,int iobase,int iobase2); +void ide_exec_cmd (IDEBus *bus,uint32_t val); +/* hw/ide/qdev.c */ void ide_bus_new (IDEBus *idebus,DeviceState *dev,int bus_id);IDEDevice *ide_create_drive (IDEBus *bus,int unit,DriveInfo *drive);
Signature · 1 line
1.7.2.3
PATCH 7/38 ide: fix whitespace gap in ide_exec_cmd
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
Now that we have the function split out, we have to reindent it. In order to increase the readability of the actual functional change, this is split out.
--- hw/ide/core.c | 734 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 367 insertions(+), 367 deletions(-)
hw/ide/core.c +367 -367
@@ -1864,423 +1864,423 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)int lba48 =0 ;#if defined(DEBUG_IDE ) -printf ("ide: CMD=%02x\n" , val); +printf ("ide: CMD=%02x\n" , val);#endif - s =idebus_active_if (bus); -/* ignore commands to non existant slave */ -if (s != bus->ifs && !s->bs) -return ; + s =idebus_active_if (bus); +/* ignore commands to non existant slave */ +if (s != bus->ifs && !s->bs) +return ; -/* Only DEVICE RESET is allowed while BSY or/and DRQ are set */ -if ((s->status & (BUSY_STAT |DRQ_STAT )) && val !=WIN_DEVICE_RESET ) -return ; +/* Only DEVICE RESET is allowed while BSY or/and DRQ are set */ +if ((s->status & (BUSY_STAT |DRQ_STAT )) && val !=WIN_DEVICE_RESET ) +return ; -switch (val) { -case WIN_IDENTIFY : -if (s->bs && s->drive_kind !=IDE_CD ) { -if (s->drive_kind !=IDE_CFATA ) -ide_identify (s); -else -ide_cfata_identify (s); - s->status =READY_STAT |SEEK_STAT ; -ide_transfer_start (s, s->io_buffer,512 , ide_transfer_stop); - }else { -if (s->drive_kind ==IDE_CD ) { -ide_set_signature (s); - } -ide_abort_command (s); - } -ide_set_irq (s->bus); -break ; -case WIN_SPECIFY : -case WIN_RECAL : - s->error =0 ; +switch (val) { +case WIN_IDENTIFY : +if (s->bs && s->drive_kind !=IDE_CD ) { +if (s->drive_kind !=IDE_CFATA ) +ide_identify (s); +else +ide_cfata_identify (s); s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; -case WIN_SETMULT : -if (s->drive_kind ==IDE_CFATA && s->nsector ==0 ) { -/* Disable Read and Write Multiple */ - s->mult_sectors =0 ; - s->status =READY_STAT |SEEK_STAT ; - }else if ((s->nsector &0xff ) !=0 && - ((s->nsector &0xff ) >MAX_MULT_SECTORS || - (s->nsector & (s->nsector -1 )) !=0 )) { -ide_abort_command (s); - }else { - s->mult_sectors = s->nsector &0xff ; - s->status =READY_STAT |SEEK_STAT ; +ide_transfer_start (s, s->io_buffer,512 , ide_transfer_stop); + }else { +if (s->drive_kind ==IDE_CD ) { +ide_set_signature (s); } -ide_set_irq (s->bus); -break ; -case WIN_VERIFY_EXT : - lba48 =1 ; -case WIN_VERIFY : -case WIN_VERIFY_ONCE : -/* do sector number check ? */ -ide_cmd_lba48_transform (s, lba48); +ide_abort_command (s); + } +ide_set_irq (s->bus); +break ; +case WIN_SPECIFY : +case WIN_RECAL : + s->error =0 ; + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case WIN_SETMULT : +if (s->drive_kind ==IDE_CFATA && s->nsector ==0 ) { +/* Disable Read and Write Multiple */ + s->mult_sectors =0 ; s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; + }else if ((s->nsector &0xff ) !=0 && + ((s->nsector &0xff ) >MAX_MULT_SECTORS || + (s->nsector & (s->nsector -1 )) !=0 )) { +ide_abort_command (s); + }else { + s->mult_sectors = s->nsector &0xff ; + s->status =READY_STAT |SEEK_STAT ; + } +ide_set_irq (s->bus); +break ; +case WIN_VERIFY_EXT : + lba48 =1 ; +case WIN_VERIFY : +case WIN_VERIFY_ONCE : +/* do sector number check ? */ +ide_cmd_lba48_transform (s, lba48); + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ;case WIN_READ_EXT : - lba48 =1 ; -case WIN_READ : -case WIN_READ_ONCE : -if (!s->bs) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); - s->req_nb_sectors =1 ; -ide_sector_read (s); -break ; + lba48 =1 ; +case WIN_READ : +case WIN_READ_ONCE : +if (!s->bs) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); + s->req_nb_sectors =1 ; +ide_sector_read (s); +break ;case WIN_WRITE_EXT : - lba48 =1 ; -case WIN_WRITE : -case WIN_WRITE_ONCE : -case CFA_WRITE_SECT_WO_ERASE : -case WIN_WRITE_VERIFY : -ide_cmd_lba48_transform (s, lba48); - s->error =0 ; - s->status =SEEK_STAT |READY_STAT ; - s->req_nb_sectors =1 ; -ide_transfer_start (s, s->io_buffer,512 , ide_sector_write); - s->media_changed =1 ; -break ; + lba48 =1 ; +case WIN_WRITE : +case WIN_WRITE_ONCE : +case CFA_WRITE_SECT_WO_ERASE : +case WIN_WRITE_VERIFY : +ide_cmd_lba48_transform (s, lba48); + s->error =0 ; + s->status =SEEK_STAT |READY_STAT ; + s->req_nb_sectors =1 ; +ide_transfer_start (s, s->io_buffer,512 , ide_sector_write); + s->media_changed =1 ; +break ;case WIN_MULTREAD_EXT : - lba48 =1 ; -case WIN_MULTREAD : -if (!s->mult_sectors) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); - s->req_nb_sectors = s->mult_sectors; -ide_sector_read (s); -break ; -case WIN_MULTWRITE_EXT : - lba48 =1 ; -case WIN_MULTWRITE : -case CFA_WRITE_MULTI_WO_ERASE : -if (!s->mult_sectors) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); - s->error =0 ; - s->status =SEEK_STAT |READY_STAT ; - s->req_nb_sectors = s->mult_sectors; - n = s->nsector; -if (n > s->req_nb_sectors) - n = s->req_nb_sectors; -ide_transfer_start (s, s->io_buffer,512 * n, ide_sector_write); - s->media_changed =1 ; -break ; + lba48 =1 ; +case WIN_MULTREAD : +if (!s->mult_sectors) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); + s->req_nb_sectors = s->mult_sectors; +ide_sector_read (s); +break ; +case WIN_MULTWRITE_EXT : + lba48 =1 ; +case WIN_MULTWRITE : +case CFA_WRITE_MULTI_WO_ERASE : +if (!s->mult_sectors) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); + s->error =0 ; + s->status =SEEK_STAT |READY_STAT ; + s->req_nb_sectors = s->mult_sectors; + n = s->nsector; +if (n > s->req_nb_sectors) + n = s->req_nb_sectors; +ide_transfer_start (s, s->io_buffer,512 * n, ide_sector_write); + s->media_changed =1 ; +break ;case WIN_READDMA_EXT : - lba48 =1 ; -case WIN_READDMA : -case WIN_READDMA_ONCE : -if (!s->bs) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); -ide_sector_read_dma (s); -break ; + lba48 =1 ; +case WIN_READDMA : +case WIN_READDMA_ONCE : +if (!s->bs) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); +ide_sector_read_dma (s); +break ;case WIN_WRITEDMA_EXT : - lba48 =1 ; -case WIN_WRITEDMA : -case WIN_WRITEDMA_ONCE : -if (!s->bs) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); -ide_sector_write_dma (s); - s->media_changed =1 ; -break ; -case WIN_READ_NATIVE_MAX_EXT : - lba48 =1 ; -case WIN_READ_NATIVE_MAX : -ide_cmd_lba48_transform (s, lba48); -ide_set_sector (s, s->nb_sectors -1 ); - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; -case WIN_CHECKPOWERMODE1 : -case WIN_CHECKPOWERMODE2 : - s->nsector =0xff ;/* device active or idle */ + lba48 =1 ; +case WIN_WRITEDMA : +case WIN_WRITEDMA_ONCE : +if (!s->bs) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); +ide_sector_write_dma (s); + s->media_changed =1 ; +break ; +case WIN_READ_NATIVE_MAX_EXT : + lba48 =1 ; +case WIN_READ_NATIVE_MAX : +ide_cmd_lba48_transform (s, lba48); +ide_set_sector (s, s->nb_sectors -1 ); + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case WIN_CHECKPOWERMODE1 : +case WIN_CHECKPOWERMODE2 : + s->nsector =0xff ;/* device active or idle */ + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case WIN_SETFEATURES : +if (!s->bs) + goto abort_cmd; +/* XXX: valid for CDROM ? */ +switch (s->feature) { +case 0xcc :/* reverting to power-on defaults enable */ +case 0x66 :/* reverting to power-on defaults disable */ +case 0x02 :/* write cache enable */ +case 0x82 :/* write cache disable */ +case 0xaa :/* read look-ahead enable */ +case 0x55 :/* read look-ahead disable */ +case 0x05 :/* set advanced power management mode */ +case 0x85 :/* disable advanced power management mode */ +case 0x69 :/* NOP */ +case 0x67 :/* NOP */ +case 0x96 :/* NOP */ +case 0x9a :/* NOP */ +case 0x42 :/* enable Automatic Acoustic Mode */ +case 0xc2 :/* disable Automatic Acoustic Mode */ s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case WIN_SETFEATURES : -if (!s->bs) - goto abort_cmd; -/* XXX: valid for CDROM ? */ -switch (s->feature) { -case 0xcc :/* reverting to power-on defaults enable */ -case 0x66 :/* reverting to power-on defaults disable */ -case 0x02 :/* write cache enable */ -case 0x82 :/* write cache disable */ -case 0xaa :/* read look-ahead enable */ -case 0x55 :/* read look-ahead disable */ -case 0x05 :/* set advanced power management mode */ -case 0x85 :/* disable advanced power management mode */ -case 0x69 :/* NOP */ -case 0x67 :/* NOP */ -case 0x96 :/* NOP */ -case 0x9a :/* NOP */ -case 0x42 :/* enable Automatic Acoustic Mode */ -case 0xc2 :/* disable Automatic Acoustic Mode */ - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; -case 0x03 : {/* set transfer mode */ +case 0x03 : {/* set transfer mode */ uint8_t val = s->nsector &0x07 ; -uint16_t *identify_data = (uint16_t *)s->identify_data; +uint16_t *identify_data = (uint16_t *)s->identify_data;switch (s->nsector >>3 ) { -case 0x00 :/* pio default */ -case 0x01 :/* pio mode */ +case 0x00 :/* pio default */ +case 0x01 :/* pio mode */ put_le16 (identify_data +62 ,0x07 );put_le16 (identify_data +63 ,0x07 );put_le16 (identify_data +88 ,0x3f );break ; -case 0x02 :/* sigle word dma mode*/ +case 0x02 :/* sigle word dma mode*/ put_le16 (identify_data +62 ,0x07 | (1 << (val +8 )));put_le16 (identify_data +63 ,0x07 );put_le16 (identify_data +88 ,0x3f );break ; -case 0x04 :/* mdma mode */ +case 0x04 :/* mdma mode */ put_le16 (identify_data +62 ,0x07 );put_le16 (identify_data +63 ,0x07 | (1 << (val +8 )));put_le16 (identify_data +88 ,0x3f );break ; -case 0x08 :/* udma mode */ +case 0x08 :/* udma mode */ put_le16 (identify_data +62 ,0x07 );put_le16 (identify_data +63 ,0x07 );put_le16 (identify_data +88 ,0x3f | (1 << (val +8 )));break ; -default : +default : goto abort_cmd; } - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; - } -default : - goto abort_cmd; - } -break ; -case WIN_FLUSH_CACHE : -case WIN_FLUSH_CACHE_EXT : -ide_flush_cache (s); -break ; -case WIN_STANDBY : -case WIN_STANDBY2 : -case WIN_STANDBYNOW1 : -case WIN_STANDBYNOW2 : -case WIN_IDLEIMMEDIATE : -case CFA_IDLEIMMEDIATE : -case WIN_SETIDLE1 : -case WIN_SETIDLE2 : -case WIN_SLEEPNOW1 : -case WIN_SLEEPNOW2 : - s->status =READY_STAT ; -ide_set_irq (s->bus); -break ; -case WIN_SEEK : -if (s->drive_kind ==IDE_CD ) - goto abort_cmd; -/* XXX: Check that seek is within bounds */ s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -/* ATAPI commands */ -case WIN_PIDENTIFY : -if (s->drive_kind ==IDE_CD ) { -ide_atapi_identify (s); - s->status =READY_STAT |SEEK_STAT ; -ide_transfer_start (s, s->io_buffer,512 , ide_transfer_stop); - }else { -ide_abort_command (s); - } -ide_set_irq (s->bus); -break ; -case WIN_DIAGNOSE : -ide_set_signature (s); -if (s->drive_kind ==IDE_CD ) - s->status =0 ;/* ATAPI spec (v6) section 9.10 defines packet -* devices to return a clear status register -* with READY_STAT *not* set. */ -else - s->status =READY_STAT |SEEK_STAT ; - s->error =0x01 ;/* Device 0 passed, Device 1 passed or not -* present. -*/ -ide_set_irq (s->bus); -break ; -case WIN_SRST : -if (s->drive_kind !=IDE_CD ) - goto abort_cmd; -ide_set_signature (s); - s->status =0x00 ;/* NOTE: READY is _not_ set */ - s->error =0x01 ; -break ; -case WIN_PACKETCMD : -if (s->drive_kind !=IDE_CD ) - goto abort_cmd; -/* overlapping commands not supported */ -if (s->feature &0x02 ) - goto abort_cmd; + } +default : + goto abort_cmd; + } +break ; +case WIN_FLUSH_CACHE : +case WIN_FLUSH_CACHE_EXT : +ide_flush_cache (s); +break ; +case WIN_STANDBY : +case WIN_STANDBY2 : +case WIN_STANDBYNOW1 : +case WIN_STANDBYNOW2 : +case WIN_IDLEIMMEDIATE : +case CFA_IDLEIMMEDIATE : +case WIN_SETIDLE1 : +case WIN_SETIDLE2 : +case WIN_SLEEPNOW1 : +case WIN_SLEEPNOW2 : + s->status =READY_STAT ; +ide_set_irq (s->bus); +break ; +case WIN_SEEK : +if (s->drive_kind ==IDE_CD ) + goto abort_cmd; +/* XXX: Check that seek is within bounds */ + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +/* ATAPI commands */ +case WIN_PIDENTIFY : +if (s->drive_kind ==IDE_CD ) { +ide_atapi_identify (s); s->status =READY_STAT |SEEK_STAT ; - s->atapi_dma = s->feature &1 ; - s->nsector =1 ; -ide_transfer_start (s, s->io_buffer,ATAPI_PACKET_SIZE , - ide_atapi_cmd); -break ; -/* CF-ATA commands */ -case CFA_REQ_EXT_ERROR_CODE : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; - s->error =0x09 ;/* miscellaneous error */ +ide_transfer_start (s, s->io_buffer,512 , ide_transfer_stop); + }else { +ide_abort_command (s); + } +ide_set_irq (s->bus); +break ; +case WIN_DIAGNOSE : +ide_set_signature (s); +if (s->drive_kind ==IDE_CD ) + s->status =0 ;/* ATAPI spec (v6) section 9.10 defines packet +* devices to return a clear status register +* with READY_STAT *not* set. */ +else s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); + s->error =0x01 ;/* Device 0 passed, Device 1 passed or not +* present. +*/ +ide_set_irq (s->bus); +break ; +case WIN_SRST : +if (s->drive_kind !=IDE_CD ) + goto abort_cmd; +ide_set_signature (s); + s->status =0x00 ;/* NOTE: READY is _not_ set */ + s->error =0x01 ; +break ; +case WIN_PACKETCMD : +if (s->drive_kind !=IDE_CD ) + goto abort_cmd; +/* overlapping commands not supported */ +if (s->feature &0x02 ) + goto abort_cmd; + s->status =READY_STAT |SEEK_STAT ; + s->atapi_dma = s->feature &1 ; + s->nsector =1 ; +ide_transfer_start (s, s->io_buffer,ATAPI_PACKET_SIZE , + ide_atapi_cmd); +break ; +/* CF-ATA commands */ +case CFA_REQ_EXT_ERROR_CODE : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; + s->error =0x09 ;/* miscellaneous error */ + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case CFA_ERASE_SECTORS : +case CFA_WEAR_LEVEL : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; +if (val ==CFA_WEAR_LEVEL ) + s->nsector =0 ; +if (val ==CFA_ERASE_SECTORS ) + s->media_changed =1 ; + s->error =0x00 ; + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case CFA_TRANSLATE_SECTOR : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; + s->error =0x00 ; + s->status =READY_STAT |SEEK_STAT ; +memset (s->io_buffer,0 ,0x200 ); + s->io_buffer[0x00 ] = s->hcyl;/* Cyl MSB */ + s->io_buffer[0x01 ] = s->lcyl;/* Cyl LSB */ + s->io_buffer[0x02 ] = s->select;/* Head */ + s->io_buffer[0x03 ] = s->sector;/* Sector */ + s->io_buffer[0x04 ] =ide_get_sector (s) >>16 ;/* LBA MSB */ + s->io_buffer[0x05 ] =ide_get_sector (s) >>8 ;/* LBA */ + s->io_buffer[0x06 ] =ide_get_sector (s) >>0 ;/* LBA LSB */ + s->io_buffer[0x13 ] =0x00 ;/* Erase flag */ + s->io_buffer[0x18 ] =0x00 ;/* Hot count */ + s->io_buffer[0x19 ] =0x00 ;/* Hot count */ + s->io_buffer[0x1a ] =0x01 ;/* Hot count */ +ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop); +ide_set_irq (s->bus); +break ; +case CFA_ACCESS_METADATA_STORAGE : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; +switch (s->feature) { +case 0x02 :/* Inquiry Metadata Storage */ +ide_cfata_metadata_inquiry (s);break ; -case CFA_ERASE_SECTORS : -case CFA_WEAR_LEVEL : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; -if (val ==CFA_WEAR_LEVEL ) - s->nsector =0 ; -if (val ==CFA_ERASE_SECTORS ) - s->media_changed =1 ; - s->error =0x00 ; - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); +case 0x03 :/* Read Metadata Storage */ +ide_cfata_metadata_read (s);break ; -case CFA_TRANSLATE_SECTOR : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; - s->error =0x00 ; - s->status =READY_STAT |SEEK_STAT ; -memset (s->io_buffer,0 ,0x200 ); - s->io_buffer[0x00 ] = s->hcyl;/* Cyl MSB */ - s->io_buffer[0x01 ] = s->lcyl;/* Cyl LSB */ - s->io_buffer[0x02 ] = s->select;/* Head */ - s->io_buffer[0x03 ] = s->sector;/* Sector */ - s->io_buffer[0x04 ] =ide_get_sector (s) >>16 ;/* LBA MSB */ - s->io_buffer[0x05 ] =ide_get_sector (s) >>8 ;/* LBA */ - s->io_buffer[0x06 ] =ide_get_sector (s) >>0 ;/* LBA LSB */ - s->io_buffer[0x13 ] =0x00 ;/* Erase flag */ - s->io_buffer[0x18 ] =0x00 ;/* Hot count */ - s->io_buffer[0x19 ] =0x00 ;/* Hot count */ - s->io_buffer[0x1a ] =0x01 ;/* Hot count */ -ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop); -ide_set_irq (s->bus); +case 0x04 :/* Write Metadata Storage */ +ide_cfata_metadata_write (s);break ; -case CFA_ACCESS_METADATA_STORAGE : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; -switch (s->feature) { -case 0x02 :/* Inquiry Metadata Storage */ -ide_cfata_metadata_inquiry (s); -break ; -case 0x03 :/* Read Metadata Storage */ -ide_cfata_metadata_read (s); -break ; -case 0x04 :/* Write Metadata Storage */ -ide_cfata_metadata_write (s); -break ; -default : - goto abort_cmd; - } -ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop); - s->status =0x00 ;/* NOTE: READY is _not_ set */ -ide_set_irq (s->bus); -break ; -case IBM_SENSE_CONDITION : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; -switch (s->feature) { -case 0x01 :/* sense temperature in device */ - s->nsector =0x50 ;/* +20 C */ -break ; -default : - goto abort_cmd; - } - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); +default : + goto abort_cmd; + } +ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop); + s->status =0x00 ;/* NOTE: READY is _not_ set */ +ide_set_irq (s->bus); +break ; +case IBM_SENSE_CONDITION : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; +switch (s->feature) { +case 0x01 :/* sense temperature in device */ + s->nsector =0x50 ;/* +20 C */ break ; +default : + goto abort_cmd; + } + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ;case WIN_SMART : -if (s->drive_kind ==IDE_CD ) +if (s->drive_kind ==IDE_CD ) goto abort_cmd; -if (s->hcyl !=0xc2 || s->lcyl !=0x4f ) +if (s->hcyl !=0xc2 || s->lcyl !=0x4f ) goto abort_cmd; -if (!s->smart_enabled && s->feature !=SMART_ENABLE ) +if (!s->smart_enabled && s->feature !=SMART_ENABLE ) goto abort_cmd; -switch (s->feature) { -case SMART_DISABLE : +switch (s->feature) { +case SMART_DISABLE : s->smart_enabled =0 ; s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case SMART_ENABLE : +case SMART_ENABLE : s->smart_enabled =1 ; s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case SMART_ATTR_AUTOSAVE : +case SMART_ATTR_AUTOSAVE :switch (s->sector) {case 0x00 : - s->smart_autosave =0 ; -break ; + s->smart_autosave =0 ; +break ;case 0xf1 : - s->smart_autosave =1 ; -break ; + s->smart_autosave =1 ; +break ;default : - goto abort_cmd; + goto abort_cmd; } s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case SMART_STATUS : +case SMART_STATUS :if (!s->smart_errors) { - s->hcyl =0xc2 ; - s->lcyl =0x4f ; + s->hcyl =0xc2 ; + s->lcyl =0x4f ; }else { - s->hcyl =0x2c ; - s->lcyl =0xf4 ; + s->hcyl =0x2c ; + s->lcyl =0xf4 ; } s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case SMART_READ_THRESH : +case SMART_READ_THRESH :memset (s->io_buffer,0 ,0x200 ); s->io_buffer[0 ] =0x01 ;/* smart struct version */ for (n=0 ; n<30 ; n++) { -if (smart_attributes[n][0 ] ==0 ) +if (smart_attributes[n][0 ] ==0 )break ; - s->io_buffer[2 +0 +(n*12 )] = smart_attributes[n][0 ]; - s->io_buffer[2 +1 +(n*12 )] = smart_attributes[n][4 ]; + s->io_buffer[2 +0 +(n*12 )] = smart_attributes[n][0 ]; + s->io_buffer[2 +1 +(n*12 )] = smart_attributes[n][4 ]; }for (n=0 ; n<511 ; n++)/* checksum */ - s->io_buffer[511 ] += s->io_buffer[n]; + s->io_buffer[511 ] += s->io_buffer[n]; s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; s->status =READY_STAT |SEEK_STAT ;ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop);ide_set_irq (s->bus);break ; -case SMART_READ_DATA : +case SMART_READ_DATA :memset (s->io_buffer,0 ,0x200 ); s->io_buffer[0 ] =0x01 ;/* smart struct version */ for (n=0 ; n<30 ; n++) { -if (smart_attributes[n][0 ] ==0 ) +if (smart_attributes[n][0 ] ==0 )break ; - s->io_buffer[2 +0 +(n*12 )] = smart_attributes[n][0 ]; - s->io_buffer[2 +1 +(n*12 )] = smart_attributes[n][1 ]; - s->io_buffer[2 +3 +(n*12 )] = smart_attributes[n][2 ]; - s->io_buffer[2 +4 +(n*12 )] = smart_attributes[n][3 ]; + s->io_buffer[2 +0 +(n*12 )] = smart_attributes[n][0 ]; + s->io_buffer[2 +1 +(n*12 )] = smart_attributes[n][1 ]; + s->io_buffer[2 +3 +(n*12 )] = smart_attributes[n][2 ]; + s->io_buffer[2 +4 +(n*12 )] = smart_attributes[n][3 ]; } s->io_buffer[362 ] =0x02 | (s->smart_autosave?0x80 :0x00 );if (s->smart_selftest_count ==0 ) { - s->io_buffer[363 ] =0 ; + s->io_buffer[363 ] =0 ; }else { - s->io_buffer[363 ] = + s->io_buffer[363 ] = s->smart_selftest_data[3 + - (s->smart_selftest_count -1 ) * -24 ]; + (s->smart_selftest_count -1 ) * +24 ]; } s->io_buffer[364 ] =0x20 ; s->io_buffer[365 ] =0x01 ;
@@ -2294,76 +2294,76 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) s->io_buffer[374 ] =0x01 ;/* minutes for poll conveyance */ for (n=0 ; n<511 ; n++) - s->io_buffer[511 ] += s->io_buffer[n]; + s->io_buffer[511 ] += s->io_buffer[n]; s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; s->status =READY_STAT |SEEK_STAT ;ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop);ide_set_irq (s->bus);break ; -case SMART_READ_LOG : +case SMART_READ_LOG :switch (s->sector) {case 0x01 :/* summary smart error log */ -memset (s->io_buffer,0 ,0x200 ); - s->io_buffer[0 ] =0x01 ; - s->io_buffer[1 ] =0x00 ;/* no error entries */ - s->io_buffer[452 ] = s->smart_errors &0xff ; - s->io_buffer[453 ] = (s->smart_errors &0xff00 ) >>8 ; +memset (s->io_buffer,0 ,0x200 ); + s->io_buffer[0 ] =0x01 ; + s->io_buffer[1 ] =0x00 ;/* no error entries */ + s->io_buffer[452 ] = s->smart_errors &0xff ; + s->io_buffer[453 ] = (s->smart_errors &0xff00 ) >>8 ; -for (n=0 ; n<511 ; n++) +for (n=0 ; n<511 ; n++) s->io_buffer[511 ] += s->io_buffer[n]; - s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; -break ; + s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; +break ;case 0x06 :/* smart self test log */ -memset (s->io_buffer,0 ,0x200 ); - s->io_buffer[0 ] =0x01 ; -if (s->smart_selftest_count ==0 ) { +memset (s->io_buffer,0 ,0x200 ); + s->io_buffer[0 ] =0x01 ; +if (s->smart_selftest_count ==0 ) { s->io_buffer[508 ] =0 ; - }else { + }else { s->io_buffer[508 ] = s->smart_selftest_count;for (n=2 ; n<506 ; n++) - s->io_buffer[n] = s->smart_selftest_data[n]; - } -for (n=0 ; n<511 ; n++) + s->io_buffer[n] = s->smart_selftest_data[n]; + } +for (n=0 ; n<511 ; n++) s->io_buffer[511 ] += s->io_buffer[n]; - s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; -break ; + s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; +break ;default : - goto abort_cmd; + goto abort_cmd; } s->status =READY_STAT |SEEK_STAT ;ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop);ide_set_irq (s->bus);break ; -case SMART_EXECUTE_OFFLINE : +case SMART_EXECUTE_OFFLINE :switch (s->sector) {case 0 :/* off-line routine */ case 1 :/* short self test */ case 2 :/* extended self test */ - s->smart_selftest_count++; -if (s->smart_selftest_count >21 ) + s->smart_selftest_count++; +if (s->smart_selftest_count >21 ) s->smart_selftest_count =0 ; - n =2 + (s->smart_selftest_count -1 ) *24 ; - s->smart_selftest_data[n] = s->sector; - s->smart_selftest_data[n+1 ] =0x00 ;/* OK and finished */ - s->smart_selftest_data[n+2 ] =0x34 ;/* hour count lsb */ - s->smart_selftest_data[n+3 ] =0x12 ;/* hour count msb */ - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; + n =2 + (s->smart_selftest_count -1 ) *24 ; + s->smart_selftest_data[n] = s->sector; + s->smart_selftest_data[n+1 ] =0x00 ;/* OK and finished */ + s->smart_selftest_data[n+2 ] =0x34 ;/* hour count lsb */ + s->smart_selftest_data[n+3 ] =0x12 ;/* hour count msb */ + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ;default : - goto abort_cmd; + goto abort_cmd; }break ; -default : +default : goto abort_cmd; - } -break ; -default : - abort_cmd: -ide_abort_command (s); -ide_set_irq (s->bus); -break ; - } + } +break ; +default : + abort_cmd: +ide_abort_command (s); +ide_set_irq (s->bus); +break ; + } }uint32_t ide_ioport_read (void *opaque,uint32_t addr1)
Signature · 1 line
1.7.2.3
PATCH 8/38 ide: Split out BMDMA code from ATA core
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
The ATA core is currently heavily intertwined with BMDMA code. Let's loosen that a bit, so we can happily replace the DMA backend with different implementations.
--- hw/ide/cmd646.c | 6 +- hw/ide/core.c | 347 +++++++++++++++-------------------------------------- hw/ide/internal.h | 69 +++++------ hw/ide/pci.c | 280 ++++++++++++++++++++++++++++++++++++++++++- hw/ide/pci.h | 30 +++++ hw/ide/piix.c | 6 +- hw/ide/via.c | 6 +- 7 files changed, 446 insertions(+), 298 deletions(-)
hw/ide/cmd646.c +3 -3
@@ -167,9 +167,10 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,for (i =0 ;i <2 ; i++) {BMDMAState *bm = &d->bmdma[i]; - d->bus[i].bmdma = bm; +bmdma_init (&d->bus[i], bm); bm->bus = d->bus+i; -qemu_add_vm_change_state_handler (ide_dma_restart_cb, bm); +qemu_add_vm_change_state_handler (d->bus[i].dma->ops->restart_cb, + &bm->dma);if (i ==0 ) {register_ioport_write (addr,4 ,1 , bmdma_writeb_0, d);
@@ -218,7 +219,6 @@ static void cmd646_reset(void *opaque)for (i =0 ; i <2 ; i++) {ide_bus_reset (&d->bus[i]); -ide_dma_reset (&d->bmdma[i]); } }
hw/ide/core.c +98 -249
545 lines not on this page · raw message
hw/ide/internal.h +32 -37
120 lines not on this page · raw message
hw/ide/pci.c +277 -3
303 lines not on this page · raw message
hw/ide/pci.h +30 -0
@@ -3,6 +3,27 @@#include <hw/ide/internal.h> +typedef struct BMDMAState { +IDEDMA dma; +uint8_t cmd; +uint8_t status; +uint32_t addr; + +IDEBus *bus; +/* current transfer state */ +uint32_t cur_addr; +uint32_t cur_prd_last; +uint32_t cur_prd_addr; +uint32_t cur_prd_len; +uint8_t unit; +BlockDriverCompletionFunc *dma_cb; +int64_t sector_num; +uint32_t nsector; +IORange addr_ioport; +QEMUBH *bh; +qemu_irq irq; +}BMDMAState ; + typedef struct PCIIDEState { PCIDevice dev; IDEBus bus[2];
@@ -10,6 +31,15 @@ typedef struct PCIIDEState {uint32_t secondary;/* used only for cmd646 */ } PCIIDEState; + +static inline IDEState *bmdma_active_if (BMDMAState *bmdma) +{ +assert (bmdma->unit != (uint8_t )-1 ); +return bmdma->bus->ifs + bmdma->unit; +} + + +void bmdma_init (IDEBus *bus,BMDMAState *bm);void bmdma_cmd_writeb (void *opaque,uint32_t addr,uint32_t val);extern const IORangeOps bmdma_addr_ioport_ops;void pci_ide_create_devs (PCIDevice *dev,DriveInfo **hd_table);
hw/ide/piix.c +3 -3
@@ -76,9 +76,10 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,for (i =0 ;i <2 ; i++) {BMDMAState *bm = &d->bmdma[i]; - d->bus[i].bmdma = bm; +bmdma_init (&d->bus[i], bm); bm->bus = d->bus+i; -qemu_add_vm_change_state_handler (ide_dma_restart_cb, bm); +qemu_add_vm_change_state_handler (d->bus[i].dma->ops->restart_cb, + &bm->dma);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
@@ -99,7 +100,6 @@ static void piix3_reset(void *opaque)for (i =0 ; i <2 ; i++) {ide_bus_reset (&d->bus[i]); -ide_dma_reset (&d->bmdma[i]); }/* TODO: this is the default. do not override. */
hw/ide/via.c +3 -3
@@ -78,9 +78,10 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,for (i =0 ;i <2 ; i++) {BMDMAState *bm = &d->bmdma[i]; - d->bus[i].bmdma = bm; +bmdma_init (&d->bus[i], bm); bm->bus = d->bus+i; -qemu_add_vm_change_state_handler (ide_dma_restart_cb, bm); +qemu_add_vm_change_state_handler (d->bus[i].dma->ops->restart_cb, + &bm->dma);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
@@ -101,7 +102,6 @@ static void via_reset(void *opaque)for (i =0 ; i <2 ; i++) {ide_bus_reset (&d->bus[i]); -ide_dma_reset (&d->bmdma[i]); }pci_set_word (pci_conf +PCI_COMMAND ,PCI_COMMAND_WAIT );
Signature · 1 line
1.7.2.3
PATCH 9/38 ide: move transfer_start after variable modification
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
We hook into transfer_start and immediately call the end function for ahci. This means that everything needs to be in place for the end function when we start the transfer, so let's move the function down to where all state is in place.
--- hw/ide/core.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
hw/ide/core.c +4 -4
@@ -814,11 +814,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s) size = s->cd_sector_size - s->io_buffer_index;if (size > s->elementary_transfer_size) size = s->elementary_transfer_size; -ide_transfer_start (s, s->io_buffer + s->io_buffer_index, - size, ide_atapi_cmd_reply_end); s->packet_transfer_size -= size; s->elementary_transfer_size -= size; s->io_buffer_index += size; +ide_transfer_start (s, s->io_buffer + s->io_buffer_index - size, + size, ide_atapi_cmd_reply_end); }else {/* a new transfer is needed */ s->nsector = (s->nsector & ~7 ) |ATAPI_INT_REASON_IO ;
@@ -843,11 +843,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s)if (size > (s->cd_sector_size - s->io_buffer_index)) size = (s->cd_sector_size - s->io_buffer_index); } -ide_transfer_start (s, s->io_buffer + s->io_buffer_index, - size, ide_atapi_cmd_reply_end); s->packet_transfer_size -= size; s->elementary_transfer_size -= size; s->io_buffer_index += size; +ide_transfer_start (s, s->io_buffer + s->io_buffer_index - size, + size, ide_atapi_cmd_reply_end);ide_set_irq (s->bus);#ifdef DEBUG_IDE_ATAPI printf ("status=0x%x\n" , s->status);
Signature · 1 line
1.7.2.3
PATCH 10/38 ide: add ncq identify data for ahci sata drives
In reply to Kevin WolfFrom: Roland Elek <[email protected]>
I modified ide_identify() to include the zero-based queue length value in word 75, and set bit 8 in word 76 to signal NCQ support in the identify data for AHCI SATA drives.
--- hw/ide/core.c | 7 +++++++ hw/ide/internal.h | 2 ++ 2 files changed, 9 insertions(+), 0 deletions(-)
hw/ide/core.c +7 -0
@@ -140,6 +140,13 @@ static void ide_identify(IDEState *s)put_le16 (p +66 ,120 );put_le16 (p +67 ,120 );put_le16 (p +68 ,120 ); + +if (s->ncq_queues) { +put_le16 (p +75 , s->ncq_queues -1 ); +/* NCQ supported */ +put_le16 (p +76 , (1 <<8 )); + } +put_le16 (p +80 ,0xf0 );/* ata3 -> ata6 supported */ put_le16 (p +81 ,0x16 );/* conforms to ata5 */ /* 14=NOP supported, 5=WCACHE supported, 0=SMART supported */
hw/ide/internal.h +2 -0
@@ -447,6 +447,8 @@ struct IDEState {int smart_errors;uint8_t smart_selftest_count;uint8_t *smart_selftest_data; +/* AHCI */ +int ncq_queues; };struct IDEDMAOps {
Signature · 1 line
1.7.2.3
PATCH 11/38 pci: add storage class for sata
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
This patch adds the storage sata class id.
--- hw/pci_ids.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci_ids.h +1 -0
@@ -15,6 +15,7 @@#define PCI_CLASS_STORAGE_SCSI 0x0100#define PCI_CLASS_STORAGE_IDE 0x0101 +#define PCI_CLASS_STORAGE_SATA 0x0106#define PCI_CLASS_STORAGE_OTHER 0x0180#define PCI_CLASS_NETWORK_ETHERNET 0x0200
Signature · 1 line
1.7.2.3
PATCH 12/38 pci: add ich9 pci id
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
We need a PCI ID for our new AHCI adapter. I just picked an ICH-9 because that's the one in the Q35 chipset.
This patch adds a PCI ID define for an ICH-9 AHCI adapter.
--- hw/pci.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci.h +1 -0
@@ -62,6 +62,7 @@/* Intel (0x8086) */ #define PCI_DEVICE_ID_INTEL_82551IT 0x1209#define PCI_DEVICE_ID_INTEL_82557 0x1229 +#define PCI_DEVICE_ID_INTEL_82801IR 0x2922/* Red Hat / Qumranet (for QEMU) -- see pci-ids.txt */ #define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
Signature · 1 line
1.7.2.3
PATCH 13/38 ahci: add ahci emulation
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
This patch adds an emulation layer for an ICH-9 AHCI controller. For now this controller does not do IDE legacy emulation. It is a pure AHCI controller.
--- Makefile.objs | 1 + hw/ide/ahci.c | 1524 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1525 insertions(+), 0 deletions(-) create mode 100644 hw/ide/ahci.c
Makefile.objs +1 -0
@@ -243,6 +243,7 @@ hw-obj-$(CONFIG_IDE_PIIX) += ide/piix.o hw-obj-$(CONFIG_IDE_CMD646) += ide/cmd646.o hw-obj-$(CONFIG_IDE_MACIO) += ide/macio.o hw-obj-$(CONFIG_IDE_VIA) += ide/via.o +hw-obj-$(CONFIG_AHCI) += ide/ahci.o # SCSI layer hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
hw/ide/ahci.c new file +1524 -0
1,524 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 14/38 config: move ide core and pci to pci.mak
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
Every device that can do PCI should also be able to do IDE. So let's move the IDE definitions over to pci.mak.
--- default-configs/arm-softmmu.mak | 1 - default-configs/i386-softmmu.mak | 3 --- default-configs/mips-softmmu.mak | 3 --- default-configs/mips64-softmmu.mak | 3 --- default-configs/mips64el-softmmu.mak | 3 --- default-configs/mipsel-softmmu.mak | 3 --- default-configs/pci.mak | 3 +++ default-configs/ppc-softmmu.mak | 3 --- default-configs/ppc64-softmmu.mak | 3 --- default-configs/ppcemb-softmmu.mak | 3 --- default-configs/sh4-softmmu.mak | 1 - default-configs/sh4eb-softmmu.mak | 1 - default-configs/sparc64-softmmu.mak | 3 --- default-configs/x86_64-softmmu.mak | 3 --- 14 files changed, 3 insertions(+), 33 deletions(-)
default-configs/arm-softmmu.mak +0 -1
@@ -8,7 +8,6 @@ CONFIG_ECC=y CONFIG_SERIAL=y CONFIG_PTIMER=y CONFIG_SD=y -CONFIG_IDE_CORE=y CONFIG_MAX7310=y CONFIG_WM8750=y CONFIG_TWL92230=y
default-configs/i386-softmmu.mak +0 -3
@@ -13,9 +13,6 @@ CONFIG_FDC=y CONFIG_ACPI=y CONFIG_APM=y CONFIG_DMA=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y CONFIG_NE2000_ISA=y
default-configs/mips-softmmu.mak +0 -3
@@ -17,9 +17,6 @@ CONFIG_ACPI=y CONFIG_APM=y CONFIG_DMA=y CONFIG_PIIX4=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y CONFIG_NE2000_ISA=y
default-configs/mips64-softmmu.mak +0 -3
@@ -17,9 +17,6 @@ CONFIG_ACPI=y CONFIG_APM=y CONFIG_DMA=y CONFIG_PIIX4=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y CONFIG_NE2000_ISA=y
default-configs/mips64el-softmmu.mak +0 -3
@@ -17,9 +17,6 @@ CONFIG_ACPI=y CONFIG_APM=y CONFIG_DMA=y CONFIG_PIIX4=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y CONFIG_IDE_VIA=y
default-configs/mipsel-softmmu.mak +0 -3
@@ -17,9 +17,6 @@ CONFIG_ACPI=y CONFIG_APM=y CONFIG_DMA=y CONFIG_PIIX4=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y CONFIG_NE2000_ISA=y
default-configs/pci.mak +3 -0
@@ -10,3 +10,6 @@ CONFIG_PCNET_COMMON=y CONFIG_LSI_SCSI_PCI=y CONFIG_RTL8139_PCI=y CONFIG_E1000_PCI=y +CONFIG_IDE_CORE=y +CONFIG_IDE_QDEV=y +CONFIG_IDE_PCI=y
default-configs/ppc-softmmu.mak +0 -3
@@ -23,9 +23,6 @@ CONFIG_GRACKLE_PCI=y CONFIG_UNIN_PCI=y CONFIG_DEC_PCI=y CONFIG_PPCE500_PCI=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_CMD646=y CONFIG_IDE_MACIO=y
default-configs/ppc64-softmmu.mak +0 -3
@@ -23,9 +23,6 @@ CONFIG_GRACKLE_PCI=y CONFIG_UNIN_PCI=y CONFIG_DEC_PCI=y CONFIG_PPCE500_PCI=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_CMD646=y CONFIG_IDE_MACIO=y
default-configs/ppcemb-softmmu.mak +0 -3
@@ -23,9 +23,6 @@ CONFIG_GRACKLE_PCI=y CONFIG_UNIN_PCI=y CONFIG_DEC_PCI=y CONFIG_PPCE500_PCI=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_CMD646=y CONFIG_IDE_MACIO=y
default-configs/sh4-softmmu.mak +0 -1
@@ -3,6 +3,5 @@ include pci.mak CONFIG_SERIAL=y CONFIG_PTIMER=y -CONFIG_IDE_CORE=y CONFIG_PFLASH_CFI02=y CONFIG_ISA_MMIO=y
default-configs/sh4eb-softmmu.mak +0 -1
@@ -3,6 +3,5 @@ include pci.mak CONFIG_SERIAL=y CONFIG_PTIMER=y -CONFIG_IDE_CORE=y CONFIG_PFLASH_CFI02=y CONFIG_ISA_MMIO=y
default-configs/sparc64-softmmu.mak +0 -3
@@ -9,8 +9,5 @@ CONFIG_SERIAL=y CONFIG_PARALLEL=y CONFIG_PCKBD=y CONFIG_FDC=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_CMD646=y
default-configs/x86_64-softmmu.mak +0 -3
@@ -13,9 +13,6 @@ CONFIG_FDC=y CONFIG_ACPI=y CONFIG_APM=y CONFIG_DMA=y -CONFIG_IDE_CORE=y -CONFIG_IDE_QDEV=y -CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y CONFIG_NE2000_ISA=y
Signature · 1 line
1.7.2.3
PATCH 15/38 config: add ahci for pci capable machines
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
This patch enables AHCI for all machines supporting PCI.
--- default-configs/pci.mak | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
default-configs/pci.mak +1 -0
@@ -13,3 +13,4 @@ CONFIG_E1000_PCI=y CONFIG_IDE_CORE=y CONFIG_IDE_QDEV=y CONFIG_IDE_PCI=y +CONFIG_AHCI=y
Signature · 1 line
1.7.2.3
PATCH 16/38 ahci: set SATA Mode Select
In reply to Kevin WolfFrom: Sebastian Herbszt <[email protected]>
Set SATA Mode Select to AHCI in the Address Map Register.
--- hw/ide/ahci.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
hw/ide/ahci.c +3 -0
@@ -1473,6 +1473,9 @@ static int pci_ahci_init(PCIDevice *dev) d->card.config[PCI_LATENCY_TIMER ] =0x00 ;/* Latency timer */ pci_config_set_interrupt_pin (d->card.config,1 ); +/* XXX Software should program this register */ + d->card.config[0x90 ] =1 <<6 ;/* Address Map Register - AHCI mode */ +qemu_register_reset (ahci_reset, d);/* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */
Signature · 1 line
1.7.2.3
PATCH 17/38 ide: honor ncq for atapi
In reply to Kevin WolfFrom: Alexander Graf <[email protected]>
ATAPI also can do ncq, so let's expose the capability.
This patch makes CD-ROM support work on Windows 7 for me.
--- hw/ide/core.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/ide/core.c +6 -0
@@ -217,6 +217,12 @@ static void ide_atapi_identify(IDEState *s)put_le16 (p +71 ,30 );/* in ns */ put_le16 (p +72 ,30 );/* in ns */ +if (s->ncq_queues) { +put_le16 (p +75 , s->ncq_queues -1 ); +/* NCQ supported */ +put_le16 (p +76 , (1 <<8 )); + } +put_le16 (p +80 ,0x1e );/* support up to ATA/ATAPI-4 */ #ifdef USE_DMA_CDROM put_le16 (p +88 ,0x3f | (1 <<13 ));/* udma5 set and supported */
Signature · 1 line
1.7.2.3
PATCH 18/38 qemu-img: Call error_set_progname
In reply to Kevin WolfCall error_set_progname during the qemu-img initialization, so that error messages printed with error_report() use the right prefix.
--- qemu-img.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
qemu-img.c +3 -0
@@ -23,6 +23,7 @@*/ #include "qemu-common.h" #include "qemu-option.h" +#include "qemu-error.h" #include "osdep.h" #include "sysemu.h" #include "block_int.h"
@@ -1612,6 +1613,8 @@ int main(int argc, char **argv)const img_cmd_t *cmd;const char *cmdname; +error_set_progname (argv[0 ]); +bdrv_init ();if (argc <2 )help ();
Signature · 1 line
1.7.2.3
PATCH 19/38 qemu-img.c: Re-factor img_create()
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
This patch re-factors img_create() moving the code doing the actual work into block.c where it can be shared with QEMU. This is needed to be able to create images from QEMU to be used for live snapshots.
--- block.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ block.h | 4 ++ qemu-img.c | 108 +--------------------------------------------- 3 files changed, 147 insertions(+), 106 deletions(-)
block.c +141 -0
@@ -2758,3 +2758,144 @@ int64_t bdrv_get_dirty_count(BlockDriverState *bs) {return bs->dirty_count; } + +int bdrv_img_create (const char *filename,const char *fmt, +const char *base_filename,const char *base_fmt, +char *options,uint64_t img_size,int flags) +{ +QEMUOptionParameter *param =NULL , *create_options =NULL ; +QEMUOptionParameter *backing_fmt; +BlockDriverState *bs =NULL ; +BlockDriver *drv, *proto_drv; +int ret =0 ; + +/* Find driver and parse its options */ + drv =bdrv_find_format (fmt); +if (!drv) { +error_report ("Unknown file format '%s'" , fmt); + ret =-1 ; + goto out; + } + + proto_drv =bdrv_find_protocol (filename); +if (!proto_drv) { +error_report ("Unknown protocol '%s'" , filename); + ret =-1 ; + goto out; + } + + create_options =append_option_parameters (create_options, + drv->create_options); + create_options =append_option_parameters (create_options, + proto_drv->create_options); + +/* Create parameter list with default values */ + param =parse_option_parameters ("" , create_options, param); + +set_option_parameter_int (param,BLOCK_OPT_SIZE , img_size); + +/* Parse -o options */ +if (options) { + param =parse_option_parameters (options, create_options, param); +if (param ==NULL ) { +error_report ("Invalid options for file format '%s'." , fmt); + ret =-1 ; + goto out; + } + } + +if (base_filename) { +if (set_option_parameter (param,BLOCK_OPT_BACKING_FILE , + base_filename)) { +error_report ("Backing file not supported for file format '%s'" , + fmt); + ret =-1 ; + goto out; + } + } + +if (base_fmt) { +if (set_option_parameter (param,BLOCK_OPT_BACKING_FMT , base_fmt)) { +error_report ("Backing file format not supported for file " +"format '%s'" , fmt); + ret =-1 ; + goto out; + } + } + + 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)) { +error_report ("Unknown backing file format '%s'" , + backing_fmt->value.s); + ret =-1 ; + goto out; + } + } + +// The size for the image must always be specified, with one exception: +// If we are using a backing file, we can obtain the size from there +if (get_option_parameter (param,BLOCK_OPT_SIZE )->value.n ==-1 ) { +QEMUOptionParameter *backing_file = +get_option_parameter (param,BLOCK_OPT_BACKING_FILE ); + +if (backing_file && backing_file->value.s) { +uint64_t size; +const char *fmt =NULL ; +char buf[32 ]; + +if (backing_fmt && backing_fmt->value.s) { + fmt = backing_fmt->value.s; + } + + bs =bdrv_new ("" ); + + ret =bdrv_open (bs, backing_file->value.s, flags, drv); +if (ret <0 ) { +error_report ("Could not open '%s'" , filename); + ret =-1 ; + goto out; + } +bdrv_get_geometry (bs, &size); + size *=512 ; + +snprintf (buf,sizeof (buf),"%" PRId64, size); +set_option_parameter (param,BLOCK_OPT_SIZE , buf); + }else { +error_report ("Image creation needs a size parameter" ); + ret =-1 ; + goto out; + } + } + +printf ("Formatting '%s', fmt=%s " , filename, fmt); +print_option_parameters (param); +puts ("" ); + + ret =bdrv_create (drv, filename, param); + +if (ret <0 ) { +if (ret == -ENOTSUP ) { +error_report ("Formatting or formatting option not supported for " +"file format '%s'" , fmt); + }else if (ret == -EFBIG ) { +error_report ("The image size is too large for file format '%s'" , + fmt); + }else { +error_report ("%s: error while creating %s: %s" , filename, fmt, +strerror (-ret)); + } + } + +out: +free_option_parameters (create_options); +free_option_parameters (param); + +if (bs) { +bdrv_delete (bs); + } +if (ret) { +return 1 ; + } +return 0 ; +}
block.h +4 -0
@@ -227,6 +227,10 @@ int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,int bdrv_load_vmstate (BlockDriverState *bs,uint8_t *buf,int64_t pos,int size); +int bdrv_img_create (const char *filename,const char *fmt, +const char *base_filename,const char *base_fmt, +char *options,uint64_t img_size,int flags); +#define BDRV_SECTORS_PER_DIRTY_CHUNK 2048void bdrv_set_dirty_tracking (BlockDriverState *bs,int enable);
qemu-img.c +2 -106
121 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 20/38 Introduce do_snapshot_blkdev() and monitor command to handle it.
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
The monitor command is:snapshot_blkdev <device> [snapshot-file] [format]
Default format is qcow2. For now snapshots without a snapshot-file, eg internal snapshots, are not supported.
--- blockdev.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ blockdev.h | 1 + hmp-commands.hx | 19 ++++++++++++++++ 3 files changed, 82 insertions(+), 0 deletions(-)
blockdev.c +62 -0
@@ -516,6 +516,68 @@ void do_commit(Monitor *mon, const QDict *qdict) } } +int do_snapshot_blkdev (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +const char *device =qdict_get_str (qdict,"device" ); +const char *filename =qdict_get_try_str (qdict,"snapshot_file" ); +const char *format =qdict_get_try_str (qdict,"format" ); +BlockDriverState *bs; +BlockDriver *drv, *proto_drv; +int ret =0 ; +int flags; + + bs =bdrv_find (device); +if (!bs) { +qerror_report (QERR_DEVICE_NOT_FOUND , device); + ret =-1 ; + goto out; + } + +if (!format) { + format ="qcow2" ; + } + + drv =bdrv_find_format (format); +if (!drv) { +qerror_report (QERR_INVALID_BLOCK_FORMAT , format); + ret =-1 ; + goto out; + } + + proto_drv =bdrv_find_protocol (filename); +if (!proto_drv) { +qerror_report (QERR_INVALID_BLOCK_FORMAT , format); + ret =-1 ; + goto out; + } + + ret =bdrv_img_create (filename, format, bs->filename, + bs->drv->format_name,NULL ,-1 , bs->open_flags); +if (ret) { + goto out; + } + +qemu_aio_flush (); +bdrv_flush (bs); + + flags = bs->open_flags; +bdrv_close (bs); + ret =bdrv_open (bs, filename, flags, drv); +/* +* If reopening the image file we just created fails, we really +* are in trouble :( +*/ +if (ret !=0 ) { +abort (); + } +out: +if (ret) { + ret =-1 ; + } + +return ret; +} +static int eject_device (Monitor *mon,BlockDriverState *bs,int force) {if (!force) {
blockdev.h +1 -0
@@ -52,5 +52,6 @@ int do_block_set_passwd(Monitor *mon, const QDict *qdict, QObject **ret_data);int do_change_block (Monitor *mon,const char *device,const char *filename,const char *fmt);int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data); +int do_snapshot_blkdev (Monitor *mon,const QDict *qdict,QObject **ret_data);#endif
hmp-commands.hx +19 -0
@@ -801,6 +801,25 @@ STEXI Set maximum tolerated downtime (in seconds) for migration. ETEXI + { + .name = "snapshot_blkdev", + .args_type = "device:s,snapshot_file:s?,format:s?", + .params = "device [new-image-file] [format]", + .help = "initiates a live snapshot\n\t\t\t" + "of device. If a new image file is specified, the\n\t\t\t" + "new image file will become the new root image.\n\t\t\t" + "If format is specified, the snapshot file will\n\t\t\t" + "be created in that format. Otherwise the\n\t\t\t" + "snapshot will be internal! (currently unsupported)", + .mhandler.cmd_new = do_snapshot_blkdev, + }, + +STEXI +@item snapshot_blkdev +@findex snapshot_blkdev +Snapshot device, using snapshot file as target if provided +ETEXI + #if defined(TARGET_I386) { .name = "drive_add",
Signature · 1 line
1.7.2.3
PATCH 21/38 Prevent creating an image with the same filename as backing file
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
--- block.c | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-)
block.c +11 -4
@@ -2764,7 +2764,7 @@ int bdrv_img_create(const char *filename, const char *fmt, char *options, uint64_t img_size, int flags) { QEMUOptionParameter *param = NULL, *create_options = NULL; -QEMUOptionParameter *backing_fmt; +QEMUOptionParameter *backing_fmt, *backing_file;BlockDriverState *bs =NULL ;BlockDriver *drv, *proto_drv;int ret =0 ;
@@ -2823,6 +2823,16 @@ int bdrv_img_create(const char *filename, const char *fmt, } } + backing_file =get_option_parameter (param,BLOCK_OPT_BACKING_FILE ); +if (backing_file && backing_file->value.s) { +if (!strcmp (filename, backing_file->value.s)) { +error_report ("Error: Trying to create an image with the " +"same filename as the backing file" ); + ret =-1 ; + goto out; + } + } + 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)) {
@@ -2836,9 +2846,6 @@ int bdrv_img_create(const char *filename, const char *fmt,// The size for the image must always be specified, with one exception: // If we are using a backing file, we can obtain the size from there if (get_option_parameter (param,BLOCK_OPT_SIZE )->value.n ==-1 ) { -QEMUOptionParameter *backing_file = -get_option_parameter (param,BLOCK_OPT_BACKING_FILE ); -if (backing_file && backing_file->value.s) {uint64_t size;const char *fmt =NULL ;
Signature · 1 line
1.7.2.3
PATCH 22/38 bdrv_img_create() use proper errno return values
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
Kevin suggested to have bdrv_img_create() return proper -errno values on error.
--- block.c | 23 ++++++++++------------- 1 files changed, 10 insertions(+), 13 deletions(-)
block.c +10 -13
@@ -2773,14 +2773,14 @@ int bdrv_img_create(const char *filename, const char *fmt, drv =bdrv_find_format (fmt);if (!drv) {error_report ("Unknown file format '%s'" , fmt); - ret =-1 ; + ret = -EINVAL ; goto out; } proto_drv =bdrv_find_protocol (filename);if (!proto_drv) {error_report ("Unknown protocol '%s'" , filename); - ret =-1 ; + ret = -EINVAL ; goto out; }
@@ -2799,7 +2799,7 @@ int bdrv_img_create(const char *filename, const char *fmt, param =parse_option_parameters (options, create_options, param);if (param ==NULL ) {error_report ("Invalid options for file format '%s'." , fmt); - ret =-1 ; + ret = -EINVAL ; goto out; } }
@@ -2809,7 +2809,7 @@ int bdrv_img_create(const char *filename, const char *fmt, base_filename)) {error_report ("Backing file not supported for file format '%s'" , fmt); - ret =-1 ; + ret = -EINVAL ; goto out; } }
@@ -2818,7 +2818,7 @@ int bdrv_img_create(const char *filename, const char *fmt,if (set_option_parameter (param,BLOCK_OPT_BACKING_FMT , base_fmt)) {error_report ("Backing file format not supported for file " "format '%s'" , fmt); - ret =-1 ; + ret = -EINVAL ; goto out; } }
@@ -2828,7 +2828,7 @@ int bdrv_img_create(const char *filename, const char *fmt,if (!strcmp (filename, backing_file->value.s)) {error_report ("Error: Trying to create an image with the " "same filename as the backing file" ); - ret =-1 ; + ret = -EINVAL ; goto out; } }
@@ -2838,7 +2838,7 @@ int bdrv_img_create(const char *filename, const char *fmt,if (!bdrv_find_format (backing_fmt->value.s)) {error_report ("Unknown backing file format '%s'" , backing_fmt->value.s); - ret =-1 ; + ret = -EINVAL ; goto out; } }
@@ -2860,7 +2860,6 @@ int bdrv_img_create(const char *filename, const char *fmt, ret =bdrv_open (bs, backing_file->value.s, flags, drv);if (ret <0 ) {error_report ("Could not open '%s'" , filename); - ret =-1 ; goto out; }bdrv_get_geometry (bs, &size);
@@ -2870,7 +2869,7 @@ int bdrv_img_create(const char *filename, const char *fmt,set_option_parameter (param,BLOCK_OPT_SIZE , buf); }else {error_report ("Image creation needs a size parameter" ); - ret =-1 ; + ret = -EINVAL ; goto out; } }
@@ -2901,8 +2900,6 @@ out:if (bs) {bdrv_delete (bs); } -if (ret) { -return 1 ; - } -return 0 ; + +return ret; }
Signature · 1 line
1.7.2.3
PATCH 23/38 qemu.img.c: Use error_report() instead of own error() implementation
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
--- qemu-img.c | 127 +++++++++++++++++++++++++++++------------------------------ 1 files changed, 62 insertions(+), 65 deletions(-)
qemu-img.c +62 -65
@@ -41,16 +41,6 @@ typedef struct img_cmd_t {/* Default to cache=writeback as data integrity is not important for qemu-tcg. */ #define BDRV_O_FLAGS BDRV_O_CACHE_WB -static void GCC_FMT_ATTR(1, 2) error(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - fprintf(stderr, "qemu-img: "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); -va_end (ap); -} -static void format_print (void *opaque,const char *name) {printf (" %s" , name);
@@ -197,13 +187,13 @@ static int print_block_option_help(const char *filename, const char *fmt)/* Find driver and parse its options */ drv =bdrv_find_format (fmt);if (!drv) { -error ("Unknown file format '%s'" , fmt); +error_report ("Unknown file format '%s'" , fmt);return 1 ; } proto_drv =bdrv_find_protocol (filename);if (!proto_drv) { -error ("Unknown protocol '%s'" , filename); +error_report ("Unknown protocol '%s'" , filename);return 1 ; }
@@ -226,30 +216,30 @@ static BlockDriverState *bdrv_new_open(const char *filename, bs =bdrv_new ("" );if (!bs) { -error ("Not enough memory" ); +error_report ("Not enough memory" ); goto fail; }if (fmt) { drv =bdrv_find_format (fmt);if (!drv) { -error ("Unknown file format '%s'" , fmt); +error_report ("Unknown file format '%s'" , fmt); goto fail; } }else { drv =NULL ; }if (bdrv_open (bs, filename, flags, drv) <0 ) { -error ("Could not open '%s'" , filename); +error_report ("Could not open '%s'" , filename); goto fail; }if (bdrv_is_encrypted (bs)) {printf ("Disk image '%s' is encrypted.\n" , filename);if (read_password (password,sizeof (password)) <0 ) { -error ("No password given" ); +error_report ("No password given" ); goto fail; }if (bdrv_set_key (bs, password) <0 ) { -error ("invalid password" ); +error_report ("invalid password" ); goto fail; } }
@@ -267,13 +257,15 @@ static int add_old_style_options(const char *fmt, QEMUOptionParameter *list, {if (base_filename) {if (set_option_parameter (list,BLOCK_OPT_BACKING_FILE , base_filename)) { -error ("Backing file not supported for file format '%s'" , fmt); +error_report ("Backing file not supported for file format '%s'" , + fmt);return -1 ; } }if (base_fmt) {if (set_option_parameter (list,BLOCK_OPT_BACKING_FMT , base_fmt)) { -error ("Backing file format not supported for file format '%s'" , fmt); +error_report ("Backing file format not supported for file " +"format '%s'" , fmt);return -1 ; } }
@@ -310,11 +302,11 @@ static int img_create(int argc, char **argv) fmt = optarg;break ;case 'e' : -error ("qemu-img: option -e is deprecated, please use \'-o " +error_report ("qemu-img: option -e is deprecated, please use \'-o " "encryption\' instead!" );return 1 ;case '6' : -error ("qemu-img: option -6 is deprecated, please use \'-o " +error_report ("qemu-img: option -6 is deprecated, please use \'-o " "compat6\' instead!" );return 1 ;case 'o' :
@@ -334,9 +326,9 @@ static int img_create(int argc, char **argv)ssize_t sval; sval =strtosz_suffix (argv[optind++],NULL ,STRTOSZ_DEFSUFFIX_B );if (sval <0 ) { -error ("Invalid image size specified! You may use k, M, G or " +error_report ("Invalid image size specified! You may use k, M, G or " "T suffixes for " ); -error ("kilobytes, megabytes, gigabytes and terabytes." ); +error_report ("kilobytes, megabytes, gigabytes and terabytes." ); ret =-1 ; goto out; }
@@ -400,7 +392,7 @@ static int img_check(int argc, char **argv) ret =bdrv_check (bs, &result);if (ret == -ENOTSUP ) { -error ("This image format does not support checks" ); +error_report ("This image format does not support checks" );bdrv_delete (bs);return 1 ; }
@@ -482,16 +474,16 @@ static int img_commit(int argc, char **argv)printf ("Image committed.\n" );break ;case -ENOENT : -error ("No disk inserted" ); +error_report ("No disk inserted" );break ;case -EACCES : -error ("Image is read-only" ); +error_report ("Image is read-only" );break ;case -ENOTSUP : -error ("Image is already committed" ); +error_report ("Image is already committed" );break ;default : -error ("Error while committing image" ); +error_report ("Error while committing image" );break ; }
@@ -614,11 +606,11 @@ static int img_convert(int argc, char **argv) compress =1 ;break ;case 'e' : -error ("qemu-img: option -e is deprecated, please use \'-o " +error_report ("qemu-img: option -e is deprecated, please use \'-o " "encryption\' instead!" );return 1 ;case '6' : -error ("qemu-img: option -6 is deprecated, please use \'-o " +error_report ("qemu-img: option -6 is deprecated, please use \'-o " "compat6\' instead!" );return 1 ;case 'o' :
@@ -643,7 +635,8 @@ static int img_convert(int argc, char **argv) }if (bs_n >1 && out_baseimg) { -error ("-B makes no sense when concatenating multiple input images" ); +error_report ("-B makes no sense when concatenating multiple input " +"images" ); ret =-1 ; goto out; }
@@ -654,7 +647,7 @@ static int img_convert(int argc, char **argv)for (bs_i =0 ; bs_i < bs_n; bs_i++) { bs[bs_i] =bdrv_new_open (argv[optind + bs_i], fmt,BDRV_O_FLAGS );if (!bs[bs_i]) { -error ("Could not open '%s'" , argv[optind + bs_i]); +error_report ("Could not open '%s'" , argv[optind + bs_i]); ret =-1 ; goto out; }
@@ -664,12 +657,12 @@ static int img_convert(int argc, char **argv)if (snapshot_name !=NULL ) {if (bs_n >1 ) { -error ("No support for concatenating multiple snapshot\n" ); +error_report ("No support for concatenating multiple snapshot\n" ); ret =-1 ; goto out; }if (bdrv_snapshot_load_tmp (bs[0 ], snapshot_name) <0 ) { -error ("Failed to load snapshot\n" ); +error_report ("Failed to load snapshot\n" ); ret =-1 ; goto out; }
@@ -678,14 +671,14 @@ static int img_convert(int argc, char **argv)/* Find driver and parse its options */ drv =bdrv_find_format (out_fmt);if (!drv) { -error ("Unknown file format '%s'" , out_fmt); +error_report ("Unknown file format '%s'" , out_fmt); ret =-1 ; goto out; } proto_drv =bdrv_find_protocol (out_filename);if (!proto_drv) { -error ("Unknown protocol '%s'" , out_filename); +error_report ("Unknown protocol '%s'" , out_filename); ret =-1 ; goto out; }
@@ -698,7 +691,7 @@ static int img_convert(int argc, char **argv)if (options) { param =parse_option_parameters (options, create_options, param);if (param ==NULL ) { -error ("Invalid options for file format '%s'." , out_fmt); +error_report ("Invalid options for file format '%s'." , out_fmt); ret =-1 ; goto out; }
@@ -724,13 +717,14 @@ static int img_convert(int argc, char **argv)get_option_parameter (param,BLOCK_OPT_ENCRYPT );if (!drv->bdrv_write_compressed) { -error ("Compression not supported for this file format" ); +error_report ("Compression not supported for this file format" ); ret =-1 ; goto out; }if (encryption && encryption->value.n) { -error ("Compression and encryption not supported at the same time" ); +error_report ("Compression and encryption not supported at " +"the same time" ); ret =-1 ; goto out; }
@@ -740,11 +734,14 @@ static int img_convert(int argc, char **argv) ret =bdrv_create (drv, out_filename, param);if (ret <0 ) {if (ret == -ENOTSUP ) { -error ("Formatting not supported for file format '%s'" , out_fmt); +error_report ("Formatting not supported for file format '%s'" , + out_fmt); }else if (ret == -EFBIG ) { -error ("The image size is too large for file format '%s'" , out_fmt); +error_report ("The image size is too large for file format '%s'" , + out_fmt); }else { -error ("%s: error while converting %s: %s" , out_filename, out_fmt,strerror (-ret)); +error_report ("%s: error while converting %s: %s" , + out_filename, out_fmt,strerror (-ret)); } goto out; }
@@ -764,12 +761,12 @@ static int img_convert(int argc, char **argv)if (compress) { ret =bdrv_get_info (out_bs, &bdi);if (ret <0 ) { -error ("could not get block driver info" ); +error_report ("could not get block driver info" ); goto out; } cluster_size = bdi.cluster_size;if (cluster_size <=0 || cluster_size >IO_BUF_SIZE ) { -error ("invalid cluster size" ); +error_report ("invalid cluster size" ); ret =-1 ; goto out; }
@@ -810,7 +807,7 @@ static int img_convert(int argc, char **argv) ret =bdrv_read (bs[bs_i], bs_num, buf2, nlow);if (ret <0 ) { -error ("error while reading" ); +error_report ("error while reading" ); goto out; }
@@ -828,7 +825,7 @@ static int img_convert(int argc, char **argv) ret =bdrv_write_compressed (out_bs, sector_num, buf, cluster_sectors);if (ret !=0 ) { -error ("error while compressing sector %" PRId64, +error_report ("error while compressing sector %" PRId64, sector_num); goto out; }
@@ -887,7 +884,7 @@ static int img_convert(int argc, char **argv) ret =bdrv_read (bs[bs_i], sector_num - bs_offset, buf, n);if (ret <0 ) { -error ("error while reading" ); +error_report ("error while reading" ); goto out; }/* NOTE: at the same time we convert, we do not write zero
@@ -906,7 +903,7 @@ static int img_convert(int argc, char **argv) is_allocated_sectors(buf1, n, &n1)) { ret =bdrv_write (out_bs, sector_num, buf1, n1);if (ret <0 ) { -error ("error while writing" ); +error_report ("error while writing" ); goto out; } }
@@ -1148,7 +1145,7 @@ static int img_snapshot(int argc, char **argv) ret =bdrv_snapshot_create (bs, &sn);if (ret) { -error ("Could not create snapshot '%s': %d (%s)" , +error_report ("Could not create snapshot '%s': %d (%s)" , snapshot_name, ret,strerror (-ret)); }break ;
@@ -1156,7 +1153,7 @@ static int img_snapshot(int argc, char **argv)case SNAPSHOT_APPLY : ret =bdrv_snapshot_goto (bs, snapshot_name);if (ret) { -error ("Could not apply snapshot '%s': %d (%s)" , +error_report ("Could not apply snapshot '%s': %d (%s)" , snapshot_name, ret,strerror (-ret)); }break ;
@@ -1164,7 +1161,7 @@ static int img_snapshot(int argc, char **argv)case SNAPSHOT_DELETE : ret =bdrv_snapshot_delete (bs, snapshot_name);if (ret) { -error ("Could not delete snapshot '%s': %d (%s)" , +error_report ("Could not delete snapshot '%s': %d (%s)" , snapshot_name, ret,strerror (-ret)); }break ;
@@ -1241,7 +1238,7 @@ static int img_rebase(int argc, char **argv)if (!unsafe && bs->backing_format[0 ] !='\0' ) { old_backing_drv =bdrv_find_format (bs->backing_format);if (old_backing_drv ==NULL ) { -error ("Invalid format name: '%s'" , bs->backing_format); +error_report ("Invalid format name: '%s'" , bs->backing_format); ret =-1 ; goto out; }
@@ -1250,7 +1247,7 @@ static int img_rebase(int argc, char **argv)if (out_basefmt !=NULL ) { new_backing_drv =bdrv_find_format (out_basefmt);if (new_backing_drv ==NULL ) { -error ("Invalid format name: '%s'" , out_basefmt); +error_report ("Invalid format name: '%s'" , out_basefmt); ret =-1 ; goto out; }
@@ -1269,7 +1266,7 @@ static int img_rebase(int argc, char **argv) ret =bdrv_open (bs_old_backing, backing_name,BDRV_O_FLAGS , old_backing_drv);if (ret) { -error ("Could not open old backing file '%s'" , backing_name); +error_report ("Could not open old backing file '%s'" , backing_name); goto out; }
@@ -1277,7 +1274,7 @@ static int img_rebase(int argc, char **argv) ret =bdrv_open (bs_new_backing, out_baseimg,BDRV_O_FLAGS , new_backing_drv);if (ret) { -error ("Could not open new backing file '%s'" , out_baseimg); +error_report ("Could not open new backing file '%s'" , out_baseimg); goto out; } }
@@ -1321,12 +1318,12 @@ static int img_rebase(int argc, char **argv)/* Read old and new backing file */ ret =bdrv_read (bs_old_backing, sector, buf_old, n);if (ret <0 ) { -error ("error while reading from old backing file" ); +error_report ("error while reading from old backing file" ); goto out; } ret =bdrv_read (bs_new_backing, sector, buf_new, n);if (ret <0 ) { -error ("error while reading from new backing file" ); +error_report ("error while reading from new backing file" ); goto out; }
@@ -1342,7 +1339,7 @@ static int img_rebase(int argc, char **argv) ret =bdrv_write (bs, sector + written, buf_old + written *512 , pnum);if (ret <0 ) { -error ("Error while writing to COW image: %s" , +error_report ("Error while writing to COW image: %s" ,strerror (-ret)); goto out; }
@@ -1363,10 +1360,10 @@ static int img_rebase(int argc, char **argv)*/ ret =bdrv_change_backing_file (bs, out_baseimg, out_basefmt);if (ret == -ENOSPC ) { -error ("Could not change the backing file to '%s': No space left in " -"the file header" , out_baseimg); +error_report ("Could not change the backing file to '%s': No " +"space left in the file header" , out_baseimg); }else if (ret <0 ) { -error ("Could not change the backing file to '%s': %s" , +error_report ("Could not change the backing file to '%s': %s" , out_baseimg,strerror (-ret)); }
@@ -1465,7 +1462,7 @@ static int img_resize(int argc, char **argv) total_size = n; }if (total_size <=0 ) { -error ("New image size must be positive" ); +error_report ("New image size must be positive" ); ret =-1 ; goto out; }
@@ -1476,13 +1473,13 @@ static int img_resize(int argc, char **argv)printf ("Image resized.\n" );break ;case -ENOTSUP : -error ("This image format does not support resize" ); +error_report ("This image format does not support resize" );break ;case -EACCES : -error ("Image is read-only" ); +error_report ("Image is read-only" );break ;default : -error ("Error resizing image (%d)" , -ret); +error_report ("Error resizing image (%d)" , -ret);break ; } out:
Signature · 1 line
1.7.2.3
PATCH 24/38 Remove NULL checks for bdrv_new return value
In reply to Kevin WolfIt's an indirect call to qemu_malloc, which never returns an error.
--- hw/xen_disk.c | 17 ++++++----------- qemu-img.c | 5 +---- qemu-io.c | 2 -- qemu-nbd.c | 2 -- 4 files changed, 7 insertions(+), 19 deletions(-)
hw/xen_disk.c +6 -11
@@ -634,17 +634,12 @@ static int blk_init(struct XenDevice *xendev)if (!blkdev->dinfo) {/* setup via xenbus -> create new block driver instance */ xen_be_printf (&blkdev->xendev,2 ,"create new bdrv (xenbus setup)\n" ); - blkdev->bs =bdrv_new (blkdev->dev); -if (blkdev->bs) { -if (bdrv_open (blkdev->bs, blkdev->filename, qflags, -bdrv_find_whitelisted_format (blkdev->fileproto)) - !=0 ) { -bdrv_delete (blkdev->bs); - blkdev->bs =NULL ; - } - } -if (!blkdev->bs) -return -1 ; + blkdev->bs =bdrv_new (blkdev->dev); +if (bdrv_open (blkdev->bs, blkdev->filename, qflags, +bdrv_find_whitelisted_format (blkdev->fileproto)) !=0 ) { +bdrv_delete (blkdev->bs); +return -1 ; + } }else {/* setup via qemu cmdline -> already setup for us */ xen_be_printf (&blkdev->xendev,2 ,"get configured bdrv (cmdline setup)\n" );
qemu-img.c +1 -4
@@ -215,10 +215,7 @@ static BlockDriverState *bdrv_new_open(const char *filename,char password[256 ]; bs =bdrv_new ("" ); -if (!bs) { -error_report ("Not enough memory" ); - goto fail; - } +if (fmt) { drv =bdrv_find_format (fmt);if (!drv) {
qemu-io.c +0 -2
@@ -1509,8 +1509,6 @@ static int openfile(char *name, int flags, int growable) } }else { bs =bdrv_new ("hda" ); -if (!bs) -return 1 ;if (bdrv_open (bs, name, flags,NULL ) <0 ) {fprintf (stderr,"%s: can't open device %s\n" , progname, name);
qemu-nbd.c +0 -2
@@ -336,8 +336,6 @@ int main(int argc, char **argv)bdrv_init (); bs =bdrv_new ("hda" ); -if (bs ==NULL ) -return 1 ;if ((ret =bdrv_open (bs, argv[optind], flags,NULL )) <0 ) { errno = -ret;
Signature · 1 line
1.7.2.3
PATCH 25/38 ide: Register vm change state handler once only
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
We register the vm change state handler in a PCI BAR map() function. This function can be called multiple times throughout the lifetime of a PCI IDE device. This results in duplicate vm change state handlers being register, none of which are ever unregistered.
Instead, register the vm change state handler in the device's init function once and for all.
piix tested, cmd646 and via not tested.
--- hw/ide/cmd646.c | 18 ++++++++++-------- hw/ide/piix.c | 34 ++++++++++++++++++++++++---------- hw/ide/via.c | 34 ++++++++++++++++++++++++---------- 3 files changed, 58 insertions(+), 28 deletions(-)
hw/ide/cmd646.c +10 -8
@@ -167,10 +167,6 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,for (i =0 ;i <2 ; i++) {BMDMAState *bm = &d->bmdma[i]; -bmdma_init (&d->bus[i], bm); - bm->bus = d->bus+i; -qemu_add_vm_change_state_handler (d->bus[i].dma->ops->restart_cb, - &bm->dma);if (i ==0 ) {register_ioport_write (addr,4 ,1 , bmdma_writeb_0, d);
@@ -228,6 +224,7 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev)PCIIDEState *d =DO_UPCAST (PCIIDEState, dev, dev);uint8_t *pci_conf = d->dev.config;qemu_irq *irq; +int i;pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_CMD );pci_config_set_device_id (pci_conf,PCI_DEVICE_ID_CMD_646 );
@@ -253,10 +250,15 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev) pci_conf[PCI_INTERRUPT_PIN ] =0x01 ;// interrupt on pin 1 irq =qemu_allocate_irqs (cmd646_set_irq, d,2 ); -ide_bus_new (&d->bus[0 ], &d->dev.qdev,0 ); -ide_bus_new (&d->bus[1 ], &d->dev.qdev,1 ); -ide_init2 (&d->bus[0 ], irq[0 ]); -ide_init2 (&d->bus[1 ], irq[1 ]); +for (i =0 ; i <2 ; i++) { +ide_bus_new (&d->bus[i], &d->dev.qdev, i); +ide_init2 (&d->bus[i], irq[i]); + +bmdma_init (&d->bus[i], &d->bmdma[i]); + bm->bus = &d->bus[i]; +qemu_add_vm_change_state_handler (d->bus[i].dma->ops->restart_cb, + &d->bmdma[i]->dma); + }vmstate_register (&dev->qdev,0 , &vmstate_ide_pci, d);qemu_register_reset (cmd646_reset, d);
hw/ide/piix.c +24 -10
@@ -76,10 +76,6 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,for (i =0 ;i <2 ; i++) {BMDMAState *bm = &d->bmdma[i]; -bmdma_init (&d->bus[i], bm); - bm->bus = d->bus+i; -qemu_add_vm_change_state_handler (d->bus[i].dma->ops->restart_cb, - &bm->dma);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
@@ -112,6 +108,29 @@ static void piix3_reset(void *opaque) pci_conf[0x20 ] =0x01 ;/* BMIBA: 20-23h */ } +static void pci_piix_init_ports (PCIIDEState *d) { +int i; +struct { +int iobase; +int iobase2; +int isairq; + } port_info[] = { + {0x1f0 ,0x3f6 ,14 }, + {0x170 ,0x376 ,15 }, + }; + +for (i =0 ; i <2 ; i++) { +ide_bus_new (&d->bus[i], &d->dev.qdev, i); +ide_init_ioport (&d->bus[i], port_info[i].iobase, port_info[i].iobase2); +ide_init2 (&d->bus[i],isa_reserve_irq (port_info[i].isairq)); + +bmdma_init (&d->bus[i], &d->bmdma[i]); + d->bmdma[i].bus = &d->bus[i]; +qemu_add_vm_change_state_handler (d->bus[i].dma->ops->restart_cb, + &d->bmdma[i].dma); + } +} +static int pci_piix_ide_initfn (PCIIDEState *d) {uint8_t *pci_conf = d->dev.config;
@@ -125,13 +144,8 @@ static int pci_piix_ide_initfn(PCIIDEState *d)vmstate_register (&d->dev.qdev,0 , &vmstate_ide_pci, d); -ide_bus_new (&d->bus[0 ], &d->dev.qdev,0 ); -ide_bus_new (&d->bus[1 ], &d->dev.qdev,1 ); -ide_init_ioport (&d->bus[0 ],0x1f0 ,0x3f6 ); -ide_init_ioport (&d->bus[1 ],0x170 ,0x376 ); +pci_piix_init_ports (d); -ide_init2 (&d->bus[0 ],isa_reserve_irq (14 )); -ide_init2 (&d->bus[1 ],isa_reserve_irq (15 ));return 0 ; }
hw/ide/via.c +24 -10
@@ -78,10 +78,6 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,for (i =0 ;i <2 ; i++) {BMDMAState *bm = &d->bmdma[i]; -bmdma_init (&d->bus[i], bm); - bm->bus = d->bus+i; -qemu_add_vm_change_state_handler (d->bus[i].dma->ops->restart_cb, - &bm->dma);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
@@ -135,6 +131,29 @@ static void via_reset(void *opaque)pci_set_long (pci_conf +0xc0 ,0x00020001 ); } +static void vt82c686b_init_ports (PCIIDEState *d) { +int i; +struct { +int iobase; +int iobase2; +int isairq; + } port_info[] = { + {0x1f0 ,0x3f6 ,14 }, + {0x170 ,0x376 ,15 }, + }; + +for (i =0 ; i <2 ; i++) { +ide_bus_new (&d->bus[i], &d->dev.qdev, i); +ide_init_ioport (&d->bus[i], port_info[i].iobase, port_info[i].iobase2); +ide_init2 (&d->bus[i],isa_reserve_irq (port_info[i].isairq)); + +bmdma_init (&d->bus[i], &d->bmdma[i]); + d->bmdma[i].bus = &d->bus[i]; +qemu_add_vm_change_state_handler (d->bus[i].dma->ops->restart_cb, + &d->bmdma[i]->dma); + } +} +/* via ide func */ static int vt82c686b_ide_initfn (PCIDevice *dev) {
@@ -154,12 +173,7 @@ static int vt82c686b_ide_initfn(PCIDevice *dev)vmstate_register (&dev->qdev,0 , &vmstate_ide_pci, d); -ide_bus_new (&d->bus[0 ], &d->dev.qdev,0 ); -ide_bus_new (&d->bus[1 ], &d->dev.qdev,1 ); -ide_init2 (&d->bus[0 ],isa_reserve_irq (14 )); -ide_init2 (&d->bus[1 ],isa_reserve_irq (15 )); -ide_init_ioport (&d->bus[0 ],0x1f0 ,0x3f6 ); -ide_init_ioport (&d->bus[1 ],0x170 ,0x376 ); +vt82c686b_init_ports (d);return 0 ; }
Signature · 1 line
1.7.2.3
PATCH 26/38 block: add discard support
In reply to Kevin WolfFrom: Christoph Hellwig <[email protected]>
Add a new bdrv_discard method to free blocks in a mapping image, and a new drive property to set the granularity for these discard. If no discard granularity support is set discard support is disabled.
--- block.c | 11 +++++++++++ block.h | 1 + block/raw.c | 6 ++++++ block_int.h | 7 ++++++- 4 files changed, 24 insertions(+), 1 deletions(-)
block.c +11 -0
@@ -1515,6 +1515,17 @@ int bdrv_has_zero_init(BlockDriverState *bs)return 1 ; } +int bdrv_discard (BlockDriverState *bs,int64_t sector_num,int nb_sectors) +{ +if (!bs->drv) { +return -ENOMEDIUM ; + } +if (!bs->drv->bdrv_discard) { +return 0 ; + } +return bs->drv->bdrv_discard (bs, sector_num, nb_sectors); +} +/* * 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
@@ -146,6 +146,7 @@ int bdrv_flush(BlockDriverState *bs);void bdrv_flush_all (void );void bdrv_close_all (void ); +int bdrv_discard (BlockDriverState *bs,int64_t sector_num,int nb_sectors);int bdrv_has_zero_init (BlockDriverState *bs);int bdrv_is_allocated (BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum);
block/raw.c +6 -0
@@ -65,6 +65,11 @@ static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)return 1 ;/* everything can be opened as raw image */ } +static int raw_discard (BlockDriverState *bs,int64_t sector_num,int nb_sectors) +{ +return bdrv_discard (bs->file, sector_num, nb_sectors); +} +static int raw_is_inserted (BlockDriverState *bs) {return bdrv_is_inserted (bs->file);
@@ -130,6 +135,7 @@ static BlockDriver bdrv_raw = { .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev, .bdrv_aio_flush = raw_aio_flush, + .bdrv_discard = raw_discard, .bdrv_is_inserted = raw_is_inserted, .bdrv_eject = raw_eject,
block_int.h +6 -1
@@ -72,6 +72,8 @@ struct BlockDriver { BlockDriverCompletionFunc *cb, void *opaque); BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque); +int (*bdrv_discard)(BlockDriverState *bs,int64_t sector_num, +int nb_sectors);int (*bdrv_aio_multiwrite)(BlockDriverState *bs,BlockRequest *reqs,int num_reqs);
@@ -227,6 +229,7 @@ typedef struct BlockConf {uint16_t min_io_size;uint32_t opt_io_size;int32_t bootindex; +uint32_t discard_granularity; } BlockConf;static inline unsigned int get_physical_block_exp (BlockConf *conf)
@@ -250,6 +253,8 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) _conf.physical_block_size, 512), \DEFINE_PROP_UINT16 ("min_io_size" , _state, _conf.min_io_size,0 ), \DEFINE_PROP_UINT32 ("opt_io_size" , _state, _conf.opt_io_size,0 ), \ - DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1) \ +DEFINE_PROP_INT32 ("bootindex" , _state, _conf.bootindex,-1 ), \ +DEFINE_PROP_UINT32 ("discard_granularity" , _state, \ + _conf.discard_granularity, 0)#endif /* BLOCK_INT_H */
Signature · 1 line
1.7.2.3
PATCH 27/38 scsi-disk: support WRITE SAME (16) with unmap bit
In reply to Kevin WolfFrom: Christoph Hellwig <[email protected]>
Support discards via the WRITE SAME command with the unmap bit set, and tell the initiator about the support for it via the block limit and the new thin provisioning EVPD pages. Also fix the comment which incorrectly describedthe block limits EVPD page.
--- hw/scsi-defs.h | 1 + hw/scsi-disk.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-)
hw/scsi-defs.h +1 -0
@@ -84,6 +84,7 @@#define MODE_SENSE_10 0x5a#define PERSISTENT_RESERVE_IN 0x5e#define PERSISTENT_RESERVE_OUT 0x5f +#define WRITE_SAME_16 0x93#define MAINTENANCE_IN 0xa3#define MAINTENANCE_OUT 0xa4#define MOVE_MEDIUM 0xa5
hw/scsi-disk.c +51 -2
84 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 28/38 qemu-io: Add discard command
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
discard [-Cq] off len -- discards a number of bytes at a specified offset
discards a range of bytes from the given offset
Example:
'discard 512 1k' - discards 1 kilobyte from 512 bytes into the file
Discards a segment of the currently open file. -C, -- report statistics in a machine parsable format -q, -- quite mode, do not show I/O statistics
--- qemu-io.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 88 insertions(+), 0 deletions(-)
qemu-io.c +88 -0
@@ -1394,6 +1394,93 @@ static const cmdinfo_t info_cmd = { .oneline = "prints information about the current file", }; +static void +discard_help (void ) +{ +printf ( +"\n" +" discards a range of bytes from the given offset\n" +"\n" +" Example:\n" +" 'discard 512 1k' - discards 1 kilobyte from 512 bytes into the file\n" +"\n" +" Discards a segment of the currently open file.\n" +" -C, -- report statistics in a machine parsable format\n" +" -q, -- quite mode, do not show I/O statistics\n" +"\n" ); +} + +static int discard_f (int argc,char **argv); + +static const cmdinfo_t discard_cmd = { + .name ="discard" , + .altname ="d" , + .cfunc = discard_f, + .argmin =2 , + .argmax =-1 , + .args ="[-Cq] off len" , + .oneline ="discards a number of bytes at a specified offset" , + .help = discard_help, +}; + +static int +discard_f (int argc,char **argv) +{ +struct timeval t1, t2; +int Cflag =0 , qflag =0 ; +int c, ret; +int64_t offset; +int count; + +while ((c =getopt (argc, argv,"Cq" )) !=EOF ) { +switch (c) { +case 'C' : + Cflag =1 ; +break ; +case 'q' : + qflag =1 ; +break ; +default : +return command_usage (&discard_cmd); + } + } + +if (optind != argc -2 ) { +return command_usage (&discard_cmd); + } + + offset =cvtnum (argv[optind]); +if (offset <0 ) { +printf ("non-numeric length argument -- %s\n" , argv[optind]); +return 0 ; + } + + optind++; + count =cvtnum (argv[optind]); +if (count <0 ) { +printf ("non-numeric length argument -- %s\n" , argv[optind]); +return 0 ; + } + +gettimeofday (&t1,NULL ); + ret =bdrv_discard (bs, offset, count); +gettimeofday (&t2,NULL ); + +if (ret <0 ) { +printf ("discard failed: %s\n" ,strerror (-ret)); + goto out; + } + +/* Finally, report back -- -C gives a parsable format */ +if (!qflag) { + t2 =tsub (t2, t1); +print_report ("discard" , &t2, offset, count, count,1 , Cflag); + } + +out: +return 0 ; +} +static int alloc_f (int argc,char **argv) {
@@ -1715,6 +1802,7 @@ int main(int argc, char **argv)add_command (&truncate_cmd);add_command (&length_cmd);add_command (&info_cmd); +add_command (&discard_cmd);add_command (&alloc_cmd);add_command (&map_cmd);
Signature · 1 line
1.7.2.3
PATCH 29/38 raw-posix: add discard support
In reply to Kevin WolfFrom: Christoph Hellwig <[email protected]>
Add support to discard blocks in a raw image residing on an XFS filesystem by calling the XFS_IOC_UNRESVSP64 ioctl to punch holes. Support for other hole punching mechanisms can be added when they become available.
--- block/raw-posix.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ configure | 26 ++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 0 deletions(-)
block/raw-posix.c +45 -0
@@ -69,6 +69,10 @@#include <sys/diskslice.h> #endif +#ifdef CONFIG_XFS +#include <xfs/xfs.h> +#endif +//#define DEBUG_FLOPPY //#define DEBUG_BLOCK
@@ -120,6 +124,9 @@ typedef struct BDRVRawState {#endif uint8_t *aligned_buf;unsigned aligned_buf_size; +#ifdef CONFIG_XFS + bool is_xfs : 1; +#endif } BDRVRawState;static int fd_open (BlockDriverState *bs);
@@ -196,6 +203,12 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,#endif } +#ifdef CONFIG_XFS +if (platform_test_xfs_fd (s->fd)) { + s->is_xfs =1 ; + } +#endif +return 0 ; out_free_buf:
@@ -740,6 +753,37 @@ static int raw_flush(BlockDriverState *bs)return qemu_fdatasync (s->fd); } +#ifdef CONFIG_XFS +static int xfs_discard (BDRVRawState *s,int64_t sector_num,int nb_sectors) +{ +struct xfs_flock64 fl; + +memset (&fl,0 ,sizeof (fl)); + fl.l_whence =SEEK_SET ; + fl.l_start = sector_num <<9 ; + fl.l_len = (int64_t )nb_sectors <<9 ; + +if (xfsctl (NULL , s->fd,XFS_IOC_UNRESVSP64 , &fl) <0 ) { +DEBUG_BLOCK_PRINT ("cannot punch hole (%s)\n" ,strerror (errno)); +return -errno; + } + +return 0 ; +} +#endif + +static int raw_discard (BlockDriverState *bs,int64_t sector_num,int nb_sectors) +{ +#ifdef CONFIG_XFS +BDRVRawState *s = bs->opaque; + +if (s->is_xfs) { +return xfs_discard (s, sector_num, nb_sectors); + } +#endif + +return 0 ; +}static QEMUOptionParameter raw_create_options[] = { {
@@ -761,6 +805,7 @@ static BlockDriver bdrv_file = { .bdrv_close = raw_close, .bdrv_create = raw_create, .bdrv_flush = raw_flush, + .bdrv_discard = raw_discard, .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev,
configure +26 -0
@@ -288,6 +288,7 @@ xen="" linux_aio="" attr="" vhost_net="" +xfs="" gprof="no" debug_tcg="no"
@@ -1399,6 +1400,27 @@ EOF fi ########################################## +# xfsctl() probe, used for raw-posix +if test "$xfs" != "no" ; then + cat > $TMPC << EOF +#include <xfs/xfs.h> +int main(void) +{ + xfsctl(NULL, 0, 0, NULL); + return 0; +} +EOF + if compile_prog "" "" ; then + xfs="yes" + else + if test "$xfs" = "yes" ; then + feature_not_found "xfs" + fi + xfs=no + fi +fi + +########################################## # vde libraries probe if test "$vde" != "no" ; then vde_libs="-lvdeplug"
@@ -2403,6 +2425,7 @@ echo "Trace backend $trace_backend" echo "Trace output file $trace_file-<pid>" echo "spice support $spice" echo "rbd support $rbd" +echo "xfsctl support $xfs" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2548,6 +2571,9 @@ fi if test "$uuid" = "yes" ; then echo "CONFIG_UUID=y" >> $config_host_mak fi +if test "$xfs" = "yes" ; then + echo "CONFIG_XFS=y" >> $config_host_mak +fi qemu_version=`head $source_path/VERSION` echo "VERSION=$qemu_version" >>$config_host_mak echo "PKGVERSION=$pkgversion" >>$config_host_mak
Signature · 1 line
1.7.2.3
PATCH 30/38 qemu-io: Fix typo in help texts
In reply to Kevin Wolf--- qemu-io.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
qemu-io.c +7 -7
@@ -326,7 +326,7 @@ read_help(void)" -l, -- length for pattern verification (only with -P)\n" " -p, -- use bdrv_pread to read the file\n" " -P, -- use a pattern to verify read data\n" -" -q, -- quite mode, do not show I/O statistics\n" +" -q, -- quiet mode, do not show I/O statistics\n" " -s, -- start offset for pattern verification (only with -P)\n" " -v, -- dump buffer to standard output\n" "\n");
@@ -509,7 +509,7 @@ readv_help(void)" -C, -- report statistics in a machine parsable format\n" " -P, -- use a pattern to verify read data\n" " -v, -- dump buffer to standard output\n" -" -q, -- quite mode, do not show I/O statistics\n" +" -q, -- quiet mode, do not show I/O statistics\n" "\n"); }
@@ -633,7 +633,7 @@ write_help(void)" -p, -- use bdrv_pwrite to write the file\n" " -P, -- use different pattern to fill file\n" " -C, -- report statistics in a machine parsable format\n" -" -q, -- quite mode, do not show I/O statistics\n" +" -q, -- quiet mode, do not show I/O statistics\n" "\n"); }
@@ -765,7 +765,7 @@ writev_help(void)" filled with a set pattern (0xcdcdcdcd).\n" " -P, -- use different pattern to fill file\n" " -C, -- report statistics in a machine parsable format\n" -" -q, -- quite mode, do not show I/O statistics\n" +" -q, -- quiet mode, do not show I/O statistics\n" "\n"); }
@@ -1100,7 +1100,7 @@ aio_read_help(void)" -C, -- report statistics in a machine parsable format\n" " -P, -- use a pattern to verify read data\n" " -v, -- dump buffer to standard output\n" -" -q, -- quite mode, do not show I/O statistics\n" +" -q, -- quiet mode, do not show I/O statistics\n" "\n"); }
@@ -1198,7 +1198,7 @@ aio_write_help(void)" used to ensure all outstanding aio requests have been completed\n" " -P, -- use different pattern to fill file\n" " -C, -- report statistics in a machine parsable format\n" -" -q, -- quite mode, do not show I/O statistics\n" +" -q, -- quiet mode, do not show I/O statistics\n" "\n"); }
@@ -1406,7 +1406,7 @@ discard_help(void)"\n" " Discards a segment of the currently open file.\n" " -C, -- report statistics in a machine parsable format\n" -" -q, -- quite mode, do not show I/O statistics\n" +" -q, -- quiet mode, do not show I/O statistics\n" "\n"); }
Signature · 1 line
1.7.2.3
PATCH 31/38 docs: Add QED image format specification
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
--- docs/specs/qed_spec.txt | 130 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 130 insertions(+), 0 deletions(-) create mode 100644 docs/specs/qed_spec.txt
docs/specs/qed_spec.txt new file +130 -0
@@ -0,0 +1,130 @@ +=Specification= + +The file format looks like this: + + +----------+----------+----------+-----+ + | cluster0 | cluster1 | cluster2 | ... | + +----------+----------+----------+-----+ + +The first cluster begins with the '''header'''. The header contains information about where regular clusters start; this allows the header to be extensible and store extra information about the image file. A regular cluster may be a '''data cluster''', an '''L2''', or an '''L1 table'''. L1 and L2 tables are composed of one or more contiguous clusters. + +Normally the file size will be a multiple of the cluster size. If the file size is not a multiple, extra information after the last cluster may not be preserved if data is written. Legitimate extra information should use space between the header and the first regular cluster. + +All fields are little-endian. + +==Header== + Header { + uint32_t magic; /* QED\0 */ + + uint32_t cluster_size; /* in bytes */ + uint32_t table_size; /* for L1 and L2 tables, in clusters */ + uint32_t header_size; /* in clusters */ + + uint64_t features; /* format feature bits */ + uint64_t compat_features; /* compat feature bits */ + uint64_t autoclear_features; /* self-resetting feature bits */ + + uint64_t l1_table_offset; /* in bytes */ + uint64_t image_size; /* total logical image size, in bytes */ + + /* if (features & QED_F_BACKING_FILE) */ + uint32_t backing_filename_offset; /* in bytes from start of header */ + uint32_t backing_filename_size; /* in bytes */ + } + +Field descriptions: +* ''cluster_size'' must be a power of 2 in range [212, 226]. +* ''table_size'' must be a power of 2 in range [1, 16]. +* ''header_size'' is the number of clusters used by the header and any additional information stored before regular clusters. +* ''features'', ''compat_features'', and ''autoclear_features'' are file format extension bitmaps. They work as follows: +** An image with unknown ''features'' bits enabled must not be opened. File format changes that are not backwards-compatible must use ''features'' bits. +** An image with unknown ''compat_features'' bits enabled can be opened safely. The unknown features are simply ignored and represent backwards-compatible changes to the file format. +** An image with unknown ''autoclear_features'' bits enable can be opened safely after clearing the unknown bits. This allows for backwards-compatible changes to the file format which degrade gracefully and can be re-enabled again by a new program later. +* ''l1_table_offset'' is the offset of the first byte of the L1 table in the image file and must be a multiple of ''cluster_size''. +* ''image_size'' is the block device size seen by the guest and must be a multiple of 512 bytes. +* ''backing_filename_offset'' and ''backing_filename_size'' describe a string in (byte offset, byte size) form. It is not NUL-terminated and has no alignment constraints. The string must be stored within the first ''header_size'' clusters. The backing filename may be an absolute path or relative to the image file. + +Feature bits: +* QED_F_BACKING_FILE = 0x01. The image uses a backing file. +* QED_F_NEED_CHECK = 0x02. The image needs a consistency check before use. +* QED_F_BACKING_FORMAT_NO_PROBE = 0x04. The backing file is a raw disk image and no file format autodetection should be attempted. This should be used to ensure that raw backing files are never detected as an image format if they happen to contain magic constants. + +There are currently no defined ''compat_features'' or ''autoclear_features'' bits. + +Fields predicated on a feature bit are only used when that feature is set. The fields always take up header space, regardless of whether or not the feature bit is set. + +==Tables== + +Tables provide the translation from logical offsets in the block device to cluster offsets in the file. + + #define TABLE_NOFFSETS (table_size * cluster_size / sizeof(uint64_t)) + + Table { + uint64_t offsets[TABLE_NOFFSETS]; + } + +The tables are organized as follows: + + +----------+ + | L1 table | + +----------+ + ,------' | '------. + +----------+ | +----------+ + | L2 table | ... | L2 table | + +----------+ +----------+ + ,------' | '------. + +----------+ | +----------+ + | Data | ... | Data | + +----------+ +----------+ + +A table is made up of one or more contiguous clusters. The table_size header field determines table size for an image file. For example, cluster_size=64 KB and table_size=4 results in 256 KB tables. + +The logical image size must be less than or equal to the maximum possible size of clusters rooted by the L1 table: + header.image_size <= TABLE_NOFFSETS * TABLE_NOFFSETS * header.cluster_size + +L1, L2, and data cluster offsets must be aligned to header.cluster_size. The following offsets have special meanings: + +===L2 table offsets=== +* 0 - unallocated. The L2 table is not yet allocated. + +===Data cluster offsets=== +* 0 - unallocated. The data cluster is not yet allocated. + +Future format extensions may wish to store per-offset information. The least significant 12 bits of an offset are reserved for this purpose and must be set to zero. Image files with cluster_size > 212 will have more unused bits which should also be zeroed. + +===Unallocated L2 tables and data clusters=== +Reads to an unallocated area of the image file access the backing file. If there is no backing file, then zeroes are produced. The backing file may be smaller than the image file and reads of unallocated areas beyond the end of the backing file produce zeroes. + +Writes to an unallocated area cause a new data clusters to be allocated, and a new L2 table if that is also unallocated. The new data cluster is populated with data from the backing file (or zeroes if no backing file) and the data being written. + +===Logical offset translation=== +Logical offsets are translated into cluster offsets as follows: + + table_bits table_bits cluster_bits + <--------> <--------> <---------------> + +----------+----------+-----------------+ + | L1 index | L2 index | byte offset | + +----------+----------+-----------------+ + + Structure of a logical offset + + offset_mask = ~(cluster_size - 1) # mask for the image file byte offset + + def logical_to_cluster_offset(l1_index, l2_index, byte_offset): + l2_offset = l1_table[l1_index] + l2_table = load_table(l2_offset) + cluster_offset = l2_table[l2_index] & offset_mask + return cluster_offset + byte_offset + +==Consistency checking== + +This section is informational and included to provide background on the use of the QED_F_NEED_CHECK ''features'' bit. + +The QED_F_NEED_CHECK bit is used to mark an image as dirty before starting an operation that could leave the image in an inconsistent state if interrupted by a crash or power failure. A dirty image must be checked on open because its metadata may not be consistent. + +Consistency check includes the following invariants: +# Each cluster is referenced once and only once. It is an inconsistency to have a cluster referenced more than once by L1 or L2 tables. A cluster has been leaked if it has no references. +# Offsets must be within the image file size and must be ''cluster_size'' aligned. +# Table offsets must at least ''table_size'' * ''cluster_size'' bytes from the end of the image file so that there is space for the entire table. + +The consistency check process starts by from ''l1_table_offset'' and scans all L2 tables. After the check completes with no other errors besides leaks, the QED_F_NEED_CHECK bit can be cleared and the image can be accessed.
Signature · 1 line
1.7.2.3
PATCH 32/38 qed: Add QEMU Enhanced Disk image format
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
This patch introduces the qed on-disk layout and implements image creation. Later patches add read/write and other functionality.
--- Makefile.objs | 1 + block/qed.c | 554 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ block/qed.h | 148 +++++++++++++++ block_int.h | 1 + 4 files changed, 704 insertions(+), 0 deletions(-) create mode 100644 block/qed.c create mode 100644 block/qed.h
Makefile.objs +1 -0
@@ -20,6 +20,7 @@ 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 += qed.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o
block/qed.c new file +554 -0
554 lines not on this page · raw message
block/qed.h new file +148 -0
148 lines not on this page · raw message
block_int.h +1 -0
@@ -37,6 +37,7 @@#define BLOCK_OPT_BACKING_FILE "backing_file"#define BLOCK_OPT_BACKING_FMT "backing_fmt"#define BLOCK_OPT_CLUSTER_SIZE "cluster_size" +#define BLOCK_OPT_TABLE_SIZE "table_size"#define BLOCK_OPT_PREALLOC "preallocation" typedef struct AIOPool {
Signature · 1 line
1.7.2.3
PATCH 33/38 qed: Table, L2 cache, and cluster functions
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
This patch adds code to look up data cluster offsets in the image via the L1/L2 tables. The L2 tables are writethrough cached in memory for performance (each read/write requires a lookup so it is essential to cache the tables).
With cluster lookup code in place it is possible to implement bdrv_is_allocated() to query the number of contiguous allocated/unallocated clusters.
--- Makefile.objs | 2 +- block/qed-cluster.c | 154 ++++++++++++++++++++++++ block/qed-gencb.c | 32 +++++ block/qed-l2-cache.c | 173 +++++++++++++++++++++++++++ block/qed-table.c | 319 ++++++++++++++++++++++++++++++++++++++++++++++++++ block/qed.c | 54 +++++++++- block/qed.h | 123 +++++++++++++++++++ trace-events | 11 ++ 8 files changed, 866 insertions(+), 2 deletions(-) create mode 100644 block/qed-cluster.c create mode 100644 block/qed-gencb.c create mode 100644 block/qed-l2-cache.c create mode 100644 block/qed-table.c
Makefile.objs +1 -1
@@ -20,7 +20,7 @@ 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 += qed.o +block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o
block/qed-cluster.c new file +154 -0
154 lines not on this page · raw message
block/qed-gencb.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* QEMU Enhanced Disk Format +* +* Copyright IBM, Corp. 2010 +* +* Authors: +* Stefan Hajnoczi <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#include "qed.h" + +void *gencb_alloc (size_t len,BlockDriverCompletionFunc *cb,void *opaque) +{ +GenericCB *gencb =qemu_malloc (len); + gencb->cb = cb; + gencb->opaque = opaque; +return gencb; +} + +void gencb_complete (void *opaque,int ret) +{ +GenericCB *gencb = opaque; +BlockDriverCompletionFunc *cb = gencb->cb; +void *user_opaque = gencb->opaque; + +qemu_free (gencb); +cb (user_opaque, ret); +}
block/qed-l2-cache.c new file +173 -0
173 lines not on this page · raw message
block/qed-table.c new file +319 -0
319 lines not on this page · raw message
block/qed.c +53 -1
80 lines not on this page · raw message
block/qed.h +123 -0
145 lines not on this page · raw message
trace-events +11 -0
@@ -192,3 +192,14 @@ disable sun4m_iommu_bad_addr(uint64_t addr) "bad addr %"PRIx64"" # vl.c disable vm_state_notify(int running, int reason) "running %d reason %d" + +# block/qed-l2-cache.c +disable qed_alloc_l2_cache_entry(void *l2_cache, void *entry) "l2_cache %p entry %p" +disable qed_unref_l2_cache_entry(void *entry, int ref) "entry %p ref %d" +disable qed_find_l2_cache_entry(void *l2_cache, void *entry, uint64_t offset, int ref) "l2_cache %p entry %p offset %"PRIu64" ref %d" + +# block/qed-table.c +disable qed_read_table(void *s, uint64_t offset, void *table) "s %p offset %"PRIu64" table %p" +disable qed_read_table_cb(void *s, void *table, int ret) "s %p table %p ret %d" +disable qed_write_table(void *s, uint64_t offset, void *table, unsigned int index, unsigned int n) "s %p offset %"PRIu64" table %p index %u n %u" +disable qed_write_table_cb(void *s, void *table, int flush, int ret) "s %p table %p flush %d ret %d"
Signature · 1 line
1.7.2.3
PATCH 34/38 qed: Read/write support
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
This patch implements the read/write state machine. Operations are fully asynchronous and multiple operations may be active at any time.
Allocating writes lock tables to ensure metadata updates do not interfere with each other. If two allocating writes need to update the same L2 table they will run sequentially. If two allocating writes need to update different L2 tables they will run in parallel.
--- Makefile.objs | 1 + block/qed.c | 628 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- block/qed.h | 26 +++ trace-events | 10 + 4 files changed, 663 insertions(+), 2 deletions(-)
Makefile.objs +1 -0
@@ -21,6 +21,7 @@ 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 += 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-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o
block/qed.c +626 -2
672 lines not on this page · raw message
block/qed.h +26 -0
@@ -116,6 +116,29 @@ typedef struct QEDRequest {CachedL2Table *l2_table; } QEDRequest; +typedef struct QEDAIOCB { +BlockDriverAIOCB common; +QEMUBH *bh; +int bh_ret;/* final return status for completion bh */ +QSIMPLEQ_ENTRY (QEDAIOCB) next;/* next request */ +bool is_write;/* false - read, true - write */ +bool *finished;/* signal for cancel completion */ +uint64_t end_pos;/* request end on block device, in bytes */ + +/* User scatter-gather list */ +QEMUIOVector *qiov; +size_t qiov_offset;/* byte count already processed */ + +/* Current cluster scatter-gather list */ +QEMUIOVector cur_qiov; +uint64_t cur_pos;/* position on block device, in bytes */ +uint64_t cur_cluster;/* cluster offset in image file */ +unsigned int cur_nclusters;/* number of clusters being accessed */ +int find_cluster_ret;/* used for L1/L2 update */ + +QEDRequest request; +}QEDAIOCB ; + typedef struct { BlockDriverState *bs; /* device */ uint64_t file_size; /* length of image file, in bytes */
@@ -127,6 +150,9 @@ typedef struct {uint32_t l1_shift;uint32_t l2_shift;uint32_t l2_mask; + +/* Allocating write request queue */ + QSIMPLEQ_HEAD(, QEDAIOCB) allocating_write_reqs; } BDRVQEDState;enum {
trace-events +10 -0
@@ -203,3 +203,13 @@ disable qed_read_table(void *s, uint64_t offset, void *table) "s %p offset %"PRI disable qed_read_table_cb(void *s, void *table, int ret) "s %p table %p ret %d" disable qed_write_table(void *s, uint64_t offset, void *table, unsigned int index, unsigned int n) "s %p offset %"PRIu64" table %p index %u n %u" disable qed_write_table_cb(void *s, void *table, int flush, int ret) "s %p table %p flush %d ret %d" + +# block/qed.c +disable qed_aio_complete(void *s, void *acb, int ret) "s %p acb %p ret %d" +disable qed_aio_setup(void *s, void *acb, int64_t sector_num, int nb_sectors, void *opaque, int is_write) "s %p acb %p sector_num %"PRId64" nb_sectors %d opaque %p is_write %d" +disable qed_aio_next_io(void *s, void *acb, int ret, uint64_t cur_pos) "s %p acb %p ret %d cur_pos %"PRIu64"" +disable qed_aio_read_data(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu" +disable qed_aio_write_data(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu" +disable qed_aio_write_prefill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64"" +disable qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64"" +disable qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu"
Signature · 1 line
1.7.2.3
PATCH 35/38 qed: Consistency check support
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
This patch adds support for the qemu-img check command. It also introduces a dirty bit in the qed header to mark modified images as needing a check. This bit is cleared when the image file is closed cleanly.
If an image file is opened and it has the dirty bit set, a consistency check will run and try to fix corrupted table offsets. These corruptions may occur if there is power loss while an allocating write is performed. Once the image is fixed it opens as normal again.
--- block/qed-check.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++++ block/qed.c | 125 +++++++++++++++++++++++++++++++- block/qed.h | 4 + 3 files changed, 336 insertions(+), 3 deletions(-) create mode 100644 block/qed-check.c
block/qed-check.c new file +210 -0
@@ -0,0 +1,210 @@ +/* +* QEMU Enhanced Disk Format Consistency Check +* +* Copyright IBM, Corp. 2010 +* +* Authors: +* Stefan Hajnoczi <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#include "qed.h" + +typedef struct { +BDRVQEDState *s; +BdrvCheckResult *result; +bool fix;/* whether to fix invalid offsets */ + +size_t nclusters; +uint32_t *used_clusters;/* referenced cluster bitmap */ + +QEDRequest request; +}QEDCheck ; + +static bool qed_test_bit (uint32_t *bitmap,uint64_t n) { +return !!(bitmap[n /32 ] & (1 << (n %32 ))); +} + +static void qed_set_bit (uint32_t *bitmap,uint64_t n) { + bitmap[n /32 ] |=1 << (n %32 ); +} + +/** +* Set bitmap bits for clusters +* +* @check: Check structure +* @offset: Starting offset in bytes +* @n: Number of clusters +*/ +static bool qed_set_used_clusters (QEDCheck *check,uint64_t offset, +unsigned int n) +{ +uint64_t cluster =qed_bytes_to_clusters (check->s, offset); +unsigned int corruptions =0 ; + +while (n-- !=0 ) { +/* Clusters should only be referenced once */ +if (qed_test_bit (check->used_clusters, cluster)) { + corruptions++; + } + +qed_set_bit (check->used_clusters, cluster); + cluster++; + } + + check->result->corruptions += corruptions; +return corruptions ==0 ; +} + +/** +* Check an L2 table +* +* @ret: Number of invalid cluster offsets +*/ +static unsigned int qed_check_l2_table (QEDCheck *check,QEDTable *table) +{ +BDRVQEDState *s = check->s; +unsigned int i, num_invalid =0 ; + +for (i =0 ; i < s->table_nelems; i++) { +uint64_t offset = table->offsets[i]; + +if (!offset) { +continue ; + } + +/* Detect invalid cluster offset */ +if (!qed_check_cluster_offset (s, offset)) { +if (check->fix) { + table->offsets[i] =0 ; + }else { + check->result->corruptions++; + } + + num_invalid++; +continue ; + } + +qed_set_used_clusters (check, offset,1 ); + } + +return num_invalid; +} + +/** +* Descend tables and check each cluster is referenced once only +*/ +static int qed_check_l1_table (QEDCheck *check,QEDTable *table) +{ +BDRVQEDState *s = check->s; +unsigned int i, num_invalid_l1 =0 ; +int ret, last_error =0 ; + +/* Mark L1 table clusters used */ +qed_set_used_clusters (check, s->header.l1_table_offset, + s->header.table_size); + +for (i =0 ; i < s->table_nelems; i++) { +unsigned int num_invalid_l2; +uint64_t offset = table->offsets[i]; + +if (!offset) { +continue ; + } + +/* Detect invalid L2 offset */ +if (!qed_check_table_offset (s, offset)) { +/* Clear invalid offset */ +if (check->fix) { + table->offsets[i] =0 ; + }else { + check->result->corruptions++; + } + + num_invalid_l1++; +continue ; + } + +if (!qed_set_used_clusters (check, offset, s->header.table_size)) { +continue ;/* skip an invalid table */ + } + + ret =qed_read_l2_table_sync (s, &check->request, offset); +if (ret) { + check->result->check_errors++; + last_error = ret; +continue ; + } + + num_invalid_l2 =qed_check_l2_table (check, + check->request.l2_table->table); + +/* Write out fixed L2 table */ +if (num_invalid_l2 >0 && check->fix) { + ret =qed_write_l2_table_sync (s, &check->request,0 , + s->table_nelems, false); +if (ret) { + check->result->check_errors++; + last_error = ret; +continue ; + } + } + } + +/* Drop reference to final table */ +qed_unref_l2_cache_entry (check->request.l2_table); + check->request.l2_table =NULL ; + +/* Write out fixed L1 table */ +if (num_invalid_l1 >0 && check->fix) { + ret =qed_write_l1_table_sync (s,0 , s->table_nelems); +if (ret) { + check->result->check_errors++; + last_error = ret; + } + } + +return last_error; +} + +/** +* Check for unreferenced (leaked) clusters +*/ +static void qed_check_for_leaks (QEDCheck *check) +{ +BDRVQEDState *s = check->s; +size_t i; + +for (i = s->header.header_size; i < check->nclusters; i++) { +if (!qed_test_bit (check->used_clusters, i)) { + check->result->leaks++; + } + } +} + +int qed_check (BDRVQEDState *s,BdrvCheckResult *result,bool fix) +{ +QEDCheck check = { + .s = s, + .result = result, + .nclusters =qed_bytes_to_clusters (s, s->file_size), + .request = { .l2_table =NULL }, + .fix = fix, + }; +int ret; + + check.used_clusters =qemu_mallocz (((check.nclusters +31 ) /32 ) * +sizeof (check.used_clusters[0 ])); + + ret =qed_check_l1_table (&check, s->l1_table); +if (ret ==0 ) { +/* Only check for leaks if entire image was scanned successfully */ +qed_check_for_leaks (&check); + } + +qemu_free (check.used_clusters); +return ret; +}
block/qed.c +122 -3
155 lines not on this page · raw message
block/qed.h +4 -0
@@ -50,11 +50,15 @@ enum {/* The image supports a backing file */ QED_F_BACKING_FILE =0x01 , +/* The image needs a consistency check before use */ +QED_F_NEED_CHECK =0x02 , +/* The backing file format must not be probed, treat as raw image */ QED_F_BACKING_FORMAT_NO_PROBE =0x04 ,/* Feature bits must be used when the on-disk format changes */ QED_FEATURE_MASK =QED_F_BACKING_FILE |/* supported feature bits */ +QED_F_NEED_CHECK |QED_F_BACKING_FORMAT_NO_PROBE ,QED_COMPAT_FEATURE_MASK =0 ,/* supported compat feature bits */ QED_AUTOCLEAR_FEATURE_MASK = 0, /* supported autoclear feature bits */
Signature · 1 line
1.7.2.3
PATCH 36/38 block/qcow2.c: rename qcow_ functions to qcow2_
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
It doesn't really make sense for functions in qcow2.c to be named qcow_ so convert the names to match correctly.
--- block/qcow2-cluster.c | 6 +- block/qcow2-snapshot.c | 6 +- block/qcow2.c | 190 +++++++++++++++++++++++++----------------------- 3 files changed, 104 insertions(+), 98 deletions(-)
block/qcow2-cluster.c +3 -3
@@ -352,8 +352,8 @@ void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num, } -static int qcow_read (BlockDriverState *bs,int64_t sector_num, -uint8_t *buf,int nb_sectors) +static int qcow2_read (BlockDriverState *bs,int64_t sector_num, +uint8_t *buf,int nb_sectors) {BDRVQcowState *s = bs->opaque;int ret, index_in_cluster, n, n1;
@@ -419,7 +419,7 @@ static int copy_sectors(BlockDriverState *bs, uint64_t start_sect,if (n <=0 )return 0 ;BLKDBG_EVENT (bs->file,BLKDBG_COW_READ ); - ret =qcow_read (bs, start_sect + n_start, s->cluster_data, n); + ret =qcow2_read (bs, start_sect + n_start, s->cluster_data, n);if (ret <0 )return ret;if (s->crypt_method) {
block/qcow2-snapshot.c +3 -3
@@ -116,7 +116,7 @@ int qcow2_read_snapshots(BlockDriverState *bs) }/* add at the end of the file a new list of snapshots */ -static int qcow_write_snapshots (BlockDriverState *bs) +static int qcow2_write_snapshots (BlockDriverState *bs) {BDRVQcowState *s = bs->opaque;QCowSnapshot *sn;
@@ -300,7 +300,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) s->snapshots = snapshots1; s->snapshots[s->nb_snapshots++] = *sn; -if (qcow_write_snapshots (bs) <0 ) +if (qcow2_write_snapshots (bs) <0 ) goto fail;#ifdef DEBUG_ALLOC qcow2_check_refcounts (bs);
@@ -378,7 +378,7 @@ int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)qemu_free (sn->name);memmove (sn, sn +1 , (s->nb_snapshots - snapshot_index -1 ) *sizeof (*sn)); s->nb_snapshots--; - ret =qcow_write_snapshots (bs); + ret =qcow2_write_snapshots (bs);if (ret <0 ) {/* XXX: restore snapshot if error ? */ return ret;
block/qcow2.c +98 -92
468 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 37/38 Add proper -errno error return values to qcow2_open()
In reply to Kevin WolfFrom: Jes Sorensen <[email protected]>
In addition this adds missing braces to the function to be consistent with the coding style.
--- block/qcow2.c | 60 +++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 42 insertions(+), 18 deletions(-)
block/qcow2.c +42 -18
@@ -140,12 +140,14 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,static int qcow2_open (BlockDriverState *bs,int flags) {BDRVQcowState *s = bs->opaque; -int len, i; +int len, i, ret =0 ;QCowHeader header;uint64_t ext_end; -if (bdrv_pread (bs->file,0 , &header,sizeof (header)) !=sizeof (header)) + ret =bdrv_pread (bs->file,0 , &header,sizeof (header)); +if (ret <0 ) { goto fail; + }be32_to_cpus (&header.magic);be32_to_cpus (&header.version);be64_to_cpus (&header.backing_file_offset);
@@ -160,16 +162,23 @@ static int qcow2_open(BlockDriverState *bs, int flags)be64_to_cpus (&header.snapshots_offset);be32_to_cpus (&header.nb_snapshots); -if (header.magic !=QCOW_MAGIC || header.version !=QCOW_VERSION ) +if (header.magic !=QCOW_MAGIC || header.version !=QCOW_VERSION ) { + ret = -EINVAL ; goto fail; + }if (header.cluster_bits <MIN_CLUSTER_BITS || - header.cluster_bits >MAX_CLUSTER_BITS ) + header.cluster_bits >MAX_CLUSTER_BITS ) { + ret = -EINVAL ; goto fail; -if (header.crypt_method >QCOW_CRYPT_AES ) + } +if (header.crypt_method >QCOW_CRYPT_AES ) { + ret = -EINVAL ; goto fail; + } s->crypt_method_header = header.crypt_method; -if (s->crypt_method_header) +if (s->crypt_method_header) { bs->encrypted =1 ; + } s->cluster_bits = header.cluster_bits; s->cluster_size =1 << s->cluster_bits; s->cluster_sectors =1 << (s->cluster_bits -9 );
@@ -191,15 +200,19 @@ static int qcow2_open(BlockDriverState *bs, int flags) s->l1_vm_state_index =size_to_l1 (s, header.size);/* the L1 table must contain at least enough entries to put header.size bytes */ -if (s->l1_size < s->l1_vm_state_index) +if (s->l1_size < s->l1_vm_state_index) { + ret = -EINVAL ; goto fail; + } s->l1_table_offset = header.l1_table_offset;if (s->l1_size >0 ) { s->l1_table =qemu_mallocz (align_offset (s->l1_size *sizeof (uint64_t ),512 )); -if (bdrv_pread (bs->file, s->l1_table_offset, s->l1_table, s->l1_size *sizeof (uint64_t )) != - s->l1_size *sizeof (uint64_t )) + ret =bdrv_pread (bs->file, s->l1_table_offset, s->l1_table, + s->l1_size *sizeof (uint64_t )); +if (ret <0 ) { goto fail; + }for (i =0 ;i < s->l1_size; i++) {be64_to_cpus (&s->l1_table[i]); }
@@ -212,35 +225,46 @@ static int qcow2_open(BlockDriverState *bs, int flags) + 512); s->cluster_cache_offset =-1 ; -if (qcow2_refcount_init (bs) <0 ) + ret =qcow2_refcount_init (bs); +if (ret !=0 ) { goto fail; + }QLIST_INIT (&s->cluster_allocs);/* read qcow2 extensions */ -if (header.backing_file_offset) +if (header.backing_file_offset) { ext_end = header.backing_file_offset; -else + }else { ext_end = s->cluster_size; -if (qcow2_read_extensions (bs,sizeof (header), ext_end)) + } +if (qcow2_read_extensions (bs,sizeof (header), ext_end)) { + ret = -EINVAL ; goto fail; + }/* read the backing file name */ if (header.backing_file_offset !=0 ) { len = header.backing_file_size; -if (len >1023 ) +if (len >1023 ) { len =1023 ; -if (bdrv_pread (bs->file, header.backing_file_offset, bs->backing_file, len) != len) + } + ret =bdrv_pread (bs->file, header.backing_file_offset, + bs->backing_file, len); +if (ret <0 ) { goto fail; + } bs->backing_file[len] ='\0' ; } -if (qcow2_read_snapshots (bs) <0 ) +if (qcow2_read_snapshots (bs) <0 ) { + ret = -EINVAL ; goto fail; + }#ifdef DEBUG_ALLOC qcow2_check_refcounts (bs);#endif -return 0 ; +return ret; fail:qcow2_free_snapshots (bs);
@@ -249,7 +273,7 @@ static int qcow2_open(BlockDriverState *bs, int flags)qemu_free (s->l2_cache);qemu_free (s->cluster_cache);qemu_free (s->cluster_data); -return -1 ; +return ret; }static int qcow2_set_key (BlockDriverState *bs,const char *key)
Signature · 1 line
1.7.2.3
PATCH 38/38 docs: Fix missing carets in QED specification
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
For some reason the carets ('^') in the QED specification disappeared. This patch puts them back.
--- docs/specs/qed_spec.txt | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
docs/specs/qed_spec.txt +2 -2
@@ -33,7 +33,7 @@ All fields are little-endian. } Field descriptions: -* ''cluster_size'' must be a power of 2 in range [212, 226]. +* ''cluster_size'' must be a power of 2 in range [2^12, 2^26]. * ''table_size'' must be a power of 2 in range [1, 16]. * ''header_size'' is the number of clusters used by the header and any additional information stored before regular clusters. * ''features'', ''compat_features'', and ''autoclear_features'' are file format extension bitmaps. They work as follows:
@@ -90,7 +90,7 @@ L1, L2, and data cluster offsets must be aligned to header.cluster_size. The fo ===Data cluster offsets=== * 0 - unallocated. The data cluster is not yet allocated. -Future format extensions may wish to store per-offset information. The least significant 12 bits of an offset are reserved for this purpose and must be set to zero. Image files with cluster_size > 212 will have more unused bits which should also be zeroed. +Future format extensions may wish to store per-offset information. The least significant 12 bits of an offset are reserved for this purpose and must be set to zero. Image files with cluster_size > 2^12 will have more unused bits which should also be zeroed. ===Unallocated L2 tables and data clusters=== Reads to an unallocated area of the image file access the backing file. If there is no backing file, then zeroes are produced. The backing file may be smaller than the image file and reads of unallocated areas beyond the end of the backing file produce zeroes.
Signature · 1 line
1.7.2.3
Quoted 8 lines · Kevin Wolf
The following changes since commit
9d861fa595c93f22d1d55b723a691531c36c9672:Merge remote branch 'arm/for-anthony' into staging (2010-12-17 08:25:17 -0600)are available in the git repository at:
git://repo.or.cz/qemu/kevin.gitfor-anthony
Pulled. Thanks.
Regards,
Anthony Liguori
Quoted 119 lines
Alexander Graf (10):
ide: split ide command interpretation off
ide: fix whitespace gap inide_exec_cmd
ide: Split out BMDMA code from ATA core
ide: movetransfer_startafter variable modification
pci: add storage class for sata
pci: add ich9 pci id
ahci: add ahci emulation
config: move ide core and pci to pci.mak
config: add ahci for pci capable machines
ide: honor ncq for atapiChristoph Hellwig (3):
block: add discard support
scsi-disk: support WRITE SAME (16) with unmap bit
raw-posix: add discard supportJes Sorensen (9):
Introducestrtosz_suffix()
qemu-img.c: Clean up handling of image size inimg_create()qemu-img.c: Re-factorimg_create()
Introducedo_snapshot_blkdev()and monitor command to handle it. Prevent creating an image with the same filename as backing filebdrv_img_create()use proper errno return valuesqemu.img.c: Useerror_report()instead of ownerror()implementationblock/qcow2.c: renameqcow_functions toqcow2_
Add proper -errno error return values toqcow2_open()Kevin Wolf (3):
qemu-img: Callerror_set_prognameRemove NULL checks forbdrv_newreturn value
qemu-io: Fix typo in help textsRoland Elek (1):
ide: add ncq identify data for ahci sata drivesRyan Harper (1):
blockdev: check dinfo ptr before usingSebastian Herbszt (1):
ahci: set SATA Mode SelectStefan Hajnoczi (10):
block: Introducepath_has_protocol()function
block: Fix the use of protocols in backing files
ide: Register vm change state handler once only
qemu-io: Add discard command
docs: Add QED image format specification
qed: Add QEMU Enhanced Disk image format
qed: Table, L2 cache, and cluster functions
qed: Read/write support
qed: Consistency check support
docs: Fix missing carets in QED specificationMakefile.objs | 3 + block.c | 234 +++++- block.h | 5 + block/qcow2-cluster.c | 6 +- block/qcow2-snapshot.c | 6 +- block/qcow2.c | 248 +++--- block/qed-check.c | 210 +++++ block/qed-cluster.c | 154 ++++ block/qed-gencb.c | 32 + block/qed-l2-cache.c | 173 ++++ block/qed-table.c | 319 +++++++ block/qed.c | 1349 ++++++++++++++++++++++++++++++ block/qed.h | 301 +++++++ block/raw-posix.c | 45 + block/raw.c | 6 + block_int.h | 8 +- blockdev.c | 68 ++- blockdev.h | 1 + configure | 26 + cutils.c | 17 +- default-configs/arm-softmmu.mak | 1 - default-configs/i386-softmmu.mak | 3 - default-configs/mips-softmmu.mak | 3 - default-configs/mips64-softmmu.mak | 3 - default-configs/mips64el-softmmu.mak | 3 - default-configs/mipsel-softmmu.mak | 3 - default-configs/pci.mak | 4 + default-configs/ppc-softmmu.mak | 3 - default-configs/ppc64-softmmu.mak | 3 - default-configs/ppcemb-softmmu.mak | 3 - default-configs/sh4-softmmu.mak | 1 - default-configs/sh4eb-softmmu.mak | 1 - default-configs/sparc64-softmmu.mak | 3 - default-configs/x86_64-softmmu.mak | 3 - docs/specs/qed_spec.txt | 130 +++ hmp-commands.hx | 19 + hw/ide/ahci.c | 1527 ++++++++++++++++++++++++++++++++++ hw/ide/cmd646.c | 18 +- hw/ide/core.c | 1116 +++++++++++-------------- hw/ide/internal.h | 73 +- hw/ide/pci.c | 280 ++++++- hw/ide/pci.h | 30 + hw/ide/piix.c | 34 +- hw/ide/via.c | 34 +- hw/pci.h | 1 + hw/pci_ids.h | 1 + hw/scsi-defs.h | 1 + hw/scsi-disk.c | 53 ++- hw/xen_disk.c | 17 +- qemu-common.h | 7 + qemu-img.c | 250 ++---- qemu-io.c | 102 +++- qemu-nbd.c | 2 - trace-events | 21 + 54 files changed, 5892 insertions(+), 1072 deletions(-)create mode 100644
block/qed-check.c
create mode 100644block/qed-cluster.c
create mode 100644block/qed-gencb.c
create mode 100644block/qed-l2-cache.c
create mode 100644block/qed-table.c
create mode 100644block/qed.c
create mode 100644block/qed.h
create mode 100644docs/specs/qed_spec.txt
create mode 100644hw/ide/ahci.c