Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: jdesfossez@efficios.com (Julien Desfossez)
Subject: [lttng-dev] [LTTNG-TOOLS PATCH v2 1/2] Command to detach a live viewer session
Date: Thu, 30 Jul 2015 11:52:33 -0400	[thread overview]
Message-ID: <1438271554-30895-1-git-send-email-jdesfossez@efficios.com> (raw)

The LTTNG_VIEWER_DETACH_SESSION command allows the viewer to detach from
the session it is currently attached to without requiring it to close
the network connection. This allows the relayd to release its reference
on the session and eventually clear it if it is destroyed on the
consumer.

Fixes: #853

Signed-off-by: Julien Desfossez <jdesfossez at efficios.com>
---
 src/bin/lttng-relayd/live.c             | 73 +++++++++++++++++++++++++++++++++
 src/bin/lttng-relayd/lttng-viewer-abi.h | 18 ++++++++
 2 files changed, 91 insertions(+)

diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c
index 562a7fa..221ec43 100644
--- a/src/bin/lttng-relayd/live.c
+++ b/src/bin/lttng-relayd/live.c
@@ -1733,6 +1733,76 @@ end:
 	return ret;
 }
 
+/*
+ * Detach a viewer session.
+ *
+ * Return 0 on success or else a negative value.
+ */
+static
+int viewer_detach_session(struct relay_connection *conn)
+{
+	int ret, found;
+	struct lttng_viewer_detach_session_response resp;
+	struct lttng_viewer_detach_session_request request;
+	struct relay_session *session, *tmp_session;
+	uint64_t to_close;
+
+	DBG("Viewer detach session received");
+
+	assert(conn);
+
+	health_code_update();
+
+	/* Receive the request from the connected client. */
+	ret = recv_request(conn->sock, &request, sizeof(request));
+	if (ret < 0) {
+		goto end;
+	}
+	to_close = be64toh(request.session_id);
+
+	if (!conn->viewer_session) {
+		resp.status = htobe32(LTTNG_VIEWER_DETACH_SESSION_ERR);
+		goto send_reply;
+	}
+
+	health_code_update();
+
+	memset(&resp, 0, sizeof(resp));
+	DBG("Cleaning connection of session ID %" PRIu64, to_close);
+
+	found = 0;
+	rcu_read_lock();
+	cds_list_for_each_entry_safe(session, tmp_session,
+			&conn->viewer_session->sessions_head,
+			viewer_session_list) {
+		if (session->id == to_close) {
+			DBG("Cleaning connection of session ID %" PRIu64, session->id);
+			cleanup_session(conn, session);
+			found = 1;
+			break;
+		}
+	}
+	rcu_read_unlock();
+
+	if (!found) {
+		resp.status = htobe32(LTTNG_VIEWER_DETACH_SESSION_ERR);
+	} else {
+		resp.status = htobe32(LTTNG_VIEWER_DETACH_SESSION_OK);
+	}
+
+send_reply:
+	health_code_update();
+	ret = send_response(conn->sock, &resp, sizeof(resp));
+	if (ret < 0) {
+		goto end;
+	}
+	health_code_update();
+	ret = 0;
+
+end:
+	return ret;
+}
+
 
 /*
  * live_relay_unknown_command: send -1 if received unknown command
@@ -1797,6 +1867,9 @@ int process_control(struct lttng_viewer_cmd *recv_hdr,
 	case LTTNG_VIEWER_CREATE_SESSION:
 		ret = viewer_create_session(conn);
 		break;
+	case LTTNG_VIEWER_DETACH_SESSION:
+		ret = viewer_detach_session(conn);
+		break;
 	default:
 		ERR("Received unknown viewer command (%u)", be32toh(recv_hdr->cmd));
 		live_relay_unknown_command(conn);
diff --git a/src/bin/lttng-relayd/lttng-viewer-abi.h b/src/bin/lttng-relayd/lttng-viewer-abi.h
index f9bce98..9b4bc1a 100644
--- a/src/bin/lttng-relayd/lttng-viewer-abi.h
+++ b/src/bin/lttng-relayd/lttng-viewer-abi.h
@@ -48,6 +48,7 @@ enum lttng_viewer_command {
 	LTTNG_VIEWER_GET_METADATA	= 6,
 	LTTNG_VIEWER_GET_NEW_STREAMS	= 7,
 	LTTNG_VIEWER_CREATE_SESSION	= 8,
+	LTTNG_VIEWER_DETACH_SESSION	= 9,
 };
 
 enum lttng_viewer_attach_return_code {
@@ -105,6 +106,11 @@ enum lttng_viewer_create_session_return_code {
 	LTTNG_VIEWER_CREATE_SESSION_ERR		= 2,
 };
 
+enum lttng_viewer_detach_session_return_code {
+	LTTNG_VIEWER_DETACH_SESSION_OK		= 1,
+	LTTNG_VIEWER_DETACH_SESSION_ERR		= 2,
+};
+
 struct lttng_viewer_session {
 	uint64_t id;
 	uint32_t live_timer;
@@ -232,4 +238,16 @@ struct lttng_viewer_create_session_response {
 	uint32_t status;
 } __attribute__((__packed__));
 
+/*
+ * LTTNG_VIEWER_DETACH_SESSION payload.
+ */
+struct lttng_viewer_detach_session_request {
+	uint64_t session_id;
+} __attribute__((__packed__));
+
+struct lttng_viewer_detach_session_response {
+	/* enum lttng_viewer_detach_session_return_code */
+	uint32_t status;
+} __attribute__((__packed__));
+
 #endif /* LTTNG_VIEWER_ABI_H */
-- 
1.9.1




             reply	other threads:[~2015-07-30 15:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-30 15:52 Julien Desfossez [this message]
2015-07-30 15:52 ` [lttng-dev] [LTTNG-TOOLS PATCH v2 2/2] Test the viewer detach command Julien Desfossez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1438271554-30895-1-git-send-email-jdesfossez@efficios.com \
    --to=jdesfossez@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox