]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: dir: .buildVol and .buildVolFrom callbacks for ploop
authorOlga Krishtal <okrishtal@virtuozzo.com>
Mon, 11 Apr 2016 16:16:20 +0000 (19:16 +0300)
committerJán Tomko <jtomko@redhat.com>
Fri, 15 Apr 2016 15:27:32 +0000 (17:27 +0200)
These callbacks let us to create ploop volumes in dir, fs and etc. pools.
If a ploop volume was created via buildVol callback, then this volume
is an empty ploop device with DiskDescriptor.xml.
If the volume was created via .buildFrom - then its content is similar to
input volume content.

Signed-off-by: Olga Krishtal <okrishtal@virtuozzo.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_backend_fs.c

index 231eccf44d66ba2ea09278e06950b740043dc933..6a035a28e76e702d2f5669c85f1b2a9b74f605a6 100644 (file)
@@ -773,6 +773,83 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
     return ret;
 }
 
+/* Create ploop directory with ploop image and DiskDescriptor.xml
+ * if function fails to create image file the directory will be deleted.*/
+int
+virStorageBackendCreatePloop(virConnectPtr conn ATTRIBUTE_UNUSED,
+                             virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
+                             virStorageVolDefPtr vol,
+                             virStorageVolDefPtr inputvol,
+                             unsigned int flags)
+{
+    int ret = -1;
+    virCommandPtr cmd = NULL;
+    char *create_tool = NULL;
+    bool created = false;
+
+    virCheckFlags(0, -1);
+
+    if (inputvol && inputvol->target.format != VIR_STORAGE_FILE_PLOOP) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unsupported input storage vol type %d"),
+                       inputvol->target.format);
+        return -1;
+    }
+
+    if (vol->target.encryption != NULL) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("encrypted ploop volumes are not supported with "
+                         "ploop init"));
+        return -1;
+    }
+
+    if (vol->target.backingStore != NULL) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("copy-on-write ploop volumes are not yet supported"));
+        return -1;
+    }
+
+    create_tool = virFindFileInPath("ploop");
+    if (!create_tool && !inputvol) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("unable to find ploop, please install "
+                               "ploop tools"));
+        return -1;
+    }
+
+    if (!inputvol) {
+        if ((virDirCreate(vol->target.path,
+                          (vol->target.perms->mode == (mode_t) -1 ?
+                           VIR_STORAGE_DEFAULT_VOL_PERM_MODE:
+                           vol->target.perms->mode),
+                          vol->target.perms->uid,
+                          vol->target.perms->gid,
+                          0)) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("error creating directory for ploop volume"));
+            goto cleanup;
+        }
+        cmd = virCommandNewArgList(create_tool, "init", "-s", NULL);
+        virCommandAddArgFormat(cmd, "%lluM", VIR_DIV_UP(vol->target.capacity,
+                                                        (1024 * 1024)));
+        virCommandAddArgList(cmd, "-t", "ext4", NULL);
+        virCommandAddArgFormat(cmd, "%s/root.hds", vol->target.path);
+
+    } else {
+        vol->target.capacity = inputvol->target.capacity;
+        cmd = virCommandNewArgList("cp", "-r", inputvol->target.path,
+                                   vol->target.path, NULL);
+    }
+    created = true;
+    ret = virCommandRun(cmd, NULL);
+ cleanup:
+    virCommandFree(cmd);
+    VIR_FREE(create_tool);
+    if (ret < 0 && created)
+        virFileDeleteTree(vol->target.path);
+    return ret;
+}
+
 enum {
     QEMU_IMG_BACKING_FORMAT_NONE = 0,
     QEMU_IMG_BACKING_FORMAT_FLAG,
@@ -1291,6 +1368,8 @@ virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
         return virStorageBackendFSImageToolTypeToFunc(tool_type);
     }
 
+    if (vol->type == VIR_STORAGE_VOL_PLOOP)
+        return virStorageBackendCreatePloop;
     if (vol->type == VIR_STORAGE_VOL_BLOCK)
         return virStorageBackendCreateBlockFrom;
     else
index 20e6079522d509fc8cf8ca3629be335d16ca4d4e..852d6ed9cf132376f3190a17b306086ac16db22d 100644 (file)
@@ -108,6 +108,14 @@ int virStorageBackendCreateRaw(virConnectPtr conn,
                                virStorageVolDefPtr vol,
                                virStorageVolDefPtr inputvol,
                                unsigned int flags);
+
+int virStorageBackendCreatePloop(virConnectPtr conn,
+                                 virStoragePoolObjPtr pool,
+                                 virStorageVolDefPtr vol,
+                                 virStorageVolDefPtr inputvol,
+                                 unsigned int flags);
+
+
 virStorageBackendBuildVolFrom
 virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
                                          virStorageVolDefPtr inputvol);
index d54dbfae45d7721c78624afd45213d4997050813..8517b26bf80c73d7eb6519b8e62317ce518794f6 100644 (file)
@@ -1179,6 +1179,8 @@ _virStorageBackendFileSystemVolBuild(virConnectPtr conn,
         create_func = virStorageBackendCreateRaw;
     } else if (vol->target.format == VIR_STORAGE_FILE_DIR) {
         create_func = createFileDir;
+    } else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
+        create_func = virStorageBackendCreatePloop;
     } else if ((tool_type = virStorageBackendFindFSImageTool(NULL)) != -1) {
         create_func = virStorageBackendFSImageToolTypeToFunc(tool_type);