mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
storage: zfs: implement pool build and delete
- Provide an implementation for buildPool and deletePool operations for the ZFS storage backend. - Add VIR_STORAGE_POOL_SOURCE_DEVICE flag to ZFS pool poolOptions as now we can specify devices to build pool from - storagepool.rng: add an optional 'sourceinfodev' to 'sourcezfs' and add an optional 'target' to 'poolzfs' entity - Add a couple of tests to storagepoolxml2xmltest
This commit is contained in:
parent
c1d55105a4
commit
b4af40226d
@ -166,6 +166,9 @@
|
||||
<ref name='commonmetadata'/>
|
||||
<ref name='sizing'/>
|
||||
<ref name='sourcezfs'/>
|
||||
<optional>
|
||||
<ref name='target'/>
|
||||
</optional>
|
||||
</interleave>
|
||||
</define>
|
||||
|
||||
@ -386,6 +389,9 @@
|
||||
<element name='source'>
|
||||
<interleave>
|
||||
<ref name='sourceinfoname'/>
|
||||
<optional>
|
||||
<ref name='sourceinfodev'/>
|
||||
</optional>
|
||||
</interleave>
|
||||
</element>
|
||||
</define>
|
||||
|
@ -282,7 +282,8 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
|
||||
},
|
||||
{.poolType = VIR_STORAGE_POOL_ZFS,
|
||||
.poolOptions = {
|
||||
.flags = (VIR_STORAGE_POOL_SOURCE_NAME),
|
||||
.flags = (VIR_STORAGE_POOL_SOURCE_NAME |
|
||||
VIR_STORAGE_POOL_SOURCE_DEVICE),
|
||||
.defaultFormat = VIR_STORAGE_FILE_RAW,
|
||||
},
|
||||
},
|
||||
|
@ -325,6 +325,61 @@ virStorageBackendZFSDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
virStorageBackendZFSBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
virStoragePoolObjPtr pool,
|
||||
unsigned int flags)
|
||||
{
|
||||
virCommandPtr cmd = NULL;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
if (pool->def->source.ndevice == 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
"%s", _("missing source devices"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd = virCommandNewArgList(ZPOOL, "create",
|
||||
pool->def->source.name, NULL);
|
||||
|
||||
for (i = 0; i < pool->def->source.ndevice; i++)
|
||||
virCommandAddArg(cmd, pool->def->source.devices[i].path);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virCommandFree(cmd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
virStorageBackendZFSDeletePool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
virStoragePoolObjPtr pool,
|
||||
unsigned int flags)
|
||||
{
|
||||
virCommandPtr cmd = NULL;
|
||||
int ret = -1;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
cmd = virCommandNewArgList(ZPOOL, "destroy",
|
||||
pool->def->source.name, NULL);
|
||||
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virCommandFree(cmd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
virStorageBackend virStorageBackendZFS = {
|
||||
.type = VIR_STORAGE_POOL_ZFS,
|
||||
@ -333,6 +388,8 @@ virStorageBackend virStorageBackendZFS = {
|
||||
.refreshPool = virStorageBackendZFSRefreshPool,
|
||||
.createVol = virStorageBackendZFSCreateVol,
|
||||
.deleteVol = virStorageBackendZFSDeleteVol,
|
||||
.buildPool = virStorageBackendZFSBuildPool,
|
||||
.deletePool = virStorageBackendZFSDeletePool,
|
||||
.uploadVol = virStorageBackendVolUploadLocal,
|
||||
.downloadVol = virStorageBackendVolDownloadLocal,
|
||||
};
|
||||
|
8
tests/storagepoolxml2xmlin/pool-zfs-sourcedev.xml
Normal file
8
tests/storagepoolxml2xmlin/pool-zfs-sourcedev.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<pool type="zfs">
|
||||
<name>zfs</name>
|
||||
<uuid>429126d2-f4bb-45b0-b336-2e81dc6d241c</uuid>
|
||||
<source>
|
||||
<name>testpool</name>
|
||||
<device path="/dev/ada1"/>
|
||||
</source>
|
||||
</pool>
|
7
tests/storagepoolxml2xmlin/pool-zfs.xml
Normal file
7
tests/storagepoolxml2xmlin/pool-zfs.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<pool type="zfs">
|
||||
<name>zfs</name>
|
||||
<uuid>024835f8-52b5-4226-b2b4-8c0d3afa5b2f</uuid>
|
||||
<source>
|
||||
<name>testpool</name>
|
||||
</source>
|
||||
</pool>
|
19
tests/storagepoolxml2xmlout/pool-zfs-sourcedev.xml
Normal file
19
tests/storagepoolxml2xmlout/pool-zfs-sourcedev.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<pool type='zfs'>
|
||||
<name>zfs</name>
|
||||
<uuid>429126d2-f4bb-45b0-b336-2e81dc6d241c</uuid>
|
||||
<capacity unit='bytes'>0</capacity>
|
||||
<allocation unit='bytes'>0</allocation>
|
||||
<available unit='bytes'>0</available>
|
||||
<source>
|
||||
<device path='/dev/ada1'/>
|
||||
<name>testpool</name>
|
||||
</source>
|
||||
<target>
|
||||
<path>/dev/zvol/testpool</path>
|
||||
<permissions>
|
||||
<mode>0755</mode>
|
||||
<owner>-1</owner>
|
||||
<group>-1</group>
|
||||
</permissions>
|
||||
</target>
|
||||
</pool>
|
18
tests/storagepoolxml2xmlout/pool-zfs.xml
Normal file
18
tests/storagepoolxml2xmlout/pool-zfs.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<pool type='zfs'>
|
||||
<name>zfs</name>
|
||||
<uuid>024835f8-52b5-4226-b2b4-8c0d3afa5b2f</uuid>
|
||||
<capacity unit='bytes'>0</capacity>
|
||||
<allocation unit='bytes'>0</allocation>
|
||||
<available unit='bytes'>0</available>
|
||||
<source>
|
||||
<name>testpool</name>
|
||||
</source>
|
||||
<target>
|
||||
<path>/dev/zvol/testpool</path>
|
||||
<permissions>
|
||||
<mode>0755</mode>
|
||||
<owner>-1</owner>
|
||||
<group>-1</group>
|
||||
</permissions>
|
||||
</target>
|
||||
</pool>
|
@ -105,6 +105,8 @@ mymain(void)
|
||||
DO_TEST("pool-gluster");
|
||||
DO_TEST("pool-gluster-sub");
|
||||
DO_TEST("pool-scsi-type-scsi-host-stable");
|
||||
DO_TEST("pool-zfs");
|
||||
DO_TEST("pool-zfs-sourcedev");
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user