diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2008-01-31 09:13:27 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2008-01-31 09:13:27 +0000 |
commit | d66e065f7f5e8ded336a4ad42a99ab98b00d1083 (patch) | |
tree | fe8a8def386d2661928bc9566cf490a17d755581 /tools/xenstore/xenstored_solaris.c | |
parent | 87fdf3231c5f7998037b1962506dd1bb81cd4ac3 (diff) | |
download | xen-d66e065f7f5e8ded336a4ad42a99ab98b00d1083.tar.gz xen-d66e065f7f5e8ded336a4ad42a99ab98b00d1083.tar.bz2 xen-d66e065f7f5e8ded336a4ad42a99ab98b00d1083.zip |
Add DTrace support to xenstored
Add USDT probes for significant xenstore operations to allow dynamic
tracing.
Signed-off-by: John Levon <john.levon@sun.com>
Diffstat (limited to 'tools/xenstore/xenstored_solaris.c')
-rw-r--r-- | tools/xenstore/xenstored_solaris.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tools/xenstore/xenstored_solaris.c b/tools/xenstore/xenstored_solaris.c index 376a00081b..ef6b51533c 100644 --- a/tools/xenstore/xenstored_solaris.c +++ b/tools/xenstore/xenstored_solaris.c @@ -15,9 +15,15 @@ #include <unistd.h> #include <stdlib.h> #include <sys/mman.h> +#include <strings.h> +#include <ucred.h> +#include <stdio.h> + #include <xen/sys/xenbus.h> +#include "talloc.h" #include "xenstored_core.h" +#include "xenstored_probes.h" evtchn_port_t xenbus_evtchn(void) { @@ -64,3 +70,98 @@ void xenbus_notify_running(void) close(fd); } + +static pid_t cred(const struct connection *conn) +{ + ucred_t *ucred = NULL; + pid_t pid; + + if (conn->domain) + return (0); + + if (getpeerucred(conn->fd, &ucred) == -1) + return (0); + + pid = ucred_getpid(ucred); + + ucred_free(ucred); + return (pid); +} + +/* + * The strings are often a number of nil-separated strings. We'll just + * replace the separators with spaces - not quite right, but good + * enough. + */ +static char * +mangle(const struct connection *conn, const struct buffered_data *in) +{ + char *str; + int i; + + if (in->hdr.msg.len == 0) + return (talloc_strdup(conn, "")); + + if ((str = talloc_zero_size(conn, in->hdr.msg.len + 1)) == NULL) + return (NULL); + + memcpy(str, in->buffer, in->hdr.msg.len); + + /* + * The protocol is absurdly inconsistent in whether the length + * includes the terminating nil or not; replace all nils that + * aren't the last one. + */ + for (i = 0; i < (in->hdr.msg.len - 1); i++) { + if (str[i] == '\0') + str[i] = ' '; + } + + return (str); +} + +void +dtrace_io(const struct connection *conn, const struct buffered_data *in, + int io_out) +{ + if (!io_out) { + if (XENSTORE_MSG_ENABLED()) { + char *mangled = mangle(conn, in); + XENSTORE_MSG(in->hdr.msg.tx_id, conn->id, cred(conn), + in->hdr.msg.type, mangled); + } + + goto out; + } + + switch (in->hdr.msg.type) { + case XS_ERROR: + if (XENSTORE_ERROR_ENABLED()) { + char *mangled = mangle(conn, in); + XENSTORE_ERROR(in->hdr.msg.tx_id, conn->id, + cred(conn), mangled); + } + break; + + case XS_WATCH_EVENT: + if (XENSTORE_WATCH_EVENT_ENABLED()) { + char *mangled = mangle(conn, in); + XENSTORE_WATCH_EVENT(conn->id, cred(conn), mangled); + } + break; + + default: + if (XENSTORE_REPLY_ENABLED()) { + char *mangled = mangle(conn, in); + XENSTORE_REPLY(in->hdr.msg.tx_id, conn->id, cred(conn), + in->hdr.msg.type, mangled); + } + break; + } + +out: + /* + * 6589130 dtrace -G fails for certain tail-calls on x86 + */ + asm("nop"); +} |