X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fconsumer.c;h=31f70434534cf56b3fd173242c1e5f3831e8c367;hb=a1ae2ea59428174575b7328b1062a6248d636b72;hp=126b01a448c062e35095ddb97fd1eaf37e5dabb2;hpb=9d1103e6d180b0326ea55759b27ffc0391075e32;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 126b01a44..31f704345 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -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; @@ -731,6 +732,8 @@ error: /* * Send file descriptor to consumer via sock. + * + * The consumer socket lock must be held by the caller. */ int consumer_send_fds(struct consumer_socket *sock, int *fds, size_t nb_fd) { @@ -755,6 +758,8 @@ error: /* * Consumer send communication message structure to consumer. + * + * The consumer socket lock must be held by the caller. */ int consumer_send_msg(struct consumer_socket *sock, struct lttcomm_consumer_msg *msg) @@ -778,6 +783,8 @@ error: /* * Consumer send channel communication message structure to consumer. + * + * The consumer socket lock must be held by the caller. */ int consumer_send_channel(struct consumer_socket *sock, struct lttcomm_consumer_msg *msg) @@ -1411,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; @@ -1421,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; @@ -1567,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; +}