aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/session
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-08-24 18:17:34 -0700
committerFlorin Coras <florin.coras@gmail.com>2019-12-21 18:50:12 +0000
commitc4c4cf5066fbdceebd62a8819e3ecd0fc879f05d (patch)
tree2bd208ee7edb7e49440397b2fd44f3515c4e817d /src/vnet/session
parentd849edf3841c1c9774c5ce209a2b903415f2370a (diff)
session: move add/del segment msg to mq
Type: refactor Change-Id: I32234173ebd69f80acb1afa4039fffbd19157f6d Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vnet/session')
-rw-r--r--src/vnet/session/application_interface.h23
-rw-r--r--src/vnet/session/application_worker.c5
-rw-r--r--src/vnet/session/session.api2
-rw-r--r--src/vnet/session/session_api.c113
-rw-r--r--src/vnet/session/session_types.h5
5 files changed, 140 insertions, 8 deletions
diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h
index a40aa9d9a7f..2e850a98e57 100644
--- a/src/vnet/session/application_interface.h
+++ b/src/vnet/session/application_interface.h
@@ -29,13 +29,13 @@ typedef struct certificate_
u8 *cert;
} app_cert_key_pair_t;
-typedef struct _stream_session_cb_vft
+typedef struct session_cb_vft_
{
/** Notify server of new segment */
- int (*add_segment_callback) (u32 api_client_index, u64 segment_handle);
+ int (*add_segment_callback) (u32 app_wrk_index, u64 segment_handle);
/** Notify server of new segment */
- int (*del_segment_callback) (u32 api_client_index, u64 segment_handle);
+ int (*del_segment_callback) (u32 app_wrk_index, u64 segment_handle);
/** Notify server of newly accepted session */
int (*session_accept_callback) (session_t * new_session);
@@ -485,6 +485,23 @@ typedef struct session_app_detach_msg_
u32 context;
} session_app_detach_msg_t;
+typedef struct app_map_another_segment_msg_
+{
+ u32 client_index;
+ u32 context;
+ u8 fd_flags;
+ u32 segment_size;
+ u8 segment_name[128];
+ u64 segment_handle;
+} session_app_add_segment_msg_t;
+
+typedef struct app_unmap_segment_msg_
+{
+ u32 client_index;
+ u32 context;
+ u64 segment_handle;
+} session_app_del_segment_msg_t;
+
typedef struct app_session_event_
{
svm_msg_q_msg_t msg;
diff --git a/src/vnet/session/application_worker.c b/src/vnet/session/application_worker.c
index bb51cb71f03..1db6baab74e 100644
--- a/src/vnet/session/application_worker.c
+++ b/src/vnet/session/application_worker.c
@@ -526,7 +526,8 @@ int
app_worker_add_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
{
application_t *app = application_get (app_wrk->app_index);
- return app->cb_fns.add_segment_callback (app_wrk->api_client_index,
+
+ return app->cb_fns.add_segment_callback (app_wrk->wrk_index,
segment_handle);
}
@@ -534,7 +535,7 @@ int
app_worker_del_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
{
application_t *app = application_get (app_wrk->app_index);
- return app->cb_fns.del_segment_callback (app_wrk->api_client_index,
+ return app->cb_fns.del_segment_callback (app_wrk->wrk_index,
segment_handle);
}
diff --git a/src/vnet/session/session.api b/src/vnet/session/session.api
index 33e53419a8d..4f9ae12eeb3 100644
--- a/src/vnet/session/session.api
+++ b/src/vnet/session/session.api
@@ -187,6 +187,7 @@ autoreply define application_detach {
};
/** \brief vpp->client, please map an additional shared memory segment
+ ### WILL BE DEPRECATED POST 20.01 ###
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param fd_flags - set of flags that indicate which, if any, fds are
@@ -206,6 +207,7 @@ autoreply define map_another_segment {
};
/** \brief vpp->client unmap shared memory segment
+ ### WILL BE DEPRECATED POST 20.01 ###
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param segment_name - segment name
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c
index 99e00a78bf3..153c528059c 100644
--- a/src/vnet/session/session_api.c
+++ b/src/vnet/session/session_api.c
@@ -81,6 +81,7 @@ session_send_fds (vl_api_registration_t * reg, int fds[], int n_fds)
return 0;
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static int
send_add_segment_callback (u32 api_client_index, u64 segment_handle)
{
@@ -130,6 +131,7 @@ send_add_segment_callback (u32 api_client_index, u64 segment_handle)
return 0;
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static int
send_del_segment_callback (u32 api_client_index, u64 segment_handle)
{
@@ -471,7 +473,103 @@ mq_send_session_migrate_cb (session_t * s, session_handle_t new_sh)
clib_warning ("not supported");
}
-static session_cb_vft_t session_mq_cb_vft = {
+static int
+mq_send_add_segment_cb (u32 app_wrk_index, u64 segment_handle)
+{
+ int fds[SESSION_N_FD_TYPE], n_fds = 0;
+ svm_msg_q_msg_t _msg, *msg = &_msg;
+ session_app_add_segment_msg_t *mp;
+ vl_api_registration_t *reg;
+ app_worker_t *app_wrk;
+ session_event_t *evt;
+ svm_msg_q_t *app_mq;
+ fifo_segment_t *fs;
+ ssvm_private_t *sp;
+ u8 fd_flags = 0;
+
+ app_wrk = app_worker_get (app_wrk_index);
+
+ reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
+ if (!reg)
+ {
+ clib_warning ("no api registration for client: %u",
+ app_wrk->api_client_index);
+ return -1;
+ }
+
+ fs = segment_manager_get_segment_w_handle (segment_handle);
+ sp = &fs->ssvm;
+ if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD)
+ {
+ if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
+ {
+ clib_warning ("can't send memfd fd");
+ return -1;
+ }
+
+ fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
+ fds[n_fds] = sp->fd;
+ n_fds += 1;
+ }
+
+ app_mq = app_wrk->event_queue;
+ if (mq_try_lock_and_alloc_msg (app_mq, msg))
+ return -1;
+
+ if (n_fds)
+ session_send_fds (reg, fds, n_fds);
+
+ evt = svm_msg_q_msg_data (app_mq, msg);
+ clib_memset (evt, 0, sizeof (*evt));
+ evt->event_type = SESSION_CTRL_EVT_APP_ADD_SEGMENT;
+ mp = (session_app_add_segment_msg_t *) evt->data;
+ clib_memset (mp, 0, sizeof (*mp));
+ mp->segment_size = sp->ssvm_size;
+ mp->fd_flags = fd_flags;
+ mp->segment_handle = segment_handle;
+ strncpy ((char *) mp->segment_name, (char *) sp->name,
+ sizeof (mp->segment_name) - 1);
+
+ svm_msg_q_add_and_unlock (app_mq, msg);
+
+ return 0;
+}
+
+static int
+mq_send_del_segment_cb (u32 app_wrk_index, u64 segment_handle)
+{
+ svm_msg_q_msg_t _msg, *msg = &_msg;
+ session_app_del_segment_msg_t *mp;
+ vl_api_registration_t *reg;
+ app_worker_t *app_wrk;
+ session_event_t *evt;
+ svm_msg_q_t *app_mq;
+
+ app_wrk = app_worker_get (app_wrk_index);
+ reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
+ if (!reg)
+ {
+ clib_warning ("no registration: %u", app_wrk->api_client_index);
+ return -1;
+ }
+
+ app_mq = app_wrk->event_queue;
+ if (mq_try_lock_and_alloc_msg (app_mq, msg))
+ return -1;
+
+ evt = svm_msg_q_msg_data (app_mq, msg);
+ clib_memset (evt, 0, sizeof (*evt));
+ evt->event_type = SESSION_CTRL_EVT_APP_DEL_SEGMENT;
+ mp = (session_app_del_segment_msg_t *) evt->data;
+ clib_memset (mp, 0, sizeof (*mp));
+ mp->segment_handle = segment_handle;
+ svm_msg_q_add_and_unlock (app_mq, msg);
+
+ return 0;
+}
+
+/* ### WILL BE DEPRECATED POST 20.01 ### */
+static session_cb_vft_t session_mq_cb_vft_old = {
.session_accept_callback = mq_send_session_accepted_cb,
.session_disconnect_callback = mq_send_session_disconnected_cb,
.session_connected_callback = mq_send_session_connected_cb,
@@ -481,6 +579,16 @@ static session_cb_vft_t session_mq_cb_vft = {
.del_segment_callback = send_del_segment_callback,
};
+static session_cb_vft_t session_mq_cb_vft = {
+ .session_accept_callback = mq_send_session_accepted_cb,
+ .session_disconnect_callback = mq_send_session_disconnected_cb,
+ .session_connected_callback = mq_send_session_connected_cb,
+ .session_reset_callback = mq_send_session_reset_cb,
+ .session_migrate_callback = mq_send_session_migrate_cb,
+ .add_segment_callback = mq_send_add_segment_cb,
+ .del_segment_callback = mq_send_del_segment_cb,
+};
+
static void
vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
{
@@ -520,7 +628,7 @@ vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
clib_memset (a, 0, sizeof (*a));
a->api_client_index = mp->client_index;
a->options = mp->options;
- a->session_cb_vft = &session_mq_cb_vft;
+ a->session_cb_vft = &session_mq_cb_vft_old;
if (mp->namespace_id_len > 64)
{
rv = VNET_API_ERROR_INVALID_VALUE;
@@ -888,6 +996,7 @@ vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
}
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
* mp)
diff --git a/src/vnet/session/session_types.h b/src/vnet/session/session_types.h
index 16d48431572..ce593b0b38c 100644
--- a/src/vnet/session/session_types.h
+++ b/src/vnet/session/session_types.h
@@ -334,6 +334,8 @@ typedef enum
SESSION_CTRL_EVT_LISTEN_URI,
SESSION_CTRL_EVT_UNLISTEN,
SESSION_CTRL_EVT_APP_DETACH,
+ SESSION_CTRL_EVT_APP_ADD_SEGMENT,
+ SESSION_CTRL_EVT_APP_DEL_SEGMENT,
} session_evt_type_t;
#define foreach_session_ctrl_evt \
@@ -355,7 +357,8 @@ typedef enum
_(WORKER_UPDATE, worker_update) \
_(WORKER_UPDATE_REPLY, worker_update_reply) \
_(APP_DETACH, app_detach) \
-
+ _(APP_ADD_SEGMENT, app_add_segment) \
+ _(APP_DEL_SEGMENT, app_del_segment) \
/* Deprecated and will be removed. Use types above */
#define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX