From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: Juergen Gross <jgross@suse.com>,
linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org
Subject: Re: [PATCH 2/3] xen: return xenstore command failures via response instead of rc
Date: Thu, 22 Dec 2016 10:49:21 -0500 [thread overview]
Message-ID: <9dc05fb2-cb84-d8e7-848b-37fb9c86b782@oracle.com> (raw)
In-Reply-To: <20161222071948.23862-3-jgross@suse.com>
On 12/22/2016 02:19 AM, Juergen Gross wrote:
> When the xenbus driver does some special handling for a Xenstore
> command any error condition related to the command should be returned
> via an error response instead of letting the related write operation
> fail. Otherwise the user land handler might take wrong decisions
> assuming the connection to Xenstore is broken.
Do we expect the user to always read the reply if no error code was
returned?
-boris
>
> While at it try to return the same error values xenstored would
> return for those cases.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
> drivers/xen/xenbus/xenbus_dev_frontend.c | 47 ++++++++++++++++++--------------
> 1 file changed, 27 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
> index a068281..79130b3 100644
> --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
> +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
> @@ -302,6 +302,29 @@ static void watch_fired(struct xenbus_watch *watch,
> mutex_unlock(&adap->dev_data->reply_mutex);
> }
>
> +static int xenbus_command_reply(struct xenbus_file_priv *u,
> + unsigned int msg_type, const char *reply)
> +{
> + struct {
> + struct xsd_sockmsg hdr;
> + const char body[16];
> + } msg;
> + int rc;
> +
> + msg.hdr = u->u.msg;
> + msg.hdr.type = msg_type;
> + msg.hdr.len = strlen(reply) + 1;
> + if (msg.hdr.len > sizeof(msg.body))
> + return -E2BIG;
> +
> + mutex_lock(&u->reply_mutex);
> + rc = queue_reply(&u->read_buffers, &msg, sizeof(msg.hdr) + msg.hdr.len);
> + wake_up(&u->read_waitq);
> + mutex_unlock(&u->reply_mutex);
> +
> + return rc;
> +}
> +
> static int xenbus_write_transaction(unsigned msg_type,
> struct xenbus_file_priv *u)
> {
> @@ -321,7 +344,7 @@ static int xenbus_write_transaction(unsigned msg_type,
> if (trans->handle.id == u->u.msg.tx_id)
> break;
> if (&trans->list == &u->transactions)
> - return -ESRCH;
> + return xenbus_command_reply(u, XS_ERROR, "ENOENT");
> }
>
> reply = xenbus_dev_request_and_reply(&u->u.msg);
> @@ -372,12 +395,12 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
> path = u->u.buffer + sizeof(u->u.msg);
> token = memchr(path, 0, u->u.msg.len);
> if (token == NULL) {
> - rc = -EILSEQ;
> + rc = xenbus_command_reply(u, XS_ERROR, "EINVAL");
> goto out;
> }
> token++;
> if (memchr(token, 0, u->u.msg.len - (token - path)) == NULL) {
> - rc = -EILSEQ;
> + rc = xenbus_command_reply(u, XS_ERROR, "EINVAL");
> goto out;
> }
>
> @@ -411,23 +434,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
> }
>
> /* Success. Synthesize a reply to say all is OK. */
> - {
> - struct {
> - struct xsd_sockmsg hdr;
> - char body[3];
> - } __packed reply = {
> - {
> - .type = msg_type,
> - .len = sizeof(reply.body)
> - },
> - "OK"
> - };
> -
> - mutex_lock(&u->reply_mutex);
> - rc = queue_reply(&u->read_buffers, &reply, sizeof(reply));
> - wake_up(&u->read_waitq);
> - mutex_unlock(&u->reply_mutex);
> - }
> + rc = xenbus_command_reply(u, msg_type, "OK");
>
> out:
> return rc;
next prev parent reply other threads:[~2016-12-22 15:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-22 7:19 [PATCH 0/3] xen: fix some minor bugs and cleanup of xenbus Juergen Gross
2016-12-22 7:19 ` [PATCH 1/3] xen: xenbus driver must not accept invalid transaction ids Juergen Gross
2016-12-22 15:38 ` Boris Ostrovsky
2016-12-22 15:51 ` Juergen Gross
2016-12-22 7:19 ` [PATCH 2/3] xen: return xenstore command failures via response instead of rc Juergen Gross
2016-12-22 15:49 ` Boris Ostrovsky [this message]
2016-12-22 15:55 ` Juergen Gross
2016-12-22 16:00 ` Boris Ostrovsky
2016-12-22 7:19 ` [PATCH 3/3] xen: remove stale xs_input_avail() from header Juergen Gross
2016-12-22 15:50 ` Boris Ostrovsky
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=9dc05fb2-cb84-d8e7-848b-37fb9c86b782@oracle.com \
--to=boris.ostrovsky@oracle.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xen-devel@lists.xenproject.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).