Allow xenstore client utilities to be built statically.
The attached patches enable the xenstore client utilities (xenstore-read/write and friends) to be built statically and against uclibc. This is useful for utility domains where a small userspace is desired.
Both static building with glibc and linking with uclibc seem to have problems with threading and so the static version of the library is built without thread support. This is OK since none of the clients actually require it.
The second patch (static-xenstore-watches) is rather optional since nothing currently requires it and it is therefore untested.
The third and fourth patches (multicall-xenstore-*) turn the clients from separate binaries (created via multiple compilation of xenstore_client.c) into a single multicall binary in order to claw back some of the space lost to static linking. This also enables the tool be used as "xenstore <command>" in addition to the existing "xenstore-<command>" way.
Ian.
# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1207658376 -3600
# Node ID 40310b53f5d0a456f12302aa07b592fd27736cb5 # Parent af1d20b86b02bf463690e8af61e77ddf169c4c6c
xenstore: support building the xenstore clients statically.
This removes threading from libxenstore.a (but not libxenstore.so) since pthreads is incompatible with static linking and none of the command line clients require threads anyway. This also disables watch support in the static library.
It is now possible to build these utilities statically with a uclibc toolchain which is useful for small userspace utility domains.
tools/xenstore/Makefile +16 -4
@@ -24,8 +24,18 @@ XENSTORED_OBJS_$(CONFIG_NetBSD) = xensto XENSTORED_OBJS += $(XENSTORED_OBJS_y) +ifneq ($(XENSTORE_STATIC_CLIENTS),y) +LIBXENSTORE := libxenstore.so +else +LIBXENSTORE := libxenstore.a +$(CLIENTS) xenstore-control xenstore-ls: CFLAGS += -static +endif + .PHONY: all -all: libxenstore.so libxenstore.a xenstored $(CLIENTS) xs_tdb_dump xenstore-control xenstore-ls +all: libxenstore.so libxenstore.a xenstored clients xs_tdb_dump + +.PHONY: clients +clients: $(CLIENTS) xenstore-control xenstore-ls ifeq ($(CONFIG_SunOS),y) xenstored_probes.h: xenstored_probes.d
@@ -42,16 +52,16 @@ xenstored: $(XENSTORED_OBJS) xenstored: $(XENSTORED_OBJS) $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDFLAGS_libxenctrl) $(SOCKET_LIBS) -o $@ -$(CLIENTS): xenstore-%: xenstore_%.o libxenstore.so +$(CLIENTS): xenstore-%: xenstore_%.o $(LIBXENSTORE) $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@ $(CLIENTS_OBJS): xenstore_%.o: xenstore_client.c $(COMPILE.c) -DCLIENT_$(*F) -o $@ $< -xenstore-control: xenstore_control.o libxenstore.so +xenstore-control: xenstore_control.o $(LIBXENSTORE) $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@ -xenstore-ls: xsls.o libxenstore.so +xenstore-ls: xsls.o $(LIBXENSTORE) $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@ xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o
@@ -61,6 +71,8 @@ libxenstore.so: libxenstore.so.$(MAJOR) ln -sf $< $@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ + +xs.opic: CFLAGS += -DUSE_PTHREAD libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^ $(SOCKET_LIBS) -lpthread
tools/xenstore/xs.c +105 -28
311 lines not on this page · raw message
# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1207658379 -3600
# Node ID 46073fa39b7bc6cb914a1bc4b4ec2397f9018374 # Parent 40310b53f5d0a456f12302aa07b592fd27736cb5
xenstore: re-enable watch support when threading is disabled.
The caller can select on the watch fd in the normal way.
This patch is only build tested.
tools/xenstore/xs.c +20 -15
@@ -118,7 +118,13 @@ struct xs_handle {struct xs_handle {int fd;struct list_head reply_list; +struct list_head watch_list; +/* Clients can select() on this pipe to wait for a watch to fire. */ +int watch_pipe[2 ]; }; + +static void watch_mutex_lock (struct xs_handle *h) {} +static void watch_mutex_unlock (struct xs_handle *h) {}static void request_mutex_lock (struct xs_handle *h) {}static void request_mutex_unlock (struct xs_handle *h) {}
@@ -130,7 +136,6 @@ static void reply_mutex_unlock(struct xsstatic int read_message (struct xs_handle *h); -#ifdef USE_PTHREAD int xs_fileno (struct xs_handle *h) {char c =0 ;
@@ -148,7 +153,6 @@ int xs_fileno(struct xs_handle *h)return h->watch_pipe[0 ]; } -#endif static int get_socket (const char *connect_to) {
@@ -215,12 +219,12 @@ static struct xs_handle *get_handle(cons h->fd = fd;INIT_LIST_HEAD (&h->reply_list); - -#ifdef USE_PTHREAD +INIT_LIST_HEAD (&h->watch_list); +/* Watch pipe is allocated on demand in xs_fileno(). */ h->watch_pipe[0 ] = h->watch_pipe[1 ] =-1 ; -INIT_LIST_HEAD (&h->watch_list); +#ifdef USE_PTHREAD pthread_mutex_init (&h->watch_mutex,NULL );pthread_cond_init (&h->watch_condvar,NULL );
@@ -269,21 +273,21 @@ void xs_daemon_close(struct xs_handle *hfree (msg); } -#ifdef USE_PTHREAD list_for_each_entry_safe (msg, tmsg, &h->watch_list, list) {free (msg->body);free (msg); } +#ifdef USE_PTHREAD request_mutex_unlock (h);reply_mutex_unlock (h);watch_mutex_unlock (h); +#endif if (h->watch_pipe[0 ] !=-1 ) {close (h->watch_pipe[0 ]);close (h->watch_pipe[1 ]); } -#endif close (h->fd);
@@ -612,7 +616,6 @@ unwind:return false; } -#ifdef USE_PTHREAD /* Watch a node for changes (poll on fd to detect, or call read_watch()). * When the node (or any child) changes, fd will become readable. * Token is returned when watch is read, to allow matching.
@@ -622,6 +625,7 @@ bool xs_watch(struct xs_handle *h, const {struct iovec iov[2 ]; +#ifdef USE_PTHREAD /* We dynamically create a reader thread on demand. */ request_mutex_lock (h);if (!h->read_thr_exists) {
@@ -632,6 +636,7 @@ bool xs_watch(struct xs_handle *h, const h->read_thr_exists = 1; }request_mutex_unlock (h); +#endif iov[0 ].iov_base = (void *)path; iov[0 ].iov_len =strlen (path) +1 ;
@@ -656,7 +661,11 @@ char **xs_read_watch(struct xs_handle *h/* Wait on the condition variable for a watch to fire. */ while (list_empty(&h->watch_list)) +#ifdef USE_PTHREAD pthread_cond_wait (&h->watch_condvar, &h->watch_mutex); +#else +read_message (h); +#endif msg = list_top(&h->watch_list, struct xs_stored_msg, list);list_del (&msg->list);
@@ -708,7 +717,6 @@ bool xs_unwatch(struct xs_handle *h, conreturn xs_bool (xs_talkv (h,XBT_NULL ,XS_UNWATCH , iov,ARRAY_SIZE (iov),NULL )); } -#endif /* Start a transaction: changes by others will not be seen during this * transaction, and changes will not be visible to others until end.
@@ -868,7 +876,6 @@ static int read_message(struct xs_handle body[msg->hdr.len] ='\0' ;if (msg->hdr.type ==XS_WATCH_EVENT ) { -#ifdef USE_PTHREAD watch_mutex_lock (h);/* Kick users out of their select() loop. */
@@ -878,14 +885,12 @@ static int read_message(struct xs_handlecontinue ;list_add_tail (&msg->list, &h->watch_list); + +#ifdef USE_PTHREAD pthread_cond_signal (&h->watch_condvar); +#endif watch_mutex_unlock (h); -#else -/* Cannot handle this event, but should never have been registered. */ - errno = -EIO ; - goto error; -#endif }else {reply_mutex_lock (h);
# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1207658430 -3600
# Node ID f9122c15f2148abf8d8a7738738298102877060f # Parent 46073fa39b7bc6cb914a1bc4b4ec2397f9018374
xenstore: make the xenstore clients a single multicall binary rather than multiply compiled source.
This saves a bunch of space when statically compiling.
.hgignore +1 -0
@@ -208,6 +208,7 @@ ^tools/xenstat/xentop/xentop$ ^tools/xenstore/testsuite/tmp/.*$ ^tools/xenstore/xen$ +^tools/xenstore/xenstore$ ^tools/xenstore/xenstore-chmod$ ^tools/xenstore/xenstore-exists$ ^tools/xenstore/xenstore-list$
tools/xenstore/Makefile +11 -9
@@ -14,7 +14,6 @@ DEP = .*.d CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod CLIENTS += xenstore-write -CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS)) XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o
@@ -28,14 +27,14 @@ LIBXENSTORE := libxenstore.so LIBXENSTORE := libxenstore.so else LIBXENSTORE := libxenstore.a -$(CLIENTS) xenstore-control xenstore-ls: CFLAGS += -static +xenstore xenstore-control xenstore-ls: CFLAGS += -static endif .PHONY: all all: libxenstore.so libxenstore.a xenstored clients xs_tdb_dump .PHONY: clients -clients: $(CLIENTS) xenstore-control xenstore-ls +clients: xenstore $(CLIENTS) xenstore-control xenstore-ls ifeq ($(CONFIG_SunOS),y) xenstored_probes.h: xenstored_probes.d
@@ -52,11 +51,11 @@ xenstored: $(XENSTORED_OBJS) xenstored: $(XENSTORED_OBJS) $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDFLAGS_libxenctrl) $(SOCKET_LIBS) -o $@ -$(CLIENTS): xenstore-%: xenstore_%.o $(LIBXENSTORE) +$(CLIENTS): xenstore + ln -f xenstore $@ + +xenstore: xenstore_client.o $(LIBXENSTORE) $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@ - -$(CLIENTS_OBJS): xenstore_%.o: xenstore_client.c - $(COMPILE.c) -DCLIENT_$(*F) -o $@ $< xenstore-control: xenstore_control.o $(LIBXENSTORE) $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@
@@ -85,7 +84,7 @@ clean: rm -f *.a *.o *.opic *.so* xenstored_probes.h rm -f xenstored xs_random xs_stress xs_crashme rm -f xs_tdb_dump xenstore-control xenstore-ls - rm -f $(CLIENTS) + rm -f xenstore $(CLIENTS) $(RM) $(DEP) .PHONY: TAGS
@@ -104,8 +103,11 @@ install: all $(INSTALL_DIR) $(DESTDIR)$(SBINDIR) $(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR) $(INSTALL_PROG) xenstored $(DESTDIR)$(SBINDIR) - $(INSTALL_PROG) $(CLIENTS) $(DESTDIR)$(BINDIR) $(INSTALL_PROG) xenstore-control $(DESTDIR)$(BINDIR) + $(INSTALL_PROG) xenstore $(DESTDIR)/usr/bin + set -e ; for c in $(CLIENTS) ; do \ + ln -f $(DESTDIR)/usr/bin/xenstore $(DESTDIR)/usr/bin/$${c} ; \ + done $(INSTALL_PROG) xenstore-ls $(DESTDIR)$(BINDIR) $(INSTALL_DIR) $(DESTDIR)$(LIBDIR) $(INSTALL_PROG) libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)
tools/xenstore/xenstore_client.c +268 -198
552 lines not on this page · raw message
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1207658430 -3600
# Node ID af555f1dfa4763a9731b05ccb73c61976234c96b # Parent f9122c15f2148abf8d8a7738738298102877060f
xenstore: merge xenstore-ls into the multicall binary.
This is done separately from moving the other utilities into the mutlicall since ls is slightly different and was already separate.
tools/xenstore/Makefile +4 -8
@@ -13,7 +13,7 @@ DEP = .*.d DEP = .*.d CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod -CLIENTS += xenstore-write +CLIENTS += xenstore-write xenstore-ls XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o
@@ -27,14 +27,14 @@ LIBXENSTORE := libxenstore.so LIBXENSTORE := libxenstore.so else LIBXENSTORE := libxenstore.a -xenstore xenstore-control xenstore-ls: CFLAGS += -static +xenstore xenstore-control: CFLAGS += -static endif .PHONY: all all: libxenstore.so libxenstore.a xenstored clients xs_tdb_dump .PHONY: clients -clients: xenstore $(CLIENTS) xenstore-control xenstore-ls +clients: xenstore $(CLIENTS) xenstore-control ifeq ($(CONFIG_SunOS),y) xenstored_probes.h: xenstored_probes.d
@@ -60,9 +60,6 @@ xenstore-control: xenstore_control.o $(L xenstore-control: xenstore_control.o $(LIBXENSTORE) $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@ -xenstore-ls: xsls.o $(LIBXENSTORE) - $(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@ - xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
@@ -83,7 +80,7 @@ clean: clean: rm -f *.a *.o *.opic *.so* xenstored_probes.h rm -f xenstored xs_random xs_stress xs_crashme - rm -f xs_tdb_dump xenstore-control xenstore-ls + rm -f xs_tdb_dump xenstore-control rm -f xenstore $(CLIENTS) $(RM) $(DEP)
@@ -108,7 +105,6 @@ install: all set -e ; for c in $(CLIENTS) ; do \ ln -f $(DESTDIR)/usr/bin/xenstore $(DESTDIR)/usr/bin/$${c} ; \ done - $(INSTALL_PROG) xenstore-ls $(DESTDIR)$(BINDIR) $(INSTALL_DIR) $(DESTDIR)$(LIBDIR) $(INSTALL_PROG) libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR) ln -sf libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenstore.so.$(MAJOR)
tools/xenstore/xenstore_client.c +172 -11
263 lines not on this page · raw message
tools/xenstore/xsls.c deleted +0 -171
171 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel