]> xenbits.xensource.com Git - libvirt.git/commitdiff
Test driver implementation of virStorageVolCreateXMLFrom
authorCole Robinson <crobinso@redhat.com>
Tue, 12 May 2009 20:15:56 +0000 (20:15 +0000)
committerCole Robinson <crobinso@redhat.com>
Tue, 12 May 2009 20:15:56 +0000 (20:15 +0000)
ChangeLog
src/test.c

index 703d805717a4c81f16a6d95d13f7adc482c3f37f..8de1e3b5540b177f339321a0a255cbe684f9a13c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue May 12 16:14:43 EDT 2009 Cole Robinson <crobinso@redhat.com>
+
+       * src/test.c: Test driver implementation of
+       virStorageVolCreateXMLFrom
+
 Tue May 12 16:11:14 EDT 2009 Cole Robinson <crobinso@redhat.com>
 
        * qemud/remote.c qemud/remote_dispatch_args.h
index 1915b573bced765f7c14ffe49565419cd307581a..f5ec6ec63714101eb609eea67c6ad6ae3912b979 100644 (file)
@@ -3140,6 +3140,100 @@ cleanup:
     return ret;
 }
 
+static virStorageVolPtr
+testStorageVolumeCreateXMLFrom(virStoragePoolPtr pool,
+                               const char *xmldesc,
+                               virStorageVolPtr clonevol,
+                               unsigned int flags ATTRIBUTE_UNUSED) {
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+    virStorageVolDefPtr privvol = NULL, origvol = NULL;
+    virStorageVolPtr ret = NULL;
+
+    testDriverLock(privconn);
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+    testDriverUnlock(privconn);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto cleanup;
+    }
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), pool->name);
+        goto cleanup;
+    }
+
+    privvol = virStorageVolDefParse(pool->conn, privpool->def, xmldesc, NULL);
+    if (privvol == NULL)
+        goto cleanup;
+
+    if (virStorageVolDefFindByName(privpool, privvol->name)) {
+        testError(pool->conn, VIR_ERR_INVALID_STORAGE_VOL,
+                  "%s", _("storage vol already exists"));
+        goto cleanup;
+    }
+
+    origvol = virStorageVolDefFindByName(privpool, clonevol->name);
+    if (!origvol) {
+        testError(pool->conn, VIR_ERR_INVALID_STORAGE_VOL,
+                  _("no storage vol with matching name '%s'"),
+                  clonevol->name);
+        goto cleanup;
+    }
+
+    /* Make sure enough space */
+    if ((privpool->def->allocation + privvol->allocation) >
+         privpool->def->capacity) {
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("Not enough free space in pool for volume '%s'"),
+                  privvol->name);
+        goto cleanup;
+    }
+    privpool->def->available = (privpool->def->capacity -
+                                privpool->def->allocation);
+
+    if (VIR_REALLOC_N(privpool->volumes.objs,
+                      privpool->volumes.count+1) < 0) {
+        virReportOOMError(pool->conn);
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC_N(privvol->target.path,
+                    strlen(privpool->def->target.path) +
+                    1 + strlen(privvol->name) + 1) < 0) {
+        virReportOOMError(pool->conn);
+        goto cleanup;
+    }
+
+    strcpy(privvol->target.path, privpool->def->target.path);
+    strcat(privvol->target.path, "/");
+    strcat(privvol->target.path, privvol->name);
+    privvol->key = strdup(privvol->target.path);
+    if (privvol->key == NULL) {
+        virReportOOMError(pool->conn);
+        goto cleanup;
+    }
+
+    privpool->def->allocation += privvol->allocation;
+    privpool->def->available = (privpool->def->capacity -
+                                privpool->def->allocation);
+
+    privpool->volumes.objs[privpool->volumes.count++] = privvol;
+
+    ret = virGetStorageVol(pool->conn, privpool->def->name,
+                           privvol->name, privvol->key);
+    privvol = NULL;
+
+cleanup:
+    virStorageVolDefFree(privvol);
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
+    return ret;
+}
+
 static int
 testStorageVolumeDelete(virStorageVolPtr vol,
                         unsigned int flags ATTRIBUTE_UNUSED) {
@@ -3583,6 +3677,7 @@ static virStorageDriver testStorageDriver = {
     .volLookupByKey = testStorageVolumeLookupByKey,
     .volLookupByPath = testStorageVolumeLookupByPath,
     .volCreateXML = testStorageVolumeCreateXML,
+    .volCreateXMLFrom = testStorageVolumeCreateXMLFrom,
     .volDelete = testStorageVolumeDelete,
     .volGetInfo = testStorageVolumeGetInfo,
     .volGetXMLDesc = testStorageVolumeGetXMLDesc,