提交 1ffc78b5 编写于 作者: D Daniel P. Berrange

Support creation of sparse LVM volumes

When calling 'lvcreate' if specifying both the '-L' and
'--virtualsize' options, the latter will be treated as
the capacity and the former as the allocation. This can
be used to support sparse volume creation. In addition,
when listing volumes it is necessary to include the 'size'
field in lvs output, so that we can detect sparse volume
allocation correctly.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 258e06c8
...@@ -171,6 +171,11 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, ...@@ -171,6 +171,11 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
"%s", _("malformed volume extent size value")); "%s", _("malformed volume extent size value"));
goto cleanup; goto cleanup;
} }
if (virStrToLong_ull(groups[8], NULL, 10, &vol->allocation) < 0) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed volume allocation value"));
goto cleanup;
}
/* Now parse the "devices" field separately */ /* Now parse the "devices" field separately */
regex = strdup(regex_unit); regex = strdup(regex_unit);
...@@ -271,12 +276,12 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool, ...@@ -271,12 +276,12 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol) virStorageVolDefPtr vol)
{ {
/* /*
* # lvs --separator , --noheadings --units b --unbuffered --nosuffix --options "lv_name,origin,uuid,devices,seg_size,vg_extent_size" VGNAME * # lvs --separator , --noheadings --units b --unbuffered --nosuffix --options "lv_name,origin,uuid,devices,seg_size,vg_extent_size,size" VGNAME
* RootLV,,06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky,/dev/hda2(0),5234491392,33554432 * RootLV,,06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky,/dev/hda2(0),5234491392,33554432,5234491392
* SwapLV,,oHviCK-8Ik0-paqS-V20c-nkhY-Bm1e-zgzU0M,/dev/hda2(156),1040187392,33554432 * SwapLV,,oHviCK-8Ik0-paqS-V20c-nkhY-Bm1e-zgzU0M,/dev/hda2(156),1040187392,33554432,1040187392
* Test2,,3pg3he-mQsA-5Sui-h0i6-HNmc-Cz7W-QSndcR,/dev/hda2(219),1073741824,33554432 * Test2,,3pg3he-mQsA-5Sui-h0i6-HNmc-Cz7W-QSndcR,/dev/hda2(219),1073741824,33554432,1073741824
* Test3,,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(251),2181038080,33554432 * Test3,,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(251),2181038080,33554432,2181038080
* Test3,Test2,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(187),1040187392,33554432 * Test3,Test2,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(187),1040187392,33554432,1040187392
* *
* Pull out name, origin, & uuid, device, device extent start #, segment size, extent size. * Pull out name, origin, & uuid, device, device extent start #, segment size, extent size.
* *
...@@ -290,10 +295,10 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool, ...@@ -290,10 +295,10 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
* striped, so "," is not a suitable separator either (rhbz 727474). * striped, so "," is not a suitable separator either (rhbz 727474).
*/ */
const char *regexes[] = { const char *regexes[] = {
"^\\s*(\\S+)#(\\S*)#(\\S+)#(\\S+)#(\\S+)#([0-9]+)#(\\S+)#([0-9]+)#?\\s*$" "^\\s*(\\S+)#(\\S*)#(\\S+)#(\\S+)#(\\S+)#([0-9]+)#(\\S+)#([0-9]+)#([0-9]+)#?\\s*$"
}; };
int vars[] = { int vars[] = {
8 9
}; };
int ret = -1; int ret = -1;
virCommandPtr cmd; virCommandPtr cmd;
...@@ -304,7 +309,7 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool, ...@@ -304,7 +309,7 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
"--units", "b", "--units", "b",
"--unbuffered", "--unbuffered",
"--nosuffix", "--nosuffix",
"--options", "lv_name,origin,uuid,devices,segtype,stripes,seg_size,vg_extent_size", "--options", "lv_name,origin,uuid,devices,segtype,stripes,seg_size,vg_extent_size,size",
pool->def->source.name, pool->def->source.name,
NULL); NULL);
if (virStorageBackendRunProgRegex(pool, if (virStorageBackendRunProgRegex(pool,
...@@ -718,6 +723,10 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, ...@@ -718,6 +723,10 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
"--name", vol->name, "--name", vol->name,
NULL); NULL);
virCommandAddArg(cmd, "-L"); virCommandAddArg(cmd, "-L");
if (vol->capacity != vol->allocation) {
virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->allocation, 1024));
virCommandAddArg(cmd, "--virtualsize");
}
virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->capacity, 1024)); virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->capacity, 1024));
if (vol->backingStore.path) if (vol->backingStore.path)
virCommandAddArgPair(cmd, "-s", vol->backingStore.path); virCommandAddArgPair(cmd, "-s", vol->backingStore.path);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册