mirror of https://gitee.com/openkylin/libvirt.git
storage: add support for creating qcow2 images with extensions
Add -o compat= and -o lazy_refcounts options for qemu-img.
This commit is contained in:
parent
31d42506fb
commit
6298f74d9a
|
@ -633,9 +633,15 @@ static int
|
||||||
virStorageBackendCreateQemuImgOpts(char **opts,
|
virStorageBackendCreateQemuImgOpts(char **opts,
|
||||||
const char *backingType,
|
const char *backingType,
|
||||||
bool encryption,
|
bool encryption,
|
||||||
bool preallocate)
|
bool preallocate,
|
||||||
|
int format,
|
||||||
|
const char *compat,
|
||||||
|
virBitmapPtr features)
|
||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
bool b;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (backingType)
|
if (backingType)
|
||||||
virBufferAsprintf(&buf, "backing_fmt=%s,", backingType);
|
virBufferAsprintf(&buf, "backing_fmt=%s,", backingType);
|
||||||
if (encryption)
|
if (encryption)
|
||||||
|
@ -643,16 +649,46 @@ virStorageBackendCreateQemuImgOpts(char **opts,
|
||||||
if (preallocate)
|
if (preallocate)
|
||||||
virBufferAddLit(&buf, "preallocation=metadata,");
|
virBufferAddLit(&buf, "preallocation=metadata,");
|
||||||
|
|
||||||
|
if (compat)
|
||||||
|
virBufferAsprintf(&buf, "compat=%s,", compat);
|
||||||
|
if (features && format == VIR_STORAGE_FILE_QCOW2) {
|
||||||
|
for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) {
|
||||||
|
ignore_value(virBitmapGetBit(features, i, &b));
|
||||||
|
if (b) {
|
||||||
|
switch ((enum virStorageFileFeature) i) {
|
||||||
|
case VIR_STORAGE_FILE_FEATURE_LAZY_REFCOUNTS:
|
||||||
|
if (STREQ_NULLABLE(compat, "0.10")) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("Feature %s not supported with compat"
|
||||||
|
" level %s"),
|
||||||
|
virStorageFileFeatureTypeToString(i),
|
||||||
|
compat);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VIR_STORAGE_FILE_FEATURE_NONE:
|
||||||
|
case VIR_STORAGE_FILE_FEATURE_LAST:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
virBufferAsprintf(&buf, "%s,",
|
||||||
|
virStorageFileFeatureTypeToString(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virBufferTrim(&buf, ",", -1);
|
virBufferTrim(&buf, ",", -1);
|
||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(&buf))
|
||||||
virBufferFreeAndReset(&buf);
|
goto no_memory;
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*opts = virBufferContentAndReset(&buf);
|
*opts = virBufferContentAndReset(&buf);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
no_memory:
|
||||||
|
virReportOOMError();
|
||||||
|
error:
|
||||||
|
virBufferFreeAndReset(&buf);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virCommandPtr
|
virCommandPtr
|
||||||
|
@ -695,6 +731,16 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
||||||
_("metadata preallocation only available with qcow2"));
|
_("metadata preallocation only available with qcow2"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (vol->target.compat && vol->target.format != VIR_STORAGE_FILE_QCOW2) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("compatibility option only available with qcow2"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (vol->target.features && vol->target.format != VIR_STORAGE_FILE_QCOW2) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("format features only available with qcow2"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (inputvol) {
|
if (inputvol) {
|
||||||
if (!(inputPath = inputvol->target.path)) {
|
if (!(inputPath = inputvol->target.path)) {
|
||||||
|
@ -816,7 +862,10 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
||||||
if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS) {
|
if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS) {
|
||||||
if (virStorageBackendCreateQemuImgOpts(&opts,
|
if (virStorageBackendCreateQemuImgOpts(&opts,
|
||||||
backing ? backingType : NULL,
|
backing ? backingType : NULL,
|
||||||
do_encryption, preallocate) < 0)
|
do_encryption, preallocate,
|
||||||
|
vol->target.format,
|
||||||
|
vol->target.compat,
|
||||||
|
vol->target.features) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (opts)
|
if (opts)
|
||||||
virCommandAddArgList(cmd, "-o", opts, NULL);
|
virCommandAddArgList(cmd, "-o", opts, NULL);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
qemu-img create -f qcow2 -b /dev/null -o backing_fmt=raw,encryption=on,compat=1.1 /var/lib/libvirt/images/OtherDemo.img 5242880K
|
|
@ -0,0 +1 @@
|
||||||
|
qemu-img create -f qcow2 -b /dev/null -o backing_fmt=raw,encryption=on,compat=1.1,lazy_refcounts /var/lib/libvirt/images/OtherDemo.img 5242880K
|
|
@ -0,0 +1,35 @@
|
||||||
|
<volume>
|
||||||
|
<name>OtherDemo.img</name>
|
||||||
|
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||||
|
<source>
|
||||||
|
</source>
|
||||||
|
<capacity unit="G">5</capacity>
|
||||||
|
<allocation>294912</allocation>
|
||||||
|
<target>
|
||||||
|
<path>/var/lib/libvirt/images/OtherDemo.img</path>
|
||||||
|
<format type='qcow2'/>
|
||||||
|
<permissions>
|
||||||
|
<mode>0644</mode>
|
||||||
|
<owner>0</owner>
|
||||||
|
<group>0</group>
|
||||||
|
<label>unconfined_u:object_r:virt_image_t:s0</label>
|
||||||
|
</permissions>
|
||||||
|
<encryption format='qcow'>
|
||||||
|
<secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
|
||||||
|
</encryption>
|
||||||
|
<compat>0.10</compat>
|
||||||
|
<features>
|
||||||
|
<lazy_refcounts/>
|
||||||
|
</features>
|
||||||
|
</target>
|
||||||
|
<backingStore>
|
||||||
|
<path>/dev/null</path>
|
||||||
|
<format type='raw'/>
|
||||||
|
<permissions>
|
||||||
|
<mode>0644</mode>
|
||||||
|
<owner>0</owner>
|
||||||
|
<group>0</group>
|
||||||
|
<label>unconfined_u:object_r:virt_image_t:s0</label>
|
||||||
|
</permissions>
|
||||||
|
</backingStore>
|
||||||
|
</volume>
|
|
@ -0,0 +1,32 @@
|
||||||
|
<volume>
|
||||||
|
<name>OtherDemo.img</name>
|
||||||
|
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||||
|
<source>
|
||||||
|
</source>
|
||||||
|
<capacity unit="G">5</capacity>
|
||||||
|
<allocation>294912</allocation>
|
||||||
|
<target>
|
||||||
|
<path>/var/lib/libvirt/images/OtherDemo.img</path>
|
||||||
|
<format type='qcow2'/>
|
||||||
|
<permissions>
|
||||||
|
<mode>0644</mode>
|
||||||
|
<owner>0</owner>
|
||||||
|
<group>0</group>
|
||||||
|
<label>unconfined_u:object_r:virt_image_t:s0</label>
|
||||||
|
</permissions>
|
||||||
|
<encryption format='qcow'>
|
||||||
|
<secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
|
||||||
|
</encryption>
|
||||||
|
<features/>
|
||||||
|
</target>
|
||||||
|
<backingStore>
|
||||||
|
<path>/dev/null</path>
|
||||||
|
<format type='raw'/>
|
||||||
|
<permissions>
|
||||||
|
<mode>0644</mode>
|
||||||
|
<owner>0</owner>
|
||||||
|
<group>0</group>
|
||||||
|
<label>unconfined_u:object_r:virt_image_t:s0</label>
|
||||||
|
</permissions>
|
||||||
|
</backingStore>
|
||||||
|
</volume>
|
|
@ -0,0 +1,35 @@
|
||||||
|
<volume>
|
||||||
|
<name>OtherDemo.img</name>
|
||||||
|
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||||
|
<source>
|
||||||
|
</source>
|
||||||
|
<capacity unit="G">5</capacity>
|
||||||
|
<allocation>294912</allocation>
|
||||||
|
<target>
|
||||||
|
<path>/var/lib/libvirt/images/OtherDemo.img</path>
|
||||||
|
<format type='qcow2'/>
|
||||||
|
<permissions>
|
||||||
|
<mode>0644</mode>
|
||||||
|
<owner>0</owner>
|
||||||
|
<group>0</group>
|
||||||
|
<label>unconfined_u:object_r:virt_image_t:s0</label>
|
||||||
|
</permissions>
|
||||||
|
<encryption format='qcow'>
|
||||||
|
<secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
|
||||||
|
</encryption>
|
||||||
|
<compat>1.1</compat>
|
||||||
|
<features>
|
||||||
|
<lazy_refcounts/>
|
||||||
|
</features>
|
||||||
|
</target>
|
||||||
|
<backingStore>
|
||||||
|
<path>/dev/null</path>
|
||||||
|
<format type='raw'/>
|
||||||
|
<permissions>
|
||||||
|
<mode>0644</mode>
|
||||||
|
<owner>0</owner>
|
||||||
|
<group>0</group>
|
||||||
|
<label>unconfined_u:object_r:virt_image_t:s0</label>
|
||||||
|
</permissions>
|
||||||
|
</backingStore>
|
||||||
|
</volume>
|
|
@ -188,6 +188,12 @@ mymain(void)
|
||||||
"qcow2-nobacking-none", 0, FMT_NONE);
|
"qcow2-nobacking-none", 0, FMT_NONE);
|
||||||
DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", "vol-file",
|
DO_TEST(false, "pool-dir", "vol-qcow2-nobacking", "vol-file",
|
||||||
"qcow2-nobacking-convert-none", 0, FMT_NONE);
|
"qcow2-nobacking-convert-none", 0, FMT_NONE);
|
||||||
|
DO_TEST(false, "pool-dir", "vol-qcow2-lazy", NULL, "qcow2-lazy", 0,
|
||||||
|
FMT_OPTIONS);
|
||||||
|
DO_TEST(false, "pool-dir", "vol-qcow2-1.1", NULL, "qcow2-1.1", 0,
|
||||||
|
FMT_OPTIONS);
|
||||||
|
DO_TEST(true, "pool-dir", "vol-qcow2-0.10-lazy", NULL, "qcow2-0.10-lazy", 0,
|
||||||
|
FMT_OPTIONS);
|
||||||
|
|
||||||
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue