From 8e78f70b1553cedacf211d6b8a9465fcd38c4198 Mon Sep 17 00:00:00 2001 From: bobijam Date: Tue, 19 Aug 2008 02:23:12 +0000 Subject: [PATCH] Branch b1_6 b=16566 o=Jonathan Li(jli@cray.com) i=shadow, bobijam Description: Upcall on Lustre log has been dumped Details : Allow for a user mode script to be called once a Lustre log has been dumped. It passes the filename of the dumped log to the script, the location of the script can be specified via /proc/sys/lnet/debug_log_upcall. --- lnet/libcfs/debug.c | 4 ++++ lnet/libcfs/linux/linux-debug.c | 36 ++++++++++++++++++++++++++++++++++++ lnet/libcfs/linux/linux-proc.c | 37 ++++++++++++++++++++++++------------- lnet/libcfs/tracefile.h | 8 +++++--- 4 files changed, 69 insertions(+), 16 deletions(-) diff --git a/lnet/libcfs/debug.c b/lnet/libcfs/debug.c index fa55ae6..fb2fe5c 100644 --- a/lnet/libcfs/debug.c +++ b/lnet/libcfs/debug.c @@ -421,6 +421,9 @@ libcfs_debug_str2mask(int *mask, const char *str, int is_subsys) return 0; } +/** + * Dump Lustre log to ::debug_file_path by calling tracefile_dump_all_pages() + */ void libcfs_debug_dumplog_internal(void *arg) { CFS_DECL_JOURNAL_DATA; @@ -434,6 +437,7 @@ void libcfs_debug_dumplog_internal(void *arg) printk(KERN_ALERT "LustreError: dumping log to %s\n", debug_file_name); tracefile_dump_all_pages(debug_file_name); + libcfs_run_debug_log_upcall(debug_file_name); } CFS_POP_JOURNAL; } diff --git a/lnet/libcfs/linux/linux-debug.c b/lnet/libcfs/linux/linux-debug.c index 7d2592c..e0eade8 100644 --- a/lnet/libcfs/linux/linux-debug.c +++ b/lnet/libcfs/linux/linux-debug.c @@ -79,6 +79,42 @@ #endif char lnet_upcall[1024] = "/usr/lib/lustre/lnet_upcall"; +char lnet_debug_log_upcall[1024] = "/usr/lib/lustre/lnet_debug_log_upcall"; + +/** + * Upcall function once a Lustre log has been dumped. + * + * \param file path of the dumped log + */ +void libcfs_run_debug_log_upcall(char *file) +{ + char *argv[3]; + int rc; + char *envp[] = { + "HOME=/", + "PATH=/sbin:/bin:/usr/sbin:/usr/bin", + NULL}; + ENTRY; + + argv[0] = lnet_debug_log_upcall; + + LASSERTF(file != NULL, "called on a null filename\n"); + argv[1] = file; //only need to pass the path of the file + + argv[2] = NULL; + + rc = USERMODEHELPER(argv[0], argv, envp); + if (rc < 0 && rc != -ENOENT) { + CERROR("Error %d invoking LNET debug log upcall %s %s; " + "check /proc/sys/lnet/debug_log_upcall\n", + rc, argv[0], argv[1]); + } else { + CDEBUG(D_HA, "Invoked LNET debug log upcall %s %s\n", + argv[0], argv[1]); + } + + EXIT; +} void libcfs_run_upcall(char **argv) { diff --git a/lnet/libcfs/linux/linux-proc.c b/lnet/libcfs/linux/linux-proc.c index 1b75f9e..cbada7ca 100644 --- a/lnet/libcfs/linux/linux-proc.c +++ b/lnet/libcfs/linux/linux-proc.c @@ -78,6 +78,10 @@ static cfs_sysctl_table_header_t *lnet_table_header = NULL; extern char lnet_upcall[1024]; +/** + * The path of debug log dump upcall script. + */ +extern char lnet_debug_log_upcall[1024]; #define PSDEV_LNET (0x100) enum { @@ -97,11 +101,12 @@ enum { PSDEV_LNET_DUMP_KERNEL, /* snapshot kernel debug buffer to file */ PSDEV_LNET_DAEMON_FILE, /* spool kernel debug buffer to file */ PSDEV_LNET_DEBUG_MB, /* size of debug buffer */ + PSDEV_LNET_DEBUG_LOG_UPCALL, /* debug log upcall script */ }; -static int -proc_call_handler(void *data, int write, - loff_t *ppos, void *buffer, size_t *lenp, +static int +proc_call_handler(void *data, int write, + loff_t *ppos, void *buffer, size_t *lenp, int (*handler)(void *data, int write, loff_t pos, void *buffer, int len)) { @@ -130,7 +135,7 @@ LL_PROC_PROTO(name) \ __##name); \ } -static int __proc_dobitmasks(void *data, int write, +static int __proc_dobitmasks(void *data, int write, loff_t pos, void *buffer, int nob) { const int tmpstrlen = 512; @@ -176,7 +181,7 @@ static int __proc_dump_kernel(void *data, int write, { if (!write) return 0; - + return trace_dump_debug_buffer_usrstr(buffer, nob); } @@ -187,14 +192,14 @@ static int __proc_daemon_file(void *data, int write, { if (!write) { int len = strlen(tracefile); - + if (pos >= len) return 0; - - return trace_copyout_string(buffer, nob, + + return trace_copyout_string(buffer, nob, tracefile + pos, "\n"); } - + return trace_daemon_command_usrstr(buffer, nob); } @@ -210,10 +215,10 @@ static int __proc_debug_mb(void *data, int write, if (pos >= len) return 0; - + return trace_copyout_string(buffer, nob, tmpstr + pos, "\n"); } - + return trace_set_debug_mb_usrstr(buffer, nob); } @@ -366,7 +371,6 @@ static cfs_sysctl_table_t lnet_table[] = { .mode = 0644, .proc_handler = &proc_console_backoff }, - { .ctl_name = PSDEV_DEBUG_PATH, .procname = "debug_path", @@ -375,7 +379,6 @@ static cfs_sysctl_table_t lnet_table[] = { .mode = 0644, .proc_handler = &proc_dostring, }, - { .ctl_name = PSDEV_LNET_UPCALL, .procname = "upcall", @@ -385,6 +388,14 @@ static cfs_sysctl_table_t lnet_table[] = { .proc_handler = &proc_dostring, }, { + .ctl_name = PSDEV_LNET_DEBUG_LOG_UPCALL, + .procname = "debug_log_upcall", + .data = lnet_debug_log_upcall, + .maxlen = sizeof(lnet_debug_log_upcall), + .mode = 0644, + .proc_handler = &proc_dostring, + }, + { .ctl_name = PSDEV_LNET_MEMUSED, .procname = "memused", .data = (int *)&libcfs_kmemory.counter, diff --git a/lnet/libcfs/tracefile.h b/lnet/libcfs/tracefile.h index 0493063..dd25327 100644 --- a/lnet/libcfs/tracefile.h +++ b/lnet/libcfs/tracefile.h @@ -45,6 +45,8 @@ extern char tracefile[TRACEFILE_NAME_SIZE]; extern long long tracefile_size; +extern void libcfs_run_debug_log_upcall(char *file); + int tracefile_init_arch(void); void tracefile_fini_arch(void); @@ -96,7 +98,7 @@ extern int trace_max_debug_mb(void); #define TRACEFILE_SIZE (500 << 20) -/* Size of a buffer for sprinting console messages if we can't get a page +/* Size of a buffer for sprinting console messages if we can't get a page * from system */ #define TRACE_CONSOLE_BUFFER_SIZE 1024 @@ -125,7 +127,7 @@ union trace_data_union { /* * Maximal number of pages allowed on ->tcd_pages and - * ->tcd_daemon_pages each. + * ->tcd_daemon_pages each. * Always TCD_MAX_PAGES * tcd_pages_factor / 100 in current * implementation. */ @@ -233,7 +235,7 @@ struct trace_page { */ unsigned short cpu; /* - * type(context) of this page + * type(context) of this page */ unsigned short type; }; -- 1.8.3.1