[ovs-dev] [PATCH 07/11] ovn-nbctl: Don't die in dhcp_options_get().

Jakub Sitnicki jkbs at redhat.com
Tue Jul 17 13:34:11 UTC 2018


Let the caller handle the error. This prepares us for reporting errors
in daemon mode.

Signed-off-by: Jakub Sitnicki <jkbs at redhat.com>
---
 ovn/utilities/ovn-nbctl.c | 44 +++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index c18fa2825..cf49a6b11 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -86,8 +86,9 @@ static void run_prerequisites(struct ctl_command[], size_t n_commands,
                               struct ovsdb_idl *);
 static bool do_nbctl(const char *args, struct ctl_command *, size_t n,
                      struct ovsdb_idl *);
-static const struct nbrec_dhcp_options *dhcp_options_get(
-    struct ctl_context *ctx, const char *id, bool must_exist);
+static char * OVS_WARN_UNUSED_RESULT dhcp_options_get(
+    struct ctl_context *ctx, const char *id, bool must_exist,
+    const struct nbrec_dhcp_options **);
 
 int
 main(int argc, char *argv[])
@@ -1448,7 +1449,10 @@ nbctl_lsp_set_dhcpv4_options(struct ctl_context *ctx)
     }
     const struct nbrec_dhcp_options *dhcp_opt = NULL;
     if (ctx->argc == 3 ) {
-        dhcp_opt = dhcp_options_get(ctx, ctx->argv[2], true);
+        error = dhcp_options_get(ctx, ctx->argv[2], true, &dhcp_opt);
+        if (error) {
+            ctl_fatal("%s", error);
+        }
     }
 
     if (dhcp_opt) {
@@ -1475,7 +1479,10 @@ nbctl_lsp_set_dhcpv6_options(struct ctl_context *ctx)
     }
     const struct nbrec_dhcp_options *dhcp_opt = NULL;
     if (ctx->argc == 3) {
-        dhcp_opt = dhcp_options_get(ctx, ctx->argv[2], true);
+        error = dhcp_options_get(ctx, ctx->argv[2], true, &dhcp_opt);
+        if (error) {
+            ctl_fatal("%s", error);
+        }
     }
 
     if (dhcp_opt) {
@@ -2696,8 +2703,9 @@ nbctl_lr_list(struct ctl_context *ctx)
     free(nodes);
 }
 
-static const struct nbrec_dhcp_options *
-dhcp_options_get(struct ctl_context *ctx, const char *id, bool must_exist)
+static char *
+dhcp_options_get(struct ctl_context *ctx, const char *id, bool must_exist,
+                 const struct nbrec_dhcp_options **dhcp_opts_p)
 {
     struct uuid dhcp_opts_uuid;
     const struct nbrec_dhcp_options *dhcp_opts = NULL;
@@ -2706,9 +2714,10 @@ dhcp_options_get(struct ctl_context *ctx, const char *id, bool must_exist)
     }
 
     if (!dhcp_opts && must_exist) {
-        ctl_fatal("%s: dhcp options UUID not found", id);
+        return xasprintf("%s: dhcp options UUID not found", id);
     }
-    return dhcp_opts;
+    *dhcp_opts_p = dhcp_opts;
+    return NULL;
 }
 
 static void
@@ -2750,8 +2759,11 @@ nbctl_dhcp_options_create(struct ctl_context *ctx)
 static void
 nbctl_dhcp_options_set_options(struct ctl_context *ctx)
 {
-    const struct nbrec_dhcp_options *dhcp_opts = dhcp_options_get(
-        ctx, ctx->argv[1], true);
+    const struct nbrec_dhcp_options *dhcp_opts;
+    char *error = dhcp_options_get(ctx, ctx->argv[1], true, &dhcp_opts);
+    if (error) {
+        ctl_fatal("%s", error);
+    }
 
     struct smap dhcp_options = SMAP_INITIALIZER(&dhcp_options);
     for (size_t i = 2; i < ctx->argc; i++) {
@@ -2771,8 +2783,11 @@ nbctl_dhcp_options_set_options(struct ctl_context *ctx)
 static void
 nbctl_dhcp_options_get_options(struct ctl_context *ctx)
 {
-    const struct nbrec_dhcp_options *dhcp_opts = dhcp_options_get(
-        ctx, ctx->argv[1], true);
+    const struct nbrec_dhcp_options *dhcp_opts;
+    char *error = dhcp_options_get(ctx, ctx->argv[1], true, &dhcp_opts);
+    if (error) {
+        ctl_fatal("%s", error);
+    }
 
     struct smap_node *node;
     SMAP_FOR_EACH(node, &dhcp_opts->options) {
@@ -2787,7 +2802,10 @@ nbctl_dhcp_options_del(struct ctl_context *ctx)
     const char *id = ctx->argv[1];
     const struct nbrec_dhcp_options *dhcp_opts;
 
-    dhcp_opts = dhcp_options_get(ctx, id, must_exist);
+    char *error = dhcp_options_get(ctx, id, must_exist, &dhcp_opts);
+    if (error) {
+        ctl_fatal("%s", error);
+    }
     if (!dhcp_opts) {
         return;
     }
-- 
2.14.4



More information about the dev mailing list