]> xenbits.xensource.com Git - libvirt.git/commitdiff
virt-host-validate.c: check for kernel namespaces
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 7 Oct 2015 15:58:39 +0000 (16:58 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 12 Oct 2015 12:15:00 +0000 (13:15 +0100)
The LXC driver requires the uts, mnt, pid & ipc
namespaces, while net & user namespaces are
optional. Validate all these are present.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
tools/virt-host-validate-common.c
tools/virt-host-validate-common.h
tools/virt-host-validate-lxc.c

index 92a19c5396fe718fd75fc99387c4404786887fdc..12a98f41fcbaff706115e185382cd5ff28fd9d99 100644 (file)
@@ -132,6 +132,26 @@ int virHostValidateDevice(const char *hvname,
 }
 
 
+int virHostValidateNamespace(const char *hvname,
+                             const char *ns_name,
+                             virHostValidateLevel level,
+                             const char *hint)
+{
+    virHostMsgCheck(hvname, "for namespace %s", ns_name);
+    char nspath[100];
+
+    snprintf(nspath, sizeof(nspath), "/proc/self/ns/%s", ns_name);
+
+    if (access(nspath, F_OK) < 0) {
+        virHostMsgFail(level, hint);
+        return -1;
+    }
+
+    virHostMsgPass();
+    return 0;
+}
+
+
 bool virHostValidateHasCPUFlag(const char *name)
 {
     FILE *fp = fopen("/proc/cpuinfo", "r");
index 25644dca8f89d9e49bb3d3f7b88e986eb4ccd494..9d8bceaea32ded57f6553c973e4718c12bee8158 100644 (file)
@@ -54,4 +54,9 @@ extern int virHostValidateLinuxKernel(const char *hvname,
                                       virHostValidateLevel level,
                                       const char *hint);
 
+extern int virHostValidateNamespace(const char *hvname,
+                                    const char *ns_name,
+                                    virHostValidateLevel level,
+                                    const char *hint);
+
 #endif /* __VIRT_HOST_VALIDATE_COMMON_H__ */
index e0d2df4bc07d315cf4243a6ba1003b91e02f6d77..43c3f5f08e912f006effae45fb274a8b0e4facae 100644 (file)
@@ -33,5 +33,35 @@ int virHostValidateLXC(void)
                                    _("Upgrade to a kernel supporting namespaces")) < 0)
         ret = -1;
 
+    if (virHostValidateNamespace("LXC", "ipc",
+                                 VIR_HOST_VALIDATE_FAIL,
+                                 _("IPC namespace support is required")) < 0)
+        ret = -1;
+
+    if (virHostValidateNamespace("LXC", "mnt",
+                                 VIR_HOST_VALIDATE_FAIL,
+                                 _("Mount namespace support is required")) < 0)
+        ret = -1;
+
+    if (virHostValidateNamespace("LXC", "pid",
+                                 VIR_HOST_VALIDATE_FAIL,
+                                 _("PID namespace support is required")) < 0)
+        ret = -1;
+
+    if (virHostValidateNamespace("LXC", "uts",
+                                 VIR_HOST_VALIDATE_FAIL,
+                                 _("UTS namespace support is required")) < 0)
+        ret = -1;
+
+    if (virHostValidateNamespace("LXC", "net",
+                                 VIR_HOST_VALIDATE_WARN,
+                                 _("Network namespace support is recommended")) < 0)
+        ret = -1;
+
+    if (virHostValidateNamespace("LXC", "user",
+                                 VIR_HOST_VALIDATE_FAIL,
+                                 _("User namespace support is recommended")) < 0)
+        ret = -1;
+
     return ret;
 }