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

Jakub Sitnicki jkbs at redhat.com
Tue Jul 17 13:34:10 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 | 39 ++++++++++++++++++++++++++++++---------
 1 file changed, 30 insertions(+), 9 deletions(-)

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 1cee059f2..c18fa2825 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -1671,17 +1671,19 @@ qos_cmp(const void *qos1_, const void *qos2_)
     }
 }
 
-static const char *
-parse_direction(const char *arg)
+static char * OVS_WARN_UNUSED_RESULT
+parse_direction(const char *arg, const char **direction_p)
 {
     /* Validate direction.  Only require the first letter. */
     if (arg[0] == 't') {
-        return "to-lport";
+        *direction_p = "to-lport";
     } else if (arg[0] == 'f') {
-        return "from-lport";
+        *direction_p = "from-lport";
     } else {
-        ctl_fatal("%s: direction must be \"to-lport\" or \"from-lport\"", arg);
+        return xasprintf("%s: direction must be \"to-lport\" or "
+                         "\"from-lport\"", arg);
     }
+    return NULL;
 }
 
 static char * OVS_WARN_UNUSED_RESULT
@@ -1710,7 +1712,12 @@ nbctl_acl_add(struct ctl_context *ctx)
         return;
     }
 
-    const char *direction = parse_direction(ctx->argv[2]);
+    const char *direction;
+    error = parse_direction(ctx->argv[2], &direction);
+    if (error) {
+        ctx->error = error;
+        return;
+    }
     int64_t priority;
     error = parse_priority(ctx->argv[3], &priority);
     if (error) {
@@ -1804,7 +1811,11 @@ nbctl_acl_del(struct ctl_context *ctx)
         return;
     }
 
-    const char *direction = parse_direction(ctx->argv[2]);
+    const char *direction;
+    error = parse_direction(ctx->argv[2], &direction);
+    if (error) {
+        ctl_fatal("%s", error);
+    }
 
     size_t n_acls = pg ? pg->n_acls : ls->n_acls;
     struct nbrec_acl **acls = pg ? pg->acls : ls->acls;
@@ -1917,13 +1928,18 @@ static void
 nbctl_qos_add(struct ctl_context *ctx)
 {
     const struct nbrec_logical_switch *ls;
-    const char *direction = parse_direction(ctx->argv[2]);
+    const char *direction;
     int64_t priority;
     int64_t dscp = -1;
     int64_t rate = 0;
     int64_t burst = 0;
     char *error;
 
+    error = parse_direction(ctx->argv[2], &direction);
+    if (error) {
+        ctx->error = error;
+        return;
+    }
     error = parse_priority(ctx->argv[3], &priority);
     if (error) {
         ctx->error = error;
@@ -2034,7 +2050,12 @@ nbctl_qos_del(struct ctl_context *ctx)
         return;
     }
 
-    const char *direction = parse_direction(ctx->argv[2]);
+    const char *direction;
+    error = parse_direction(ctx->argv[2], &direction);
+    if (error) {
+        ctx->error = error;
+        return;
+    }
 
     /* If priority and match are not specified, delete all qos_rules with the
      * specified direction. */
-- 
2.14.4



More information about the dev mailing list