]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuDomainCreateDeviceRecursive: Fail on unsupported file type
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Jun 2017 08:56:20 +0000 (10:56 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 11 Jul 2017 12:45:15 +0000 (14:45 +0200)
Currently, we silently assume that file we are creating in the
namespace is either a link or a device (character or block one).
This is not always the case. Therefore instead of doing something
wrong, claim about unsupported file type.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_domain.c

index cde5a8e6af7f2ce7ca9e1bb9a5fb6729eca8beeb..0b664bb531f67cff9d868041f5ea7385f0727c0b 100644 (file)
@@ -7720,6 +7720,7 @@ qemuDomainCreateDeviceRecursive(const char *device,
     struct stat sb;
     int ret = -1;
     bool isLink = false;
+    bool isDev = false;
     bool create = false;
 #ifdef WITH_SELINUX
     char *tcon = NULL;
@@ -7742,6 +7743,7 @@ qemuDomainCreateDeviceRecursive(const char *device,
     }
 
     isLink = S_ISLNK(sb.st_mode);
+    isDev = S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode);
 
     /* Here, @device might be whatever path in the system. We
      * should create the path in the namespace iff it's "/dev"
@@ -7841,7 +7843,7 @@ qemuDomainCreateDeviceRecursive(const char *device,
         if (qemuDomainCreateDeviceRecursive(target, data,
                                             allow_noent, ttl - 1) < 0)
             goto cleanup;
-    } else {
+    } else if (isDev) {
         if (create &&
             mknod(devicePath, sb.st_mode, sb.st_rdev) < 0) {
             if (errno == EEXIST) {
@@ -7863,6 +7865,11 @@ qemuDomainCreateDeviceRecursive(const char *device,
                                  devicePath);
             goto cleanup;
         }
+    } else {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+                       _("unsupported device type %s 0%o"),
+                       device, sb.st_mode);
+        goto cleanup;
     }
 
     if (!create) {