From b66962c0f92b29353ac255400783e9b0faa9c2e3 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 12 Jan 2015 19:54:52 -0500 Subject: [PATCH] LU-5275 lprocfs: remove all non-seq file functions With the completion of the move to seq_file based proc handling for lustre we can remove all the no longer used non-seq_file handling routines. Rename lprocfs_try_remove_proc_entry to match the new function in newer kernels and RHEL6.6 that does a similar thing (remove_proc_subtree). Change-Id: Ieff19f0216770da94f29562d51abcbf5869bad34 Signed-off-by: James Simmons Reviewed-on: http://review.whamcloud.com/12235 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Bob Glossman Reviewed-by: John L. Hammond Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- lustre/autoconf/lustre-core.m4 | 42 +++-- lustre/include/lprocfs_status.h | 72 +------- lustre/obdclass/genops.c | 16 +- lustre/obdclass/lprocfs_status.c | 293 ++++---------------------------- lustre/obdclass/lprocfs_status_server.c | 6 - 5 files changed, 71 insertions(+), 358 deletions(-) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 500e350..85632e6 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -1281,7 +1281,7 @@ hlist_for_each_entry_3args, [ # f73a1c7d117d07a96d89475066188a2b79e53c48 # AC_DEFUN([LC_HAVE_BIO_END_SECTOR], [ -LB_CHECK_COMPILE([if 'bio_end_sector is defined], +LB_CHECK_COMPILE([if 'bio_end_sector' is defined], bio_end_sector, [ #include ],[ @@ -1295,21 +1295,38 @@ bio_end_sector, [ ]) # LC_HAVE_BIO_END_SECTOR # -# LC_HAVE_ONLY_PROCFS_SEQ +# LC_HAVE_REMOVE_PROC_SUBTREE # -# 3.10+ only supports procfs seq_files handling +# 3.10 introduced remove_proc_subtree # -AC_DEFUN([LC_HAVE_ONLY_PROCFS_SEQ], [ -LB_CHECK_COMPILE([if procfs only supports using 'seq_files'], -only_procfs_seq_files, [ +AC_DEFUN([LC_HAVE_REMOVE_PROC_SUBTREE], [ +LB_CHECK_COMPILE([if 'remove_proc_subtree' is defined], +remove_proc_subtree, [ #include ],[ - ((struct proc_dir_entry *)0)->write_proc(NULL, NULL, 0, NULL); -], [], [ - AC_DEFINE(HAVE_ONLY_PROCFS_SEQ, 1, - [only seq_files supported]) + remove_proc_subtree(NULL, NULL); +], [ + AC_DEFINE(HAVE_REMOVE_PROC_SUBTREE, 1, + [remove_proc_subtree is defined]) +]) +]) # LC_HAVE_REMOVE_PROC_SUBTREE + +# +# LC_HAVE_PROC_REMOVE +# +# 3.10 introduced proc_remove +# +AC_DEFUN([LC_HAVE_PROC_REMOVE], [ +LB_CHECK_COMPILE([if 'proc_remove' is defined], +proc_remove, [ + #include +],[ + proc_remove(NULL); +], [ + AC_DEFINE(HAVE_PROC_REMOVE, 1, + [proc_remove is defined]) ]) -]) # LC_HAVE_ONLY_PROCFS_SEQ +]) # LC_HAVE_PROC_REMOVE # # LC_BLKDEV_RELEASE_RETURN_INT @@ -1624,8 +1641,9 @@ AC_DEFUN([LC_PROG_LINUX], [ LC_HAVE_BIO_END_SECTOR # 3.10 - LC_HAVE_ONLY_PROCFS_SEQ LC_BLKDEV_RELEASE_RETURN_INT + LC_HAVE_REMOVE_PROC_SUBTREE + LC_HAVE_PROC_REMOVE # 3.11 LC_INVALIDATE_RANGE diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index d1c197a..42eec31 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -35,12 +35,12 @@ * * lustre/include/lprocfs_status.h * - * Top level header file for LProc SNMP + * Top level header file for LProc * * Author: Hariharan Thantry thantry@users.sourceforge.net */ -#ifndef _LPROCFS_SNMP_H -#define _LPROCFS_SNMP_H +#ifndef _LPROCFS_STATUS_H +#define _LPROCFS_STATUS_H #include #include @@ -49,26 +49,6 @@ #include -#ifndef HAVE_ONLY_PROCFS_SEQ -struct lprocfs_vars { - const char *name; - read_proc_t *read_fptr; - write_proc_t *write_fptr; - void *data; - const struct file_operations *fops; - /** - * /proc file mode. - */ - mode_t proc_mode; -}; - -struct lprocfs_static_vars { - struct lprocfs_vars *module_vars; - struct lprocfs_vars *obd_vars; -}; - -#endif - struct lprocfs_seq_vars { const char *name; const struct file_operations *fops; @@ -627,16 +607,6 @@ extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name, struct lprocfs_stats *stats); /* lprocfs_status.c */ -#ifndef HAVE_ONLY_PROCFS_SEQ -extern int lprocfs_add_vars(struct proc_dir_entry *root, - struct lprocfs_vars *var, - void *data); - -extern struct proc_dir_entry *lprocfs_register(const char *name, - struct proc_dir_entry *parent, - struct lprocfs_vars *list, - void *data); -#endif extern int lprocfs_seq_add_vars(struct proc_dir_entry *root, struct lprocfs_seq_vars *var, void *data); @@ -647,13 +617,9 @@ lprocfs_seq_register(const char *name, struct proc_dir_entry *parent, extern void lprocfs_remove(struct proc_dir_entry **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 struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *root, - const char *name); - +#ifndef HAVE_REMOVE_PROC_SUBTREE +extern int remove_proc_subtree(const char *name, + struct proc_dir_entry *parent); #define PDE_DATA(inode) (PDE(inode)->data) static inline int LPROCFS_ENTRY_CHECK(struct inode *inode) @@ -717,12 +683,6 @@ extern ssize_t lprocfs_timeouts_seq_write(struct file *file, const char *buffer, size_t count, loff_t *off); #ifdef HAVE_SERVER_SUPPORT -#ifndef HAVE_ONLY_PROCFS_SEQ -extern ssize_t lprocfs_fops_read(struct file *f, char __user *buf, - size_t size, loff_t *ppos); -extern ssize_t lprocfs_fops_write(struct file *f, const char __user *buf, - size_t size, loff_t *ppos); -#endif extern ssize_t lprocfs_evict_client_seq_write(struct file *file, const char *buffer, size_t count, loff_t *off); @@ -1042,16 +1002,6 @@ static inline struct proc_dir_entry * lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent, const char *format, ...) {return NULL; } -#ifndef HAVE_ONLY_PROCFS_SEQ -static inline struct proc_dir_entry * -lprocfs_register(const char *name, struct proc_dir_entry *parent, - struct lprocfs_vars *list, void *data) -{ return NULL; } -static inline int lprocfs_add_vars(struct proc_dir_entry *root, - struct lprocfs_vars *var, - void *data) -{ return 0; } -#endif static inline int lprocfs_seq_add_vars(struct proc_dir_entry *root, struct lprocfs_seq_vars *var, void *data) @@ -1065,14 +1015,6 @@ static inline void lprocfs_remove(struct proc_dir_entry **root) 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; } -static inline struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head, - const char *name) -{ return 0; } -#endif static inline int lprocfs_obd_setup(struct obd_device *dev) { return 0; } static inline int lprocfs_obd_cleanup(struct obd_device *dev) @@ -1192,4 +1134,4 @@ int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num, #endif /* CONFIG_PROC_FS */ -#endif /* LPROCFS_SNMP_H */ +#endif /* LPROCFS_STATUS_H */ diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 50eb6b5..a76b448 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -223,15 +223,9 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, failed: if (type->typ_name != NULL) { #ifdef CONFIG_PROC_FS - if (type->typ_procroot != NULL) { -#ifndef HAVE_ONLY_PROCFS_SEQ - lprocfs_try_remove_proc_entry(type->typ_name, - proc_lustre_root); -#else + if (type->typ_procroot != NULL) remove_proc_subtree(type->typ_name, proc_lustre_root); #endif - } -#endif OBD_FREE(type->typ_name, strlen(name) + 1); } if (type->typ_md_ops != NULL) @@ -267,14 +261,8 @@ int class_unregister_type(const char *name) * we can't reference pointer as it can get invalided when another * module removes the entry */ #ifdef CONFIG_PROC_FS - if (type->typ_procroot != NULL) { -#ifndef HAVE_ONLY_PROCFS_SEQ - lprocfs_try_remove_proc_entry(type->typ_name, proc_lustre_root); -#else + if (type->typ_procroot != NULL) remove_proc_subtree(type->typ_name, proc_lustre_root); -#endif - } - if (type->typ_procsym != NULL) lprocfs_remove(&type->typ_procsym); #endif diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index f00f3fd..1afdffb 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -40,7 +40,6 @@ #define DEBUG_SUBSYSTEM S_CLASS - #include #include #include @@ -117,213 +116,7 @@ struct proc_dir_entry *lprocfs_add_symlink(const char *name, } EXPORT_SYMBOL(lprocfs_add_symlink); -#ifdef HAVE_ONLY_PROCFS_SEQ static const struct file_operations lprocfs_generic_fops = { }; -#else - -ssize_t -lprocfs_fops_read(struct file *f, char __user *buf, size_t size, loff_t *ppos) -{ - struct inode *inode = f->f_dentry->d_inode; - struct proc_dir_entry *dp = PDE(inode); - char *page, *start = NULL; - int rc, eof = 1, count; - - if (*ppos >= PAGE_CACHE_SIZE) - return 0; - - page = (char *)__get_free_page(GFP_KERNEL); - if (page == NULL) - return -ENOMEM; - - rc = LPROCFS_ENTRY_CHECK(inode); - if (rc < 0) - goto out; - - OBD_FAIL_TIMEOUT(OBD_FAIL_LPROC_REMOVE, 10); - if (dp->read_proc != NULL) - rc = dp->read_proc(page, &start, *ppos, PAGE_CACHE_SIZE, - &eof, dp->data); - else - rc = 0; - - if (rc <= 0) - goto out; - - /* for lustre proc read, the read count must be less than PAGE_SIZE */ - LASSERT(eof == 1); - - if (start == NULL) { - rc -= *ppos; - if (rc < 0) - rc = 0; - if (rc == 0) - goto out; - start = page + *ppos; - } else if (start < page) { - start = page; - } - - count = (rc < size) ? rc : size; - if (copy_to_user(buf, start, count)) { - rc = -EFAULT; - goto out; - } - *ppos += count; - -out: - free_page((unsigned long)page); - return rc; -} - -ssize_t -lprocfs_fops_write(struct file *f, const char __user *buf, size_t size, - loff_t *ppos) -{ - struct inode *inode = f->f_dentry->d_inode; - struct proc_dir_entry *dp = PDE(inode); - int rc; - - rc = LPROCFS_ENTRY_CHECK(inode); - if (rc < 0) - return rc; - - if (dp->write_proc != NULL) - rc = dp->write_proc(f, buf, size, dp->data); - else - rc = -EIO; - - return rc; -} - -static struct file_operations lprocfs_generic_fops = { - .owner = THIS_MODULE, - .read = lprocfs_fops_read, - .write = lprocfs_fops_write, -}; - -/* 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) -{ - struct proc_dir_entry *temp; - - if (head == NULL) - return NULL; - - temp = head->subdir; - while (temp != NULL) { - if (strcmp(temp->name, name) == 0) - return temp; - temp = temp->next; - } - return NULL; -} - -struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head, - const char *name) -{ - struct proc_dir_entry *temp; - - down_read(&_lprocfs_lock); - temp = __lprocfs_srch(head, name); - up_read(&_lprocfs_lock); - return temp; -} -EXPORT_SYMBOL(lprocfs_srch); - -static int __lprocfs_add_vars(struct proc_dir_entry *root, - struct lprocfs_vars *list, - void *data) -{ - int rc = 0; - - if (root == NULL || list == NULL) - return -EINVAL; - - while (list->name != NULL) { - struct proc_dir_entry *cur_root, *proc; - char *pathcopy, *cur, *next, pathbuf[64]; - int pathsize = strlen(list->name) + 1; - - proc = NULL; - cur_root = root; - - /* need copy of path for strsep */ - if (strlen(list->name) > sizeof(pathbuf) - 1) { - OBD_ALLOC(pathcopy, pathsize); - if (pathcopy == NULL) - GOTO(out, rc = -ENOMEM); - } else { - pathcopy = pathbuf; - } - - next = pathcopy; - strcpy(pathcopy, list->name); - - while (cur_root != NULL && (cur = strsep(&next, "/"))) { - if (*cur =='\0') /* skip double/trailing "/" */ - continue; - - proc = __lprocfs_srch(cur_root, cur); - CDEBUG(D_OTHER, "cur_root=%s, cur=%s, next=%s, (%s)\n", - cur_root->name, cur, next, - (proc ? "exists" : "new")); - if (next != NULL) { - cur_root = (proc ? proc : - proc_mkdir(cur, cur_root)); - } else if (proc == NULL) { - mode_t mode = 0; - if (list->proc_mode != 0000) { - mode = list->proc_mode; - } else { - if (list->read_fptr) - mode = 0444; - if (list->write_fptr) - mode |= 0200; - } - proc = create_proc_entry(cur, mode, cur_root); - } - } - - if (pathcopy != pathbuf) - OBD_FREE(pathcopy, pathsize); - - if (cur_root == NULL || proc == NULL) { - CERROR("LprocFS: No memory to create /proc entry %s\n", - list->name); - GOTO(out, rc = -ENOMEM); - } - - if (list->fops) - proc->proc_fops = list->fops; - else - proc->proc_fops = &lprocfs_generic_fops; - proc->read_proc = list->read_fptr; - proc->write_proc = list->write_fptr; - proc->data = (list->data ? list->data : data); - list++; - } -out: - return rc; -} - -int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list, - void *data) -{ - int rc = 0; - - down_write(&_lprocfs_lock); - rc = __lprocfs_add_vars(root, list, data); - up_write(&_lprocfs_lock); - - return rc; -} -EXPORT_SYMBOL(lprocfs_add_vars); -#endif /** * Add /proc entries. @@ -366,7 +159,11 @@ lprocfs_seq_add_vars(struct proc_dir_entry *root, struct lprocfs_seq_vars *list, } EXPORT_SYMBOL(lprocfs_seq_add_vars); -#ifndef HAVE_ONLY_PROCFS_SEQ +#ifndef HAVE_REMOVE_PROC_SUBTREE +/* for b=10866, global variable */ +DECLARE_RWSEM(_lprocfs_lock); +EXPORT_SYMBOL(_lprocfs_lock); + static void lprocfs_remove_nolock(struct proc_dir_entry **proot) { struct proc_dir_entry *root = *proot; @@ -399,31 +196,8 @@ static void lprocfs_remove_nolock(struct proc_dir_entry **proot) break; } } -#endif - -void lprocfs_remove(struct proc_dir_entry **rooth) -{ -#ifndef HAVE_ONLY_PROCFS_SEQ - down_write(&_lprocfs_lock); /* search vs remove race */ - lprocfs_remove_nolock(rooth); - up_write(&_lprocfs_lock); -#else - proc_remove(*rooth); - *rooth = NULL; -#endif -} -EXPORT_SYMBOL(lprocfs_remove); -void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent) -{ - LASSERT(parent != NULL); - remove_proc_entry(name, 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) +int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { struct proc_dir_entry *t = NULL; struct proc_dir_entry **p; @@ -462,42 +236,39 @@ void lprocfs_try_remove_proc_entry(const char *name, lprocfs_remove_nolock(&t); up_write(&_lprocfs_lock); - return; + return 0; } -EXPORT_SYMBOL(lprocfs_try_remove_proc_entry); +EXPORT_SYMBOL(remove_proc_subtree); +#endif /* !HAVE_REMOVE_PROC_SUBTREE */ -struct proc_dir_entry *lprocfs_register(const char *name, - struct proc_dir_entry *parent, - struct lprocfs_vars *list, void *data) +#ifndef HAVE_PROC_REMOVE +void proc_remove(struct proc_dir_entry *de) { - struct proc_dir_entry *entry; - int rc; - - down_write(&_lprocfs_lock); - entry = __lprocfs_srch(parent, name); - if (entry != NULL) { - CERROR("entry '%s' already registered\n", name); - GOTO(out, entry = ERR_PTR(-EALREADY)); - } - - entry = proc_mkdir(name, parent); - if (entry == NULL) - GOTO(out, entry = ERR_PTR(-ENOMEM)); - - if (list != NULL) { - rc = __lprocfs_add_vars(entry, list, data); - if (rc != 0) { - lprocfs_remove_nolock(&entry); - GOTO(out, entry = ERR_PTR(rc)); - } - } -out: +#ifndef HAVE_REMOVE_PROC_SUBTREE + down_write(&_lprocfs_lock); /* search vs remove race */ + lprocfs_remove_nolock(&de); up_write(&_lprocfs_lock); - return entry; +#else + if (de) + remove_proc_subtree(de->name, de->parent); +#endif } -EXPORT_SYMBOL(lprocfs_register); #endif +void lprocfs_remove(struct proc_dir_entry **rooth) +{ + proc_remove(*rooth); + *rooth = NULL; +} +EXPORT_SYMBOL(lprocfs_remove); + +void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent) +{ + LASSERT(parent != NULL); + remove_proc_entry(name, parent); +} +EXPORT_SYMBOL(lprocfs_remove_proc_entry); + struct proc_dir_entry * lprocfs_seq_register(const char *name, struct proc_dir_entry *parent, struct lprocfs_seq_vars *list, void *data) diff --git a/lustre/obdclass/lprocfs_status_server.c b/lustre/obdclass/lprocfs_status_server.c index cfefaa5..b7215dd 100644 --- a/lustre/obdclass/lprocfs_status_server.c +++ b/lustre/obdclass/lprocfs_status_server.c @@ -345,15 +345,9 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid) GOTO(destroy_new, rc = -ENOMEM); memcpy(buffer, libcfs_nid2str(*nid), LNET_NIDSTR_SIZE); -#ifndef HAVE_ONLY_PROCFS_SEQ - new_stat->nid_proc = lprocfs_register(buffer, - obd->obd_proc_exports_entry, - NULL, NULL); -#else new_stat->nid_proc = lprocfs_seq_register(buffer, obd->obd_proc_exports_entry, NULL, NULL); -#endif OBD_FREE(buffer, LNET_NIDSTR_SIZE); if (IS_ERR(new_stat->nid_proc)) { -- 1.8.3.1