From: Liu Yuan <namei.unix@gmail.com>
To: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Cc: Kevin Wolf <kwolf@redhat.com>,
sheepdog@lists.wpkg.org, mitake.hitoshi@gmail.com,
MORITA Kazutaka <morita.kazutaka@gmail.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/2] sheepdog: improve error handling for a case of failed lock
Date: Fri, 8 Aug 2014 14:43:16 +0800 [thread overview]
Message-ID: <20140808064316.GF12057@ubuntu-trusty> (raw)
In-Reply-To: <87tx5nzeqw.wl%mitake.hitoshi@lab.ntt.co.jp>
On Fri, Aug 08, 2014 at 03:17:59PM +0900, Hitoshi Mitake wrote:
> At Fri, 8 Aug 2014 13:31:39 +0800,
> Liu Yuan wrote:
> >
> > On Thu, Aug 07, 2014 at 04:28:40PM +0900, Hitoshi Mitake wrote:
> > > Recently, sheepdog revived its VDI locking functionality. This patch
> > > updates sheepdog driver of QEMU for this feature:
> > >
> > > 1. Improve error message when QEMU fails to acquire lock of
> > > VDI. Current sheepdog driver prints an error message "VDI isn't
> > > locked" when it fails to acquire lock. It is a little bit confusing
> > > because the mesage says VDI isn't locked but it is actually locked by
> > > other VM. This patch modifies this confusing message.
> > >
> > > 2. Change error code for a case of failed locking. -EBUSY is a
> > > suitable one.
> > >
> > > Reported-by: Valerio Pachera <sirio81@gmail.com>
> > > Cc: Kevin Wolf <kwolf@redhat.com>
> > > Cc: Stefan Hajnoczi <stefanha@redhat.com>
> > > Cc: Liu Yuan <namei.unix@gmail.com>
> > > Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
> > > Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
> > > ---
> > > block/sheepdog.c | 4 ++++
> > > 1 file changed, 4 insertions(+)
> > >
> > > diff --git a/block/sheepdog.c b/block/sheepdog.c
> > > index 36f76f0..0b3f86d 100644
> > > --- a/block/sheepdog.c
> > > +++ b/block/sheepdog.c
> > > @@ -1112,9 +1112,13 @@ static int find_vdi_name(BDRVSheepdogState *s, const char *filename,
> > >
> > > if (rsp->result != SD_RES_SUCCESS) {
> > > error_setg(errp, "cannot get vdi info, %s, %s %" PRIu32 " %s",
> > > + rsp->result == SD_RES_VDI_NOT_LOCKED ?
> >
> > I'm puzzled by this check.
> >
> > we use SD_RES_VDI_LOCKED to indicate vid is already locked, no?
>
> We use SD_RES_VDI_NOT_LOCKED for indicating locking by this VM fails.
>
> >
> > > + "VDI is already locked by other VM" :
But this message said it was locked by others, and we have SD_RES_VDI_LOCKED for
this case.
We need fix sheep daemon for this case to return SD_RES_VDI_LOCKED for already
locked case and NOT_LOCKED for other sheep internal errors.
> > > sd_strerror(rsp->result), filename, snapid, tag);
> > > if (rsp->result == SD_RES_NO_VDI) {
> > > ret = -ENOENT;
> > > + } else if (rsp->result == SD_RES_VDI_NOT_LOCKED) {
> > > + ret = -EBUSY;
> > > } else {
> > > ret = -EIO;
> > > }
> >
> > It is better to use switch case to handle the result.
>
> using switch statement in this case only increases a number of lines
> of code:
>
> Current change:
> if (rsp->result == SD_RES_NO_VDI) {
> ret = -ENOENT;
> } else if (rsp->result == SD_RES_VDI_NOT_LOCKED) {
> ...
>
> Change with switch:
> switch (rsp->result) {
> case SD_RES_NO_VDI:
> ret = -ENOENT;
> break;
> case SD_RES_VDI_NOT_LOCKED:
> ...
>
> The change with switch statement requires one more line for break;. I
> think if statement is suitable for this case.
If you insist on 'if-else' over swtich case, it is fine with me. But I'd suggest
switch-case because it looks cleaner and easier to understand if we have more
than 2 branches.
Thanks
Yuan
next prev parent reply other threads:[~2014-08-08 6:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-07 7:28 [Qemu-devel] [PATCH 0/2] sheepdog driver update related to VDI locking feature Hitoshi Mitake
2014-08-07 7:28 ` [Qemu-devel] [PATCH 1/2] sheepdog: adopting protocol update for VDI locking Hitoshi Mitake
2014-08-08 5:20 ` Liu Yuan
2014-08-08 6:12 ` Hitoshi Mitake
2014-08-08 7:49 ` Liu Yuan
2014-08-11 2:17 ` Hitoshi Mitake
2014-08-11 3:34 ` Liu Yuan
2014-08-11 3:43 ` Liu Yuan
2014-08-07 7:28 ` [Qemu-devel] [PATCH 2/2] sheepdog: improve error handling for a case of failed lock Hitoshi Mitake
2014-08-08 5:31 ` Liu Yuan
2014-08-08 6:17 ` Hitoshi Mitake
2014-08-08 6:43 ` Liu Yuan [this message]
2014-08-11 2:35 ` Hitoshi Mitake
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=20140808064316.GF12057@ubuntu-trusty \
--to=namei.unix@gmail.com \
--cc=kwolf@redhat.com \
--cc=mitake.hitoshi@gmail.com \
--cc=mitake.hitoshi@lab.ntt.co.jp \
--cc=morita.kazutaka@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=sheepdog@lists.wpkg.org \
--cc=stefanha@redhat.com \
/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).