Skip to contentSkip to conversation

trivial: Replace some qemu_open_old() with qemu_open()

PATCH In review Zhao Liu 6 participants 20 messages Jul 15, 2024 – Jul 16, 2024 Arm STM32

lore
Share & tools
lore

Zhao Liu

author
#0 lore raw

cover trivial: Replace some qemu_open_old() with qemu_open()

Hi list,

After Daniel's renaming (448058aa99aa "util: rename qemu_open() to qemu_open_old()"), I find some qemu_open_old() can be directly replaced by the new qemu_open().

This series considers the case where @errp exists, for which @errp can be passed directly to qemu_open().

There would be more cleanup to help qemu_open_old() retire as early as possible.

Thanks and Best Regards,
Zhao
---
Zhao Liu (7):
hw/i386/sgx: Get rid of qemu_open_old() hw/usb/host-libusb: Get rid of qemu_open_old() hw/usb/u2f-passthru: Get rid of qemu_open_old() hw/vfio/container: Get rid of qemu_open_old() backends/hostmem-epc: Get rid of qemu_open_old() backends/iommufd: Get rid of qemu_open_old() backends/rng-random: Get rid of qemu_open_old()

 backends/hostmem-epc.c | 4 +---
 backends/iommufd.c     | 3 +--
 backends/rng-random.c  | 9 +++++----
 hw/i386/sgx.c          | 6 ++++--
 hw/usb/host-libusb.c   | 3 +--
 hw/usb/u2f-passthru.c  | 4 +---
 hw/vfio/container.c    | 6 ++----
 7 files changed, 15 insertions(+), 20 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/7 hw/i386/sgx: Get rid of qemu_open_old()

Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open(). And considering the SGX enablement description is useful, convert it into a error message hint.

Cc Paolo Bonzini <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
---
 hw/i386/sgx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/i386/sgx.c +4 -2
index de76397bcfb3..a14a84bc6f69 100644
@@ -157,10 +157,12 @@ SGXInfo *qmp_query_sgx_capabilities(Error **errp)
 {
     SGXInfo *info = NULL;
     uint32_t eax, ebx, ecx, edx;
+    Error *local_err = NULL;
 
-    int fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
+    int fd = qemu_open("/dev/sgx_vepc", O_RDWR, &local_err);
     if (fd < 0) {
-        error_setg(errp, "SGX is not enabled in KVM");
+        error_append_hint(&local_err, "SGX is not enabled in KVM");
+        error_propagate(errp, local_err);
         return NULL;
     }
 
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/7 hw/usb/host-libusb: Get rid of qemu_open_old()

In reply to Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

---
 hw/usb/host-libusb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/usb/host-libusb.c +1 -2
index 80122b41259a..691bc881fbcd 100644
@@ -1212,9 +1212,8 @@ static void usb_host_realize(USBDevice *udev, Error **errp)
     if (s->hostdevice) {
         int fd;
         s->needs_autoscan = false;
-        fd = qemu_open_old(s->hostdevice, O_RDWR);
+        fd = qemu_open(s->hostdevice, O_RDWR, errp);
         if (fd < 0) {
-            error_setg_errno(errp, errno, "failed to open %s", s->hostdevice);
             return;
         }
         rc = usb_host_open(s, NULL, fd);
Signature · 1 line
2.34.1
Reviewed-by on v1 2/7
#3 lore raw

Re: [PATCH 2/7] hw/usb/host-libusb: Get rid of qemu_open_old()

Quoted 11 lines · Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

---
  hw/usb/host-libusb.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
author
#4 lore raw

PATCH 3/7 hw/usb/u2f-passthru: Get rid of qemu_open_old()

In reply to Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

---
 hw/usb/u2f-passthru.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/usb/u2f-passthru.c +1 -3
index b7025d303d07..c4a783d12864 100644
@@ -482,10 +482,8 @@ static void u2f_passthru_realize(U2FKeyState *base, Error **errp)
         return;
 #endif
     } else {
-        fd = qemu_open_old(key->hidraw, O_RDWR);
+        fd = qemu_open(key->hidraw, O_RDWR, errp);
         if (fd < 0) {
-            error_setg(errp, "%s: Failed to open %s", TYPE_U2F_PASSTHRU,
-                       key->hidraw);
             return;
         }
 
Signature · 1 line
2.34.1
Reviewed-by on v1 3/7
#5 lore raw

Re: [PATCH 3/7] hw/usb/u2f-passthru: Get rid of qemu_open_old()

Quoted 11 lines · Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

---
  hw/usb/u2f-passthru.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
author
#6 lore raw

PATCH 4/7 hw/vfio/container: Get rid of qemu_open_old()

In reply to Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

Cc Alex Williamson <[email protected]>
Cc "Cédric Le Goater" <[email protected]>
---
 hw/vfio/container.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
hw/vfio/container.c +2 -4
index 425db1a14c07..38a9df34964a 100644
@@ -600,9 +600,8 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
         }
     }
 
-    fd = qemu_open_old("/dev/vfio/vfio", O_RDWR);
+    fd = qemu_open("/dev/vfio/vfio", O_RDWR, errp);
     if (fd < 0) {
-        error_setg_errno(errp, errno, "failed to open /dev/vfio/vfio");
         goto put_space_exit;
     }
 
@@ -743,9 +742,8 @@ static VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp)
     group = g_malloc0(sizeof(*group));
 
     snprintf(path, sizeof(path), "/dev/vfio/%d", groupid);
-    group->fd = qemu_open_old(path, O_RDWR);
+    group->fd = qemu_open(path, O_RDWR, errp);
     if (group->fd < 0) {
-        error_setg_errno(errp, errno, "failed to open %s", path);
         goto free_group_exit;
     }
 
Signature · 1 line
2.34.1
Reviewed-by on v1 4/7
#7 lore raw

Re: [PATCH 4/7] hw/vfio/container: Get rid of qemu_open_old()

Quoted 5 lines · Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

Quoted 8 lines

So replace qemu_open_old() with qemu_open().

Cc Alex Williamson <[email protected]>
Cc "Cédric Le Goater" <[email protected]>
---
  hw/vfio/container.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
Reviewed-by on v1 4/7
#8 lore raw

Re: [PATCH 4/7] hw/vfio/container: Get rid of qemu_open_old()

In reply to Zhao Liu
Quoted 10 lines · Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

Cc Alex Williamson <[email protected]>
Cc "Cédric Le Goater" <[email protected]>

Thanks,

C.

Quoted 30 lines
---
  hw/vfio/container.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
hw/vfio/container.c +2 -4
index 425db1a14c07..38a9df34964a 100644
@@ -600,9 +600,8 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
          }
      }
 
-    fd = qemu_open_old("/dev/vfio/vfio", O_RDWR);
+    fd = qemu_open("/dev/vfio/vfio", O_RDWR, errp);
      if (fd < 0) {
-        error_setg_errno(errp, errno, "failed to open /dev/vfio/vfio");
          goto put_space_exit;
      }
 
@@ -743,9 +742,8 @@ static VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp)
      group = g_malloc0(sizeof(*group));
 
      snprintf(path, sizeof(path), "/dev/vfio/%d", groupid);
-    group->fd = qemu_open_old(path, O_RDWR);
+    group->fd = qemu_open(path, O_RDWR, errp);
      if (group->fd < 0) {
-        error_setg_errno(errp, errno, "failed to open %s", path);
          goto free_group_exit;
      }
 
author
#9 lore raw

PATCH 5/7 backends/hostmem-epc: Get rid of qemu_open_old()

In reply to Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

Cc David Hildenbrand <[email protected]>
Cc Igor Mammedov <[email protected]>
---
 backends/hostmem-epc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
backends/hostmem-epc.c +1 -3
index f58fcf00a10b..6c024d6217d2 100644
@@ -29,10 +29,8 @@ sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
         return false;
     }
 
-    fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
+    fd = qemu_open("/dev/sgx_vepc", O_RDWR, errp);
     if (fd < 0) {
-        error_setg_errno(errp, errno,
-                         "failed to open /dev/sgx_vepc to alloc SGX EPC");
         return false;
     }
 
Signature · 1 line
2.34.1
Reviewed-by on v1 5/7
#10 lore raw

Re: [PATCH 5/7] backends/hostmem-epc: Get rid of qemu_open_old()

Quoted 5 lines · Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

Quoted 8 lines

So replace qemu_open_old() with qemu_open().

Cc David Hildenbrand <[email protected]>
Cc Igor Mammedov <[email protected]>
---
  backends/hostmem-epc.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
Reviewed-by on v1 5/7
#11 lore raw

Re: [PATCH 5/7] backends/hostmem-epc: Get rid of qemu_open_old()

In reply to Zhao Liu
Quoted 10 lines · On Mon, 15 Jul 2024 16:21:53 +0800 Zhao Liu <[email protected]> wrote:
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

Cc David Hildenbrand <[email protected]>
Cc Igor Mammedov <[email protected]>
Quoted 20 lines
---
 backends/hostmem-epc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
backends/hostmem-epc.c +1 -3
index f58fcf00a10b..6c024d6217d2 100644
@@ -29,10 +29,8 @@ sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
         return false;
     }
 
-    fd = qemu_open_old("/dev/sgx_vepc", O_RDWR);
+    fd = qemu_open("/dev/sgx_vepc", O_RDWR, errp);
     if (fd < 0) {
-        error_setg_errno(errp, errno,
-                         "failed to open /dev/sgx_vepc to alloc SGX EPC");
         return false;
     }
 
author
#12 lore raw

PATCH 6/7 backends/iommufd: Get rid of qemu_open_old()

In reply to Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

Cc Yi Liu <[email protected]>
Cc Eric Auger <[email protected]>
Cc Zhenzhong Duan <[email protected]>
---
 backends/iommufd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
backends/iommufd.c +1 -2
index 84fefbc9ee7a..cabd1b50025d 100644
@@ -77,9 +77,8 @@ bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp)
     int fd;
 
     if (be->owned && !be->users) {
-        fd = qemu_open_old("/dev/iommu", O_RDWR);
+        fd = qemu_open("/dev/iommu", O_RDWR, errp);
         if (fd < 0) {
-            error_setg_errno(errp, errno, "/dev/iommu opening failed");
             return false;
         }
         be->fd = fd;
Signature · 1 line
2.34.1
Reviewed-by on v1 6/7
#13 lore raw

Re: [PATCH 6/7] backends/iommufd: Get rid of qemu_open_old()

Quoted 7 lines · Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

Quoted 7 lines
Cc Yi Liu <[email protected]>
Cc Eric Auger <[email protected]>
Cc Zhenzhong Duan <[email protected]>
---
  backends/iommufd.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed-by on v1 6/7
#14 lore raw

Re: [PATCH 6/7] backends/iommufd: Get rid of qemu_open_old()

In reply to Zhao Liu
Quoted 7 lines · Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open().

Quoted 7 lines
Cc Yi Liu <[email protected]>
Cc Eric Auger <[email protected]>
Cc Zhenzhong Duan <[email protected]>
---
  backends/iommufd.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 15 lines
backends/iommufd.c +1 -2
index 84fefbc9ee7a..cabd1b50025d 100644
@@ -77,9 +77,8 @@ bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp)
      int fd;
 
      if (be->owned && !be->users) {
-        fd = qemu_open_old("/dev/iommu", O_RDWR);
+        fd = qemu_open("/dev/iommu", O_RDWR, errp);
          if (fd < 0) {
-            error_setg_errno(errp, errno, "/dev/iommu opening failed");
              return false;
          }
          be->fd = fd;
Signature · 2 lines
Regards,
Yi Liu
author
#15 lore raw

PATCH 7/7 backends/rng-random: Get rid of qemu_open_old()

In reply to Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open(). And considering rng_random_opened() will lose its obvious error handling case after removing error_setg_file_open(), add comment to remind here.

Cc Laurent Vivier <[email protected]>
Cc Amit Shah <[email protected]>
---
 backends/rng-random.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
backends/rng-random.c +5 -4
index 80eb5be138ce..3cdb982533b5 100644
@@ -75,10 +75,11 @@ static void rng_random_opened(RngBackend *b, Error **errp)
         error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
                    "filename", "a valid filename");
     } else {
-        s->fd = qemu_open_old(s->filename, O_RDONLY | O_NONBLOCK);
-        if (s->fd == -1) {
-            error_setg_file_open(errp, errno, s->filename);
-        }
+        /*
+         * Once the open fails, the error message is integrated into
+         * the *errp object by qemu_open().
+         */
+        s->fd = qemu_open(s->filename, O_RDONLY | O_NONBLOCK, errp);
     }
 }
 
Signature · 1 line
2.34.1
Reviewed-by on v1 7/7
#16 lore raw

Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()

Quoted 22 lines · Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open(). And considering rng_random_opened() will lose its obvious error handling case after removing error_setg_file_open(), add comment to remind here.

Cc Laurent Vivier <[email protected]>
Cc Amit Shah <[email protected]>
---
  backends/rng-random.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
backends/rng-random.c +0 -0
index 80eb5be138ce..3cdb982533b5 100644
@@ -75,10 +75,11 @@ static void rng_random_opened(RngBackend *b, Error **errp)
          error_setg(errp, QERR_INVALID_PARAMETER_VALUE,

backends/rng-random.c static void rng_random_opened(RngBackend *b, Error **errp) · line 81

Quoted 10 lines
backends/rng-random.c +4 -4
                     "filename", "a valid filename");
      } else {
-        s->fd = qemu_open_old(s->filename, O_RDONLY | O_NONBLOCK);
-        if (s->fd == -1) {
-            error_setg_file_open(errp, errno, s->filename);
-        }
+        /*
+         * Once the open fails, the error message is integrated into
+         * the *errp object by qemu_open().
+         */

IMHO this comment is superfluous, I'd drop it, otherwise:

Quoted 4 lines
backends/rng-random.c +1 -0
+        s->fd = qemu_open(s->filename, O_RDONLY | O_NONBLOCK, errp);
      }
  }
 
author
#17 lore raw

Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()

Quoted 40 lines · Philippe Mathieu-Daudé

Date: Mon, 15 Jul 2024 11:46:54 +0200
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()

Quoted 22 lines · Zhao Liu
Quoted 2 lines · osdep.h

Don't introduce new usage of this function, prefer the following qemu_open/qemu_create that take an "Error **errp".

So replace qemu_open_old() with qemu_open(). And considering rng_random_opened() will lose its obvious error handling case after removing error_setg_file_open(), add comment to remind here.

Cc Laurent Vivier <[email protected]>
Cc Amit Shah <[email protected]>
---
  backends/rng-random.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
backends/rng-random.c +0 -0
index 80eb5be138ce..3cdb982533b5 100644
@@ -75,10 +75,11 @@ static void rng_random_opened(RngBackend *b, Error **errp)
          error_setg(errp, QERR_INVALID_PARAMETER_VALUE,

backends/rng-random.c static void rng_random_opened(RngBackend *b, Error **errp) · line 81

Quoted 10 lines
backends/rng-random.c +4 -4
                     "filename", "a valid filename");
      } else {
-        s->fd = qemu_open_old(s->filename, O_RDONLY | O_NONBLOCK);
-        if (s->fd == -1) {
-            error_setg_file_open(errp, errno, s->filename);
-        }
+        /*
+         * Once the open fails, the error message is integrated into
+         * the *errp object by qemu_open().
+         */

IMHO this comment is superfluous, I'd drop it, otherwise:

Quoted 2 lines

Thanks Philippe! I'll wait patch 1's comment, after that I can post a new version with the change you mentioned.

#18 lore raw

Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()

15.07.2024 13:10, Zhao Liu wrote:
...

Quoted 2 lines

Thanks Philippe! I'll wait patch 1's comment, after that I can post a new version with the change you mentioned.

I don't think either of this is necessary. Patch 1 LGTM, and I'll drop the comment while applying.

/mjt

Signature · 4 lines
GPG Key transition (from rsa2048 to rsa4096) since 2024-04-24.
New key: rsa4096/61AD3D98ECDF2C8E  9D8B E14E 3F2A 9DD7 9199  28F1 61AD 3D98 ECDF 2C8E
Old key: rsa2048/457CE0A0804465C5  6EE1 95D1 886E 8FFB 810D  4324 457C E0A0 8044 65C5
Transition statement: http://www.corpit.ru/mjt/gpg-transition-2024.txt
author
#19 lore raw

Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()

Quoted 4 lines · Michael Tokarev

Date: Mon, 15 Jul 2024 14:07:00 +0300
From: Michael Tokarev <[email protected]>
Subject: Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()

Quoted 8 lines

15.07.2024 13:10, Zhao Liu wrote:
...

Quoted 2 lines

Thanks Philippe! I'll wait patch 1's comment, after that I can post a new version with the change you mentioned.

I don't think either of this is necessary. Patch 1 LGTM, and I'll drop the comment while applying.

Many thanks!