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