xentoollog, libvchan: Minor improvements
v2 cover xentoollog, libvchan: Minor improvements
The point of this series is to make an API promise about what ENOENT means from libxenvchan_client_init, to make it easier to build async code on top of this (eg, libxl).
There is a lot of internal tidying, but also a necessary prefix is a change to xentoollog to make it OK to pass NULL for a logger. This allows elimination of all the duplicates of the default logger creation. (Otherwise we'd have to have added yet another dupe to libvchan.)
+ 01/11 tools/libs/toollog: Provide a default logger
+ 02/11 tools/libs/toollog: Use the default logger
+ 03/11 tools/libs/*: Rely on the default logger
a 04/11 tools/libvchan: Initialise xs_transaction_t to XBT_NULL, not NULL
a 05/11 tools/xenstore: Document that xs_close(0) is OK.
a 06/11 tools/libvchan: init_xs_srv: Simplify error handling (1)
a 07/11 tools/libvchan: init_xs_srv: Simplify error handling (2)
a 08/11 tools/libvchan: init_xs_srv: Turn xs retry from goto into for (;;)
a 09/11 tools/libvchan: Add xentoollog to direct dependencies
a 10/11 tools/libvchan: libxenvchan_*_init: Promise an errno
11/11 tools/libvchan: libxenvchan_client_init: use ENOENT for no server + new patch in v2
a acked by tools maintainer
tools/libs/call/core.c | 10 ----- tools/libs/call/private.h | 2 +- tools/libs/devicemodel/core.c | 11 ----- tools/libs/devicemodel/private.h | 2 +- tools/libs/evtchn/core.c | 10 ----- tools/libs/evtchn/private.h | 2 +- tools/libs/foreignmemory/core.c | 10 ----- tools/libs/foreignmemory/private.h | 2 +- tools/libs/gnttab/gntshr_core.c | 10 ----- tools/libs/gnttab/gnttab_core.c | 10 ----- tools/libs/gnttab/private.h | 2 +- tools/libs/toollog/Makefile | 2 +- tools/libs/toollog/include/xentoollog.h | 12 ++++-- tools/libs/toollog/libxentoollog.map | 5 +++ tools/libs/toollog/xtl_core.c | 7 ++++ tools/libs/toollog/xtl_logger_stdio.c | 26 ++++++++++++ tools/libvchan/Makefile | 6 +-- tools/libvchan/init.c | 72 +++++++++++++++++++-------------- tools/libvchan/libxenvchan.h | 8 +++- tools/libvchan/xenvchan.pc.in | 2 +- tools/xenstore/include/xenstore.h | 2 +- 21 files changed, 105 insertions(+), 108 deletions(-)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/11 tools/libs/toollog: Provide a default logger
This is most conveniently done like this because xtl_logger_stdio.c knows how to provide a static logger without doing any memory allocations. That's useful because it can't fail.
Add the new symbol to the map file and bump the minor version accordingly.
---
v2: New in this version of the series
--- tools/libs/toollog/Makefile | 2 +- tools/libs/toollog/include/xentoollog.h | 5 +++++ tools/libs/toollog/libxentoollog.map | 5 +++++ tools/libs/toollog/xtl_logger_stdio.c | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-)
tools/libs/toollog/Makefile +1 -1
@@ -2,7 +2,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 -MINOR = 0 +MINOR = 1 SHLIB_LDFLAGS += -Wl,--version-script=libxentoollog.map CFLAGS += -Werror -Wmissing-prototypes
tools/libs/toollog/include/xentoollog.h +5 -0
@@ -86,6 +86,11 @@ void xtl_stdiostream_adjust_flags(xentoollog_logger_stdiostream*,void xtl_logger_destroy (struct xentoollog_logger *logger/* 0 is ok */ ); +xentoollog_logger_stdiostream *xtl_defaultlogger_stdiostream (void ); +/* Returns pointer to a static global logger which writes to stderr. +* Reconfiguring it is permitted but destroying it is forbidden. +* This function cannot fail. */ +/*---------- facilities for generating log messages ----------*/ void xtl_logv(struct xentoollog_logger *logger,
tools/libs/toollog/libxentoollog.map +5 -0
@@ -10,3 +10,8 @@ VERS_1.0 { xtl_stdiostream_set_minlevel; local: *; /* Do not expose anything by default */ }; + +VERS_1.1 { + global: + xtl_defaultlogger_stdiostream; +} VERS_1.0;
tools/libs/toollog/xtl_logger_stdio.c +26 -0
@@ -28,6 +28,7 @@#include <stdlib.h> #include <errno.h> #include <stdbool.h> +#include <pthread.h> struct xentoollog_logger_stdiostream {xentoollog_logger vtable;
@@ -191,6 +192,31 @@ xentoollog_logger_stdiostream *xtl_createlogger_stdiostreamreturn XTL_NEW_LOGGER (stdiostream, newlogger); } +xentoollog_logger_stdiostream *xtl_defaultlogger_stdiostream (void ) { +static xentoollog_logger_stdiostream deflogger = { + .vtable = { + .vmessage = stdiostream_vmessage, + .progress = stdiostream_progress, + .destroy =0 ,/* no-one should destroy this */ + }, + .min_level =XTL_PROGRESS , +/* for other fields except .f, 0 is good */ + }; + +/* +* Unfortunately, stderr is not a `constant expression', so we +* can't handle it in the initialisation. Also we can't do a +* lockless assignment, even of the identical value, without +* violating threading rules. Nnng. +*/ +static pthread_mutex_t mutex =PTHREAD_MUTEX_INITIALIZER ; +pthread_mutex_lock (&mutex); + deflogger.f = stderr; +pthread_mutex_unlock (&mutex); + +return &deflogger; +}; +/* * Local variables: * mode: C
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 01/11] tools/libs/toollog: Provide a default logger
Quoted 82 lines · Ian Jackson
This is most conveniently done like this because
xtl_logger_stdio.cknows how to provide a static logger without doing any memory allocations. That's useful because it can't fail.Add the new symbol to the map file and bump the minor version accordingly.
Signed-off-by Ian Jackson <[email protected]>CC Wei Liu <[email protected]>---
v2: New in this version of the series--- tools/libs/toollog/Makefile | 2 +- tools/libs/toollog/include/xentoollog.h | 5 +++++ tools/libs/toollog/libxentoollog.map | 5 +++++ tools/libs/toollog/xtl_logger_stdio.c | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-)tools/libs/toollog/Makefile +1
-1@@ -2,7 +2,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 -MINOR = 0 +MINOR = 1 SHLIB_LDFLAGS += -Wl,--version-script=libxentoollog.map CFLAGS += -Werror -Wmissing-prototypestools/libs/toollog/include/xentoollog.h +5
-0@@ -86,6 +86,11 @@ void xtl_stdiostream_adjust_flags(xentoollog_logger_stdiostream*,void xtl_logger_destroy (struct xentoollog_logger *logger/* 0 is ok */ ); +xentoollog_logger_stdiostream *xtl_defaultlogger_stdiostream (void ); +/* Returns pointer to a static global logger which writes to stderr. +* Reconfiguring it is permitted but destroying it is forbidden. +* This function cannot fail. */ +/*---------- facilities for generating log messages ----------*/ void xtl_logv(struct xentoollog_logger *logger,tools/libs/toollog/libxentoollog.map +5
-0@@ -10,3 +10,8 @@ VERS_1.0 { xtl_stdiostream_set_minlevel; local: *; /* Do not expose anything by default */ }; + +VERS_1.1 { + global: + xtl_defaultlogger_stdiostream; +} VERS_1.0;tools/libs/toollog/xtl_logger_stdio.c +7
-0@@ -28,6 +28,7 @@#include <stdlib.h> #include <errno.h> #include <stdbool.h> +#include <pthread.h> struct xentoollog_logger_stdiostream {xentoollog_logger vtable;@@ -191,6 +192,31 @@ xentoollog_logger_stdiostream *xtl_createlogger_stdiostreamreturn XTL_NEW_LOGGER (stdiostream, newlogger); } +xentoollog_logger_stdiostream *xtl_defaultlogger_stdiostream (void ) { +static xentoollog_logger_stdiostream deflogger = { + .vtable = { + .vmessage = stdiostream_vmessage, + .progress = stdiostream_progress, + .destroy =0 ,/* no-one should destroy this */
tools/libs/toollog/xtl_logger_stdio.c xentoollog_logger_stdiostream *xtl_createlogger_stdiostream · line 210
Quoted 10 lines
tools/libs/toollog/xtl_logger_stdio.c +10
-0+ }, + .min_level = XTL_PROGRESS, +/* for other fields except .f, 0 is good */ + }; + +/* +* Unfortunately, stderr is not a `constant expression', so we +* can't handle it in the initialisation. Also we can't do a +* lockless assignment, even of the identical value, without +* violating threading rules. Nnng.
You want something like:
static xentoollog_logger_stdiostream stdio_logger = { .vtable = {
.vmessage = stdiostream_vmessage, .progress = stdiostream_progress, .destroy = 0, /* no-one should destroy this */ },
.min_level = XTL_PROGRESS,
/* for other fields except .f, 0 is good */ };
static void __attribute__((__constructor__)) init_stdio_logger(void) {
stdio_logger.f = stderr;
}
Which will cause the library loader to DTRT, but not require you to link against pthread (which is a latent bug here, as you didn't update the SHDEPS).
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 01/11] tools/libs/toollog: Provide a default logger
Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2 01/11] tools/libs/toollog: Provide a default logger"):
Quoted 12 lines
You want something like:
static
xentoollog_logger_stdiostreamstdio_logger= { .vtable = {
.vmessage =stdiostream_vmessage, .progress =stdiostream_progress, .destroy = 0, /* no-one should destroy this */ },
.min_level =XTL_PROGRESS,
/* for other fields except .f, 0 is good */ };
Quoted 4 lines
static void __attribute__((__constructor__))
init_stdio_logger(void){
stdio_logger.f = stderr;
}
Blimey. Is that portable enough ? I can switch to that if we think so. It's certainly more pleasant.
Quoted 3 lines
Which will cause the library loader to DTRT, but not require you to link against pthread (which is a latent bug here, as you didn't update the SHDEPS).
Oops, although in practice I think this is not going to make any difference on any supported platform.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 01/11] tools/libs/toollog: Provide a default logger
Quoted 13 lines · Ian Jackson
Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2 01/11]
tools/libs/toollog: Provide a default logger"):Quoted 12 lines
You want something like:
static
xentoollog_logger_stdiostreamstdio_logger= { .vtable = {
.vmessage =stdiostream_vmessage, .progress =stdiostream_progress, .destroy = 0, /* no-one should destroy this */ },
.min_level =XTL_PROGRESS,
/* for other fields except .f, 0 is good */ };
Quoted 5 lines
Quoted 4 lines
static void __attribute__((__constructor__))
init_stdio_logger(void){
stdio_logger.f = stderr;
}Blimey. Is that portable enough ?
Should be. Its how C++ globals work, and it appears that we already use it in xc_dom.h for the dombuilder register_{loader,arch_hooks}() infrastructure.
Quoted 1 line
I can switch to that if we think so. It's certainly more pleasant.
Absolutely (although be warned - that was entirely untested code).
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 01/11] tools/libs/toollog: Provide a default logger
Quoted 14 lines · Andrew Cooper
Quoted 13 lines · Ian Jackson
Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2 01/11]
tools/libs/toollog: Provide a default logger"):Quoted 12 lines
You want something like:
static
xentoollog_logger_stdiostreamstdio_logger= { .vtable = {
.vmessage =stdiostream_vmessage, .progress =stdiostream_progress, .destroy = 0, /* no-one should destroy this */ },
.min_level =XTL_PROGRESS,
/* for other fields except .f, 0 is good */ };
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
static void __attribute__((__constructor__))
init_stdio_logger(void){
stdio_logger.f = stderr;
}Blimey. Is that portable enough ?
Should be. Its how C++ globals work, and it appears that we already use it in
xc_dom.hfor the dombuilder register_{loader,arch_hooks}() infrastructure.
Although actually, you can't capture stderr in a variable like this at all. freopen() at a later point will close the current FILE object and create a new one, after which this logger will use-after-free.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 01/11] tools/libs/toollog: Provide a default logger
Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2 01/11] tools/libs/toollog: Provide a default logger"):
Quoted 3 lines
Although actually, you can't capture stderr in a variable like this at all.
freopen()at a later point will close the current FILE object and create a new one, after which this logger will use-after-free.
freopen(...,f) always returns NULL or f. There's no way to change the pointer value of stderr. Indeed some libcs have
#define stderr (&__stdiostreams[2])
or some such.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/11 tools/libs/toollog: Use the default logger
In reply to Ian JacksonPreviously xtl_log, xtl_logv and xtl_progress would all crash if passed logger=NULL. Have the use the default logger instead. This is more convenient.
---
v2: New in this version of the series
--- tools/libs/toollog/include/xentoollog.h | 9 +++++---- tools/libs/toollog/xtl_core.c | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-)
tools/libs/toollog/include/xentoollog.h +5 -4
@@ -89,25 +89,26 @@ void xtl_logger_destroy(struct xentoollog_logger *logger /* 0 is ok */);xentoollog_logger_stdiostream *xtl_defaultlogger_stdiostream (void );/* Returns pointer to a static global logger which writes to stderr. * Reconfiguring it is permitted but destroying it is forbidden. -* This function cannot fail. */ +* This function cannot fail. +* This default logger is usedd by xtl_log et al when logger==NULL. */ /*---------- facilities for generating log messages ----------*/ -void xtl_logv (struct xentoollog_logger *logger, +void xtl_logv (struct xentoollog_logger *logger/* NULL ok */ ,xentoollog_level level,int errnoval/* or -1 */ ,const char *context/* eg "xc", "xenstore", "xl", may be 0 */ ,const char *format/* does not contain \n */ ,va_list ) __attribute__((format (printf,5 ,0 ))); -void xtl_log (struct xentoollog_logger *logger, +void xtl_log (struct xentoollog_logger *logger/* NULL ok */ ,xentoollog_level level,int errnoval/* or -1 */ ,const char *context/* eg "xc", "xenstore", "xl" */ ,const char *format/* does not contain \n */ , ...) __attribute__((format (printf,5 ,6 ))); -void xtl_progress (struct xentoollog_logger *logger, +void xtl_progress (struct xentoollog_logger *logger/* NULL ok */ ,const char *context/* see above, may be 0 */ ,const char *doing_what,unsigned long done,unsigned long total);
tools/libs/toollog/xtl_core.c +7 -0
@@ -38,6 +38,11 @@ const char *xtl_level_to_string(xentoollog_level level) {return level_strings[level]; } +static void defaultlogger (xentoollog_logger **logger) { +if (*logger)return ; + *logger = (xentoollog_logger *)xtl_defaultlogger_stdiostream (); +} + void xtl_logv(struct xentoollog_logger *logger, xentoollog_level level, int errnoval /* or -1 */,
@@ -46,6 +51,7 @@ void xtl_logv(struct xentoollog_logger *logger, va_list al) {int errno_save = errno;assert (level >XTL_NONE && level <XTL_NUM_LEVELS ); +defaultlogger (&logger); logger->vmessage (logger,level,errnoval,context,format,al); errno = errno_save; }
@@ -67,6 +73,7 @@ void xtl_progress(struct xentoollog_logger *logger, unsigned long done, unsigned long total) { int percent = 0; +defaultlogger (&logger);if (!logger->progress)return ;if ( total )
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 02/11] tools/libs/toollog: Use the default logger
Quoted 6 lines · Ian Jackson
Previously
xtl_log,xtl_logvandxtl_progresswould all crash if passed logger=NULL. Have the use the default logger instead. This is more convenient.Signed-off-by Ian Jackson <[email protected]>CC Wei Liu <[email protected]>
Quoted 74 lines
---
v2: New in this version of the series--- tools/libs/toollog/include/xentoollog.h | 9 +++++---- tools/libs/toollog/xtl_core.c | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-)tools/libs/toollog/include/xentoollog.h +5
-4@@ -89,25 +89,26 @@ void xtl_logger_destroy(struct xentoollog_logger *logger /* 0 is ok */);xentoollog_logger_stdiostream *xtl_defaultlogger_stdiostream (void );/* Returns pointer to a static global logger which writes to stderr. * Reconfiguring it is permitted but destroying it is forbidden. -* This function cannot fail. */ +* This function cannot fail. +* This default logger is usedd by xtl_log et al when logger==NULL. */ /*---------- facilities for generating log messages ----------*/ -void xtl_logv (struct xentoollog_logger *logger, +void xtl_logv (struct xentoollog_logger *logger/* NULL ok */ ,xentoollog_level level,int errnoval/* or -1 */ ,const char *context/* eg "xc", "xenstore", "xl", may be 0 */ ,const char *format/* does not contain \n */ ,va_list ) __attribute__((format (printf,5 ,0 ))); -void xtl_log (struct xentoollog_logger *logger, +void xtl_log (struct xentoollog_logger *logger/* NULL ok */ ,xentoollog_level level,int errnoval/* or -1 */ ,const char *context/* eg "xc", "xenstore", "xl" */ ,const char *format/* does not contain \n */ , ...) __attribute__((format (printf,5 ,6 ))); -void xtl_progress (struct xentoollog_logger *logger, +void xtl_progress (struct xentoollog_logger *logger/* NULL ok */ ,const char *context/* see above, may be 0 */ ,const char *doing_what,unsigned long done,unsigned long total);tools/libs/toollog/xtl_core.c +7
-0@@ -38,6 +38,11 @@ const char *xtl_level_to_string(xentoollog_level level) {return level_strings[level]; } +static void defaultlogger (xentoollog_logger **logger) { +if (*logger)return ; + *logger = (xentoollog_logger *)xtl_defaultlogger_stdiostream (); +} + void xtl_logv(struct xentoollog_logger *logger, xentoollog_level level, int errnoval /* or -1 */,@@ -46,6 +51,7 @@ void xtl_logv(struct xentoollog_logger *logger, va_list al) {int errno_save = errno;assert (level >XTL_NONE && level <XTL_NUM_LEVELS ); +defaultlogger (&logger); logger->vmessage (logger,level,errnoval,context,format,al); errno = errno_save; }@@ -67,6 +73,7 @@ void xtl_progress(struct xentoollog_logger *logger, unsigned long done, unsigned long total) { int percent = 0; +defaultlogger (&logger);if (!logger->progress)return ;if ( total )
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 02/11] tools/libs/toollog: Use the default logger
In reply to Ian JacksonQuoted 5 lines · Ian Jackson
Previously
xtl_log,xtl_logvandxtl_progresswould all crash if passed logger=NULL. Have the use the default logger instead. This is more convenient.Signed-off-by Ian Jackson <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 3/11 tools/libs/*: Rely on the default logger
In reply to Ian JacksonDelete 11 entirely formulaic conditional calls to
xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
and associated logger_tofree variables, error handling, etc.
No overall functional change, although some memory allocation errors may no longer occur.
After this there are still several calls to xtl_createlogger_stdiostream in tree, but they almost all have non-default message level etc. so it is not obvious that they should be replaced.
The exception is in xc_private.c where xch->error_handler is initialised using a copy of the default initialisation boilerplate (ant there is the associated xch->error_handler_tofree). However, there is also xch->dombuild_logger, and xch->dombuild_logger_tofree which is handled differently and so must be retained. It seems better to keep the xch code internally consistent, and decoupled from the general default.
---
v2: New in this version of the series
--- tools/libs/call/core.c | 10 ---------- tools/libs/call/private.h | 2 +- tools/libs/devicemodel/core.c | 11 ----------- tools/libs/devicemodel/private.h | 2 +- tools/libs/evtchn/core.c | 10 ---------- tools/libs/evtchn/private.h | 2 +- tools/libs/foreignmemory/core.c | 10 ---------- tools/libs/foreignmemory/private.h | 2 +- tools/libs/gnttab/gntshr_core.c | 10 ---------- tools/libs/gnttab/gnttab_core.c | 10 ---------- tools/libs/gnttab/private.h | 2 +- 11 files changed, 5 insertions(+), 66 deletions(-)
tools/libs/call/core.c +0 -10
@@ -54,14 +54,6 @@ xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags) xcall->buffer_cache_misses =0 ; xcall->buffer_cache_toobig =0 ; xcall->logger = logger; - xcall->logger_tofree =NULL ; - -if (!xcall->logger) { - xcall->logger = xcall->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!xcall->logger) goto err; - } rc =osdep_xencall_open (xcall);if ( rc <0 ) goto err;
@@ -71,7 +63,6 @@ xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags) err:xentoolcore__deregister_active_handle (&xcall->tc_ah);osdep_xencall_close (xcall); -xtl_logger_destroy (xcall->logger_tofree);free (xcall);return NULL ; }
@@ -86,7 +77,6 @@ int xencall_close(xencall_handle *xcall)xentoolcore__deregister_active_handle (&xcall->tc_ah); rc =osdep_xencall_close (xcall);buffer_release_cache (xcall); -xtl_logger_destroy (xcall->logger_tofree);free (xcall);return rc; }
tools/libs/call/private.h +1 -1
@@ -18,7 +18,7 @@#endif struct xencall_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;unsigned flags;/* partially with /dev/ no /dev/ */
tools/libs/devicemodel/core.c +0 -11
@@ -46,15 +46,6 @@ xendevicemodel_handle *xendevicemodel_open(xentoollog_logger *logger, dmod->flags = open_flags; dmod->logger = logger; - dmod->logger_tofree =NULL ; - -if (!dmod->logger) { - dmod->logger = dmod->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!dmod->logger) - goto err; - } dmod->xcall =xencall_open (dmod->logger,0 );if (!dmod->xcall)
@@ -67,7 +58,6 @@ xendevicemodel_handle *xendevicemodel_open(xentoollog_logger *logger,return dmod; err: -xtl_logger_destroy (dmod->logger_tofree);xentoolcore__deregister_active_handle (&dmod->tc_ah);xencall_close (dmod->xcall);free (dmod);
@@ -85,7 +75,6 @@ int xendevicemodel_close(xendevicemodel_handle *dmod)xentoolcore__deregister_active_handle (&dmod->tc_ah);xencall_close (dmod->xcall); -xtl_logger_destroy (dmod->logger_tofree);free (dmod);return rc; }
tools/libs/devicemodel/private.h +1 -1
@@ -10,7 +10,7 @@#include <xentoolcore_internal.h> struct xendevicemodel_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;unsigned int flags;xencall_handle *xcall;int fd;
tools/libs/evtchn/core.c +0 -10
@@ -37,18 +37,10 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags) xce->fd =-1 ; xce->logger = logger; - xce->logger_tofree =NULL ; xce->tc_ah.restrict_callback = all_restrict_cb;xentoolcore__register_active_handle (&xce->tc_ah); -if (!xce->logger) { - xce->logger = xce->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!xce->logger) goto err; - } - rc =osdep_evtchn_open (xce);if ( rc <0 ) goto err;
@@ -57,7 +49,6 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags) err:xentoolcore__deregister_active_handle (&xce->tc_ah);osdep_evtchn_close (xce); -xtl_logger_destroy (xce->logger_tofree);free (xce);return NULL ; }
@@ -71,7 +62,6 @@ int xenevtchn_close(xenevtchn_handle *xce)xentoolcore__deregister_active_handle (&xce->tc_ah); rc =osdep_evtchn_close (xce); -xtl_logger_destroy (xce->logger_tofree);free (xce);return rc; }
tools/libs/evtchn/private.h +1 -1
@@ -9,7 +9,7 @@#include <xen/xen.h> struct xenevtchn_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;int fd;Xentoolcore__Active_Handle tc_ah; };
tools/libs/foreignmemory/core.c +0 -10
@@ -41,18 +41,10 @@ xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger, fmem->fd =-1 ; fmem->logger = logger; - fmem->logger_tofree =NULL ; fmem->tc_ah.restrict_callback = all_restrict_cb;xentoolcore__register_active_handle (&fmem->tc_ah); -if (!fmem->logger) { - fmem->logger = fmem->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!fmem->logger) goto err; - } - rc =osdep_xenforeignmemory_open (fmem);if ( rc <0 ) goto err;
@@ -61,7 +53,6 @@ xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger, err:xentoolcore__deregister_active_handle (&fmem->tc_ah);osdep_xenforeignmemory_close (fmem); -xtl_logger_destroy (fmem->logger_tofree);free (fmem);return NULL ; }
@@ -75,7 +66,6 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem)xentoolcore__deregister_active_handle (&fmem->tc_ah); rc =osdep_xenforeignmemory_close (fmem); -xtl_logger_destroy (fmem->logger_tofree);free (fmem);return rc; }
tools/libs/foreignmemory/private.h +1 -1
@@ -19,7 +19,7 @@#endif struct xenforeignmemory_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;unsigned flags;int fd;Xentoolcore__Active_Handle tc_ah;
tools/libs/gnttab/gntshr_core.c +0 -10
@@ -31,14 +31,6 @@ xengntshr_handle *xengntshr_open(xentoollog_logger *logger, unsigned open_flags) xgs->fd =-1 ; xgs->logger = logger; - xgs->logger_tofree =NULL ; - -if (!xgs->logger) { - xgs->logger = xgs->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!xgs->logger) goto err; - } rc =osdep_gntshr_open (xgs);if ( rc <0 ) goto err;
@@ -47,7 +39,6 @@ xengntshr_handle *xengntshr_open(xentoollog_logger *logger, unsigned open_flags) err:osdep_gntshr_close (xgs); -xtl_logger_destroy (xgs->logger_tofree);free (xgs);return NULL ; }
@@ -60,7 +51,6 @@ int xengntshr_close(xengntshr_handle *xgs)return 0 ; rc =osdep_gntshr_close (xgs); -xtl_logger_destroy (xgs->logger_tofree);free (xgs);return rc; }
tools/libs/gnttab/gnttab_core.c +0 -10
@@ -37,18 +37,10 @@ xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned open_flags) xgt->fd =-1 ; xgt->logger = logger; - xgt->logger_tofree =NULL ; xgt->tc_ah.restrict_callback = all_restrict_cb;xentoolcore__register_active_handle (&xgt->tc_ah); -if (!xgt->logger) { - xgt->logger = xgt->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!xgt->logger) goto err; - } - rc =osdep_gnttab_open (xgt);if ( rc <0 ) goto err;
@@ -57,7 +49,6 @@ xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned open_flags) err:xentoolcore__deregister_active_handle (&xgt->tc_ah);osdep_gnttab_close (xgt); -xtl_logger_destroy (xgt->logger_tofree);free (xgt);return NULL ; }
@@ -71,7 +62,6 @@ int xengnttab_close(xengnttab_handle *xgt)xentoolcore__deregister_active_handle (&xgt->tc_ah); rc =osdep_gnttab_close (xgt); -xtl_logger_destroy (xgt->logger_tofree);free (xgt);return rc; }
tools/libs/gnttab/private.h +1 -1
@@ -12,7 +12,7 @@ #define GSERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gntshr", _f)struct xengntdev_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;int fd;Xentoolcore__Active_Handle tc_ah; };
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 03/11] tools/libs/*: Rely on the default logger
Quoted 20 lines · Ian Jackson
Delete 11 entirely formulaic conditional calls to
xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
and associatedlogger_tofreevariables, error handling, etc.No overall functional change, although some memory allocation errors may no longer occur.
After this there are still several calls to
xtl_createlogger_stdiostreamin tree, but they almost all have non-default message level etc. so it is not obvious that they should be replaced.The exception is in
xc_private.cwherexch->error_handleris initialised using a copy of the default initialisation boilerplate (ant there is the associatedxch->error_handler_tofree). However, there is alsoxch->dombuild_logger, andxch->dombuild_logger_tofreewhich is handled differently and so must be retained. It seems better to keep the xch code internally consistent, and decoupled from the general default.
Quoted 2 lines
Signed-off-by Ian Jackson <[email protected]>CC Wei Liu <[email protected]>
Quoted 304 lines
---
v2: New in this version of the series--- tools/libs/call/core.c | 10 ---------- tools/libs/call/private.h | 2 +- tools/libs/devicemodel/core.c | 11 ----------- tools/libs/devicemodel/private.h | 2 +- tools/libs/evtchn/core.c | 10 ---------- tools/libs/evtchn/private.h | 2 +- tools/libs/foreignmemory/core.c | 10 ---------- tools/libs/foreignmemory/private.h | 2 +- tools/libs/gnttab/gntshr_core.c | 10 ---------- tools/libs/gnttab/gnttab_core.c | 10 ---------- tools/libs/gnttab/private.h | 2 +- 11 files changed, 5 insertions(+), 66 deletions(-)tools/libs/call/core.c +0
-10@@ -54,14 +54,6 @@ xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags) xcall->buffer_cache_misses =0 ; xcall->buffer_cache_toobig =0 ; xcall->logger = logger; - xcall->logger_tofree =NULL ; - -if (!xcall->logger) { - xcall->logger = xcall->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!xcall->logger) goto err; - } rc =osdep_xencall_open (xcall);if ( rc <0 ) goto err;@@ -71,7 +63,6 @@ xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags) err:xentoolcore__deregister_active_handle (&xcall->tc_ah);osdep_xencall_close (xcall); -xtl_logger_destroy (xcall->logger_tofree);free (xcall);return NULL ; }@@ -86,7 +77,6 @@ int xencall_close(xencall_handle *xcall)xentoolcore__deregister_active_handle (&xcall->tc_ah); rc =osdep_xencall_close (xcall);buffer_release_cache (xcall); -xtl_logger_destroy (xcall->logger_tofree);free (xcall);return rc; }tools/libs/call/private.h +1
-1@@ -18,7 +18,7 @@#endif struct xencall_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;unsigned flags;/* partially with /dev/ no /dev/ */ tools/libs/devicemodel/core.c +0
-11@@ -46,15 +46,6 @@ xendevicemodel_handle *xendevicemodel_open(xentoollog_logger *logger, dmod->flags = open_flags; dmod->logger = logger; - dmod->logger_tofree =NULL ; - -if (!dmod->logger) { - dmod->logger = dmod->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!dmod->logger) - goto err; - } dmod->xcall =xencall_open (dmod->logger,0 );if (!dmod->xcall)@@ -67,7 +58,6 @@ xendevicemodel_handle *xendevicemodel_open(xentoollog_logger *logger,return dmod; err: -xtl_logger_destroy (dmod->logger_tofree);xentoolcore__deregister_active_handle (&dmod->tc_ah);xencall_close (dmod->xcall);free (dmod);@@ -85,7 +75,6 @@ int xendevicemodel_close(xendevicemodel_handle *dmod)xentoolcore__deregister_active_handle (&dmod->tc_ah);xencall_close (dmod->xcall); -xtl_logger_destroy (dmod->logger_tofree);free (dmod);return rc; }tools/libs/devicemodel/private.h +1
-1@@ -10,7 +10,7 @@#include <xentoolcore_internal.h> struct xendevicemodel_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;unsigned int flags;xencall_handle *xcall;int fd;tools/libs/evtchn/core.c +0
-10@@ -37,18 +37,10 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags) xce->fd =-1 ; xce->logger = logger; - xce->logger_tofree =NULL ; xce->tc_ah.restrict_callback = all_restrict_cb;xentoolcore__register_active_handle (&xce->tc_ah); -if (!xce->logger) { - xce->logger = xce->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!xce->logger) goto err; - } - rc =osdep_evtchn_open (xce);if ( rc <0 ) goto err;@@ -57,7 +49,6 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags) err:xentoolcore__deregister_active_handle (&xce->tc_ah);osdep_evtchn_close (xce); -xtl_logger_destroy (xce->logger_tofree);free (xce);return NULL ; }@@ -71,7 +62,6 @@ int xenevtchn_close(xenevtchn_handle *xce)xentoolcore__deregister_active_handle (&xce->tc_ah); rc =osdep_evtchn_close (xce); -xtl_logger_destroy (xce->logger_tofree);free (xce);return rc; }tools/libs/evtchn/private.h +1
-1@@ -9,7 +9,7 @@#include <xen/xen.h> struct xenevtchn_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;int fd;Xentoolcore__Active_Handle tc_ah; };tools/libs/foreignmemory/core.c +0
-10@@ -41,18 +41,10 @@ xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger, fmem->fd =-1 ; fmem->logger = logger; - fmem->logger_tofree =NULL ; fmem->tc_ah.restrict_callback = all_restrict_cb;xentoolcore__register_active_handle (&fmem->tc_ah); -if (!fmem->logger) { - fmem->logger = fmem->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!fmem->logger) goto err; - } - rc =osdep_xenforeignmemory_open (fmem);if ( rc <0 ) goto err;@@ -61,7 +53,6 @@ xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger, err:xentoolcore__deregister_active_handle (&fmem->tc_ah);osdep_xenforeignmemory_close (fmem); -xtl_logger_destroy (fmem->logger_tofree);free (fmem);return NULL ; }@@ -75,7 +66,6 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem)xentoolcore__deregister_active_handle (&fmem->tc_ah); rc =osdep_xenforeignmemory_close (fmem); -xtl_logger_destroy (fmem->logger_tofree);free (fmem);return rc; }tools/libs/foreignmemory/private.h +1
-1@@ -19,7 +19,7 @@#endif struct xenforeignmemory_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;unsigned flags;int fd;Xentoolcore__Active_Handle tc_ah;tools/libs/gnttab/gntshr_core.c +0
-10@@ -31,14 +31,6 @@ xengntshr_handle *xengntshr_open(xentoollog_logger *logger, unsigned open_flags) xgs->fd =-1 ; xgs->logger = logger; - xgs->logger_tofree =NULL ; - -if (!xgs->logger) { - xgs->logger = xgs->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!xgs->logger) goto err; - } rc =osdep_gntshr_open (xgs);if ( rc <0 ) goto err;@@ -47,7 +39,6 @@ xengntshr_handle *xengntshr_open(xentoollog_logger *logger, unsigned open_flags) err:osdep_gntshr_close (xgs); -xtl_logger_destroy (xgs->logger_tofree);free (xgs);return NULL ; }@@ -60,7 +51,6 @@ int xengntshr_close(xengntshr_handle *xgs)return 0 ; rc =osdep_gntshr_close (xgs); -xtl_logger_destroy (xgs->logger_tofree);free (xgs);return rc; }tools/libs/gnttab/gnttab_core.c +0
-10@@ -37,18 +37,10 @@ xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned open_flags) xgt->fd =-1 ; xgt->logger = logger; - xgt->logger_tofree =NULL ; xgt->tc_ah.restrict_callback = all_restrict_cb;xentoolcore__register_active_handle (&xgt->tc_ah); -if (!xgt->logger) { - xgt->logger = xgt->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!xgt->logger) goto err; - } - rc =osdep_gnttab_open (xgt);if ( rc <0 ) goto err;@@ -57,7 +49,6 @@ xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned open_flags) err:xentoolcore__deregister_active_handle (&xgt->tc_ah);osdep_gnttab_close (xgt); -xtl_logger_destroy (xgt->logger_tofree);free (xgt);return NULL ; }@@ -71,7 +62,6 @@ int xengnttab_close(xengnttab_handle *xgt)xentoolcore__deregister_active_handle (&xgt->tc_ah); rc =osdep_gnttab_close (xgt); -xtl_logger_destroy (xgt->logger_tofree);free (xgt);return rc; }tools/libs/gnttab/private.h +1
-1@@ -12,7 +12,7 @@ #define GSERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gntshr", _f)struct xengntdev_handle { -xentoollog_logger *logger, *logger_tofree; +xentoollog_logger *logger;int fd;Xentoolcore__Active_Handle tc_ah; };
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 03/11] tools/libs/*: Rely on the default logger
In reply to Ian JacksonQuoted 20 lines · Ian Jackson
Delete 11 entirely formulaic conditional calls to
xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
and associatedlogger_tofreevariables, error handling, etc.No overall functional change, although some memory allocation errors may no longer occur.
After this there are still several calls to
xtl_createlogger_stdiostreamin tree, but they almost all have non-default message level etc. so it is not obvious that they should be replaced.The exception is in
xc_private.cwherexch->error_handleris initialised using a copy of the default initialisation boilerplate (ant there is the associatedxch->error_handler_tofree). However, there is alsoxch->dombuild_logger, andxch->dombuild_logger_tofreewhich is handled differently and so must be retained. It seems better to keep the xch code internally consistent, and decoupled from the general default.
Quoted 1 line
Signed-off-by Ian Jackson <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 4/11 tools/libvchan: Initialise xs_transaction_t to XBT_NULL, not NULL
In reply to Ian JacksonThis is an integer type, not a pointer.
--- tools/libvchan/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libvchan/init.c +1 -1
@@ -250,7 +250,7 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_basechar buf[64 ];char ref[16 ];char * domid_str =NULL ; -xs_transaction_t xs_trans =NULL ; +xs_transaction_t xs_trans =XBT_NULL ; xs =xs_domain_open ();if (!xs) goto fail;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 5/11 tools/xenstore: Document that xs_close(0) is OK.
In reply to Ian Jackson--- tools/xenstore/include/xenstore.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/xenstore/include/xenstore.h +1 -1
@@ -77,7 +77,7 @@ typedef uint32_t xs_transaction_t;struct xs_handle *xs_open (unsigned long flags);/* Close the connection to the xs daemon. */ -void xs_close (struct xs_handle *xsh); +void xs_close (struct xs_handle *xsh/* NULL ok */ );/* Connect to the xs daemon. * Returns a handle or NULL.
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 6/11 tools/libvchan: init_xs_srv: Simplify error handling (1)
In reply to Ian Jackson* Use xs_close instead of the deprecated xs_daemon_close.
* Initialise xs to NULL. That means xs_close can now be called in
all cases. Move it to the fail clause.
* free(domid_str) is already safe in all cases since domid_str is initialised to NULL. Move it to the fail clause.
No overall functional change: xs_close is the same as xs_daemon_close; and it and free are now sometimes called on NULL, but those are no-ops.
--- tools/libvchan/init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/libvchan/init.c +3 -3
@@ -245,7 +245,7 @@ fail:static int init_xs_srv (struct libxenvchan *ctrl,int domain,const char * xs_base,int ring_ref) {int ret =-1 ; -struct xs_handle *xs; +struct xs_handle *xs =NULL ;struct xs_permissions perms[2 ];char buf[64 ];char ref[16 ];
@@ -292,9 +292,9 @@ retry_transaction: ret =0 ; } fail_xs_open: -free (domid_str); -xs_daemon_close (xs); fail: +free (domid_str); +xs_close (xs);return ret; }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 7/11 tools/libvchan: init_xs_srv: Simplify error handling (2)
In reply to Ian Jackson* Abolish fail_xs_open which is now exactly the same as fail.
* Change all gotos to refer to fail instead.
No functional change.
--- tools/libvchan/init.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
tools/libvchan/init.c +6 -7
@@ -256,7 +256,7 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base goto fail; domid_str =xs_read (xs,0 ,"domid" ,NULL );if (!domid_str) - goto fail_xs_open; + goto fail;// owner domain is us perms[0 ].id =atoi (domid_str);
@@ -269,21 +269,21 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base retry_transaction: xs_trans =xs_transaction_start (xs);if (!xs_trans) - goto fail_xs_open; + goto fail;snprintf (ref,sizeof ref,"%d" , ring_ref);snprintf (buf,sizeof buf,"%s/ring-ref" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) - goto fail_xs_open; + goto fail;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) - goto fail_xs_open; + goto fail;snprintf (ref,sizeof ref,"%d" , ctrl->event_port);snprintf (buf,sizeof buf,"%s/event-channel" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) - goto fail_xs_open; + goto fail;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) - goto fail_xs_open; + goto fail;if (!xs_transaction_end (xs, xs_trans,0 )) {if (errno ==EAGAIN )
@@ -291,7 +291,6 @@ retry_transaction: }else { ret =0 ; } - fail_xs_open: fail:free (domid_str);xs_close (xs);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 8/11 tools/libvchan: init_xs_srv: Turn xs retry from goto into for (; ; )
In reply to Ian JacksonNo functional change.
--- tools/libvchan/init.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-)
tools/libvchan/init.c +26 -24
@@ -266,31 +266,33 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base perms[1 ].id = domain; perms[1 ].perms =XS_PERM_READ ; -retry_transaction: - xs_trans =xs_transaction_start (xs); -if (!xs_trans) - goto fail; - -snprintf (ref,sizeof ref,"%d" , ring_ref); -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_base); -if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) - goto fail; -if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) - goto fail; - -snprintf (ref,sizeof ref,"%d" , ctrl->event_port); -snprintf (buf,sizeof buf,"%s/event-channel" , xs_base); -if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) - goto fail; -if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) - goto fail; - -if (!xs_transaction_end (xs, xs_trans,0 )) { -if (errno ==EAGAIN ) - goto retry_transaction; - }else { - ret =0 ; +for (;;) { + xs_trans =xs_transaction_start (xs); +if (!xs_trans) + goto fail; + +snprintf (ref,sizeof ref,"%d" , ring_ref); +snprintf (buf,sizeof buf,"%s/ring-ref" , xs_base); +if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) + goto fail; +if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) + goto fail; + +snprintf (ref,sizeof ref,"%d" , ctrl->event_port); +snprintf (buf,sizeof buf,"%s/event-channel" , xs_base); +if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) + goto fail; +if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) + goto fail; + +if (xs_transaction_end (xs, xs_trans,0 )) +break ; +else if (errno !=EAGAIN ) + goto fail; +/* EAGAIN, retry */ } + ret =0 ; + fail:free (domid_str);xs_close (xs);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 9/11 tools/libvchan: Add xentoollog to direct dependencies
In reply to Ian JacksonWe are going to add a call to xtl_log.
--- tools/libvchan/Makefile | 6 +++--- tools/libvchan/xenvchan.pc.in | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
tools/libvchan/Makefile +3 -3
@@ -10,9 +10,9 @@ NODE_OBJS = node.o NODE2_OBJS = node-select.o LIBVCHAN_PIC_OBJS = $(patsubst %.o,%.opic,$(LIBVCHAN_OBJS)) -LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxengnttab) $(LDLIBS_libxenevtchn) -$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn) -$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn) +LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxengnttab) $(LDLIBS_libxenevtchn) $(LDLIBS_libxentoollog) +$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn) $(CFLAGS_libxentoollog) +$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn) $(CFLAGS_libxentoollog) MAJOR = 4.12 MINOR = 0
tools/libvchan/xenvchan.pc.in +1 -1
@@ -7,4 +7,4 @@ Description: The Xenvchan library for Xen hypervisor Version: @@version@@ Cflags: -I${includedir} @@cflagslocal@@ Libs: @@libsflag@@${libdir} -lxenvchan -Requires.private: xentoollog,xenstore,xenevtchn,xengnttab +Requires.private: xentoollog,xenstore,xenevtchn,xengnttab,xentoollog
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 10/11 tools/libvchan: libxenvchan_*_init: Promise an errno
In reply to Ian JacksonThese functions do in fact leave errno set. We are going to want to use this.
--- tools/libvchan/libxenvchan.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libvchan/libxenvchan.h +2 -2
@@ -95,7 +95,7 @@ struct libxenvchan {* @param xs_path Base xenstore path for storing ring/event data * @param send_min The minimum size (in bytes) of the send ring (left) * @param recv_min The minimum size (in bytes) of the receive ring (right) -* @return The structure, or NULL in case of an error +* @return The structure, or NULL in case of an error (setting errno) */ struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger, int domain, const char* xs_path,
@@ -108,7 +108,7 @@ struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,* @param logger Logger for libxc errors * @param domain The peer domain to connect to * @param xs_path Base xenstore path for storing ring/event data -* @return The structure, or NULL in case of an error +* @return The structure, or NULL in case of an error (setting errno) */ struct libxenvchan *libxenvchan_client_init (struct xentoollog_logger *logger,int domain,const char * xs_path);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 11/11 tools/libvchan: libxenvchan_client_init: use ENOENT for no server
In reply to Ian Jackson* Promise that we will set errno to ENOENT if the server is not yet set up.
* Arrange that all ENOENT returns other than from the read of ring-ref are turned into EIO, logging when we do so.
--- tools/libvchan/init.c | 11 ++++++++++- tools/libvchan/libxenvchan.h | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-)
tools/libvchan/init.c +10 -1
@@ -45,6 +45,7 @@#include <xen/sys/gntalloc.h> #include <xen/sys/gntdev.h> #include <libxenvchan.h> +#include <xentoollog.h> #ifndef PAGE_SHIFT #define PAGE_SHIFT 12
@@ -419,7 +420,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,snprintf (buf,sizeof buf,"%s/ring-ref" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) - goto fail; + goto fail_allow_enoent; ring_ref =atoi (ref);free (ref);if (!ring_ref)
@@ -452,7 +453,15 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,if (xs)xs_daemon_close (xs);return ctrl; + fail: +if (errno ==ENOENT ) { +xtl_log (logger,XTL_ERROR , errno,"vchan" , +"error talking to server `%s', returning EIO" , + xs_path); + errno =EIO ; + } + fail_allow_enoent:libxenvchan_close (ctrl); ctrl =NULL ; goto out;
tools/libvchan/libxenvchan.h +4 -0
@@ -105,6 +105,10 @@ struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,* safely, however no locking is performed, so you must prevent multiple clients * from connecting to a single server. * +* Failing with ENOENT means the server has not yet called +* libxenvchan_server_init, You may wait for a server to appear by +* setting a xenstore watch on xs_path. +* * @param logger Logger for libxc errors * @param domain The peer domain to connect to * @param xs_path Base xenstore path for storing ring/event data
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/11] tools/libvchan: libxenvchan_client_init: use ENOENT for no server
Quoted 7 lines · Ian Jackson
* Promise that we will set errno to ENOENT if the server is not yet set up.
* Arrange that all ENOENT returns other than from the read of ring-ref are turned into EIO, logging when we do so.Signed-off-by Ian Jackson <[email protected]>CC Marek Marczykowski-Górecki <[email protected]>
Since xtl_log now accepts NULL, it should be fine. Thanks!
Quoted 57 lines
--- tools/libvchan/init.c | 11 ++++++++++- tools/libvchan/libxenvchan.h | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-)tools/libvchan/init.c +10
-1@@ -45,6 +45,7 @@#include <xen/sys/gntalloc.h> #include <xen/sys/gntdev.h> #include <libxenvchan.h> +#include <xentoollog.h> #ifndef PAGE_SHIFT #define PAGE_SHIFT 12@@ -419,7 +420,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,snprintf (buf,sizeof buf,"%s/ring-ref" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) - goto fail; + goto fail_allow_enoent; ring_ref =atoi (ref);free (ref);if (!ring_ref)@@ -452,7 +453,15 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,if (xs)xs_daemon_close (xs);return ctrl; + fail: +if (errno ==ENOENT ) { +xtl_log (logger,XTL_ERROR , errno,"vchan" , +"error talking to server `%s', returning EIO" , + xs_path); + errno =EIO ; + } + fail_allow_enoent:libxenvchan_close (ctrl); ctrl =NULL ; goto out;tools/libvchan/libxenvchan.h +4
-0@@ -105,6 +105,10 @@ struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,* safely, however no locking is performed, so you must prevent multiple clients * from connecting to a single server. * +* Failing with ENOENT means the server has not yet called +* libxenvchan_server_init, You may wait for a server to appear by +* setting a xenstore watch on xs_path. +* * @param logger Logger for libxc errors * @param domain The peer domain to connect to * @param xs_path Base xenstore path for storing ring/event data
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/11] tools/libvchan: libxenvchan_client_init: use ENOENT for no server
Marek Marczykowski-Górecki writes ("Re: [Xen-devel] [PATCH v2 11/11] tools/libvchan: libxenvchan_client_init: use ENOENT for no server"):
Quoted 2 lines
Since
xtl_lognow accepts NULL, it should be fine. Thanks!Reviewed-by Marek Marczykowski-Górecki <[email protected]>
Thanks.
I am reluctant to commit this series without having been able to test it. There's the libvchan node.c and node-select.c but they seem a bit raw.
Do you have a script or something to wrap them up ?
Ideally I guess this would be run by osstest somehow.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/11] tools/libvchan: libxenvchan_client_init: use ENOENT for no server
Quoted 11 lines · Ian Jackson
Marek Marczykowski-Górecki writes ("Re: [Xen-devel] [PATCH v2 11/11]
tools/libvchan:libxenvchan_client_init: use ENOENT for no server"):Quoted 2 lines
Since
xtl_lognow accepts NULL, it should be fine. Thanks!Reviewed-by Marek Marczykowski-Górecki <[email protected]>Thanks.
I am reluctant to commit this series without having been able to test it. There's the libvchan
node.candnode-select.cbut they seem a bit raw.Do you have a script or something to wrap them up ?
Not really. I've done a manual test, in two domains:
server: vchan-node2 server $xid2 /local/domain/$xid1/data/vchan/$xid2/1234
client: vchan-node2 client $xid1 /local/domain/$xid1/data/vchan/$xid2/1234
($xid1 and $xid2 are domains ID of server and client respectively)
When start it in this order, it works fine. But if I start the client earlier, I get libxenvchan_*_init: Permission denied. That makes sense - before server setup permissions on xenstore, the client can't read the entries but not because of ENOENT, but EACCESS.
Quoted 1 line
Ideally I guess this would be run by osstest somehow.
I've tried... But stumbled across a bunch of problems:
1. Xen tools are not installed in guest
2. vchan-node* are not installed at all
3. I need two domUs for this (or maybe dom0 and domU?) and processes running in parallel (this is where my perl ends).
I gave up after point 2. Do you want patches for point 1 and 2 anyway? New ts-guest-xen-install assume the build for dom0 is fine for domU too (which is true for Debian)...
As for the second point, I've installed it into $(bindir) as a quick hack, but not sure if this is the best option.
I'm not jet sure how to put all those pieces together. I guess I need to edit sg-run-job, but that's jet another language...
BTW vchan doesn't like loopback connections (within the same domain), as gnttab doesn't like it. Is it something fixable, or is it working as designed? If the latter, I think at least kernel shouldn't panic in that case... More details:
https://github.com/QubesOS/qubes-issues/issues/951
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/11] tools/libvchan: libxenvchan_client_init: use ENOENT for no server
In reply to Ian JacksonQuoted 6 lines · Ian Jackson
* Promise that we will set errno to ENOENT if the server is not yet set up.
* Arrange that all ENOENT returns other than from the read of ring-ref are turned into EIO, logging when we do so.Signed-off-by Ian Jackson <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel