Reporting of errors detected by handler_read() before it returns
Sorry for the late reply. Maybe add a tcmu prefix to the subject next time.
Quoted 44 lines · David Butterfield
In
tcmu-runner.hsome comments in structtcmur_handlersay this:/* * Below callbacks are only executed by generic_handle_cmd. * Returns: * - TCMU_STS_OK if the handler has queued the command. * - TCMU_STS_NO_RESOURCE if the handler was not able to allocate * resources for the command. * * If TCMU_STS_OK is returned from the callout the handler must call * the tcmulib_cmd->done function with TCMU_STS return code. */ rw_fn_t write; rw_fn_t read; flush_fn_t flush; unmap_fn_t unmap;It is not clear what the handler should do if it detects a non-resource error, processing one of those command types, before returning from the handler's callout function.
The comment appears to say that
rhandler->write()could returnTCMU_STS_OKafter callingcmd->done(..., TCMU_STS_error)(so callers should be warned that the completion can occur before the request call returns).But given that the caller has to check for
TCMU_STS_NO_RESOURCEanyway, perhaps it is also permitted to simply return other errors directly from the callout function, always omitting the call tocmd->done()whenTCMU_STS_OKis not returned.However, the code in
file_example.cdoes not do either of those things, and directly violates the comment intcmu-runner.h-- this excerpt is fromfile_read():while (remaining) { ret = preadv(state->fd, iov, iov_cnt, offset); if (ret < 0) { tcmu_err("read failed: %m\n"); ret = TCMU_STS_RD_ERR; goto done; } ... } ret = TCMU_STS_OK; done: return ret;
Quoted 8 lines
The
file_read()function operates synchronously, and never issues a call tocmd->done()for successful reads returningTCMU_STS_OK, contradicting the comment intcmu-runner.h.Assuming the function is required to call
cmd->done()for a successful operation, a question remains which of these solutions is more correct or preferred. (I would prefer the first one be allowed -- to return anyTCMU_STS_errordirectly from the function and omit the call tocmd->done()whenever returningTCMU_STS_OK.)
Update your tcmu-runner git repo :)
A little bit ago, the comments in tcmu-runner.h were updated to make it clear what type of handler can do what, and also support for not having to call cmd->done in handlers like file_example was added.