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

Re: [libvirt] [PATCHv2] network: Added hook for network modification event



On 05/25/2016 08:21 AM, Khramov Anton wrote:
> From: Anton Khramov <anton endocode com>
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1181539
> ---
>  docs/hooks.html.in          | 2 ++
>  src/network/bridge_driver.c | 5 +++++
>  src/util/virhook.c          | 3 ++-
>  src/util/virhook.h          | 1 +
>  4 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/docs/hooks.html.in b/docs/hooks.html.in
> index 1aae00c..d4f4ac3 100644
> --- a/docs/hooks.html.in
> +++ b/docs/hooks.html.in
> @@ -250,6 +250,8 @@
>            <pre>/etc/libvirt/hooks/network network_name plugged begin -</pre>
>          Please note, that in this case, the script is passed both network and
>          domain XMLs on its stdin.</li>
> +      <li>When network is updated, the hook script is called as:<br/>
> +          <pre>/etc/libvirt/hooks/network network_name updated begin -</pre></li>
>        <li>When the domain from previous case is shutting down, the interface
>          is unplugged. This leads to another script invocation:<br/>
>            <pre>/etc/libvirt/hooks/network network_name unplugged begin -</pre>
> diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
> index 0fd2095..1566ea7 100644
> --- a/src/network/bridge_driver.c
> +++ b/src/network/bridge_driver.c
> @@ -3387,6 +3387,11 @@ networkUpdate(virNetworkPtr net,
>      if (needFirewallRefresh && networkAddFirewallRules(network->def) < 0)
>          goto cleanup;
>  
> +    /* call the 'updated' network hook script */
> +    if (networkRunHook(network, NULL, NULL, VIR_HOOK_NETWORK_OP_UPDATED,
> +                       VIR_HOOK_SUBOP_BEGIN) < 0)
> +        goto cleanup;
> +

Hmm. I think the hook should probably come after all the UPDATE_AFFECT_LIVE
stuff below this in the code. Does your usecase depend on this hook happening
before dnsmasq restart? If so, maybe we two hooks, one for 'UPDATED' and one
for 'UPDATED_FIREWALL' or similar.

The networkUpdate function is a bit weird in that it saves the CONFIG to disk
here, but then proceeds to do more live changes afterwards. I figure saving
the config should be the last thing we attempt to do.

ccing laine

Thanks,
Cole

>      if (flags & VIR_NETWORK_UPDATE_AFFECT_CONFIG) {
>          /* save updated persistent config to disk */
>          if (virNetworkSaveConfig(driver->networkConfigDir,
> diff --git a/src/util/virhook.c b/src/util/virhook.c
> index d37d6da..a8422a2 100644
> --- a/src/util/virhook.c
> +++ b/src/util/virhook.c
> @@ -93,7 +93,8 @@ VIR_ENUM_IMPL(virHookNetworkOp, VIR_HOOK_NETWORK_OP_LAST,
>                "started",
>                "stopped",
>                "plugged",
> -              "unplugged")
> +              "unplugged",
> +              "updated")
>  
>  static int virHooksFound = -1;
>  
> diff --git a/src/util/virhook.h b/src/util/virhook.h
> index 550ef84..4015426 100644
> --- a/src/util/virhook.h
> +++ b/src/util/virhook.h
> @@ -82,6 +82,7 @@ typedef enum {
>      VIR_HOOK_NETWORK_OP_STOPPED,        /* network has stopped */
>      VIR_HOOK_NETWORK_OP_IFACE_PLUGGED,  /* an interface has been plugged into the network */
>      VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGED,    /* an interface was unplugged from the network */
> +    VIR_HOOK_NETWORK_OP_UPDATED,        /* network has been updated */
>  
>      VIR_HOOK_NETWORK_OP_LAST,
>  } virHookNetworkOpType;
> 


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