4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #ifndef _LUSTRE_COMPAT_H
34 #define _LUSTRE_COMPAT_H
36 #include <linux/aio.h>
38 #include <linux/fs_struct.h>
39 #include <linux/namei.h>
40 #include <linux/pagemap.h>
41 #include <linux/bio.h>
42 #include <linux/xattr.h>
43 #include <linux/workqueue.h>
44 #include <linux/blkdev.h>
45 #include <linux/slab.h>
47 #include <libcfs/linux/linux-fs.h>
48 #include <lustre_patchless_compat.h>
49 #include <obd_support.h>
51 #ifdef HAVE_FS_STRUCT_RWLOCK
52 # define LOCK_FS_STRUCT(fs) write_lock(&(fs)->lock)
53 # define UNLOCK_FS_STRUCT(fs) write_unlock(&(fs)->lock)
55 # define LOCK_FS_STRUCT(fs) spin_lock(&(fs)->lock)
56 # define UNLOCK_FS_STRUCT(fs) spin_unlock(&(fs)->lock)
59 #ifdef HAVE_FS_STRUCT_SEQCOUNT
60 # define WRITE_FS_SEQ_BEGIN(fs) write_seqcount_begin(&(fs)->seq)
61 # define WRITE_FS_SEQ_END(fs) write_seqcount_end(&(fs)->seq)
63 # define WRITE_FS_SEQ_BEGIN(fs)
64 # define WRITE_FS_SEQ_END(fs)
66 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
67 struct dentry *dentry)
76 WRITE_FS_SEQ_BEGIN(fs);
86 #define current_ngroups current_cred()->group_info->ngroups
87 #define current_groups current_cred()->group_info->small_block
90 * OBD need working random driver, thus all our
91 * initialization routines must be called after device
92 * driver initialization
96 #define module_init(a) late_initcall(a)
99 #ifndef MODULE_ALIAS_FS
100 #define MODULE_ALIAS_FS(name)
103 #ifdef HAVE_GENERIC_PERMISSION_2ARGS
104 # define ll_generic_permission(inode, mask, flags, check_acl) \
105 generic_permission(inode, mask)
106 #elif defined HAVE_GENERIC_PERMISSION_4ARGS
107 # define ll_generic_permission(inode, mask, flags, check_acl) \
108 generic_permission(inode, mask, flags, check_acl)
110 # define ll_generic_permission(inode, mask, flags, check_acl) \
111 generic_permission(inode, mask, check_acl)
114 #ifdef HAVE_4ARGS_VFS_SYMLINK
115 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
116 vfs_symlink(dir, dentry, path, mode)
118 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
119 vfs_symlink(dir, dentry, path)
122 #if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
123 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
124 generic_file_llseek_size(file, offset, origin, maxbytes, eof);
126 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
127 generic_file_llseek_size(file, offset, origin, maxbytes);
130 #ifdef HAVE_INODE_DIO_WAIT
131 /* inode_dio_wait(i) use as-is for write lock */
132 # define inode_dio_write_done(i) do {} while (0) /* for write unlock */
134 # define inode_dio_wait(i) down_write(&(i)->i_alloc_sem)
135 # define inode_dio_write_done(i) up_write(&(i)->i_alloc_sem)
138 #ifndef HAVE_SIMPLE_SETATTR
139 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
142 #ifndef HAVE_INIT_LIST_HEAD_RCU
143 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
145 WRITE_ONCE(list->next, list);
146 WRITE_ONCE(list->prev, list);
150 #ifndef HAVE_DQUOT_SUSPEND
151 # define ll_vfs_dq_init vfs_dq_init
152 # define ll_vfs_dq_drop vfs_dq_drop
153 # define ll_vfs_dq_transfer vfs_dq_transfer
154 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
156 # define ll_vfs_dq_init dquot_initialize
157 # define ll_vfs_dq_drop dquot_drop
158 # define ll_vfs_dq_transfer dquot_transfer
159 # define ll_vfs_dq_off(sb, remount) dquot_suspend(sb, -1)
162 #ifndef HAVE_BLKDEV_GET_BY_DEV
163 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
166 #ifdef HAVE_BVEC_ITER
167 #define bio_idx(bio) (bio->bi_iter.bi_idx)
168 #define bio_set_sector(bio, sector) (bio->bi_iter.bi_sector = sector)
169 #define bvl_to_page(bvl) (bvl->bv_page)
171 #define bio_idx(bio) (bio->bi_idx)
172 #define bio_set_sector(bio, sector) (bio->bi_sector = sector)
173 #define bio_sectors(bio) ((bio)->bi_size >> 9)
174 #ifndef HAVE_BIO_END_SECTOR
175 #define bio_end_sector(bio) (bio->bi_sector + bio_sectors(bio))
177 #define bvl_to_page(bvl) (bvl->bv_page)
180 #ifdef HAVE_BVEC_ITER
181 #define bio_start_sector(bio) (bio->bi_iter.bi_sector)
183 #define bio_start_sector(bio) (bio->bi_sector)
186 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
187 #define blk_queue_max_segments(rq, seg) \
188 do { blk_queue_max_phys_segments(rq, seg); \
189 blk_queue_max_hw_segments(rq, seg); } while (0)
191 #define queue_max_phys_segments(rq) queue_max_segments(rq)
192 #define queue_max_hw_segments(rq) queue_max_segments(rq)
196 #define DECLARE_PLUG(plug) struct blk_plug plug
197 #else /* !HAVE_BLK_PLUG */
198 #define DECLARE_PLUG(name)
199 #define blk_start_plug(plug) do {} while (0)
200 #define blk_finish_plug(plug) do {} while (0)
203 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
204 #define ll_kmap_atomic(a, b) kmap_atomic(a)
205 #define ll_kunmap_atomic(a, b) kunmap_atomic(a)
207 #define ll_kmap_atomic(a, b) kmap_atomic(a, b)
208 #define ll_kunmap_atomic(a, b) kunmap_atomic(a, b)
211 #ifndef HAVE_CLEAR_INODE
212 #define clear_inode(i) end_writeback(i)
215 #ifndef HAVE_DENTRY_D_CHILD
216 #define d_child d_u.d_child
219 #ifdef HAVE_DENTRY_D_U_D_ALIAS
220 #define d_alias d_u.d_alias
223 #ifndef DATA_FOR_LLITE_IS_LIST
224 #define ll_d_hlist_node hlist_node
225 #define ll_d_hlist_empty(list) hlist_empty(list)
226 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
227 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
228 # ifdef HAVE_HLIST_FOR_EACH_3ARG
229 # define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
230 p = NULL; hlist_for_each_entry(dentry, i_dentry, d_alias)
232 # define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
233 hlist_for_each_entry(dentry, p, i_dentry, d_alias)
235 #define DECLARE_LL_D_HLIST_NODE_PTR(name) struct ll_d_hlist_node *name
237 #define ll_d_hlist_node list_head
238 #define ll_d_hlist_empty(list) list_empty(list)
239 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
240 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
241 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
242 list_for_each_entry(dentry, i_dentry, d_alias)
243 #define DECLARE_LL_D_HLIST_NODE_PTR(name) /* nothing */
244 #endif /* !DATA_FOR_LLITE_IS_LIST */
246 #ifndef HAVE_D_IN_LOOKUP
247 static inline int d_in_lookup(struct dentry *dentry)
257 # define NO_QUOTA (-EDQUOT)
261 #define SEEK_DATA 3 /* seek to the next data */
264 #define SEEK_HOLE 4 /* seek to the next hole */
267 #ifndef FMODE_UNSIGNED_OFFSET
268 #define FMODE_UNSIGNED_OFFSET ((__force fmode_t)0x2000)
271 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
272 # define ext2_set_bit __test_and_set_bit_le
273 # define ext2_clear_bit __test_and_clear_bit_le
274 # define ext2_test_bit test_bit_le
275 # define ext2_find_first_zero_bit find_first_zero_bit_le
276 # define ext2_find_next_zero_bit find_next_zero_bit_le
279 #ifdef ATTR_TIMES_SET
280 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
282 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
285 #ifndef XATTR_NAME_POSIX_ACL_ACCESS
286 # define XATTR_NAME_POSIX_ACL_ACCESS POSIX_ACL_XATTR_ACCESS
289 #ifndef XATTR_NAME_POSIX_ACL_DEFAULT
290 # define XATTR_NAME_POSIX_ACL_DEFAULT POSIX_ACL_XATTR_DEFAULT
293 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
294 # define lm_compare_owner fl_compare_owner
298 * After 3.1, kernel's nameidata.intent.open.flags is different
299 * with lustre's lookup_intent.it_flags, as lustre's it_flags'
300 * lower bits equal to FMODE_xxx while kernel doesn't transliterate
301 * lower bits of nameidata.intent.open.flags to FMODE_xxx.
303 #include <linux/version.h>
304 static inline int ll_namei_to_lookup_intent_flag(int flag)
306 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
307 flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
312 #include <linux/fs.h>
313 #ifndef HAVE_PROTECT_I_NLINK
314 static inline void set_nlink(struct inode *inode, unsigned int nlink)
316 inode->i_nlink = nlink;
320 #ifdef HAVE_INODEOPS_USE_UMODE_T
321 # define ll_umode_t umode_t
323 # define ll_umode_t int
326 #ifndef HAVE_VM_FAULT_T
327 #define vm_fault_t int
330 #include <linux/dcache.h>
331 #ifndef HAVE_D_MAKE_ROOT
332 static inline struct dentry *d_make_root(struct inode *root)
334 struct dentry *res = d_alloc_root(root);
336 if (res == NULL && root)
343 #ifdef HAVE_DIRTY_INODE_HAS_FLAG
344 # define ll_dirty_inode(inode, flag) (inode)->i_sb->s_op->dirty_inode((inode), flag)
346 # define ll_dirty_inode(inode, flag) (inode)->i_sb->s_op->dirty_inode((inode))
349 #ifdef HAVE_FILE_F_INODE
350 # define set_file_inode(file, inode) (file)->f_inode = inode
352 # define set_file_inode(file, inode)
355 #ifndef HAVE_FILE_INODE
356 static inline struct inode *file_inode(const struct file *file)
358 return file->f_path.dentry->d_inode;
362 #ifdef HAVE_OLDSIZE_TRUNCATE_PAGECACHE
363 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, 0, size)
365 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, size)
368 #ifdef HAVE_VFS_RENAME_5ARGS
369 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL)
370 #elif defined HAVE_VFS_RENAME_6ARGS
371 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL, 0)
373 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d)
376 #ifdef HAVE_VFS_UNLINK_3ARGS
377 #define ll_vfs_unlink(a, b) vfs_unlink(a, b, NULL)
379 #define ll_vfs_unlink(a, b) vfs_unlink(a, b)
382 #ifndef HAVE_INODE_OWNER_OR_CAPABLE
383 #define inode_owner_or_capable(inode) is_owner_or_cap(inode)
386 static inline int ll_vfs_getattr(struct path *path, struct kstat *st)
390 #ifdef HAVE_INODEOPS_ENHANCED_GETATTR
391 rc = vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
392 #elif defined HAVE_VFS_GETATTR_2ARGS
393 rc = vfs_getattr(path, st);
395 rc = vfs_getattr(path->mnt, path->dentry, st);
400 #ifndef HAVE_D_IS_POSITIVE
401 static inline bool d_is_positive(const struct dentry *dentry)
403 return dentry->d_inode != NULL;
407 #ifdef HAVE_VFS_CREATE_USE_NAMEIDATA
408 # define LL_VFS_CREATE_FALSE NULL
410 # define LL_VFS_CREATE_FALSE false
413 #ifndef HAVE_INODE_LOCK
414 # define inode_lock(inode) mutex_lock(&(inode)->i_mutex)
415 # define inode_unlock(inode) mutex_unlock(&(inode)->i_mutex)
416 # define inode_trylock(inode) mutex_trylock(&(inode)->i_mutex)
419 #ifndef HAVE_RADIX_EXCEPTION_ENTRY
420 static inline int radix_tree_exceptional_entry(void *arg)
426 #ifndef HAVE_TRUNCATE_INODE_PAGES_FINAL
427 static inline void truncate_inode_pages_final(struct address_space *map)
429 truncate_inode_pages(map, 0);
433 #ifndef HAVE_PTR_ERR_OR_ZERO
434 static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
444 #define SIZE_MAX (~(size_t)0)
447 #ifdef HAVE_SECURITY_IINITSEC_CALLBACK
448 # define ll_security_inode_init_security(inode, dir, name, value, len, \
449 initxattrs, dentry) \
450 security_inode_init_security(inode, dir, &((dentry)->d_name), \
452 #elif defined HAVE_SECURITY_IINITSEC_QSTR
453 # define ll_security_inode_init_security(inode, dir, name, value, len, \
454 initxattrs, dentry) \
455 security_inode_init_security(inode, dir, &((dentry)->d_name), \
457 #else /* !HAVE_SECURITY_IINITSEC_CALLBACK && !HAVE_SECURITY_IINITSEC_QSTR */
458 # define ll_security_inode_init_security(inode, dir, name, value, len, \
459 initxattrs, dentry) \
460 security_inode_init_security(inode, dir, name, value, len)
463 #ifndef bio_for_each_segment_all /* since kernel version 3.9 */
464 #ifdef HAVE_BVEC_ITER
465 #define bio_for_each_segment_all(bv, bio, it) \
466 for (it = 0, bv = (bio)->bi_io_vec; it < (bio)->bi_vcnt; it++, bv++)
468 #define bio_for_each_segment_all(bv, bio, it) bio_for_each_segment(bv, bio, it)
472 #ifdef HAVE_PID_NS_FOR_CHILDREN
473 # define ll_task_pid_ns(task) ((task)->nsproxy->pid_ns_for_children)
475 # define ll_task_pid_ns(task) ((task)->nsproxy->pid_ns)
478 #ifdef HAVE_FULL_NAME_HASH_3ARGS
479 # define ll_full_name_hash(salt, name, len) full_name_hash(salt, name, len)
481 # define ll_full_name_hash(salt, name, len) full_name_hash(name, len)
484 #ifdef HAVE_STRUCT_POSIX_ACL_XATTR
485 # define posix_acl_xattr_header struct posix_acl_xattr_header
486 # define posix_acl_xattr_entry struct posix_acl_xattr_entry
487 # define GET_POSIX_ACL_XATTR_ENTRY(head) ((void *)((head) + 1))
489 # define GET_POSIX_ACL_XATTR_ENTRY(head) ((head)->a_entries)
492 #ifdef HAVE_IOP_XATTR
493 #ifdef HAVE_XATTR_HANDLER_FLAGS
494 #define ll_setxattr generic_setxattr
495 #define ll_getxattr generic_getxattr
496 #define ll_removexattr generic_removexattr
498 int ll_setxattr(struct dentry *dentry, const char *name,
499 const void *value, size_t size, int flags);
500 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
501 void *buf, size_t buf_size);
502 int ll_removexattr(struct dentry *dentry, const char *name);
503 #endif /* ! HAVE_XATTR_HANDLER_FLAGS */
504 #endif /* HAVE_IOP_XATTR */
506 #ifndef HAVE_VFS_SETXATTR
507 const struct xattr_handler *get_xattr_type(const char *name);
510 __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
511 const void *value, size_t size, int flags)
513 # ifdef HAVE_XATTR_HANDLER_FLAGS
514 const struct xattr_handler *handler;
517 handler = get_xattr_type(name);
521 # if defined(HAVE_XATTR_HANDLER_INODE_PARAM)
522 rc = handler->set(handler, dentry, inode, name, value, size, flags);
523 # elif defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
524 rc = handler->set(handler, dentry, name, value, size, flags);
526 rc = handler->set(dentry, name, value, size, flags, handler->flags);
527 # endif /* !HAVE_XATTR_HANDLER_INODE_PARAM */
529 # else /* !HAVE_XATTR_HANDLER_FLAGS */
530 return ll_setxattr(dentry, name, value, size, flags);
531 # endif /* HAVE_XATTR_HANDLER_FLAGS */
533 #endif /* HAVE_VFS_SETXATTR */
535 #ifdef HAVE_IOP_SET_ACL
536 #ifdef CONFIG_FS_POSIX_ACL
537 #ifndef HAVE_POSIX_ACL_UPDATE_MODE
538 static inline int posix_acl_update_mode(struct inode *inode, umode_t *mode_p,
539 struct posix_acl **acl)
541 umode_t mode = inode->i_mode;
544 error = posix_acl_equiv_mode(*acl, &mode);
549 if (!in_group_p(inode->i_gid) &&
550 !capable_wrt_inode_uidgid(inode, CAP_FSETID))
555 #endif /* HAVE_POSIX_ACL_UPDATE_MODE */
559 #ifndef HAVE_IOV_ITER_TRUNCATE
560 static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
562 if (i->count > count)
568 static inline bool is_sxid(umode_t mode)
570 return (mode & S_ISUID) || ((mode & S_ISGID) && (mode & S_IXGRP));
575 #define IS_NOSEC(inode) (!is_sxid(inode->i_mode))
579 * mount MS_* flags split from superblock SB_* flags
580 * if the SB_* flags are not available use the MS_* flags
582 #if !defined(SB_RDONLY) && defined(MS_RDONLY)
583 # define SB_RDONLY MS_RDONLY
585 #if !defined(SB_ACTIVE) && defined(MS_ACTIVE)
586 # define SB_ACTIVE MS_ACTIVE
588 #if !defined(SB_NOSEC) && defined(MS_NOSEC)
589 # define SB_NOSEC MS_NOSEC
591 #if !defined(SB_POSIXACL) && defined(MS_POSIXACL)
592 # define SB_POSIXACL MS_POSIXACL
594 #if !defined(SB_NODIRATIME) && defined(MS_NODIRATIME)
595 # define SB_NODIRATIME MS_NODIRATIME
598 #ifndef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
599 static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
604 static inline struct iovec iov_iter_iovec(const struct iov_iter *iter)
606 return (struct iovec) {
607 .iov_base = iter->iov->iov_base + iter->iov_offset,
608 .iov_len = min(iter->count,
609 iter->iov->iov_len - iter->iov_offset),
613 #define iov_for_each(iov, iter, start) \
614 for (iter = (start); \
615 (iter).count && ((iov = iov_iter_iovec(&(iter))), 1); \
616 iov_iter_advance(&(iter), (iov).iov_len))
618 static inline ssize_t
619 generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
625 iov_for_each(iov, i, *iter) {
628 res = generic_file_aio_read(iocb, &iov, 1, iocb->ki_pos);
636 if (res < iov.iov_len)
641 iov_iter_advance(iter, bytes);
645 static inline ssize_t
646 __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
652 /* Since LLITE updates file size at the end of I/O in
653 * vvp_io_commit_write(), append write has to be done in atomic when
654 * there are multiple segments because otherwise each iteration to
655 * __generic_file_aio_write() will see original file size */
656 if (unlikely(iocb->ki_filp->f_flags & O_APPEND && iter->nr_segs > 1)) {
657 struct iovec *iov_copy;
660 OBD_ALLOC(iov_copy, sizeof(*iov_copy) * iter->nr_segs);
664 iov_for_each(iov, i, *iter)
665 iov_copy[count++] = iov;
667 bytes = __generic_file_aio_write(iocb, iov_copy, count,
669 OBD_FREE(iov_copy, sizeof(*iov_copy) * iter->nr_segs);
672 iov_iter_advance(iter, bytes);
676 iov_for_each(iov, i, *iter) {
679 res = __generic_file_aio_write(iocb, &iov, 1, &iocb->ki_pos);
687 if (res < iov.iov_len)
692 iov_iter_advance(iter, bytes);
695 #endif /* HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
697 static inline void __user *get_vmf_address(struct vm_fault *vmf)
699 #ifdef HAVE_VM_FAULT_ADDRESS
700 return (void __user *)vmf->address;
702 return vmf->virtual_address;
706 #ifdef HAVE_VM_OPS_USE_VM_FAULT_ONLY
707 # define ll_filemap_fault(vma, vmf) filemap_fault(vmf)
709 # define ll_filemap_fault(vma, vmf) filemap_fault(vma, vmf)
712 #ifndef HAVE_CURRENT_TIME
713 static inline struct timespec current_time(struct inode *inode)
721 * time_after32 - compare two 32-bit relative times
722 * @a: the time which may be after @b
723 * @b: the time which may be before @a
725 * time_after32(a, b) returns true if the time @a is after time @b.
726 * time_before32(b, a) returns true if the time @b is before time @a.
728 * Similar to time_after(), compare two 32-bit timestamps for relative
729 * times. This is useful for comparing 32-bit seconds values that can't
730 * be converted to 64-bit values (e.g. due to disk format or wire protocol
731 * issues) when it is known that the times are less than 68 years apart.
733 #define time_after32(a, b) ((s32)((u32)(b) - (u32)(a)) < 0)
734 #define time_before32(b, a) time_after32(a, b)
742 #ifndef alloc_workqueue
743 #define alloc_workqueue(name, flags, max_active) create_workqueue(name)
747 #define smp_store_mb(var, value) set_mb(var, value)
751 #define READ_ONCE ACCESS_ONCE
754 #if IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY)
755 static inline unsigned short blk_integrity_interval(struct blk_integrity *bi)
757 #ifdef HAVE_INTERVAL_EXP_BLK_INTEGRITY
758 return bi->interval_exp ? 1 << bi->interval_exp : 0;
759 #elif defined(HAVE_INTERVAL_BLK_INTEGRITY)
762 return bi->sector_size;
763 #endif /* !HAVE_INTERVAL_EXP_BLK_INTEGRITY */
766 static inline const char *blk_integrity_name(struct blk_integrity *bi)
768 #ifdef HAVE_INTERVAL_EXP_BLK_INTEGRITY
769 return bi->profile->name;
775 static inline unsigned int bip_size(struct bio_integrity_payload *bip)
777 #ifdef HAVE_BIP_ITER_BIO_INTEGRITY_PAYLOAD
778 return bip->bip_iter.bi_size;
780 return bip->bip_size;
783 #else /* !CONFIG_BLK_DEV_INTEGRITY */
784 static inline unsigned short blk_integrity_interval(struct blk_integrity *bi)
788 static inline const char *blk_integrity_name(struct blk_integrity *bi)
790 /* gcc8 dislikes when strcmp() is called against NULL */
793 #endif /* !CONFIG_BLK_DEV_INTEGRITY */
795 #ifndef INTEGRITY_FLAG_READ
796 #define INTEGRITY_FLAG_READ BLK_INTEGRITY_VERIFY
799 #ifndef INTEGRITY_FLAG_WRITE
800 #define INTEGRITY_FLAG_WRITE BLK_INTEGRITY_GENERATE
803 static inline bool bdev_integrity_enabled(struct block_device *bdev, int rw)
805 #if IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY)
806 struct blk_integrity *bi = bdev_get_integrity(bdev);
811 #ifdef HAVE_INTERVAL_EXP_BLK_INTEGRITY
812 if (rw == 0 && bi->profile->verify_fn != NULL &&
813 (bi->flags & INTEGRITY_FLAG_READ))
816 if (rw == 1 && bi->profile->generate_fn != NULL &&
817 (bi->flags & INTEGRITY_FLAG_WRITE))
820 if (rw == 0 && bi->verify_fn != NULL &&
821 (bi->flags & INTEGRITY_FLAG_READ))
824 if (rw == 1 && bi->generate_fn != NULL &&
825 (bi->flags & INTEGRITY_FLAG_WRITE))
827 #endif /* !HAVE_INTERVAL_EXP_BLK_INTEGRITY */
828 #endif /* !CONFIG_BLK_DEV_INTEGRITY */
833 #ifdef HAVE_PAGEVEC_INIT_ONE_PARAM
834 #define ll_pagevec_init(pvec, n) pagevec_init(pvec)
836 #define ll_pagevec_init(pvec, n) pagevec_init(pvec, n)
840 #define page_tree i_pages
842 #define i_pages tree_lock
843 #define xa_lock_irq(lockp) spin_lock_irq(lockp)
844 #define xa_unlock_irq(lockp) spin_unlock_irq(lockp)
847 #ifndef KMEM_CACHE_USERCOPY
848 #define kmem_cache_create_usercopy(name, size, align, flags, useroffset, \
850 kmem_cache_create(name, size, align, flags, ctor)
853 #endif /* _LUSTRE_COMPAT_H */