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

Zhao Liu posted 7 patches 4 months, 1 week ago
Maintainers: David Hildenbrand <david@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Yi Liu <yi.l.liu@intel.com>, Eric Auger <eric.auger@redhat.com>, Zhenzhong Duan <zhenzhong.duan@intel.com>, Laurent Vivier <lvivier@redhat.com>, Amit Shah <amit@kernel.org>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>
[PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()
Posted by Zhao Liu 4 months, 1 week ago
For qemu_open_old(), osdep.h said:

> 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 <lvivier@redhat.com>
Cc: Amit Shah <amit@kernel.org>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 backends/rng-random.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/backends/rng-random.c b/backends/rng-random.c
index 80eb5be138ce..3cdb982533b5 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -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);
     }
 }
 
-- 
2.34.1
Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()
Posted by Philippe Mathieu-Daudé 4 months, 1 week ago
On 15/7/24 10:21, Zhao Liu wrote:
> For qemu_open_old(), osdep.h said:
> 
>> 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 <lvivier@redhat.com>
> Cc: Amit Shah <amit@kernel.org>
> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> ---
>   backends/rng-random.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/backends/rng-random.c b/backends/rng-random.c
> index 80eb5be138ce..3cdb982533b5 100644
> --- a/backends/rng-random.c
> +++ b/backends/rng-random.c
> @@ -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().
> +         */

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

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> +        s->fd = qemu_open(s->filename, O_RDONLY | O_NONBLOCK, errp);
>       }
>   }
>   


Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()
Posted by Zhao Liu 4 months, 1 week ago
On Mon, Jul 15, 2024 at 11:46:54AM +0200, Philippe Mathieu-Daudé wrote:
> Date: Mon, 15 Jul 2024 11:46:54 +0200
> From: Philippe Mathieu-Daudé <philmd@linaro.org>
> Subject: Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()
> 
> On 15/7/24 10:21, Zhao Liu wrote:
> > For qemu_open_old(), osdep.h said:
> > 
> > > 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 <lvivier@redhat.com>
> > Cc: Amit Shah <amit@kernel.org>
> > Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> > ---
> >   backends/rng-random.c | 9 +++++----
> >   1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/backends/rng-random.c b/backends/rng-random.c
> > index 80eb5be138ce..3cdb982533b5 100644
> > --- a/backends/rng-random.c
> > +++ b/backends/rng-random.c
> > @@ -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().
> > +         */
> 
> IMHO this comment is superfluous, I'd drop it, otherwise:
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>

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()
Posted by Michael Tokarev 4 months, 1 week ago
15.07.2024 13:10, Zhao Liu wrote:
...
> 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

-- 
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()
Posted by Zhao Liu 4 months, 1 week ago
On Mon, Jul 15, 2024 at 02:07:00PM +0300, Michael Tokarev wrote:
> Date: Mon, 15 Jul 2024 14:07:00 +0300
> From: Michael Tokarev <mjt@tls.msk.ru>
> Subject: Re: [PATCH 7/7] backends/rng-random: Get rid of qemu_open_old()
> 
> 15.07.2024 13:10, Zhao Liu wrote:
> ...
> > 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!