From: Jim Fehlig <jfehlig@novell.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] xl: Return error when no userdata exists
Date: Thu, 27 Jan 2011 12:10:12 -0700 [thread overview]
Message-ID: <4D41C314.4040203@novell.com> (raw)
In-Reply-To: <19777.49190.822476.585064@mariner.uk.xensource.com>
Ian Jackson wrote:
> Jim Fehlig writes ("[Xen-devel] [PATCH] xl: Return error when no userdata exists"):
>
>> xl: Return error when no userdata exists
>>
>> The libvirt libxenlight driver will store its own userdata with
>> id 'libvirt-xml', but currently libxl_userdata_retrieve() does
>> not fail on non-existent userdata due to inverted error check.
>>
>
> Nonexistent userdata is the same as zero-length userdata, according to
> the specification. From libxl.h:
>
> int libxl_userdata_store(libxl_ctx *ctx, uint32_t domid,
> const char *userdata_userid,
> const uint8_t *data, int datalen);
> /* If datalen==0, data is not used and the user data for
> * that domain and userdata_userid is deleted. */
>
> int libxl_userdata_retrieve(libxl_ctx *ctx, uint32_t domid,
> const char *userdata_userid,
> uint8_t **data_r, int *datalen_r);
> /* On successful return, *data_r is from malloc.
> * If there is no data for that domain and userdata_userid,
> * *data_r and *datalen_r will be set to 0.
> * data_r and datalen_r may be 0.
> * On error return, *data_r and *datalen_r are undefined.
> */
>
> So I think to detect absence of userdata you should be checking
> *data_r or *datalen_r on successful return from
> libxl_userdata_retrieve.
>
Okay.
> You are however correct in that there is a bug in the error handling:
> if libxl_read_file_contents fails (ie, e!=0) for a reason other than
> ENOENT, libxl_userdata_retrieve improperly ignores it.
>
Right.
> I think the patch below fixes this.
>
> Do you agree ?
>
Yes.
Acked-by: Jim Fehlig <jfehlig@novell.com>
Thanks,
Jim
> Thanks,
> Ian.
>
>
> libxl: correct error path in libxl_userdata_retrieve
>
> Firstly, if libxl_read_file_contents fails, it doesn't really leave
> *data and *datalen_r undefined - it leaves them unchanged. Tighten up
> the spec for the benefit of libxl_userdata_retrieve.
>
> Secondly, libxl_userdata_retrieve ignored errors, assuming they were
> all ENOENT. Instead it should fail on unexpected errors.
>
> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
>
>
> diff -r 6067a17114bc tools/libxl/libxl_dom.c
> --- a/tools/libxl/libxl_dom.c Thu Jan 27 16:17:27 2011 +0000
> +++ b/tools/libxl/libxl_dom.c Thu Jan 27 18:55:41 2011 +0000
> @@ -671,7 +671,10 @@ int libxl_userdata_retrieve(libxl_ctx *c
> }
>
> e = libxl_read_file_contents(ctx, filename, data_r ? &data : 0, &datalen);
> -
> + if (e && errno != ENOENT) {
> + rc = ERROR_FAIL;
> + goto out;
> + }
> if (!e && !datalen) {
> LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "userdata file %s is empty", filename);
> if (data_r) assert(!*data_r);
> diff -r 6067a17114bc tools/libxl/libxl_utils.h
> --- a/tools/libxl/libxl_utils.h Thu Jan 27 16:17:27 2011 +0000
> +++ b/tools/libxl/libxl_utils.h Thu Jan 27 18:55:41 2011 +0000
> @@ -36,7 +36,7 @@ int libxl_read_file_contents(libxl_ctx *
> /* Reads the contents of the plain file filename into a mallocd
> * buffer. Returns 0 or errno. Any errors other than ENOENT are logged.
> * If the file is empty, *data_r and *datalen_r are set to 0.
> - * On error, *data_r and *datalen_r are undefined.
> + * On error, *data_r and *datalen_r are unchanged.
> * data_r and/or datalen_r may be 0.
> */
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>
next prev parent reply other threads:[~2011-01-27 19:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-27 17:34 [PATCH] xl: Return error when no userdata exists Jim Fehlig
2011-01-27 18:57 ` Ian Jackson
2011-01-27 19:10 ` Jim Fehlig [this message]
2011-01-28 16:44 ` Ian Jackson
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=4D41C314.4040203@novell.com \
--to=jfehlig@novell.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=xen-devel@lists.xensource.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 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.