]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Make logical pools independent on target path
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 30 Apr 2013 11:48:46 +0000 (13:48 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 16 Jul 2013 10:16:37 +0000 (12:16 +0200)
When using logical pools, we had to trust the target->path provided.
This parameter, however, can be completely ommited and we can use
'/dev/<source.name>' safely and populate it to target.path.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=952973

docs/schemas/storagepool.rng
src/conf/storage_conf.c
src/storage/storage_backend_logical.c
src/storage/storage_driver.c
tests/storagepoolxml2xmlin/pool-logical-create.xml
tests/storagepoolxml2xmlin/pool-logical-nopath.xml [new file with mode: 0644]
tests/storagepoolxml2xmlout/pool-logical-nopath.xml [new file with mode: 0644]
tests/storagepoolxml2xmltest.c

index 6da3c11ac1d1d6a171d5d3dbf1303bda48f12ed8..a4ef5aff0c6962ca4067bf1577b5239031b0a28f 100644 (file)
@@ -62,7 +62,7 @@
     <ref name='commonmetadata'/>
     <ref name='sizing'/>
     <ref name='sourcelogical'/>
-    <ref name='target'/>
+    <ref name='targetlogical'/>
   </define>
 
   <define name='pooldisk'>
     </element>
   </define>
 
+  <define name='targetlogical'>
+    <element name='target'>
+      <optional>
+        <element name='path'>
+          <ref name='absFilePath'/>
+        </element>
+      </optional>
+      <ref name='permissions'/>
+    </element>
+  </define>
+
   <define name='sourceinfohost'>
     <oneOrMore>
       <element name='host'>
index d6df1ed71f48ca54a3566f39535656cc457800dc..002663f1e4e3f92aecbec8b5099e2d8ec81dc4d8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * storage_conf.c: config handling for storage driver
  *
- * Copyright (C) 2006-2012 Red Hat, Inc.
+ * Copyright (C) 2006-2013 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -956,10 +956,17 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
     /* When we are working with a virtual disk we can skip the target
      * path and permissions */
     if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) {
-        if (!(target_path = virXPathString("string(./target/path)", ctxt))) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("missing storage pool target path"));
-            goto error;
+        if (ret->type == VIR_STORAGE_POOL_LOGICAL) {
+            if (virAsprintf(&target_path, "/dev/%s", ret->source.name) < 0) {
+                goto error;
+            }
+        } else {
+            target_path = virXPathString("string(./target/path)", ctxt);
+            if (!target_path) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("missing storage pool target path"));
+                goto error;
+            }
         }
         ret->target.path = virFileSanitizePath(target_path);
         if (!ret->target.path)
index 416a0424fe2536dba8596f90d77476ed7ddfc007..8998a11b92158c93de7853c49dce4b69842a0773 100644 (file)
@@ -454,17 +454,7 @@ virStorageBackendLogicalCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                                   virStoragePoolObjPtr pool,
                                   bool *isActive)
 {
-    char *path;
-
-    *isActive = false;
-    if (virAsprintf(&path, "/dev/%s", pool->def->source.name) < 0)
-        return -1;
-
-    if (access(path, F_OK) == 0)
-        *isActive = true;
-
-    VIR_FREE(path);
-
+    *isActive = (access(pool->def->target.path, F_OK) == 0);
     return 0;
 }
 
@@ -794,21 +784,16 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
                                   unsigned int flags)
 {
     int ret = -1;
-    char *volpath = NULL;
 
     virCommandPtr lvchange_cmd = NULL;
     virCommandPtr lvremove_cmd = NULL;
 
     virCheckFlags(0, -1);
 
-    if (virAsprintf(&volpath, "%s/%s",
-                    pool->def->source.name, vol->name) < 0)
-        goto cleanup;
-
     virFileWaitForDevices();
 
-    lvchange_cmd = virCommandNewArgList(LVCHANGE, "-aln", volpath, NULL);
-    lvremove_cmd = virCommandNewArgList(LVREMOVE, "-f", volpath, NULL);
+    lvchange_cmd = virCommandNewArgList(LVCHANGE, "-aln", vol->target.path, NULL);
+    lvremove_cmd = virCommandNewArgList(LVREMOVE, "-f", vol->target.path, NULL);
 
     if (virCommandRun(lvremove_cmd, NULL) < 0) {
         if (virCommandRun(lvchange_cmd, NULL) < 0) {
@@ -821,7 +806,6 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
 
     ret = 0;
 cleanup:
-    VIR_FREE(volpath);
     virCommandFree(lvchange_cmd);
     virCommandFree(lvremove_cmd);
     return ret;
index a8eb731aec2eec30f421fbbbb66e0b6f972dd80f..43bf6dece5f19b48be6a128f0c9d563202424303 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * storage_driver.c: core driver for storage APIs
  *
- * Copyright (C) 2006-2012 Red Hat, Inc.
+ * Copyright (C) 2006-2013 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
index 4c670899da5e0f61ce573c2c43f372dcd64a90e1..fd551e016b25f8bcfbacac6a8fee5cfed7fc74f8 100644 (file)
@@ -10,7 +10,7 @@
     <device path="/dev/sdb3"/>
   </source>
   <target>
-    <path>/dev/HostVG</path>
+    <path>/invalid/nonexistent/path</path>
     <permissions>
       <mode>0700</mode>
       <owner>0</owner>
diff --git a/tests/storagepoolxml2xmlin/pool-logical-nopath.xml b/tests/storagepoolxml2xmlin/pool-logical-nopath.xml
new file mode 100644 (file)
index 0000000..e1bb4db
--- /dev/null
@@ -0,0 +1,19 @@
+<pool type='logical'>
+  <name>HostVG</name>
+  <uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid>
+  <capacity>99891544064</capacity>
+  <allocation>99220455424</allocation>
+  <available>671088640</available>
+  <source>
+    <device path="/dev/sdb1"/>
+    <device path="/dev/sdb2"/>
+    <device path="/dev/sdb3"/>
+  </source>
+  <target>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-logical-nopath.xml b/tests/storagepoolxml2xmlout/pool-logical-nopath.xml
new file mode 100644 (file)
index 0000000..7413f1c
--- /dev/null
@@ -0,0 +1,22 @@
+<pool type='logical'>
+  <name>HostVG</name>
+  <uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid>
+  <capacity unit='bytes'>0</capacity>
+  <allocation unit='bytes'>0</allocation>
+  <available unit='bytes'>0</available>
+  <source>
+    <device path='/dev/sdb1'/>
+    <device path='/dev/sdb2'/>
+    <device path='/dev/sdb3'/>
+    <name>HostVG</name>
+    <format type='lvm2'/>
+  </source>
+  <target>
+    <path>/dev/HostVG</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
index 53a7f83ca177dfda56d2877fa906f773e87e6ed3..d59cff9746ab610a7ac2602c3f3f38d9ea0140ab 100644 (file)
@@ -87,6 +87,7 @@ mymain(void)
     DO_TEST("pool-dir");
     DO_TEST("pool-fs");
     DO_TEST("pool-logical");
+    DO_TEST("pool-logical-nopath");
     DO_TEST("pool-logical-create");
     DO_TEST("pool-disk");
     DO_TEST("pool-iscsi");