Whamcloud - gitweb
Revert "LU-2800 autoconf: remove LC_PROCFS_USERS test"
[fs/lustre-release.git] / libcfs / include / libcfs / params_tree.h
index 41413eb..1bf8d37 100644 (file)
@@ -78,8 +78,46 @@ typedef struct poll_table_struct                cfs_poll_table_t;
 /* in lprocfs_stat.c, to protect the private data for proc entries */
 extern struct rw_semaphore             _lprocfs_lock;
 
+/* to begin from 2.6.23, Linux defines self file_operations (proc_reg_file_ops)
+ * in procfs, the proc file_operation defined by Lustre (lprocfs_generic_fops)
+ * will be wrapped into the new defined proc_reg_file_ops, which instroduces
+ * user count in proc_dir_entrey(pde_users) to protect the proc entry from
+ * being deleted. then the protection lock (_lprocfs_lock) defined by Lustre
+ * isn't necessary anymore for lprocfs_generic_fops(e.g. lprocfs_fops_read).
+ * see bug19706 for detailed information.
+ */
+#ifndef HAVE_PROCFS_USERS
+
+#define LPROCFS_ENTRY()                \
+do {                                   \
+       down_read(&_lprocfs_lock);      \
+} while(0)
+
+#define LPROCFS_EXIT()                 \
+do {                                   \
+       up_read(&_lprocfs_lock);        \
+} while(0)
+
+#else
+#define LPROCFS_ENTRY() do{ }while(0)
+#define LPROCFS_EXIT()  do{ }while(0)
+#endif
+
+#ifdef HAVE_PROCFS_DELETED
+
+static inline
+int LPROCFS_ENTRY_AND_CHECK(struct proc_dir_entry *dp)
+{
+        LPROCFS_ENTRY();
+        if ((dp)->deleted) {
+                LPROCFS_EXIT();
+                return -ENODEV;
+        }
+        return 0;
+}
+#elif defined(HAVE_PROCFS_USERS) /* !HAVE_PROCFS_DELETED*/
 static inline
-int LPROCFS_ENTRY_CHECK(struct proc_dir_entry *dp)
+int LPROCFS_ENTRY_AND_CHECK(struct proc_dir_entry *dp)
 {
        int deleted = 0;
 
@@ -91,6 +129,14 @@ int LPROCFS_ENTRY_CHECK(struct proc_dir_entry *dp)
                return -ENODEV;
        return 0;
 }
+#else /* !HAVE_PROCFS_DELETED*/
+static inline
+int LPROCFS_ENTRY_AND_CHECK(struct proc_dir_entry *dp)
+{
+        LPROCFS_ENTRY();
+        return 0;
+}
+#endif /* HAVE_PROCFS_DELETED */
 #define LPROCFS_SRCH_ENTRY()            \
 do {                                    \
         down_read(&_lprocfs_lock);      \
@@ -201,9 +247,12 @@ do {                                                    \
         rc = 0;                                         \
 } while(0)
 
+#define LPROCFS_ENTRY()             do {} while(0)
+#define LPROCFS_EXIT()              do {} while(0)
 static inline
-int LPROCFS_ENTRY_CHECK(cfs_param_dentry_t *dp)
+int LPROCFS_ENTRY_AND_CHECK(cfs_param_dentry_t *dp)
 {
+        LPROCFS_ENTRY();
         return 0;
 }
 #define LPROCFS_WRITE_ENTRY()       do {} while(0)