nvmf: State change functions now have a return code
When the state change is known to fail immediately, use a return code instead of calling the callback. Most of the callbacks didn't actually check for errors, so this patch also doesn't check for errors on return codes. That should be done in the future. Change-Id: I67e03f93d7f53892473dfc073f4150e7e620cad2 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/394281 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
6711e5a525
commit
d346b9c5a2
@ -171,10 +171,12 @@ typedef void (*spdk_nvmf_subsystem_state_change_done)(struct spdk_nvmf_subsystem
|
||||
* \param cb_fn A function that will be called once the subsystem has changed state.
|
||||
* \param cb_arg Argument passed to cb_fn.
|
||||
*
|
||||
* \return 0 on success. Negated errno on failure. The callback provided
|
||||
* will only be called on success.
|
||||
*/
|
||||
void spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg);
|
||||
int spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg);
|
||||
|
||||
/**
|
||||
* Transition an NVMe-oF subsystem from Active to Inactive state.
|
||||
@ -183,10 +185,12 @@ void spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem,
|
||||
* \param cb_fn A function that will be called once the subsystem has changed state.
|
||||
* \param cb_arg Argument passed to cb_fn.
|
||||
*
|
||||
* \return 0 on success. Negated errno on failure. The callback provided
|
||||
* will only be called on success.
|
||||
*/
|
||||
void spdk_nvmf_subsystem_stop(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg);
|
||||
int spdk_nvmf_subsystem_stop(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg);
|
||||
|
||||
/**
|
||||
* Transition an NVMe-oF subsystem from Active to Paused state.
|
||||
@ -195,10 +199,12 @@ void spdk_nvmf_subsystem_stop(struct spdk_nvmf_subsystem *subsystem,
|
||||
* \param cb_fn A function that will be called once the subsystem has changed state.
|
||||
* \param cb_arg Argument passed to cb_fn.
|
||||
*
|
||||
* \return 0 on success. Negated errno on failure. The callback provided
|
||||
* will only be called on success.
|
||||
*/
|
||||
void spdk_nvmf_subsystem_pause(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg);
|
||||
int spdk_nvmf_subsystem_pause(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg);
|
||||
|
||||
/**
|
||||
* Transition an NVMe-oF subsystem from Paused to Active state.
|
||||
@ -207,10 +213,12 @@ void spdk_nvmf_subsystem_pause(struct spdk_nvmf_subsystem *subsystem,
|
||||
* \param cb_fn A function that will be called once the subsystem has changed state.
|
||||
* \param cb_arg Argument passed to cb_fn.
|
||||
*
|
||||
* \return 0 on success. Negated errno on failure. The callback provided
|
||||
* will only be called on success.
|
||||
*/
|
||||
void spdk_nvmf_subsystem_resume(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg);
|
||||
int spdk_nvmf_subsystem_resume(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg);
|
||||
|
||||
/**
|
||||
* Search the target for a subsystem with the given NQN
|
||||
|
@ -395,7 +395,9 @@ subsystem_state_change_done(struct spdk_io_channel_iter *i, int status)
|
||||
}
|
||||
}
|
||||
|
||||
ctx->cb_fn(ctx->subsystem, ctx->cb_arg, status);
|
||||
if (ctx->cb_fn) {
|
||||
ctx->cb_fn(ctx->subsystem, ctx->cb_arg, status);
|
||||
}
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
@ -433,7 +435,7 @@ subsystem_state_change_on_pg(struct spdk_io_channel_iter *i)
|
||||
spdk_for_each_channel_continue(i, rc);
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
spdk_nvmf_subsystem_state_change(struct spdk_nvmf_subsystem *subsystem,
|
||||
enum spdk_nvmf_subsystem_state requested_state,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
@ -459,21 +461,18 @@ spdk_nvmf_subsystem_state_change(struct spdk_nvmf_subsystem *subsystem,
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
cb_fn(subsystem, cb_arg, -EINVAL);
|
||||
return;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
if (!ctx) {
|
||||
cb_fn(subsystem, cb_arg, -ENOMEM);
|
||||
return;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = spdk_nvmf_subsystem_set_state(subsystem, intermediate_state);
|
||||
if (rc) {
|
||||
free(ctx);
|
||||
cb_fn(subsystem, cb_arg, -1);
|
||||
return;
|
||||
return rc;
|
||||
}
|
||||
|
||||
ctx->subsystem = subsystem;
|
||||
@ -485,38 +484,40 @@ spdk_nvmf_subsystem_state_change(struct spdk_nvmf_subsystem *subsystem,
|
||||
subsystem_state_change_on_pg,
|
||||
ctx,
|
||||
subsystem_state_change_done);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg)
|
||||
{
|
||||
spdk_nvmf_subsystem_state_change(subsystem, SPDK_NVMF_SUBSYSTEM_ACTIVE, cb_fn, cb_arg);
|
||||
return spdk_nvmf_subsystem_state_change(subsystem, SPDK_NVMF_SUBSYSTEM_ACTIVE, cb_fn, cb_arg);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
spdk_nvmf_subsystem_stop(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg)
|
||||
{
|
||||
spdk_nvmf_subsystem_state_change(subsystem, SPDK_NVMF_SUBSYSTEM_INACTIVE, cb_fn, cb_arg);
|
||||
return spdk_nvmf_subsystem_state_change(subsystem, SPDK_NVMF_SUBSYSTEM_INACTIVE, cb_fn, cb_arg);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
spdk_nvmf_subsystem_pause(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg)
|
||||
{
|
||||
spdk_nvmf_subsystem_state_change(subsystem, SPDK_NVMF_SUBSYSTEM_PAUSED, cb_fn, cb_arg);
|
||||
return spdk_nvmf_subsystem_state_change(subsystem, SPDK_NVMF_SUBSYSTEM_PAUSED, cb_fn, cb_arg);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
spdk_nvmf_subsystem_resume(struct spdk_nvmf_subsystem *subsystem,
|
||||
spdk_nvmf_subsystem_state_change_done cb_fn,
|
||||
void *cb_arg)
|
||||
{
|
||||
spdk_nvmf_subsystem_state_change(subsystem, SPDK_NVMF_SUBSYSTEM_ACTIVE, cb_fn, cb_arg);
|
||||
return spdk_nvmf_subsystem_state_change(subsystem, SPDK_NVMF_SUBSYSTEM_ACTIVE, cb_fn, cb_arg);
|
||||
}
|
||||
|
||||
struct spdk_nvmf_subsystem *
|
||||
|
Loading…
Reference in New Issue
Block a user