[ovs-dev] [PATCH ovn v3] ovn-nbctl: Create daemon control socket in ovn run dir

Dumitru Ceara dceara at redhat.com
Fri Apr 10 13:35:25 UTC 2020


On 4/8/20 4:46 PM, numans at ovn.org wrote:
> From: Numan Siddique <numans at ovn.org>
> 
> ovn-nbctl when run as a daemon is creating the ctl socket in
> the ovs rundir. This patch fixes this issue by creating it in
> the ovn rundir.
> 
> When an ovn service is run with -u option (which specifies the
> ctl socket path) and if this path is not absolute, the ovn
> ctl socket path is created in the ovs run dir. This patch
> also fixes this issue by creating it in the ovn run dir.
> 
> Reported-by: Dan Williams <dcbw at redhat.com>
> Signed-off-by: Numan Siddique <numans at ovn.org>

Hi Numan,

Looks good to me.

Acked-by: Dumitru Ceara <dceara at redhat.com>

However, I think we should have a follow up patch that takes care of
"--log-file" as well. E.g.:

ovn-nbctl --detach --log-file

This will create the socket file in the OVN rundir but the log file will
be created in the OVS rundir. This is true for all OVN daemons started
manually (without ovn-ctl).

What do you think?

Thanks,
Dumitru

> ---
> v2 -> v3
> ----
>   * Addressed the review comments from Ilya. Handled the unixctl
>     socket creation in ovn-controller-vtep and ovn-trace which was
>     missed out in v2.
> v1 -> v2
> ------
>   * Addressed the review comments from Ilya. If the ctl socket
>     path is specified and if it is not absolute path it is
>     now created in the ovn run dir.
> 
>  controller-vtep/ovn-controller-vtep.c |  5 ++++-
>  controller/ovn-controller.c           |  2 +-
>  ic/ovn-ic.c                           | 10 +++-------
>  lib/ovn-util.c                        |  9 +++++----
>  lib/ovn-util.h                        |  2 +-
>  northd/ovn-northd.c                   | 10 +++-------
>  utilities/ovn-nbctl.c                 |  6 +++++-
>  utilities/ovn-trace.c                 |  6 +++++-
>  8 files changed, 27 insertions(+), 23 deletions(-)
> 
> diff --git a/controller-vtep/ovn-controller-vtep.c b/controller-vtep/ovn-controller-vtep.c
> index b30a731d4..253a709ab 100644
> --- a/controller-vtep/ovn-controller-vtep.c
> +++ b/controller-vtep/ovn-controller-vtep.c
> @@ -67,7 +67,10 @@ main(int argc, char *argv[])
>  
>      daemonize_start(false);
>  
> -    retval = unixctl_server_create(NULL, &unixctl);
> +    char *abs_unixctl_path = get_abs_unix_ctl_path(NULL);
> +    retval = unixctl_server_create(abs_unixctl_path, &unixctl);
> +    free(abs_unixctl_path);
> +
>      if (retval) {
>          exit(EXIT_FAILURE);
>      }
> diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
> index 2893eaac1..4d21ba0fd 100644
> --- a/controller/ovn-controller.c
> +++ b/controller/ovn-controller.c
> @@ -1729,7 +1729,7 @@ main(int argc, char *argv[])
>  
>      daemonize_start(true);
>  
> -    char *abs_unixctl_path = get_abs_unix_ctl_path();
> +    char *abs_unixctl_path = get_abs_unix_ctl_path(NULL);
>      retval = unixctl_server_create(abs_unixctl_path, &unixctl);
>      free(abs_unixctl_path);
>      if (retval) {
> diff --git a/ic/ovn-ic.c b/ic/ovn-ic.c
> index bf8205de2..d931ca50f 100644
> --- a/ic/ovn-ic.c
> +++ b/ic/ovn-ic.c
> @@ -1575,13 +1575,9 @@ main(int argc, char *argv[])
>  
>      daemonize_start(false);
>  
> -    if (!unixctl_path) {
> -        char *abs_unixctl_path = get_abs_unix_ctl_path();
> -        retval = unixctl_server_create(abs_unixctl_path, &unixctl);
> -        free(abs_unixctl_path);
> -    } else {
> -        retval = unixctl_server_create(unixctl_path, &unixctl);
> -    }
> +    char *abs_unixctl_path = get_abs_unix_ctl_path(unixctl_path);
> +    retval = unixctl_server_create(abs_unixctl_path, &unixctl);
> +    free(abs_unixctl_path);
>  
>      if (retval) {
>          exit(EXIT_FAILURE);
> diff --git a/lib/ovn-util.c b/lib/ovn-util.c
> index df18fda89..514e2489f 100644
> --- a/lib/ovn-util.c
> +++ b/lib/ovn-util.c
> @@ -377,7 +377,7 @@ default_ic_sb_db(void)
>  }
>  
>  char *
> -get_abs_unix_ctl_path(void)
> +get_abs_unix_ctl_path(const char *path)
>  {
>  #ifdef _WIN32
>      enum { WINDOWS = 1 };
> @@ -386,9 +386,10 @@ get_abs_unix_ctl_path(void)
>  #endif
>  
>      long int pid = getpid();
> -    char *abs_path =
> -        WINDOWS ? xasprintf("%s/%s.ctl", ovn_rundir(), program_name)
> -                : xasprintf("%s/%s.%ld.ctl", ovn_rundir(), program_name, pid);
> +    char *abs_path
> +        = (path ? abs_file_name(ovn_rundir(), path)
> +           : WINDOWS ? xasprintf("%s/%s.ctl", ovn_rundir(), program_name)
> +           : xasprintf("%s/%s.%ld.ctl", ovn_rundir(), program_name, pid));
>      return abs_path;
>  }
>  
> diff --git a/lib/ovn-util.h b/lib/ovn-util.h
> index 32c8334b0..11238f61c 100644
> --- a/lib/ovn-util.h
> +++ b/lib/ovn-util.h
> @@ -82,7 +82,7 @@ const char *default_nb_db(void);
>  const char *default_sb_db(void);
>  const char *default_ic_nb_db(void);
>  const char *default_ic_sb_db(void);
> -char *get_abs_unix_ctl_path(void);
> +char *get_abs_unix_ctl_path(const char *path);
>  
>  struct ovsdb_idl_table_class;
>  const char *db_table_usage(struct ds *tables,
> diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
> index 076278197..29e1fd450 100644
> --- a/northd/ovn-northd.c
> +++ b/northd/ovn-northd.c
> @@ -11600,13 +11600,9 @@ main(int argc, char *argv[])
>  
>      daemonize_start(false);
>  
> -    if (!unixctl_path) {
> -        char *abs_unixctl_path = get_abs_unix_ctl_path();
> -        retval = unixctl_server_create(abs_unixctl_path, &unixctl);
> -        free(abs_unixctl_path);
> -    } else {
> -        retval = unixctl_server_create(unixctl_path, &unixctl);
> -    }
> +    char *abs_unixctl_path = get_abs_unix_ctl_path(unixctl_path);
> +    retval = unixctl_server_create(abs_unixctl_path, &unixctl);
> +    free(abs_unixctl_path);
>  
>      if (retval) {
>          exit(EXIT_FAILURE);
> diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
> index 59abe0051..a88c1ddc2 100644
> --- a/utilities/ovn-nbctl.c
> +++ b/utilities/ovn-nbctl.c
> @@ -6436,7 +6436,11 @@ server_loop(struct ovsdb_idl *idl, int argc, char *argv[])
>  
>      service_start(&argc, &argv);
>      daemonize_start(false);
> -    int error = unixctl_server_create(unixctl_path, &server);
> +
> +    char *abs_unixctl_path = get_abs_unix_ctl_path(unixctl_path);
> +    int error = unixctl_server_create(abs_unixctl_path, &server);
> +    free(abs_unixctl_path);
> +
>      if (error) {
>          ctl_fatal("failed to create unixctl server (%s)",
>                    ovs_retval_to_string(error));
> diff --git a/utilities/ovn-trace.c b/utilities/ovn-trace.c
> index 84e5f2b5c..5e1d92c72 100644
> --- a/utilities/ovn-trace.c
> +++ b/utilities/ovn-trace.c
> @@ -125,7 +125,11 @@ main(int argc, char *argv[])
>      bool exiting = false;
>      if (get_detach()) {
>          daemonize_start(false);
> -        int error = unixctl_server_create(unixctl_path, &server);
> +
> +        char *abs_unixctl_path = get_abs_unix_ctl_path(unixctl_path);
> +        int error = unixctl_server_create(abs_unixctl_path, &server);
> +        free(abs_unixctl_path);
> +
>          if (error) {
>              ovs_fatal(error, "failed to create unixctl server");
>          }
> 



More information about the dev mailing list