]> xenbits.xensource.com Git - libvirt.git/commitdiff
storageVolCreateXMLFrom: Allow multiple accesses to origvol
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 16 Apr 2014 13:16:20 +0000 (15:16 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 6 May 2014 08:24:44 +0000 (10:24 +0200)
When creating a new volume, it is possible to copy data into it from
another already existing volume (referred to as @origvol). Obviously,
the read-only access to @origvol is required, which is thread safe
(probably not performance-wise though). However, with current code
both @newvol and @origvol are marked as building for the time of
copying data from the @origvol to @newvol. The rationale behind
is to disallow some operations on both @origvol and @newvol, e.g.
vol-wipe, vol-delete, vol-download. While it makes sense to not allow
such operations on partly copied mirror, but it doesn't make sense to
disallow vol-create or vol-download on the source (@origvol).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/storage_conf.h
src/storage/storage_driver.c

index 9ad38e1854443a08ca79207514e91361376c08e8..eae959c9ffc830ff4d197c0b31498241f7568ddb 100644 (file)
@@ -64,6 +64,7 @@ struct _virStorageVolDef {
     int type; /* enum virStorageVolType */
 
     unsigned int building;
+    unsigned int in_use;
 
     virStorageVolSource source;
     virStorageSource target;
index 2cb834756317af4c15df812ee7a5d0b86d4ab9cc..542b3827a4f590b57f4d51b09acdc0f547f8e2de 100644 (file)
@@ -1640,6 +1640,13 @@ storageVolDelete(virStorageVolPtr obj,
     if (virStorageVolDeleteEnsureACL(obj->conn, pool->def, vol) < 0)
         goto cleanup;
 
+    if (vol->in_use) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("volume '%s' is still in use."),
+                       vol->name);
+        goto cleanup;
+    }
+
     if (vol->building) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        _("volume '%s' is still being allocated."),
@@ -1912,8 +1919,8 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
 
     /* Drop the pool lock during volume allocation */
     pool->asyncjobs++;
-    origvol->building = 1;
     newvol->building = 1;
+    origvol->in_use++;
     virStoragePoolObjUnlock(pool);
 
     if (origpool) {
@@ -1929,7 +1936,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
         virStoragePoolObjLock(origpool);
     storageDriverUnlock(driver);
 
-    origvol->building = 0;
+    origvol->in_use--;
     newvol->building = 0;
     allocation = newvol->target.allocation;
     pool->asyncjobs--;
@@ -2076,6 +2083,13 @@ storageVolUpload(virStorageVolPtr obj,
     if (virStorageVolUploadEnsureACL(obj->conn, pool->def, vol) < 0)
         goto cleanup;
 
+    if (vol->in_use) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("volume '%s' is still in use."),
+                       vol->name);
+        goto cleanup;
+    }
+
     if (vol->building) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        _("volume '%s' is still being allocated."),
@@ -2167,6 +2181,13 @@ storageVolResize(virStorageVolPtr obj,
     if (virStorageVolResizeEnsureACL(obj->conn, pool->def, vol) < 0)
         goto cleanup;
 
+    if (vol->in_use) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("volume '%s' is still in use."),
+                       vol->name);
+        goto cleanup;
+    }
+
     if (vol->building) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        _("volume '%s' is still being allocated."),
@@ -2474,6 +2495,13 @@ storageVolWipePattern(virStorageVolPtr obj,
     if (virStorageVolWipePatternEnsureACL(obj->conn, pool->def, vol) < 0)
         goto cleanup;
 
+    if (vol->in_use) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("volume '%s' is still in use."),
+                       vol->name);
+        goto cleanup;
+    }
+
     if (vol->building) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        _("volume '%s' is still being allocated."),