Command to make a directory on the consumer or relay
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.c
index 5cbd42f6301d327abefdb159541dc7f651983e9d..31f70434534cf56b3fd173242c1e5f3831e8c367 100644 (file)
@@ -561,7 +561,7 @@ struct consumer_output *consumer_copy_output(struct consumer_output *obj)
        }
        output->enabled = obj->enabled;
        output->net_seq_index = obj->net_seq_index;
-       memcpy(output->subdir, obj->subdir, PATH_MAX);
+       memcpy(output->subdir, obj->subdir, sizeof(output->subdir));
        output->snapshot = obj->snapshot;
        output->relay_major_version = obj->relay_major_version;
        output->relay_minor_version = obj->relay_minor_version;
@@ -715,11 +715,12 @@ int consumer_set_network_uri(struct consumer_output *obj,
                        goto error;
                }
 
-               if (lttng_strncpy(obj->subdir, tmp_path, sizeof(obj->subdir))) {
+               if (lttng_strncpy(obj->dst.net.base_dir, tmp_path,
+                               sizeof(obj->dst.net.base_dir))) {
                        ret = -LTTNG_ERR_INVALID;
                        goto error;
                }
-               DBG3("Consumer set network uri subdir path %s", tmp_path);
+               DBG3("Consumer set network uri base_dir path %s", tmp_path);
        }
 
        return 0;
@@ -1417,8 +1418,11 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key,
                msg.u.snapshot_channel.use_relayd = 1;
                ret = snprintf(msg.u.snapshot_channel.pathname,
                                sizeof(msg.u.snapshot_channel.pathname),
-                               "%s/%s-%s-%" PRIu64 "%s", output->consumer->subdir,
-                               output->name, output->datetime, output->nb_snapshot,
+                               "%s/%s/%s-%s-%" PRIu64 "%s",
+                               output->consumer->dst.net.base_dir,
+                               output->consumer->subdir,
+                               output->name, output->datetime,
+                               output->nb_snapshot,
                                session_path);
                if (ret < 0) {
                        ret = -LTTNG_ERR_NOMEM;
@@ -1427,8 +1431,10 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key,
        } else {
                ret = snprintf(msg.u.snapshot_channel.pathname,
                                sizeof(msg.u.snapshot_channel.pathname),
-                               "%s/%s-%s-%" PRIu64 "%s", output->consumer->dst.trace_path,
-                               output->name, output->datetime, output->nb_snapshot,
+                               "%s/%s-%s-%" PRIu64 "%s",
+                               output->consumer->dst.session_root_path,
+                               output->name, output->datetime,
+                               output->nb_snapshot,
                                session_path);
                if (ret < 0) {
                        ret = -LTTNG_ERR_NOMEM;
@@ -1573,3 +1579,48 @@ end:
        rcu_read_unlock();
        return ret;
 }
+
+/*
+ * Ask the consumer to create a directory.
+ *
+ * Called with the consumer socket lock held.
+ */
+int consumer_mkdir(struct consumer_socket *socket, uint64_t session_id,
+               const struct consumer_output *output, const char *path,
+               uid_t uid, gid_t gid)
+{
+       int ret;
+       struct lttcomm_consumer_msg msg;
+
+       assert(socket);
+
+       DBG("Consumer mkdir %s in session %" PRIu64, path, session_id);
+
+       memset(&msg, 0, sizeof(msg));
+       msg.cmd_type = LTTNG_CONSUMER_MKDIR;
+       msg.u.mkdir.session_id = session_id;
+       msg.u.mkdir.uid = uid;
+       msg.u.mkdir.gid = gid;
+       ret = snprintf(msg.u.mkdir.path, sizeof(msg.u.mkdir.path), "%s", path);
+       if (ret < 0 || ret >= sizeof(msg.u.mkdir.path)) {
+               ERR("Format path");
+               ret = -1;
+               goto error;
+       }
+
+       if (output->type == CONSUMER_DST_NET) {
+               msg.u.mkdir.relayd_id = output->net_seq_index;
+       } else {
+               msg.u.mkdir.relayd_id = (uint64_t) -1ULL;
+       }
+
+       health_code_update();
+       ret = consumer_send_msg(socket, &msg);
+       if (ret < 0) {
+               goto error;
+       }
+
+error:
+       health_code_update();
+       return ret;
+}
This page took 0.027055 seconds and 5 git commands to generate.