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:
parent
39f5b26bc4
commit
1519aa4715
@ -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}
|
||||
|
||||
Connect to iSCSI target and create bdev backed by this connection.
|
||||
|
@ -28,6 +28,10 @@ struct bdev_iscsi_lun;
|
||||
#define BDEV_ISCSI_CONNECTION_POLL_US 500 /* 0.5 ms */
|
||||
#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"
|
||||
|
||||
/* MAXIMUM UNMAP LBA COUNT:
|
||||
@ -75,6 +79,7 @@ struct bdev_iscsi_lun {
|
||||
bool unmap_supported;
|
||||
uint32_t max_unmap;
|
||||
struct spdk_poller *poller;
|
||||
struct spdk_poller *timeout_poller;
|
||||
};
|
||||
|
||||
struct bdev_iscsi_io_channel {
|
||||
@ -95,6 +100,29 @@ struct bdev_iscsi_conn_req {
|
||||
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
|
||||
complete_conn_req(struct bdev_iscsi_conn_req *req, struct spdk_bdev *bdev,
|
||||
int status)
|
||||
@ -498,6 +526,15 @@ bdev_iscsi_poll_lun(void *_lun)
|
||||
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
|
||||
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);
|
||||
lun->main_td = spdk_get_thread();
|
||||
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;
|
||||
}
|
||||
lun->ch_count++;
|
||||
@ -650,6 +691,7 @@ _iscsi_destroy_cb(void *ctx)
|
||||
|
||||
lun->main_td = NULL;
|
||||
spdk_poller_unregister(&lun->poller);
|
||||
spdk_poller_unregister(&lun->timeout_poller);
|
||||
|
||||
pthread_mutex_unlock(&lun->mutex);
|
||||
}
|
||||
@ -678,6 +720,7 @@ bdev_iscsi_destroy_cb(void *io_device, void *ctx_buf)
|
||||
|
||||
lun->main_td = NULL;
|
||||
spdk_poller_unregister(&lun->poller);
|
||||
spdk_poller_unregister(&lun->timeout_poller);
|
||||
}
|
||||
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 = 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_timeout(req->context, g_opts.timeout);
|
||||
rc = rc ? rc : iscsi_full_connect_async(req->context, iscsi_url->portal, iscsi_url->lun,
|
||||
iscsi_connect_cb, req);
|
||||
if (rc == 0 && iscsi_url->user[0] != '\0') {
|
||||
|
@ -8,6 +8,11 @@
|
||||
|
||||
#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);
|
||||
|
||||
/**
|
||||
@ -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
|
||||
*/
|
||||
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 */
|
||||
|
@ -10,6 +10,42 @@
|
||||
|
||||
#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 {
|
||||
char *name;
|
||||
char *initiator_iqn;
|
||||
|
@ -1116,6 +1116,20 @@ def bdev_error_delete(client, name):
|
||||
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):
|
||||
"""Construct an iSCSI block device.
|
||||
|
||||
|
@ -996,6 +996,14 @@ if __name__ == "__main__":
|
||||
p.add_argument('name', help='error bdev name')
|
||||
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):
|
||||
print_json(rpc.bdev.bdev_iscsi_create(args.client,
|
||||
name=args.name,
|
||||
|
Loading…
Reference in New Issue
Block a user