]>
Commit | Line | Data |
---|---|---|
46598e97 AD |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: Alexandre Derumier <aderumier@odiso.com> | |
83faa3fe | 3 | Date: Mon, 6 Apr 2020 12:16:42 +0200 |
d7f4e01a | 4 | Subject: [PATCH] PVE: [Up] qemu-img dd: add -n skip_create |
46598e97 | 5 | |
b855dce7 | 6 | Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> |
107132be | 7 | [FE: fix getopt-string + add documentation] |
d03e1b3c | 8 | Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> |
46598e97 | 9 | --- |
107132be FE |
10 | docs/tools/qemu-img.rst | 11 ++++++++++- |
11 | qemu-img-cmds.hx | 4 ++-- | |
12 | qemu-img.c | 23 ++++++++++++++--------- | |
13 | 3 files changed, 26 insertions(+), 12 deletions(-) | |
46598e97 | 14 | |
107132be | 15 | diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst |
d03e1b3c | 16 | index 15aeddc6d8..5e713e231d 100644 |
107132be FE |
17 | --- a/docs/tools/qemu-img.rst |
18 | +++ b/docs/tools/qemu-img.rst | |
19 | @@ -208,6 +208,10 @@ Parameters to convert subcommand: | |
20 | ||
21 | Parameters to dd subcommand: | |
22 | ||
23 | +.. option:: -n | |
24 | + | |
25 | + Skip the creation of the target volume | |
26 | + | |
27 | .. program:: qemu-img-dd | |
28 | ||
29 | .. option:: bs=BLOCK_SIZE | |
30 | @@ -488,7 +492,7 @@ Command description: | |
31 | it doesn't need to be specified separately in this case. | |
32 | ||
33 | ||
34 | -.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [bs=BLOCK_SIZE] [count=BLOCKS] [skip=BLOCKS] if=INPUT of=OUTPUT | |
35 | +.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [-n] [bs=BLOCK_SIZE] [count=BLOCKS] [skip=BLOCKS] if=INPUT of=OUTPUT | |
36 | ||
37 | dd copies from *INPUT* file to *OUTPUT* file converting it from | |
38 | *FMT* format to *OUTPUT_FMT* format. | |
39 | @@ -499,6 +503,11 @@ Command description: | |
40 | ||
41 | The size syntax is similar to :manpage:`dd(1)`'s size syntax. | |
42 | ||
43 | + If the ``-n`` option is specified, the target volume creation will be | |
44 | + skipped. This is useful for formats such as ``rbd`` if the target | |
45 | + volume has already been created with site specific options that cannot | |
46 | + be supplied through ``qemu-img``. | |
47 | + | |
48 | .. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=OFMT] [--backing-chain] [-U] FILENAME | |
49 | ||
50 | Give information about the disk image *FILENAME*. Use it in | |
51 | diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx | |
dc9827a6 | 52 | index d1616c045a..b5b0bb4467 100644 |
107132be FE |
53 | --- a/qemu-img-cmds.hx |
54 | +++ b/qemu-img-cmds.hx | |
55 | @@ -58,9 +58,9 @@ SRST | |
56 | ERST | |
57 | ||
58 | DEF("dd", img_dd, | |
59 | - "dd [--image-opts] [-U] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [osize=output_size] if=input of=output") | |
60 | + "dd [--image-opts] [-U] [-f fmt] [-O output_fmt] [-n] [bs=block_size] [count=blocks] [skip=blocks] [osize=output_size] if=input of=output") | |
61 | SRST | |
62 | -.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [bs=BLOCK_SIZE] [count=BLOCKS] [skip=BLOCKS] [osize=OUTPUT_SIZE] if=INPUT of=OUTPUT | |
63 | +.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [-n] [bs=BLOCK_SIZE] [count=BLOCKS] [skip=BLOCKS] [osize=OUTPUT_SIZE] if=INPUT of=OUTPUT | |
64 | ERST | |
65 | ||
66 | DEF("info", img_info, | |
46598e97 | 67 | diff --git a/qemu-img.c b/qemu-img.c |
4b7975e7 | 68 | index 58bf9b43d1..9d414d639b 100644 |
46598e97 AD |
69 | --- a/qemu-img.c |
70 | +++ b/qemu-img.c | |
4b7975e7 | 71 | @@ -5024,7 +5024,7 @@ static int img_dd(int argc, char **argv) |
46598e97 AD |
72 | const char *fmt = NULL; |
73 | int64_t size = 0, readsize = 0; | |
d03e1b3c | 74 | int64_t out_pos, in_pos; |
46598e97 AD |
75 | - bool force_share = false; |
76 | + bool force_share = false, skip_create = false; | |
77 | struct DdInfo dd = { | |
78 | .flags = 0, | |
79 | .count = 0, | |
4b7975e7 | 80 | @@ -5062,7 +5062,7 @@ static int img_dd(int argc, char **argv) |
46598e97 AD |
81 | { 0, 0, 0, 0 } |
82 | }; | |
83 | ||
84 | - while ((c = getopt_long(argc, argv, ":hf:O:U", long_options, NULL))) { | |
107132be | 85 | + while ((c = getopt_long(argc, argv, ":hf:O:Un", long_options, NULL))) { |
46598e97 AD |
86 | if (c == EOF) { |
87 | break; | |
88 | } | |
4b7975e7 | 89 | @@ -5082,6 +5082,9 @@ static int img_dd(int argc, char **argv) |
46598e97 AD |
90 | case 'h': |
91 | help(); | |
92 | break; | |
93 | + case 'n': | |
94 | + skip_create = true; | |
95 | + break; | |
96 | case 'U': | |
97 | force_share = true; | |
98 | break; | |
4b7975e7 | 99 | @@ -5212,13 +5215,15 @@ static int img_dd(int argc, char **argv) |
46598e97 AD |
100 | size - in.bsz * in.offset, &error_abort); |
101 | } | |
102 | ||
103 | - ret = bdrv_create(drv, out.filename, opts, &local_err); | |
104 | - if (ret < 0) { | |
105 | - error_reportf_err(local_err, | |
106 | - "%s: error while creating output image: ", | |
107 | - out.filename); | |
108 | - ret = -1; | |
109 | - goto out; | |
110 | + if (!skip_create) { | |
111 | + ret = bdrv_create(drv, out.filename, opts, &local_err); | |
112 | + if (ret < 0) { | |
113 | + error_reportf_err(local_err, | |
114 | + "%s: error while creating output image: ", | |
115 | + out.filename); | |
116 | + ret = -1; | |
117 | + goto out; | |
118 | + } | |
119 | } | |
120 | ||
121 | /* TODO, we can't honour --image-opts for the target, |