Re: [PATCH 4/5] virFileRewrite: Allow callback report errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 10, 2022 at 12:13:25PM +0100, Michal Privoznik wrote:
> Sometimes it may be handy for the callback to report error, even
> though our current callbacks are trivial. Let's report an error
> only if callback returns a well known value, otherwise assume it
> reported error message on its own.
> 
> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---
>  src/util/virfile.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/src/util/virfile.c b/src/util/virfile.c
> index f99e7f95e1..dd065a537c 100644
> --- a/src/util/virfile.c
> +++ b/src/util/virfile.c
> @@ -499,6 +499,10 @@ int virFileUnlock(int fd G_GNUC_UNUSED,
>   * @uid:@gid (pass -1 for current uid/gid) and written by
>   * @rewrite callback.
>   *
> + * A negative value returned by @rewrite callback is treated as
> + * error and if the value is different to -1 then it's the
> + * callback's responsibility to report error.

I'd sugest just updating the existing caller to always report
an error, rather than having different semantics for -1 vs -2.


> @@ -524,9 +529,11 @@ virFileRewrite(const char *path,
>          goto cleanup;
>      }
>  
> -    if (rewrite(fd, opaque) < 0) {
> -        virReportSystemError(errno, _("cannot write data to file '%s'"),
> -                             newfile);

And simply get rid of this virReportSystemError call entirely

> +    if ((rc = rewrite(fd, opaque)) < 0) {
> +        if (rc == -1) {
> +            virReportSystemError(errno, _("cannot write data to file '%s'"),
> +                                 newfile);
> +        }
>          goto cleanup;
>      }
>  
> -- 
> 2.34.1
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux