Initial import of the snapshot ABI/API in lttng-ctl
authorDavid Goulet <dgoulet@efficios.com>
Fri, 12 Apr 2013 19:47:13 +0000 (15:47 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 27 Jun 2013 16:19:02 +0000 (12:19 -0400)
Nothing on the session daemon side as been added except the command
values added to the process client command subsystem.

Signed-off-by: David Goulet <dgoulet@efficios.com>
include/Makefile.am
include/lttng/snapshot-internal.h [new file with mode: 0644]
include/lttng/snapshot.h [new file with mode: 0644]
src/bin/lttng-sessiond/main.c
src/common/defaults.h
src/common/sessiond-comm/sessiond-comm.h
src/lib/lttng-ctl/Makefile.am
src/lib/lttng-ctl/lttng-ctl.c
src/lib/lttng-ctl/snapshot.c [new file with mode: 0644]

index 0bcb6f92ffbb8f8f0deb18fb100e752f497dc289..f3413e6dfa376bed65bdfea3db1a22eb0dabf574 100644 (file)
@@ -1 +1,3 @@
-lttnginclude_HEADERS = lttng/lttng.h lttng/lttng-error.h
+lttnginclude_HEADERS = lttng/lttng.h lttng/lttng-error.h lttng/snapshot.h
+
+noinst_HEADERS = lttng/snapshot-internal.h
diff --git a/include/lttng/snapshot-internal.h b/include/lttng/snapshot-internal.h
new file mode 100644 (file)
index 0000000..a14564b
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LTTNG_SNAPSHOT_INTERNAL_ABI_H
+#define LTTNG_SNAPSHOT_INTERNAL_ABI_H
+
+#include <limits.h>
+#include <stdint.h>
+
+/*
+ * Object used for the snapshot API. This is opaque to the public library.
+ */
+struct lttng_snapshot_output {
+       /*
+        * ID of the snapshot output. This is only used when they are listed. It is
+        * assigned by the session daemon so when adding an output, this value will
+        * not be used.
+        */
+       uint32_t id;
+       /*
+        * Maximum size in bytes of the snapshot meaning the total size of all
+        * stream combined. A value of 0 is unlimited.
+        */
+       uint64_t max_size;
+       /* Name of the output so it can be recognized easily when listing them. */
+       char name[NAME_MAX];
+       /* Destination of the output. See lttng(1) for URL format. */
+       char ctrl_url[PATH_MAX];
+       /* Destination of the output. See lttng(1) for URL format. */
+       char data_url[PATH_MAX];
+};
+
+/*
+ * Snapshot output list object opaque to the user.
+ */
+struct lttng_snapshot_output_list {
+       /*
+        * The position in the output array. This is changed by a get_next call.
+        */
+       int index;
+
+       /*
+        * Number of element in the array.
+        */
+       size_t count;
+
+       /*
+        * Containes snapshot output object.
+        */
+       struct lttng_snapshot_output *array;
+};
+
+#endif /* LTTNG_SNAPSHOT_INTERNAL_ABI_H */
diff --git a/include/lttng/snapshot.h b/include/lttng/snapshot.h
new file mode 100644 (file)
index 0000000..8f5ee89
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LTTNG_SNAPSHOT_H
+#define LTTNG_SNAPSHOT_H
+
+#include <limits.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Snapshot output object is opaque to the user. Use the helper functions below
+ * to use them.
+ */
+struct lttng_snapshot_output;
+struct lttng_snapshot_output_list;
+
+/*
+ * Return an newly allocated snapshot output object or NULL on error.
+ */
+struct lttng_snapshot_output *lttng_snapshot_output_create(void);
+
+/*
+ * Free a given snapshot output object.
+ */
+void lttng_snapshot_output_destroy(struct lttng_snapshot_output *output);
+
+/*
+ * Snapshot output getter family functions. They all return the value present
+ * in the object.
+ */
+
+/* Return snapshot ID. */
+uint32_t lttng_snapshot_output_get_id(struct lttng_snapshot_output *output);
+/* Return maximum size of a snapshot. */
+uint64_t lttng_snapshot_output_get_maxsize(struct lttng_snapshot_output *output);
+/* Return snapshot name. */
+const char *lttng_snapshot_output_get_name(struct lttng_snapshot_output *output);
+/* Return snapshot control URL in a text format. */
+const char *lttng_snapshot_output_get_ctrl_url(struct lttng_snapshot_output *output);
+/* Return snapshot data URL in a text format. */
+const char *lttng_snapshot_output_get_data_url(struct lttng_snapshot_output *output);
+
+/*
+ * Snapshot output setter family functions.
+ *
+ * For every set* call, 0 is returned on success or else LTTNG_ERR_INVALID is
+ * returned indicating that at least one given parameter is invalid.
+ */
+
+/* Set a custom ID. */
+int lttng_snapshot_output_set_id(uint32_t id,
+               struct lttng_snapshot_output *output);
+/* Set the maximum size. */
+int lttng_snapshot_output_set_size(uint64_t size,
+               struct lttng_snapshot_output *output);
+/* Set the snapshot name. */
+int lttng_snapshot_output_set_name(const char *name,
+               struct lttng_snapshot_output *output);
+/* Set the control URL. Local and remote URL are supported. */
+int lttng_snapshot_output_set_ctrl_url(const char *url,
+               struct lttng_snapshot_output *output);
+/* Set the data URL. Local and remote URL are supported. */
+int lttng_snapshot_output_set_data_url(const char *url,
+               struct lttng_snapshot_output *output);
+
+/*
+ * Add an output object to a session identified by name.
+ *
+ * Return 0 on success or else a negative LTTNG_ERR code.
+ */
+int lttng_snapshot_add_output(const char *session_name,
+               struct lttng_snapshot_output *output);
+
+/*
+ * Delete an output object to a session identified by name.
+ *
+ * Return 0 on success or else a negative LTTNG_ERR code.
+ */
+int lttng_snapshot_del_output(const char *session_name,
+               struct lttng_snapshot_output *output);
+
+/*
+ * List all snapshot output(s) of a session identified by name. The output list
+ * object is populated and can be iterated over with the get_next call below.
+ *
+ * Return 0 on success or else a negative LTTNG_ERR code and the list pointer
+ * is untouched.
+ */
+int lttng_snapshot_list_output(const char *session_name,
+               struct lttng_snapshot_output_list **list);
+
+/*
+ * Return the next available snapshot output object in the given list. A list
+ * output command MUST have been done before.
+ *
+ * Return the next object on success or else NULL indicating the end of the
+ * list.
+ */
+struct lttng_snapshot_output *lttng_snapshot_output_list_get_next(
+               struct lttng_snapshot_output_list *list);
+
+/*
+ * Free an output list object.
+ */
+void lttng_snapshot_output_list_destroy(struct lttng_snapshot_output_list *list);
+
+/*
+ * Snapshot a trace for the given session.
+ *
+ * The output object can be NULL but an add output MUST be done prior to this
+ * call. If it's not NULL, it will be used to snapshot a trace.
+ *
+ * The wait parameter is ignored for now. The snapshot record command will
+ * ALWAYS wait for the snapshot to complete before returning meaning the
+ * snapshot has been written on disk or streamed over the network to a relayd.
+ *
+ * Return 0 on success or else a negative LTTNG_ERR value.
+ */
+int lttng_snapshot_record(const char *session_name,
+               struct lttng_snapshot_output *output, int wait);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LTTNG_SNAPSHOT_H */
index f5a4db4dcb9830e98adc72ec8cd268bf6e7f3795..31f48a2739fb0216ef9645ca4bb4a51162244ed6 100644 (file)
@@ -2494,6 +2494,10 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
        case LTTNG_START_TRACE:
        case LTTNG_STOP_TRACE:
        case LTTNG_DATA_PENDING:
+       case LTTNG_SNAPSHOT_ADD_OUTPUT:
+       case LTTNG_SNAPSHOT_DEL_OUTPUT:
+       case LTTNG_SNAPSHOT_LIST_OUTPUT:
+       case LTTNG_SNAPSHOT_RECORD:
                need_domain = 0;
                break;
        default:
@@ -3176,6 +3180,26 @@ skip_domain:
                ret = cmd_data_pending(cmd_ctx->session);
                break;
        }
+       case LTTNG_SNAPSHOT_ADD_OUTPUT:
+       {
+               ret = LTTNG_ERR_UND;
+               break;
+       }
+       case LTTNG_SNAPSHOT_DEL_OUTPUT:
+       {
+               ret = LTTNG_ERR_UND;
+               break;
+       }
+       case LTTNG_SNAPSHOT_LIST_OUTPUT:
+       {
+               ret = LTTNG_ERR_UND;
+               break;
+       }
+       case LTTNG_SNAPSHOT_RECORD:
+       {
+               ret = LTTNG_ERR_UND;
+               break;
+       }
        default:
                ret = LTTNG_ERR_UND;
                break;
index c040634880516231af7be0463e9ba650ff3b82db..388b9f0d78348b54ed97889139b69a720d2ebb7e 100644 (file)
 
 #define DEFAULT_UST_STREAM_FD_NUM                      2 /* Number of fd per UST stream. */
 
+#define DEFAULT_SNAPSHOT_NAME                          "snapshot"
+
 extern size_t default_channel_subbuf_size;
 extern size_t default_metadata_subbuf_size;
 extern size_t default_ust_pid_channel_subbuf_size;
index c0b89a1232dfebd5e5f6b09da3c82ee186bfca6d..aeca78e50b9d2b3efb998028ab8e49225d0e4ecc 100644 (file)
@@ -28,6 +28,7 @@
 #define _GNU_SOURCE
 #include <limits.h>
 #include <lttng/lttng.h>
+#include <lttng/snapshot-internal.h>
 #include <common/compat/socket.h>
 #include <common/uri.h>
 #include <common/defaults.h>
@@ -82,6 +83,10 @@ enum lttcomm_sessiond_command {
        LTTNG_ENABLE_EVENT_WITH_FILTER      = 22,
        LTTNG_HEALTH_CHECK                  = 23,
        LTTNG_DATA_PENDING                  = 24,
+       LTTNG_SNAPSHOT_ADD_OUTPUT           = 25,
+       LTTNG_SNAPSHOT_DEL_OUTPUT           = 26,
+       LTTNG_SNAPSHOT_LIST_OUTPUT          = 27,
+       LTTNG_SNAPSHOT_RECORD               = 28,
 };
 
 enum lttcomm_relayd_command {
@@ -240,6 +245,13 @@ struct lttcomm_session_msg {
                        /* Number of lttng_uri following */
                        uint32_t size;
                } LTTNG_PACKED uri;
+               struct {
+                       struct lttng_snapshot_output output;
+               } LTTNG_PACKED snapshot_output;
+               struct {
+                       uint32_t wait;
+                       struct lttng_snapshot_output output;
+               } LTTNG_PACKED snapshot_record;
        } u;
 } LTTNG_PACKED;
 
@@ -271,6 +283,10 @@ struct lttcomm_lttng_msg {
        char payload[];
 } LTTNG_PACKED;
 
+struct lttcomm_lttng_output_id {
+       uint32_t id;
+} LTTNG_PACKED;
+
 struct lttcomm_health_msg {
        uint32_t component;
        uint32_t cmd;
index 542f4bbcf19f95dae67ab25176b93df6a9ff11d5..2178ed32f4728c61aedd98a131da6f73fdd9a12f 100644 (file)
@@ -4,7 +4,7 @@ SUBDIRS = filter
 
 lib_LTLIBRARIES = liblttng-ctl.la
 
-liblttng_ctl_la_SOURCES = lttng-ctl.c
+liblttng_ctl_la_SOURCES = lttng-ctl.c snapshot.c
 
 liblttng_ctl_la_LIBADD = \
                $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \
index afd55a1abf882e41ce6acb8bbceaec46ff77fe2e..c9693f711f5140f26f63c2b34fa99bb578ca321c 100644 (file)
@@ -340,6 +340,11 @@ static int connect_sessiond(void)
 {
        int ret;
 
+       /* Don't try to connect if already connected. */
+       if (connected) {
+               return 0;
+       }
+
        ret = set_session_daemon_path();
        if (ret < 0) {
                goto error;
diff --git a/src/lib/lttng-ctl/snapshot.c b/src/lib/lttng-ctl/snapshot.c
new file mode 100644 (file)
index 0000000..9dc2c67
--- /dev/null
@@ -0,0 +1,325 @@
+/*
+ * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define _GNU_SOURCE
+#include <assert.h>
+#include <string.h>
+
+#include <common/sessiond-comm/sessiond-comm.h>
+#include <lttng/lttng-error.h>
+#include <lttng/snapshot.h>
+#include <lttng/snapshot-internal.h>
+
+#include "lttng-ctl-helper.h"
+
+/*
+ * Add an output object to a session identified by name.
+ *
+ * Return 0 on success or else a negative LTTNG_ERR code.
+ */
+int lttng_snapshot_add_output(const char *session_name,
+               struct lttng_snapshot_output *output)
+{
+       int ret;
+       struct lttcomm_session_msg lsm;
+       struct lttcomm_lttng_output_id *reply;
+
+       if (!session_name || !output) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       memset(&lsm, 0, sizeof(lsm));
+       lsm.cmd_type = LTTNG_SNAPSHOT_ADD_OUTPUT;
+
+       lttng_ctl_copy_string(lsm.session.name, session_name,
+                       sizeof(lsm.session.name));
+       memcpy(&lsm.u.snapshot_output.output, output,
+                       sizeof(lsm.u.snapshot_output.output));
+
+       ret = lttng_ctl_ask_sessiond(&lsm, (void **) &reply);
+       if (ret < 0) {
+               return ret;
+       }
+
+       output->id = reply->id;
+       free(reply);
+
+       return 0;
+}
+
+/*
+ * Delete an output object to a session identified by name.
+ *
+ * Return 0 on success or else a negative LTTNG_ERR code.
+ */
+int lttng_snapshot_del_output(const char *session_name,
+               struct lttng_snapshot_output *output)
+{
+       struct lttcomm_session_msg lsm;
+
+       if (!session_name || !output) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       memset(&lsm, 0, sizeof(lsm));
+       lsm.cmd_type = LTTNG_SNAPSHOT_DEL_OUTPUT;
+
+       lttng_ctl_copy_string(lsm.session.name, session_name,
+                       sizeof(lsm.session.name));
+       memcpy(&lsm.u.snapshot_output.output, output,
+                       sizeof(lsm.u.snapshot_output.output));
+
+       return lttng_ctl_ask_sessiond(&lsm, NULL);
+}
+
+/*
+ * List all snapshot output(s) of a session identified by name. The output list
+ * object is populated and can be iterated over with the get_next call below.
+ *
+ * Return 0 on success or else a negative LTTNG_ERR code and the list pointer
+ * is untouched.
+ */
+int lttng_snapshot_list_output(const char *session_name,
+               struct lttng_snapshot_output_list **list)
+{
+       int ret;
+       struct lttcomm_session_msg lsm;
+       struct lttng_snapshot_output_list *new_list = NULL;
+
+       if (!session_name || !list) {
+               ret = -LTTNG_ERR_INVALID;
+               goto error;
+       }
+
+       memset(&lsm, 0, sizeof(lsm));
+       lsm.cmd_type = LTTNG_SNAPSHOT_LIST_OUTPUT;
+
+       lttng_ctl_copy_string(lsm.session.name, session_name,
+                       sizeof(lsm.session.name));
+
+       new_list = zmalloc(sizeof(*new_list));
+       if (!new_list) {
+               ret = -LTTNG_ERR_NOMEM;
+               goto error;
+       }
+
+       ret = lttng_ctl_ask_sessiond(&lsm, (void **) &new_list->array);
+       if (ret < 0) {
+               goto free_error;
+       }
+
+       new_list->count = ret / sizeof(struct lttng_snapshot_output);
+       *list = new_list;
+       return 0;
+
+free_error:
+       free(new_list);
+error:
+       return ret;
+}
+
+/*
+ * Return the next available snapshot output object in the given list. A list
+ * output command MUST have been done before.
+ *
+ * Return the next object on success or else NULL indicating the end of the
+ * list.
+ */
+struct lttng_snapshot_output *lttng_snapshot_output_list_get_next(
+               struct lttng_snapshot_output_list *list)
+{
+       struct lttng_snapshot_output *output = NULL;
+
+       if (!list) {
+               goto error;
+       }
+
+       /* We've reached the end. */
+       if (list->index == list->count) {
+               goto end;
+       }
+
+       output = &list->array[list->index];
+       list->index++;
+
+end:
+error:
+       return output;
+}
+
+/*
+ * Free an output list object.
+ */
+void lttng_snapshot_output_list_destroy(struct lttng_snapshot_output_list *list)
+{
+       if (!list) {
+               return;
+       }
+
+       free(list->array);
+       free(list);
+}
+
+/*
+ * Snapshot a trace for the given session.
+ *
+ * The output object can be NULL but an add output MUST be done prior to this
+ * call. If it's not NULL, it will be used to snapshot a trace.
+ *
+ * The wait parameter is ignored for now. The snapshot record command will
+ * ALWAYS wait for the snapshot to complete before returning meaning the
+ * snapshot has been written on disk or streamed over the network to a relayd.
+ *
+ * Return 0 on success or else a negative LTTNG_ERR value.
+ */
+int lttng_snapshot_record(const char *session_name,
+               struct lttng_snapshot_output *output, int wait)
+{
+       struct lttcomm_session_msg lsm;
+
+       if (!session_name) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       memset(&lsm, 0, sizeof(lsm));
+       lsm.cmd_type = LTTNG_SNAPSHOT_RECORD;
+
+       lttng_ctl_copy_string(lsm.session.name, session_name,
+                       sizeof(lsm.session.name));
+
+       /*
+        * Not having an output object will use the default one of the session that
+        * would need to be set by a call to add output prior to calling snapshot
+        * record.
+        */
+       if (output) {
+               memcpy(&lsm.u.snapshot_record.output, output,
+                               sizeof(lsm.u.snapshot_record.output));
+       }
+
+       /* The wait param is ignored. */
+
+       return lttng_ctl_ask_sessiond(&lsm, NULL);
+}
+
+/*
+ * Return an newly allocated snapshot output object or NULL on error.
+ */
+struct lttng_snapshot_output *lttng_snapshot_output_create(void)
+{
+       return zmalloc(sizeof(struct lttng_snapshot_output));
+}
+
+/*
+ * Free a given snapshot output object.
+ */
+void lttng_snapshot_output_destroy(struct lttng_snapshot_output *obj)
+{
+       if (obj) {
+               free(obj);
+       }
+}
+
+/*
+ * Getter family functions of snapshot output.
+ */
+
+uint32_t lttng_snapshot_output_get_id(struct lttng_snapshot_output *output)
+{
+       return output->id;
+}
+
+const char *lttng_snapshot_output_get_name(
+               struct lttng_snapshot_output *output)
+{
+       return output->name;
+}
+
+const char *lttng_snapshot_output_get_data_url(struct lttng_snapshot_output *output)
+{
+       return output->data_url;
+}
+
+const char *lttng_snapshot_output_get_ctrl_url(struct lttng_snapshot_output *output)
+{
+       return output->ctrl_url;
+}
+
+uint64_t lttng_snapshot_output_get_maxsize(
+               struct lttng_snapshot_output *output)
+{
+       return output->max_size;
+}
+
+/*
+ * Setter family functions for snapshot output.
+ */
+
+int lttng_snapshot_output_set_id(uint32_t id,
+               struct lttng_snapshot_output *output)
+{
+       if (!output || id == 0) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       output->id = id;
+       return 0;
+}
+
+int lttng_snapshot_output_set_size(uint64_t size,
+               struct lttng_snapshot_output *output)
+{
+       if (!output) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       output->max_size = size;
+       return 0;
+}
+
+int lttng_snapshot_output_set_name(const char *name,
+               struct lttng_snapshot_output *output)
+{
+       if (!output || !name) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       lttng_ctl_copy_string(output->name, name, sizeof(output->name));
+       return 0;
+}
+
+int lttng_snapshot_output_set_ctrl_url(const char *url,
+               struct lttng_snapshot_output *output)
+{
+       if (!output || !url) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       lttng_ctl_copy_string(output->ctrl_url, url, sizeof(output->ctrl_url));
+       return 0;
+}
+
+int lttng_snapshot_output_set_data_url(const char *url,
+               struct lttng_snapshot_output *output)
+{
+       if (!output || !url) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       lttng_ctl_copy_string(output->data_url, url, sizeof(output->data_url));
+       return 0;
+}
This page took 0.032743 seconds and 4 git commands to generate.