Whamcloud - gitweb
LU-1994 kernel: fix reference counting with l_dentry_open
[fs/lustre-release.git] / lustre / include / linux / lustre_compat25.h
index b37e3cd..e0a29ff 100644 (file)
@@ -140,19 +140,28 @@ static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
 #define ll_blkdev_put(a, b) blkdev_put(a)
 #endif
 
-static inline struct file *ll_dentry_open(struct dentry *dentry,
-                                         struct vfsmount *mnt, int flags,
-                                         const struct cred *cred)
-{
 #ifdef HAVE_DENTRY_OPEN_USE_PATH
-       struct path path = { .mnt = mnt, .dentry = dentry };
-       return dentry_open(&path, flags, cred);
-#elif defined HAVE_DENTRY_OPEN_4ARGS
-       return dentry_open(dentry, mnt, flags, cred);
+#define ll_dentry_open(a,b,c)  dentry_open(a,b,c)
 #else
-       return dentry_open(dentry, mnt, flags);
-#endif
+/*
+ * dentry_open handles its own reference counting since Linux v3.6
+ * (commit 765927b2). Callers should free their own references.
+ *
+ * Prior versions expected the caller to increment the references.
+ * The references are retained on success and freed on error.
+ */
+static inline struct file *ll_dentry_open(struct path *path, int flags,
+                                         const struct cred *cred)
+{
+       mntget(path->mnt);
+       dget(path->dentry);
+# ifdef HAVE_DENTRY_OPEN_4ARGS
+       return dentry_open(path->dentry, path->mnt, flags, cred);
+# else
+       return dentry_open(path->dentry, path->mnt, flags);
+# endif
 }
+#endif
 
 #ifdef HAVE_SECURITY_PLUG
 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
@@ -168,6 +177,14 @@ static inline struct file *ll_dentry_open(struct dentry *dentry,
 
 #endif
 
+#if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
+#define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
+               generic_file_llseek_size(file, offset, origin, maxbytes, eof);
+#else
+#define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
+               generic_file_llseek_size(file, offset, origin, maxbytes);
+#endif
+
 #ifdef HAVE_INODE_DIO_WAIT
 /* inode_dio_wait(i) use as-is for write lock */
 # define inode_dio_write_done(i)       do {} while (0) /* for write unlock */