Fix: force the client to create a viewer session before attaching
authorJulien Desfossez <jdesfossez@efficios.com>
Thu, 30 Jan 2014 20:44:20 +0000 (15:44 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 10 Feb 2014 19:55:17 +0000 (14:55 -0500)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
src/bin/lttng-relayd/connection.h
src/bin/lttng-relayd/live.c
src/bin/lttng-relayd/lttng-viewer-abi.h
src/bin/lttng-relayd/session.h

index 6fb8913bf4dc53756fc8e68a872b394f69c24efc..931169ec0616d348e5198a46d2b22b24b2eb9867 100644 (file)
@@ -44,6 +44,7 @@ enum connection_type {
 struct relay_connection {
        struct lttcomm_sock *sock;
        struct relay_session *session;
+       struct relay_viewer_session *viewer_session;
        struct cds_wfq_node qnode;
        struct lttng_ht_node_ulong sock_n;
        struct rcu_head rcu_node;
index b3b7ee427268ff6d24169a037b44eab134eddef9..b2e8e7c8bb1305b07c121172ecb1d2e760339348 100644 (file)
@@ -926,6 +926,12 @@ int viewer_attach_session(struct relay_connection *conn)
 
        health_code_update();
 
+       if (!conn->viewer_session) {
+               DBG("Client trying to attach before creating a live viewer session");
+               response.status = htobe32(LTTNG_VIEWER_ATTACH_NO_SESSION);
+               goto send_reply;
+       }
+
        rcu_read_lock();
        session = session_find_by_id(conn->sessions_ht,
                        be64toh(request.session_id));
@@ -1491,6 +1497,42 @@ end:
        return ret;
 }
 
+/*
+ * Create a viewer session.
+ *
+ * Return 0 on success or else a negative value.
+ */
+static
+int viewer_create_session(struct relay_connection *conn)
+{
+       int ret;
+       struct lttng_viewer_create_session_response resp;
+
+       DBG("Viewer create session received");
+
+       resp.status = htobe32(LTTNG_VIEWER_CREATE_SESSION_OK);
+       conn->viewer_session = zmalloc(sizeof(conn->viewer_session));
+       if (!conn->viewer_session) {
+               ERR("Allocation viewer session");
+               resp.status = htobe32(LTTNG_VIEWER_CREATE_SESSION_ERR);
+               goto send_reply;
+       }
+       CDS_INIT_LIST_HEAD(&conn->viewer_session->sessions_head);
+
+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
  */
@@ -1550,6 +1592,9 @@ int process_control(struct lttng_viewer_cmd *recv_hdr,
        case LTTNG_VIEWER_GET_NEW_STREAMS:
                ret = viewer_get_new_streams(conn);
                break;
+       case LTTNG_VIEWER_CREATE_SESSION:
+               ret = viewer_create_session(conn);
+               break;
        default:
                ERR("Received unknown viewer command (%u)", be32toh(recv_hdr->cmd));
                live_relay_unknown_command(conn);
index 3a91da8a6a587002fbbafaf810f87e132bcfa708..aa073c4e05cfe63cae4a87865924bf8f47b5e304 100644 (file)
@@ -47,6 +47,7 @@ enum lttng_viewer_command {
        LTTNG_VIEWER_GET_PACKET         = 5,
        LTTNG_VIEWER_GET_METADATA       = 6,
        LTTNG_VIEWER_GET_NEW_STREAMS    = 7,
+       LTTNG_VIEWER_CREATE_SESSION     = 8,
 };
 
 enum lttng_viewer_attach_return_code {
@@ -55,6 +56,7 @@ enum lttng_viewer_attach_return_code {
        LTTNG_VIEWER_ATTACH_UNK         = 3, /* The session ID is unknown. */
        LTTNG_VIEWER_ATTACH_NOT_LIVE    = 4, /* The session is not live. */
        LTTNG_VIEWER_ATTACH_SEEK_ERR    = 5, /* Seek error. */
+       LTTNG_VIEWER_ATTACH_NO_SESSION  = 6, /* No viewer session created. */
 };
 
 enum lttng_viewer_next_index_return_code {
@@ -97,6 +99,11 @@ enum lttng_viewer_new_streams_return_code {
        LTTNG_VIEWER_NEW_STREAMS_ERR          = 3, /* Error. */
 };
 
+enum lttng_viewer_create_session_return_code {
+       LTTNG_VIEWER_CREATE_SESSION_OK          = 1,
+       LTTNG_VIEWER_CREATE_SESSION_ERR         = 2,
+};
+
 struct lttng_viewer_session {
        uint64_t id;
        uint32_t live_timer;
@@ -219,4 +226,9 @@ struct lttng_viewer_new_streams_response {
        char stream_list[];
 } __attribute__((__packed__));
 
+struct lttng_viewer_create_session_response {
+       /* enum lttng_viewer_create_session_return_code */
+       uint32_t status;
+} __attribute__((__packed__));
+
 #endif /* LTTNG_VIEWER_H */
index 4953cdcd3252883c800f442d3703ee6b4e40c063..cb125be18b4bbcf10ac2dfacf513e1ee4d166ee6 100644 (file)
@@ -22,6 +22,7 @@
 #include <limits.h>
 #include <inttypes.h>
 #include <pthread.h>
+#include <urcu/list.h>
 
 #include <common/hashtable/hashtable.h>
 
@@ -71,6 +72,15 @@ struct relay_session {
         * process of sending those streams.
         */
        pthread_mutex_t viewer_ready_lock;
+
+       /*
+        * Member of the session list in struct relay_viewer_session.
+        */
+       struct cds_list_head viewer_session_list;
+};
+
+struct relay_viewer_session {
+       struct cds_list_head sessions_head;
 };
 
 static inline void session_viewer_attach(struct relay_session *session)
This page took 0.039011 seconds and 4 git commands to generate.