Message ID | 1330570168-8226-2-git-send-email-wdongxu@linux.vnet.ibm.com |
---|---|
State | New |
Headers | show |
On Thu, Mar 1, 2012 at 2:49 AM, Dong Xu Wang <wdongxu@linux.vnet.ibm.com> wrote: > From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> > > We can not use raw to support snapshot_file, but add-cow can do this. > > CC: Marcelo Tosatti <mtosatti@redhat.com> > CC: Kevin Wolf <kwolf@redhat.com> > CC: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> > Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> > --- > blockdev.c | 53 ++++++++++++++++++++++++++++++++++++++++++---- > docs/live-block-ops.txt | 8 ++++++- > 2 files changed, 55 insertions(+), 6 deletions(-) > > diff --git a/blockdev.c b/blockdev.c > index d78aa51..c820fcb 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -687,12 +687,55 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, > return; > } > > - ret = bdrv_img_create(snapshot_file, format, bs->filename, > - bs->drv->format_name, NULL, -1, flags); > - if (ret) { > - error_set(errp, QERR_UNDEFINED_ERROR); > - return; > + if (strcmp(format, "add-cow")) { > + ret = bdrv_img_create(snapshot_file, format, bs->filename, > + bs->drv->format_name, NULL, -1, flags); > + if (ret) { > + error_set(errp, QERR_UNDEFINED_ERROR); > + return; > + } I'm confused here because I thought we need three files: 1. The .add-cow file containing the bitmap 2. The cow image file containing allocated sectors 3. The backing file containing the original image We're only passing in snapshot_file and bs->filename. How will #2, the cow file, be created? Stefan
image file will be created automaticly, file name is formated as: sprintf(image_file, "%s.raw", snapshot_file); I just add ".raw" to the file name of #1 in you comments as file name of #2. On Wed, Mar 7, 2012 at 21:10, Stefan Hajnoczi <stefanha@gmail.com> wrote: > On Thu, Mar 1, 2012 at 2:49 AM, Dong Xu Wang <wdongxu@linux.vnet.ibm.com> wrote: >> From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> >> >> We can not use raw to support snapshot_file, but add-cow can do this. >> >> CC: Marcelo Tosatti <mtosatti@redhat.com> >> CC: Kevin Wolf <kwolf@redhat.com> >> CC: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> >> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> >> --- >> blockdev.c | 53 ++++++++++++++++++++++++++++++++++++++++++---- >> docs/live-block-ops.txt | 8 ++++++- >> 2 files changed, 55 insertions(+), 6 deletions(-) >> >> diff --git a/blockdev.c b/blockdev.c >> index d78aa51..c820fcb 100644 >> --- a/blockdev.c >> +++ b/blockdev.c >> @@ -687,12 +687,55 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, >> return; >> } >> >> - ret = bdrv_img_create(snapshot_file, format, bs->filename, >> - bs->drv->format_name, NULL, -1, flags); >> - if (ret) { >> - error_set(errp, QERR_UNDEFINED_ERROR); >> - return; >> + if (strcmp(format, "add-cow")) { >> + ret = bdrv_img_create(snapshot_file, format, bs->filename, >> + bs->drv->format_name, NULL, -1, flags); >> + if (ret) { >> + error_set(errp, QERR_UNDEFINED_ERROR); >> + return; >> + } > > I'm confused here because I thought we need three files: > 1. The .add-cow file containing the bitmap > 2. The cow image file containing allocated sectors > 3. The backing file containing the original image > > We're only passing in snapshot_file and bs->filename. How will #2, > the cow file, be created? > > Stefan >
On Thu, Mar 8, 2012 at 1:50 AM, Dong Xu Wang <wdongxu@linux.vnet.ibm.com> wrote: > image file will be created automaticly, file name is formated as: > sprintf(image_file, "%s.raw", snapshot_file); > > I just add ".raw" to the file name of #1 in you comments as file name of #2. Oops, I looked at the if (strcmp()) case instead of the else case. :) Stefan
diff --git a/blockdev.c b/blockdev.c index d78aa51..c820fcb 100644 --- a/blockdev.c +++ b/blockdev.c @@ -687,12 +687,55 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, return; } - ret = bdrv_img_create(snapshot_file, format, bs->filename, - bs->drv->format_name, NULL, -1, flags); - if (ret) { - error_set(errp, QERR_UNDEFINED_ERROR); - return; + if (strcmp(format, "add-cow")) { + ret = bdrv_img_create(snapshot_file, format, bs->filename, + bs->drv->format_name, NULL, -1, flags); + if (ret) { + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } + } else { + char image_file[1024]; + char option[1024]; + + uint64_t size; + BlockDriver *backing_drv = NULL; + BlockDriverState *backing_bs = NULL; + + backing_bs = bdrv_new(""); + backing_drv = bdrv_find_format(bs->drv->format_name); + if (!backing_drv) { + error_report("Unknown backing file format '%s'", + bs->drv->format_name); + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } + ret = bdrv_open(backing_bs, bs->filename, flags, backing_drv); + if (ret < 0) { + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } + bdrv_get_geometry(backing_bs, &size); + size *= 512; + bdrv_delete(backing_bs); + + sprintf(image_file, "%s.raw", snapshot_file); + + ret = bdrv_img_create(image_file, "raw", NULL, + NULL, NULL, size, flags); + if (ret) { + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } + sprintf(option, "image_file=%s.raw", snapshot_file); + ret = bdrv_img_create(snapshot_file, format, bs->filename, + bs->drv->format_name, option, -1, flags); + if (ret) { + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } } + bs->backing_format[0] = '\0'; bdrv_drain_all(); bdrv_flush(bs); diff --git a/docs/live-block-ops.txt b/docs/live-block-ops.txt index a257087..7edbf91 100644 --- a/docs/live-block-ops.txt +++ b/docs/live-block-ops.txt @@ -2,7 +2,8 @@ LIVE BLOCK OPERATIONS ===================== High level description of live block operations. Note these are not -supported for use with the raw format at the moment. +supported for use with the raw format at the moment, but we can use +add-cow as metadata to suport raw format. Snapshot live merge =================== @@ -55,4 +56,9 @@ into that image. Example: (qemu) block_stream ide0-hd0 +Raw is not supported, but we can use add-cow in the 1st step: +(qemu) snapshot_blkdev ide0-hd0 /new-path/disk.img add-cow + +It will create a raw file named disk.img.raw, with the same virtual size of +ide0-hd0 first, and then create disk.img.