sessiond: comm: add fd count information for lttng-ctl -> sessiond comm
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 14 Jul 2020 17:00:06 +0000 (13:00 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 10 Aug 2020 21:42:19 +0000 (17:42 -0400)
This allows bulk reception of fds incoming from lttng-ctl before doing
any object deserialization.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I16f054be1d8b8d1e7868784c9b4088750b9a3651

src/bin/lttng-sessiond/cmd.c
src/common/sessiond-comm/sessiond-comm.h
src/lib/lttng-ctl/lttng-ctl.c

index 37c0e31ce9dfe73b9713088c83ed1427f83ad389..1922fd594c6dc519838a359dc9704eab7318ab01 100644 (file)
@@ -4283,6 +4283,20 @@ int cmd_register_trigger(struct command_ctx *cmd_ctx, int sock,
                goto end;
        }
 
+       /* Receive fds, if any. */
+       if (cmd_ctx->lsm.fd_count > 0) {
+               ret = lttcomm_recv_payload_fds_unix_sock(
+                               sock, cmd_ctx->lsm.fd_count, &trigger_payload);
+               if (ret > 0 && ret != cmd_ctx->lsm.fd_count * sizeof(int)) {
+                       ret = LTTNG_ERR_INVALID_PROTOCOL;
+                       goto end;
+               } else if (ret <= 0) {
+                       ret = LTTNG_ERR_FATAL;
+                       goto end;
+               }
+       }
+
+       /* Deserialize trigger. */
        {
                struct lttng_payload_view view =
                                lttng_payload_view_from_payload(
@@ -4333,6 +4347,19 @@ int cmd_unregister_trigger(struct command_ctx *cmd_ctx, int sock,
                goto end;
        }
 
+       /* Receive fds, if any. */
+       if (cmd_ctx->lsm.fd_count > 0) {
+               ret = lttcomm_recv_payload_fds_unix_sock(
+                               sock, cmd_ctx->lsm.fd_count, &trigger_payload);
+               if (ret > 0 && ret != cmd_ctx->lsm.fd_count * sizeof(int)) {
+                       ret = LTTNG_ERR_INVALID_PROTOCOL;
+                       goto end;
+               } else if (ret <= 0) {
+                       ret = LTTNG_ERR_FATAL;
+                       goto end;
+               }
+       }
+
        {
                struct lttng_payload_view view =
                                lttng_payload_view_from_payload(
index d054a8bd05a1f49fef96a1fe8051586a6183bd02..c15a26f889bc83bcd682103abb4ab079622dab18 100644 (file)
@@ -416,6 +416,8 @@ struct lttcomm_session_msg {
                        /* An lttng_session_descriptor follows. */
                } LTTNG_PACKED create_session;
        } u;
+       /* Count of fds sent. */
+       uint32_t fd_count;
 } LTTNG_PACKED;
 
 #define LTTNG_FILTER_MAX_LEN   65536
index 700a83a13eaa022476935a7bd74c6637943d286e..81ddeb74a081c0f14c0979e9647194b9ff2e08df 100644 (file)
@@ -3083,10 +3083,16 @@ end:
 int lttng_register_trigger(struct lttng_trigger *trigger)
 {
        int ret;
-       struct lttcomm_session_msg lsm;
-       struct lttng_payload payload;
+       struct lttcomm_session_msg lsm = {
+               .cmd_type = LTTNG_REGISTER_TRIGGER,
+       };
+       struct lttcomm_session_msg *message_lsm;
+       struct lttng_payload message;
+       struct lttng_payload reply;
+
+       lttng_payload_init(&message);
+       lttng_payload_init(&reply);
 
-       lttng_payload_init(&payload);
        if (!trigger) {
                ret = -LTTNG_ERR_INVALID;
                goto end;
@@ -3097,19 +3103,39 @@ int lttng_register_trigger(struct lttng_trigger *trigger)
                goto end;
        }
 
-       ret = lttng_trigger_serialize(trigger, &payload);
+       lttng_dynamic_buffer_append(&message.buffer, &lsm, sizeof(lsm));
+
+       /*
+        * This is needed to populate the trigger object size for the command
+        * header.
+       */
+       message_lsm = (struct lttcomm_session_msg *) message.buffer.data;
+
+       ret = lttng_trigger_serialize(trigger, &message);
        if (ret < 0) {
                ret = -LTTNG_ERR_UNK;
                goto end;
        }
 
-       memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_REGISTER_TRIGGER;
-       lsm.u.trigger.length = (uint32_t) payload.buffer.size;
-       ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(
-                       &lsm, payload.buffer.data, payload.buffer.size, NULL);
+       message_lsm->u.trigger.length = (uint32_t) message.buffer.size - sizeof(lsm);
+
+       {
+               struct lttng_payload_view message_view =
+                               lttng_payload_view_from_payload(
+                                               &message, 0, -1);
+
+               message_lsm->fd_count = lttng_payload_view_get_fd_handle_count(
+                               &message_view);
+               ret = lttng_ctl_ask_sessiond_payload(&message_view, &reply);
+               if (ret < 0) {
+                       goto end;
+               }
+       }
+
+       ret = 0;
 end:
-       lttng_payload_reset(&payload);
+       lttng_payload_reset(&message);
+       lttng_payload_reset(&reply);
        return ret;
 }
 
@@ -3117,9 +3143,13 @@ int lttng_unregister_trigger(struct lttng_trigger *trigger)
 {
        int ret;
        struct lttcomm_session_msg lsm;
-       struct lttng_payload payload;
+       struct lttcomm_session_msg *message_lsm;
+       struct lttng_payload message;
+       struct lttng_payload reply;
+
+       lttng_payload_init(&message);
+       lttng_payload_init(&reply);
 
-       lttng_payload_init(&payload);
        if (!trigger) {
                ret = -LTTNG_ERR_INVALID;
                goto end;
@@ -3130,19 +3160,47 @@ int lttng_unregister_trigger(struct lttng_trigger *trigger)
                goto end;
        }
 
-       ret = lttng_trigger_serialize(trigger, &payload);
+       memset(&lsm, 0, sizeof(lsm));
+       lsm.cmd_type = LTTNG_UNREGISTER_TRIGGER;
+
+       lttng_dynamic_buffer_append(&message.buffer, &lsm, sizeof(lsm));
+
+       /*
+        * This is needed to populate the trigger object size for the command
+        * header and number of fds sent.
+       */
+       message_lsm = (struct lttcomm_session_msg *) message.buffer.data;
+
+       ret = lttng_trigger_serialize(trigger, &message);
        if (ret < 0) {
                ret = -LTTNG_ERR_UNK;
                goto end;
        }
 
-       memset(&lsm, 0, sizeof(lsm));
-       lsm.cmd_type = LTTNG_UNREGISTER_TRIGGER;
-       lsm.u.trigger.length = (uint32_t) payload.buffer.size;
-       ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(
-                       &lsm, payload.buffer.data, payload.buffer.size, NULL);
+       message_lsm->u.trigger.length = (uint32_t) message.buffer.size - sizeof(lsm);
+
+       {
+               struct lttng_payload_view message_view =
+                               lttng_payload_view_from_payload(
+                                               &message, 0, -1);
+
+               /*
+                * Update the message header with the number of fd that will be
+                * sent.
+                */
+               message_lsm->fd_count = lttng_payload_view_get_fd_handle_count(
+                               &message_view);
+
+               ret = lttng_ctl_ask_sessiond_payload(&message_view, &reply);
+               if (ret < 0) {
+                       goto end;
+               }
+       }
+
+       ret = 0;
 end:
-       lttng_payload_reset(&payload);
+       lttng_payload_reset(&message);
+       lttng_payload_reset(&reply);
        return ret;
 }
 
This page took 0.043858 seconds and 4 git commands to generate.