Ian Campbell
2010-Dec-02 13:50 UTC
[Xen-devel] [PATCH 0 of 2] libxc: Add option to disable threading at runtime.
The following series allows the library user to disable reentrancy protection in the library. This is to enable libxc to be used by language bindings which do their own reentrancy protection and/or have threading models which conflict with the use of threads in the library. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-02 13:50 UTC
[Xen-devel] [PATCH 1 of 2] libxc: rename safe_strerror to xc_strerror and pass in an XC handle for future use
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1291294140 0
# Node ID 09bd65d842658b39e584b1d4bbc08e9813813937
# Parent 74b5822000a8f1d597f765c8d0a243e095de2f22
libxc: rename safe_strerror to xc_strerror and pass in an XC handle for future
use.
Make the function public since I have future patches which depend on this.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
diff -r 74b5822000a8 -r 09bd65d84265 tools/libxc/ia64/xc_ia64_linux_save.c
--- a/tools/libxc/ia64/xc_ia64_linux_save.c Thu Dec 02 12:49:00 2010 +0000
+++ b/tools/libxc/ia64/xc_ia64_linux_save.c Thu Dec 02 12:49:00 2010 +0000
@@ -660,7 +660,7 @@ xc_domain_save(xc_interface *xch, int io
FIXME: to be tracked. */
fprintf(stderr, "cannot map mfn page %lx gpfn %lx:
%s\n",
xc_ia64_p2m_mfn(&p2m_table, N),
- N, safe_strerror(errno));
+ N, xc_strerror(xch, errno));
goto out;
}
diff -r 74b5822000a8 -r 09bd65d84265 tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c Thu Dec 02 12:49:00 2010 +0000
+++ b/tools/libxc/xc_private.c Thu Dec 02 12:49:00 2010 +0000
@@ -543,7 +543,7 @@ _xc_init_errbuf(void)
pthread_key_create(&errbuf_pkey, _xc_clean_errbuf);
}
-char *safe_strerror(int errcode)
+const char *xc_strerror(xc_interface *xch, int errcode)
{
#define XS_BUFSIZE 32
char *errbuf;
diff -r 74b5822000a8 -r 09bd65d84265 tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h Thu Dec 02 12:49:00 2010 +0000
+++ b/tools/libxc/xc_private.h Thu Dec 02 12:49:00 2010 +0000
@@ -74,7 +74,6 @@ struct xc_interface {
const char *currently_progress_reporting;
};
-char *safe_strerror(int errcode);
void xc_report_error(xc_interface *xch, int code, const char *fmt, ...);
void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
int code, const char *fmt, va_list args)
@@ -96,7 +95,7 @@ void xc_report_progress_step(xc_interfac
#define ERROR(_m, _a...) xc_report_error(xch,XC_INTERNAL_ERROR,_m , ## _a )
#define PERROR(_m, _a...) xc_report_error(xch,XC_INTERNAL_ERROR,_m \
- " (%d = %s)", ## _a , errno, safe_strerror(errno))
+ " (%d = %s)", ## _a , errno, xc_strerror(xch,
errno))
/*
* HYPERCALL ARGUMENT BUFFERS
diff -r 74b5822000a8 -r 09bd65d84265 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h Thu Dec 02 12:49:00 2010 +0000
+++ b/tools/libxc/xenctrl.h Thu Dec 02 12:49:00 2010 +0000
@@ -1411,6 +1411,11 @@ typedef struct xc_error {
*/
const char *xc_error_code_to_desc(int code);
+/*
+ * Convert an errno value to a text description.
+ */
+const char *xc_strerror(xc_interface *xch, int errcode);
+
/*
* Return a pointer to the last error with level XC_REPORT_ERROR. This
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Ian Campbell
2010-Dec-02 13:50 UTC
[Xen-devel] [PATCH 2 of 2] libxc: allow caller to specify no re-entrancy protection when opening the interface
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1291294140 0
# Node ID 5de5590e2edb9a1245495ccc1ee804b47ad54087
# Parent 09bd65d842658b39e584b1d4bbc08e9813813937
libxc: allow caller to specify no re-entrancy protection when opening the
interface
Used by language bindings which provide their own re-entrancy which conflicts
with pthreads.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
diff -r 09bd65d84265 -r 5de5590e2edb tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c Thu Dec 02 12:49:00 2010 +0000
+++ b/tools/libxc/xc_private.c Thu Dec 02 12:49:00 2010 +0000
@@ -32,6 +32,7 @@ xc_interface *xc_interface_open(xentooll
unsigned open_flags) {
xc_interface xch_buf, *xch = &xch_buf;
+ xch->flags = open_flags;
xch->fd = -1;
xch->dombuild_logger_file = 0;
xc_clear_last_error(xch);
@@ -545,30 +546,37 @@ _xc_init_errbuf(void)
const char *xc_strerror(xc_interface *xch, int errcode)
{
+ if ( xch->flags & XC_OPENFLAG_NON_REENTRANT )
+ {
+ return strerror(errcode);
+ }
+ else
+ {
#define XS_BUFSIZE 32
- char *errbuf;
- static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
- char *strerror_str;
+ char *errbuf;
+ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+ char *strerror_str;
- pthread_once(&errbuf_pkey_once, _xc_init_errbuf);
+ pthread_once(&errbuf_pkey_once, _xc_init_errbuf);
- errbuf = pthread_getspecific(errbuf_pkey);
- if (errbuf == NULL) {
- errbuf = malloc(XS_BUFSIZE);
- pthread_setspecific(errbuf_pkey, errbuf);
+ errbuf = pthread_getspecific(errbuf_pkey);
+ if (errbuf == NULL) {
+ errbuf = malloc(XS_BUFSIZE);
+ pthread_setspecific(errbuf_pkey, errbuf);
+ }
+
+ /*
+ * Thread-unsafe strerror() is protected by a local mutex. We copy the
+ * string to a thread-private buffer before releasing the mutex.
+ */
+ pthread_mutex_lock(&mutex);
+ strerror_str = strerror(errcode);
+ strncpy(errbuf, strerror_str, XS_BUFSIZE);
+ errbuf[XS_BUFSIZE-1] = ''\0'';
+ pthread_mutex_unlock(&mutex);
+
+ return errbuf;
}
-
- /*
- * Thread-unsafe strerror() is protected by a local mutex. We copy
- * the string to a thread-private buffer before releasing the mutex.
- */
- pthread_mutex_lock(&mutex);
- strerror_str = strerror(errcode);
- strncpy(errbuf, strerror_str, XS_BUFSIZE);
- errbuf[XS_BUFSIZE-1] = ''\0'';
- pthread_mutex_unlock(&mutex);
-
- return errbuf;
}
void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits)
diff -r 09bd65d84265 -r 5de5590e2edb tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h Thu Dec 02 12:49:00 2010 +0000
+++ b/tools/libxc/xc_private.h Thu Dec 02 12:49:00 2010 +0000
@@ -67,6 +67,7 @@
struct xc_interface {
int fd;
+ int flags;
xentoollog_logger *error_handler, *error_handler_tofree;
xentoollog_logger *dombuild_logger, *dombuild_logger_tofree;
struct xc_error last_error; /* for xc_get_last_error */
diff -r 09bd65d84265 -r 5de5590e2edb tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h Thu Dec 02 12:49:00 2010 +0000
+++ b/tools/libxc/xenctrl.h Thu Dec 02 12:49:00 2010 +0000
@@ -132,8 +132,17 @@ xc_interface *xc_interface_open(xentooll
* if dombuild_logger=NULL, will log to a file
*/
+/*
+ * Note: if XC_OPENFLAG_NON_REENTRANT is passed then libxc must not be
+ * called reentrantly and the calling application is responsible for
+ * providing mutual exclusion surrounding all libxc calls itself.
+ *
+ * In particular xc_{get,clear}_last_error only remain valid for the
+ * duration of the critical section containing the call which failed.
+ */
enum xc_open_flags {
- XC_OPENFLAG_DUMMY = 01, /* do not actually open a xenctrl interface */
+ XC_OPENFLAG_DUMMY = 1<<0, /* do not actually open a xenctrl
interface */
+ XC_OPENFLAG_NON_REENTRANT = 1<<1, /* assume library is only every
called from a single thread */
};
/**
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Vincent Hanquez
2010-Dec-02 14:56 UTC
Re: [Xen-devel] [PATCH 0 of 2] libxc: Add option to disable threading at runtime.
On 02/12/10 13:50, Ian Campbell wrote:> The following series allows the library user to disable reentrancy > protection in the library. > > This is to enable libxc to be used by language bindings which do their > own reentrancy protection and/or have threading models which conflict > with the use of threads in the library.great patchseries ! -- Vincent _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stefano Stabellini
2010-Dec-13 16:54 UTC
Re: [Xen-devel] [PATCH 0 of 2] libxc: Add option to disable threading at runtime.
On Thu, 2 Dec 2010, Ian Campbell wrote:> The following series allows the library user to disable reentrancy > protection in the library. > > This is to enable libxc to be used by language bindings which do their > own reentrancy protection and/or have threading models which conflict > with the use of threads in the library. > > Signed-off-by: Ian Campbell <ian.campbell@citrix.com>both applied _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel