[libvirt] [PATCH] vz: set mount point for container image-based disks

Maxim Nestratov mnestratov at parallels.com
Sun Sep 20 19:17:51 UTC 2015


From: Maxim Nestratov <mnestratov at virtuozzo.com>

In order to support not only root disks with type=file for containers,
we need to specify mount points for them.
For instance, if a secondary disk is added by the following record in
xml:

    <disk type='file' device='disk'>
      <driver type='ploop' cache='writeback'/>
      <source file='/vz/some_path_to_image_dir'/>
      <target bus='sata' dev='sdb'/>
    </disk>

we are going to add it to container mounted to '/mnt/sdb' path.

Signed-off-by: Maxim Nestratov <mnestratov at virtuozzo.com>
---
 src/vz/vz_sdk.c |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 744b58a..6642933 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -3292,21 +3292,48 @@ static int prlsdkAddDisk(PRL_HANDLE sdkdom,
         goto cleanup;
     }
 
-    if (bootDisk == true) {
+    if (bootDisk) {
         pret = PrlVmDev_GetIndex(sdkdisk, &devIndex);
         prlsdkCheckRetGoto(pret, cleanup);
 
         if (prlsdkAddDeviceToBootList(sdkdom, devIndex, devType, 0) < 0)
             goto cleanup;
 
-        /* If we add physical device as a boot disk to container
-         * we have to specify mount point for it */
-        if (isCt) {
+    }
+
+    if (isCt) {
+
+        /* If we add a disk as a boot disk to a container
+         * (it doesn't matter whether it has image or real device backend)
+         * we have to specify the root mount point for it */
+        if (bootDisk) {
             pret = PrlVmDevHd_SetMountPoint(sdkdisk, "/");
             prlsdkCheckRetGoto(pret, cleanup);
+        } else {
+
+            /* In case of image we need to specify a mount point
+             * to make it usable within a container */
+            if (disk->src->type == VIR_STORAGE_TYPE_FILE) {
+                char *mount_point;
+                char *dev_name = strrchr(disk->dst, '/');
+
+                if (!dev_name) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Unexpected format of disk destination '%s'."));
+                    goto cleanup;
+                }
+
+                if (virAsprintf(&mount_point, "/mnt%s", dev_name) < 0)
+                    goto cleanup;
+
+                pret = PrlVmDevHd_SetMountPoint(sdkdisk, mount_point);
+                VIR_FREE(mount_point);
+                prlsdkCheckRetGoto(pret, cleanup);
+            }
         }
     }
 
+
     return 0;
  cleanup:
     PrlHandle_Free(sdkdisk);
-- 
1.7.1




More information about the libvir-list mailing list