[PATCH v2] storage: zfs: implement pool build and delete

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 - 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 ++++++++++++++++++++++
 tests/storagepoolxml2xmlin/pool-zfs-sourcedev.xml  |  8 +++
 tests/storagepoolxml2xmlin/pool-zfs.xml            |  7 +++
 tests/storagepoolxml2xmlout/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 908cc11..2d165a3 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -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>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index d42cde7..36696a4 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 d8201ac..9482706 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 0000000..b0e0a96
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-zfs-sourcedev.xml
@@ -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>
diff --git a/tests/storagepoolxml2xmlin/pool-zfs.xml b/tests/storagepoolxml2xmlin/pool-zfs.xml
new file mode 100644
index 0000000..813342f
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-zfs.xml
@@ -0,0 +1,7 @@
+<pool type="zfs">
+  <name>zfs</name>
+  <uuid>024835f8-52b5-4226-b2b4-8c0d3afa5b2f</uuid>
+  <source>
+    <name>testpool</name>
+  </source>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-zfs-sourcedev.xml b/tests/storagepoolxml2xmlout/pool-zfs-sourcedev.xml
new file mode 100644
index 0000000..bbd2e9f
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-zfs-sourcedev.xml
@@ -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>
diff --git a/tests/storagepoolxml2xmlout/pool-zfs.xml b/tests/storagepoolxml2xmlout/pool-zfs.xml
new file mode 100644
index 0000000..ff02329
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-zfs.xml
@@ -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>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index d7ae10b..8a2c0b5 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;
 }
-- 
2.0.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]