From: Ian Jackson <Ian.Jackson@eu.citrix.com>
To: Paul Durrant <paul.durrant@citrix.com>
Cc: xen-devel@lists.xenproject.org, Wei Liu <wei.liu2@citrix.com>,
Ian Campbell <Ian.Campbell@citrix.com>
Subject: Re: [PATCH v2 2/3] libxl: check for underlying xenstore operation failure...
Date: Tue, 24 Nov 2015 16:48:58 +0000 [thread overview]
Message-ID: <22100.38138.259001.703812@mariner.uk.xensource.com> (raw)
In-Reply-To: <1447682423-1638-3-git-send-email-paul.durrant@citrix.com>
(Added CC to Ian C and Wei.)
Paul Durrant writes ("[Xen-devel] [PATCH v2 2/3] libxl: check for underlying xenstore operation failure..."):
> ...in libxl__xs_writev_perms() and libxl__xs_printf()
Thanks for looking at this.
> ERROR_FAIL is returned when any underlying operation fails. This is a
> semantic change in the case of a vasprintf() failure in libxl__xs_printf(),
> but appears to be better than returning a hardcoded -1.
This is what libxl__alloc_failed is for. But, surely it would be
better to replace the call to vasprintf with one to libxl__vsprintf ?
> path = libxl__sprintf(gc, "%s/%s", dir, kvs[i]);
> if (path && kvs[i + 1]) {
> int length = strlen(kvs[i + 1]);
> - xs_write(ctx->xsh, t, path, kvs[i + 1], length);
> - if (perms)
> - xs_set_permissions(ctx->xsh, t, path, perms, num_perms);
> + if (!xs_write(ctx->xsh, t, path, kvs[i + 1], length))
> + return ERROR_FAIL;
This is a good change semantically but I'm not keen on this error
handling style. CODING_STYLE says:
* Function calls which might fail (ie most function calls) are
handled by putting the return/status value into a variable, and
then checking it in a separate statement:
char *dompath = libxl__xs_get_dompath(gc, bl->domid);
if (!dompath) { rc = ERROR_FAIL; goto out; }
In this case the libxenstore return value variable should be called
`r', I think. CODING_STYLE says:
int r; /* the return value from a system call (or libxc call) */
> + if (perms &&
> + !xs_set_permissions(ctx->xsh, t, path, perms, num_perms))
> + return ERROR_FAIL;
And this is worse, I'm afraid. Nested ifs are not expensive and there
is no risk of overloading the compiler. So I would like to see this:
if (perms) {
r = xs_set ...
if (r) ...
}
I won't insist on you changing the error exits to use `goto out',
although I tend to think that would be better.
Thanks,
Ian.
next prev parent reply other threads:[~2015-11-24 16:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-16 14:00 [PATCH v2 0/3] libxl: xenstore related cleanup Paul Durrant
2015-11-16 14:00 ` [PATCH v2 1/3] libxl: re-name libxl__xs_write() to libxl__xs_printf() Paul Durrant
2015-11-16 17:15 ` Ian Jackson
2015-11-24 16:22 ` Ian Campbell
2015-11-25 11:27 ` Paul Durrant
2015-11-16 14:00 ` [PATCH v2 2/3] libxl: check for underlying xenstore operation failure Paul Durrant
2015-11-24 16:48 ` Ian Jackson [this message]
2015-11-24 17:24 ` Paul Durrant
2015-11-16 14:00 ` [PATCH v2 3/3] libxl: stop using libxl__xs_mkdir() for ~/control/shutdown Paul Durrant
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=22100.38138.259001.703812@mariner.uk.xensource.com \
--to=ian.jackson@eu.citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=paul.durrant@citrix.com \
--cc=wei.liu2@citrix.com \
--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 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.