]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
LXC: hostdev: create parent directory for hostdev
authorGao feng <gaofeng@cn.fujitsu.com>
Tue, 9 Jul 2013 10:16:20 +0000 (11:16 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 18 Feb 2014 17:37:21 +0000 (17:37 +0000)
Create parent directroy for hostdev automatically when we
start a lxc domain or attach a hostdev to a lxc domain.

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
(cherry picked from commit 468ee0bc4d6007f4af51235838cac7499fa22773)

src/lxc/lxc_container.c
src/lxc/lxc_driver.c

index db2c0d14664f6c4810e18499cbab5f1f3d040774..0dc143d27bf5e7258061ce1a26d8a87595d091f3 100644 (file)
@@ -1581,14 +1581,15 @@ static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_U
     int ret = -1;
     struct stat sb;
     mode_t mode;
+    char *dev = def->source.caps.u.storage.block;
 
-    if (def->source.caps.u.storage.block == NULL) {
+    if (dev == NULL) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Missing storage host block path"));
         goto cleanup;
     }
 
-    if (virAsprintf(&src, "/.oldroot/%s", def->source.caps.u.storage.block) < 0) {
+    if (virAsprintf(&src, "/.oldroot/%s", dev) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1603,19 +1604,25 @@ static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_U
     if (!S_ISBLK(sb.st_mode)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Storage source %s must be a block device"),
-                       def->source.caps.u.storage.block);
+                       dev);
+        goto cleanup;
+    }
+
+    if (lxcContainerSetupHostdevCapsMakePath(dev) < 0) {
+        virReportError(errno,
+                       _("Failed to create directory for device %s"),
+                       dev);
         goto cleanup;
     }
 
     mode = 0700 | S_IFBLK;
 
-    VIR_DEBUG("Creating dev %s (%d,%d)",
-              def->source.caps.u.storage.block,
+    VIR_DEBUG("Creating dev %s (%d,%d)", dev,
               major(sb.st_rdev), minor(sb.st_rdev));
-    if (mknod(def->source.caps.u.storage.block, mode, sb.st_rdev) < 0) {
+    if (mknod(dev, mode, sb.st_rdev) < 0) {
         virReportSystemError(errno,
                              _("Unable to create device %s"),
-                             def->source.caps.u.storage.block);
+                             dev);
         goto cleanup;
     }
 
@@ -1638,14 +1645,15 @@ static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUS
     int ret = -1;
     struct stat sb;
     mode_t mode;
+    char *dev = def->source.caps.u.misc.chardev;
 
-    if (def->source.caps.u.misc.chardev == NULL) {
+    if (dev == NULL) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Missing storage host block path"));
         goto cleanup;
     }
 
-    if (virAsprintf(&src, "/.oldroot/%s", def->source.caps.u.misc.chardev) < 0) {
+    if (virAsprintf(&src, "/.oldroot/%s", dev) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1660,19 +1668,25 @@ static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUS
     if (!S_ISCHR(sb.st_mode)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Storage source %s must be a character device"),
-                       def->source.caps.u.misc.chardev);
+                       dev);
+        goto cleanup;
+    }
+
+    if (lxcContainerSetupHostdevCapsMakePath(dev) < 0) {
+        virReportError(errno,
+                       _("Failed to create directory for device %s"),
+                       dev);
         goto cleanup;
     }
 
     mode = 0700 | S_IFCHR;
 
-    VIR_DEBUG("Creating dev %s (%d,%d)",
-              def->source.caps.u.misc.chardev,
+    VIR_DEBUG("Creating dev %s (%d,%d)", dev,
               major(sb.st_rdev), minor(sb.st_rdev));
-    if (mknod(def->source.caps.u.misc.chardev, mode, sb.st_rdev) < 0) {
+    if (mknod(dev, mode, sb.st_rdev) < 0) {
         virReportSystemError(errno,
                              _("Unable to create device %s"),
-                             def->source.caps.u.misc.chardev);
+                             dev);
         goto cleanup;
     }
 
index 1b8b22d5ffef6268d602a49913d4d7cc2ec09bca..4907d795995e69ccdefccefea7e5b92c35548f27 100644 (file)
@@ -3544,6 +3544,13 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
+    if (lxcContainerSetupHostdevCapsMakePath(dst) < 0) {
+        virReportSystemError(errno,
+                             _("Unable to create directroy for device %s"),
+                             dst);
+        goto cleanup;
+    }
+
     mode = 0700 | S_IFBLK;
 
     VIR_DEBUG("Creating dev %s (%d,%d)",
@@ -3648,6 +3655,13 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
+    if (lxcContainerSetupHostdevCapsMakePath(dst) < 0) {
+        virReportSystemError(errno,
+                             _("Unable to create directroy for device %s"),
+                             dst);
+        goto cleanup;
+    }
+
     mode = 0700 | S_IFCHR;
 
     VIR_DEBUG("Creating dev %s (%d,%d)",