Whamcloud - gitweb
LU-2071 lprocfs: Memory leak on lustre proc access
authorOleg Drokin <green@whamcloud.com>
Tue, 2 Oct 2012 02:55:27 +0000 (22:55 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 5 Oct 2012 20:23:39 +0000 (16:23 -0400)
Make __LPROC_SEQ_FOPS to call lprocfs_single_release in release so that
the memory allocated in single_open to be freed.
Rename some of the auto-named methods to better reflect on the nature
of the underlying calls.
The previous code used to leak 32 bytes per every lustre proc file open
that uses lprocfs_..._seq_open primitive.

Change-Id: I08cc1bbb28af444f3fa5e903e38fd4a16dc4c79b
Signed-off-by: Oleg Drokin <green@whamcloud.com>
Reviewed-on: http://review.whamcloud.com/4150
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: wangdi <di.wang@whamcloud.com>
lustre/include/lprocfs_status.h
lustre/obdclass/lprocfs_status.c

index f5a9181..dc32c08 100644 (file)
@@ -681,6 +681,7 @@ int lprocfs_obd_rd_ir_factor(char *page, char **start, off_t off,
 int lprocfs_obd_wr_ir_factor(struct file *file, const char *buffer,
                              unsigned long count, void *data);
 
 int lprocfs_obd_wr_ir_factor(struct file *file, const char *buffer,
                              unsigned long count, void *data);
 
+extern int lprocfs_single_release(cfs_inode_t *, struct file *);
 extern int lprocfs_seq_release(cfs_inode_t *, struct file *);
 
 /* You must use these macros when you want to refer to
 extern int lprocfs_seq_release(cfs_inode_t *, struct file *);
 
 /* You must use these macros when you want to refer to
@@ -702,7 +703,7 @@ extern int lprocfs_seq_release(cfs_inode_t *, struct file *);
   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)                           \
   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##_seq_open(cfs_inode_t *inode, struct file *file) {        \
+static int name##_single_open(cfs_inode_t *inode, struct file *file) {     \
         struct proc_dir_entry *dp = PDE(inode);                            \
         int rc;                                                            \
         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
         struct proc_dir_entry *dp = PDE(inode);                            \
         int rc;                                                            \
         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
@@ -715,11 +716,11 @@ static int name##_seq_open(cfs_inode_t *inode, struct file *file) {        \
 }                                                                          \
 struct file_operations name##_fops = {                                     \
         .owner   = THIS_MODULE,                                            \
 }                                                                          \
 struct file_operations name##_fops = {                                     \
         .owner   = THIS_MODULE,                                            \
-        .open    = name##_seq_open,                                        \
+        .open    = name##_single_open,                                     \
         .read    = seq_read,                                               \
         .write   = custom_seq_write,                                       \
         .llseek  = seq_lseek,                                              \
         .read    = seq_read,                                               \
         .write   = custom_seq_write,                                       \
         .llseek  = seq_lseek,                                              \
-        .release = lprocfs_seq_release,                                    \
+        .release = lprocfs_single_release,                                 \
 }
 
 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
 }
 
 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
index 521047c..624140c 100644 (file)
@@ -63,6 +63,13 @@ CFS_MODULE_PARM(lprocfs_no_percpu_stats, "i", int, 0644,
 CFS_DECLARE_RWSEM(_lprocfs_lock);
 EXPORT_SYMBOL(_lprocfs_lock);
 
 CFS_DECLARE_RWSEM(_lprocfs_lock);
 EXPORT_SYMBOL(_lprocfs_lock);
 
+int lprocfs_single_release(struct inode *inode, struct file *file)
+{
+        LPROCFS_EXIT();
+        return single_release(inode, file);
+}
+EXPORT_SYMBOL(lprocfs_single_release);
+
 int lprocfs_seq_release(struct inode *inode, struct file *file)
 {
         LPROCFS_EXIT();
 int lprocfs_seq_release(struct inode *inode, struct file *file)
 {
         LPROCFS_EXIT();