From: James Simmons Date: Fri, 15 Nov 2013 13:16:01 +0000 (-0500) Subject: LU-3319 procfs: provide framework for seq_file handling X-Git-Tag: 2.5.52~22 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=3270bfc2370884933628f95122da00d430db6072 LU-3319 procfs: provide framework for seq_file handling In linux 3.10 kernels and above the proc file system interface changed. To handle this change we need to move from the current method of using proc_read and proc_write function pointers to using the seq_file. This patch provides the base to enable moving all the lustre proc handling gradually over to this new method of proc data handling. Signed-off-by: James Simmons Change-Id: I06d941398bf248bffab851f9f25bea6bbe438a30 Reviewed-on: http://review.whamcloud.com/7135 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Bob Glossman Reviewed-by: Yang Sheng Reviewed-by: Oleg Drokin --- diff --git a/libcfs/include/libcfs/darwin/darwin-prim.h b/libcfs/include/libcfs/darwin/darwin-prim.h index 8385acc..07edf35 100644 --- a/libcfs/include/libcfs/darwin/darwin-prim.h +++ b/libcfs/include/libcfs/darwin/darwin-prim.h @@ -123,9 +123,9 @@ cfs_proc_dir_entry_t * cfs_create_proc_entry(char *name, int mod, void cfs_free_proc_entry(cfs_proc_dir_entry_t *de); void cfs_remove_proc_entry(char *name, cfs_proc_dir_entry_t *entry); -typedef int (cfs_read_proc_t)(char *page, char **start, off_t off, +typedef int (read_proc_t)(char *page, char **start, off_t off, int count, int *eof, void *data); -typedef int (cfs_write_proc_t)(struct file *file, const char *buffer, +typedef int (write_proc_t)(struct file *file, const char *buffer, unsigned long count, void *data); /* diff --git a/libcfs/include/libcfs/linux/linux-prim.h b/libcfs/include/libcfs/linux/linux-prim.h index e525279..56a990c 100644 --- a/libcfs/include/libcfs/linux/linux-prim.h +++ b/libcfs/include/libcfs/linux/linux-prim.h @@ -95,8 +95,6 @@ LL_PROC_PROTO(name) \ /* * Proc file system APIs */ -typedef read_proc_t cfs_read_proc_t; -typedef write_proc_t cfs_write_proc_t; typedef struct proc_dir_entry cfs_proc_dir_entry_t; #define cfs_create_proc_entry(n, m, p) create_proc_entry(n, m, p) #define cfs_free_proc_entry(e) free_proc_entry(e) diff --git a/libcfs/include/libcfs/params_tree.h b/libcfs/include/libcfs/params_tree.h index 3e94d7d..238408c 100644 --- a/libcfs/include/libcfs/params_tree.h +++ b/libcfs/include/libcfs/params_tree.h @@ -48,32 +48,14 @@ #endif #ifdef LPROCFS -typedef struct file cfs_param_file_t; typedef struct inode cfs_inode_t; -typedef struct proc_inode cfs_proc_inode_t; -typedef struct seq_file cfs_seq_file_t; -typedef struct seq_operations cfs_seq_ops_t; typedef struct file_operations cfs_param_file_ops_t; typedef struct proc_dir_entry cfs_param_dentry_t; typedef struct poll_table_struct cfs_poll_table_t; #define CFS_PARAM_MODULE THIS_MODULE -#define CFS_PDE(value) PDE(value) #define cfs_file_private(file) (file->private_data) -#define cfs_dentry_data(dentry) (dentry->data) -#define cfs_proc_inode_pde(proc_inode) (proc_inode->pde) -#define cfs_proc_inode(proc_inode) (proc_inode->vfs_inode) -#define cfs_seq_read_common seq_read -#define cfs_seq_lseek_common seq_lseek -#define cfs_seq_private(seq) (seq->private) -#define cfs_seq_printf(seq, format, ...) seq_printf(seq, format, \ - ## __VA_ARGS__) -#define cfs_seq_release(inode, file) seq_release(inode, file) -#define cfs_seq_puts(seq, s) seq_puts(seq, s) -#define cfs_seq_putc(seq, s) seq_putc(seq, s) -#define cfs_seq_read(file, buf, count, ppos, rc) (rc = seq_read(file, buf, \ - count, ppos)) -#define cfs_seq_open(file, ops, rc) (rc = seq_open(file, ops)) +#ifndef HAVE_ONLY_PROCFS_SEQ /* in lprocfs_stat.c, to protect the private data for proc entries */ extern struct rw_semaphore _lprocfs_lock; @@ -109,104 +91,126 @@ do { \ do { \ up_write(&_lprocfs_lock); \ } while(0) + +#define PDE_DATA(inode) PDE(inode)->data + +#else /* New proc api */ + +static inline cfs_param_dentry_t* PDE(struct inode *inode) +{ + return NULL; +} + +static inline +int LPROCFS_ENTRY_CHECK(cfs_param_dentry_t *dp) +{ + return 0; +} + +#define LPROCFS_WRITE_ENTRY() do {} while(0) +#define LPROCFS_WRITE_EXIT() do {} while(0) + +#endif + #else /* !LPROCFS */ -typedef struct cfs_params_file { - void *param_private; - loff_t param_pos; - unsigned int param_flags; -} cfs_param_file_t; +struct file { + void *param_private; + loff_t param_pos; + unsigned int param_flags; +}; typedef struct cfs_param_inode { - void *param_private; + void *param_private; } cfs_inode_t; typedef struct cfs_param_dentry { - void *param_data; + void *param_data; } cfs_param_dentry_t; typedef struct cfs_proc_inode { - cfs_param_dentry_t *param_pde; - cfs_inode_t param_inode; + cfs_param_dentry_t *param_pde; + cfs_inode_t param_inode; } cfs_proc_inode_t; -struct cfs_seq_operations; -typedef struct cfs_seq_file { - char *buf; - size_t size; - size_t from; - size_t count; - loff_t index; - loff_t version; +struct seq_operations; +struct seq_file { + char *buf; + size_t size; + size_t from; + size_t count; + loff_t index; + loff_t version; struct mutex lock; - struct cfs_seq_operations *op; - void *private; -} cfs_seq_file_t; + const struct seq_operations *op; + void *private; +}; -typedef struct cfs_seq_operations { - void *(*start) (cfs_seq_file_t *m, loff_t *pos); - void (*stop) (cfs_seq_file_t *m, void *v); - void *(*next) (cfs_seq_file_t *m, void *v, loff_t *pos); - int (*show) (cfs_seq_file_t *m, void *v); -} cfs_seq_ops_t; +struct seq_operations { + void *(*start) (struct seq_file *m, loff_t *pos); + void (*stop) (struct seq_file *m, void *v); + void *(*next) (struct seq_file *m, void *v, loff_t *pos); + int (*show) (struct seq_file *m, void *v); +}; typedef void *cfs_poll_table_t; -typedef struct cfs_param_file_ops{ +typedef struct cfs_param_file_ops { struct module *owner; int (*open) (cfs_inode_t *, struct file *); loff_t (*llseek)(struct file *, loff_t, int); - int (*release) (cfs_inode_t *, cfs_param_file_t *); + int (*release) (cfs_inode_t *, struct file *); unsigned int (*poll) (struct file *, cfs_poll_table_t *); ssize_t (*write) (struct file *, const char *, size_t, loff_t *); ssize_t (*read)(struct file *, char *, size_t, loff_t *); } cfs_param_file_ops_t; typedef cfs_param_file_ops_t *cfs_lproc_filep_t; -static inline cfs_proc_inode_t *FAKE_PROC_I(const cfs_inode_t *inode) +#define CFS_PARAM_MODULE NULL +#define seq_lseek NULL + +static inline int seq_read(char *buf, size_t count, loff_t *ppos) { - return container_of(inode, cfs_proc_inode_t, param_inode); + return 0; } -static inline cfs_param_dentry_t *FAKE_PDE(cfs_inode_t *inode) +static inline int +seq_open(struct file *file, const struct seq_operations *fops) { - return FAKE_PROC_I(inode)->param_pde; + struct seq_file *p = file->param_private; + + if (!p) { + LIBCFS_ALLOC(p, sizeof(*p)); + if (!p) + return -ENOMEM; + file->param_private = p; + } + memset(p, 0, sizeof(*p)); + p->op = fops; + return 0; } -#define CFS_PARAM_MODULE NULL -#define CFS_PDE(value) FAKE_PDE(value) -#define cfs_file_private(file) (file->param_private) -#define cfs_dentry_data(dentry) (dentry->param_data) -#define cfs_proc_inode(proc_inode) (proc_inode->param_inode) -#define cfs_proc_inode_pde(proc_inode) (proc_inode->param_pde) -#define cfs_seq_read_common NULL -#define cfs_seq_lseek_common NULL -#define cfs_seq_private(seq) (seq->private) -#define cfs_seq_read(file, buf, count, ppos, rc) do {} while(0) -#define cfs_seq_open(file, ops, rc) \ -do { \ - cfs_seq_file_t *p = cfs_file_private(file); \ - if (!p) { \ - LIBCFS_ALLOC(p, sizeof(*p)); \ - if (!p) { \ - rc = -ENOMEM; \ - break; \ - } \ - cfs_file_private(file) = p; \ - } \ - memset(p, 0, sizeof(*p)); \ - p->op = ops; \ - rc = 0; \ -} while(0) +static inline cfs_proc_inode_t *FAKE_PROC_I(const cfs_inode_t *inode) +{ + return container_of(inode, cfs_proc_inode_t, param_inode); +} + +static inline cfs_param_dentry_t *PDE(cfs_inode_t *inode) +{ + return FAKE_PROC_I(inode)->param_pde; +} static inline int LPROCFS_ENTRY_CHECK(cfs_param_dentry_t *dp) { - return 0; + return 0; } #define LPROCFS_WRITE_ENTRY() do {} while(0) #define LPROCFS_WRITE_EXIT() do {} while(0) +int seq_printf(struct seq_file *, const char *, ...) + __attribute__ ((format (printf,2,3))); + #endif /* LPROCFS */ /* XXX: params_tree APIs */ diff --git a/libcfs/include/libcfs/user-prim.h b/libcfs/include/libcfs/user-prim.h index 33e0f62..ab2671e 100644 --- a/libcfs/include/libcfs/user-prim.h +++ b/libcfs/include/libcfs/user-prim.h @@ -128,11 +128,11 @@ static inline void schedule_timeout(int64_t t) {} /* * Lproc */ -typedef int (cfs_read_proc_t)(char *page, char **start, off_t off, - int count, int *eof, void *data); +typedef int (read_proc_t)(char *page, char **start, off_t off, + int count, int *eof, void *data); struct file; /* forward ref */ -typedef int (cfs_write_proc_t)(struct file *file, const char *buffer, +typedef int (write_proc_t)(struct file *file, const char *buffer, unsigned long count, void *data); /* diff --git a/libcfs/include/libcfs/winnt/winnt-prim.h b/libcfs/include/libcfs/winnt/winnt-prim.h index 153a9a8..21a475c 100644 --- a/libcfs/include/libcfs/winnt/winnt-prim.h +++ b/libcfs/include/libcfs/winnt/winnt-prim.h @@ -132,9 +132,9 @@ int misc_deregister(struct miscdevice *psdev); * Proc emulator file system APIs */ -typedef int cfs_read_proc_t(char *page, char **start, off_t off, +typedef int read_proc_t(char *page, char **start, off_t off, int count, int *eof, void *data); -typedef int cfs_write_proc_t(struct file *file, const char *buffer, +typedef int write_proc_t(struct file *file, const char *buffer, unsigned long count, void *data); #define CFS_PROC_ENTRY_MAGIC 'CPEM' @@ -155,8 +155,8 @@ typedef struct cfs_proc_entry struct cfs_proc_entry *parent; struct _file_entry { // proc file / leaf entry - cfs_read_proc_t * read_proc; - cfs_write_proc_t * write_proc; + read_proc_t * read_proc; + write_proc_t * write_proc; }; mode_t mode; @@ -332,9 +332,6 @@ int seq_escape(struct seq_file *, const char *, const char *); int seq_putc(struct seq_file *m, char c); int seq_puts(struct seq_file *m, const char *s); -int seq_printf(struct seq_file *, const char *, ...) - __attribute__ ((format (printf,2,3))); - int seq_path(struct seq_file *, struct path *, char *); int single_open(struct file *, int (*)(struct seq_file *, void *), void *); diff --git a/libcfs/libcfs/autoMakefile.am b/libcfs/libcfs/autoMakefile.am index 66154b1..2f6f9ab 100644 --- a/libcfs/libcfs/autoMakefile.am +++ b/libcfs/libcfs/autoMakefile.am @@ -47,7 +47,7 @@ libcfs_a_SOURCES= posix/posix-debug.c user-prim.c user-lock.c user-tcpip.c \ prng.c user-bitops.c user-mem.c hash.c kernel_user_comm.c \ workitem.c fail.c libcfs_cpu.c libcfs_mem.c libcfs_lock.c \ posix/rbtree.c user-crypto.c posix/posix-crc32.c \ - posix/posix-adler.c heap.c + posix/posix-adler.c posix/posix-proc.c heap.c if HAVE_PCLMULQDQ if NEED_PCLMULQDQ_CRC32 @@ -75,9 +75,9 @@ macos_PROGRAMS = libcfs nodist_libcfs_SOURCES = darwin/darwin-sync.c darwin/darwin-mem.c \ darwin/darwin-prim.c darwin/darwin-fs.c darwin/darwin-curproc.c \ - darwin/darwin-tcpip.c darwin/darwin-utils.c \ - darwin/darwin-debug.c darwin/darwin-proc.c \ - darwin/darwin-tracefile.c darwin/darwin-module.c \ + darwin/darwin-tcpip.c darwin/darwin-utils.c \ + darwin/darwin-debug.c darwin/darwin-proc.c \ + darwin/darwin-tracefile.c darwin/darwin-module.c \ posix/posix-debug.c module.c tracefile.c nidstrings.c watchdog.c \ kernel_user_comm.c hash.c posix/rbtree.c heap.c diff --git a/libcfs/libcfs/posix/posix-proc.c b/libcfs/libcfs/posix/posix-proc.c new file mode 100644 index 0000000..8566ff7 --- /dev/null +++ b/libcfs/libcfs/posix/posix-proc.c @@ -0,0 +1,44 @@ +/* + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.gnu.org/licenses/gpl-2.0.html + * + * GPL HEADER END + */ +/* + * Authors: James Simmons + */ +#include + +int seq_printf(struct seq_file *m, const char *f, ...) +{ + va_list args; + int len; + + if (m->count < m->size) { + va_start(args, f); + len = vsnprintf(m->buf + m->count, m->size - m->count, f, args); + va_end(args); + if (m->count + len < m->size) { + m->count += len; + return 0; + } + } + m->count = m->size; + return -1; +} +EXPORT_SYMBOL(seq_printf); diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 583d759..d31510bc 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -1221,6 +1221,24 @@ LB_LINUX_TRY_COMPILE([ ]) # +# 3.10+ only supports procfs seq_files handling +# +AC_DEFUN([LC_HAVE_ONLY_PROCFS_SEQ], +[AC_MSG_CHECKING([if procfs only supports using seq_files]) +LB_LINUX_TRY_COMPILE([ + #include +],[ + struct inode *inode = NULL; + PDE_DATA(inode); +],[ + AC_DEFINE(HAVE_ONLY_PROCFS_SEQ, 1, [only seq_files supported]) + AC_MSG_RESULT([yes]) +],[ + AC_MSG_RESULT([no]) +]) +]) + +# # LC_PROG_LINUX # # Lustre linux kernel checks @@ -1314,6 +1332,9 @@ AC_DEFUN([LC_PROG_LINUX], LC_HAVE_HLIST_FOR_EACH_3ARG LC_HAVE_F_PATH_MNT + # 3.10 + LC_HAVE_ONLY_PROCFS_SEQ + # if test x$enable_server != xno ; then LC_FUNC_DEV_SET_RDONLY diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index 6156c08..2080592 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -54,21 +54,34 @@ #include #include +#ifndef HAVE_ONLY_PROCFS_SEQ struct lprocfs_vars { const char *name; - cfs_read_proc_t *read_fptr; - cfs_write_proc_t *write_fptr; + read_proc_t *read_fptr; + write_proc_t *write_fptr; void *data; const struct file_operations *fops; /** * /proc file mode. - */ - mode_t proc_mode; + */ + mode_t proc_mode; }; struct lprocfs_static_vars { - struct lprocfs_vars *module_vars; - struct lprocfs_vars *obd_vars; + struct lprocfs_vars *module_vars; + struct lprocfs_vars *obd_vars; +}; + +#endif + +struct lprocfs_seq_vars { + const char *name; + const struct file_operations *fops; + void *data; + /** + * /proc file mode. + */ + mode_t proc_mode; }; /* if we find more consumers this could be generalized */ @@ -573,13 +586,17 @@ struct obd_export; struct nid_stat; extern int lprocfs_add_clear_entry(struct obd_device * obd, cfs_proc_dir_entry_t *entry); +#ifdef HAVE_SERVER_SUPPORT extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid, int *newnid); +#endif extern int lprocfs_exp_cleanup(struct obd_export *exp); extern cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root, char *name, - cfs_read_proc_t *read_proc, - cfs_write_proc_t *write_proc, +#ifndef HAVE_ONLY_PROCFS_SEQ + read_proc_t *read_proc, + write_proc_t *write_proc, +#endif void *data, struct file_operations *fops); extern struct proc_dir_entry * @@ -596,28 +613,39 @@ extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name, struct lprocfs_stats *stats); /* lprocfs_status.c */ +#ifndef HAVE_ONLY_PROCFS_SEQ extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root, struct lprocfs_vars *var, void *data); extern cfs_proc_dir_entry_t *lprocfs_register(const char *name, - cfs_proc_dir_entry_t *parent, - struct lprocfs_vars *list, - void *data); + cfs_proc_dir_entry_t *parent, + struct lprocfs_vars *list, + void *data); +#endif +extern int lprocfs_seq_add_vars(cfs_proc_dir_entry_t *root, + struct lprocfs_seq_vars *var, + void *data); +extern cfs_proc_dir_entry_t * +lprocfs_seq_register(const char *name, cfs_proc_dir_entry_t *parent, + struct lprocfs_seq_vars *list, void *data); extern void lprocfs_remove(cfs_proc_dir_entry_t **root); extern void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent); +#ifndef HAVE_ONLY_PROCFS_SEQ extern void lprocfs_try_remove_proc_entry(const char *name, struct proc_dir_entry *parent); extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root, const char *name); - extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list); +#endif +extern int lprocfs_seq_obd_setup(struct obd_device *dev); extern int lprocfs_obd_cleanup(struct obd_device *obd); +#ifdef HAVE_SERVER_SUPPORT extern struct file_operations lprocfs_evict_client_fops; - +#endif extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, const char *name, mode_t mode, const struct file_operations *seq_fops, @@ -628,7 +656,7 @@ extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name, void *data); /* Generic callbacks */ - +#ifndef HAVE_ONLY_PROCFS_SEQ extern int lprocfs_rd_u64(char *page, char **start, off_t off, int count, int *eof, void *data); extern int lprocfs_rd_atomic(char *page, char **start, off_t off, @@ -637,8 +665,6 @@ extern int lprocfs_wr_atomic(struct file *file, const char *buffer, unsigned long count, void *data); extern int lprocfs_rd_uint(char *page, char **start, off_t off, int count, int *eof, void *data); -extern int lprocfs_wr_uint(struct file *file, const char *buffer, - unsigned long count, void *data); extern int lprocfs_rd_uuid(char *page, char **start, off_t off, int count, int *eof, void *data); extern int lprocfs_rd_name(char *page, char **start, off_t off, @@ -657,15 +683,41 @@ extern int lprocfs_rd_num_exports(char *page, char **start, off_t off, int count, int *eof, void *data); extern int lprocfs_rd_numrefs(char *page, char **start, off_t off, int count, int *eof, void *data); +#endif +extern int lprocfs_u64_seq_show(struct seq_file *m, void *data); +extern int lprocfs_atomic_seq_show(struct seq_file *m, void *data); +extern ssize_t lprocfs_atomic_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off); +extern int lprocfs_uint_seq_show(struct seq_file *m, void *data); +extern ssize_t lprocfs_uint_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off); +extern int lprocfs_wr_uint(struct file *file, const char *buffer, + unsigned long count, void *data); +extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data); +extern int lprocfs_name_seq_show(struct seq_file *m, void *data); +extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data); +extern int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data); +extern int lprocfs_import_seq_show(struct seq_file *m, void *data); +extern int lprocfs_state_seq_show(struct seq_file *m, void *data); +extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data); struct adaptive_timeout; +#ifndef HAVE_ONLY_PROCFS_SEQ extern int lprocfs_at_hist_helper(char *page, int count, int rc, struct adaptive_timeout *at); extern int lprocfs_rd_timeouts(char *page, char **start, off_t off, int count, int *eof, void *data); extern int lprocfs_wr_timeouts(struct file *file, const char *buffer, unsigned long count, void *data); +#endif +extern int lprocfs_seq_at_hist_helper(struct seq_file *m, + struct adaptive_timeout *at); +extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data); +extern ssize_t +lprocfs_timeouts_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off); extern int lprocfs_wr_evict_client(struct file *file, const char *buffer, unsigned long count, void *data); +#ifndef HAVE_ONLY_PROCFS_SEQ extern int lprocfs_wr_ping(struct file *file, const char *buffer, unsigned long count, void *data); extern int lprocfs_wr_import(struct file *file, const char *buffer, @@ -674,8 +726,20 @@ extern int lprocfs_rd_pinger_recov(char *page, char **start, off_t off, int count, int *eof, void *data); extern int lprocfs_wr_pinger_recov(struct file *file, const char *buffer, unsigned long count, void *data); +#endif +extern ssize_t +lprocfs_ping_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off); +extern ssize_t +lprocfs_import_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off); +extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data); +extern ssize_t +lprocfs_pinger_recov_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off); /* Statfs helpers */ +#ifndef HAVE_ONLY_PROCFS_SEQ extern int lprocfs_rd_blksize(char *page, char **start, off_t off, int count, int *eof, void *data); extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off, @@ -690,11 +754,19 @@ extern int lprocfs_rd_filesfree(char *page, char **start, off_t off, int count, int *eof, void *data); extern int lprocfs_rd_filegroups(char *page, char **start, off_t off, int count, int *eof, void *data); +#endif +extern int lprocfs_blksize_seq_show(struct seq_file *m, void *data); +extern int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data); +extern int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data); +extern int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data); +extern int lprocfs_filestotal_seq_show(struct seq_file *m, void *data); +extern int lprocfs_filesfree_seq_show(struct seq_file *m, void *data); extern int lprocfs_write_helper(const char *buffer, unsigned long count, int *val); extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count, int *val, int mult); +extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult); extern int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val, int mult); extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count, @@ -703,7 +775,7 @@ extern int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count, __u64 *val, int mult); char *lprocfs_find_named_value(const char *buffer, const char *name, - unsigned long *count); + size_t *count); void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value); void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value); void lprocfs_oh_clear(struct obd_histogram *oh); @@ -712,10 +784,11 @@ unsigned long lprocfs_oh_sum(struct obd_histogram *oh); void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx, struct lprocfs_counter *cnt); +#ifdef HAVE_SERVER_SUPPORT /* lprocfs_status.c: recovery status */ int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off, int count, int *eof, void *data); - +#endif /* lprocfs_statuc.c: hash statistics */ int lprocfs_obd_rd_hash(char *page, char **start, off_t off, int count, int *eof, void *data); @@ -742,28 +815,64 @@ extern int lprocfs_seq_release(cfs_inode_t *, struct file *); #define LPROCFS_CLIMP_EXIT(obd) \ up_read(&(obd)->u.cli.cl_sem); - /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only proc entries; otherwise, you will define name##_seq_write function also for a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally, call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */ -#define __LPROC_SEQ_FOPS(name, custom_seq_write) \ -static int name##_single_open(cfs_inode_t *inode, struct file *file) { \ - struct proc_dir_entry *dp = PDE(inode); \ - LPROCFS_ENTRY_CHECK(dp); \ - return single_open(file, name##_seq_show, dp->data); \ -} \ -struct file_operations name##_fops = { \ - .owner = THIS_MODULE, \ - .open = name##_single_open, \ - .read = seq_read, \ - .write = custom_seq_write, \ - .llseek = seq_lseek, \ - .release = lprocfs_single_release, \ +#define __LPROC_SEQ_FOPS(name, custom_seq_write) \ +static int name##_single_open(cfs_inode_t *inode, struct file *file) \ +{ \ + LPROCFS_ENTRY_CHECK(PDE(inode)); \ + return single_open(file, name##_seq_show, PDE_DATA(inode)); \ +} \ +struct file_operations name##_fops = { \ + .owner = THIS_MODULE, \ + .open = name##_single_open, \ + .read = seq_read, \ + .write = custom_seq_write, \ + .llseek = seq_lseek, \ + .release = lprocfs_single_release, \ } -#define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL) -#define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write) +#define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL) +#define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write) + +#define LPROC_SEQ_FOPS_RO_TYPE(name, type) \ + static int name##_##type##_seq_show(struct seq_file *m, void *v)\ + { \ + return lprocfs_##type##_seq_show(m, m->private); \ + } \ + LPROC_SEQ_FOPS_RO(name##_##type) + +#define LPROC_SEQ_FOPS_RW_TYPE(name, type) \ + static int name##_##type##_seq_show(struct seq_file *m, void *v)\ + { \ + return lprocfs_##type##_seq_show(m, m->private); \ + } \ + static ssize_t name##_##type##_seq_write(struct file *file, \ + const char *buffer, size_t count, loff_t *off) \ + { \ + struct seq_file *seq = file->private_data; \ + return lprocfs_##type##_seq_write(file, buffer, \ + count, seq->private); \ + } \ + LPROC_SEQ_FOPS(name##_##type); + +#define LPROC_SEQ_FOPS_WO_TYPE(name, type) \ + static ssize_t name##_##type##_write(struct file *file, \ + const char *buffer, size_t count, loff_t *off) \ + { \ + return lprocfs_##type##_seq_write(file, buffer, count, off); \ + } \ + static int name##_##type##_open(cfs_inode_t *inode, struct file *file) \ + { \ + return single_open(file, NULL, PDE_DATA(inode)); \ + } \ + struct file_operations name##_##type##_fops = { \ + .open = name##_##type##_open, \ + .write = name##_##type##_write, \ + .release = lprocfs_single_release, \ + }; /* lprocfs_jobstats.c */ int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, @@ -791,10 +900,16 @@ int lprocfs_obd_rd_recovery_time_hard(char *page, char **start, off_t off, int lprocfs_obd_wr_recovery_time_hard(struct file *file, const char *buffer, unsigned long count, void *data); +#ifndef HAVE_ONLY_PROCFS_SEQ int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off, int count, int *eof, void *data); int lprocfs_obd_wr_max_pages_per_rpc(struct file *file, const char *buffer, unsigned long count, void *data); +#endif +int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data); +ssize_t +lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off); int lprocfs_target_rd_instance(char *page, char **start, off_t off, int count, int *eof, void *data); @@ -917,15 +1032,19 @@ static inline void lprocfs_free_md_stats(struct obd_device *obddev) struct obd_export; static inline int lprocfs_add_clear_entry(struct obd_export *exp) { return 0; } +#ifdef HAVE_SERVER_SUPPORT static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid, int *newnid) { return 0; } +#endif static inline int lprocfs_exp_cleanup(struct obd_export *exp) { return 0; } static inline cfs_proc_dir_entry_t * lprocfs_add_simple(struct proc_dir_entry *root, char *name, - cfs_read_proc_t *read_proc, cfs_write_proc_t *write_proc, - void *data, struct file_operations *fops) +#ifndef HAVE_ONLY_PROCFS_SEQ + read_proc_t *read_proc, write_proc_t *write_proc, +#endif + void *data, struct file_operations *fops) {return 0; } static inline struct proc_dir_entry * lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent, @@ -942,19 +1061,32 @@ int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off, int count, int *eof, void *data) {return count;} +#ifndef HAVE_ONLY_PROCFS_SEQ static inline cfs_proc_dir_entry_t * lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent, - struct lprocfs_vars *list, void *data) + struct lprocfs_vars *list, void *data) { return NULL; } static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root, struct lprocfs_vars *var, void *data) { return 0; } +#endif +static inline int lprocfs_seq_add_vars(cfs_proc_dir_entry_t *root, + struct lprocfs_seq_vars *var, + void *data) +{ return 0; } +#ifndef HAVE_ONLY_PROCFS_SEQ +static inline cfs_proc_dir_entry_t * +lprocfs_seq_register(const char *name, cfs_proc_dir_entry_t *parent, + struct lprocfs_vars *list, void *data) +{ return NULL; } +#endif static inline void lprocfs_remove(cfs_proc_dir_entry_t **root) { return; } static inline void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent) { return; } +#ifndef HAVE_ONLY_PROCFS_SEQ static inline void lprocfs_try_remove_proc_entry(const char *name, struct proc_dir_entry *parent) { return; } @@ -962,13 +1094,17 @@ static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head, const char *name) { return 0; } static inline int lprocfs_obd_setup(struct obd_device *dev, - struct lprocfs_vars *list) + struct lprocfs_vars *list) +{ return 0; } +#endif +static inline int lprocfs_seq_obd_setup(struct obd_device *dev) { return 0; } static inline int lprocfs_obd_cleanup(struct obd_device *dev) { return 0; } static inline int lprocfs_rd_u64(char *page, char **start, off_t off, int count, int *eof, void *data) { return 0; } +#ifndef HAVE_ONLY_PROCFS_SEQ static inline int lprocfs_rd_uuid(char *page, char **start, off_t off, int count, int *eof, void *data) { return 0; } @@ -996,8 +1132,7 @@ static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off, static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off, int count, int *eof, void *data) { return 0; } -static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off, - int count, int *eof, void *data) +static inline int lprocfs_rd_numrefs(struct seq_file *m, void *data) { return 0; } struct adaptive_timeout; static inline int lprocfs_at_hist_helper(char *page, int count, int rc, @@ -1023,8 +1158,55 @@ static inline int lprocfs_wr_import(struct file *file, const char *buffer, static inline int lprocfs_wr_pinger_recov(struct file *file, const char *buffer, unsigned long count, void *data) { return 0; } +#endif +static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline int lprocfs_name_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline int lprocfs_server_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline int lprocfs_import_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline int lprocfs_state_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data) +{ return 0; } +struct adaptive_timeout; +static inline int lprocfs_seq_at_hist_helper(struct seq_file *m, + struct adaptive_timeout *at) +{ return 0; } +static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline ssize_t +lprocfs_timeouts_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) +{ return 0; } +static inline ssize_t +lprocfs_evict_client_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) +{ return 0; } +static inline ssize_t +lprocfs_ping_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) +{ return 0; } +static inline ssize_t +lprocfs_import_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) +{ return 0; } +static inline int +lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline ssize_t +lprocfs_pinger_recov_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) +{ return 0; } /* Statfs helpers */ +#ifndef HAVE_ONLY_PROCFS_SEQ static inline int lprocfs_rd_blksize(char *page, char **start, off_t off, int count, int *eof, void *data) @@ -1049,9 +1231,24 @@ static inline int lprocfs_rd_filesfree(char *page, char **start, off_t off, int count, int *eof, void *data) { return 0; } +#endif static inline -int lprocfs_rd_filegroups(char *page, char **start, off_t off, - int count, int *eof, void *data) +int lprocfs_blksize_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline +int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline +int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline +int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline +int lprocfs_filestotal_seq_show(struct seq_file *m, void *data) +{ return 0; } +static inline +int lprocfs_filesfree_seq_show(struct seq_file *m, void *data) { return 0; } static inline void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) @@ -1076,6 +1273,9 @@ __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx, #define LPROC_SEQ_FOPS_RO(name) #define LPROC_SEQ_FOPS(name) +#define LPROC_SEQ_FOPS_RO_TYPE(name, type) +#define LPROC_SEQ_FOPS_RW_TYPE(name, type) +#define LPROC_SEQ_FOPS_WO_TYPE(name, type) /* lprocfs_jobstats.c */ static inline diff --git a/lustre/include/obd.h b/lustre/include/obd.h index fd0d2e2..fd9363e 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -958,10 +958,12 @@ struct obd_device { unsigned int obd_md_cntr_base; struct lprocfs_stats *obd_md_stats; - cfs_proc_dir_entry_t *obd_proc_entry; - cfs_proc_dir_entry_t *obd_proc_exports_entry; - cfs_proc_dir_entry_t *obd_svc_procroot; - struct lprocfs_stats *obd_svc_stats; + struct proc_dir_entry *obd_proc_entry; + struct proc_dir_entry *obd_proc_exports_entry; + void *obd_proc_private; /* type private PDEs */ + struct proc_dir_entry *obd_svc_procroot; + struct lprocfs_stats *obd_svc_stats; + struct lprocfs_seq_vars *obd_vars; cfs_atomic_t obd_evict_inprogress; wait_queue_head_t obd_evict_inprogress_waitq; cfs_list_t obd_evict_list; /* protected with pet_lock */ diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index 39c0dd8..5c6ff26 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -87,8 +87,12 @@ struct lu_device_type; /* genops.c */ struct obd_export *class_conn2export(struct lustre_handle *); int class_register_type(struct obd_ops *, struct md_ops *, - struct lprocfs_vars *, const char *nm, - struct lu_device_type *ldt); + struct lprocfs_seq_vars *module_vars, +#ifndef HAVE_ONLY_PROCFS_SEQ + struct lprocfs_vars *, +#endif + const char *nm, + struct lu_device_type *ldt); int class_unregister_type(const char *nm); struct obd_device *class_newdev(const char *type_name, const char *name); @@ -134,8 +138,12 @@ typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *, struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg, const char *new_name); int class_process_config(struct lustre_cfg *lcfg); +#ifndef HAVE_ONLY_PROCFS_SEQ int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, struct lustre_cfg *lcfg, void *data); +#endif +int class_process_proc_seq_param(char *prefix, struct lprocfs_seq_vars *lvars, + struct lustre_cfg *lcfg, void *data); int class_attach(struct lustre_cfg *lcfg); int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg); int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg); @@ -152,6 +160,7 @@ int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg); int class_add_uuid(const char *uuid, __u64 nid); /*obdecho*/ +#ifndef HAVE_ONLY_PROCFS_SEQ #ifdef LPROCFS extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars); #else @@ -160,6 +169,7 @@ static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars) memset(lvars, 0, sizeof(*lvars)); } #endif +#endif #define CFG_F_START 0x01 /* Set when we start updating from a log */ #define CFG_F_MARKER 0x02 /* We are within a maker */ diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index ada0d66..2686924 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -423,7 +423,7 @@ static int ll_rd_max_cached_mb(char *page, char **start, off_t off, } static int ll_wr_max_cached_mb(struct file *file, const char *buffer, - unsigned long count, void *data) + unsigned long nob, void *data) { struct super_block *sb = data; struct ll_sb_info *sbi = ll_s2sbi(sb); @@ -431,6 +431,7 @@ static int ll_wr_max_cached_mb(struct file *file, const char *buffer, struct lu_env *env; int refcheck; int mult, rc, pages_number; + size_t count = nob; int diff = 0; int nrpages = 0; ENTRY; diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 2929033..56d6e20 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -2983,13 +2983,14 @@ struct md_ops lmv_md_ops = { int __init lmv_init(void) { struct lprocfs_static_vars lvars; - int rc; lprocfs_lmv_init_vars(&lvars); - rc = class_register_type(&lmv_obd_ops, &lmv_md_ops, - lvars.module_vars, LUSTRE_LMV_NAME, NULL); - return rc; + return class_register_type(&lmv_obd_ops, &lmv_md_ops, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_LMV_NAME, NULL); } #ifdef __KERNEL__ diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index 2315222..f1e2465 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -1012,8 +1012,11 @@ static int __init lod_mod_init(void) lprocfs_lod_init_vars(&lvars); - rc = class_register_type(&lod_obd_device_ops, NULL, lvars.module_vars, - LUSTRE_LOD_NAME, &lod_device_type); + rc = class_register_type(&lod_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_LOD_NAME, &lod_device_type); if (rc) { lu_kmem_fini(lod_caches); return rc; diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index 0eb30ec..5f25c6f 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -2929,8 +2929,11 @@ int __init lov_init(void) } lprocfs_lov_init_vars(&lvars); - rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars, - LUSTRE_LOV_NAME, &lov_device_type); + rc = class_register_type(&lov_obd_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_LOV_NAME, &lov_device_type); if (rc) { kmem_cache_destroy(lov_oinfo_slab); diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index 89fec8e..850cef6 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -2797,13 +2797,14 @@ struct md_ops mdc_md_ops = { int __init mdc_init(void) { - int rc; struct lprocfs_static_vars lvars = { 0 }; lprocfs_mdc_init_vars(&lvars); - rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars, - LUSTRE_MDC_NAME, NULL); - RETURN(rc); + return class_register_type(&mdc_obd_ops, &mdc_md_ops, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_MDC_NAME, NULL); } #ifdef __KERNEL__ diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 0153d18..0f53539 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -1498,8 +1498,11 @@ static int __init mdd_mod_init(void) hsm_actions_logops.lop_add = llog_cat_add_rec; hsm_actions_logops.lop_declare_add = llog_cat_declare_add_rec; - rc = class_register_type(&mdd_obd_device_ops, NULL, lvars.module_vars, - LUSTRE_MDD_NAME, &mdd_device_type); + rc = class_register_type(&mdd_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_MDD_NAME, &mdd_device_type); if (rc) lu_kmem_fini(mdd_caches); return rc; diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index b0a7529..f7ffd9a 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -5635,9 +5635,11 @@ static int __init mdt_mod_init(void) GOTO(lu_fini, rc); lprocfs_mdt_init_vars(&lvars); - rc = class_register_type(&mdt_obd_device_ops, NULL, - lvars.module_vars, LUSTRE_MDT_NAME, - &mdt_device_type); + rc = class_register_type(&mdt_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_MDT_NAME, &mdt_device_type); if (rc) GOTO(mds_fini, rc); lu_fini: diff --git a/lustre/mdt/mdt_mds.c b/lustre/mdt/mdt_mds.c index d91d1d4..64231f7 100644 --- a/lustre/mdt/mdt_mds.c +++ b/lustre/mdt/mdt_mds.c @@ -531,8 +531,6 @@ static struct obd_ops mds_obd_device_ops = { int mds_mod_init(void) { - int rc; - if (mdt_num_threads != 0 && mds_num_threads == 0) { LCONSOLE_INFO("mdt_num_threads module parameter is deprecated, " "use mds_num_threads instead or unset both for " @@ -540,10 +538,11 @@ int mds_mod_init(void) mds_num_threads = mdt_num_threads; } - rc = class_register_type(&mds_obd_device_ops, NULL, - lprocfs_mds_module_vars, LUSTRE_MDS_NAME, - &mds_device_type); - return rc; + return class_register_type(&mds_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lprocfs_mds_module_vars, +#endif + LUSTRE_MDS_NAME, &mds_device_type); } void mds_mod_exit(void) diff --git a/lustre/mgc/libmgc.c b/lustre/mgc/libmgc.c index bcc3617..49a329a 100644 --- a/lustre/mgc/libmgc.c +++ b/lustre/mgc/libmgc.c @@ -158,6 +158,9 @@ struct obd_ops mgc_obd_ops = { int __init mgc_init(void) { - return class_register_type(&mgc_obd_ops, NULL, - NULL, LUSTRE_MGC_NAME, NULL); + return class_register_type(&mgc_obd_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + NULL, +#endif + LUSTRE_MGC_NAME, NULL); } diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index 64ab255..a8a8f76 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -2026,7 +2026,10 @@ struct obd_ops mgc_obd_ops = { int __init mgc_init(void) { return class_register_type(&mgc_obd_ops, NULL, NULL, - LUSTRE_MGC_NAME, NULL); +#ifndef HAVE_ONLY_PROCFS_SEQ + NULL, +#endif + LUSTRE_MGC_NAME, NULL); } #ifdef __KERNEL__ diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index cb6666c..560dd19 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -1379,10 +1379,11 @@ static int __init mgs_init(void) struct lprocfs_static_vars lvars; lprocfs_mgs_init_vars(&lvars); - class_register_type(&mgs_obd_device_ops, NULL, lvars.module_vars, - LUSTRE_MGS_NAME, &mgs_device_type); - - return 0; + return class_register_type(&mgs_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_MGS_NAME, &mgs_device_type); } static void /*__exit*/ mgs_exit(void) diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 7f5a6bc..b430c24 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -163,8 +163,11 @@ EXPORT_SYMBOL(class_put_type); #define CLASS_MAX_NAME 1024 int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, - struct lprocfs_vars *vars, const char *name, - struct lu_device_type *ldt) + struct lprocfs_seq_vars *module_vars, +#ifndef HAVE_ONLY_PROCFS_SEQ + struct lprocfs_vars *vars, +#endif + const char *name, struct lu_device_type *ldt) { struct obd_type *type; int rc = 0; @@ -200,13 +203,23 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, spin_lock_init(&type->obd_type_lock); #ifdef LPROCFS - type->typ_procroot = lprocfs_register(type->typ_name, proc_lustre_root, - vars, type); - if (IS_ERR(type->typ_procroot)) { - rc = PTR_ERR(type->typ_procroot); - type->typ_procroot = NULL; - GOTO (failed, rc); - } +#ifndef HAVE_ONLY_PROCFS_SEQ + if (vars) { + type->typ_procroot = lprocfs_register(type->typ_name, + proc_lustre_root, + vars, type); + } else +#endif + { + type->typ_procroot = lprocfs_seq_register(type->typ_name, + proc_lustre_root, + module_vars, type); + } + if (IS_ERR(type->typ_procroot)) { + rc = PTR_ERR(type->typ_procroot); + type->typ_procroot = NULL; + GOTO (failed, rc); + } #endif if (ldt != NULL) { type->typ_lu = ldt; @@ -228,6 +241,13 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, OBD_FREE_PTR(type->typ_md_ops); if (type->typ_dt_ops != NULL) OBD_FREE_PTR(type->typ_dt_ops); +#ifdef LPROCFS +#ifndef HAVE_ONLY_PROCFS_SEQ + lprocfs_try_remove_proc_entry(type->typ_name, proc_lustre_root); +#else + remove_proc_subtree(type->typ_name, proc_lustre_root); +#endif +#endif OBD_FREE(type, sizeof(*type)); RETURN(rc); } @@ -256,8 +276,13 @@ int class_unregister_type(const char *name) * other modules can share names (i.e. lod can use lov entry). so * we can't reference pointer as it can get invalided when another * module removes the entry */ +#ifdef LPROCFS +#ifndef HAVE_ONLY_PROCFS_SEQ lprocfs_try_remove_proc_entry(type->typ_name, proc_lustre_root); - +#else + remove_proc_subtree(type->typ_name, proc_lustre_root); +#endif +#endif if (type->typ_lu) lu_device_type_fini(type->typ_lu); diff --git a/lustre/obdclass/llog_test.c b/lustre/obdclass/llog_test.c index b41ab6f..7402d9d 100644 --- a/lustre/obdclass/llog_test.c +++ b/lustre/obdclass/llog_test.c @@ -1070,8 +1070,11 @@ static int __init llog_test_init(void) struct lprocfs_static_vars lvars; lprocfs_llog_test_init_vars(&lvars); - return class_register_type(&llog_obd_ops, NULL, - lvars.module_vars, "llog_test", NULL); + return class_register_type(&llog_obd_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + "llog_test", NULL); } static void __exit llog_test_exit(void) diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 207c724..0c805be 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -41,7 +41,7 @@ #define DEBUG_SUBSYSTEM S_CLASS #ifndef __KERNEL__ -# include +#include #endif #include @@ -56,10 +56,6 @@ CFS_MODULE_PARM(lprocfs_no_percpu_stats, "i", int, 0644, #define MAX_STRING_SIZE 128 -/* for bug 10866, global variable */ -DECLARE_RWSEM(_lprocfs_lock); -EXPORT_SYMBOL(_lprocfs_lock); - int lprocfs_single_release(struct inode *inode, struct file *file) { return single_release(inode, file); @@ -72,6 +68,11 @@ int lprocfs_seq_release(struct inode *inode, struct file *file) } EXPORT_SYMBOL(lprocfs_seq_release); +#ifndef HAVE_ONLY_PROCFS_SEQ +/* for b=10866, global variable */ +DECLARE_RWSEM(_lprocfs_lock); +EXPORT_SYMBOL(_lprocfs_lock); + static struct proc_dir_entry *__lprocfs_srch(struct proc_dir_entry *head, const char *name) { @@ -109,6 +110,7 @@ EXPORT_SYMBOL(lprocfs_srch); the page pointer for the next write into the buffer, incrementing the total length written to the buffer, and decrementing the size left in the buffer. */ +#ifdef HAVE_SERVER_SUPPORT static int lprocfs_obd_snprintf(char **page, int end, int *len, const char *format, ...) { @@ -125,11 +127,15 @@ static int lprocfs_obd_snprintf(char **page, int end, int *len, *page += n; *len += n; return n; } +#endif /* HAVE_SERVER_SUPPORT */ +#endif /* HAVE_ONLY_PROCFS_SEQ */ cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root, char *name, - read_proc_t *read_proc, - write_proc_t *write_proc, +#ifndef HAVE_ONLY_PROCFS_SEQ + read_proc_t *read_proc, + write_proc_t *write_proc, +#endif void *data, struct file_operations *fops) { @@ -138,25 +144,40 @@ cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root, if (root == NULL || name == NULL) return ERR_PTR(-EINVAL); - if (read_proc) - mode = 0444; - if (write_proc) - mode |= 0200; - if (fops) - mode = 0644; - LPROCFS_WRITE_ENTRY(); - proc = create_proc_entry(name, mode, root); - if (!proc) { - CERROR("LprocFS: No memory to create /proc entry %s", name); - LPROCFS_WRITE_EXIT(); - return ERR_PTR(-ENOMEM); - } - proc->read_proc = read_proc; - proc->write_proc = write_proc; - proc->data = data; - if (fops) - proc->proc_fops = fops; - LPROCFS_WRITE_EXIT(); + + if (!fops) { +#ifndef HAVE_ONLY_PROCFS_SEQ + if (read_proc) + mode = 0444; + if (write_proc) + mode |= 0200; + + LPROCFS_WRITE_ENTRY(); + proc = create_proc_entry(name, mode, root); + if (!proc) { + CERROR("LprocFS: No memory to create /proc entry %s", name); + LPROCFS_WRITE_EXIT(); + return ERR_PTR(-ENOMEM); + } + proc->read_proc = read_proc; + proc->write_proc = write_proc; + proc->data = data; + LPROCFS_WRITE_EXIT(); +#else + return ERR_PTR(-EINVAL); +#endif + } else { + if (fops->read) + mode = 0444; + if (fops->write) + mode |= 0200; + proc = proc_create_data(name, mode, root, fops, data); + if (!proc) { + CERROR("LprocFS: No memory to create /proc entry %s", + name); + return ERR_PTR(-ENOMEM); + } + } return proc; } EXPORT_SYMBOL(lprocfs_add_simple); @@ -189,6 +210,7 @@ struct proc_dir_entry *lprocfs_add_symlink(const char *name, } EXPORT_SYMBOL(lprocfs_add_symlink); +#ifndef HAVE_ONLY_PROCFS_SEQ static ssize_t lprocfs_fops_read(struct file *f, char __user *buf, size_t size, loff_t *ppos) { @@ -259,7 +281,11 @@ static struct file_operations lprocfs_generic_fops = { .read = lprocfs_fops_read, .write = lprocfs_fops_write, }; +#else +static struct file_operations lprocfs_generic_fops = { }; +#endif +#ifdef HAVE_SERVER_SUPPORT int lprocfs_evict_client_open(struct inode *inode, struct file *f) { struct proc_dir_entry *dp = PDE(f->f_dentry->d_inode); @@ -289,7 +315,9 @@ struct file_operations lprocfs_evict_client_fops = { .release = lprocfs_evict_client_release, }; EXPORT_SYMBOL(lprocfs_evict_client_fops); +#endif +#ifndef HAVE_ONLY_PROCFS_SEQ static int __lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list, void *data) @@ -366,6 +394,21 @@ out: return rc; } +int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list, + void *data) +{ + int rc = 0; + + LPROCFS_WRITE_ENTRY(); + rc = __lprocfs_add_vars(root, list, data); + LPROCFS_WRITE_EXIT(); + + return rc; +} +EXPORT_SYMBOL(lprocfs_add_vars); + +#endif + /** * Add /proc entries. * @@ -377,19 +420,37 @@ out: * \retval 0 on success * < 0 on error */ -int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list, +int +lprocfs_seq_add_vars(struct proc_dir_entry *root, struct lprocfs_seq_vars *list, void *data) { - int rc; + if (root == NULL || list == NULL) + return -EINVAL; - LPROCFS_WRITE_ENTRY(); - rc = __lprocfs_add_vars(root, list, data); - LPROCFS_WRITE_EXIT(); + while (list->name != NULL) { + struct proc_dir_entry *proc; + mode_t mode = 0; - return rc; + if (list->proc_mode != 0000) { + mode = list->proc_mode; + } else if (list->fops) { + if (list->fops->read) + mode = 0444; + if (list->fops->write) + mode |= 0200; + } + proc = proc_create_data(list->name, mode, root, + list->fops ?: &lprocfs_generic_fops, + list->data ?: data); + if (proc == NULL) + return -ENOMEM; + list++; + } + return 0; } -EXPORT_SYMBOL(lprocfs_add_vars); +EXPORT_SYMBOL(lprocfs_seq_add_vars); +#ifndef HAVE_ONLY_PROCFS_SEQ void lprocfs_remove_nolock(struct proc_dir_entry **proot) { struct proc_dir_entry *root = *proot; @@ -422,12 +483,18 @@ void lprocfs_remove_nolock(struct proc_dir_entry **proot) break; } } +#endif void lprocfs_remove(struct proc_dir_entry **rooth) { +#ifndef HAVE_ONLY_PROCFS_SEQ LPROCFS_WRITE_ENTRY(); /* search vs remove race */ lprocfs_remove_nolock(rooth); LPROCFS_WRITE_EXIT(); +#else + proc_remove(*rooth); + *rooth = NULL; +#endif } EXPORT_SYMBOL(lprocfs_remove); @@ -438,6 +505,7 @@ void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent) } EXPORT_SYMBOL(lprocfs_remove_proc_entry); +#ifndef HAVE_ONLY_PROCFS_SEQ void lprocfs_try_remove_proc_entry(const char *name, struct proc_dir_entry *parent) { @@ -511,19 +579,35 @@ struct proc_dir_entry *lprocfs_register(const char *name, } out: LPROCFS_WRITE_EXIT(); - return entry; } EXPORT_SYMBOL(lprocfs_register); +#endif + +struct proc_dir_entry * +lprocfs_seq_register(const char *name, struct proc_dir_entry *parent, + struct lprocfs_seq_vars *list, void *data) +{ + struct proc_dir_entry *newchild; + + newchild = proc_mkdir(name, parent); + if (newchild != NULL && list != NULL) { + int rc = lprocfs_seq_add_vars(newchild, list, data); + if (rc) { + lprocfs_remove(&newchild); + return ERR_PTR(rc); + } + } + return newchild; +} +EXPORT_SYMBOL(lprocfs_seq_register); /* Generic callbacks */ -int lprocfs_rd_uint(char *page, char **start, off_t off, - int count, int *eof, void *data) +int lprocfs_uint_seq_show(struct seq_file *m, void *data) { - unsigned int *temp = data; - return snprintf(page, count, "%u\n", *temp); + return seq_printf(m, "%u\n", *(unsigned int *)data); } -EXPORT_SYMBOL(lprocfs_rd_uint); +EXPORT_SYMBOL(lprocfs_uint_seq_show); int lprocfs_wr_uint(struct file *file, const char *buffer, unsigned long count, void *data) @@ -545,6 +629,615 @@ int lprocfs_wr_uint(struct file *file, const char *buffer, } EXPORT_SYMBOL(lprocfs_wr_uint); +ssize_t lprocfs_uint_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) +{ + int *data = ((struct seq_file *)file->private_data)->private; + int val = 0, rc; + + rc = lprocfs_write_helper(buffer, count, &val); + if (rc < 0) + return rc; + + return lprocfs_wr_uint(file, buffer, count, data); +} +EXPORT_SYMBOL(lprocfs_uint_seq_write); + +int lprocfs_u64_seq_show(struct seq_file *m, void *data) +{ + LASSERT(data != NULL); + return seq_printf(m, LPU64"\n", *(__u64 *)data); +} +EXPORT_SYMBOL(lprocfs_u64_seq_show); + +int lprocfs_atomic_seq_show(struct seq_file *m, void *data) +{ + cfs_atomic_t *atom = data; + LASSERT(atom != NULL); + return seq_printf(m, "%d\n", atomic_read(atom)); +} +EXPORT_SYMBOL(lprocfs_atomic_seq_show); + +ssize_t +lprocfs_atomic_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) +{ + cfs_atomic_t *atm = ((struct seq_file *)file->private_data)->private; + int val = 0; + int rc; + + rc = lprocfs_write_helper(buffer, count, &val); + if (rc < 0) + return rc; + + if (val <= 0) + return -ERANGE; + + cfs_atomic_set(atm, val); + return count; +} +EXPORT_SYMBOL(lprocfs_atomic_seq_write); + +int lprocfs_uuid_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + + LASSERT(obd != NULL); + return seq_printf(m, "%s\n", obd->obd_uuid.uuid); +} +EXPORT_SYMBOL(lprocfs_uuid_seq_show); + +int lprocfs_name_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *dev = data; + + LASSERT(dev != NULL); + return seq_printf(m, "%s\n", dev->obd_name); +} +EXPORT_SYMBOL(lprocfs_name_seq_show); + +int lprocfs_blksize_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + struct obd_statfs osfs; + int rc = obd_statfs(NULL, obd->obd_self_export, &osfs, + cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), + OBD_STATFS_NODELAY); + if (!rc) + rc = seq_printf(m, "%u\n", osfs.os_bsize); + return rc; +} +EXPORT_SYMBOL(lprocfs_blksize_seq_show); + +int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + struct obd_statfs osfs; + int rc = obd_statfs(NULL, obd->obd_self_export, &osfs, + cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), + OBD_STATFS_NODELAY); + if (!rc) { + __u32 blk_size = osfs.os_bsize >> 10; + __u64 result = osfs.os_blocks; + + while (blk_size >>= 1) + result <<= 1; + + rc = seq_printf(m, LPU64"\n", result); + } + return rc; +} +EXPORT_SYMBOL(lprocfs_kbytestotal_seq_show); + +int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + struct obd_statfs osfs; + int rc = obd_statfs(NULL, obd->obd_self_export, &osfs, + cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), + OBD_STATFS_NODELAY); + if (!rc) { + __u32 blk_size = osfs.os_bsize >> 10; + __u64 result = osfs.os_bfree; + + while (blk_size >>= 1) + result <<= 1; + + rc = seq_printf(m, LPU64"\n", result); + } + return rc; +} +EXPORT_SYMBOL(lprocfs_kbytesfree_seq_show); + +int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + struct obd_statfs osfs; + int rc = obd_statfs(NULL, obd->obd_self_export, &osfs, + cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), + OBD_STATFS_NODELAY); + if (!rc) { + __u32 blk_size = osfs.os_bsize >> 10; + __u64 result = osfs.os_bavail; + + while (blk_size >>= 1) + result <<= 1; + + rc = seq_printf(m, LPU64"\n", result); + } + return rc; +} +EXPORT_SYMBOL(lprocfs_kbytesavail_seq_show); + +int lprocfs_filestotal_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + struct obd_statfs osfs; + int rc = obd_statfs(NULL, obd->obd_self_export, &osfs, + cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), + OBD_STATFS_NODELAY); + if (!rc) + rc = seq_printf(m, LPU64"\n", osfs.os_files); + return rc; +} +EXPORT_SYMBOL(lprocfs_filestotal_seq_show); + +int lprocfs_filesfree_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + struct obd_statfs osfs; + int rc = obd_statfs(NULL, obd->obd_self_export, &osfs, + cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), + OBD_STATFS_NODELAY); + if (!rc) + rc = seq_printf(m, LPU64"\n", osfs.os_ffree); + return rc; +} +EXPORT_SYMBOL(lprocfs_filesfree_seq_show); + +int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + struct obd_import *imp; + char *imp_state_name = NULL; + int rc = 0; + + LASSERT(obd != NULL); + LPROCFS_CLIMP_CHECK(obd); + imp = obd->u.cli.cl_import; + imp_state_name = ptlrpc_import_state_name(imp->imp_state); + rc = seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name, + imp->imp_deactive ? "\tDEACTIVATED" : ""); + + LPROCFS_CLIMP_EXIT(obd); + return rc; +} +EXPORT_SYMBOL(lprocfs_server_uuid_seq_show); + +int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + struct ptlrpc_connection *conn; + int rc = 0; + + LASSERT(obd != NULL); + + LPROCFS_CLIMP_CHECK(obd); + conn = obd->u.cli.cl_import->imp_connection; + if (conn && obd->u.cli.cl_import) + rc = seq_printf(m, "%s\n", conn->c_remote_uuid.uuid); + else + rc = seq_printf(m, "%s\n", ""); + + LPROCFS_CLIMP_EXIT(obd); + return rc; +} +EXPORT_SYMBOL(lprocfs_conn_uuid_seq_show); + +/** add up per-cpu counters */ +void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx, + struct lprocfs_counter *cnt) +{ + unsigned int num_entry; + struct lprocfs_counter *percpu_cntr; + int i; + unsigned long flags = 0; + + memset(cnt, 0, sizeof(*cnt)); + + if (stats == NULL) { + /* set count to 1 to avoid divide-by-zero errs in callers */ + cnt->lc_count = 1; + return; + } + + cnt->lc_min = LC_MIN_INIT; + + num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags); + + for (i = 0; i < num_entry; i++) { + if (stats->ls_percpu[i] == NULL) + continue; + percpu_cntr = lprocfs_stats_counter_get(stats, i, idx); + + cnt->lc_count += percpu_cntr->lc_count; + cnt->lc_sum += percpu_cntr->lc_sum; + if (percpu_cntr->lc_min < cnt->lc_min) + cnt->lc_min = percpu_cntr->lc_min; + if (percpu_cntr->lc_max > cnt->lc_max) + cnt->lc_max = percpu_cntr->lc_max; + cnt->lc_sumsquare += percpu_cntr->lc_sumsquare; + } + + lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags); +} +EXPORT_SYMBOL(lprocfs_stats_collect); + +/** + * Append a space separated list of current set flags to str. + */ +#define flag2seqstr(flag) \ + do { \ + if (imp->imp_##flag) \ + seq_printf(m, "%s" #flag, first ? "" : ", "); \ + } while (0) +static int obd_import_flags2seqstr(struct obd_import *imp, struct seq_file *m) +{ + bool first = true; + + if (imp->imp_obd->obd_no_recov) { + seq_printf(m, "no_recov"); + first = false; + } + + flag2seqstr(invalid); + flag2seqstr(deactive); + flag2seqstr(replayable); + flag2seqstr(pingable); + return 0; +} +#undef flags2seqstr + +static const char *obd_connect_names[] = { + "read_only", + "lov_index", + "unused", + "write_grant", + "server_lock", + "version", + "request_portal", + "acl", + "xattr", + "create_on_write", + "truncate_lock", + "initial_transno", + "inode_bit_locks", + "join_file(obsolete)", + "getattr_by_fid", + "no_oh_for_devices", + "remote_client", + "remote_client_by_force", + "max_byte_per_rpc", + "64bit_qdata", + "mds_capability", + "oss_capability", + "early_lock_cancel", + "som", + "adaptive_timeouts", + "lru_resize", + "mds_mds_connection", + "real_conn", + "change_qunit_size", + "alt_checksum_algorithm", + "fid_is_enabled", + "version_recovery", + "pools", + "grant_shrink", + "skip_orphan", + "large_ea", + "full20", + "layout_lock", + "64bithash", + "object_max_bytes", + "imp_recov", + "jobstats", + "umask", + "einprogress", + "grant_param", + "flock_owner", + "lvb_type", + "nanoseconds_times", + "lightweight_conn", + "short_io", + "pingless", + "flock_deadlock", + "disp_stripe", + "unknown", + NULL +}; + +static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep) +{ + bool first = true; + __u64 mask = 1; + int i; + + for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) { + if (flags & mask) { + seq_printf(m, "%s%s", + first ? "" : sep, obd_connect_names[i]); + first = false; + } + } + if (flags & ~(mask - 1)) + seq_printf(m, "%sunknown flags "LPX64, + first ? "" : sep, flags & ~(mask - 1)); +} + +int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep) +{ + __u64 mask = 1; + int i, ret = 0; + + for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) { + if (flags & mask) + ret += snprintf(page + ret, count - ret, "%s%s", + ret ? sep : "", obd_connect_names[i]); + } + if (flags & ~(mask - 1)) + ret += snprintf(page + ret, count - ret, + "%sunknown flags "LPX64, + ret ? sep : "", flags & ~(mask - 1)); + return ret; +} +EXPORT_SYMBOL(obd_connect_flags2str); + +int lprocfs_import_seq_show(struct seq_file *m, void *data) +{ + struct lprocfs_counter ret; + struct lprocfs_counter_header *header; + struct obd_device *obd = (struct obd_device *)data; + struct obd_import *imp; + struct obd_import_conn *conn; + int j; + int k; + int rw = 0; + + LASSERT(obd != NULL); + LPROCFS_CLIMP_CHECK(obd); + imp = obd->u.cli.cl_import; + + seq_printf(m,"import:\n" + " name: %s\n" + " target: %s\n" + " state: %s\n" + " instance: %u\n" + " connect_flags: [", + obd->obd_name, + obd2cli_tgt(obd), + ptlrpc_import_state_name(imp->imp_state), + imp->imp_connect_data.ocd_instance); + obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags, + ", "); + seq_printf(m, "]\n" + " import_flags: ["); + obd_import_flags2seqstr(imp, m); + + seq_printf(m, "]\n" + " connection:\n" + " failover_nids: ["); + spin_lock(&imp->imp_lock); + j = 0; + list_for_each_entry(conn, &imp->imp_conn_list, oic_item) { + seq_printf(m, "%s%s", j ? ", " : "", + libcfs_nid2str(conn->oic_conn->c_peer.nid)); + j++; + } + seq_printf(m, "]\n" + " current_connection: %s\n" + " connection_attempts: %u\n" + " generation: %u\n" + " in-progress_invalidations: %u\n", + imp->imp_connection == NULL ? "" : + libcfs_nid2str(imp->imp_connection->c_peer.nid), + imp->imp_conn_cnt, + imp->imp_generation, + atomic_read(&imp->imp_inval_count)); + spin_unlock(&imp->imp_lock); + + if (obd->obd_svc_stats == NULL) + goto out_climp; + + header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR]; + lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret); + if (ret.lc_count != 0) { + /* first argument to do_div MUST be __u64 */ + __u64 sum = ret.lc_sum; + do_div(sum, ret.lc_count); + ret.lc_sum = sum; + } else + ret.lc_sum = 0; + seq_printf(m, " rpcs:\n" + " inflight: %u\n" + " unregistering: %u\n" + " timeouts: %u\n" + " avg_waittime: "LPU64" %s\n", + atomic_read(&imp->imp_inflight), + atomic_read(&imp->imp_unregistering), + atomic_read(&imp->imp_timeouts), + ret.lc_sum, header->lc_units); + + k = 0; + for(j = 0; j < IMP_AT_MAX_PORTALS; j++) { + if (imp->imp_at.iat_portal[j] == 0) + break; + k = max_t(unsigned int, k, + at_get(&imp->imp_at.iat_service_estimate[j])); + } + seq_printf(m, " service_estimates:\n" + " services: %u sec\n" + " network: %u sec\n", + k, + at_get(&imp->imp_at.iat_net_latency)); + + seq_printf(m, " transactions:\n" + " last_replay: "LPU64"\n" + " peer_committed: "LPU64"\n" + " last_checked: "LPU64"\n", + imp->imp_last_replay_transno, + imp->imp_peer_committed_transno, + imp->imp_last_transno_checked); + + /* avg data rates */ + for (rw = 0; rw <= 1; rw++) { + lprocfs_stats_collect(obd->obd_svc_stats, + PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw, + &ret); + if (ret.lc_sum > 0 && ret.lc_count > 0) { + /* first argument to do_div MUST be __u64 */ + __u64 sum = ret.lc_sum; + do_div(sum, ret.lc_count); + ret.lc_sum = sum; + seq_printf(m, " %s_data_averages:\n" + " bytes_per_rpc: "LPU64"\n", + rw ? "write" : "read", + ret.lc_sum); + } + k = (int)ret.lc_sum; + j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES; + header = &obd->obd_svc_stats->ls_cnt_header[j]; + lprocfs_stats_collect(obd->obd_svc_stats, j, &ret); + if (ret.lc_sum > 0 && ret.lc_count != 0) { + /* first argument to do_div MUST be __u64 */ + __u64 sum = ret.lc_sum; + do_div(sum, ret.lc_count); + ret.lc_sum = sum; + seq_printf(m, " %s_per_rpc: "LPU64"\n", + header->lc_units, ret.lc_sum); + j = (int)ret.lc_sum; + if (j > 0) + seq_printf(m, " MB_per_sec: %u.%.02u\n", + k / j, (100 * k / j) % 100); + } + } + +out_climp: + LPROCFS_CLIMP_EXIT(obd); + return 0; +} +EXPORT_SYMBOL(lprocfs_import_seq_show); + +int lprocfs_state_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = (struct obd_device *)data; + struct obd_import *imp; + int j, k; + + LASSERT(obd != NULL); + LPROCFS_CLIMP_CHECK(obd); + imp = obd->u.cli.cl_import; + + seq_printf(m, "current_state: %s\n", + ptlrpc_import_state_name(imp->imp_state)); + seq_printf(m, "state_history:\n"); + k = imp->imp_state_hist_idx; + for (j = 0; j < IMP_STATE_HIST_LEN; j++) { + struct import_state_hist *ish = + &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN]; + if (ish->ish_state == 0) + continue; + seq_printf(m, " - ["CFS_TIME_T", %s]\n", + ish->ish_time, + ptlrpc_import_state_name(ish->ish_state)); + } + + LPROCFS_CLIMP_EXIT(obd); + return 0; +} +EXPORT_SYMBOL(lprocfs_state_seq_show); + +int lprocfs_seq_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at) +{ + int i; + for (i = 0; i < AT_BINS; i++) + seq_printf(m, "%3u ", at->at_hist[i]); + seq_printf(m, "\n"); + return 0; +} +EXPORT_SYMBOL(lprocfs_seq_at_hist_helper); + +/* See also ptlrpc_lprocfs_timeouts_show_seq */ +int lprocfs_timeouts_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = (struct obd_device *)data; + struct obd_import *imp; + unsigned int cur, worst; + time_t now, worstt; + struct dhms ts; + int i; + + LASSERT(obd != NULL); + LPROCFS_CLIMP_CHECK(obd); + imp = obd->u.cli.cl_import; + + now = cfs_time_current_sec(); + + /* Some network health info for kicks */ + s2dhms(&ts, now - imp->imp_last_reply_time); + seq_printf(m, "%-10s : %ld, "DHMS_FMT" ago\n", + "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts)); + + cur = at_get(&imp->imp_at.iat_net_latency); + worst = imp->imp_at.iat_net_latency.at_worst_ever; + worstt = imp->imp_at.iat_net_latency.at_worst_time; + s2dhms(&ts, now - worstt); + seq_printf(m, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ", + "network", cur, worst, worstt, DHMS_VARS(&ts)); + lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_net_latency); + + for(i = 0; i < IMP_AT_MAX_PORTALS; i++) { + if (imp->imp_at.iat_portal[i] == 0) + break; + cur = at_get(&imp->imp_at.iat_service_estimate[i]); + worst = imp->imp_at.iat_service_estimate[i].at_worst_ever; + worstt = imp->imp_at.iat_service_estimate[i].at_worst_time; + s2dhms(&ts, now - worstt); + seq_printf(m, "portal %-2d : cur %3u worst %3u (at %ld, " + DHMS_FMT" ago) ", imp->imp_at.iat_portal[i], + cur, worst, worstt, DHMS_VARS(&ts)); + lprocfs_seq_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]); + } + + LPROCFS_CLIMP_EXIT(obd); + return 0; +} +EXPORT_SYMBOL(lprocfs_timeouts_seq_show); + +int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *obd = data; + __u64 flags; + + LPROCFS_CLIMP_CHECK(obd); + flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags; + seq_printf(m, "flags="LPX64"\n", flags); + obd_connect_seq_flags2str(m, flags, "\n"); + seq_printf(m, "\n"); + LPROCFS_CLIMP_EXIT(obd); + return 0; +} +EXPORT_SYMBOL(lprocfs_connect_flags_seq_show); + +#ifndef HAVE_ONLY_PROCFS_SEQ + +int lprocfs_rd_uint(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + unsigned int *temp = data; + return snprintf(page, count, "%u\n", *temp); +} +EXPORT_SYMBOL(lprocfs_rd_uint); + int lprocfs_rd_u64(char *page, char **start, off_t off, int count, int *eof, void *data) { @@ -766,45 +1459,6 @@ int lprocfs_rd_conn_uuid(char *page, char **start, off_t off, int count, } EXPORT_SYMBOL(lprocfs_rd_conn_uuid); -/** add up per-cpu counters */ -void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx, - struct lprocfs_counter *cnt) -{ - unsigned int num_entry; - struct lprocfs_counter *percpu_cntr; - int i; - unsigned long flags = 0; - - memset(cnt, 0, sizeof(*cnt)); - - if (stats == NULL) { - /* set count to 1 to avoid divide-by-zero errs in callers */ - cnt->lc_count = 1; - return; - } - - cnt->lc_min = LC_MIN_INIT; - - num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags); - - for (i = 0; i < num_entry; i++) { - if (stats->ls_percpu[i] == NULL) - continue; - percpu_cntr = lprocfs_stats_counter_get(stats, i, idx); - - cnt->lc_count += percpu_cntr->lc_count; - cnt->lc_sum += percpu_cntr->lc_sum; - if (percpu_cntr->lc_min < cnt->lc_min) - cnt->lc_min = percpu_cntr->lc_min; - if (percpu_cntr->lc_max > cnt->lc_max) - cnt->lc_max = percpu_cntr->lc_max; - cnt->lc_sumsquare += percpu_cntr->lc_sumsquare; - } - - lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags); -} -EXPORT_SYMBOL(lprocfs_stats_collect); - /** * Append a space separated list of current set flags to str. */ @@ -826,82 +1480,6 @@ static int obd_import_flags2str(struct obd_import *imp, char *str, int max) } #undef flags2str -static const char *obd_connect_names[] = { - "read_only", - "lov_index", - "unused", - "write_grant", - "server_lock", - "version", - "request_portal", - "acl", - "xattr", - "create_on_write", - "truncate_lock", - "initial_transno", - "inode_bit_locks", - "join_file(obsolete)", - "getattr_by_fid", - "no_oh_for_devices", - "remote_client", - "remote_client_by_force", - "max_byte_per_rpc", - "64bit_qdata", - "mds_capability", - "oss_capability", - "early_lock_cancel", - "som", - "adaptive_timeouts", - "lru_resize", - "mds_mds_connection", - "real_conn", - "change_qunit_size", - "alt_checksum_algorithm", - "fid_is_enabled", - "version_recovery", - "pools", - "grant_shrink", - "skip_orphan", - "large_ea", - "full20", - "layout_lock", - "64bithash", - "object_max_bytes", - "imp_recov", - "jobstats", - "umask", - "einprogress", - "grant_param", - "flock_owner", - "lvb_type", - "nanoseconds_times", - "lightweight_conn", - "short_io", - "pingless", - "flock_deadlock", - "disp_stripe", - "unknown", - NULL -}; - -int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep) -{ - __u64 mask = 1; - int i, ret = 0; - - for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) { - if (flags & mask) - ret += snprintf(page + ret, count - ret, "%s%s", - ret ? sep : "", obd_connect_names[i]); - } - if (flags & ~(mask - 1)) - ret += snprintf(page + ret, count - ret, - "%sunknown flags "LPX64, - ret ? sep : "", flags & ~(mask - 1)); - return ret; -} -EXPORT_SYMBOL(obd_connect_flags2str); - int lprocfs_rd_import(char *page, char **start, off_t off, int count, int *eof, void *data) { @@ -1189,23 +1767,46 @@ EXPORT_SYMBOL(lprocfs_rd_numrefs); int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list) { - int rc = 0; + int rc = 0; - LASSERT(obd != NULL); - LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC); - LASSERT(obd->obd_type->typ_procroot != NULL); - - obd->obd_proc_entry = lprocfs_register(obd->obd_name, - obd->obd_type->typ_procroot, - list, obd); - if (IS_ERR(obd->obd_proc_entry)) { - rc = PTR_ERR(obd->obd_proc_entry); - CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name); - obd->obd_proc_entry = NULL; - } - return rc; + LASSERT(obd != NULL); + LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC); + LASSERT(obd->obd_type->typ_procroot != NULL); + + obd->obd_proc_entry = lprocfs_register(obd->obd_name, + obd->obd_type->typ_procroot, + list, obd); + if (IS_ERR(obd->obd_proc_entry)) { + rc = PTR_ERR(obd->obd_proc_entry); + CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name); + obd->obd_proc_entry = NULL; + } + return rc; } EXPORT_SYMBOL(lprocfs_obd_setup); +#endif + +int +lprocfs_seq_obd_setup(struct obd_device *obd) +{ + int rc = 0; + + LASSERT(obd != NULL); + LASSERT(obd->obd_vars != NULL); + LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC); + LASSERT(obd->obd_type->typ_procroot != NULL); + + obd->obd_proc_entry = lprocfs_seq_register(obd->obd_name, + obd->obd_type->typ_procroot, + obd->obd_vars, obd); + if (IS_ERR(obd->obd_proc_entry)) { + rc = PTR_ERR(obd->obd_proc_entry); + CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name); + obd->obd_proc_entry = NULL; + } + return rc; +} +EXPORT_SYMBOL(lprocfs_seq_obd_setup); int lprocfs_obd_cleanup(struct obd_device *obd) { @@ -1213,7 +1814,6 @@ int lprocfs_obd_cleanup(struct obd_device *obd) return -EINVAL; if (obd->obd_proc_exports_entry) { /* Should be no exports left */ - LASSERT(obd->obd_proc_exports_entry->subdir == NULL); lprocfs_remove(&obd->obd_proc_exports_entry); obd->obd_proc_exports_entry = NULL; } @@ -1500,19 +2100,19 @@ struct seq_operations lprocfs_stats_seq_sops = { static int lprocfs_stats_seq_open(struct inode *inode, struct file *file) { - struct proc_dir_entry *dp = PDE(inode); - struct seq_file *seq; - int rc; - - if (LPROCFS_ENTRY_CHECK(dp)) - return -ENOENT; + struct seq_file *seq; + int rc; - rc = seq_open(file, &lprocfs_stats_seq_sops); +#ifndef HAVE_ONLY_PROCFS_SEQ + if (LPROCFS_ENTRY_CHECK(PDE(inode))) + return -ENOENT; +#endif + rc = seq_open(file, &lprocfs_stats_seq_sops); if (rc) - return rc; - seq = file->private_data; - seq->private = dp->data; - return 0; + return rc; + seq = file->private_data; + seq->private = PDE_DATA(inode); + return 0; } struct file_operations lprocfs_stats_seq_fops = { @@ -1527,22 +2127,14 @@ struct file_operations lprocfs_stats_seq_fops = { int lprocfs_register_stats(struct proc_dir_entry *root, const char *name, struct lprocfs_stats *stats) { - struct proc_dir_entry *entry; - LASSERT(root != NULL); - - LPROCFS_WRITE_ENTRY(); - entry = create_proc_entry(name, 0644, root); - if (entry) { - entry->proc_fops = &lprocfs_stats_seq_fops; - entry->data = stats; - } - - LPROCFS_WRITE_EXIT(); - - if (entry == NULL) - return -ENOMEM; + struct proc_dir_entry *entry; + LASSERT(root != NULL); - return 0; + entry = proc_create_data(name, 0644, root, + &lprocfs_stats_seq_fops, stats); + if (entry == NULL) + return -ENOMEM; + return 0; } EXPORT_SYMBOL(lprocfs_register_stats); @@ -1987,6 +2579,7 @@ int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer, } EXPORT_SYMBOL(lprocfs_nid_stats_clear_write); +#ifdef HAVE_SERVER_SUPPORT int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid) { struct nid_stat *new_stat, *old_stat; @@ -2097,6 +2690,7 @@ destroy_new: RETURN(rc); } EXPORT_SYMBOL(lprocfs_exp_setup); +#endif int lprocfs_exp_cleanup(struct obd_export *exp) { @@ -2258,6 +2852,31 @@ int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val, } EXPORT_SYMBOL(lprocfs_read_frac_helper); +int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult) +{ + long decimal_val, frac_val; + + decimal_val = val / mult; + seq_printf(m, "%ld", decimal_val); + frac_val = val % mult; + + if (frac_val > 0) { + frac_val *= 100; + frac_val /= mult; + } + if (frac_val > 0) { + /* Three cases: x0, xx, 0x */ + if ((frac_val % 10) != 0) + seq_printf(m, ".%ld", frac_val); + else + seq_printf(m, ".%ld", frac_val / 10); + } + + seq_printf(m, "\n"); + return 0; +} +EXPORT_SYMBOL(lprocfs_seq_read_frac_helper); + int lprocfs_write_u64_helper(const char *buffer, unsigned long count,__u64 *val) { return lprocfs_write_frac_u64_helper(buffer, count, val, 1); @@ -2350,7 +2969,7 @@ static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len) * If \a name is not found the original \a buffer is returned. */ char *lprocfs_find_named_value(const char *buffer, const char *name, - unsigned long *count) + size_t *count) { char *val; size_t buflen = *count; @@ -2380,24 +2999,18 @@ int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, const struct file_operations *seq_fops, void *data) { - struct proc_dir_entry *entry; - ENTRY; + struct proc_dir_entry *entry; + ENTRY; /* Disallow secretly (un)writable entries. */ LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0)); - LPROCFS_WRITE_ENTRY(); - entry = create_proc_entry(name, mode, parent); - if (entry) { - entry->proc_fops = seq_fops; - entry->data = data; - } - LPROCFS_WRITE_EXIT(); + entry = proc_create_data(name, mode, parent, seq_fops, data); - if (entry == NULL) - RETURN(-ENOMEM); + if (entry == NULL) + RETURN(-ENOMEM); - RETURN(0); + RETURN(0); } EXPORT_SYMBOL(lprocfs_seq_create); @@ -2471,6 +3084,7 @@ int lprocfs_obd_rd_hash(char *page, char **start, off_t off, } EXPORT_SYMBOL(lprocfs_obd_rd_hash); +#ifdef HAVE_SERVER_SUPPORT int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off, int count, int *eof, void *data) { @@ -2596,6 +3210,7 @@ out: return min(count, len - (int)off); } EXPORT_SYMBOL(lprocfs_obd_rd_recovery_status); +#endif int lprocfs_obd_rd_ir_factor(char *page, char **start, off_t off, int count, int *eof, void *data) @@ -2694,6 +3309,19 @@ int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off, } EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc); +int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data) +{ + struct obd_device *dev = data; + struct client_obd *cli = &dev->u.cli; + int rc; + + client_obd_list_lock(&cli->cl_loi_list_lock); + rc = seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc); + client_obd_list_unlock(&cli->cl_loi_list_lock); + return rc; +} +EXPORT_SYMBOL(lprocfs_obd_max_pages_per_rpc_seq_show); + #ifdef HAVE_SERVER_SUPPORT int lprocfs_target_rd_instance(char *page, char **start, off_t off, int count, int *eof, void *data) diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index 94352df..806acfc 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -1278,6 +1278,7 @@ out: } EXPORT_SYMBOL(class_process_config); +#ifndef HAVE_ONLY_PROCFS_SEQ int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, struct lustre_cfg *lcfg, void *data) { @@ -1320,15 +1321,16 @@ int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, keylen == strlen(var->name)) { matched++; rc = -EROFS; - if (var->write_fptr) { - mm_segment_t oldfs; - oldfs = get_fs(); - set_fs(KERNEL_DS); - rc = (var->write_fptr)(NULL, sval, - vallen, data); - set_fs(oldfs); - } - break; + + if (var->write_fptr) { + mm_segment_t oldfs; + oldfs = get_fs(); + set_fs(KERNEL_DS); + rc = (var->write_fptr)(NULL, sval, + vallen, data); + set_fs(oldfs); + } + break; } j++; } @@ -1365,6 +1367,101 @@ int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, #endif } EXPORT_SYMBOL(class_process_proc_param); +#endif + +int class_process_proc_seq_param(char *prefix, struct lprocfs_seq_vars *lvars, + struct lustre_cfg *lcfg, void *data) +{ +#ifdef __KERNEL__ + struct lprocfs_seq_vars *var; + struct file fakefile; + struct seq_file fake_seqfile; + char *key, *sval; + int i, keylen, vallen; + int matched = 0, j = 0; + int rc = 0; + int skip = 0; + ENTRY; + + if (lcfg->lcfg_command != LCFG_PARAM) { + CERROR("Unknown command: %d\n", lcfg->lcfg_command); + RETURN(-EINVAL); + } + + /* fake a seq file so that var->fops->write can work... */ + fakefile.private_data = &fake_seqfile; + fake_seqfile.private = data; + /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt + or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar + or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */ + for (i = 1; i < lcfg->lcfg_bufcount; i++) { + key = lustre_cfg_buf(lcfg, i); + /* Strip off prefix */ + class_match_param(key, prefix, &key); + sval = strchr(key, '='); + if (!sval || (*(sval + 1) == 0)) { + CERROR("Can't parse param %s (missing '=')\n", key); + /* rc = -EINVAL; continue parsing other params */ + continue; + } + keylen = sval - key; + sval++; + vallen = strlen(sval); + matched = 0; + j = 0; + /* Search proc entries */ + while (lvars[j].name) { + var = &lvars[j]; + if (class_match_param(key, (char *)var->name, 0) == 0 && + keylen == strlen(var->name)) { + matched++; + rc = -EROFS; + + if (var->fops && var->fops->write) { + mm_segment_t oldfs; + oldfs = get_fs(); + set_fs(KERNEL_DS); + rc = (var->fops->write)(&fakefile, sval, + vallen, NULL); + set_fs(oldfs); + } + break; + } + j++; + } + if (!matched) { + /* If the prefix doesn't match, return error so we + can pass it down the stack */ + if (strnchr(key, keylen, '.')) + RETURN(-ENOSYS); + CERROR("%s: unknown param %s\n", + (char *)lustre_cfg_string(lcfg, 0), key); + /* rc = -EINVAL; continue parsing other params */ + skip++; + } else if (rc < 0) { + CERROR("writing proc entry %s err %d\n", + var->name, rc); + rc = 0; + } else { + CDEBUG(D_CONFIG, "%s.%.*s: Set parameter %.*s=%s\n", + lustre_cfg_string(lcfg, 0), + (int)strlen(prefix) - 1, prefix, + (int)(sval - key - 1), key, sval); + } + } + + if (rc > 0) + rc = 0; + if (!rc && skip) + rc = skip; + RETURN(rc); +#else + CDEBUG(D_CONFIG, "liblustre can't process params.\n"); + /* Don't throw config error */ + RETURN(0); +#endif +} +EXPORT_SYMBOL(class_process_proc_seq_param); #ifdef __KERNEL__ extern int lustre_check_exclusion(struct super_block *sb, char *svname); diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index 5eb750a..f84a516 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -3229,16 +3229,18 @@ int echo_client_init(void) lprocfs_echo_init_vars(&lvars); - rc = lu_kmem_init(echo_caches); - if (rc == 0) { - rc = class_register_type(&echo_client_obd_ops, NULL, - lvars.module_vars, - LUSTRE_ECHO_CLIENT_NAME, - &echo_device_type); - if (rc) - lu_kmem_fini(echo_caches); - } - return rc; + rc = lu_kmem_init(echo_caches); + if (rc == 0) { + rc = class_register_type(&echo_client_obd_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_ECHO_CLIENT_NAME, + &echo_device_type); + if (rc) + lu_kmem_fini(echo_caches); + } + return rc; } void echo_client_exit(void) @@ -3265,10 +3267,13 @@ static int __init obdecho_init(void) if (rc != 0) goto failed_0; - rc = class_register_type(&echo_obd_ops, NULL, lvars.module_vars, - LUSTRE_ECHO_NAME, NULL); - if (rc != 0) - goto failed_1; + rc = class_register_type(&echo_obd_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_ECHO_NAME, NULL); + if (rc != 0) + goto failed_1; # endif rc = echo_client_init(); diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index 2ddd9a2..ce5b7ae 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -1903,8 +1903,11 @@ int __init ofd_init(void) lprocfs_ofd_init_vars(&lvars); - rc = class_register_type(&ofd_obd_ops, NULL, lvars.module_vars, - LUSTRE_OST_NAME, &ofd_device_type); + rc = class_register_type(&ofd_obd_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_OST_NAME, &ofd_device_type); return rc; } diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index 796b1f5..428e51f 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -178,11 +178,12 @@ static int osc_rd_cached_mb(char *page, char **start, off_t off, int count, /* shrink the number of caching pages to a specific number */ static int osc_wr_cached_mb(struct file *file, const char *buffer, - unsigned long count, void *data) + unsigned long nob, void *data) { struct obd_device *dev = data; struct client_obd *cli = &dev->u.cli; int pages_number, mult, rc; + size_t count = nob; mult = 1 << (20 - PAGE_CACHE_SHIFT); buffer = lprocfs_find_named_value(buffer, "used_mb:", &count); diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index c3a839d..d3a7247 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -3733,8 +3733,11 @@ int __init osc_init(void) lprocfs_osc_init_vars(&lvars); - rc = class_register_type(&osc_obd_ops, NULL, lvars.module_vars, - LUSTRE_OSC_NAME, &osc_device_type); + rc = class_register_type(&osc_obd_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_OSC_NAME, &osc_device_type); if (rc) { lu_kmem_fini(osc_caches); RETURN(rc); diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 6fafb57..d10f4e9 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -5867,8 +5867,11 @@ static int __init osd_mod_init(void) if (rc) return rc; - rc = class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars, - LUSTRE_OSD_LDISKFS_NAME, &osd_device_type); + rc = class_register_type(&osd_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_OSD_LDISKFS_NAME, &osd_device_type); if (rc) lu_kmem_fini(ldiskfs_caches); return rc; diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index f400f5e..77f4799 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -898,9 +898,11 @@ int __init osd_init(void) if (rc) return rc; - rc = class_register_type(&osd_obd_device_ops, NULL, - lprocfs_osd_module_vars, - LUSTRE_OSD_ZFS_NAME, &osd_device_type); + rc = class_register_type(&osd_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lprocfs_osd_module_vars, +#endif + LUSTRE_OSD_ZFS_NAME, &osd_device_type); if (rc) lu_kmem_fini(osd_caches); return rc; diff --git a/lustre/osp/osp_dev.c b/lustre/osp/osp_dev.c index 1094a65..9c6a33c 100644 --- a/lustre/osp/osp_dev.c +++ b/lustre/osp/osp_dev.c @@ -1197,8 +1197,11 @@ static int __init osp_mod_init(void) lprocfs_osp_init_vars(&lvars); - rc = class_register_type(&osp_obd_device_ops, NULL, lvars.module_vars, - LUSTRE_OSP_NAME, &osp_device_type); + rc = class_register_type(&osp_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_OSP_NAME, &osp_device_type); /* create "osc" entry in procfs for compatibility purposes */ if (rc != 0) { @@ -1208,8 +1211,11 @@ static int __init osp_mod_init(void) lprocfs_lwp_init_vars(&lvars); - rc = class_register_type(&lwp_obd_device_ops, NULL, lvars.module_vars, - LUSTRE_LWP_NAME, &lwp_device_type); + rc = class_register_type(&lwp_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_LWP_NAME, &lwp_device_type); if (rc != 0) { class_unregister_type(LUSTRE_OSP_NAME); lu_kmem_fini(osp_caches); diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c index 1adc42f..72010ba 100644 --- a/lustre/ost/ost_handler.c +++ b/lustre/ost/ost_handler.c @@ -882,8 +882,11 @@ static int __init ost_init(void) ENTRY; lprocfs_ost_init_vars(&lvars); - rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars, - LUSTRE_OSS_NAME, NULL); + rc = class_register_type(&ost_obd_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_OSS_NAME, NULL); if (ost_num_threads != 0 && oss_num_threads == 0) { LCONSOLE_INFO("ost_num_threads module parameter is deprecated, " diff --git a/lustre/ptlrpc/nrs_crr.c b/lustre/ptlrpc/nrs_crr.c index 27959cf..134b88e 100644 --- a/lustre/ptlrpc/nrs_crr.c +++ b/lustre/ptlrpc/nrs_crr.c @@ -718,7 +718,7 @@ static int ptlrpc_lprocfs_wr_nrs_crrn_quantum(struct file *file, long quantum_reg; long quantum_hp; /** lprocfs_find_named_value() modifies its argument, so keep a copy */ - unsigned long count_copy; + size_t count_copy; int rc = 0; int rc2 = 0; diff --git a/lustre/ptlrpc/nrs_orr.c b/lustre/ptlrpc/nrs_orr.c index b723bca..3753fb9 100644 --- a/lustre/ptlrpc/nrs_orr.c +++ b/lustre/ptlrpc/nrs_orr.c @@ -1291,7 +1291,7 @@ static int ptlrpc_lprocfs_wr_nrs_orr_quantum(struct file *file, long quantum_reg; long quantum_hp; /** lprocfs_find_named_value() modifies its argument, so keep a copy */ - unsigned long count_copy; + size_t count_copy; int rc = 0; int rc2 = 0; @@ -1510,7 +1510,7 @@ static int ptlrpc_lprocfs_wr_nrs_orr_offset_type(struct file *file, char *val_hp; bool physical_reg; bool physical_hp; - unsigned long count_copy; + size_t count_copy; int rc = 0; int rc2 = 0; @@ -1772,7 +1772,7 @@ static int ptlrpc_lprocfs_wr_nrs_orr_supported(struct file *file, char *val_hp; enum nrs_orr_supp supp_reg; enum nrs_orr_supp supp_hp; - unsigned long count_copy; + size_t count_copy; int rc = 0; int rc2 = 0; diff --git a/lustre/quota/qmt_dev.c b/lustre/quota/qmt_dev.c index 7dcce4a..012b11d 100644 --- a/lustre/quota/qmt_dev.c +++ b/lustre/quota/qmt_dev.c @@ -466,8 +466,11 @@ int qmt_glb_init(void) int rc; ENTRY; - rc = class_register_type(&qmt_obd_ops, NULL, NULL, LUSTRE_QMT_NAME, - &qmt_device_type); + rc = class_register_type(&qmt_obd_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + NULL, +#endif + LUSTRE_QMT_NAME, &qmt_device_type); RETURN(rc); }