[PATCH v3 4/4] vz: support filesystem type volume

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

 



Vz containers are able to use ploop volumes from storage pools
to work upon.

To use filesystem type volume, pool name and volume name should be
specifaed in <source> :
   <filesystem type='volume' accessmode='passthrough'>
      <driver type='ploop' format='ploop'/>
      <source pool='guest_images' volume='TEST_POOL_CT'/>
      <target dir='/'/>
   </filesystem>

The information about pool and volume is stored in ct dom configuration:
<StorageURL>libvirt://localhost/pool_name/vol_name</StorageURL>
and can be easily obtained via PrlVmDevHd_GetStorageURL sdk call.

The only shorcoming: if storage pool is moved somewhere the ct
should be redefined in order to refresh the information aboot path
to root.hdd

Signed-off-by: Olga Krishtal <okrishtal@xxxxxxxxxxxxx>
---
 src/storage/storage_driver.c |   4 ++
 src/vz/vz_driver.c           |   2 +-
 src/vz/vz_sdk.c              | 119 ++++++++++++++++++++++++++++++++++++++++---
 src/vz/vz_sdk.h              |   2 +-
 4 files changed, 118 insertions(+), 9 deletions(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index cb9d578..dedc5c6 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -3509,6 +3509,10 @@ virStorageTranslateDiskSourcePool(virConnectPtr conn,
             def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
             break;
 
+        case VIR_STORAGE_VOL_PLOOP:
+            def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
+            break;
+
         case VIR_STORAGE_VOL_NETWORK:
         case VIR_STORAGE_VOL_NETDIR:
             virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index b17cea7..ae6c13d 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -762,7 +762,7 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
             if (prlsdkCreateVm(driver, def))
                 goto cleanup;
         } else if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
-            if (prlsdkCreateCt(driver, def))
+            if (prlsdkCreateCt(conn, def))
                 goto cleanup;
         } else {
             virReportError(VIR_ERR_INVALID_ARG,
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 5d4f76a..fd1296c 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -33,6 +33,7 @@
 #include "virtime.h"
 #include "virhostcpu.h"
 
+#include "storage/storage_driver.h"
 #include "vz_sdk.h"
 
 #define VIR_FROM_THIS VIR_FROM_PARALLELS
@@ -645,6 +646,8 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk,
 {
     char *buf = NULL;
     int ret = -1;
+    char **matches = NULL;
+    virURIPtr uri = NULL;
 
     fs->type = VIR_DOMAIN_FS_TYPE_FILE;
     fs->fsdriver = VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP;
@@ -655,12 +658,51 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk,
     fs->readonly = false;
     fs->symlinksResolved = false;
 
-    if (!(buf = prlsdkGetStringParamVar(PrlVmDev_GetImagePath, prldisk)))
+    if (!(buf = prlsdkGetStringParamVar(PrlVmDevHd_GetStorageURL, prldisk)))
         goto cleanup;
 
-    fs->src->path = buf;
-    buf = NULL;
+    if (!virStringIsEmpty(buf)) {
+        if (!(uri = virURIParse(buf)))
+            goto cleanup;
+        if (STRNEQ("libvirt", uri->scheme)) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Unknown uri scheme: '%s'"),
+                           uri->scheme);
+            goto cleanup;
+        }
+
+        if (!(matches = virStringSplitCount(uri->path, "/", 0, NULL)) ||
+            !matches[0]) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("splitting StorageUrl failed %s"), uri->path);
+            goto cleanup;
+        }
+        if (!matches[1]) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("can't identify pool in uri %s "), uri->path);
+            goto cleanup;
+        }
+        if (!matches[2]) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("can't identify volume in uri %s"), uri->path);
+            goto cleanup;
+        }
+        fs->type = VIR_DOMAIN_FS_TYPE_VOLUME;
+        if (VIR_ALLOC(fs->src->srcpool) < 0)
+            goto cleanup;
+        if (VIR_STRDUP(fs->src->srcpool->pool, matches[1]) < 0)
+            goto cleanup;
+        if (VIR_STRDUP(fs->src->srcpool->volume, matches[2]) < 0)
+            goto cleanup;
+        VIR_FREE(buf);
+    } else {
+        fs->type = VIR_DOMAIN_FS_TYPE_FILE;
+        if (!(buf = prlsdkGetStringParamVar(PrlVmDev_GetImagePath, prldisk)))
+            goto cleanup;
 
+        fs->src->path = buf;
+        buf = NULL;
+    }
     if (!(buf = prlsdkGetStringParamVar(PrlVmDevHd_GetMountPoint, prldisk)))
         goto cleanup;
 
@@ -671,6 +713,7 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk,
 
  cleanup:
     VIR_FREE(buf);
+    virStringFreeList(matches);
     return ret;
 }
 
@@ -2695,10 +2738,11 @@ static int prlsdkCheckNetUnsupportedParams(virDomainNetDefPtr net)
 
 static int prlsdkCheckFSUnsupportedParams(virDomainFSDefPtr fs)
 {
-    if (fs->type != VIR_DOMAIN_FS_TYPE_FILE) {
+    if (fs->type != VIR_DOMAIN_FS_TYPE_FILE &&
+        fs->type != VIR_DOMAIN_FS_TYPE_VOLUME) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Only file based filesystems are "
-                         "supported by vz driver."));
+                       _("Only file based or volume based filesystems "
+                         "are supported by vz driver."));
         return -1;
     }
 
@@ -3514,6 +3558,7 @@ prlsdkAddFS(PRL_HANDLE sdkdom, virDomainFSDefPtr fs)
     PRL_RESULT pret;
     PRL_HANDLE sdkdisk = PRL_INVALID_HANDLE;
     int ret = -1;
+    char *storage = NULL;
 
     if (fs->type == VIR_DOMAIN_FS_TYPE_TEMPLATE)
         return 0;
@@ -3524,6 +3569,14 @@ prlsdkAddFS(PRL_HANDLE sdkdom, virDomainFSDefPtr fs)
     pret = PrlVmCfg_CreateVmDev(sdkdom, PDE_HARD_DISK, &sdkdisk);
     prlsdkCheckRetGoto(pret, cleanup);
 
+    if (fs->type == VIR_DOMAIN_FS_TYPE_VOLUME) {
+        if (virAsprintf(&storage, "libvirt://localhost/%s/%s", fs->src->srcpool->pool,
+                        fs->src->srcpool->volume) < 0)
+            goto cleanup;
+        pret = PrlVmDevHd_SetStorageURL(sdkdisk, storage);
+        prlsdkCheckRetGoto(pret, cleanup);
+    }
+
     pret = PrlVmDev_SetEnabled(sdkdisk, 1);
     prlsdkCheckRetGoto(pret, cleanup);
 
@@ -3548,6 +3601,7 @@ prlsdkAddFS(PRL_HANDLE sdkdom, virDomainFSDefPtr fs)
     ret = 0;
 
  cleanup:
+    VIR_FREE(storage);
     PrlHandle_Free(sdkdisk);
     return ret;
 }
@@ -3848,8 +3902,52 @@ prlsdkCreateVm(vzDriverPtr driver, virDomainDefPtr def)
     return ret;
 }
 
+static int
+virStorageTranslatePoolLocal(virConnectPtr conn, virStorageSourcePtr src)
+{
+
+    virStoragePoolPtr pool = NULL;
+    virStorageVolPtr vol = NULL;
+    virStorageVolInfo info;
+    int ret = -1;
+
+    if (!(pool = virStoragePoolLookupByName(conn, src->srcpool->pool)))
+        return -1;
+    if (virStoragePoolIsActive(pool) != 1) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("storage pool '%s' containing volume '%s' "
+                         "is not active"), src->srcpool->pool,
+                       src->srcpool->volume);
+        goto cleanup;
+    }
+
+    if (!(vol = virStorageVolLookupByName(pool, src->srcpool->volume)))
+        goto cleanup;
+
+    if (virStorageVolGetInfo(vol, &info) < 0)
+        goto cleanup;
+
+    if (info.type != VIR_STORAGE_VOL_PLOOP) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Unsupported volume format '%s'"),
+                       virStorageVolTypeToString(info.type));
+        goto cleanup;
+    }
+
+    if (!(src->path = virStorageVolGetPath(vol)))
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virObjectUnref(pool);
+    virObjectUnref(vol);
+    return ret;
+}
+
+
 int
-prlsdkCreateCt(vzDriverPtr driver, virDomainDefPtr def)
+prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def)
 {
     PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
     PRL_GET_VM_CONFIG_PARAM_DATA confParam;
@@ -3857,6 +3955,8 @@ prlsdkCreateCt(vzDriverPtr driver, virDomainDefPtr def)
     PRL_HANDLE result = PRL_INVALID_HANDLE;
     PRL_RESULT pret;
     PRL_UINT32 flags;
+    vzConnPtr privconn = conn->privateData;
+    vzDriverPtr driver = privconn->driver;
     int ret = -1;
     int useTemplate = 0;
     size_t i;
@@ -3869,6 +3969,11 @@ prlsdkCreateCt(vzDriverPtr driver, virDomainDefPtr def)
         }
         if (def->fss[i]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE)
             useTemplate = 1;
+        if (def->fss[i]->type == VIR_DOMAIN_FS_TYPE_VOLUME) {
+            if (virStorageTranslatePoolLocal(conn, def->fss[i]->src) < 0)
+                goto cleanup;
+        }
+
     }
 
     if (useTemplate && def->nfss > 1) {
diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h
index 41557a3..2b0cbd3 100644
--- a/src/vz/vz_sdk.h
+++ b/src/vz/vz_sdk.h
@@ -57,7 +57,7 @@ prlsdkApplyConfig(vzDriverPtr driver,
                   virDomainObjPtr dom,
                   virDomainDefPtr new);
 int prlsdkCreateVm(vzDriverPtr driver, virDomainDefPtr def);
-int prlsdkCreateCt(vzDriverPtr driver, virDomainDefPtr def);
+int prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def);
 int
 prlsdkUnregisterDomain(vzDriverPtr driver, virDomainObjPtr dom, unsigned int flags);
 int
-- 
1.8.3.1

--
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]