trivial: Replace some qemu_open_old() with qemu_open()
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
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.
--- hw/i386/sgx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/i386/sgx.c +4 -2
@@ -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
PATCH 2/7 hw/usb/host-libusb: Get rid of qemu_open_old()
In reply to Zhao LiuQuoted 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
@@ -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
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()withqemu_open().Signed-off-by Zhao Liu <[email protected]>--- hw/usb/host-libusb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH 3/7 hw/usb/u2f-passthru: Get rid of qemu_open_old()
In reply to Zhao LiuQuoted 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
@@ -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
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()withqemu_open().Signed-off-by Zhao Liu <[email protected]>--- hw/usb/u2f-passthru.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
PATCH 4/7 hw/vfio/container: Get rid of qemu_open_old()
In reply to Zhao LiuQuoted 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/vfio/container.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/vfio/container.c +2 -4
@@ -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
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()withqemu_open().Cc Alex Williamson <[email protected]>Cc "Cédric Le Goater" <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/vfio/container.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Re: [PATCH 4/7] hw/vfio/container: Get rid of qemu_open_old()
In reply to Zhao LiuQuoted 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()withqemu_open().Cc Alex Williamson <[email protected]>Cc "Cédric Le Goater" <[email protected]>Signed-off-by Zhao Liu <[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@@ -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; }
PATCH 5/7 backends/hostmem-epc: Get rid of qemu_open_old()
In reply to Zhao LiuQuoted 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().
--- backends/hostmem-epc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
backends/hostmem-epc.c +1 -3
@@ -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
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()withqemu_open().Cc David Hildenbrand <[email protected]>Cc Igor Mammedov <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- backends/hostmem-epc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Re: [PATCH 5/7] backends/hostmem-epc: Get rid of qemu_open_old()
In reply to Zhao LiuQuoted 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()withqemu_open().Cc David Hildenbrand <[email protected]>Cc Igor Mammedov <[email protected]>Signed-off-by Zhao Liu <[email protected]>
Quoted 20 lines
--- backends/hostmem-epc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)backends/hostmem-epc.c +1
-3@@ -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; }
PATCH 6/7 backends/iommufd: Get rid of qemu_open_old()
In reply to Zhao LiuQuoted 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().
--- backends/iommufd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
backends/iommufd.c +1 -2
@@ -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
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()withqemu_open().
Quoted 7 lines
Cc Yi Liu <[email protected]>Cc Eric Auger <[email protected]>Cc Zhenzhong Duan <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- backends/iommufd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Re: [PATCH 6/7] backends/iommufd: Get rid of qemu_open_old()
In reply to Zhao LiuQuoted 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()withqemu_open().
Quoted 7 lines
Cc Yi Liu <[email protected]>Cc Eric Auger <[email protected]>Cc Zhenzhong Duan <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- backends/iommufd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 15 lines
backends/iommufd.c +1
-2@@ -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
PATCH 7/7 backends/rng-random: Get rid of qemu_open_old()
In reply to Zhao LiuQuoted 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.
--- backends/rng-random.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
backends/rng-random.c +5 -4
@@ -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
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()withqemu_open(). And consideringrng_random_opened()will lose its obvious error handling case after removingerror_setg_file_open(), add comment to remind here.Cc Laurent Vivier <[email protected]>Cc Amit Shah <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- backends/rng-random.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)backends/rng-random.c +0
-0@@ -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); } }
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 ofqemu_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()withqemu_open(). And consideringrng_random_opened()will lose its obvious error handling case after removingerror_setg_file_open(), add comment to remind here.Cc Laurent Vivier <[email protected]>Cc Amit Shah <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- backends/rng-random.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)backends/rng-random.c +0
-0@@ -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
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks Philippe! I'll wait patch 1's comment, after that I can post a new version with the change you mentioned.
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
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 ofqemu_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!