FVD: add internal snapshot functionality
Subsystems (2)
PATCH 1/1 FVD: add internal snapshot functionality
This patch is part of the Fast Virtual Disk (FVD) proposal. See http://wiki.qemu.org/Features/FVD.
This patch adds to FVD the feature of internal snapsot, which is a big step forward over QCOW's snapshot function in terms of efficiency. FVD's snapshot implementation achieves the following ideal properties of a snapshot function:
G1: Do no harm (or avoid being a misfeature), i.e., the added snapshot code should not slow down the runtime performance of an image that has no snapshots. This implies that an image without snapshot should not cache the reference count table in memory and should not update the on-disk reference count table.
G2: Even better, an image with 1 snapshot runs as fast as an image without snapshot.
G3: Even even better, an image with 1,000 snapshots runs as fast as an image without snapshot. This basically means getting the snapshot feature for free.
G4: An image with 1,000 snapshots consumes no more memory than an image without snapshot. This again means getting the snapshot feature for free.
G5: Regardless of the number of existing snapshots, creating a new snapshot is fast, e.g., taking no more than 1 second.
G6: Regardless of the number of existing snapshots, deleting a snapshot is fast, e.g., taking no more than 1 second.
FVD's internal snapshot achieves the ideal properties of G1-G6, by 1) using the reference count table to only track "static" snapshots, 2) not keeping the reference count table in memory, 3) not updating the on-disk "static" reference count table when the VM runs, and 4) efficiently tracking dynamically allocated blocks by piggybacking on FVD's other features, i.e., its journal and small one-level lookup table.
--- Makefile.objs | 2 +- block.c | 2 +- block/blksim.c | 25 +- block/fvd-create.c | 272 ++++++++------- block/fvd-debug.c | 16 +- block/fvd-flush.c | 192 ----------- block/fvd-journal-buf.c | 52 ++-- block/fvd-journal.c | 159 +++++---- block/fvd-load.c | 43 ++- block/fvd-misc.c | 202 +++++++---- block/fvd-open.c | 381 ++++++++++++++------- block/fvd-prefetch.c | 2 +- block/fvd-read.c | 8 +- block/fvd-snapshot.c | 878 +++++++++++++++++++++++++++++++++++++++++++++++ block/fvd-store.c | 321 ++++++++++++------ block/fvd-update.c | 260 +++++++++++++-- block/fvd-write.c | 398 +++++++++++++++------- block/fvd.c | 15 +- block/fvd.h | 188 ++++++----- bswap.h | 24 ++ qemu-img.c | 2 +- qemu-io-auto.c | 9 +- qemu-option.c | 12 +- test-fvd.sh | 115 +++++-- test-qcow2.sh | 4 +- test-vdi.sh | 2 +- 26 files changed, 2554 insertions(+), 1030 deletions(-) delete mode 100644 block/fvd-flush.c create mode 100644 block/fvd-snapshot.c
Makefile.objs +1 -1
@@ -15,6 +15,7 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o +block-obj-y += bitops.o bitmap.o block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
@@ -101,7 +102,6 @@ common-obj-y += msmouse.o ps2.o common-obj-y += qdev.o qdev-properties.o common-obj-y += block-migration.o common-obj-y += pflib.o -common-obj-y += bitmap.o bitops.o common-obj-$(CONFIG_BRLAPI) += baum.o common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
block.c +1 -1
@@ -58,7 +58,7 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,static int bdrv_write_em (BlockDriverState *bs,int64_t sector_num,const uint8_t *buf,int nb_sectors); -QTAILQ_HEAD(, BlockDriverState) bdrv_states = +static QTAILQ_HEAD(, BlockDriverState) bdrv_states =QTAILQ_HEAD_INITIALIZER (bdrv_states); static QLIST_HEAD(, BlockDriver) bdrv_drivers =
block/blksim.c +12 -13
@@ -116,9 +116,10 @@ static int do_io(BlockDriverState * bs, int64_t sector_num, uint8_t * buf, sector_num, nb_sectors); } -if ((ret=lseek (s->fd, sector_num *512 ,SEEK_SET )) <0 ) { +if (lseek64 (s->fd, (off64_t)(sector_num *512 ),SEEK_SET ) <0 ) {fprintf (stderr,"Error: lseek %s sector_num=%" PRId64"\n" , bs->filename, sector_num); +abort (); }/* Buffer must be aligned for O_DIRECT. */
@@ -464,13 +465,12 @@ static void run_task_by_acb(SimAIOCB * acb)if (acb->ret ==0 ) {if (acb->qiov->niov ==1 ) { -if (blksim_read - (bs, acb->sector_num, acb->qiov->iov->iov_base, - acb->nb_sectors) !=0 ) { +if (blksim_read (bs, acb->sector_num, acb->qiov->iov->iov_base, + acb->nb_sectors) !=0 ) {fprintf (stderr,"Error in reading %s sector_num=%" PRId64" nb_sectors=%d\n" , acb->common.bs->filename, acb->sector_num, acb->nb_sectors); -exit (1 ); +abort (); } }else {uint8_t *buf =qemu_blockalign (acb->common.bs, acb->qiov->size);
@@ -478,7 +478,7 @@ static void run_task_by_acb(SimAIOCB * acb)fprintf (stderr,"Error in reading %s sector_num=%" PRId64" nb_sectors=%d\n" , acb->common.bs->filename, acb->sector_num, acb->nb_sectors); -exit (1 ); +abort (); }qemu_iovec_from_buffer (acb->qiov, buf, acb->qiov->size);qemu_vfree (buf);
@@ -499,7 +499,7 @@ static void run_task_by_acb(SimAIOCB * acb)fprintf (stderr,"Error in writing %s sector_num=%" PRId64" nb_sectors=%d\n" , acb->common.bs->filename, acb->sector_num, acb->nb_sectors); -exit (1 ); +abort (); } }else { uint8_t *buf = qemu_blockalign(acb->common.bs,
@@ -509,7 +509,7 @@ static void run_task_by_acb(SimAIOCB * acb)fprintf (stderr,"Error in writing %s sector_num=%" PRId64" nb_sectors=%d\n" , acb->common.bs->filename, acb->sector_num, acb->nb_sectors); -exit (1 ); +abort (); }qemu_vfree (buf); }
@@ -625,6 +625,7 @@ static int blksim_open(BlockDriverState * bs, const char *filename, {BDRVSimState *s = bs->opaque;int open_flags =O_BINARY |O_LARGEFILE ; +int64_t len; blksim_invoked = true;
@@ -644,13 +645,11 @@ static int blksim_open(BlockDriverState * bs, const char *filename,return -errno; } -int64_t len =lseek (s->fd,0 ,SEEK_END ); -if (len >=0 ) { - bs->total_sectors = len /512 ; - }else { - bs->total_sectors =0 ; +if ((len =lseek64 (s->fd, (off64_t )0 ,SEEK_END )) <0 ) { +return len; } + bs->total_sectors = len /512 ; bs->growable =1 ; bs->buffer_alignment =512 ;return 0 ;
block/fvd-create.c +146 -126
495 lines not on this page · raw message
block/fvd-debug.c +13 -3
@@ -51,6 +51,7 @@ static void TRACE_STORE_IN_FVD(const char *str, int64_t sector_num,#ifndef FVD_DEBUG #define my_qemu_malloc qemu_malloc +#define my_qemu_realloc (p,old_size,new_size) qemu_realloc(p,new_size)#define my_qemu_mallocz qemu_mallocz#define my_qemu_blockalign qemu_blockalign#define my_qemu_free qemu_free
@@ -71,6 +72,10 @@ static int alloc_line;#define my_qemu_malloc (size) \ ((void*)(alloc_file=__FILE__, alloc_line=__LINE__, _my_qemu_malloc(size))) +#define my_qemu_realloc (p,old_size,new_size) \ + ((void*)(alloc_file=__FILE__, alloc_line=__LINE__, \ + _my_qemu_realloc(p,old_size,new_size))) +#define my_qemu_mallocz (size) \ ((void*)(alloc_file=__FILE__, alloc_line=__LINE__, _my_qemu_mallocz(size)))
@@ -94,7 +99,6 @@ static void COPY_UUID(FvdAIOCB * to, FvdAIOCB * from) {if (from) { to->uuid = from->uuid; -FVD_DEBUG_ACB (to); } }
@@ -210,8 +214,6 @@ static inline void *_my_qemu_aio_get(AIOPool * pool, BlockDriverState * bs, acb->uuid = ++fvd_uuid; acb->magic =FVDAIOCB_MAGIC ; -FVD_DEBUG_ACB (acb); -#ifdef DEBUG_MEMORY_LEAK trace_alloc (&acb->tracer,-1 );#endif
@@ -306,6 +308,14 @@ static inline void _my_qemu_vfree(void *ptr)#endif } +static inline void *_my_qemu_realloc (void *p,size_t old_size,size_t new_size) +{ +void *q =_my_qemu_malloc (new_size); +memcpy (q, p,MIN (old_size, new_size)); +_my_qemu_free (p); +return q; +} +static void count_pending_requests (BDRVFvdState * s) {int m =0 , n =0 , k =0 ;
block/fvd-flush.c deleted +0 -192
192 lines not on this page · raw message
block/fvd-journal-buf.c +25 -27
129 lines not on this page · raw message
block/fvd-journal.c +84 -75
346 lines not on this page · raw message
block/fvd-load.c +23 -20
142 lines not on this page · raw message
block/fvd-misc.c +133 -69
281 lines not on this page · raw message
block/fvd-open.c +253 -128
527 lines not on this page · raw message
block/fvd-prefetch.c +1 -1
@@ -25,7 +25,7 @@ void fvd_init_prefetch(void *opaque)QDEBUG ("Start prefetching\n" );if (!s->data_region_prepared) { -init_data_region (s); +init_data_region (bs); } s->prefetch_acb =my_qemu_malloc (sizeof (FvdAIOCB *)*s->num_prefetch_slots);
block/fvd-read.c +2 -6
@@ -19,10 +19,6 @@ static inline void calc_read_region(BDRVFvdState * s, int64_t sector_num,int64_t * p_last_sec_in_fvd, int64_t * p_first_sec_in_backing, int64_t * p_last_sec_in_backing); -static inline BlockDriverAIOCB *load_data (FvdAIOCB * parent_acb, -BlockDriverState * bs,int64_t sector_num, -QEMUIOVector * orig_qiov,int nb_sectors, -BlockDriverCompletionFunc * cb,void *opaque); static BlockDriverAIOCB *fvd_aio_readv(BlockDriverState * bs, int64_t sector_num, QEMUIOVector * qiov,
@@ -34,7 +30,7 @@ static BlockDriverAIOCB *fvd_aio_readv(BlockDriverState * bs,TRACE_REQUEST (false, sector_num, nb_sectors);if (!s->data_region_prepared) { -init_data_region (s); +init_data_region (bs); } if (s->prefetch_state == PREFETCH_STATE_FINISHED
@@ -156,7 +152,7 @@ static BlockDriverAIOCB *fvd_aio_readv(BlockDriverState * bs,int buf_size = acb->read.read_fvd.iov.iov_len +ROUND_UP (bitmap_bytes,512 ); acb->read.read_fvd.iov.iov_base = -my_qemu_blockalign (s->fvd_data, buf_size); +my_qemu_blockalign (bs->file, buf_size);uint8_t *saved_bitmap = ((uint8_t *) acb->read.read_fvd.iov.iov_base) + acb->read.read_fvd.iov.iov_len;memcpy (saved_bitmap, s->fresh_bitmap + b, bitmap_bytes);
block/fvd-snapshot.c new file +878 -0
712 lines not on this page · raw message
block/fvd-store.c +224 -97
321 lines not on this page · raw message
block/fvd-update.c +237 -23
260 lines not on this page · raw message
block/fvd-write.c +276 -122
398 lines not on this page · raw message
block/fvd.h +108 -80
188 lines not on this page · raw message
test-fvd.sh +85 -30
115 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.0.4
Part of the diff is not shown here. View the raw message.