mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
add qemu-img convert -n option (skip target volume creation)
Add a -n option to skip volume creation on qemu-img convert. This is useful for targets such as rbd / ceph, where the target volume may already exist; we cannot always rely on qemu-img convert to create the image, as dependent on the output format, there may be parameters which are not possible to specify through the qemu-img convert command line. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Alexandre Derumier <aderumier@odiso.com> Signed-off-by: Alex Bligh <alex@alex.org.uk> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
b3f3a30f38
commit
b2e10493c7
6 changed files with 162 additions and 18 deletions
53
qemu-img.c
53
qemu-img.c
|
@ -103,6 +103,8 @@ 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"
|
||||
" '--output' takes the format in which the output must be done (human or json)\n"
|
||||
" '-n' skips the target volume creation (useful if the volume is created\n"
|
||||
" prior to running qemu-img)\n"
|
||||
"\n"
|
||||
"Parameters to check subcommand:\n"
|
||||
" '-r' tries to repair any inconsistencies that are found during the check.\n"
|
||||
|
@ -1116,7 +1118,8 @@ out3:
|
|||
|
||||
static int img_convert(int argc, char **argv)
|
||||
{
|
||||
int c, ret = 0, n, n1, bs_n, bs_i, compress, cluster_size, cluster_sectors;
|
||||
int c, ret = 0, n, n1, bs_n, bs_i, compress, cluster_size,
|
||||
cluster_sectors, skip_create;
|
||||
int progress = 0, flags;
|
||||
const char *fmt, *out_fmt, *cache, *out_baseimg, *out_filename;
|
||||
BlockDriver *drv, *proto_drv;
|
||||
|
@ -1139,8 +1142,9 @@ static int img_convert(int argc, char **argv)
|
|||
cache = "unsafe";
|
||||
out_baseimg = NULL;
|
||||
compress = 0;
|
||||
skip_create = 0;
|
||||
for(;;) {
|
||||
c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:q");
|
||||
c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:qn");
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
@ -1197,6 +1201,9 @@ static int img_convert(int argc, char **argv)
|
|||
case 'q':
|
||||
quiet = true;
|
||||
break;
|
||||
case 'n':
|
||||
skip_create = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1329,20 +1336,22 @@ static int img_convert(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
/* Create the new image */
|
||||
ret = bdrv_create(drv, out_filename, param);
|
||||
if (ret < 0) {
|
||||
if (ret == -ENOTSUP) {
|
||||
error_report("Formatting not supported for file format '%s'",
|
||||
out_fmt);
|
||||
} else if (ret == -EFBIG) {
|
||||
error_report("The image size is too large for file format '%s'",
|
||||
out_fmt);
|
||||
} else {
|
||||
error_report("%s: error while converting %s: %s",
|
||||
out_filename, out_fmt, strerror(-ret));
|
||||
if (!skip_create) {
|
||||
/* Create the new image */
|
||||
ret = bdrv_create(drv, out_filename, param);
|
||||
if (ret < 0) {
|
||||
if (ret == -ENOTSUP) {
|
||||
error_report("Formatting not supported for file format '%s'",
|
||||
out_fmt);
|
||||
} else if (ret == -EFBIG) {
|
||||
error_report("The image size is too large for file format '%s'",
|
||||
out_fmt);
|
||||
} else {
|
||||
error_report("%s: error while converting %s: %s",
|
||||
out_filename, out_fmt, strerror(-ret));
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
flags = BDRV_O_RDWR;
|
||||
|
@ -1363,6 +1372,20 @@ static int img_convert(int argc, char **argv)
|
|||
bdrv_get_geometry(bs[0], &bs_sectors);
|
||||
buf = qemu_blockalign(out_bs, IO_BUF_SIZE);
|
||||
|
||||
if (skip_create) {
|
||||
int64_t output_length = bdrv_getlength(out_bs);
|
||||
if (output_length < 0) {
|
||||
error_report("unable to get output image length: %s\n",
|
||||
strerror(-output_length));
|
||||
ret = -1;
|
||||
goto out;
|
||||
} else if (output_length < total_sectors << BDRV_SECTOR_BITS) {
|
||||
error_report("output file is smaller than input file");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (compress) {
|
||||
ret = bdrv_get_info(out_bs, &bdi);
|
||||
if (ret < 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue