Project

General

Profile

Feature #853 » 0001-Test-implement-a-command-to-detach-a-viewer-session.patch

Julien Desfossez, 11/18/2014 11:08 AM

View differences:

src/bin/lttng-relayd/live.c
1752 1752
	return ret;
1753 1753
}
1754 1754

  
1755
/*
1756
 * Detach a viewer session.
1757
 *
1758
 * Return 0 on success or else a negative value.
1759
 */
1760
static
1761
int viewer_detach_session(struct relay_connection *conn)
1762
{
1763
	int ret, found;
1764
	struct lttng_viewer_detach_session_response resp;
1765
	struct lttng_viewer_detach_session_request request;
1766
	struct relay_session *session, *tmp_session;
1767
	uint64_t to_close;
1768

  
1769
	DBG("Viewer detach session received");
1770

  
1771
	assert(conn);
1772

  
1773
	health_code_update();
1774

  
1775
	/* Receive the request from the connected client. */
1776
	ret = recv_request(conn->sock, &request, sizeof(request));
1777
	if (ret < 0) {
1778
		goto end;
1779
	}
1780
	to_close = be64toh(request.session_id);
1781

  
1782
	if (!conn->viewer_session) {
1783
		resp.status = htobe32(LTTNG_VIEWER_DETACH_SESSION_ERR);
1784
		goto send_reply;
1785
	}
1786

  
1787
	health_code_update();
1788

  
1789
	memset(&resp, 0, sizeof(resp));
1790
	DBG("Cleaning connection of session ID %" PRIu64, to_close);
1791

  
1792
	found = 0;
1793
	rcu_read_lock();
1794
	cds_list_for_each_entry_safe(session, tmp_session,
1795
			&conn->viewer_session->sessions_head,
1796
			viewer_session_list) {
1797
		if (session->id == to_close) {
1798
			DBG("Cleaning connection of session ID %" PRIu64, session->id);
1799
			cleanup_session(conn, session);
1800
			found = 1;
1801
			break;
1802
		}
1803
	}
1804
	rcu_read_unlock();
1805

  
1806
	if (!found) {
1807
		resp.status = htobe32(LTTNG_VIEWER_DETACH_SESSION_ERR);
1808
	} else {
1809
		resp.status = htobe32(LTTNG_VIEWER_DETACH_SESSION_OK);
1810
	}
1811

  
1812
send_reply:
1813
	health_code_update();
1814
	ret = send_response(conn->sock, &resp, sizeof(resp));
1815
	if (ret < 0) {
1816
		goto end;
1817
	}
1818
	health_code_update();
1819
	ret = 0;
1820

  
1821
end:
1822
	return ret;
1823
}
1824

  
1755 1825

  
1756 1826
/*
1757 1827
 * live_relay_unknown_command: send -1 if received unknown command
......
1816 1886
	case LTTNG_VIEWER_CREATE_SESSION:
1817 1887
		ret = viewer_create_session(conn);
1818 1888
		break;
1889
	case LTTNG_VIEWER_DETACH_SESSION:
1890
		ret = viewer_detach_session(conn);
1891
		break;
1819 1892
	default:
1820 1893
		ERR("Received unknown viewer command (%u)", be32toh(recv_hdr->cmd));
1821 1894
		live_relay_unknown_command(conn);
src/bin/lttng-relayd/lttng-viewer-abi.h
48 48
	LTTNG_VIEWER_GET_METADATA	= 6,
49 49
	LTTNG_VIEWER_GET_NEW_STREAMS	= 7,
50 50
	LTTNG_VIEWER_CREATE_SESSION	= 8,
51
	LTTNG_VIEWER_DETACH_SESSION	= 9,
51 52
};
52 53

  
53 54
enum lttng_viewer_attach_return_code {
......
105 106
	LTTNG_VIEWER_CREATE_SESSION_ERR		= 2,
106 107
};
107 108

  
109
enum lttng_viewer_detach_session_return_code {
110
	LTTNG_VIEWER_DETACH_SESSION_OK		= 1,
111
	LTTNG_VIEWER_DETACH_SESSION_ERR		= 2,
112
};
113

  
108 114
struct lttng_viewer_session {
109 115
	uint64_t id;
110 116
	uint32_t live_timer;
......
232 238
	uint32_t status;
233 239
} __attribute__((__packed__));
234 240

  
241
/*
242
 * LTTNG_VIEWER_DETACH_SESSION payload.
243
 */
244
struct lttng_viewer_detach_session_request {
245
	uint64_t session_id;
246
} __attribute__((__packed__));
247

  
248
struct lttng_viewer_detach_session_response {
249
	/* enum lttng_viewer_detach_session_return_code */
250
	uint32_t status;
251
} __attribute__((__packed__));
252

  
235 253
#endif /* LTTNG_VIEWER_ABI_H */
236
- 
(2-2/3)