From d97476efdffe9c6bb35a3b31b99327eda4156dfa Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 10 Nov 2017 10:02:00 -0700 Subject: [PATCH] iscsi: shutdown iscsi library as part of subsystem fini path With the new asynchronous subsystem finish framework, we can drive shutdown of existing connections as part of the subsystem finish path instead of a separate spdk_iscsi_shutdown function called as the shutdown function in response to SIGINT. This is a step towards enabling a single target app that supports multiple protocols (i.e. iSCSI + vhost + NVMe-oF). Signed-off-by: Jim Harris Change-Id: Id9f596a8091912a72ab7eb93cb45a46fdb130a48 Reviewed-on: https://review.gerrithub.io/386695 Reviewed-by: Ben Walker Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System --- app/iscsi_tgt/iscsi_tgt.c | 2 +- lib/event/subsystems/iscsi/iscsi.c | 9 +++++++-- lib/iscsi/conn.c | 2 +- lib/iscsi/iscsi.c | 7 ------- lib/iscsi/iscsi.h | 5 +++-- lib/iscsi/iscsi_subsystem.c | 16 +++++++++++++++- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/app/iscsi_tgt/iscsi_tgt.c b/app/iscsi_tgt/iscsi_tgt.c index f99aa99d5..556462596 100644 --- a/app/iscsi_tgt/iscsi_tgt.c +++ b/app/iscsi_tgt/iscsi_tgt.c @@ -102,7 +102,7 @@ main(int argc, char **argv) } } - opts.shutdown_cb = spdk_iscsi_shutdown; + opts.shutdown_cb = NULL; opts.usr1_handler = spdk_sigusr1; printf("Using net framework %s\n", spdk_net_framework_get_name()); diff --git a/lib/event/subsystems/iscsi/iscsi.c b/lib/event/subsystems/iscsi/iscsi.c index 10604136a..2afadc6ae 100644 --- a/lib/event/subsystems/iscsi/iscsi.c +++ b/lib/event/subsystems/iscsi/iscsi.c @@ -47,11 +47,16 @@ spdk_iscsi_subsystem_init(void) spdk_subsystem_init_next(rc); } +static void +spdk_iscsi_subsystem_fini_done(void *arg) +{ + spdk_subsystem_fini_next(); +} + static void spdk_iscsi_subsystem_fini(void *arg1, void *arg2) { - spdk_iscsi_fini(); - spdk_subsystem_fini_next(); + spdk_iscsi_fini(spdk_iscsi_subsystem_fini_done, NULL); } SPDK_SUBSYSTEM_REGISTER(iscsi, spdk_iscsi_subsystem_init, spdk_iscsi_subsystem_fini, diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index faab019be..c1a13c481 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -756,7 +756,7 @@ static void spdk_iscsi_conn_check_shutdown_cb(void *arg1, void *arg2) { spdk_iscsi_conns_cleanup(); - spdk_app_stop(0); + spdk_iscsi_fini_done(); } static void diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 1e566b8c4..8ac54d169 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -4684,13 +4684,6 @@ spdk_append_iscsi_sess(struct spdk_iscsi_conn *conn, return 0; } -void -spdk_iscsi_shutdown(void) -{ - spdk_iscsi_portal_grp_close_all(); - spdk_shutdown_iscsi_conns(); -} - bool spdk_iscsi_is_deferred_free_pdu(struct spdk_iscsi_pdu *pdu) { if (pdu == NULL) diff --git a/lib/iscsi/iscsi.h b/lib/iscsi/iscsi.h index 45cf23525..61f77bac2 100644 --- a/lib/iscsi/iscsi.h +++ b/lib/iscsi/iscsi.h @@ -320,7 +320,9 @@ extern struct spdk_iscsi_globals g_spdk_iscsi; struct spdk_iscsi_task; int spdk_iscsi_init(void); -void spdk_iscsi_fini(void); +typedef void (*spdk_iscsi_fini_cb)(void *arg); +void spdk_iscsi_fini(spdk_iscsi_fini_cb cb_fn, void *cb_arg); +void spdk_iscsi_fini_done(void); void spdk_iscsi_config_text(FILE *fp); int spdk_iscsi_send_nopin(struct spdk_iscsi_conn *conn); @@ -344,7 +346,6 @@ void spdk_del_connection_queued_task(void *tailq, struct spdk_scsi_lun *lun); void spdk_del_transfer_task(struct spdk_iscsi_conn *conn, uint32_t CmdSN); bool spdk_iscsi_is_deferred_free_pdu(struct spdk_iscsi_pdu *pdu); -void spdk_iscsi_shutdown(void); int spdk_iscsi_negotiate_params(struct spdk_iscsi_conn *conn, struct iscsi_param **params_p, uint8_t *data, int alloc_len, int data_len); diff --git a/lib/iscsi/iscsi_subsystem.c b/lib/iscsi/iscsi_subsystem.c index 1a0d4599c..1d71eaa87 100644 --- a/lib/iscsi/iscsi_subsystem.c +++ b/lib/iscsi/iscsi_subsystem.c @@ -49,6 +49,9 @@ #include "spdk_internal/event.h" #include "spdk_internal/log.h" +static spdk_iscsi_fini_cb g_fini_cb_fn; +static void *g_fini_cb_arg; + #define ISCSI_CONFIG_TMPL \ "[iSCSI]\n" \ " # node name (not include optional part)\n" \ @@ -875,7 +878,17 @@ spdk_iscsi_init(void) } void -spdk_iscsi_fini(void) +spdk_iscsi_fini(spdk_iscsi_fini_cb cb_fn, void *cb_arg) +{ + g_fini_cb_fn = cb_fn; + g_fini_cb_arg = cb_arg; + + spdk_iscsi_portal_grp_close_all(); + spdk_shutdown_iscsi_conns(); +} + +void +spdk_iscsi_fini_done(void) { spdk_iscsi_check_pools(); spdk_iscsi_free_pools(); @@ -887,6 +900,7 @@ spdk_iscsi_fini(void) free(g_spdk_iscsi.nodebase); pthread_mutex_destroy(&g_spdk_iscsi.mutex); + g_fini_cb_fn(g_fini_cb_arg); } void