All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Christie <mchristi@redhat.com>
To: target-devel@vger.kernel.org
Subject: Re: Reporting of errors detected by handler_read() before it returns
Date: Thu, 01 Aug 2019 16:18:47 +0000	[thread overview]
Message-ID: <5D4310E7.5020701@redhat.com> (raw)

Sorry for the late reply. Maybe add a tcmu prefix to the subject next time.

On 07/23/2019 09:07 PM, David Butterfield wrote:
> In tcmu-runner.h some comments in struct tcmur_handler say 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 return TCMU_STS_OK after calling
> cmd->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_RESOURCE anyway, perhaps it is also
> permitted to simply return other errors directly from the callout function, always omitting
> the call to cmd->done() when TCMU_STS_OK is not returned.
> 
> However, the code in file_example.c does not do either of those things, and directly
> violates the comment in tcmu-runner.h -- this excerpt is from file_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;
> 
> The file_read() function operates synchronously, and never issues a call to cmd->done()
> for successful reads returning TCMU_STS_OK, contradicting the comment in tcmu-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 any TCMU_STS_error directly from the function and
> omit the call to cmd->done() whenever returning TCMU_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.

             reply	other threads:[~2019-08-01 16:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-01 16:18 Mike Christie [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-07-24  2:07 Reporting of errors detected by handler_read() before it returns David Butterfield

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5D4310E7.5020701@redhat.com \
    --to=mchristi@redhat.com \
    --cc=target-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.