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