Re: [PATCH 10/16] network: Introduce virNetworkObj{Get|Set}Autostart

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

 



On Fri, May 19, 2017 at 09:03:18AM -0400, John Ferlan wrote:
> In preparation for privatizing the virNetworkObj structure, move the guts
> of the Get/Set Autostart from the driver into virnetworkobj. Alter the driver
> to make the calls to the networkobj code.
> 
> Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
> ---
>  src/conf/virnetworkobj.c    | 74 +++++++++++++++++++++++++++++++++++++++++++++
>  src/conf/virnetworkobj.h    | 11 ++++++-
>  src/libvirt_private.syms    |  2 ++
>  src/network/bridge_driver.c | 53 ++++----------------------------
>  src/test/test_driver.c      |  6 ++--
>  5 files changed, 96 insertions(+), 50 deletions(-)
> 
> diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
> index 488fffd..a21aa26 100644
> --- a/src/conf/virnetworkobj.c
> +++ b/src/conf/virnetworkobj.c
> @@ -121,6 +121,80 @@ virNetworkObjGetNewDef(virNetworkObjPtr obj)
>  }
>  
>  
> +int
> +virNetworkObjGetAutostart(virNetworkObjPtr obj)
> +{
> +    return obj->autostart;
> +}
> +
> +
> +int
> +virNetworkObjSetAutostart(virNetworkObjPtr obj,
> +                          const char *configDir,
> +                          const char *autostartDir,
> +                          int autostart)
> +{
> +    virNetworkDefPtr def = obj->def;
> +    char *configFile = NULL;
> +    char *autostartLink = NULL;
> +    int ret = -1;
> +
> +    if (!obj->persistent) {
> +        virReportError(VIR_ERR_OPERATION_INVALID,
> +                       _("cannot set autostart for transient network '%s'"),
> +                       def->name);
> +        return -1;
> +    }
> +
> +    autostart = (autostart != 0);
> +
> +    if (obj->autostart != autostart) {
> +        if (configDir && autostartDir) {
> +            if (!(configFile = virNetworkConfigFile(configDir, def->name)))
> +                goto cleanup;
> +
> +            if (!(autostartLink = virNetworkConfigFile(autostartDir,
> +                                                       def->name)))
> +                goto cleanup;
> +
> +            if (autostart) {
> +                if (virFileMakePath(autostartDir) < 0) {
> +                    virReportSystemError(errno,
> +                                         _("cannot create autostart dir '%s'"),
> +                                         autostartDir);
> +                    goto cleanup;
> +                }
> +
> +                if (symlink(configFile, autostartLink) < 0) {
> +                    virReportSystemError(errno,
> +                                         _("failed to create symlink '%s' "
> +                                           "to '%s'"),
> +                                         autostartLink, configFile);
> +                    goto cleanup;
> +                }
> +            } else {
> +                if (unlink(autostartLink) < 0 &&
> +                    errno != ENOENT && errno != ENOTDIR) {
> +                    virReportSystemError(errno,
> +                                         _("failed to delete symlink '%s'"),
> +                                         autostartLink);
> +                    goto cleanup;
> +                }
> +            }
> +        }
> +
> +        obj->autostart = autostart;
> +    }
> +
> +    ret = 0;
> +
> + cleanup:
> +    VIR_FREE(configFile);
> +    VIR_FREE(autostartLink);
> +    return ret;
> +}

The same review as for [1], keep the file operations in driver code.

Pavel

[1] <https://www.redhat.com/archives/libvir-list/2017-July/msg00359.html>

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[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