consumerd: Implement clear stream/session commands
[lttng-tools.git] / src / common / relayd / relayd.c
index 2adcbe415c63f16a176dba9167c247f34eb0eba3..9f0cf1e3e56e74038ecc4c61f99e1e9cdbed7431 100644 (file)
@@ -72,14 +72,14 @@ static int send_command(struct lttcomm_relayd_sock *rsock,
                memcpy(buf + sizeof(header), data, size);
        }
 
+       DBG3("Relayd sending command %d of size %" PRIu64, (int) cmd, buf_size);
        ret = rsock->sock.ops->sendmsg(&rsock->sock, buf, buf_size, flags);
        if (ret < 0) {
+               PERROR("Failed to send command %d of size %" PRIu64,
+                               (int) cmd, buf_size);
                ret = -errno;
                goto error;
        }
-
-       DBG3("Relayd sending command %d of size %" PRIu64, cmd, buf_size);
-
 error:
        free(buf);
 alloc_error:
@@ -378,7 +378,8 @@ end:
  * If major versions are compatible, we assign minor_to_use to the
  * minor version of the procotol we are going to use for this session.
  *
- * Return 0 if compatible else negative value.
+ * Return 0 if the two daemons are compatible, LTTNG_ERR_RELAYD_VERSION_FAIL
+ * otherwise, or a negative value on network errors.
  */
 int relayd_version_check(struct lttcomm_relayd_sock *rsock)
 {
@@ -420,7 +421,7 @@ int relayd_version_check(struct lttcomm_relayd_sock *rsock)
         */
        if (msg.major != rsock->major) {
                /* Not compatible */
-               ret = -1;
+               ret = LTTNG_ERR_RELAYD_VERSION_FAIL;
                DBG2("Relayd version is NOT compatible. Relayd version %u != %u (us)",
                                msg.major, rsock->major);
                goto error;
@@ -940,3 +941,45 @@ int relayd_reset_metadata(struct lttcomm_relayd_sock *rsock,
 error:
        return ret;
 }
+
+/*
+ * Ask the relay to clear files associated with the socket session.
+ */
+int relayd_clear_session(struct lttcomm_relayd_sock *rsock)
+{
+       int ret;
+       struct lttcomm_relayd_generic_reply reply;
+
+       /* Code flow error. Safety net. */
+       assert(rsock);
+
+       DBG("Relayd clear session");
+
+       /* Send command */
+       ret = send_command(rsock, RELAYD_CLEAR_SESSION_CUSTOM_EFFICIOS, NULL, 0, 0);
+       if (ret < 0) {
+               goto error;
+       }
+
+       /* Receive response */
+       ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
+       if (ret < 0) {
+               goto error;
+       }
+
+       reply.ret_code = be32toh(reply.ret_code);
+
+       /* Return session id or negative ret code. */
+       if (reply.ret_code != LTTNG_OK) {
+               ret = -1;
+               ERR("Relayd clear session replied error %d", reply.ret_code);
+       } else {
+               /* Success */
+               ret = 0;
+       }
+
+       DBG("Relayd clear session successful");
+
+error:
+       return ret;
+}
This page took 0.025333 seconds and 5 git commands to generate.