From b4af40226d09adeaf9e33a1d6594c4e8ce7f771d Mon Sep 17 00:00:00 2001 From: Roman Bogorodskiy Date: Sun, 7 Sep 2014 18:01:34 +0400 Subject: [PATCH] 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 --- docs/schemas/storagepool.rng | 6 ++ src/conf/storage_conf.c | 3 +- src/storage/storage_backend_zfs.c | 57 +++++++++++++++++++ .../pool-zfs-sourcedev.xml | 8 +++ tests/storagepoolxml2xmlin/pool-zfs.xml | 7 +++ .../pool-zfs-sourcedev.xml | 19 +++++++ tests/storagepoolxml2xmlout/pool-zfs.xml | 18 ++++++ tests/storagepoolxml2xmltest.c | 2 + 8 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 tests/storagepoolxml2xmlin/pool-zfs-sourcedev.xml create mode 100644 tests/storagepoolxml2xmlin/pool-zfs.xml create mode 100644 tests/storagepoolxml2xmlout/pool-zfs-sourcedev.xml create mode 100644 tests/storagepoolxml2xmlout/pool-zfs.xml diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng index 908cc1129d..2d165a3493 100644 --- a/docs/schemas/storagepool.rng +++ b/docs/schemas/storagepool.rng @@ -166,6 +166,9 @@ + + + @@ -386,6 +389,9 @@ + + + diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index d42cde7b5c..36696a4607 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -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, }, }, diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backend_zfs.c index d8201ac1b6..948270680c 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -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, }; diff --git a/tests/storagepoolxml2xmlin/pool-zfs-sourcedev.xml b/tests/storagepoolxml2xmlin/pool-zfs-sourcedev.xml new file mode 100644 index 0000000000..b0e0a9651e --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-zfs-sourcedev.xml @@ -0,0 +1,8 @@ + + zfs + 429126d2-f4bb-45b0-b336-2e81dc6d241c + + testpool + + + diff --git a/tests/storagepoolxml2xmlin/pool-zfs.xml b/tests/storagepoolxml2xmlin/pool-zfs.xml new file mode 100644 index 0000000000..813342fc97 --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-zfs.xml @@ -0,0 +1,7 @@ + + zfs + 024835f8-52b5-4226-b2b4-8c0d3afa5b2f + + testpool + + diff --git a/tests/storagepoolxml2xmlout/pool-zfs-sourcedev.xml b/tests/storagepoolxml2xmlout/pool-zfs-sourcedev.xml new file mode 100644 index 0000000000..bbd2e9f84c --- /dev/null +++ b/tests/storagepoolxml2xmlout/pool-zfs-sourcedev.xml @@ -0,0 +1,19 @@ + + zfs + 429126d2-f4bb-45b0-b336-2e81dc6d241c + 0 + 0 + 0 + + + testpool + + + /dev/zvol/testpool + + 0755 + -1 + -1 + + + diff --git a/tests/storagepoolxml2xmlout/pool-zfs.xml b/tests/storagepoolxml2xmlout/pool-zfs.xml new file mode 100644 index 0000000000..ff02329ca8 --- /dev/null +++ b/tests/storagepoolxml2xmlout/pool-zfs.xml @@ -0,0 +1,18 @@ + + zfs + 024835f8-52b5-4226-b2b4-8c0d3afa5b2f + 0 + 0 + 0 + + testpool + + + /dev/zvol/testpool + + 0755 + -1 + -1 + + + diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index d7ae10b41b..8a2c0b50a1 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -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; }