Whamcloud - gitweb
447dc436640ad4e77db95c7d9f7836305125febc
[fs/lustre-release.git] / lustre / llite / rw26.c
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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/lustre/llite/rw26.c
37  *
38  * Lustre Lite I/O page cache routines for the 2.5/2.6 kernel version
39  */
40
41 #include <linux/kernel.h>
42 #include <linux/mm.h>
43 #include <linux/string.h>
44 #include <linux/stat.h>
45 #include <linux/errno.h>
46 #include <linux/unistd.h>
47 #include <asm/uaccess.h>
48
49 #ifdef HAVE_MIGRATE_H
50 #include <linux/migrate.h>
51 #elif defined(HAVE_MIGRATE_MODE_H)
52 #include <linux/migrate_mode.h>
53 #endif
54 #include <linux/fs.h>
55 #include <linux/buffer_head.h>
56 #include <linux/mpage.h>
57 #include <linux/writeback.h>
58 #include <linux/stat.h>
59 #include <asm/uaccess.h>
60 #include <linux/mm.h>
61 #include <linux/pagemap.h>
62
63 #define DEBUG_SUBSYSTEM S_LLITE
64
65 #include <lustre_lite.h>
66 #include "llite_internal.h"
67 #include <linux/lustre_compat25.h>
68
69 /**
70  * Implements Linux VM address_space::invalidatepage() method. This method is
71  * called when the page is truncate from a file, either as a result of
72  * explicit truncate, or when inode is removed from memory (as a result of
73  * final iput(), umount, or memory pressure induced icache shrinking).
74  *
75  * [0, offset] bytes of the page remain valid (this is for a case of not-page
76  * aligned truncate). Lustre leaves partially truncated page in the cache,
77  * relying on struct inode::i_size to limit further accesses.
78  */
79 static void ll_invalidatepage(struct page *vmpage, unsigned long offset)
80 {
81         struct inode     *inode;
82         struct lu_env    *env;
83         struct cl_page   *page;
84         struct cl_object *obj;
85
86         int refcheck;
87
88         LASSERT(PageLocked(vmpage));
89         LASSERT(!PageWriteback(vmpage));
90
91         /*
92          * It is safe to not check anything in invalidatepage/releasepage
93          * below because they are run with page locked and all our io is
94          * happening with locked page too
95          */
96         if (offset == 0) {
97                 env = cl_env_get(&refcheck);
98                 if (!IS_ERR(env)) {
99                         inode = vmpage->mapping->host;
100                         obj = ll_i2info(inode)->lli_clob;
101                         if (obj != NULL) {
102                                 page = cl_vmpage_page(vmpage, obj);
103                                 if (page != NULL) {
104                                         cl_page_delete(env, page);
105                                         cl_page_put(env, page);
106                                 }
107                         } else
108                                 LASSERT(vmpage->private == 0);
109                         cl_env_put(env, &refcheck);
110                 }
111         }
112 }
113
114 #ifdef HAVE_RELEASEPAGE_WITH_INT
115 #define RELEASEPAGE_ARG_TYPE int
116 #else
117 #define RELEASEPAGE_ARG_TYPE gfp_t
118 #endif
119 static int ll_releasepage(struct page *vmpage, RELEASEPAGE_ARG_TYPE gfp_mask)
120 {
121         struct lu_env           *env;
122         void                    *cookie;
123         struct cl_object        *obj;
124         struct cl_page          *page;
125         struct address_space    *mapping;
126         int result = 0;
127
128         LASSERT(PageLocked(vmpage));
129         if (PageWriteback(vmpage) || PageDirty(vmpage))
130                 return 0;
131
132         mapping = vmpage->mapping;
133         if (mapping == NULL)
134                 return 1;
135
136         obj = ll_i2info(mapping->host)->lli_clob;
137         if (obj == NULL)
138                 return 1;
139
140         /* 1 for caller, 1 for cl_page and 1 for page cache */
141         if (page_count(vmpage) > 3)
142                 return 0;
143
144         page = cl_vmpage_page(vmpage, obj);
145         if (page == NULL)
146                 return 1;
147
148         cookie = cl_env_reenter();
149         env = cl_env_percpu_get();
150         LASSERT(!IS_ERR(env));
151
152         if (!cl_page_in_use(page)) {
153                 result = 1;
154                 cl_page_delete(env, page);
155         }
156
157         /* To use percpu env array, the call path can not be rescheduled;
158          * otherwise percpu array will be messed if ll_releaspage() called
159          * again on the same CPU.
160          *
161          * If this page holds the last refc of cl_object, the following
162          * call path may cause reschedule:
163          *   cl_page_put -> cl_page_free -> cl_object_put ->
164          *     lu_object_put -> lu_object_free -> lov_delete_raid0 ->
165          *     cl_locks_prune.
166          *
167          * However, the kernel can't get rid of this inode until all pages have
168          * been cleaned up. Now that we hold page lock here, it's pretty safe
169          * that we won't get into object delete path.
170          */
171         LASSERT(cl_object_refc(obj) > 1);
172         cl_page_put(env, page);
173
174         cl_env_percpu_put(env);
175         cl_env_reexit(cookie);
176         return result;
177 }
178
179 #define MAX_DIRECTIO_SIZE 2*1024*1024*1024UL
180
181 static inline int ll_get_user_pages(int rw, unsigned long user_addr,
182                                     size_t size, struct page ***pages,
183                                     int *max_pages)
184 {
185         int result = -ENOMEM;
186
187         /* set an arbitrary limit to prevent arithmetic overflow */
188         if (size > MAX_DIRECTIO_SIZE) {
189                 *pages = NULL;
190                 return -EFBIG;
191         }
192
193         *max_pages = (user_addr + size + PAGE_CACHE_SIZE - 1) >>
194                      PAGE_CACHE_SHIFT;
195         *max_pages -= user_addr >> PAGE_CACHE_SHIFT;
196
197         OBD_ALLOC_LARGE(*pages, *max_pages * sizeof(**pages));
198         if (*pages) {
199                 down_read(&current->mm->mmap_sem);
200                 result = get_user_pages(current, current->mm, user_addr,
201                                         *max_pages, (rw == READ), 0, *pages,
202                                         NULL);
203                 up_read(&current->mm->mmap_sem);
204                 if (unlikely(result <= 0))
205                         OBD_FREE_LARGE(*pages, *max_pages * sizeof(**pages));
206         }
207
208         return result;
209 }
210
211 /*  ll_free_user_pages - tear down page struct array
212  *  @pages: array of page struct pointers underlying target buffer */
213 static void ll_free_user_pages(struct page **pages, int npages, int do_dirty)
214 {
215         int i;
216
217         for (i = 0; i < npages; i++) {
218                 if (pages[i] == NULL)
219                         break;
220                 if (do_dirty)
221                         set_page_dirty_lock(pages[i]);
222                 page_cache_release(pages[i]);
223         }
224
225         OBD_FREE_LARGE(pages, npages * sizeof(*pages));
226 }
227
228 ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io,
229                            int rw, struct inode *inode,
230                            struct ll_dio_pages *pv)
231 {
232         struct cl_page    *clp;
233         struct cl_2queue  *queue;
234         struct cl_object  *obj = io->ci_obj;
235         int i;
236         ssize_t rc = 0;
237         loff_t file_offset  = pv->ldp_start_offset;
238         long size           = pv->ldp_size;
239         int page_count      = pv->ldp_nr;
240         struct page **pages = pv->ldp_pages;
241         long page_size      = cl_page_size(obj);
242         bool do_io;
243         int  io_pages       = 0;
244         ENTRY;
245
246         queue = &io->ci_queue;
247         cl_2queue_init(queue);
248         for (i = 0; i < page_count; i++) {
249                 if (pv->ldp_offsets)
250                     file_offset = pv->ldp_offsets[i];
251
252                 LASSERT(!(file_offset & (page_size - 1)));
253                 clp = cl_page_find(env, obj, cl_index(obj, file_offset),
254                                    pv->ldp_pages[i], CPT_TRANSIENT);
255                 if (IS_ERR(clp)) {
256                         rc = PTR_ERR(clp);
257                         break;
258                 }
259
260                 rc = cl_page_own(env, io, clp);
261                 if (rc) {
262                         LASSERT(clp->cp_state == CPS_FREEING);
263                         cl_page_put(env, clp);
264                         break;
265                 }
266
267                 do_io = true;
268
269                 /* check the page type: if the page is a host page, then do
270                  * write directly */
271                 if (clp->cp_type == CPT_CACHEABLE) {
272                         struct page *vmpage = cl_page_vmpage(clp);
273                         struct page *src_page;
274                         struct page *dst_page;
275                         void       *src;
276                         void       *dst;
277
278                         src_page = (rw == WRITE) ? pages[i] : vmpage;
279                         dst_page = (rw == WRITE) ? vmpage : pages[i];
280
281                         src = ll_kmap_atomic(src_page, KM_USER0);
282                         dst = ll_kmap_atomic(dst_page, KM_USER1);
283                         memcpy(dst, src, min(page_size, size));
284                         ll_kunmap_atomic(dst, KM_USER1);
285                         ll_kunmap_atomic(src, KM_USER0);
286
287                         /* make sure page will be added to the transfer by
288                          * cl_io_submit()->...->vvp_page_prep_write(). */
289                         if (rw == WRITE)
290                                 set_page_dirty(vmpage);
291
292                         if (rw == READ) {
293                                 /* do not issue the page for read, since it
294                                  * may reread a ra page which has NOT uptodate
295                                  * bit set. */
296                                 cl_page_disown(env, io, clp);
297                                 do_io = false;
298                         }
299                 }
300
301                 if (likely(do_io)) {
302                         cl_2queue_add(queue, clp);
303
304                         /*
305                          * Set page clip to tell transfer formation engine
306                          * that page has to be sent even if it is beyond KMS.
307                          */
308                         cl_page_clip(env, clp, 0, min(size, page_size));
309
310                         ++io_pages;
311                 }
312
313                 /* drop the reference count for cl_page_find */
314                 cl_page_put(env, clp);
315                 size -= page_size;
316                 file_offset += page_size;
317         }
318
319         if (rc == 0 && io_pages) {
320                 rc = cl_io_submit_sync(env, io,
321                                        rw == READ ? CRT_READ : CRT_WRITE,
322                                        queue, 0);
323         }
324         if (rc == 0)
325                 rc = pv->ldp_size;
326
327         cl_2queue_discard(env, io, queue);
328         cl_2queue_disown(env, io, queue);
329         cl_2queue_fini(env, queue);
330         RETURN(rc);
331 }
332 EXPORT_SYMBOL(ll_direct_rw_pages);
333
334 static ssize_t ll_direct_IO_26_seg(const struct lu_env *env, struct cl_io *io,
335                                    int rw, struct inode *inode,
336                                    struct address_space *mapping,
337                                    size_t size, loff_t file_offset,
338                                    struct page **pages, int page_count)
339 {
340     struct ll_dio_pages pvec = { .ldp_pages        = pages,
341                                  .ldp_nr           = page_count,
342                                  .ldp_size         = size,
343                                  .ldp_offsets      = NULL,
344                                  .ldp_start_offset = file_offset
345                                };
346
347     return ll_direct_rw_pages(env, io, rw, inode, &pvec);
348 }
349
350 #ifdef KMALLOC_MAX_SIZE
351 #define MAX_MALLOC KMALLOC_MAX_SIZE
352 #else
353 #define MAX_MALLOC (128 * 1024)
354 #endif
355
356 /* This is the maximum size of a single O_DIRECT request, based on the
357  * kmalloc limit.  We need to fit all of the brw_page structs, each one
358  * representing PAGE_SIZE worth of user data, into a single buffer, and
359  * then truncate this to be a full-sized RPC.  For 4kB PAGE_SIZE this is
360  * up to 22MB for 128kB kmalloc and up to 682MB for 4MB kmalloc. */
361 #define MAX_DIO_SIZE ((MAX_MALLOC / sizeof(struct brw_page) * PAGE_CACHE_SIZE) & \
362                       ~(DT_MAX_BRW_SIZE - 1))
363 static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
364                                const struct iovec *iov, loff_t file_offset,
365                                unsigned long nr_segs)
366 {
367         struct lu_env *env;
368         struct cl_io *io;
369         struct file *file = iocb->ki_filp;
370         struct inode *inode = file->f_mapping->host;
371         struct ccc_object *obj = cl_inode2ccc(inode);
372         long count = iov_length(iov, nr_segs);
373         long tot_bytes = 0, result = 0;
374         struct ll_inode_info *lli = ll_i2info(inode);
375         unsigned long seg = 0;
376         long size = MAX_DIO_SIZE;
377         int refcheck;
378         ENTRY;
379
380         if (!lli->lli_has_smd)
381                 RETURN(-EBADF);
382
383         /* FIXME: io smaller than PAGE_SIZE is broken on ia64 ??? */
384         if ((file_offset & ~CFS_PAGE_MASK) || (count & ~CFS_PAGE_MASK))
385                 RETURN(-EINVAL);
386
387         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), size=%lu (max %lu), "
388                "offset=%lld=%llx, pages %lu (max %lu)\n",
389                PFID(ll_inode2fid(inode)), inode, count, MAX_DIO_SIZE,
390                file_offset, file_offset, count >> PAGE_CACHE_SHIFT,
391                MAX_DIO_SIZE >> PAGE_CACHE_SHIFT);
392
393         /* Check that all user buffers are aligned as well */
394         for (seg = 0; seg < nr_segs; seg++) {
395                 if (((unsigned long)iov[seg].iov_base & ~CFS_PAGE_MASK) ||
396                     (iov[seg].iov_len & ~CFS_PAGE_MASK))
397                         RETURN(-EINVAL);
398         }
399
400         env = cl_env_get(&refcheck);
401         LASSERT(!IS_ERR(env));
402         io = ccc_env_io(env)->cui_cl.cis_io;
403         LASSERT(io != NULL);
404
405         /* 0. Need locking between buffered and direct access. and race with
406          *    size changing by concurrent truncates and writes.
407          * 1. Need inode mutex to operate transient pages.
408          */
409         if (rw == READ)
410                 mutex_lock(&inode->i_mutex);
411
412         LASSERT(obj->cob_transient_pages == 0);
413         for (seg = 0; seg < nr_segs; seg++) {
414                 long iov_left = iov[seg].iov_len;
415                 unsigned long user_addr = (unsigned long)iov[seg].iov_base;
416
417                 if (rw == READ) {
418                         if (file_offset >= i_size_read(inode))
419                                 break;
420                         if (file_offset + iov_left > i_size_read(inode))
421                                 iov_left = i_size_read(inode) - file_offset;
422                 }
423
424                 while (iov_left > 0) {
425                         struct page **pages;
426                         int page_count, max_pages = 0;
427                         long bytes;
428
429                         bytes = min(size, iov_left);
430                         page_count = ll_get_user_pages(rw, user_addr, bytes,
431                                                        &pages, &max_pages);
432                         if (likely(page_count > 0)) {
433                                 if (unlikely(page_count <  max_pages))
434                                         bytes = page_count << PAGE_CACHE_SHIFT;
435                                 result = ll_direct_IO_26_seg(env, io, rw, inode,
436                                                              file->f_mapping,
437                                                              bytes, file_offset,
438                                                              pages, page_count);
439                                 ll_free_user_pages(pages, max_pages, rw==READ);
440                         } else if (page_count == 0) {
441                                 GOTO(out, result = -EFAULT);
442                         } else {
443                                 result = page_count;
444                         }
445                         if (unlikely(result <= 0)) {
446                                 /* If we can't allocate a large enough buffer
447                                  * for the request, shrink it to a smaller
448                                  * PAGE_SIZE multiple and try again.
449                                  * We should always be able to kmalloc for a
450                                  * page worth of page pointers = 4MB on i386. */
451                                 if (result == -ENOMEM &&
452                                     size > (PAGE_CACHE_SIZE / sizeof(*pages)) *
453                                            PAGE_CACHE_SIZE) {
454                                         size = ((((size / 2) - 1) |
455                                                  ~CFS_PAGE_MASK) + 1) &
456                                                 CFS_PAGE_MASK;
457                                         CDEBUG(D_VFSTRACE,"DIO size now %lu\n",
458                                                size);
459                                         continue;
460                                 }
461
462                                 GOTO(out, result);
463                         }
464
465                         tot_bytes += result;
466                         file_offset += result;
467                         iov_left -= result;
468                         user_addr += result;
469                 }
470         }
471 out:
472         LASSERT(obj->cob_transient_pages == 0);
473         if (rw == READ)
474                 mutex_unlock(&inode->i_mutex);
475
476         if (tot_bytes > 0) {
477                 struct ccc_io *cio = ccc_env_io(env);
478
479                 /* no commit async for direct IO */
480                 cio->u.write.cui_written += tot_bytes;
481         }
482
483         cl_env_put(env, &refcheck);
484         RETURN(tot_bytes ? tot_bytes : result);
485 }
486
487 /**
488  * Prepare partially written-to page for a write.
489  */
490 static int ll_prepare_partial_page(const struct lu_env *env, struct cl_io *io,
491                                    struct cl_page *pg)
492 {
493         struct cl_attr *attr   = ccc_env_thread_attr(env);
494         struct cl_object *obj  = io->ci_obj;
495         struct ccc_page *cp    = cl_object_page_slice(obj, pg);
496         loff_t          offset = cl_offset(obj, ccc_index(cp));
497         int             result;
498
499         cl_object_attr_lock(obj);
500         result = cl_object_attr_get(env, obj, attr);
501         cl_object_attr_unlock(obj);
502         if (result == 0) {
503                 /*
504                  * If are writing to a new page, no need to read old data.
505                  * The extent locking will have updated the KMS, and for our
506                  * purposes here we can treat it like i_size.
507                  */
508                 if (attr->cat_kms <= offset) {
509                         char *kaddr = ll_kmap_atomic(cp->cpg_page, KM_USER0);
510
511                         memset(kaddr, 0, cl_page_size(obj));
512                         ll_kunmap_atomic(kaddr, KM_USER0);
513                 } else if (cp->cpg_defer_uptodate)
514                         cp->cpg_ra_used = 1;
515                 else
516                         result = ll_page_sync_io(env, io, pg, CRT_READ);
517         }
518         return result;
519 }
520
521 static int ll_write_begin(struct file *file, struct address_space *mapping,
522                           loff_t pos, unsigned len, unsigned flags,
523                           struct page **pagep, void **fsdata)
524 {
525         struct ll_cl_context *lcc;
526         struct lu_env  *env;
527         struct cl_io   *io;
528         struct cl_page *page;
529
530         struct cl_object *clob = ll_i2info(mapping->host)->lli_clob;
531         pgoff_t index = pos >> PAGE_CACHE_SHIFT;
532         struct page *vmpage = NULL;
533         unsigned from = pos & (PAGE_CACHE_SIZE - 1);
534         unsigned to = from + len;
535         int result = 0;
536         ENTRY;
537
538         CDEBUG(D_VFSTRACE, "Writing %lu of %d to %d bytes\n", index, from, len);
539
540         lcc = ll_cl_init(file, NULL);
541         if (IS_ERR(lcc))
542                 GOTO(out, result = PTR_ERR(lcc));
543
544         env = lcc->lcc_env;
545         io  = lcc->lcc_io;
546
547         /* To avoid deadlock, try to lock page first. */
548         vmpage = grab_cache_page_nowait(mapping, index);
549         if (unlikely(vmpage == NULL ||
550                      PageDirty(vmpage) || PageWriteback(vmpage))) {
551                 struct ccc_io *cio = ccc_env_io(env);
552                 struct cl_page_list *plist = &cio->u.write.cui_queue;
553
554                 /* if the page is already in dirty cache, we have to commit
555                  * the pages right now; otherwise, it may cause deadlock
556                  * because it holds page lock of a dirty page and request for
557                  * more grants. It's okay for the dirty page to be the first
558                  * one in commit page list, though. */
559                 if (vmpage != NULL && plist->pl_nr > 0) {
560                         unlock_page(vmpage);
561                         page_cache_release(vmpage);
562                         vmpage = NULL;
563                 }
564
565                 /* commit pages and then wait for page lock */
566                 result = vvp_io_write_commit(env, io);
567                 if (result < 0)
568                         GOTO(out, result);
569
570                 if (vmpage == NULL) {
571                         vmpage = grab_cache_page_write_begin(mapping, index,
572                                                              flags);
573                         if (vmpage == NULL)
574                                 GOTO(out, result = -ENOMEM);
575                 }
576         }
577
578         page = cl_page_find(env, clob, vmpage->index, vmpage, CPT_CACHEABLE);
579         if (IS_ERR(page))
580                 GOTO(out, result = PTR_ERR(page));
581
582         lcc->lcc_page = page;
583         lu_ref_add(&page->cp_reference, "cl_io", io);
584
585         cl_page_assume(env, io, page);
586         if (!PageUptodate(vmpage)) {
587                 /*
588                  * We're completely overwriting an existing page,
589                  * so _don't_ set it up to date until commit_write
590                  */
591                 if (from == 0 && to == PAGE_SIZE) {
592                         CL_PAGE_HEADER(D_PAGE, env, page, "full page write\n");
593                         POISON_PAGE(vmpage, 0x11);
594                 } else {
595                         /* TODO: can be optimized at OSC layer to check if it
596                          * is a lockless IO. In that case, it's not necessary
597                          * to read the data. */
598                         result = ll_prepare_partial_page(env, io, page);
599                         if (result == 0)
600                                 SetPageUptodate(vmpage);
601                 }
602         }
603         if (result < 0)
604                 cl_page_unassume(env, io, page);
605         EXIT;
606 out:
607         if (result < 0) {
608                 if (vmpage != NULL) {
609                         unlock_page(vmpage);
610                         page_cache_release(vmpage);
611                 }
612                 if (!IS_ERR(lcc))
613                         ll_cl_fini(lcc);
614         } else {
615                 *pagep = vmpage;
616                 *fsdata = lcc;
617         }
618         RETURN(result);
619 }
620
621 static int ll_write_end(struct file *file, struct address_space *mapping,
622                         loff_t pos, unsigned len, unsigned copied,
623                         struct page *vmpage, void *fsdata)
624 {
625         struct ll_cl_context *lcc = fsdata;
626         struct lu_env *env;
627         struct cl_io *io;
628         struct ccc_io *cio;
629         struct cl_page *page;
630         unsigned from = pos & (PAGE_CACHE_SIZE - 1);
631         bool unplug = false;
632         int result = 0;
633         ENTRY;
634
635         page_cache_release(vmpage);
636
637         LASSERT(lcc != NULL);
638         env  = lcc->lcc_env;
639         page = lcc->lcc_page;
640         io   = lcc->lcc_io;
641         cio  = ccc_env_io(env);
642
643         LASSERT(cl_page_is_owned(page, io));
644         if (copied > 0) {
645                 struct cl_page_list *plist = &cio->u.write.cui_queue;
646
647                 lcc->lcc_page = NULL; /* page will be queued */
648
649                 /* Add it into write queue */
650                 cl_page_list_add(plist, page);
651                 if (plist->pl_nr == 1) /* first page */
652                         cio->u.write.cui_from = from;
653                 else
654                         LASSERT(from == 0);
655                 cio->u.write.cui_to = from + copied;
656
657                 /* We may have one full RPC, commit it soon */
658                 if (plist->pl_nr >= PTLRPC_MAX_BRW_PAGES)
659                         unplug = true;
660
661                 CL_PAGE_DEBUG(D_VFSTRACE, env, page,
662                               "queued page: %d.\n", plist->pl_nr);
663         } else {
664                 cl_page_disown(env, io, page);
665
666                 /* page list is not contiguous now, commit it now */
667                 unplug = true;
668         }
669
670         if (unplug ||
671             file->f_flags & O_SYNC || IS_SYNC(file->f_dentry->d_inode))
672                 result = vvp_io_write_commit(env, io);
673
674         ll_cl_fini(lcc);
675         RETURN(result >= 0 ? copied : result);
676 }
677
678 #ifdef CONFIG_MIGRATION
679 int ll_migratepage(struct address_space *mapping,
680                 struct page *newpage, struct page *page
681 #ifdef HAVE_MIGRATEPAGE_4ARGS
682                 , enum migrate_mode mode
683 #endif
684                 )
685 {
686         /* Always fail page migration until we have a proper implementation */
687         return -EIO;
688 }
689 #endif
690
691 #ifndef MS_HAS_NEW_AOPS
692 struct address_space_operations ll_aops = {
693         .readpage       = ll_readpage,
694 //        .readpages      = ll_readpages,
695         .direct_IO      = ll_direct_IO_26,
696         .writepage      = ll_writepage,
697         .writepages     = ll_writepages,
698         .set_page_dirty = __set_page_dirty_nobuffers,
699         .write_begin    = ll_write_begin,
700         .write_end      = ll_write_end,
701         .invalidatepage = ll_invalidatepage,
702         .releasepage    = (void *)ll_releasepage,
703 #ifdef CONFIG_MIGRATION
704         .migratepage    = ll_migratepage,
705 #endif
706         .bmap           = NULL
707 };
708 #else
709 struct address_space_operations_ext ll_aops = {
710         .orig_aops.readpage             = ll_readpage,
711         .orig_aops.direct_IO            = ll_direct_IO_26,
712         .orig_aops.writepage            = ll_writepage,
713         .orig_aops.writepages           = ll_writepages,
714         .orig_aops.set_page_dirty       = __set_page_dirty_nobuffers,
715         .orig_aops.invalidatepage       = ll_invalidatepage,
716         .orig_aops.releasepage          = ll_releasepage,
717 #ifdef CONFIG_MIGRATION
718         .orig_aops.migratepage          = ll_migratepage,
719 #endif
720         .orig_aops.bmap                 = NULL,
721         .write_begin                    = ll_write_begin,
722         .write_end                      = ll_write_end
723 };
724 #endif