Support del-output with an output name
authorDavid Goulet <dgoulet@efficios.com>
Thu, 11 Jul 2013 20:57:53 +0000 (16:57 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 12 Jul 2013 15:18:28 +0000 (11:18 -0400)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/snapshot.c
src/bin/lttng-sessiond/snapshot.h
src/bin/lttng/commands/snapshot.c

index 850bac508fb4972793c5991050d5c39f56a3f9fd..b2faa41b114177082d49e41570f43d47384f098f 100644 (file)
@@ -2279,14 +2279,11 @@ int cmd_snapshot_del_output(struct ltt_session *session,
                struct lttng_snapshot_output *output)
 {
        int ret;
-       struct snapshot_output *sout;
+       struct snapshot_output *sout = NULL;
 
        assert(session);
        assert(output);
 
-       DBG("Cmd snapshot del output id %" PRIu32 " for session %s", output->id,
-                       session->name);
-
        rcu_read_lock();
 
        /*
@@ -2298,7 +2295,15 @@ int cmd_snapshot_del_output(struct ltt_session *session,
                goto error;
        }
 
-       sout = snapshot_find_output_by_id(output->id, &session->snapshot);
+       if (output->id) {
+               DBG("Cmd snapshot del output id %" PRIu32 " for session %s", output->id,
+                               session->name);
+               sout = snapshot_find_output_by_id(output->id, &session->snapshot);
+       } else if (*output->name != '\0') {
+               DBG("Cmd snapshot del output name %s for session %s", output->name,
+                               session->name);
+               sout = snapshot_find_output_by_name(output->name, &session->snapshot);
+       }
        if (!sout) {
                ret = LTTNG_ERR_INVALID;
                goto error;
index d2fc8ca691a15de1455dbb5cb3019f41cd756b09..4c23ee424292176032da37d2a57fa9cd21e3ec5e 100644 (file)
@@ -222,6 +222,32 @@ void snapshot_output_destroy(struct snapshot_output *obj)
        free(obj);
 }
 
+/*
+ * RCU read side lock MUST be acquired before calling this since the returned
+ * pointer is in a RCU hash table.
+ *
+ * Return the reference on success or else NULL.
+ */
+struct snapshot_output *snapshot_find_output_by_name(const char *name,
+               struct snapshot *snapshot)
+{
+       struct lttng_ht_iter iter;
+       struct snapshot_output *output = NULL;
+
+       assert(snapshot);
+       assert(name);
+
+       cds_lfht_for_each_entry(snapshot->output_ht->ht, &iter.iter, output,
+               node.node) {
+               if (!strncmp(output->name, name, strlen(name))) {
+                       return output;
+               }
+       }
+
+       /* Not found */
+       return NULL;
+}
+
 /*
  * RCU read side lock MUST be acquired before calling this since the returned
  * pointer is in a RCU hash table.
index 44d2ae7f5ba283039f9d9cb4ea9933834ad17af0..a505128a6e03bf9f2471419cc0fa052c18b408fd 100644 (file)
@@ -75,5 +75,7 @@ int snapshot_output_init_with_uri(uint64_t max_size, const char *name,
                struct snapshot *snapshot);
 struct snapshot_output *snapshot_find_output_by_id(uint32_t id,
                struct snapshot *snapshot);
+struct snapshot_output *snapshot_find_output_by_name(const char *name,
+               struct snapshot *snapshot);
 
 #endif /* SNAPSHOT_H */
index be28511b33f65c5a5cc39710b7c755432aacb6a7..f58d9516b18c4603bff9f9ddd0d586b953c44bba 100644 (file)
@@ -211,7 +211,7 @@ error:
 /*
  * Delete output by ID.
  */
-static int del_output(uint32_t id)
+static int del_output(uint32_t id, const char *name)
 {
        int ret;
        struct lttng_snapshot_output *output = NULL;
@@ -222,7 +222,14 @@ static int del_output(uint32_t id)
                goto error;
        }
 
-       ret = lttng_snapshot_output_set_id(id, output);
+       if (name) {
+               ret = lttng_snapshot_output_set_name(name, output);
+       } else if (id != UINT32_MAX) {
+               ret = lttng_snapshot_output_set_id(id, output);
+       } else {
+               ret = CMD_ERROR;
+               goto error;
+       }
        if (ret < 0) {
                ret = CMD_FATAL;
                goto error;
@@ -233,8 +240,13 @@ static int del_output(uint32_t id)
                goto error;
        }
 
-       MSG("Snapshot output id %" PRIu32 " successfully deleted for session %s",
-                       id, current_session_name);
+       if (id != UINT32_MAX) {
+               MSG("Snapshot output id %" PRIu32 " successfully deleted for session %s",
+                               id, current_session_name);
+       } else {
+               MSG("Snapshot output %s successfully deleted for session %s",
+                               name, current_session_name);
+       }
 
 error:
        lttng_snapshot_output_destroy(output);
@@ -297,6 +309,8 @@ end:
 static int cmd_del_output(int argc, const char **argv)
 {
        int ret = CMD_SUCCESS;
+       char *name;
+       long id;
 
        if (argc < 2) {
                usage(stderr);
@@ -304,7 +318,17 @@ static int cmd_del_output(int argc, const char **argv)
                goto end;
        }
 
-       ret = del_output(atoi(argv[1]));
+       errno = 0;
+       id = strtol(argv[1], &name, 10);
+       if (id == 0 && errno == 0) {
+               ret = del_output(UINT32_MAX, name);
+       } else if (errno == 0 && *name == '\0') {
+               ret = del_output(id, NULL);
+       } else {
+               ERR("Argument %s not recognized", argv[1]);
+               ret = -1;
+               goto end;
+       }
 
 end:
        return ret;
This page took 0.030067 seconds and 5 git commands to generate.