diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/stpd/ChangeLog | 4 | ||||
-rw-r--r-- | runtime/stpd/stpd.c | 10 | ||||
-rw-r--r-- | runtime/transport/ChangeLog | 23 | ||||
-rw-r--r-- | runtime/transport/procfs.c | 52 | ||||
-rw-r--r-- | runtime/transport/relayfs-config.h.in | 2 | ||||
-rw-r--r-- | runtime/transport/relayfs.c | 104 | ||||
-rw-r--r-- | runtime/transport/relayfs.h | 22 | ||||
-rw-r--r-- | runtime/transport/transport.c | 12 |
8 files changed, 212 insertions, 17 deletions
diff --git a/runtime/stpd/ChangeLog b/runtime/stpd/ChangeLog index dfaf199b..8151f5be 100644 --- a/runtime/stpd/ChangeLog +++ b/runtime/stpd/ChangeLog @@ -1,3 +1,7 @@ +2006-03-15 Tom Zanussi <zanussi@us.ibm.com> + + * stpd.c (main): Add runtime check for relayfs vs relay-on-proc. + 2006-03-06 Martin Hunt <hunt@redhat.com> * librelay.c (start_cmd): Set proper uid/gid before execing diff --git a/runtime/stpd/stpd.c b/runtime/stpd/stpd.c index bb1a81e0..e99f4b47 100644 --- a/runtime/stpd/stpd.c +++ b/runtime/stpd/stpd.c @@ -23,8 +23,9 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <strings.h> +#include <string.h> #include <sys/wait.h> +#include <sys/statfs.h> #include <pwd.h> #include "librelay.h" @@ -88,6 +89,7 @@ int main(int argc, char **argv) { int c, status; pid_t pid; + struct statfs st; while ((c = getopt(argc, argv, "mpqrb:n:t:d:c:vo:u:")) != EOF) { @@ -210,7 +212,11 @@ int main(int argc, char **argv) outfile_name = DEFAULT_OUTFILE_NAME; } - sprintf(stpd_filebase, "/mnt/relay/%d/cpu", getpid()); + if (statfs("/mnt/relay", &st) < 0) + sprintf(stpd_filebase, "/proc/systemtap/stap_%d/cpu", driver_pid); + else + sprintf(stpd_filebase, "/mnt/relay/%d/cpu", getpid()); + if (init_stp(stpd_filebase, !quiet)) { //fprintf(stderr, "Couldn't initialize stpd. Exiting.\n"); exit(1); diff --git a/runtime/transport/ChangeLog b/runtime/transport/ChangeLog index d3b29e37..36667ecc 100644 --- a/runtime/transport/ChangeLog +++ b/runtime/transport/ChangeLog @@ -1,3 +1,26 @@ +2006-03-15 Tom Zanussi <zanussi@us.ibm.com> + + * procfs.c (_stp_proc_read): Add ifdef for CONFIG_RELAY. + (_stp_get_proc_root): New function. + (_stp_force_dir_create): New function. + (_stp_register_procfs): Add support for CONFIG_RELAY files in + proc. + + * relayfs.c (_stp_subbuf_start): Fix ppc64 compilation error + mentioned in bug #2406. + (_stp_create_buf_file): New function. + (_stp_remove_buf_file): New function. + (_stp_relayfs_close): Add support for CONFIG_RELAY. + (_stp_relayfs_open): Add support for CONFIG_RELAY. + + * relayfs.h: Add support for CONFIG_RELAY and + RELAYFS_VERSION_GE_4. + * transport.c (_stp_handle_buf_info.c): Add support for + CONFIG_RELAY. + * transport (_stp_transport_open.c): Add support for CONFIG_RELAY. + + * relayfs-config.h.in: New file. + 2006-03-15 Martin Hunt <hunt@redhat.com> * procfs.c (STP_DEFAULT_BUFFERS): Bump up to 256. diff --git a/runtime/transport/procfs.c b/runtime/transport/procfs.c index 96337466..22b14046 100644 --- a/runtime/transport/procfs.c +++ b/runtime/transport/procfs.c @@ -31,13 +31,13 @@ _stp_proc_read (struct file *file, char __user *buf, size_t count, loff_t *ppos) return -EINVAL; out.cpu = cpu; -#ifdef RELAYFS_VERSION_GE_4 +#if RELAYFS_VERSION_GE_4 || defined (CONFIG_RELAY) out.produced = _stp_chan->buf[cpu]->subbufs_produced; out.consumed = _stp_chan->buf[cpu]->subbufs_consumed; #else out.produced = atomic_read(&_stp_chan->buf[cpu]->subbufs_produced); out.consumed = atomic_read(&_stp_chan->buf[cpu]->subbufs_consumed); -#endif /* RELAYFS_VERSION_GE_4 */ +#endif /* RELAYFS_VERSION_GE_4 || CONFIG_RELAY */ num = sizeof(out); if (copy_to_user(buf, &out, num)) @@ -262,6 +262,38 @@ err: return _stp_current_buffers; } +#if defined (STP_RELAYFS) && defined(CONFIG_RELAY) +struct dentry *module_dir_dentry; + +static inline struct dentry *_stp_get_proc_root(void) +{ + struct file_system_type *procfs_type; + struct super_block *procfs_sb; + + procfs_type = get_fs_type("proc"); + if (!procfs_type || list_empty(&procfs_type->fs_supers)) + return NULL; + procfs_sb = list_entry(procfs_type->fs_supers.next, + struct super_block, s_instances); + return procfs_sb->s_root; +} + +static inline struct dentry *_stp_force_dir_creation(const char *dirname, struct dentry *parent) +{ + struct dentry *dir_dentry; + + mutex_lock(&parent->d_inode->i_mutex); + dir_dentry = lookup_one_len(dirname, parent, strlen(dirname)); + mutex_unlock(&parent->d_inode->i_mutex); + if (IS_ERR(dir_dentry)) { + dir_dentry = NULL; + remove_proc_entry(dirname, NULL); + } + + return dir_dentry; +} +#endif /* STP_RELAYFS && CONFIG_RELAY */ + static int _stp_register_procfs (void) { int i; @@ -270,6 +302,10 @@ static int _stp_register_procfs (void) int j; char buf[8]; #endif +#if defined (CONFIG_RELAY) + struct dentry *proc_root_dentry; + struct dentry *systemtap_dir_dentry; +#endif /* CONFIG_RELAY */ struct proc_dir_entry *de; struct list_head *p, *tmp; @@ -301,11 +337,23 @@ static int _stp_register_procfs (void) goto err0; } +#if defined (STP_RELAYFS) && defined (CONFIG_RELAY) + proc_root_dentry = _stp_get_proc_root(); + systemtap_dir_dentry = _stp_force_dir_creation(dirname, proc_root_dentry); + if (!systemtap_dir_dentry) + goto err0; +#endif /* STP_RELAYFS && CONFIG_RELAY */ /* now create /proc/systemtap/module_name */ _stp_proc_mod = proc_mkdir (THIS_MODULE->name, _stp_proc_root); if (_stp_proc_mod == NULL) goto err0; +#if defined (STP_RELAYFS) && defined (CONFIG_RELAY) + module_dir_dentry = _stp_force_dir_creation(THIS_MODULE->name, systemtap_dir_dentry); + if (!module_dir_dentry) + goto err0; +#endif /* STP_RELAYFS && CONFIG_RELAY */ + #ifdef STP_RELAYFS /* now for each cpu "n", create /proc/systemtap/module_name/n */ for_each_cpu(i) { diff --git a/runtime/transport/relayfs-config.h.in b/runtime/transport/relayfs-config.h.in new file mode 100644 index 00000000..57fcc053 --- /dev/null +++ b/runtime/transport/relayfs-config.h.in @@ -0,0 +1,2 @@ +/* relayfs version ge 4 */ +#define RELAYFS_VERSION_GE_4 @RELAYFS_VERSION_GE_4@ diff --git a/runtime/transport/relayfs.c b/runtime/transport/relayfs.c index 0754d320..6cf240fd 100644 --- a/runtime/transport/relayfs.c +++ b/runtime/transport/relayfs.c @@ -20,7 +20,7 @@ #include "relayfs.h" -#ifdef RELAYFS_VERSION_GE_4 +#if RELAYFS_VERSION_GE_4 || defined (CONFIG_RELAY) /** * _stp_subbuf_start - subbuf_start() relayfs callback implementation @@ -28,7 +28,7 @@ static int _stp_subbuf_start(struct rchan_buf *buf, void *subbuf, void *prev_subbuf, - unsigned int prev_padding) + size_t prev_padding) { if (relay_buf_full(buf)) return 0; @@ -36,7 +36,7 @@ static int _stp_subbuf_start(struct rchan_buf *buf, if (prev_subbuf) *((unsigned *)prev_subbuf) = prev_padding; - subbuf_start_reserve(buf, sizeof(prev_padding)); + subbuf_start_reserve(buf, sizeof(unsigned int)); return 1; } @@ -69,22 +69,83 @@ static void _stp_buf_full(struct rchan_buf *buf, *((unsigned *)subbuf) = padding; } -#endif /* RELAYFS_VERSION_GE_4 */ +#endif /* RELAYFS_VERSION_GE_4 || CONFIG_RELAY */ + +#if defined (CONFIG_RELAY) +static struct dentry *_stp_create_buf_file(const char *filename, + struct dentry *parent, + int mode, + struct rchan_buf *buf, + int *is_global) +{ + struct proc_dir_entry *pde; + struct dentry *dentry; + struct proc_dir_entry *parent_pde = NULL; + + if (parent) + parent_pde = PDE(parent->d_inode); + pde = create_proc_entry(filename, S_IFREG|S_IRUSR, parent_pde); + if (unlikely(!pde)) + return NULL; + pde->proc_fops = &relay_file_operations; + + mutex_lock(&parent->d_inode->i_mutex); + dentry = lookup_one_len(filename, parent, strlen(filename)); + mutex_unlock(&parent->d_inode->i_mutex); + if (IS_ERR(dentry)) + remove_proc_entry(filename, parent_pde); + + dentry->d_inode->u.generic_ip = buf; + + return dentry; +} + +static int _stp_remove_buf_file(struct dentry *dentry) +{ + struct proc_dir_entry *pde = PDE(dentry->d_inode); + + remove_proc_entry(pde->name, pde->parent); + + return 0; +} +#endif /* CONFIG_RELAY */ /* relayfs callback functions */ +#if defined (CONFIG_RELAY) +static struct rchan_callbacks stp_rchan_callbacks = +{ + .subbuf_start = _stp_subbuf_start, + .create_buf_file = _stp_create_buf_file, + .remove_buf_file = _stp_remove_buf_file, +}; +#else static struct rchan_callbacks stp_rchan_callbacks = { .subbuf_start = _stp_subbuf_start, -#ifndef RELAYFS_VERSION_GE_4 +#if !RELAYFS_VERSION_GE_4 .buf_full = _stp_buf_full, -#endif /* RELAYFS_VERSION_GE_4 */ +#endif /* !RELAYFS_VERSION_GE_4 */ }; +#endif /* CONFIG_RELAY */ /** * _stp_relayfs_close - destroys relayfs channel * @chan: the relayfs channel * @dir: the directory containing the relayfs files */ +#if defined (CONFIG_RELAY) +void _stp_relayfs_close(struct rchan *chan, struct dentry *dir) +{ + if (!chan) + return; + + relay_close(chan); + if (dir) { + struct proc_dir_entry *pde = PDE(dir->d_inode); + remove_proc_entry(pde->name, pde->parent); + } +} +#else void _stp_relayfs_close(struct rchan *chan, struct dentry *dir) { if (!chan) @@ -94,6 +155,7 @@ void _stp_relayfs_close(struct rchan *chan, struct dentry *dir) if (dir) relayfs_remove_dir(dir); } +#endif /* CONFIG_RELAY */ /** * _stp_relayfs_open - create relayfs channel @@ -101,11 +163,38 @@ void _stp_relayfs_close(struct rchan *chan, struct dentry *dir) * @subbuf_size: size of relayfs sub-buffers * @pid: daemon pid * @outdir: receives directory dentry + * @parentdir: parent directory dentry * * Returns relay channel, NULL on failure * * Creates relayfs files as /systemtap/pid/cpuX in relayfs root */ +#if defined (CONFIG_RELAY) +extern struct dentry *module_dentry; +struct rchan *_stp_relayfs_open(unsigned n_subbufs, + unsigned subbuf_size, + int pid, + struct dentry **outdir, + struct dentry *parent_dir) +{ + char dirname[16]; + struct rchan *chan; + struct dentry* dir = NULL; + + sprintf(dirname, "%d", pid); + + /* TODO: need to create systemtap dir */ + chan = relay_open("cpu", parent_dir, subbuf_size, + n_subbufs, &stp_rchan_callbacks); + if (!chan) { + printk("STP: couldn't create relayfs channel.\n"); + if (dir) + remove_proc_entry(dirname, NULL); + } + *outdir = dir; + return chan; +} +#else struct rchan *_stp_relayfs_open(unsigned n_subbufs, unsigned subbuf_size, int pid, @@ -124,7 +213,7 @@ struct rchan *_stp_relayfs_open(unsigned n_subbufs, return NULL; } -#ifdef RELAYFS_VERSION_GE_4 +#if RELAYFS_VERSION_GE_4 chan = relay_open("cpu", dir, subbuf_size, n_subbufs, &stp_rchan_callbacks); #else @@ -141,6 +230,7 @@ struct rchan *_stp_relayfs_open(unsigned n_subbufs, *outdir = dir; return chan; } +#endif /* CONFIG_RELAY */ #endif /* _TRANSPORT_RELAYFS_C_ */ diff --git a/runtime/transport/relayfs.h b/runtime/transport/relayfs.h index 5ca174e4..aafb26b2 100644 --- a/runtime/transport/relayfs.h +++ b/runtime/transport/relayfs.h @@ -5,16 +5,30 @@ * @brief Header file for relayfs transport */ -#ifdef RELAYFS_VERSION_GE_4 -#include <linux/relayfs_fs.h> +#include "relayfs-config.h" + +#if defined (CONFIG_RELAYFS_FS) || defined (CONFIG_RELAYFS_FS_MODULE) +# include <linux/relayfs_fs.h> +#elif defined (CONFIG_RELAY) +# include <linux/relay.h> +# include <linux/namei.h> #else -#include "../relayfs/linux/relayfs_fs.h" -#endif /* RELAYFS_VERSION_GE_4 */ +# undef STP_RELAYFS +#endif +#if defined (CONFIG_RELAY) +struct rchan *_stp_relayfs_open(unsigned n_subbufs, + unsigned subbuf_size, + int pid, + struct dentry **outdir, + struct dentry *parent_dir); +#else struct rchan *_stp_relayfs_open(unsigned n_subbufs, unsigned subbuf_size, int pid, struct dentry **outdir); +#endif + void _stp_relayfs_close(struct rchan *chan, struct dentry *dir); #endif /* _TRANSPORT_RELAYFS_H_ */ diff --git a/runtime/transport/transport.c b/runtime/transport/transport.c index a38d1f56..01bab497 100644 --- a/runtime/transport/transport.c +++ b/runtime/transport/transport.c @@ -82,13 +82,13 @@ static void _stp_handle_buf_info(int *cpuptr) struct buf_info out; out.cpu = *cpuptr; -#ifdef RELAYFS_VERSION_GE_4 +#if RELAYFS_VERSION_GE_4 || defined (CONFIG_RELAY) out.produced = _stp_chan->buf[*cpuptr]->subbufs_produced; out.consumed = _stp_chan->buf[*cpuptr]->subbufs_consumed; #else out.produced = atomic_read(&_stp_chan->buf[*cpuptr]->subbufs_produced); out.consumed = atomic_read(&_stp_chan->buf[*cpuptr]->subbufs_consumed); -#endif /* RELAYFS_VERSION_GE_4 */ +#endif /* RELAYFS_VERSION_GE_4 || CONFIG_RELAY */ _stp_transport_send(STP_BUF_INFO, &out, sizeof(out)); } @@ -190,6 +190,10 @@ void _stp_transport_close() kbug("---- CLOSED ----\n"); } +#if defined (STP_RELAYFS) && defined (CONFIG_RELAY) +extern struct dentry *module_dir_dentry; +#endif /* STP_RELAYFS && CONFIG_RELAY */ + /** * _stp_transport_open - open proc and relayfs channels * with proper parameters @@ -223,7 +227,11 @@ int _stp_transport_open(struct transport_info *info) info->n_subbufs = n_subbufs; info->subbuf_size = subbuf_size; +#if defined (CONFIG_RELAY) + _stp_chan = _stp_relayfs_open(n_subbufs, subbuf_size, _stp_pid, &_stp_dir, module_dir_dentry); +#else _stp_chan = _stp_relayfs_open(n_subbufs, subbuf_size, _stp_pid, &_stp_dir); +#endif /* CONFIG_RELAY */ if (!_stp_chan) { _stp_unregister_procfs(); return -ENOMEM; |