Whamcloud - gitweb
LU-13581 build: xarray and lockdep_is_held const clash
[fs/lustre-release.git] / lustre / include / lustre_compat.h
index 1d16ac9..5defcfd 100644 (file)
@@ -35,7 +35,6 @@
 
 #include <linux/aio.h>
 #include <linux/fs.h>
-#include <linux/fs_struct.h>
 #include <linux/namei.h>
 #include <linux/pagemap.h>
 #include <linux/posix_acl_xattr.h>
                        vfs_symlink(dir, dentry, path)
 #endif
 
-#ifndef HAVE_INIT_LIST_HEAD_RCU
-static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
-{
-       WRITE_ONCE(list->next, list);
-       WRITE_ONCE(list->prev, list);
-}
-#endif
-
 #ifdef HAVE_BVEC_ITER
 #define bio_idx(bio)                   (bio->bi_iter.bi_idx)
 #define bio_set_sector(bio, sector)    (bio->bi_iter.bi_sector = sector)
@@ -124,12 +115,13 @@ static inline int d_in_lookup(struct dentry *dentry)
 #define ll_vfs_unlink(a, b) vfs_unlink(a, b)
 #endif
 
-static inline int ll_vfs_getattr(struct path *path, struct kstat *st)
+static inline int ll_vfs_getattr(struct path *path, struct kstat *st,
+                                u32 request_mask, unsigned int flags)
 {
        int rc;
 
 #ifdef HAVE_INODEOPS_ENHANCED_GETATTR
-       rc = vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
+       rc = vfs_getattr(path, st, request_mask, flags);
 #else
        rc = vfs_getattr(path, st);
 #endif
@@ -149,11 +141,19 @@ static inline bool d_is_positive(const struct dentry *dentry)
 # define inode_trylock(inode) mutex_trylock(&(inode)->i_mutex)
 #endif
 
-#ifndef HAVE_XA_IS_VALUE
-static inline bool xa_is_value(void *entry)
+/* Old kernels lacked both Xarray support and the page cache
+ * using Xarrays. Our back ported Xarray support introduces
+ * the real xa_is_value() but we need a wrapper as well for
+ * the page cache interaction. Lets keep xa_is_value() separate
+ * in old kernels for Xarray support and page cache handling.
+ */
+#ifndef HAVE_XARRAY_SUPPORT
+static inline bool ll_xa_is_value(void *entry)
 {
        return radix_tree_exceptional_entry(entry);
 }
+#else
+#define ll_xa_is_value xa_is_value
 #endif
 
 #ifndef HAVE_TRUNCATE_INODE_PAGES_FINAL
@@ -201,31 +201,6 @@ static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
 #define ll_removexattr  generic_removexattr
 #endif /* HAVE_IOP_XATTR */
 
-#ifndef HAVE_VFS_SETXATTR
-const struct xattr_handler *get_xattr_type(const char *name);
-
-static inline int
-__vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
-              const void *value, size_t size, int flags)
-{
-       const struct xattr_handler *handler;
-       int rc;
-
-       handler = get_xattr_type(name);
-       if (!handler)
-               return -EOPNOTSUPP;
-
-#  if defined(HAVE_XATTR_HANDLER_INODE_PARAM)
-       rc = handler->set(handler, dentry, inode, name, value, size, flags);
-#  elif defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
-       rc = handler->set(handler, dentry, name, value, size, flags);
-#  else
-       rc = handler->set(dentry, name, value, size, flags, handler->flags);
-#  endif /* !HAVE_XATTR_HANDLER_INODE_PARAM */
-       return rc;
-}
-#endif /* HAVE_VFS_SETXATTR */
-
 #ifndef HAVE_POSIX_ACL_VALID_USER_NS
 #define posix_acl_valid(a,b)           posix_acl_valid(b)
 #endif
@@ -344,7 +319,7 @@ __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
                struct iovec *iov_copy;
                int count = 0;
 
-               OBD_ALLOC(iov_copy, sizeof(*iov_copy) * iter->nr_segs);
+               OBD_ALLOC_PTR_ARRAY(iov_copy, iter->nr_segs);
                if (!iov_copy)
                        return -ENOMEM;
 
@@ -353,7 +328,7 @@ __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
 
                bytes = __generic_file_aio_write(iocb, iov_copy, count,
                                                 &iocb->ki_pos);
-               OBD_FREE(iov_copy, sizeof(*iov_copy) * iter->nr_segs);
+               OBD_FREE_PTR_ARRAY(iov_copy, iter->nr_segs);
 
                if (bytes > 0)
                        iov_iter_advance(iter, bytes);
@@ -403,6 +378,27 @@ static inline struct timespec current_time(struct inode *inode)
 }
 #endif
 
+#ifndef time_after32
+/**
+ * time_after32 - compare two 32-bit relative times
+ * @a: the time which may be after @b
+ * @b: the time which may be before @a
+ *
+ * Needed for kernels earlier than v4.14-rc1~134^2
+ *
+ * time_after32(a, b) returns true if the time @a is after time @b.
+ * time_before32(b, a) returns true if the time @b is before time @a.
+ *
+ * Similar to time_after(), compare two 32-bit timestamps for relative
+ * times.  This is useful for comparing 32-bit seconds values that can't
+ * be converted to 64-bit values (e.g. due to disk format or wire protocol
+ * issues) when it is known that the times are less than 68 years apart.
+ */
+#define time_after32(a, b)     ((s32)((u32)(b) - (u32)(a)) < 0)
+#define time_before32(b, a)    time_after32(a, b)
+
+#endif
+
 #ifndef smp_store_mb
 #define smp_store_mb(var, value)       set_mb(var, value)
 #endif
@@ -504,13 +500,12 @@ static inline bool bdev_integrity_enabled(struct block_device *bdev, int rw)
 
 #ifdef HAVE_I_PAGES
 #define page_tree i_pages
+#define ll_xa_lock_irqsave(lockp, flags) xa_lock_irqsave(lockp, flags)
+#define ll_xa_unlock_irqrestore(lockp, flags) xa_unlock_irqrestore(lockp, flags)
 #else
 #define i_pages tree_lock
-#endif
-
-#ifndef xa_lock_irqsave
-#define xa_lock_irqsave(lockp, flags) spin_lock_irqsave(lockp, flags)
-#define xa_unlock_irqrestore(lockp, flags) spin_unlock_irqrestore(lockp, flags)
+#define ll_xa_lock_irqsave(lockp, flags) spin_lock_irqsave(lockp, flags)
+#define ll_xa_unlock_irqrestore(lockp, flags) spin_unlock_irqrestore(lockp, flags)
 #endif
 
 #ifndef HAVE_LOCK_PAGE_MEMCG
@@ -528,4 +523,45 @@ static inline bool bdev_integrity_enabled(struct block_device *bdev, int rw)
 #define selinux_is_enabled() 1
 #endif
 
+static inline int ll_vfs_getxattr(struct dentry *dentry, struct inode *inode,
+                                 const char *name,
+                                 void *value, size_t size)
+{
+#ifndef HAVE_VFS_SETXATTR
+       if (unlikely(!inode->i_op->getxattr))
+               return -ENODATA;
+
+       return inode->i_op->getxattr(dentry, name, value, size);
+#else
+       return __vfs_getxattr(dentry, inode, name, value, size);
+#endif
+}
+
+static inline int ll_vfs_setxattr(struct dentry *dentry, struct inode *inode,
+                                 const char *name,
+                                 const void *value, size_t size, int flags)
+{
+#ifndef HAVE_VFS_SETXATTR
+       if (unlikely(!inode->i_op->setxattr))
+               return -EOPNOTSUPP;
+
+       return inode->i_op->setxattr(dentry, name, value, size, flags);
+#else
+       return __vfs_setxattr(dentry, inode, name, value, size, flags);
+#endif
+}
+
+static inline int ll_vfs_removexattr(struct dentry *dentry, struct inode *inode,
+                                    const char *name)
+{
+#ifndef HAVE_VFS_SETXATTR
+       if (unlikely(!inode->i_op->setxattr))
+               return -EOPNOTSUPP;
+
+       return inode->i_op->removexattr(dentry, name);
+#else
+       return __vfs_removexattr(dentry, name);
+#endif
+}
+
 #endif /* _LUSTRE_COMPAT_H */