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

Re: [libvirt] [PATCH 1/4] Unify checking for machine1 systemd service



On Thu, Feb 23, 2017 at 12:53:06PM +0100, Ján Tomko wrote:
> Both virSystemdTerminateMachine and virSystemdCreateMachine
> propagate the error to tell between a non-systemd system
> and a hard error.
> 
> In virSystemdGetMachineNameByPID both are treated the same,
> but an error is ignored by the callers.
> 
> Split out the checks into a separate function.
> ---
>  src/util/virsystemd.c | 31 +++++++++++++++++--------------
>  1 file changed, 17 insertions(+), 14 deletions(-)
> 
> diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
> index 7ec3eee..d7a4e78 100644
> --- a/src/util/virsystemd.c
> +++ b/src/util/virsystemd.c
> @@ -182,6 +182,20 @@ virSystemdMakeMachineName(const char *drivername,
>      return machinename;
>  }
>  
> +/* -2 = machine1 is not supported on this machine
> + * -1 = error
> + *  0 = machine1 is available
> + */
> +static int
> +virSystemdHasCreateMachine(void)

How about virSystemdHasMachined?  It's not only used to create a machine so
the function name may be misleading.  That would also require to change the
names in the following patch to virSystemdHasMachinedCachedValue and
virSystemdHasMachinedResetCachedValue.

ACK series with that fixed.

Pavel

> +{
> +    int ret;
> +    if ((ret = virDBusIsServiceEnabled("org.freedesktop.machine1")) < 0)
> +        return ret;
> +
> +    return virDBusIsServiceRegistered("org.freedesktop.systemd1");
> +}
> +
>  
>  char *
>  virSystemdGetMachineNameByPID(pid_t pid)
> @@ -190,10 +204,7 @@ virSystemdGetMachineNameByPID(pid_t pid)
>      DBusMessage *reply = NULL;
>      char *name = NULL, *object = NULL;
>  
> -    if (virDBusIsServiceEnabled("org.freedesktop.machine1") < 0)
> -        goto cleanup;
> -
> -    if (virDBusIsServiceRegistered("org.freedesktop.systemd1") < 0)
> +    if (virSystemdHasCreateMachine() < 0)
>          goto cleanup;
>  
>      if (!(conn = virDBusGetSystemBus()))
> @@ -268,11 +279,7 @@ int virSystemdCreateMachine(const char *name,
>      char *slicename = NULL;
>      static int hasCreateWithNetwork = 1;
>  
> -    ret = virDBusIsServiceEnabled("org.freedesktop.machine1");
> -    if (ret < 0)
> -        return ret;
> -
> -    if ((ret = virDBusIsServiceRegistered("org.freedesktop.systemd1")) < 0)
> +    if ((ret = virSystemdHasCreateMachine()) < 0)
>          return ret;
>  
>      if (!(conn = virDBusGetSystemBus()))
> @@ -434,11 +441,7 @@ int virSystemdTerminateMachine(const char *name)
>  
>      memset(&error, 0, sizeof(error));
>  
> -    ret = virDBusIsServiceEnabled("org.freedesktop.machine1");
> -    if (ret < 0)
> -        goto cleanup;
> -
> -    if ((ret = virDBusIsServiceRegistered("org.freedesktop.systemd1")) < 0)
> +    if ((ret = virSystemdHasCreateMachine()) < 0)
>          goto cleanup;
>  
>      ret = -1;
> -- 
> 2.10.2
> 
> --
> libvir-list mailing list
> libvir-list redhat com
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: signature.asc
Description: Digital signature


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