Whamcloud - gitweb
LU-9859 libcfs: delete libcfs/linux/libcfs.h
[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
44 #include <libcfs/linux/linux-fs.h>
45 #include <lustre_patchless_compat.h>
46 #include <obd_support.h>
47
48 #ifdef HAVE_FS_STRUCT_RWLOCK
49 # define LOCK_FS_STRUCT(fs)     write_lock(&(fs)->lock)
50 # define UNLOCK_FS_STRUCT(fs)   write_unlock(&(fs)->lock)
51 #else
52 # define LOCK_FS_STRUCT(fs)     spin_lock(&(fs)->lock)
53 # define UNLOCK_FS_STRUCT(fs)   spin_unlock(&(fs)->lock)
54 #endif
55
56 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
57                                  struct dentry *dentry)
58 {
59         struct path path;
60         struct path old_pwd;
61
62         path.mnt = mnt;
63         path.dentry = dentry;
64         LOCK_FS_STRUCT(fs);
65         old_pwd = fs->pwd;
66         path_get(&path);
67         fs->pwd = path;
68         UNLOCK_FS_STRUCT(fs);
69
70         if (old_pwd.dentry)
71                 path_put(&old_pwd);
72 }
73
74 /*
75  * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
76  * ATTR_* attributes (see bug 13828)
77  */
78 #define ATTR_BLOCKS    (1 << 27)
79
80 #define current_ngroups current_cred()->group_info->ngroups
81 #define current_groups current_cred()->group_info->small_block
82
83 /*
84  * OBD need working random driver, thus all our
85  * initialization routines must be called after device
86  * driver initialization
87  */
88 #ifndef MODULE
89 #undef module_init
90 #define module_init(a)     late_initcall(a)
91 #endif
92
93 #ifndef MODULE_ALIAS_FS
94 #define MODULE_ALIAS_FS(name)
95 #endif
96
97 #define LTIME_S(time)                   (time.tv_sec)
98
99 #ifdef HAVE_GENERIC_PERMISSION_2ARGS
100 # define ll_generic_permission(inode, mask, flags, check_acl) \
101          generic_permission(inode, mask)
102 #elif defined HAVE_GENERIC_PERMISSION_4ARGS
103 # define ll_generic_permission(inode, mask, flags, check_acl) \
104          generic_permission(inode, mask, flags, check_acl)
105 #else
106 # define ll_generic_permission(inode, mask, flags, check_acl) \
107          generic_permission(inode, mask, check_acl)
108 #endif
109
110 #ifdef HAVE_4ARGS_VFS_SYMLINK
111 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
112                 vfs_symlink(dir, dentry, path, mode)
113 #else
114 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
115                        vfs_symlink(dir, dentry, path)
116 #endif
117
118 #if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
119 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
120                 generic_file_llseek_size(file, offset, origin, maxbytes, eof);
121 #else
122 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
123                 generic_file_llseek_size(file, offset, origin, maxbytes);
124 #endif
125
126 #ifdef HAVE_INODE_DIO_WAIT
127 /* inode_dio_wait(i) use as-is for write lock */
128 # define inode_dio_write_done(i)        do {} while (0) /* for write unlock */
129 #else
130 # define inode_dio_wait(i)              down_write(&(i)->i_alloc_sem)
131 # define inode_dio_write_done(i)        up_write(&(i)->i_alloc_sem)
132 #endif
133
134 #ifndef FS_HAS_FIEMAP
135 #define FS_HAS_FIEMAP                   (0)
136 #endif
137
138 #ifndef HAVE_SIMPLE_SETATTR
139 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
140 #endif
141
142 #ifndef SLAB_DESTROY_BY_RCU
143 #define SLAB_DESTROY_BY_RCU 0
144 #endif
145
146 #ifndef HAVE_DQUOT_SUSPEND
147 # define ll_vfs_dq_init             vfs_dq_init
148 # define ll_vfs_dq_drop             vfs_dq_drop
149 # define ll_vfs_dq_transfer         vfs_dq_transfer
150 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
151 #else
152 # define ll_vfs_dq_init             dquot_initialize
153 # define ll_vfs_dq_drop             dquot_drop
154 # define ll_vfs_dq_transfer         dquot_transfer
155 # define ll_vfs_dq_off(sb, remount) dquot_suspend(sb, -1)
156 #endif
157
158 #ifndef HAVE_BLKDEV_GET_BY_DEV
159 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
160 #endif
161
162 #ifdef HAVE_BVEC_ITER
163 #define bio_idx(bio)                    (bio->bi_iter.bi_idx)
164 #define bio_set_sector(bio, sector)     (bio->bi_iter.bi_sector = sector)
165 #define bvl_to_page(bvl)                (bvl->bv_page)
166 #else
167 #define bio_idx(bio)                    (bio->bi_idx)
168 #define bio_set_sector(bio, sector)     (bio->bi_sector = sector)
169 #define bio_sectors(bio)                ((bio)->bi_size >> 9)
170 #ifndef HAVE_BIO_END_SECTOR
171 #define bio_end_sector(bio)             (bio->bi_sector + bio_sectors(bio))
172 #endif
173 #define bvl_to_page(bvl)                (bvl->bv_page)
174 #endif
175
176 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
177 #define blk_queue_max_segments(rq, seg)                      \
178         do { blk_queue_max_phys_segments(rq, seg);           \
179              blk_queue_max_hw_segments(rq, seg); } while (0)
180 #else
181 #define queue_max_phys_segments(rq)       queue_max_segments(rq)
182 #define queue_max_hw_segments(rq)         queue_max_segments(rq)
183 #endif
184
185 #ifdef HAVE_BLK_PLUG
186 #define DECLARE_PLUG(plug)      struct blk_plug plug
187 #else /* !HAVE_BLK_PLUG */
188 #define DECLARE_PLUG(name)
189 #define blk_start_plug(plug)    do {} while (0)
190 #define blk_finish_plug(plug)   do {} while (0)
191 #endif
192
193 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
194 #define ll_kmap_atomic(a, b)    kmap_atomic(a)
195 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a)
196 #else
197 #define ll_kmap_atomic(a, b)    kmap_atomic(a, b)
198 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a, b)
199 #endif
200
201 #ifndef HAVE_CLEAR_INODE
202 #define clear_inode(i)          end_writeback(i)
203 #endif
204
205 #ifndef HAVE_DENTRY_D_CHILD
206 #define d_child                 d_u.d_child
207 #endif
208
209 #ifdef HAVE_DENTRY_D_U_D_ALIAS
210 #define d_alias                 d_u.d_alias
211 #endif
212
213 #ifndef DATA_FOR_LLITE_IS_LIST
214 #define ll_d_hlist_node hlist_node
215 #define ll_d_hlist_empty(list) hlist_empty(list)
216 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
217 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
218 # ifdef HAVE_HLIST_FOR_EACH_3ARG
219 # define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
220         p = NULL; hlist_for_each_entry(dentry, i_dentry, d_alias)
221 # else
222 # define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
223         hlist_for_each_entry(dentry, p, i_dentry, d_alias)
224 # endif
225 #define DECLARE_LL_D_HLIST_NODE_PTR(name) struct ll_d_hlist_node *name
226 #else
227 #define ll_d_hlist_node list_head
228 #define ll_d_hlist_empty(list) list_empty(list)
229 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
230 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
231 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
232         list_for_each_entry(dentry, i_dentry, d_alias)
233 #define DECLARE_LL_D_HLIST_NODE_PTR(name) /* nothing */
234 #endif /* !DATA_FOR_LLITE_IS_LIST */
235
236 #ifndef QUOTA_OK
237 # define QUOTA_OK 0
238 #endif
239 #ifndef NO_QUOTA
240 # define NO_QUOTA (-EDQUOT)
241 #endif
242
243 #ifndef SEEK_DATA
244 #define SEEK_DATA      3       /* seek to the next data */
245 #endif
246 #ifndef SEEK_HOLE
247 #define SEEK_HOLE      4       /* seek to the next hole */
248 #endif
249
250 #ifndef FMODE_UNSIGNED_OFFSET
251 #define FMODE_UNSIGNED_OFFSET   ((__force fmode_t)0x2000)
252 #endif
253
254 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
255 # define ext2_set_bit             __test_and_set_bit_le
256 # define ext2_clear_bit           __test_and_clear_bit_le
257 # define ext2_test_bit            test_bit_le
258 # define ext2_find_first_zero_bit find_first_zero_bit_le
259 # define ext2_find_next_zero_bit  find_next_zero_bit_le
260 #endif
261
262 #ifdef ATTR_TIMES_SET
263 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
264 #else
265 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
266 #endif
267
268 #ifndef XATTR_NAME_POSIX_ACL_ACCESS
269 # define XATTR_NAME_POSIX_ACL_ACCESS POSIX_ACL_XATTR_ACCESS
270 #endif
271
272 #ifndef XATTR_NAME_POSIX_ACL_DEFAULT
273 # define XATTR_NAME_POSIX_ACL_DEFAULT POSIX_ACL_XATTR_DEFAULT
274 #endif
275
276 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
277 # define lm_compare_owner       fl_compare_owner
278 #endif
279
280 /*
281  * After 3.1, kernel's nameidata.intent.open.flags is different
282  * with lustre's lookup_intent.it_flags, as lustre's it_flags'
283  * lower bits equal to FMODE_xxx while kernel doesn't transliterate
284  * lower bits of nameidata.intent.open.flags to FMODE_xxx.
285  * */
286 #include <linux/version.h>
287 static inline int ll_namei_to_lookup_intent_flag(int flag)
288 {
289 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
290         flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
291 #endif
292         return flag;
293 }
294
295 #include <linux/fs.h>
296 #ifndef HAVE_PROTECT_I_NLINK
297 static inline void set_nlink(struct inode *inode, unsigned int nlink)
298 {
299         inode->i_nlink = nlink;
300 }
301 #endif
302
303 #ifdef HAVE_INODEOPS_USE_UMODE_T
304 # define ll_umode_t     umode_t
305 #else
306 # define ll_umode_t     int
307 #endif
308
309 #include <linux/dcache.h>
310 #ifndef HAVE_D_MAKE_ROOT
311 static inline struct dentry *d_make_root(struct inode *root)
312 {
313         struct dentry *res = d_alloc_root(root);
314
315         if (res == NULL && root)
316                 iput(root);
317
318         return res;
319 }
320 #endif
321
322 #ifdef HAVE_DIRTY_INODE_HAS_FLAG
323 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode), flag)
324 #else
325 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode))
326 #endif
327
328 #ifdef HAVE_FILE_F_INODE
329 # define set_file_inode(file, inode)    (file)->f_inode = inode
330 #else
331 # define set_file_inode(file, inode)
332 #endif
333
334 #ifndef HAVE_FILE_INODE
335 static inline struct inode *file_inode(const struct file *file)
336 {
337         return file->f_path.dentry->d_inode;
338 }
339 #endif
340
341 #ifdef HAVE_OLDSIZE_TRUNCATE_PAGECACHE
342 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, 0, size)
343 #else
344 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, size)
345 #endif
346
347 #ifdef HAVE_VFS_RENAME_5ARGS
348 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL)
349 #elif defined HAVE_VFS_RENAME_6ARGS
350 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL, 0)
351 #else
352 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d)
353 #endif
354
355 #ifdef HAVE_VFS_UNLINK_3ARGS
356 #define ll_vfs_unlink(a, b) vfs_unlink(a, b, NULL)
357 #else
358 #define ll_vfs_unlink(a, b) vfs_unlink(a, b)
359 #endif
360
361 #ifndef HAVE_INODE_LOCK
362 # define inode_lock(inode) mutex_lock(&(inode)->i_mutex)
363 # define inode_unlock(inode) mutex_unlock(&(inode)->i_mutex)
364 # define inode_trylock(inode) mutex_trylock(&(inode)->i_mutex)
365 #endif
366
367 #ifndef HAVE_RADIX_EXCEPTION_ENTRY
368 static inline int radix_tree_exceptional_entry(void *arg)
369 {
370         return 0;
371 }
372 #endif
373
374 #ifndef HAVE_TRUNCATE_INODE_PAGES_FINAL
375 static inline void truncate_inode_pages_final(struct address_space *map)
376 {
377         truncate_inode_pages(map, 0);
378                 /* Workaround for LU-118 */
379         if (map->nrpages) {
380                 spin_lock_irq(&map->tree_lock);
381                 spin_unlock_irq(&map->tree_lock);
382         }       /* Workaround end */
383 }
384 #endif
385
386 #ifndef SIZE_MAX
387 #define SIZE_MAX        (~(size_t)0)
388 #endif
389
390 #ifdef HAVE_SECURITY_IINITSEC_CALLBACK
391 # define ll_security_inode_init_security(inode, dir, name, value, len, \
392                                          initxattrs, dentry)           \
393          security_inode_init_security(inode, dir, &((dentry)->d_name), \
394                                       initxattrs, dentry)
395 #elif defined HAVE_SECURITY_IINITSEC_QSTR
396 # define ll_security_inode_init_security(inode, dir, name, value, len, \
397                                          initxattrs, dentry)           \
398          security_inode_init_security(inode, dir, &((dentry)->d_name), \
399                                       name, value, len)
400 #else /* !HAVE_SECURITY_IINITSEC_CALLBACK && !HAVE_SECURITY_IINITSEC_QSTR */
401 # define ll_security_inode_init_security(inode, dir, name, value, len, \
402                                          initxattrs, dentry)           \
403          security_inode_init_security(inode, dir, name, value, len)
404 #endif
405
406 #ifndef bio_for_each_segment_all /* since kernel version 3.9 */
407 #ifdef HAVE_BVEC_ITER
408 #define bio_for_each_segment_all(bv, bio, it) \
409         for (it = 0, bv = (bio)->bi_io_vec; it < (bio)->bi_vcnt; it++, bv++)
410 #else
411 #define bio_for_each_segment_all(bv, bio, it) bio_for_each_segment(bv, bio, it)
412 #endif
413 #endif
414
415 #ifdef HAVE_PID_NS_FOR_CHILDREN
416 # define ll_task_pid_ns(task)   ((task)->nsproxy->pid_ns_for_children)
417 #else
418 # define ll_task_pid_ns(task)   ((task)->nsproxy->pid_ns)
419 #endif
420
421 #ifdef HAVE_FULL_NAME_HASH_3ARGS
422 # define ll_full_name_hash(salt, name, len) full_name_hash(salt, name, len)
423 #else
424 # define ll_full_name_hash(salt, name, len) full_name_hash(name, len)
425 #endif
426
427 #ifdef HAVE_STRUCT_POSIX_ACL_XATTR
428 # define posix_acl_xattr_header struct posix_acl_xattr_header
429 # define posix_acl_xattr_entry  struct posix_acl_xattr_entry
430 # define GET_POSIX_ACL_XATTR_ENTRY(head) ((void *)((head) + 1))
431 #else
432 # define GET_POSIX_ACL_XATTR_ENTRY(head) ((head)->a_entries)
433 #endif
434
435 #ifdef HAVE_IOP_XATTR
436 #ifdef HAVE_XATTR_HANDLER_FLAGS
437 #define ll_setxattr     generic_setxattr
438 #define ll_getxattr     generic_getxattr
439 #define ll_removexattr  generic_removexattr
440 #else
441 int ll_setxattr(struct dentry *dentry, const char *name,
442                 const void *value, size_t size, int flags);
443 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
444                     void *buf, size_t buf_size);
445 int ll_removexattr(struct dentry *dentry, const char *name);
446 #endif /* ! HAVE_XATTR_HANDLER_FLAGS */
447 #endif /* HAVE_IOP_XATTR */
448
449 #ifndef HAVE_VFS_SETXATTR
450 const struct xattr_handler *get_xattr_type(const char *name);
451
452 #ifdef HAVE_XATTR_HANDLER_FLAGS
453 static inline int
454 __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
455                const void *value, size_t size, int flags)
456 {
457         const struct xattr_handler *handler;
458         int rc;
459
460         handler = get_xattr_type(name);
461         if (!handler)
462                 return -ENXIO;
463
464 #if defined(HAVE_XATTR_HANDLER_INODE_PARAM)
465         rc = handler->set(handler, dentry, inode, name, value, size,
466                           XATTR_CREATE);
467 #elif defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
468         rc = handler->set(handler, dentry, name, value, size, XATTR_CREATE);
469 #else
470         rc = handler->set(dentry, name, value, size, XATTR_CREATE,
471                           handler->flags);
472 #endif /* !HAVE_XATTR_HANDLER_INODE_PARAM */
473         return rc;
474 }
475 #else /* !HAVE_XATTR_HANDLER_FLAGS */
476 static inline int
477 __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
478                const void *value, size_t size, int flags)
479 {
480         return ll_setxattr(dentry, name, value, size, flags);
481 }
482 #endif /* HAVE_XATTR_HANDLER_FLAGS */
483 #endif /* HAVE_VFS_SETXATTR */
484
485 #ifdef HAVE_IOP_SET_ACL
486 #ifdef CONFIG_FS_POSIX_ACL
487 #ifndef HAVE_POSIX_ACL_UPDATE_MODE
488 static inline int posix_acl_update_mode(struct inode *inode, umode_t *mode_p,
489                           struct posix_acl **acl)
490 {
491         umode_t mode = inode->i_mode;
492         int error;
493
494         error = posix_acl_equiv_mode(*acl, &mode);
495         if (error < 0)
496                 return error;
497         if (error == 0)
498                 *acl = NULL;
499         if (!in_group_p(inode->i_gid) &&
500             !capable_wrt_inode_uidgid(inode, CAP_FSETID))
501                 mode &= ~S_ISGID;
502         *mode_p = mode;
503         return 0;
504 }
505 #endif /* HAVE_POSIX_ACL_UPDATE_MODE */
506 #endif
507 #endif
508
509 #ifndef HAVE_IOV_ITER_TRUNCATE
510 static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
511 {
512         if (i->count > count)
513                 i->count = count;
514 }
515 #endif
516
517 #ifndef HAVE_IS_SXID
518 static inline bool is_sxid(umode_t mode)
519 {
520         return (mode & S_ISUID) || ((mode & S_ISGID) && (mode & S_IXGRP));
521 }
522 #endif
523
524 #ifndef IS_NOSEC
525 #define IS_NOSEC(inode) (!is_sxid(inode->i_mode))
526 #endif
527
528 #ifndef MS_NOSEC
529 static inline void inode_has_no_xattr(struct inode *inode)
530 {
531         return;
532 }
533 #endif
534
535 #ifndef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
536 static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
537 {
538         i->count = count;
539 }
540
541 static inline struct iovec iov_iter_iovec(const struct iov_iter *iter)
542 {
543         return (struct iovec) {
544                 .iov_base = iter->iov->iov_base + iter->iov_offset,
545                 .iov_len = min(iter->count,
546                                iter->iov->iov_len - iter->iov_offset),
547         };
548 }
549
550 #define iov_for_each(iov, iter, start)                                  \
551         for (iter = (start);                                            \
552              (iter).count && ((iov = iov_iter_iovec(&(iter))), 1);      \
553              iov_iter_advance(&(iter), (iov).iov_len))
554
555 static inline ssize_t
556 generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
557 {
558         struct iovec iov;
559         struct iov_iter i;
560         ssize_t bytes = 0;
561
562         iov_for_each(iov, i, *iter) {
563                 ssize_t res;
564
565                 res = generic_file_aio_read(iocb, &iov, 1, iocb->ki_pos);
566                 if (res <= 0) {
567                         if (bytes == 0)
568                                 bytes = res;
569                         break;
570                 }
571
572                 bytes += res;
573                 if (res < iov.iov_len)
574                         break;
575         }
576
577         if (bytes > 0)
578                 iov_iter_advance(iter, bytes);
579         return bytes;
580 }
581
582 static inline ssize_t
583 __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
584 {
585         struct iovec iov;
586         struct iov_iter i;
587         ssize_t bytes = 0;
588
589         /* Since LLITE updates file size at the end of I/O in
590          * vvp_io_commit_write(), append write has to be done in atomic when
591          * there are multiple segments because otherwise each iteration to
592          * __generic_file_aio_write() will see original file size */
593         if (unlikely(iocb->ki_filp->f_flags & O_APPEND && iter->nr_segs > 1)) {
594                 struct iovec *iov_copy;
595                 int count = 0;
596
597                 OBD_ALLOC(iov_copy, sizeof(*iov_copy) * iter->nr_segs);
598                 if (!iov_copy)
599                         return -ENOMEM;
600
601                 iov_for_each(iov, i, *iter)
602                         iov_copy[count++] = iov;
603
604                 bytes = __generic_file_aio_write(iocb, iov_copy, count,
605                                                  &iocb->ki_pos);
606                 OBD_FREE(iov_copy, sizeof(*iov_copy) * iter->nr_segs);
607
608                 if (bytes > 0)
609                         iov_iter_advance(iter, bytes);
610                 return bytes;
611         }
612
613         iov_for_each(iov, i, *iter) {
614                 ssize_t res;
615
616                 res = __generic_file_aio_write(iocb, &iov, 1, &iocb->ki_pos);
617                 if (res <= 0) {
618                         if (bytes == 0)
619                                 bytes = res;
620                         break;
621                 }
622
623                 bytes += res;
624                 if (res < iov.iov_len)
625                         break;
626         }
627
628         if (bytes > 0)
629                 iov_iter_advance(iter, bytes);
630         return bytes;
631 }
632 #endif /* HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
633
634 static inline void __user *get_vmf_address(struct vm_fault *vmf)
635 {
636 #ifdef HAVE_VM_FAULT_ADDRESS
637         return (void __user *)vmf->address;
638 #else
639         return vmf->virtual_address;
640 #endif
641 }
642
643 #ifdef HAVE_VM_OPS_USE_VM_FAULT_ONLY
644 # define ll_filemap_fault(vma, vmf) filemap_fault(vmf)
645 #else
646 # define ll_filemap_fault(vma, vmf) filemap_fault(vma, vmf)
647 #endif
648
649 #ifndef HAVE_CURRENT_TIME
650 static inline struct timespec current_time(struct inode *inode)
651 {
652         return CURRENT_TIME;
653 }
654 #endif
655
656 #ifndef time_after32
657 /**
658  * time_after32 - compare two 32-bit relative times
659  * @a: the time which may be after @b
660  * @b: the time which may be before @a
661  *
662  * time_after32(a, b) returns true if the time @a is after time @b.
663  * time_before32(b, a) returns true if the time @b is before time @a.
664  *
665  * Similar to time_after(), compare two 32-bit timestamps for relative
666  * times.  This is useful for comparing 32-bit seconds values that can't
667  * be converted to 64-bit values (e.g. due to disk format or wire protocol
668  * issues) when it is known that the times are less than 68 years apart.
669  */
670 #define time_after32(a, b)     ((s32)((u32)(b) - (u32)(a)) < 0)
671 #define time_before32(b, a)    time_after32(a, b)
672 #endif
673
674 #endif /* _LUSTRE_COMPAT_H */