[libvirt] [PATCH 4/8] qemuDomainCreateDeviceRecursive: Fail on unsupported file type

Michal Privoznik posted 8 patches 8 years, 7 months ago
[libvirt] [PATCH 4/8] qemuDomainCreateDeviceRecursive: Fail on unsupported file type
Posted by Michal Privoznik 8 years, 7 months ago
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>
---
 src/qemu/qemu_domain.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 286d60761..e6fb041de 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7707,6 +7707,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;
@@ -7729,6 +7730,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"
@@ -7828,7 +7830,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) {
@@ -7850,6 +7852,11 @@ qemuDomainCreateDeviceRecursive(const char *device,
                                  devicePath);
             goto cleanup;
         }
+    } else {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+                       _("unsupported device type %s %o"),
+                       device, (int) sb.st_mode);
+        goto cleanup;
     }
 
     if (!create) {
-- 
2.13.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/8] qemuDomainCreateDeviceRecursive: Fail on unsupported file type
Posted by John Ferlan 8 years, 7 months ago

On 06/22/2017 12:18 PM, Michal Privoznik wrote:
> 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>
> ---
>  src/qemu/qemu_domain.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 

Your call - should the "%o" be a "0%o"  (see virStoragePoolDefFormatBuf
and virFileMakePathHelper)?  I think that's the more "proper" formatting
style used...


Reviewed-by: John Ferlan <jferlan@redhat.com>

John

-
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 286d60761..e6fb041de 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -7707,6 +7707,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;
> @@ -7729,6 +7730,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"
> @@ -7828,7 +7830,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) {
> @@ -7850,6 +7852,11 @@ qemuDomainCreateDeviceRecursive(const char *device,
>                                   devicePath);
>              goto cleanup;
>          }
> +    } else {
> +        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
> +                       _("unsupported device type %s %o"),
                                                        ^^
e.g. s/%o/0%o

(that's a zero not a capital Oh)

> +                       device, (int) sb.st_mode);
> +        goto cleanup;
>      }
>  
>      if (!create) {
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/8] qemuDomainCreateDeviceRecursive: Fail on unsupported file type
Posted by Michal Privoznik 8 years, 7 months ago
On 06/27/2017 11:55 PM, John Ferlan wrote:
> 
> 
> On 06/22/2017 12:18 PM, Michal Privoznik wrote:
>> 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>
>> ---
>>  src/qemu/qemu_domain.c | 9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>
> 
> Your call - should the "%o" be a "0%o"  (see virStoragePoolDefFormatBuf
> and virFileMakePathHelper)?  I think that's the more "proper" formatting
> style used...
> 

Ah, good point. It really should be "0%o". I'll fix that.
Also, as I am looking around now what we use in other areas I've found
that we even have a syntax-check rule for using the latter. For some
reason it isn't caught here...

> 
> Reviewed-by: John Ferlan <jferlan@redhat.com>

Thanks.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list