tools/libxc: fix error handling in xc_mem_paging_load
A message that is not in the archive (sent off-list or not yet received): [email protected]
Andres Lagar-Cavilla
Acked-byQuoted 20 lines
Date: Wed, 18 Jan 2012 18:15:24 +0100
From: Olaf Hering <[email protected]>
To: [email protected]
Subject: [Xen-devel] [PATCH]tools/libxc: fix error handling in
xc_mem_paging_load
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1326906775 -3600
# Node ID1821b0e1ce16d0015542d4164505d97f130f09d7# Parent15ab61865ecbd146f6ce65fbea5bf49bfd9c6cb1tools/libxc: fix error handling inxc_mem_paging_load
xc_mem_paging_load()does not pass errors in errno and the actual errno fromxc_mem_event_control()is overwritten bymunlock().xenpaging_populate_page()needs to check errno, but with the switch toxc_mem_paging_load()it could not receive ENOMEM anymore.
Quoted 4 lines
Update
xc_mem_paging_load()to return -1 and preserve errno duringmunlock().Signed-off-by Olaf Hering <[email protected]>
Quoted 320 lines
diff -r
15ab61865ecb-r1821b0e1ce16tools/libxc/xc_mem_paging.ctools/libxc/xc_mem_paging.c +10
-6@@ -68,23 +68,28 @@ int xc_mem_paging_prep(xc_interface *xchint xc_mem_paging_load (xc_interface *xch,domid_t domain_id,unsigned long gfn,void *buffer) { -int rc; +int rc, old_errno; + + errno = -EINVAL ;if ( !buffer ) -return -EINVAL ; +return -1 ;if ( ((unsigned long ) buffer) & (XC_PAGE_SIZE -1 ) ) -return -EINVAL ; +return -1 ;if (mlock (buffer,XC_PAGE_SIZE ) ) -return -errno; +return -1 ; rc =xc_mem_event_control (xch, domain_id,XEN_DOMCTL_MEM_EVENT_OP_PAGING_PREP ,XEN_DOMCTL_MEM_EVENT_OP_PAGING , buffer,NULL , gfn); - (void )munlock (buffer,XC_PAGE_SIZE ); + old_errno = errno; +munlock (buffer,XC_PAGE_SIZE ); + errno = old_errno; +return rc; } ------------------------------Message: 4
Date: Wed, 18 Jan 2012 17:13:31 +0000
From: Ian Jackson <[email protected]>
To: Ian Campbell <[email protected]>
Cc: Daniel De Graaf <[email protected]>,
"[email protected]" <[email protected]>
Subject: Re: [Xen-devel] [PATCH 13/18] xenstored: support running in
minios stubdom
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"Ian Campbell writes ("Re: [Xen-devel] [PATCH 13/18] xenstored: support running in minios stubdom"):
Review
Quoted 8 lines
One thing which might help is to provide nop versions of functions instead of idef'ing both the definition and callsite. e.g.
static voidwrite_pidfile(const char *pidfile)(quoted diff) +4
-0+#ifndef __MINIOS__ stuff +#else + nothing +endifI would normally prefer:
Review
Quoted 8 lines
(quoted diff) +5
-0+#ifndef __MINIOS__ static void write_pidfile(const char *pidfile) stuff } +#else +static void write_pidfile(const char *pidfile) +} +endifI think this is fairly easy to read; the only hard part is figuring out which version is being used, which can often be done by putting the relevant bits in a separate file.
Ian.
------------------------------
Message: 5
Date: Wed, 18 Jan 2012 17:33:24 +0000
From: Ian Campbell <[email protected]>
To: Ian Jackson <[email protected]>
Cc: "[email protected]" <[email protected]>
Subject: Re: [Xen-devel] [PATCH 3/9] libxl: New event generation API
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"Quoted 36 lines · Ian Jackson
Replace the existing API for retrieving high-level events (events about domains, etc.) from libxl with a new one.
This changes the definition and semantics of the `libxl_event' structure, and replaces the calls for obtaining information about domain death and disk eject events.
This is an incompatible change, sorry. The alternative was to try to provide both the previous horrid API and the new one, and would also involve never using the name `libxl_event' for the new interface.
The new "
libxl_event" structure is blacklisted in the ocaml bindings for two reasons:
- It has a field name "type" (which is a keyword in ocaml); the ocaml idl generator should massage this field name on output, to "type_" perhaps.
- The ocaml idl generator does not support KeyedUnion.Signed-off-by Ian Jackson <[email protected]>--- tools/libxl/libxl.c | 329 +++++++++++++++++++++++++++++----------- tools/libxl/libxl.h | 55 +------ tools/libxl/libxl_event.c | 236 ++++++++++++++++++++++++++--- tools/libxl/libxl_event.h | 183 ++++++++++++++++++++++- tools/libxl/libxl_internal.h | 77 +++++++++- tools/libxl/libxl_types.idl | 34 ++++- tools/libxl/xl_cmdimpl.c | 270 +++++++++++++++++++-------------- tools/ocaml/libs/xl/genwrap.py | 1 + 8 files changed, 908 insertions(+), 277 deletions(-)tools/libxl/libxl.c +0
-0tools/libxl/libxl.c int libxl_ctx_free(libxl_ctx *ctx) · line 123
Quoted 9 lines
tools/libxl/libxl.c +6
-0@@ -95,6 +115,13 @@ int libxl_ctx_free(libxl_ctx *ctx)/* Deregister all libxl__ev_KINDs: */ +free_disable_deaths (gc, &CTX ->death_list); +free_disable_deaths (gc, &CTX ->death_reported); + +libxl_evgen_disk_eject *eject; +while ((eject =LIBXL_LIST_FIRST (&CTX ->disk_eject_evgens))) +libxl__evdisable_disk_eject (gc, eject);Why a helper for deaths but not ejects?
[...]
Quoted 38 lines
tools/libxl/libxl_event.c +0
-0/* tools/libxl/libxl_event.h +10
-0+#define LIBXL_EVENTMASK_ALL (~(unsigned long)0) + +typedef int libxl_event_predicate (const libxl_event *,void *user); +/* Return value is 0 if the event is unwanted or non-0 if it is. +* Predicates are not allowed to fail. +*/ + +int libxl_event_check (libxl_ctx *ctx,libxl_event **event_r, +unsigned long typemask, + libxl_event_predicate *predicate, void
*predicate_user);tools/libxl/libxl_event.h +11
-0+/* Searches for an event, already-happened, which matches typemask +* and predicate. predicate==0 matches any event. +* libxl_event_check returns the event, which must then later be +* freed by the caller using libxl_event_free. +* +* Returns ERROR_NOT_READY if no such event has happened. +*/ + +int libxl_event_wait (libxl_ctx *ctx,libxl_event **event_r, +unsigned long typemask, + libxl_event_predicate *predicate, void
*predicate_user);tools/libxl/libxl_event.h +3
-0+/* Like libxl_event_check but blocks if no suitable events are +* available, until some are. Uses libxl_osevent_beforepoll/ +* _afterpoll so may be inefficient if very many domains are being tools/libxl/libxl_event.h
Quoted 10 lines
tools/libxl/libxl_event.h +10
-0+* handled by a single program. +*/ + +void libxl_event_free (libxl_ctx *ctx,libxl_event *event); + + +/* Alternatively or additionally, the application may also use this: */ + +typedef struct libxl_event_hooks { + uint64_t event_occurs_mask;libxl_event_{wait,check} and
LIBXL_EVENTMASK_ALLhave an unsigned long mask. Are they not the same set of bits?[...]
Quoted 5 lines
+ * The user value is returned in the generated events and may be
+ * used by the caller for whatever it likes. The typeev_useris
+ * guaranteed to be an unsigned integer type which is at least
+ * as big asuint64_tand is also guaranteed to be big enough to
+ * contain anyintptr_tvalue.Does anything actually guarantee that
sizeof(uint64_t)>sizeof(intptr_t)? I'm sure it's true in practice and I'm happy to rely on it. Just interested.Quoted 5 lines
+ *[...]
+ * Applications should ensure that they eventually retrieve every
+ * event usinglibxl_event_checkorlibxl_event_wait, since events
+ * which occur but are not retreived by the application will be queuedretrieved
Quoted 4 lines
+ * inside libxl indefinitely. libxl_event_check/_wait may be O(n)
+ * where n is the number of queued events which do not match the
+ * criteria specified in the arguments to check/wait.
+ */[...]
Quoted 6 lines
tools/libxl/libxl_types.idl +0
-0@@ -395,3 +390,32 @@ libxl_sched_sedf = Struct("sched_sedf", [ ("extratime", integer),tools/libxl/libxl_types.idl libxl_sched_sedf = Struct("sched_sedf", [ · line 400
Quoted 10 lines
tools/libxl/libxl_types.idl +8
-0("weight", integer), ], dispose_fn=None) + +libxl_event_type = Enumeration("event_type", [ + (1, "DOMAIN_SHUTDOWN"), + (2, "DOMAIN_DESTROY"), + (3, "DISK_EJECT"), + ]) + +libxl_ev_user = UInt(64)The other option here would be Builtin(...) and an entry in the builtin table in the wrapper generator.
Arguably the idl could be improved by causing
Number()to have a width field. Currently it has a signedness and width is a property of UInt but the latter could be pushed up the hierarchy.You'd still end up with
FOO =Number("FOO", width=X)
which isn't really much better.Or the ocaml generate could handle Number as the biggest int.
Hrm. None of that seems all that much better than what you have. Chalk it up to potential future work.
tools/libxl/libxl_types.idl
Quoted 5 lines
tools/libxl/libxl_types.idl +1
-0+libxl_ev_link = Builtin("ev_link", passby=PASS_BY_REFERENCE,private=True)
tools/libxl/libxl_types.idl +3
-0+ +libxl_event = Struct("event",[ + ("link", libxl_ev_link,0),This "0" == "const=False" which is the default. I don't think it is necessary.
[...]
Quoted 9 lines
tools/libxl/xl_cmdimpl.c +0
-0@@ -1702,92 +1729,106 @@ start: }LOG ("Waiting for domain %s (domid %d) to die [pid %ld]" , d_config.c_info.name, domid, (long )getpid ());[...]
Quoted 3 lines
tools/libxl/xl_cmdimpl.c +2
-0+ ret =libxl_evenable_domain_death (ctx, domid,0 , &deathw); +if (ret) goto out;[...]
tools/libxl/xl_cmdimpl.c
Quoted 2 lines
tools/libxl/xl_cmdimpl.c +2
-0+if (!diskws) { + diskws =xmalloc (sizeof (*diskws) * d_config.num_disks);I didn't see this getting freed on the exit path.
tools/libxl/xl_cmdimpl.c
Quoted 9 lines
tools/libxl/xl_cmdimpl.c +5
-0+for (i =0 ; i < d_config.num_disks; i++) + diskws[i] =NULL ; + } +for (i =0 ; i < d_config.num_disks; i++) { + ret = libxl_evenable_disk_eject(ctx, domid,d_config.disks[i].vdev,
tools/libxl/xl_cmdimpl.c +3
-0+ 0, &diskws[i]); +if (ret) goto out; + }This is all (I think) safe for
num_disks== 0 but why waste the effort?Incidentally we have libxl_device_disk.removable which might be an opportunity to optimise? Assuming it is meaningful in that way. I think in reality only emulated CD-ROM devices ever generate this event but perhaps exposing that in the API overcomplicates things.
[...]
Ian.
------------------------------
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-develEnd of Xen-devel Digest, Vol 83, Issue 288
******************************************
Andres Lagar-Cavilla
Acked-byQuoted 20 lines
Date: Wed, 18 Jan 2012 18:15:24 +0100
From: Olaf Hering <[email protected]>
To: [email protected]
Subject: [Xen-devel] [PATCH]tools/libxc: fix error handling in
xc_mem_paging_load
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1326906775 -3600
# Node ID1821b0e1ce16d0015542d4164505d97f130f09d7# Parent15ab61865ecbd146f6ce65fbea5bf49bfd9c6cb1tools/libxc: fix error handling inxc_mem_paging_load
xc_mem_paging_load()does not pass errors in errno and the actual errno fromxc_mem_event_control()is overwritten bymunlock().xenpaging_populate_page()needs to check errno, but with the switch toxc_mem_paging_load()it could not receive ENOMEM anymore.
Quoted 4 lines
Update
xc_mem_paging_load()to return -1 and preserve errno duringmunlock().Signed-off-by Olaf Hering <[email protected]>
Bump on this one. It's a simple and necessary fix. And:
Thanks,
Andres
Quoted 320 lines
diff -r
15ab61865ecb-r1821b0e1ce16tools/libxc/xc_mem_paging.ctools/libxc/xc_mem_paging.c +10
-6@@ -68,23 +68,28 @@ int xc_mem_paging_prep(xc_interface *xchint xc_mem_paging_load (xc_interface *xch,domid_t domain_id,unsigned long gfn,void *buffer) { -int rc; +int rc, old_errno; + + errno = -EINVAL ;if ( !buffer ) -return -EINVAL ; +return -1 ;if ( ((unsigned long ) buffer) & (XC_PAGE_SIZE -1 ) ) -return -EINVAL ; +return -1 ;if (mlock (buffer,XC_PAGE_SIZE ) ) -return -errno; +return -1 ; rc =xc_mem_event_control (xch, domain_id,XEN_DOMCTL_MEM_EVENT_OP_PAGING_PREP ,XEN_DOMCTL_MEM_EVENT_OP_PAGING , buffer,NULL , gfn); - (void )munlock (buffer,XC_PAGE_SIZE ); + old_errno = errno; +munlock (buffer,XC_PAGE_SIZE ); + errno = old_errno; +return rc; } ------------------------------Message: 4
Date: Wed, 18 Jan 2012 17:13:31 +0000
From: Ian Jackson <[email protected]>
To: Ian Campbell <[email protected]>
Cc: Daniel De Graaf <[email protected]>,
"[email protected]" <[email protected]>
Subject: Re: [Xen-devel] [PATCH 13/18] xenstored: support running in
minios stubdom
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"Ian Campbell writes ("Re: [Xen-devel] [PATCH 13/18] xenstored: support running in minios stubdom"):
Review
Quoted 8 lines
One thing which might help is to provide nop versions of functions instead of idef'ing both the definition and callsite. e.g.
static voidwrite_pidfile(const char *pidfile)(quoted diff) +4
-0+#ifndef __MINIOS__ stuff +#else + nothing +endifI would normally prefer:
Review
Quoted 8 lines
(quoted diff) +5
-0+#ifndef __MINIOS__ static void write_pidfile(const char *pidfile) stuff } +#else +static void write_pidfile(const char *pidfile) +} +endifI think this is fairly easy to read; the only hard part is figuring out which version is being used, which can often be done by putting the relevant bits in a separate file.
Ian.
------------------------------
Message: 5
Date: Wed, 18 Jan 2012 17:33:24 +0000
From: Ian Campbell <[email protected]>
To: Ian Jackson <[email protected]>
Cc: "[email protected]" <[email protected]>
Subject: Re: [Xen-devel] [PATCH 3/9] libxl: New event generation API
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"Quoted 36 lines · Ian Jackson
Replace the existing API for retrieving high-level events (events about domains, etc.) from libxl with a new one.
This changes the definition and semantics of the `libxl_event' structure, and replaces the calls for obtaining information about domain death and disk eject events.
This is an incompatible change, sorry. The alternative was to try to provide both the previous horrid API and the new one, and would also involve never using the name `libxl_event' for the new interface.
The new "
libxl_event" structure is blacklisted in the ocaml bindings for two reasons:
- It has a field name "type" (which is a keyword in ocaml); the ocaml idl generator should massage this field name on output, to "type_" perhaps.
- The ocaml idl generator does not support KeyedUnion.Signed-off-by Ian Jackson <[email protected]>--- tools/libxl/libxl.c | 329 +++++++++++++++++++++++++++++----------- tools/libxl/libxl.h | 55 +------ tools/libxl/libxl_event.c | 236 ++++++++++++++++++++++++++--- tools/libxl/libxl_event.h | 183 ++++++++++++++++++++++- tools/libxl/libxl_internal.h | 77 +++++++++- tools/libxl/libxl_types.idl | 34 ++++- tools/libxl/xl_cmdimpl.c | 270 +++++++++++++++++++-------------- tools/ocaml/libs/xl/genwrap.py | 1 + 8 files changed, 908 insertions(+), 277 deletions(-)tools/libxl/libxl.c +0
-0tools/libxl/libxl.c int libxl_ctx_free(libxl_ctx *ctx) · line 123
Quoted 9 lines
tools/libxl/libxl.c +6
-0@@ -95,6 +115,13 @@ int libxl_ctx_free(libxl_ctx *ctx)/* Deregister all libxl__ev_KINDs: */ +free_disable_deaths (gc, &CTX ->death_list); +free_disable_deaths (gc, &CTX ->death_reported); + +libxl_evgen_disk_eject *eject; +while ((eject =LIBXL_LIST_FIRST (&CTX ->disk_eject_evgens))) +libxl__evdisable_disk_eject (gc, eject);Why a helper for deaths but not ejects?
[...]
Quoted 38 lines
tools/libxl/libxl_event.c +0
-0/* tools/libxl/libxl_event.h +10
-0+#define LIBXL_EVENTMASK_ALL (~(unsigned long)0) + +typedef int libxl_event_predicate (const libxl_event *,void *user); +/* Return value is 0 if the event is unwanted or non-0 if it is. +* Predicates are not allowed to fail. +*/ + +int libxl_event_check (libxl_ctx *ctx,libxl_event **event_r, +unsigned long typemask, + libxl_event_predicate *predicate, void
*predicate_user);tools/libxl/libxl_event.h +11
-0+/* Searches for an event, already-happened, which matches typemask +* and predicate. predicate==0 matches any event. +* libxl_event_check returns the event, which must then later be +* freed by the caller using libxl_event_free. +* +* Returns ERROR_NOT_READY if no such event has happened. +*/ + +int libxl_event_wait (libxl_ctx *ctx,libxl_event **event_r, +unsigned long typemask, + libxl_event_predicate *predicate, void
*predicate_user);tools/libxl/libxl_event.h +3
-0+/* Like libxl_event_check but blocks if no suitable events are +* available, until some are. Uses libxl_osevent_beforepoll/ +* _afterpoll so may be inefficient if very many domains are being tools/libxl/libxl_event.h
Quoted 10 lines
tools/libxl/libxl_event.h +10
-0+* handled by a single program. +*/ + +void libxl_event_free (libxl_ctx *ctx,libxl_event *event); + + +/* Alternatively or additionally, the application may also use this: */ + +typedef struct libxl_event_hooks { + uint64_t event_occurs_mask;libxl_event_{wait,check} and
LIBXL_EVENTMASK_ALLhave an unsigned long mask. Are they not the same set of bits?[...]
Quoted 5 lines
+ * The user value is returned in the generated events and may be
+ * used by the caller for whatever it likes. The typeev_useris
+ * guaranteed to be an unsigned integer type which is at least
+ * as big asuint64_tand is also guaranteed to be big enough to
+ * contain anyintptr_tvalue.Does anything actually guarantee that
sizeof(uint64_t)>sizeof(intptr_t)? I'm sure it's true in practice and I'm happy to rely on it. Just interested.Quoted 5 lines
+ *[...]
+ * Applications should ensure that they eventually retrieve every
+ * event usinglibxl_event_checkorlibxl_event_wait, since events
+ * which occur but are not retreived by the application will be queuedretrieved
Quoted 4 lines
+ * inside libxl indefinitely. libxl_event_check/_wait may be O(n)
+ * where n is the number of queued events which do not match the
+ * criteria specified in the arguments to check/wait.
+ */[...]
Quoted 6 lines
tools/libxl/libxl_types.idl +0
-0@@ -395,3 +390,32 @@ libxl_sched_sedf = Struct("sched_sedf", [ ("extratime", integer),tools/libxl/libxl_types.idl libxl_sched_sedf = Struct("sched_sedf", [ · line 400
Quoted 10 lines
tools/libxl/libxl_types.idl +8
-0("weight", integer), ], dispose_fn=None) + +libxl_event_type = Enumeration("event_type", [ + (1, "DOMAIN_SHUTDOWN"), + (2, "DOMAIN_DESTROY"), + (3, "DISK_EJECT"), + ]) + +libxl_ev_user = UInt(64)The other option here would be Builtin(...) and an entry in the builtin table in the wrapper generator.
Arguably the idl could be improved by causing
Number()to have a width field. Currently it has a signedness and width is a property of UInt but the latter could be pushed up the hierarchy.You'd still end up with
FOO =Number("FOO", width=X)
which isn't really much better.Or the ocaml generate could handle Number as the biggest int.
Hrm. None of that seems all that much better than what you have. Chalk it up to potential future work.
tools/libxl/libxl_types.idl
Quoted 5 lines
tools/libxl/libxl_types.idl +1
-0+libxl_ev_link = Builtin("ev_link", passby=PASS_BY_REFERENCE,private=True)
tools/libxl/libxl_types.idl +3
-0+ +libxl_event = Struct("event",[ + ("link", libxl_ev_link,0),This "0" == "const=False" which is the default. I don't think it is necessary.
[...]
Quoted 9 lines
tools/libxl/xl_cmdimpl.c +0
-0@@ -1702,92 +1729,106 @@ start: }LOG ("Waiting for domain %s (domid %d) to die [pid %ld]" , d_config.c_info.name, domid, (long )getpid ());[...]
Quoted 3 lines
tools/libxl/xl_cmdimpl.c +2
-0+ ret =libxl_evenable_domain_death (ctx, domid,0 , &deathw); +if (ret) goto out;[...]
tools/libxl/xl_cmdimpl.c
Quoted 2 lines
tools/libxl/xl_cmdimpl.c +2
-0+if (!diskws) { + diskws =xmalloc (sizeof (*diskws) * d_config.num_disks);I didn't see this getting freed on the exit path.
tools/libxl/xl_cmdimpl.c
Quoted 9 lines
tools/libxl/xl_cmdimpl.c +5
-0+for (i =0 ; i < d_config.num_disks; i++) + diskws[i] =NULL ; + } +for (i =0 ; i < d_config.num_disks; i++) { + ret = libxl_evenable_disk_eject(ctx, domid,d_config.disks[i].vdev,
tools/libxl/xl_cmdimpl.c +3
-0+ 0, &diskws[i]); +if (ret) goto out; + }This is all (I think) safe for
num_disks== 0 but why waste the effort?Incidentally we have libxl_device_disk.removable which might be an opportunity to optimise? Assuming it is meaningful in that way. I think in reality only emulated CD-ROM devices ever generate this event but perhaps exposing that in the API overcomplicates things.
[...]
Ian.
------------------------------
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-develEnd of Xen-devel Digest, Vol 83, Issue 288
******************************************