add qemu-img convert -C option (skip target volume creation)
PATCH 1/1 add qemu-img convert -C option (skip target volume creation)
Add a -C 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.
Code:
Author: Alexandre Derumier <[email protected]>
Documentaton:
Author: Alex Bligh <[email protected]>
--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 37 ++++++++++++++++++++++--------------- qemu-img.texi | 15 ++++++++++++++- 3 files changed, 38 insertions(+), 18 deletions(-)
qemu-img-cmds.hx +2 -2
@@ -34,9 +34,9 @@ STEXI ETEXI DEF("convert", img_convert, - "convert [-c] [-p] [-q] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename") + "convert [-c] [-p] [-q] [-C] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename") STEXI -@item convert [-c] [-p] [-q] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p] [-q] [-C] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} ETEXI DEF("info", img_info,
qemu-img.c +22 -15
@@ -103,6 +103,7 @@ 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" +" '-C' skips the target volume creation (useful for rbd)\n" "\n" "Parameters to check subcommand:\n" " '-r' tries to repair any inconsistencies that are found during the check.\n"
@@ -1116,7 +1117,7 @@ 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, skipcreate;int progress =0 , flags;const char *fmt, *out_fmt, *cache, *out_baseimg, *out_filename;BlockDriver *drv, *proto_drv;
@@ -1139,8 +1140,9 @@ static int img_convert(int argc, char **argv) cache ="unsafe" ; out_baseimg =NULL ; compress =0 ; + skipcreate =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:qC" );if (c ==-1 ) {break ; }
@@ -1161,6 +1163,9 @@ static int img_convert(int argc, char **argv)case 'c' : compress =1 ;break ; +case 'C' : + skipcreate =1 ; +break ;case 'e' :error_report ("option -e is deprecated, please use \'-o " "encryption\' instead!" );
@@ -1329,20 +1334,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 (!skipcreate) { +/* 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 ;
qemu-img.texi +14 -1
@@ -96,6 +96,14 @@ Second image format Strict mode - fail on on different image size or sector allocation @end table +Parameters to convert subcommand: + +@table @option + +@item -C +Skip the creation of the target volume +@end table + Command description: @table @option
@@ -171,7 +179,7 @@ Error on reading data @end table -@item convert [-c] [-p] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p] [-C] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} Convert the disk image @var{filename} or a snapshot @var{snapshot_name} to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally compressed (@code{-c}
@@ -190,6 +198,11 @@ created as a copy on write image of the specified base image; the @var{backing_file} should have the same content as the input's base image, however the path, image format, etc may differ. +If the @code{-C} option is specified, the target volume creation will be +skipped. This is useful for formats such as @code{rbd} if the target +volume has already been created with site specific options that cannot +be supplied through qemu-img. + @item info [-f @var{fmt}] [--output=@var{ofmt}] [--backing-chain] @var{filename} Give information about the disk image @var{filename}. Use it in
Signature · 1 line
1.7.9.5
Quoted 44 lines · Alex Bligh
Add a -C 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.
Code:
Author: Alexandre Derumier <[email protected]>
Signed-off-by Alexandre Derumier <[email protected]>Signed-off-by Alex Bligh <[email protected]>Documentaton:
Author: Alex Bligh <[email protected]>
Signed-off-by Alex Bligh <[email protected]>--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 37 ++++++++++++++++++++++--------------- qemu-img.texi | 15 ++++++++++++++- 3 files changed, 38 insertions(+), 18 deletions(-)qemu-img-cmds.hx +2
-2@@ -34,9 +34,9 @@ STEXI ETEXI DEF("convert", img_convert, - "convert [-c] [-p] [-q] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename") + "convert [-c] [-p] [-q] [-C] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename") STEXI -@item convert [-c] [-p] [-q] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p] [-q] [-C] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} ETEXI DEF("info", img_info,qemu-img.c +0
-0
qemu-img.c static void help(void) · line 106
Quoted 4 lines
qemu-img.c +1
-0@@ -103,6 +103,7 @@ 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" +" '-C' skips the target volume creation (useful for rbd)\n"
The statement "useful for rbd" is not very informative, maybe you could use "'-C' skips the target volume creation (assuming it already exists)".
qemu-img.c out3: · line 1120
Quoted 9 lines
qemu-img.c +1
-1"\n" "Parameters to check subcommand:\n" " '-r' tries to repair any inconsistencies that are found during the check.\n" @@ -1116,7 +1117,7 @@ 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, skipcreate;
This line is too long, please break it.
Quoted 104 lines
qemu-img.c +20
-14int progress =0 , flags;const char *fmt, *out_fmt, *cache, *out_baseimg, *out_filename;BlockDriver *drv, *proto_drv;@@ -1139,8 +1140,9 @@ static int img_convert(int argc, char **argv) cache ="unsafe" ; out_baseimg =NULL ; compress =0 ; + skipcreate =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:qC" );if (c ==-1 ) {break ; }@@ -1161,6 +1163,9 @@ static int img_convert(int argc, char **argv)case 'c' : compress =1 ;break ; +case 'C' : + skipcreate =1 ; +break ;case 'e' :error_report ("option -e is deprecated, please use \'-o " "encryption\' instead!" );@@ -1329,20 +1334,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 (!skipcreate) { +/* 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 ;qemu-img.texi +14
-1@@ -96,6 +96,14 @@ Second image format Strict mode - fail on on different image size or sector allocation @end table +Parameters to convert subcommand: + +@table @option + +@item -C +Skip the creation of the target volume +@end table + Command description: @table @option@@ -171,7 +179,7 @@ Error on reading data @end table -@item convert [-c] [-p] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p] [-C] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} Convert the disk image @var{filename} or a snapshot @var{snapshot_name} to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally compressed (@code{-c}@@ -190,6 +198,11 @@ created as a copy on write image of the specified base image; the @var{backing_file} should have the same content as the input's base image, however the path, image format, etc may differ. +If the @code{-C} option is specified, the target volume creation will be +skipped. This is useful for formats such as @code{rbd} if the target +volume has already been created with site specific options that cannot +be supplied through qemu-img. + @item info [-f @var{fmt}] [--output=@var{ofmt}] [--backing-chain] @var{filename} Give information about the disk image @var{filename}. Use it inSignature · 1 line
1.7.9.5
Signature · 1 line
Fam
Quoted 10 lines · Fam Zheng
qemu-img.c static void help(void) · line 106
Quoted 7 lines
qemu-img.c +1
-0@@ -103,6 +103,7 @@ 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" +" '-C' skips the target volume creation (useful for rbd)\n" The statement "useful for rbd" is not very informative, maybe you could use "'-C' skips the target volume creation (assuming it already exists)".
Done with slightly different text - see v2 just posted
Quoted 6 lines
qemu-img.c out3: · line 1120
Quoted 4 lines
qemu-img.c +1
-1static 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, skipcreate;This line is too long, please break it.
Done in v2 just posted.
Signature · 1 line
Alex Bligh