bdev_iscsi: support iscsi timeout setting

Change-Id: I189ae677dfb13feb834b73fd1f55bf2545679213
Signed-off-by: gongwei <gongwei833x@gmail.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14110
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
gongwei 2022-08-18 09:48:32 +00:00 committed by Tomasz Zawadzki
parent 39f5b26bc4
commit 1519aa4715
6 changed files with 145 additions and 1 deletions

View File

@ -4608,6 +4608,42 @@ Example response:
} }
~~~ ~~~
### bdev_iscsi_set_options {#rpc_bdev_iscsi_set_options}
This RPC can be called at any time, but the new value will only take effect for new iSCSI bdevs.
#### Parameters
Name | Optional | Type | Description
-------------------------- | -------- | ----------- | -----------
timeout | Optional | number | Timeout for command, in seconds, if 0, don't track timeout
#### Example
Example request:
~~~json
request:
{
"params": {
"timeout": 30
},
"jsonrpc": "2.0",
"method": "bdev_iscsi_set_options",
"id": 1
}
~~~
Example response:
~~~json
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
~~~
### bdev_iscsi_create {#rpc_bdev_iscsi_create} ### bdev_iscsi_create {#rpc_bdev_iscsi_create}
Connect to iSCSI target and create bdev backed by this connection. Connect to iSCSI target and create bdev backed by this connection.

View File

@ -28,6 +28,10 @@ struct bdev_iscsi_lun;
#define BDEV_ISCSI_CONNECTION_POLL_US 500 /* 0.5 ms */ #define BDEV_ISCSI_CONNECTION_POLL_US 500 /* 0.5 ms */
#define BDEV_ISCSI_NO_MAIN_CH_POLL_US 10000 /* 10ms */ #define BDEV_ISCSI_NO_MAIN_CH_POLL_US 10000 /* 10ms */
#define BDEV_ISCSI_TIMEOUT_POLL_PERIOD_DEFAULT 1000000ULL /* 1 s */
#define BDEV_ISCSI_TIMEOUT_DEFAULT 30 /* 30 s */
#define BDEV_ISCSI_TIMEOUT_POLL_PERIOD_DIVISOR 30
#define DEFAULT_INITIATOR_NAME "iqn.2016-06.io.spdk:init" #define DEFAULT_INITIATOR_NAME "iqn.2016-06.io.spdk:init"
/* MAXIMUM UNMAP LBA COUNT: /* MAXIMUM UNMAP LBA COUNT:
@ -75,6 +79,7 @@ struct bdev_iscsi_lun {
bool unmap_supported; bool unmap_supported;
uint32_t max_unmap; uint32_t max_unmap;
struct spdk_poller *poller; struct spdk_poller *poller;
struct spdk_poller *timeout_poller;
}; };
struct bdev_iscsi_io_channel { struct bdev_iscsi_io_channel {
@ -95,6 +100,29 @@ struct bdev_iscsi_conn_req {
TAILQ_ENTRY(bdev_iscsi_conn_req) link; TAILQ_ENTRY(bdev_iscsi_conn_req) link;
}; };
static struct spdk_bdev_iscsi_opts g_opts = {
.timeout = BDEV_ISCSI_TIMEOUT_DEFAULT,
.timeout_poller_period_us = BDEV_ISCSI_TIMEOUT_POLL_PERIOD_DEFAULT,
};
void
bdev_iscsi_get_opts(struct spdk_bdev_iscsi_opts *opts)
{
*opts = g_opts;
}
int
bdev_iscsi_set_opts(struct spdk_bdev_iscsi_opts *opts)
{
/* make the poller period equal to timeout / 30 */
opts->timeout_poller_period_us = (opts->timeout * 1000000ULL) /
BDEV_ISCSI_TIMEOUT_POLL_PERIOD_DIVISOR;
g_opts = *opts;
return 0;
}
static void static void
complete_conn_req(struct bdev_iscsi_conn_req *req, struct spdk_bdev *bdev, complete_conn_req(struct bdev_iscsi_conn_req *req, struct spdk_bdev *bdev,
int status) int status)
@ -498,6 +526,15 @@ bdev_iscsi_poll_lun(void *_lun)
return SPDK_POLLER_IDLE; return SPDK_POLLER_IDLE;
} }
static int
bdev_iscsi_poll_lun_timeout(void *_lun)
{
struct bdev_iscsi_lun *lun = _lun;
/* passing 0 here to iscsi_service means do nothing except for timeout checks */
iscsi_service(lun->context, 0);
return SPDK_POLLER_BUSY;
}
static int static int
bdev_iscsi_no_main_ch_poll(void *arg) bdev_iscsi_no_main_ch_poll(void *arg)
{ {
@ -624,6 +661,10 @@ bdev_iscsi_create_cb(void *io_device, void *ctx_buf)
assert(lun->main_td == NULL); assert(lun->main_td == NULL);
lun->main_td = spdk_get_thread(); lun->main_td = spdk_get_thread();
lun->poller = SPDK_POLLER_REGISTER(bdev_iscsi_poll_lun, lun, 0); lun->poller = SPDK_POLLER_REGISTER(bdev_iscsi_poll_lun, lun, 0);
if (g_opts.timeout > 0) {
lun->timeout_poller = SPDK_POLLER_REGISTER(bdev_iscsi_poll_lun_timeout, lun,
g_opts.timeout_poller_period_us);
}
ch->lun = lun; ch->lun = lun;
} }
lun->ch_count++; lun->ch_count++;
@ -650,6 +691,7 @@ _iscsi_destroy_cb(void *ctx)
lun->main_td = NULL; lun->main_td = NULL;
spdk_poller_unregister(&lun->poller); spdk_poller_unregister(&lun->poller);
spdk_poller_unregister(&lun->timeout_poller);
pthread_mutex_unlock(&lun->mutex); pthread_mutex_unlock(&lun->mutex);
} }
@ -678,6 +720,7 @@ bdev_iscsi_destroy_cb(void *io_device, void *ctx_buf)
lun->main_td = NULL; lun->main_td = NULL;
spdk_poller_unregister(&lun->poller); spdk_poller_unregister(&lun->poller);
spdk_poller_unregister(&lun->timeout_poller);
} }
pthread_mutex_unlock(&lun->mutex); pthread_mutex_unlock(&lun->mutex);
} }
@ -1001,6 +1044,7 @@ create_iscsi_disk(const char *bdev_name, const char *url, const char *initiator_
rc = iscsi_set_session_type(req->context, ISCSI_SESSION_NORMAL); rc = iscsi_set_session_type(req->context, ISCSI_SESSION_NORMAL);
rc = rc ? rc : iscsi_set_header_digest(req->context, ISCSI_HEADER_DIGEST_NONE); rc = rc ? rc : iscsi_set_header_digest(req->context, ISCSI_HEADER_DIGEST_NONE);
rc = rc ? rc : iscsi_set_targetname(req->context, iscsi_url->target); rc = rc ? rc : iscsi_set_targetname(req->context, iscsi_url->target);
rc = rc ? rc : iscsi_set_timeout(req->context, g_opts.timeout);
rc = rc ? rc : iscsi_full_connect_async(req->context, iscsi_url->portal, iscsi_url->lun, rc = rc ? rc : iscsi_full_connect_async(req->context, iscsi_url->portal, iscsi_url->lun,
iscsi_connect_cb, req); iscsi_connect_cb, req);
if (rc == 0 && iscsi_url->user[0] != '\0') { if (rc == 0 && iscsi_url->user[0] != '\0') {

View File

@ -8,6 +8,11 @@
#include "spdk/bdev.h" #include "spdk/bdev.h"
struct spdk_bdev_iscsi_opts {
uint64_t timeout;
uint64_t timeout_poller_period_us;
};
typedef void (*spdk_delete_iscsi_complete)(void *cb_arg, int bdeverrno); typedef void (*spdk_delete_iscsi_complete)(void *cb_arg, int bdeverrno);
/** /**
@ -43,5 +48,6 @@ int create_iscsi_disk(const char *bdev_name, const char *url, const char *initia
* \param cb_arg Completion callback custom arguments * \param cb_arg Completion callback custom arguments
*/ */
void delete_iscsi_disk(const char *bdev_name, spdk_delete_iscsi_complete cb_fn, void *cb_arg); void delete_iscsi_disk(const char *bdev_name, spdk_delete_iscsi_complete cb_fn, void *cb_arg);
void bdev_iscsi_get_opts(struct spdk_bdev_iscsi_opts *opts);
int bdev_iscsi_set_opts(struct spdk_bdev_iscsi_opts *opts);
#endif /* SPDK_BDEV_ISCSI_H */ #endif /* SPDK_BDEV_ISCSI_H */

View File

@ -10,6 +10,42 @@
#include "spdk/log.h" #include "spdk/log.h"
static const struct spdk_json_object_decoder rpc_bdev_iscsi_options_decoders[] = {
{"timeout", offsetof(struct spdk_bdev_iscsi_opts, timeout), spdk_json_decode_uint64, true},
};
static void
rpc_bdev_iscsi_set_options(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct spdk_bdev_iscsi_opts opts;
int rc;
bdev_iscsi_get_opts(&opts);
if (params && spdk_json_decode_object(params, rpc_bdev_iscsi_options_decoders,
SPDK_COUNTOF(rpc_bdev_iscsi_options_decoders),
&opts)) {
SPDK_ERRLOG("spdk_json_decode_object failed\n");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"spdk_json_decode_object failed");
return;
}
rc = bdev_iscsi_set_opts(&opts);
if (rc == -EPERM) {
spdk_jsonrpc_send_error_response(request, -EPERM,
"RPC not permitted with iscsi already connected");
} else if (rc) {
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
} else {
spdk_jsonrpc_send_bool_response(request, true);
}
return;
}
SPDK_RPC_REGISTER("bdev_iscsi_set_options", rpc_bdev_iscsi_set_options,
SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
struct rpc_bdev_iscsi_create { struct rpc_bdev_iscsi_create {
char *name; char *name;
char *initiator_iqn; char *initiator_iqn;

View File

@ -1116,6 +1116,20 @@ def bdev_error_delete(client, name):
return client.call('bdev_error_delete', params) return client.call('bdev_error_delete', params)
def bdev_iscsi_set_options(client, timeout):
"""Set options for the bdev iscsi.
Args:
timeout: Timeout for command, in seconds, if 0, don't track timeout
"""
params = {}
if timeout is not None:
params['timeout'] = timeout
return client.call('bdev_iscsi_set_options', params)
def bdev_iscsi_create(client, name, url, initiator_iqn): def bdev_iscsi_create(client, name, url, initiator_iqn):
"""Construct an iSCSI block device. """Construct an iSCSI block device.

View File

@ -996,6 +996,14 @@ if __name__ == "__main__":
p.add_argument('name', help='error bdev name') p.add_argument('name', help='error bdev name')
p.set_defaults(func=bdev_error_delete) p.set_defaults(func=bdev_error_delete)
def bdev_iscsi_set_options(args):
rpc.bdev.bdev_iscsi_set_options(args.client,
timeout=args.timeout)
p = subparsers.add_parser('bdev_iscsi_set_options', help='Set options for the bdev iscsi type.')
p.add_argument('-t', '--timeout', help="Timeout for command, in seconds, if 0, don't track timeout.", type=int)
p.set_defaults(func=bdev_iscsi_set_options)
def bdev_iscsi_create(args): def bdev_iscsi_create(args):
print_json(rpc.bdev.bdev_iscsi_create(args.client, print_json(rpc.bdev.bdev_iscsi_create(args.client,
name=args.name, name=args.name,