Whamcloud - gitweb
LU-12477 kernel: remove < 2.6.39 kernel support
[fs/lustre-release.git] / lustre / include / lustre_compat.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #ifndef _LUSTRE_COMPAT_H
34 #define _LUSTRE_COMPAT_H
35
36 #include <linux/aio.h>
37 #include <linux/fs.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>
46
47 #include <libcfs/linux/linux-fs.h>
48 #include <lustre_patchless_compat.h>
49 #include <obd_support.h>
50
51 #define current_ngroups current_cred()->group_info->ngroups
52 #define current_groups current_cred()->group_info->small_block
53
54 #ifdef HAVE_4ARGS_VFS_SYMLINK
55 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
56                 vfs_symlink(dir, dentry, path, mode)
57 #else
58 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
59                        vfs_symlink(dir, dentry, path)
60 #endif
61
62 #if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
63 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
64                 generic_file_llseek_size(file, offset, origin, maxbytes, eof);
65 #else
66 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
67                 generic_file_llseek_size(file, offset, origin, maxbytes);
68 #endif
69
70 #ifdef HAVE_INODE_DIO_WAIT
71 /* inode_dio_wait(i) use as-is for write lock */
72 # define inode_dio_write_done(i)        do {} while (0) /* for write unlock */
73 #else
74 # define inode_dio_wait(i)              down_write(&(i)->i_alloc_sem)
75 # define inode_dio_write_done(i)        up_write(&(i)->i_alloc_sem)
76 #endif
77
78 #ifndef HAVE_INIT_LIST_HEAD_RCU
79 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
80 {
81         WRITE_ONCE(list->next, list);
82         WRITE_ONCE(list->prev, list);
83 }
84 #endif
85
86 #ifdef HAVE_BVEC_ITER
87 #define bio_idx(bio)                    (bio->bi_iter.bi_idx)
88 #define bio_set_sector(bio, sector)     (bio->bi_iter.bi_sector = sector)
89 #define bvl_to_page(bvl)                (bvl->bv_page)
90 #else
91 #define bio_idx(bio)                    (bio->bi_idx)
92 #define bio_set_sector(bio, sector)     (bio->bi_sector = sector)
93 #define bio_sectors(bio)                ((bio)->bi_size >> 9)
94 #ifndef HAVE_BIO_END_SECTOR
95 #define bio_end_sector(bio)             (bio->bi_sector + bio_sectors(bio))
96 #endif
97 #define bvl_to_page(bvl)                (bvl->bv_page)
98 #endif
99
100 #ifdef HAVE_BVEC_ITER
101 #define bio_start_sector(bio) (bio->bi_iter.bi_sector)
102 #else
103 #define bio_start_sector(bio) (bio->bi_sector)
104 #endif
105
106 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
107 #define ll_kmap_atomic(a, b)    kmap_atomic(a)
108 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a)
109 #else
110 #define ll_kmap_atomic(a, b)    kmap_atomic(a, b)
111 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a, b)
112 #endif
113
114 #ifndef HAVE_CLEAR_INODE
115 #define clear_inode(i)          end_writeback(i)
116 #endif
117
118 #ifndef HAVE_DENTRY_D_CHILD
119 #define d_child                 d_u.d_child
120 #endif
121
122 #ifdef HAVE_DENTRY_D_U_D_ALIAS
123 #define d_alias                 d_u.d_alias
124 #endif
125
126 #ifndef DATA_FOR_LLITE_IS_LIST
127 #define ll_d_hlist_node hlist_node
128 #define ll_d_hlist_empty(list) hlist_empty(list)
129 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
130 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
131 # ifdef HAVE_HLIST_FOR_EACH_3ARG
132 # define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
133         p = NULL; hlist_for_each_entry(dentry, i_dentry, d_alias)
134 # else
135 # define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
136         hlist_for_each_entry(dentry, p, i_dentry, d_alias)
137 # endif
138 #define DECLARE_LL_D_HLIST_NODE_PTR(name) struct ll_d_hlist_node *name
139 #else
140 #define ll_d_hlist_node list_head
141 #define ll_d_hlist_empty(list) list_empty(list)
142 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
143 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
144 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
145         list_for_each_entry(dentry, i_dentry, d_alias)
146 #define DECLARE_LL_D_HLIST_NODE_PTR(name) /* nothing */
147 #endif /* !DATA_FOR_LLITE_IS_LIST */
148
149 #ifndef HAVE_D_IN_LOOKUP
150 static inline int d_in_lookup(struct dentry *dentry)
151 {
152         return false;
153 }
154 #endif
155
156 #ifndef QUOTA_OK
157 # define QUOTA_OK 0
158 #endif
159 #ifndef NO_QUOTA
160 # define NO_QUOTA (-EDQUOT)
161 #endif
162
163 #ifndef SEEK_DATA
164 #define SEEK_DATA      3       /* seek to the next data */
165 #endif
166 #ifndef SEEK_HOLE
167 #define SEEK_HOLE      4       /* seek to the next hole */
168 #endif
169
170 #ifndef FMODE_UNSIGNED_OFFSET
171 #define FMODE_UNSIGNED_OFFSET   ((__force fmode_t)0x2000)
172 #endif
173
174 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
175 # define ext2_set_bit             __test_and_set_bit_le
176 # define ext2_clear_bit           __test_and_clear_bit_le
177 # define ext2_test_bit            test_bit_le
178 # define ext2_find_first_zero_bit find_first_zero_bit_le
179 # define ext2_find_next_zero_bit  find_next_zero_bit_le
180 #endif
181
182 #ifdef ATTR_TIMES_SET
183 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
184 #else
185 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
186 #endif
187
188 #ifndef XATTR_NAME_POSIX_ACL_ACCESS
189 # define XATTR_NAME_POSIX_ACL_ACCESS POSIX_ACL_XATTR_ACCESS
190 #endif
191
192 #ifndef XATTR_NAME_POSIX_ACL_DEFAULT
193 # define XATTR_NAME_POSIX_ACL_DEFAULT POSIX_ACL_XATTR_DEFAULT
194 #endif
195
196 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
197 # define lm_compare_owner       fl_compare_owner
198 #endif
199
200 /*
201  * After 3.1, kernel's nameidata.intent.open.flags is different
202  * with lustre's lookup_intent.it_flags, as lustre's it_flags'
203  * lower bits equal to FMODE_xxx while kernel doesn't transliterate
204  * lower bits of nameidata.intent.open.flags to FMODE_xxx.
205  * */
206 #include <linux/version.h>
207 static inline int ll_namei_to_lookup_intent_flag(int flag)
208 {
209 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
210         flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
211 #endif
212         return flag;
213 }
214
215 #include <linux/fs.h>
216 #ifndef HAVE_PROTECT_I_NLINK
217 static inline void set_nlink(struct inode *inode, unsigned int nlink)
218 {
219         inode->i_nlink = nlink;
220 }
221 #endif
222
223 #ifdef HAVE_INODEOPS_USE_UMODE_T
224 # define ll_umode_t     umode_t
225 #else
226 # define ll_umode_t     int
227 #endif
228
229 #ifndef HAVE_VM_FAULT_T
230 #define vm_fault_t int
231 #endif
232
233 #include <linux/dcache.h>
234 #ifndef HAVE_D_MAKE_ROOT
235 static inline struct dentry *d_make_root(struct inode *root)
236 {
237         struct dentry *res = d_alloc_root(root);
238
239         if (res == NULL && root)
240                 iput(root);
241
242         return res;
243 }
244 #endif
245
246 #ifdef HAVE_DIRTY_INODE_HAS_FLAG
247 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode), flag)
248 #else
249 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode))
250 #endif
251
252 #ifdef HAVE_FILE_F_INODE
253 # define set_file_inode(file, inode)    (file)->f_inode = inode
254 #else
255 # define set_file_inode(file, inode)
256 #endif
257
258 #ifndef HAVE_FILE_INODE
259 static inline struct inode *file_inode(const struct file *file)
260 {
261         return file->f_path.dentry->d_inode;
262 }
263 #endif
264
265 #ifdef HAVE_OLDSIZE_TRUNCATE_PAGECACHE
266 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, 0, size)
267 #else
268 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, size)
269 #endif
270
271 #ifdef HAVE_VFS_RENAME_5ARGS
272 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL)
273 #elif defined HAVE_VFS_RENAME_6ARGS
274 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL, 0)
275 #else
276 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d)
277 #endif
278
279 #ifdef HAVE_VFS_UNLINK_3ARGS
280 #define ll_vfs_unlink(a, b) vfs_unlink(a, b, NULL)
281 #else
282 #define ll_vfs_unlink(a, b) vfs_unlink(a, b)
283 #endif
284
285 #ifndef HAVE_INODE_OWNER_OR_CAPABLE
286 #define inode_owner_or_capable(inode) is_owner_or_cap(inode)
287 #endif
288
289 static inline int ll_vfs_getattr(struct path *path, struct kstat *st)
290 {
291         int rc;
292
293 #ifdef HAVE_INODEOPS_ENHANCED_GETATTR
294         rc = vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
295 #elif defined HAVE_VFS_GETATTR_2ARGS
296         rc = vfs_getattr(path, st);
297 #else
298         rc = vfs_getattr(path->mnt, path->dentry, st);
299 #endif
300         return rc;
301 }
302
303 #ifndef HAVE_D_IS_POSITIVE
304 static inline bool d_is_positive(const struct dentry *dentry)
305 {
306         return dentry->d_inode != NULL;
307 }
308 #endif
309
310 #ifdef HAVE_VFS_CREATE_USE_NAMEIDATA
311 # define LL_VFS_CREATE_FALSE NULL
312 #else
313 # define LL_VFS_CREATE_FALSE false
314 #endif
315
316 #ifndef HAVE_INODE_LOCK
317 # define inode_lock(inode) mutex_lock(&(inode)->i_mutex)
318 # define inode_unlock(inode) mutex_unlock(&(inode)->i_mutex)
319 # define inode_trylock(inode) mutex_trylock(&(inode)->i_mutex)
320 #endif
321
322 #ifndef HAVE_RADIX_EXCEPTION_ENTRY
323 static inline int radix_tree_exceptional_entry(void *arg)
324 {
325         return 0;
326 }
327 #endif
328
329 #ifndef HAVE_TRUNCATE_INODE_PAGES_FINAL
330 static inline void truncate_inode_pages_final(struct address_space *map)
331 {
332         truncate_inode_pages(map, 0);
333 }
334 #endif
335
336 #ifndef HAVE_PTR_ERR_OR_ZERO
337 static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
338 {
339         if (IS_ERR(ptr))
340                 return PTR_ERR(ptr);
341         else
342                 return 0;
343 }
344 #endif
345
346 #ifndef SIZE_MAX
347 #define SIZE_MAX        (~(size_t)0)
348 #endif
349
350 #ifdef HAVE_SECURITY_IINITSEC_CALLBACK
351 # define ll_security_inode_init_security(inode, dir, name, value, len, \
352                                          initxattrs, dentry)           \
353          security_inode_init_security(inode, dir, &((dentry)->d_name), \
354                                       initxattrs, dentry)
355 #elif defined HAVE_SECURITY_IINITSEC_QSTR
356 # define ll_security_inode_init_security(inode, dir, name, value, len, \
357                                          initxattrs, dentry)           \
358          security_inode_init_security(inode, dir, &((dentry)->d_name), \
359                                       name, value, len)
360 #else /* !HAVE_SECURITY_IINITSEC_CALLBACK && !HAVE_SECURITY_IINITSEC_QSTR */
361 # define ll_security_inode_init_security(inode, dir, name, value, len, \
362                                          initxattrs, dentry)           \
363          security_inode_init_security(inode, dir, name, value, len)
364 #endif
365
366 #ifndef bio_for_each_segment_all /* since kernel version 3.9 */
367 #ifdef HAVE_BVEC_ITER
368 #define bio_for_each_segment_all(bv, bio, it) \
369         for (it = 0, bv = (bio)->bi_io_vec; it < (bio)->bi_vcnt; it++, bv++)
370 #else
371 #define bio_for_each_segment_all(bv, bio, it) bio_for_each_segment(bv, bio, it)
372 #endif
373 #endif
374
375 #ifdef HAVE_PID_NS_FOR_CHILDREN
376 # define ll_task_pid_ns(task)   ((task)->nsproxy->pid_ns_for_children)
377 #else
378 # define ll_task_pid_ns(task)   ((task)->nsproxy->pid_ns)
379 #endif
380
381 #ifdef HAVE_FULL_NAME_HASH_3ARGS
382 # define ll_full_name_hash(salt, name, len) full_name_hash(salt, name, len)
383 #else
384 # define ll_full_name_hash(salt, name, len) full_name_hash(name, len)
385 #endif
386
387 #ifdef HAVE_STRUCT_POSIX_ACL_XATTR
388 # define posix_acl_xattr_header struct posix_acl_xattr_header
389 # define posix_acl_xattr_entry  struct posix_acl_xattr_entry
390 # define GET_POSIX_ACL_XATTR_ENTRY(head) ((void *)((head) + 1))
391 #else
392 # define GET_POSIX_ACL_XATTR_ENTRY(head) ((head)->a_entries)
393 #endif
394
395 #ifdef HAVE_IOP_XATTR
396 #define ll_setxattr     generic_setxattr
397 #define ll_getxattr     generic_getxattr
398 #define ll_removexattr  generic_removexattr
399 #endif /* HAVE_IOP_XATTR */
400
401 #ifndef HAVE_VFS_SETXATTR
402 const struct xattr_handler *get_xattr_type(const char *name);
403
404 static inline int
405 __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
406                const void *value, size_t size, int flags)
407 {
408         const struct xattr_handler *handler;
409         int rc;
410
411         handler = get_xattr_type(name);
412         if (!handler)
413                 return -EOPNOTSUPP;
414
415 #  if defined(HAVE_XATTR_HANDLER_INODE_PARAM)
416         rc = handler->set(handler, dentry, inode, name, value, size, flags);
417 #  elif defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
418         rc = handler->set(handler, dentry, name, value, size, flags);
419 #  else
420         rc = handler->set(dentry, name, value, size, flags, handler->flags);
421 #  endif /* !HAVE_XATTR_HANDLER_INODE_PARAM */
422         return rc;
423 }
424 #endif /* HAVE_VFS_SETXATTR */
425
426 #ifdef HAVE_IOP_SET_ACL
427 #ifdef CONFIG_FS_POSIX_ACL
428 #ifndef HAVE_POSIX_ACL_UPDATE_MODE
429 static inline int posix_acl_update_mode(struct inode *inode, umode_t *mode_p,
430                           struct posix_acl **acl)
431 {
432         umode_t mode = inode->i_mode;
433         int error;
434
435         error = posix_acl_equiv_mode(*acl, &mode);
436         if (error < 0)
437                 return error;
438         if (error == 0)
439                 *acl = NULL;
440         if (!in_group_p(inode->i_gid) &&
441             !capable_wrt_inode_uidgid(inode, CAP_FSETID))
442                 mode &= ~S_ISGID;
443         *mode_p = mode;
444         return 0;
445 }
446 #endif /* HAVE_POSIX_ACL_UPDATE_MODE */
447 #endif
448 #endif
449
450 #ifndef HAVE_IOV_ITER_TRUNCATE
451 static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
452 {
453         if (i->count > count)
454                 i->count = count;
455 }
456 #endif
457
458 #ifndef HAVE_IS_SXID
459 static inline bool is_sxid(umode_t mode)
460 {
461         return (mode & S_ISUID) || ((mode & S_ISGID) && (mode & S_IXGRP));
462 }
463 #endif
464
465 #ifndef IS_NOSEC
466 #define IS_NOSEC(inode) (!is_sxid(inode->i_mode))
467 #endif
468
469 /*
470  * mount MS_* flags split from superblock SB_* flags
471  * if the SB_* flags are not available use the MS_* flags
472  */
473 #if !defined(SB_RDONLY) && defined(MS_RDONLY)
474 # define SB_RDONLY MS_RDONLY
475 #endif
476 #if !defined(SB_ACTIVE) && defined(MS_ACTIVE)
477 # define SB_ACTIVE MS_ACTIVE
478 #endif
479 #if !defined(SB_NOSEC) && defined(MS_NOSEC)
480 # define SB_NOSEC MS_NOSEC
481 #endif
482 #if !defined(SB_POSIXACL) && defined(MS_POSIXACL)
483 # define SB_POSIXACL MS_POSIXACL
484 #endif
485 #if !defined(SB_NODIRATIME) && defined(MS_NODIRATIME)
486 # define SB_NODIRATIME MS_NODIRATIME
487 #endif
488
489 #ifndef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
490 static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
491 {
492         i->count = count;
493 }
494
495 static inline struct iovec iov_iter_iovec(const struct iov_iter *iter)
496 {
497         return (struct iovec) {
498                 .iov_base = iter->iov->iov_base + iter->iov_offset,
499                 .iov_len = min(iter->count,
500                                iter->iov->iov_len - iter->iov_offset),
501         };
502 }
503
504 #define iov_for_each(iov, iter, start)                                  \
505         for (iter = (start);                                            \
506              (iter).count && ((iov = iov_iter_iovec(&(iter))), 1);      \
507              iov_iter_advance(&(iter), (iov).iov_len))
508
509 static inline ssize_t
510 generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
511 {
512         struct iovec iov;
513         struct iov_iter i;
514         ssize_t bytes = 0;
515
516         iov_for_each(iov, i, *iter) {
517                 ssize_t res;
518
519                 res = generic_file_aio_read(iocb, &iov, 1, iocb->ki_pos);
520                 if (res <= 0) {
521                         if (bytes == 0)
522                                 bytes = res;
523                         break;
524                 }
525
526                 bytes += res;
527                 if (res < iov.iov_len)
528                         break;
529         }
530
531         if (bytes > 0)
532                 iov_iter_advance(iter, bytes);
533         return bytes;
534 }
535
536 static inline ssize_t
537 __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
538 {
539         struct iovec iov;
540         struct iov_iter i;
541         ssize_t bytes = 0;
542
543         /* Since LLITE updates file size at the end of I/O in
544          * vvp_io_commit_write(), append write has to be done in atomic when
545          * there are multiple segments because otherwise each iteration to
546          * __generic_file_aio_write() will see original file size */
547         if (unlikely(iocb->ki_filp->f_flags & O_APPEND && iter->nr_segs > 1)) {
548                 struct iovec *iov_copy;
549                 int count = 0;
550
551                 OBD_ALLOC(iov_copy, sizeof(*iov_copy) * iter->nr_segs);
552                 if (!iov_copy)
553                         return -ENOMEM;
554
555                 iov_for_each(iov, i, *iter)
556                         iov_copy[count++] = iov;
557
558                 bytes = __generic_file_aio_write(iocb, iov_copy, count,
559                                                  &iocb->ki_pos);
560                 OBD_FREE(iov_copy, sizeof(*iov_copy) * iter->nr_segs);
561
562                 if (bytes > 0)
563                         iov_iter_advance(iter, bytes);
564                 return bytes;
565         }
566
567         iov_for_each(iov, i, *iter) {
568                 ssize_t res;
569
570                 res = __generic_file_aio_write(iocb, &iov, 1, &iocb->ki_pos);
571                 if (res <= 0) {
572                         if (bytes == 0)
573                                 bytes = res;
574                         break;
575                 }
576
577                 bytes += res;
578                 if (res < iov.iov_len)
579                         break;
580         }
581
582         if (bytes > 0)
583                 iov_iter_advance(iter, bytes);
584         return bytes;
585 }
586 #endif /* HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
587
588 static inline void __user *get_vmf_address(struct vm_fault *vmf)
589 {
590 #ifdef HAVE_VM_FAULT_ADDRESS
591         return (void __user *)vmf->address;
592 #else
593         return vmf->virtual_address;
594 #endif
595 }
596
597 #ifdef HAVE_VM_OPS_USE_VM_FAULT_ONLY
598 # define ll_filemap_fault(vma, vmf) filemap_fault(vmf)
599 #else
600 # define ll_filemap_fault(vma, vmf) filemap_fault(vma, vmf)
601 #endif
602
603 #ifndef HAVE_CURRENT_TIME
604 static inline struct timespec current_time(struct inode *inode)
605 {
606         return CURRENT_TIME;
607 }
608 #endif
609
610 #ifndef time_after32
611 /**
612  * time_after32 - compare two 32-bit relative times
613  * @a: the time which may be after @b
614  * @b: the time which may be before @a
615  *
616  * time_after32(a, b) returns true if the time @a is after time @b.
617  * time_before32(b, a) returns true if the time @b is before time @a.
618  *
619  * Similar to time_after(), compare two 32-bit timestamps for relative
620  * times.  This is useful for comparing 32-bit seconds values that can't
621  * be converted to 64-bit values (e.g. due to disk format or wire protocol
622  * issues) when it is known that the times are less than 68 years apart.
623  */
624 #define time_after32(a, b)     ((s32)((u32)(b) - (u32)(a)) < 0)
625 #define time_before32(b, a)    time_after32(a, b)
626
627 #endif
628
629 #ifndef __GFP_COLD
630 #define __GFP_COLD 0
631 #endif
632
633 #ifndef alloc_workqueue
634 #define alloc_workqueue(name, flags, max_active) create_workqueue(name)
635 #endif
636
637 #ifndef smp_store_mb
638 #define smp_store_mb(var, value)        set_mb(var, value)
639 #endif
640
641 #ifndef READ_ONCE
642 #define READ_ONCE ACCESS_ONCE
643 #endif
644
645 #if IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY)
646 static inline unsigned short blk_integrity_interval(struct blk_integrity *bi)
647 {
648 #ifdef HAVE_INTERVAL_EXP_BLK_INTEGRITY
649         return bi->interval_exp ? 1 << bi->interval_exp : 0;
650 #elif defined(HAVE_INTERVAL_BLK_INTEGRITY)
651         return bi->interval;
652 #else
653         return bi->sector_size;
654 #endif /* !HAVE_INTERVAL_EXP_BLK_INTEGRITY */
655 }
656
657 static inline const char *blk_integrity_name(struct blk_integrity *bi)
658 {
659 #ifdef HAVE_INTERVAL_EXP_BLK_INTEGRITY
660         return bi->profile->name;
661 #else
662         return bi->name;
663 #endif
664 }
665
666 static inline unsigned int bip_size(struct bio_integrity_payload *bip)
667 {
668 #ifdef HAVE_BIP_ITER_BIO_INTEGRITY_PAYLOAD
669         return bip->bip_iter.bi_size;
670 #else
671         return bip->bip_size;
672 #endif
673 }
674 #else /* !CONFIG_BLK_DEV_INTEGRITY */
675 static inline unsigned short blk_integrity_interval(struct blk_integrity *bi)
676 {
677         return 0;
678 }
679 static inline const char *blk_integrity_name(struct blk_integrity *bi)
680 {
681         /* gcc8 dislikes when strcmp() is called against NULL */
682         return "";
683 }
684 #endif /* !CONFIG_BLK_DEV_INTEGRITY */
685
686 #ifndef INTEGRITY_FLAG_READ
687 #define INTEGRITY_FLAG_READ BLK_INTEGRITY_VERIFY
688 #endif
689
690 #ifndef INTEGRITY_FLAG_WRITE
691 #define INTEGRITY_FLAG_WRITE BLK_INTEGRITY_GENERATE
692 #endif
693
694 static inline bool bdev_integrity_enabled(struct block_device *bdev, int rw)
695 {
696 #if IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY)
697         struct blk_integrity *bi = bdev_get_integrity(bdev);
698
699         if (bi == NULL)
700                 return false;
701
702 #ifdef HAVE_INTERVAL_EXP_BLK_INTEGRITY
703         if (rw == 0 && bi->profile->verify_fn != NULL &&
704             (bi->flags & INTEGRITY_FLAG_READ))
705                 return true;
706
707         if (rw == 1 && bi->profile->generate_fn != NULL &&
708             (bi->flags & INTEGRITY_FLAG_WRITE))
709                 return true;
710 #else
711         if (rw == 0 && bi->verify_fn != NULL &&
712             (bi->flags & INTEGRITY_FLAG_READ))
713                 return true;
714
715         if (rw == 1 && bi->generate_fn != NULL &&
716             (bi->flags & INTEGRITY_FLAG_WRITE))
717                 return true;
718 #endif /* !HAVE_INTERVAL_EXP_BLK_INTEGRITY */
719 #endif /* !CONFIG_BLK_DEV_INTEGRITY */
720
721         return false;
722 }
723
724 #ifdef HAVE_PAGEVEC_INIT_ONE_PARAM
725 #define ll_pagevec_init(pvec, n) pagevec_init(pvec)
726 #else
727 #define ll_pagevec_init(pvec, n) pagevec_init(pvec, n)
728 #endif
729
730 #ifdef HAVE_I_PAGES
731 #define page_tree i_pages
732 #else
733 #define i_pages tree_lock
734 #define xa_lock_irq(lockp) spin_lock_irq(lockp)
735 #define xa_unlock_irq(lockp) spin_unlock_irq(lockp)
736 #endif
737
738 #ifndef KMEM_CACHE_USERCOPY
739 #define kmem_cache_create_usercopy(name, size, align, flags, useroffset, \
740                                    usersize, ctor)                       \
741         kmem_cache_create(name, size, align, flags, ctor)
742 #endif
743
744 #endif /* _LUSTRE_COMPAT_H */