Block patches
The following changes since commit 8cc9b43f7c5f826b39af4b012ad89bb55faac29c:
target-microblaze: lwx/swx: first implementation (2012-06-04 10:19:46 +0200)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.git for-anthony
Josh Durgin (1):
rbd: hook up cache options
Kevin Wolf (3):
qemu-img check -r for repairing images qemu-img check: Print fixed clusters and recheck
qcow2: Support for fixing refcount inconsistencies
MORITA Kazutaka (1):
sheepdog: add coroutine_fn markers to coroutine functions
Markus Armbruster (1):
Un-inline fdctrl_init_isa()
Paolo Bonzini (4):
block: implement is_allocated for raw
stream: tweak usage of bdrv_co_is_allocated
stream: move is_allocated_above to block.c
stream: move rate limiting to a separate header file
Zhi Yong Wu (2):
qcow2: remove a line of unnecessary code
qcow2: fix the byte endian convertion
block.c | 53 +++++++++++++++++++++- block.h | 13 +++++- block/qcow2-cluster.c | 1 - block/qcow2-refcount.c | 33 ++++++++++++-- block/qcow2.c | 5 +- block/qcow2.h | 3 +- block/qed-check.c | 2 + block/qed.c | 5 +- block/raw-posix.c | 98 +++++++++++++++++++++++++++++++++++++++++ block/raw.c | 8 +++ block/rbd.c | 19 ++++++++ block/sheepdog.c | 9 ++-- block/stream.c | 109 +++++++--------------------------------------- block/vdi.c | 7 +++- block_int.h | 3 +- hw/fdc.c | 20 ++++++++ hw/fdc.h | 24 +--------- hw/ide/piix.c | 3 +- hw/isa.h | 2 - hw/pc_sysfw.c | 1 + include/qemu/ratelimit.h | 48 ++++++++++++++++++++ qemu-common.h | 1 + qemu-img-cmds.hx | 4 +- qemu-img.c | 35 +++++++++++++- qemu-img.texi | 7 +++- 25 files changed, 369 insertions(+), 144 deletions(-) create mode 100644 include/qemu/ratelimit.h
PATCH 1/12 qcow2: remove a line of unnecessary code
From: Zhi Yong Wu <[email protected]>
Commit 3948d1d4 removed the pointer argument we filled in with l2_offset but forgot to remove the unnecessary l2_offset assignment.
--- block/qcow2-cluster.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
block/qcow2-cluster.c +0 -1
@@ -538,7 +538,6 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,if (l2_offset) {qcow2_free_clusters (bs, l2_offset, s->l2_size *sizeof (uint64_t )); } - l2_offset = s->l1_table[l1_index] &L1E_OFFSET_MASK ; }/* find the cluster offset for the given disk offset */
Signature · 1 line
1.7.6.5
PATCH 2/12 qcow2: fix the byte endian convertion
In reply to Kevin WolfFrom: Zhi Yong Wu <[email protected]>
--- block/qcow2-refcount.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
block/qcow2-refcount.c +1 -1
@@ -367,7 +367,7 @@ static int alloc_refcount_block(BlockDriverState *bs, }for (i =0 ; i < table_size; i++) { -cpu_to_be64s (&new_table[i]); +be64_to_cpus (&new_table[i]); }/* Hook up the new refcount table in the qcow2 header */
Signature · 1 line
1.7.6.5
Re: [Qemu-devel] [PATCH 02/12] qcow2: fix the byte endian convertion
Quoted 1 line · Kevin Wolf
From: Zhi Yong Wu <[email protected]>
Is it too late to s/convertion/conversion/ in the subject?
Quoted 21 lines
Signed-off-by Zhi Yong Wu <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Signed-off-by Kevin Wolf <[email protected]>--- block/qcow2-refcount.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)block/qcow2-refcount.c +1
-1@@ -367,7 +367,7 @@ static int alloc_refcount_block(BlockDriverState *bs, }for (i =0 ; i < table_size; i++) { -cpu_to_be64s (&new_table[i]); +be64_to_cpus (&new_table[i]); }/* Hook up the new refcount table in the qcow2 header */
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 02/12] qcow2: fix the byte endian convertion
Am 04.06.2012 18:43, schrieb Eric Blake:
Quoted 4 lines · Kevin Wolf
Quoted 1 line
From: Zhi Yong Wu <[email protected]>
Is it too late to s/convertion/conversion/ in the subject?
Depends on whether Anthony has already pulled to his local repo, I guess. I've renamed it to "qcow2: fix endianness conversion" in my tree now, we'll see which versions will get into master.
Kevin
Re: [Qemu-devel] [PATCH 02/12] qcow2: fix the byte endian convertion
In reply to Kevin WolfQuoted 5 lines · Kevin Wolf
From: Zhi Yong Wu <[email protected]>
Signed-off-by Zhi Yong Wu <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Signed-off-by Kevin Wolf <[email protected]>
It appears to be a good candidate for -stable, no?
Thanks,
/mjt
Re: [Qemu-devel] [PATCH 02/12] qcow2: fix the byte endian convertion
Am 07.06.2012 09:13, schrieb Michael Tokarev:
Quoted 8 lines · Kevin Wolf
Quoted 5 lines
From: Zhi Yong Wu <[email protected]>
Signed-off-by Zhi Yong Wu <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Signed-off-by Kevin Wolf <[email protected]>It appears to be a good candidate for -stable, no?
No, it's merely cosmetic. cpu_to_be64s() and be64_to_cpus() do the same, they both swap the byte order if the host is little endian.
Kevin
PATCH 3/12 block: implement is_allocated for raw
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Either FIEMAP, or SEEK_DATA+SEEK_HOLE can be used to implement the is_allocated callback for raw files. On Linux ext4, btrfs and XFS all support it.
--- block/raw-posix.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ block/raw.c | 8 ++++ 2 files changed, 106 insertions(+), 0 deletions(-)
block/raw-posix.c +98 -0
@@ -52,6 +52,10 @@#include <sys/param.h> #include <linux/cdrom.h> #include <linux/fd.h> +#include <linux/fs.h> +#endif +#ifdef CONFIG_FIEMAP +#include <linux/fiemap.h> #endif #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)#include <sys/disk.h>
@@ -583,6 +587,99 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)return result; } +/* +* Returns true iff the specified sector is present in the disk image. Drivers +* not implementing the functionality are assumed to not support backing files, +* hence all their sectors are reported as allocated. +* +* If 'sector_num' is beyond the end of the disk image the return value is 0 +* and 'pnum' is set to 0. +* +* 'pnum' is set to the number of sectors (including and immediately following +* the specified sector) that are known to be in the same +* allocated/unallocated state. +* +* 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes +* beyond the end of the disk image it will be clamped. +*/ +static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs, +int64_t sector_num, +int nb_sectors,int *pnum) +{ +BDRVRawState *s = bs->opaque; +off_t start, data, hole; +int ret; + + ret =fd_open (bs); +if (ret <0 ) { +return ret; + } + + start = sector_num *BDRV_SECTOR_SIZE ; +#ifdef CONFIG_FIEMAP +struct { +struct fiemap fm; +struct fiemap_extent fe; + } f; + f.fm.fm_start = start; + f.fm.fm_length = (int64_t )nb_sectors *BDRV_SECTOR_SIZE ; + f.fm.fm_flags =0 ; + f.fm.fm_extent_count =1 ; + f.fm.fm_reserved =0 ; +if (ioctl (s->fd,FS_IOC_FIEMAP , &f) ==-1 ) { +/* Assume everything is allocated. */ + *pnum = nb_sectors; +return 1 ; + } + +if (f.fm.fm_mapped_extents ==0 ) { +/* No extents found, data is beyond f.fm.fm_start + f.fm.fm_length. +* f.fm.fm_start + f.fm.fm_length must be clamped to the file size! +*/ +off_t length =lseek (s->fd,0 ,SEEK_END ); + hole = f.fm.fm_start; + data =MIN (f.fm.fm_start + f.fm.fm_length, length); + }else { + data = f.fe.fe_logical; + hole = f.fe.fe_logical + f.fe.fe_length; + } +#elif definedSEEK_HOLE && definedSEEK_DATA + hole =lseek (s->fd, start,SEEK_HOLE ); +if (hole ==-1 ) { +/* -ENXIO indicates that sector_num was past the end of the file. +* There is a virtual hole there. */ +assert (errno != -ENXIO ); + +/* Most likely EINVAL. Assume everything is allocated. */ + *pnum = nb_sectors; +return 1 ; + } + +if (hole > start) { + data = start; + }else { +/* On a hole. We need another syscall to find its end. */ + data =lseek (s->fd, start,SEEK_DATA ); +if (data ==-1 ) { + data =lseek (s->fd,0 ,SEEK_END ); + } + } +#else + *pnum = nb_sectors; +return 1 ; +#endif + +if (data <= start) { +/* On a data extent, compute sectors to the end of the extent. */ + *pnum =MIN (nb_sectors, (hole - start) /BDRV_SECTOR_SIZE ); +return 1 ; + }else { +/* On a hole, compute sectors to the beginning of the next extent. */ + *pnum =MIN (nb_sectors, (data - start) /BDRV_SECTOR_SIZE ); +return 0 ; + } +} +#ifdef CONFIG_XFS static int xfs_discard (BDRVRawState *s,int64_t sector_num,int nb_sectors) {
@@ -634,6 +731,7 @@ static BlockDriver bdrv_file = { .bdrv_close = raw_close, .bdrv_create = raw_create, .bdrv_co_discard = raw_co_discard, + .bdrv_co_is_allocated = raw_co_is_allocated, .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev,
block/raw.c +8 -0
@@ -25,6 +25,13 @@ static void raw_close(BlockDriverState *bs) { } +static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs, +int64_t sector_num, +int nb_sectors,int *pnum) +{ +return bdrv_co_is_allocated (bs->file, sector_num, nb_sectors, pnum); +} +static int64_t raw_getlength (BlockDriverState *bs) {return bdrv_getlength (bs->file);
@@ -108,6 +115,7 @@ static BlockDriver bdrv_raw = { .bdrv_co_readv = raw_co_readv, .bdrv_co_writev = raw_co_writev, + .bdrv_co_is_allocated = raw_co_is_allocated, .bdrv_co_discard = raw_co_discard, .bdrv_probe = raw_probe,
Signature · 1 line
1.7.6.5
PATCH 4/12 stream: tweak usage of bdrv_co_is_allocated
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
is_allocated_base has complex semantics that are not really usable outside streaming. Split the check in two parts, where the allocated state for the top bs is moved to the caller. The resulting function is more generally useful.
--- block/stream.c | 51 +++++++++++++++++++++++++-------------------------- 1 files changed, 25 insertions(+), 26 deletions(-)
block/stream.c +25 -26
@@ -101,45 +101,33 @@ static void close_unused_images(BlockDriverState *top, BlockDriverState *base,/* * Given an image chain: [BASE] -> [INTER1] -> [INTER2] -> [TOP] * -* Return true if the given sector is allocated in top. -* Return false if the given sector is allocated in intermediate images. -* Return true otherwise. +* Return true if the given sector is allocated in any image between +* BASE and TOP (inclusive). BASE can be NULL to check if the given +* sector is allocated in any image of the chain. Return false otherwise. * * 'pnum' is set to the number of sectors (including and immediately following * the specified sector) that are known to be in the same * allocated/unallocated state. * */ -static int coroutine_fn is_allocated_base(BlockDriverState *top, -BlockDriverState *base, -int64_t sector_num, -int nb_sectors,int *pnum) +static int coroutine_fn is_allocated_above(BlockDriverState *top, +BlockDriverState *base, +int64_t sector_num, +int nb_sectors,int *pnum) {BlockDriverState *intermediate; -int ret, n; - - ret =bdrv_co_is_allocated (top, sector_num, nb_sectors, &n); -if (ret) { - *pnum = n; -return ret; - } - -/* -* Is the unallocated chunk [sector_num, n] also -* unallocated between base and top? -*/ - intermediate = top->backing_hd; +int ret, n = nb_sectors; + intermediate = top;while (intermediate != base) {int pnum_inter; - ret =bdrv_co_is_allocated (intermediate, sector_num, nb_sectors, &pnum_inter);if (ret <0 ) {return ret; }else if (ret) { *pnum = pnum_inter; -return 0 ; +return 1 ; }/*
@@ -156,7 +144,7 @@ static int coroutine_fn is_allocated_base(BlockDriverState *top, } *pnum = n; -return 1 ; +return 0 ; } static void coroutine_fn stream_run(void *opaque)
@@ -189,6 +177,7 @@ static void coroutine_fn stream_run(void *opaque)for (sector_num =0 ; sector_num < end; sector_num += n) {uint64_t delay_ns =0 ; +bool copy; wait:/* Note that even when no rate limit is applied we need to yield
@@ -199,10 +188,20 @@ wait:break ; } - ret =is_allocated_base (bs, base, sector_num, -STREAM_BUFFER_SIZE /BDRV_SECTOR_SIZE , &n); + ret =bdrv_co_is_allocated (bs, sector_num, +STREAM_BUFFER_SIZE /BDRV_SECTOR_SIZE , &n); +if (ret ==1 ) { +/* Allocated in the top, no need to copy. */ + copy = false; + }else { +/* Copy if allocated in the intermediate images. Limit to the +* known-unallocated area [sector_num, sector_num+n). */ + ret =is_allocated_above (bs->backing_hd, base, sector_num, n, &n); + copy = (ret ==1 ); + } +trace_stream_one_iteration (s, sector_num, n, ret); -if (ret ==0 ) { +if (ret >=0 && copy) {if (s->common.speed) { delay_ns =ratelimit_calculate_delay (&s->limit, n);if (delay_ns >0 ) {
Signature · 1 line
1.7.6.5
PATCH 5/12 stream: move is_allocated_above to block.c
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
--- block.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ block.h | 4 ++++ block/stream.c | 53 ++--------------------------------------------------- 3 files changed, 55 insertions(+), 51 deletions(-)
block.c +49 -0
@@ -2569,6 +2569,55 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,return data.ret; } +/* +* Given an image chain: ... -> [BASE] -> [INTER1] -> [INTER2] -> [TOP] +* +* Return true if the given sector is allocated in any image between +* BASE and TOP (inclusive). BASE can be NULL to check if the given +* sector is allocated in any image of the chain. Return false otherwise. +* +* 'pnum' is set to the number of sectors (including and immediately following +* the specified sector) that are known to be in the same +* allocated/unallocated state. +* +*/ +int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, +BlockDriverState *base, +int64_t sector_num, +int nb_sectors,int *pnum) +{ +BlockDriverState *intermediate; +int ret, n = nb_sectors; + + intermediate = top; +while (intermediate && intermediate != base) { +int pnum_inter; + ret =bdrv_co_is_allocated (intermediate, sector_num, nb_sectors, + &pnum_inter); +if (ret <0 ) { +return ret; + }else if (ret) { + *pnum = pnum_inter; +return 1 ; + } + +/* +* [sector_num, nb_sectors] is unallocated on top but intermediate +* might have +* +* [sector_num+x, nr_sectors] allocated. +*/ +if (n > pnum_inter) { + n = pnum_inter; + } + + intermediate = intermediate->backing_hd; + } + + *pnum = n; +return 0 ; +} +BlockInfoList *qmp_query_block (Error **errp) {BlockInfoList *head =NULL , *cur_item =NULL ;
block.h +4 -0
@@ -165,6 +165,10 @@ int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num,int nb_sectors,int *pnum); +int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, +BlockDriverState *base, +int64_t sector_num, +int nb_sectors,int *pnum);BlockDriverState *bdrv_find_backing_image (BlockDriverState *bs,const char *backing_file);int bdrv_truncate (BlockDriverState *bs,int64_t offset);
block/stream.c +2 -51
67 lines not on this page · raw message
Signature · 1 line
1.7.6.5
PATCH 6/12 stream: move rate limiting to a separate header file
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Make the code reusable.
--- block/stream.c | 31 +--------------------------- include/qemu/ratelimit.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 include/qemu/ratelimit.h
block/stream.c +2 -29
@@ -13,6 +13,7 @@#include "trace.h" #include "block_int.h" +#include "qemu/ratelimit.h" enum {/*
@@ -25,34 +26,6 @@ enum {#define SLICE_TIME 100000000ULL/* ns */ -typedef struct { -int64_t next_slice_time; -uint64_t slice_quota; -uint64_t dispatched; -}RateLimit ; - -static int64_t ratelimit_calculate_delay (RateLimit *limit,uint64_t n) -{ -int64_t now =qemu_get_clock_ns (rt_clock); - -if (limit->next_slice_time < now) { - limit->next_slice_time = now +SLICE_TIME ; - limit->dispatched =0 ; - } -if (limit->dispatched ==0 || limit->dispatched + n <= limit->slice_quota) { - limit->dispatched += n; -return 0 ; - }else { - limit->dispatched = n; -return limit->next_slice_time - now; - } -} - -static void ratelimit_set_speed (RateLimit *limit,uint64_t speed) -{ - limit->slice_quota = speed / (1000000000ULL /SLICE_TIME ); -} - typedef struct StreamBlockJob { BlockJob common; RateLimit limit;
@@ -198,7 +171,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp)error_set (errp,QERR_INVALID_PARAMETER ,"speed" );return ; } -ratelimit_set_speed (&s->limit, speed /BDRV_SECTOR_SIZE ); +ratelimit_set_speed (&s->limit, speed /BDRV_SECTOR_SIZE ,SLICE_TIME ); }static BlockJobType stream_job_type = {
include/qemu/ratelimit.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.7.6.5
PATCH 7/12 Un-inline fdctrl_init_isa()
In reply to Kevin WolfFrom: Markus Armbruster <[email protected]>
--- hw/fdc.c | 20 ++++++++++++++++++++ hw/fdc.h | 24 ++---------------------- hw/ide/piix.c | 3 ++- hw/isa.h | 2 -- hw/pc_sysfw.c | 1 + qemu-common.h | 1 + 6 files changed, 26 insertions(+), 25 deletions(-)
hw/fdc.c +20 -0
@@ -1888,6 +1888,26 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl)return 0 ; } +ISADevice *fdctrl_init_isa (ISABus *bus,DriveInfo **fds) +{ +ISADevice *dev; + + dev =isa_try_create (bus,"isa-fdc" ); +if (!dev) { +return NULL ; + } + +if (fds[0 ]) { +qdev_prop_set_drive_nofail (&dev->qdev,"driveA" , fds[0 ]->bdrv); + } +if (fds[1 ]) { +qdev_prop_set_drive_nofail (&dev->qdev,"driveB" , fds[1 ]->bdrv); + } +qdev_init_nofail (&dev->qdev); + +return dev; +} +void fdctrl_init_sysbus (qemu_irq irq,int dma_chann,target_phys_addr_t mmio_base,DriveInfo **fds) {
hw/fdc.h +2 -22
@@ -1,32 +1,12 @@#ifndef HW_FDC_H #define HW_FDC_H -#include "isa.h" -#include "blockdev.h" +#include "qemu-common.h" /* fdc.c */ #define MAX_FD 2 -static inline ISADevice *fdctrl_init_isa (ISABus *bus,DriveInfo **fds) -{ -ISADevice *dev; - - dev =isa_try_create (bus,"isa-fdc" ); -if (!dev) { -return NULL ; - } - -if (fds[0 ]) { -qdev_prop_set_drive_nofail (&dev->qdev,"driveA" , fds[0 ]->bdrv); - } -if (fds[1 ]) { -qdev_prop_set_drive_nofail (&dev->qdev,"driveB" , fds[1 ]->bdrv); - } -qdev_init_nofail (&dev->qdev); - -return dev; -} - +ISADevice *fdctrl_init_isa (ISABus *bus,DriveInfo **fds);void fdctrl_init_sysbus (qemu_irq irq,int dma_chann,target_phys_addr_t mmio_base,DriveInfo **fds); void sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base,
hw/ide/piix.c +2 -1
@@ -22,11 +22,12 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include <hw/hw.h> #include <hw/pc.h> #include <hw/pci.h> #include <hw/isa.h> -#include "block.h" +#include "blockdev.h" #include "sysemu.h" #include "dma.h"
hw/isa.h +0 -2
@@ -9,8 +9,6 @@#define ISA_NUM_IRQS 16 -typedef struct ISADevice ISADevice ; -#define TYPE_ISA_DEVICE "isa-device"#define ISA_DEVICE (obj) \ OBJECT_CHECK(ISADevice, (obj), TYPE_ISA_DEVICE)
hw/pc_sysfw.c +1 -0
@@ -23,6 +23,7 @@* THE SOFTWARE. */ +#include "blockdev.h" #include "sysbus.h" #include "hw.h" #include "pc.h"
qemu-common.h +1 -0
@@ -239,6 +239,7 @@ typedef struct VLANState VLANState;typedef struct VLANClientState VLANClientState ;typedef struct i2c_bus i2c_bus ;typedef struct ISABus ISABus ; +typedef struct ISADevice ISADevice ;typedef struct SMBusDevice SMBusDevice ;typedef struct PCIHostState PCIHostState ;typedef struct PCIExpressHost PCIExpressHost ;
Signature · 1 line
1.7.6.5
PATCH 8/12 qemu-img check -r for repairing images
In reply to Kevin WolfThe QED block driver already provides the functionality to not only detect inconsistencies in images, but also fix them. However, this functionality cannot be manually invoked with qemu-img, but the check happens only automatically during bdrv_open().
This adds a -r switch to qemu-img check that allows manual invocation of an image repair.
--- block.c | 4 ++-- block.h | 7 ++++++- block/qcow2.c | 7 ++++++- block/qed.c | 5 +++-- block/vdi.c | 7 ++++++- block_int.h | 3 ++- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 ++++++++++++++++++++++--- qemu-img.texi | 7 ++++++- 9 files changed, 55 insertions(+), 14 deletions(-)
block.c +2 -2
@@ -1222,14 +1222,14 @@ bool bdrv_dev_is_medium_locked(BlockDriverState *bs)* free of errors) or -errno when an internal error occurred. The results of the * check are stored in res. */ -int bdrv_check (BlockDriverState *bs,BdrvCheckResult *res) +int bdrv_check (BlockDriverState *bs,BdrvCheckResult *res,BdrvCheckMode fix) {if (bs->drv->bdrv_check ==NULL ) {return -ENOTSUP ; }memset (res,0 ,sizeof (*res)); -return bs->drv->bdrv_check (bs, res); +return bs->drv->bdrv_check (bs, res, fix); }#define COMMIT_BUF_SECTORS 2048
block.h +6 -1
@@ -190,7 +190,12 @@ typedef struct BdrvCheckResult {BlockFragInfo bfi; } BdrvCheckResult; -int bdrv_check (BlockDriverState *bs,BdrvCheckResult *res); +typedef enum { +BDRV_FIX_LEAKS =1 , +BDRV_FIX_ERRORS =2 , +}BdrvCheckMode ; + +int bdrv_check (BlockDriverState *bs,BdrvCheckResult *res,BdrvCheckMode fix);/* async block I/O */ typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
block/qcow2.c +6 -1
@@ -1470,8 +1470,13 @@ static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) } -static int qcow2_check (BlockDriverState *bs,BdrvCheckResult *result) +static int qcow2_check (BlockDriverState *bs,BdrvCheckResult *result, +BdrvCheckMode fix) { +if (fix) { +return -ENOTSUP ; + } +return qcow2_check_refcounts (bs, result); }
block/qed.c +3 -2
@@ -1517,11 +1517,12 @@ static void bdrv_qed_invalidate_cache(BlockDriverState *bs)bdrv_qed_open (bs, bs->open_flags); } -static int bdrv_qed_check (BlockDriverState *bs,BdrvCheckResult *result) +static int bdrv_qed_check (BlockDriverState *bs,BdrvCheckResult *result, +BdrvCheckMode fix) {BDRVQEDState *s = bs->opaque; -return qed_check (s, result, false); +return qed_check (s, result, !!fix); }static QEMUOptionParameter qed_create_options[] = {
block/vdi.c +6 -1
@@ -277,7 +277,8 @@ static void vdi_header_print(VdiHeader *header) }#endif -static int vdi_check (BlockDriverState *bs,BdrvCheckResult *res) +static int vdi_check (BlockDriverState *bs,BdrvCheckResult *res, +BdrvCheckMode fix) {/* TODO: additional checks possible. */ BDRVVdiState *s = (BDRVVdiState *)bs->opaque;
@@ -286,6 +287,10 @@ static int vdi_check(BlockDriverState *bs, BdrvCheckResult *res)uint32_t *bmap;logout ("\n" ); +if (fix) { +return -ENOTSUP ; + } + bmap =g_malloc (s->header.blocks_in_image *sizeof (uint32_t ));memset (bmap,0xff , s->header.blocks_in_image *sizeof (uint32_t ));
block_int.h +2 -1
@@ -241,7 +241,8 @@ struct BlockDriver {* Returns 0 for completed check, -errno for internal errors. * The check results are stored in result. */ -int (*bdrv_check)(BlockDriverState * bs,BdrvCheckResult *result); +int (*bdrv_check)(BlockDriverState * bs,BdrvCheckResult *result, +BdrvCheckMode fix);void (*bdrv_debug_event)(BlockDriverState *bs,BlkDebugEvent event);
qemu-img-cmds.hx +2 -2
@@ -10,9 +10,9 @@ STEXI ETEXI DEF("check", img_check, - "check [-f fmt] filename") + "check [-f fmt] [-r [leaks | all]] filename") STEXI -@item check [-f @var{fmt}] @var{filename} +@item check [-f @var{fmt}] [-r [leaks | all]] @var{filename} ETEXI DEF("create", img_create,
qemu-img.c +22 -3
@@ -85,6 +85,12 @@ static void help(void)" '-S' indicates the consecutive number of bytes that must contain only zeros\n" " for qemu-img to create a sparse image during conversion\n" "\n" +"Parameters to check subcommand:\n" +" '-r' tries to repair any inconsistencies that are found during the check.\n" +" '-r leaks' repairs only cluster leaks, whereas '-r all' fixes all\n" +" kinds of errors, with a higher risk of choosing the wrong fix or\n" +" hiding corruption that has already occured.\n" +"\n" "Parameters to snapshot subcommand:\n" " 'snapshot' is the name of the snapshot to create, apply or delete\n" " '-a' applies a snapshot (revert disk to saved state)\n"
@@ -372,10 +378,12 @@ static int img_check(int argc, char **argv)const char *filename, *fmt;BlockDriverState *bs;BdrvCheckResult result; +int fix =0 ; +int flags =BDRV_O_FLAGS ; fmt =NULL ;for (;;) { - c =getopt (argc, argv,"f:h" ); + c =getopt (argc, argv,"f:hr:" );if (c ==-1 ) {break ; }
@@ -387,6 +395,17 @@ static int img_check(int argc, char **argv)case 'f' : fmt = optarg;break ; +case 'r' : + flags |=BDRV_O_RDWR ; + +if (!strcmp (optarg,"leaks" )) { + fix =BDRV_FIX_LEAKS ; + }else if (!strcmp (optarg,"all" )) { + fix =BDRV_FIX_LEAKS |BDRV_FIX_ERRORS ; + }else { +help (); + } +break ; } }if (optind >= argc) {
@@ -394,11 +413,11 @@ static int img_check(int argc, char **argv) } filename = argv[optind++]; - bs =bdrv_new_open (filename, fmt,BDRV_O_FLAGS ); + bs =bdrv_new_open (filename, fmt, flags);if (!bs) {return 1 ; } - ret =bdrv_check (bs, &result); + ret =bdrv_check (bs, &result, fix);if (ret == -ENOTSUP ) {error_report ("This image format does not support checks" );
qemu-img.texi +6 -1
@@ -70,10 +70,15 @@ lists all snapshots in the given image Command description: @table @option -@item check [-f @var{fmt}] @var{filename} +@item check [-f @var{fmt}] [-r [leaks | all]] @var{filename} Perform a consistency check on the disk image @var{filename}. +If @code{-r} is specified, qemu-img tries to repair any inconsistencies found +during the check. @code{-r leaks} repairs only cluster leaks, whereas +@code{-r all} fixes all kinds of errors, with a higher risk of choosing the +wrong fix or hiding corruption that has already occured. + Only the formats @code{qcow2}, @code{qed} and @code{vdi} support consistency checks.
Signature · 1 line
1.7.6.5
PATCH 9/12 qemu-img check: Print fixed clusters and recheck
In reply to Kevin WolfWhen any inconsistencies have been fixed, print the statistics and run another check to make sure everything is correct now.
--- block.h | 2 ++ block/qed-check.c | 2 ++ qemu-img.c | 10 ++++++++++ 3 files changed, 14 insertions(+), 0 deletions(-)
block.h +2 -0
@@ -187,6 +187,8 @@ typedef struct BdrvCheckResult {int corruptions;int leaks;int check_errors; +int corruptions_fixed; +int leaks_fixed;BlockFragInfo bfi; } BdrvCheckResult;
block/qed-check.c +2 -0
@@ -87,6 +87,7 @@ static unsigned int qed_check_l2_table(QEDCheck *check, QEDTable *table)if (!qed_check_cluster_offset (s, offset)) {if (check->fix) { table->offsets[i] =0 ; + check->result->corruptions_fixed++; }else { check->result->corruptions++; }
@@ -127,6 +128,7 @@ static int qed_check_l1_table(QEDCheck *check, QEDTable *table)/* Clear invalid offset */ if (check->fix) { table->offsets[i] =0 ; + check->result->corruptions_fixed++; }else { check->result->corruptions++; }
qemu-img.c +10 -0
@@ -425,6 +425,16 @@ static int img_check(int argc, char **argv)return 1 ; } +if (result.corruptions_fixed || result.leaks_fixed) { +printf ("The following inconsistencies were found and repaired:\n\n" +" %d leaked clusters\n" +" %d corruptions\n\n" +"Double checking the fixed image now...\n" , + result.leaks_fixed, + result.corruptions_fixed); + ret =bdrv_check (bs, &result,0 ); + } +if (!(result.corruptions || result.leaks || result.check_errors)) {printf ("No errors were found on the image.\n" ); }else {
Signature · 1 line
1.7.6.5
PATCH 10/12 qcow2: Support for fixing refcount inconsistencies
In reply to Kevin Wolf--- block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++---- block/qcow2.c | 6 +----- block/qcow2.h | 3 ++- 3 files changed, 30 insertions(+), 10 deletions(-)
block/qcow2-refcount.c +27 -4
@@ -1122,11 +1122,12 @@ fail:* Returns 0 if no errors are found, the number of errors in case the image is * detected as corrupted, and -errno when an internal error occurred. */ -int qcow2_check_refcounts (BlockDriverState *bs,BdrvCheckResult *res) +int qcow2_check_refcounts (BlockDriverState *bs,BdrvCheckResult *res, +BdrvCheckMode fix) {BDRVQcowState *s = bs->opaque; -int64_t size; -int nb_clusters, refcount1, refcount2, i; +int64_t size, i; +int nb_clusters, refcount1, refcount2;QCowSnapshot *sn;uint16_t *refcount_table;int ret;
@@ -1205,9 +1206,31 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res) refcount2 = refcount_table[i];if (refcount1 != refcount2) { + +/* Check if we're allowed to fix the mismatch */ +int *num_fixed =NULL ; +if (refcount1 > refcount2 && (fix &BDRV_FIX_LEAKS )) { + num_fixed = &res->leaks_fixed; + }else if (refcount1 < refcount2 && (fix &BDRV_FIX_ERRORS )) { + num_fixed = &res->corruptions_fixed; + } +fprintf (stderr,"%s cluster %d refcount=%d reference=%d\n" , - refcount1 < refcount2 ?"ERROR" :"Leaked" , + num_fixed !=NULL ?"Repairing" : + refcount1 < refcount2 ?"ERROR" : +"Leaked" , i, refcount1, refcount2); + +if (num_fixed) { + ret =update_refcount (bs, i << s->cluster_bits,1 , + refcount2 - refcount1); +if (ret >=0 ) { + (*num_fixed)++; +continue ; + } + } + +/* And if we couldn't, print an error */ if (refcount1 < refcount2) { res->corruptions++; }else {
block/qcow2.c +1 -5
@@ -1473,11 +1473,7 @@ static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)static int qcow2_check (BlockDriverState *bs,BdrvCheckResult *result,BdrvCheckMode fix) { -if (fix) { -return -ENOTSUP ; - } - -return qcow2_check_refcounts (bs, result); +return qcow2_check_refcounts (bs, result, fix); }#if 0
block/qcow2.h +2 -1
@@ -261,7 +261,8 @@ void qcow2_free_any_clusters(BlockDriverState *bs,int qcow2_update_snapshot_refcount (BlockDriverState *bs,int64_t l1_table_offset,int l1_size,int addend); -int qcow2_check_refcounts (BlockDriverState *bs,BdrvCheckResult *res); +int qcow2_check_refcounts (BlockDriverState *bs,BdrvCheckResult *res, +BdrvCheckMode fix);/* qcow2-cluster.c functions */ int qcow2_grow_l1_table (BlockDriverState *bs,int min_size,bool exact_size);
Signature · 1 line
1.7.6.5
PATCH 11/12 rbd: hook up cache options
In reply to Kevin WolfFrom: Josh Durgin <[email protected]>
Writeback caching was added in Ceph 0.46, and writethrough will be in 0.47. These are controlled by general config options, so there's no need to check for librbd version.
--- block/rbd.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
block/rbd.c +19 -0
@@ -476,6 +476,25 @@ static int qemu_rbd_open(BlockDriverState *bs, const char *filename, int flags) s->snap =g_strdup (snap_buf); } +/* +* Fallback to more conservative semantics if setting cache +* options fails. Ignore errors from setting rbd_cache because the +* only possible error is that the option does not exist, and +* librbd defaults to no caching. If write through caching cannot +* be set up, fall back to no caching. +*/ +if (flags &BDRV_O_NOCACHE ) { +rados_conf_set (s->cluster,"rbd_cache" ,"false" ); + }else { +rados_conf_set (s->cluster,"rbd_cache" ,"true" ); +if (!(flags &BDRV_O_CACHE_WB )) { + r =rados_conf_set (s->cluster,"rbd_cache_max_dirty" ,"0" ); +if (r <0 ) { +rados_conf_set (s->cluster,"rbd_cache" ,"false" ); + } + } + } +if (strstr (conf,"conf=" ) ==NULL ) {/* try default location, but ignore failure */ rados_conf_read_file (s->cluster,NULL );
Signature · 1 line
1.7.6.5
PATCH 12/12 sheepdog: add coroutine_fn markers to coroutine functions
In reply to Kevin WolfFrom: MORITA Kazutaka <[email protected]>
--- block/sheepdog.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
block/sheepdog.c +5 -4
@@ -522,8 +522,8 @@ static int send_req(int sockfd, SheepdogReq *hdr, void *data,return ret; } -static int send_co_req (int sockfd,SheepdogReq *hdr,void *data, -unsigned int *wlen) +static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data, +unsigned int *wlen) {int ret;
@@ -540,6 +540,7 @@ static int send_co_req(int sockfd, SheepdogReq *hdr, void *data,return ret; } +static int do_req (int sockfd,SheepdogReq *hdr,void *data,unsigned int *wlen,unsigned int *rlen) {
@@ -576,8 +577,8 @@ out:return ret; } -static int do_co_req (int sockfd,SheepdogReq *hdr,void *data, -unsigned int *wlen,unsigned int *rlen) +static coroutine_fn int do_co_req(int sockfd, SheepdogReq *hdr, void *data, +unsigned int *wlen,unsigned int *rlen) {int ret;
Signature · 1 line
1.7.6.5
Quoted 6 lines · Kevin Wolf
The following changes since commit
8cc9b43f7c5f826b39af4b012ad89bb55faac29c:target-microblaze: lwx/swx: first implementation (2012-06-04 10:19:46 +0200)are available in the git repository at:
git://repo.or.cz/qemu/kevin.gitfor-anthony
Pulled. Thanks.
Regards,
Anthony Liguori
Quoted 54 lines
Josh Durgin (1):
rbd: hook up cache optionsKevin Wolf (3):
qemu-img check -r for repairing images qemu-img check: Print fixed clusters and recheck
qcow2: Support for fixing refcount inconsistenciesMORITA Kazutaka (1):
sheepdog: addcoroutine_fnmarkers to coroutine functionsMarkus Armbruster (1):
Un-inlinefdctrl_init_isa()Paolo Bonzini (4):
block: implementis_allocatedfor raw
stream: tweak usage ofbdrv_co_is_allocated
stream: moveis_allocated_abovetoblock.c
stream: move rate limiting to a separate header fileZhi Yong Wu (2):
qcow2: remove a line of unnecessary code
qcow2: fix the byte endian convertionblock.c | 53 +++++++++++++++++++++- block.h | 13 +++++- block/qcow2-cluster.c | 1 - block/qcow2-refcount.c | 33 ++++++++++++-- block/qcow2.c | 5 +- block/qcow2.h | 3 +- block/qed-check.c | 2 + block/qed.c | 5 +- block/raw-posix.c | 98 +++++++++++++++++++++++++++++++++++++++++ block/raw.c | 8 +++ block/rbd.c | 19 ++++++++ block/sheepdog.c | 9 ++-- block/stream.c | 109 +++++++--------------------------------------- block/vdi.c | 7 +++- block_int.h | 3 +- hw/fdc.c | 20 ++++++++ hw/fdc.h | 24 +--------- hw/ide/piix.c | 3 +- hw/isa.h | 2 - hw/pc_sysfw.c | 1 + include/qemu/ratelimit.h | 48 ++++++++++++++++++++ qemu-common.h | 1 + qemu-img-cmds.hx | 4 +- qemu-img.c | 35 +++++++++++++- qemu-img.texi | 7 +++- 25 files changed, 369 insertions(+), 144 deletions(-)create mode 100644
include/qemu/ratelimit.h
Am 07.06.2012 03:17, schrieb Anthony Liguori:
Quoted 9 lines · Kevin Wolf
Quoted 6 lines
The following changes since commit
8cc9b43f7c5f826b39af4b012ad89bb55faac29c:target-microblaze: lwx/swx: first implementation (2012-06-04 10:19:46 +0200)are available in the git repository at:
git://repo.or.cz/qemu/kevin.gitfor-anthonyPulled. Thanks.
But not pushed?
Kevin
Quoted 4 lines · Kevin Wolf
Am 07.06.2012 03:17, schrieb Anthony Liguori:
Quoted 3 lines · Kevin Wolf
Quoted 2 lines
The following changes since commit
8cc9b43f7c5f826b39af4b012ad89bb55faac29c:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
target-microblaze: lwx/swx: first implementation (2012-06-04 10:19:46 +0200)are available in the git repository at:
git://repo.or.cz/qemu/kevin.gitfor-anthonyPulled. Thanks.
But not pushed?
I'm having a really hard time connecting to repo.or.cz here. Looks like I mistook a timeout for success and mistakenly merged nothing.
I'm still having trouble getting to repo.or.cz. I'll be back in the States Saturday evening so will process this pull Sunday or Monday.
Do you want to update the branch in the interim to fix the build issue?
Regards,
Anthony Liguori
Quoted 2 lines
Kevin
Am 08.06.2012 16:07, schrieb Anthony Liguori:
Quoted 12 lines · Kevin Wolf
Quoted 11 lines
Am 07.06.2012 03:17, schrieb Anthony Liguori:
Quoted 9 lines · Kevin Wolf
Quoted 6 lines
The following changes since commit
8cc9b43f7c5f826b39af4b012ad89bb55faac29c:target-microblaze: lwx/swx: first implementation (2012-06-04 10:19:46 +0200)are available in the git repository at:
git://repo.or.cz/qemu/kevin.gitfor-anthonyPulled. Thanks.
Quoted 7 lines
Quoted 1 line
But not pushed?
I'm having a really hard time connecting to repo.or.cz here. Looks like I mistook a timeout for success and mistakenly merged nothing.
I'm still having trouble getting to repo.or.cz. I'll be back in the States Saturday evening so will process this pull Sunday or Monday.
Hm, when repo.or.cz started behaving bad, I started to use things like 'while ! git fetch repo.or.cz; do sleep 1; done' (it would always succeed after a few attempts), but recently it never needed more than one attempt.
Quoted 1 line
Do you want to update the branch in the interim to fix the build issue?
Sure, updated it now.
Kevin