4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/lustre/llite/rw26.c
33 * Lustre Lite I/O page cache routines for the 2.5/2.6 kernel version
36 #include <linux/buffer_head.h>
37 #include <linux/errno.h>
39 #include <linux/kernel.h>
41 #include <linux/mpage.h>
42 #include <linux/pagemap.h>
43 #include <linux/string.h>
44 #include <linux/unistd.h>
45 #include <linux/writeback.h>
46 #include <linux/migrate.h>
48 #define DEBUG_SUBSYSTEM S_LLITE
50 #include "llite_internal.h"
51 #include <lustre_compat.h>
53 #ifdef HAVE_INVALIDATE_FOLIO
55 * Implements Linux VM address_space::invalidate_folio() method. This method is
56 * called when the folio is truncated from a file, either as a result of
57 * explicit truncate, or when inode is removed from memory (as a result of
58 * final iput(), umount, or memory pressure induced icache shrinking).
60 * [0, off] bytes of the folio remain valid (this is for a case of non-page
61 * aligned truncate). Lustre leaves partially truncated folios in the cache,
62 * relying on struct inode::i_size to limit further accesses.
64 static void ll_invalidate_folio(struct folio *folio, size_t offset, size_t len)
69 struct cl_object *obj;
71 LASSERT(!folio_test_writeback(folio));
72 LASSERT(folio_test_locked(folio));
74 if (!(offset == 0 && len == folio_size(folio)) &&
75 !folio_test_large(folio))
78 /* Drop the pages from the folio */
79 env = cl_env_percpu_get();
80 LASSERT(!IS_ERR(env));
82 inode = folio_inode(folio);
83 obj = ll_i2info(inode)->lli_clob;
85 int n, npgs = folio_nr_pages(folio);
87 for (n = 0; n < npgs; n++) {
88 struct page *vmpage = folio_page(folio, n);
90 LASSERT(PageLocked(vmpage));
91 LASSERT(!PageWriteback(vmpage));
93 page = cl_vmpage_page(vmpage, obj);
95 cl_page_delete(env, page);
96 cl_page_put(env, page);
100 LASSERT(!folio_get_private(folio));
102 cl_env_percpu_put(env);
107 * Implements Linux VM address_space::invalidatepage() method. This method is
108 * called when the page is truncate from a file, either as a result of
109 * explicit truncate, or when inode is removed from memory (as a result of
110 * final iput(), umount, or memory pressure induced icache shrinking).
112 * [0, offset] bytes of the page remain valid (this is for a case of not-page
113 * aligned truncate). Lustre leaves partially truncated page in the cache,
114 * relying on struct inode::i_size to limit further accesses.
116 static void ll_invalidatepage(struct page *vmpage,
117 #ifdef HAVE_INVALIDATE_RANGE
118 unsigned int offset, unsigned int length
126 struct cl_page *page;
127 struct cl_object *obj;
129 LASSERT(PageLocked(vmpage));
130 LASSERT(!PageWriteback(vmpage));
133 * It is safe to not check anything in invalidatepage/releasepage
134 * below because they are run with page locked and all our io is
135 * happening with locked page too
137 #ifdef HAVE_INVALIDATE_RANGE
138 if (offset == 0 && length == PAGE_SIZE) {
142 /* See the comment in ll_releasepage() */
143 env = cl_env_percpu_get();
144 LASSERT(!IS_ERR(env));
146 inode = vmpage->mapping->host;
147 obj = ll_i2info(inode)->lli_clob;
149 page = cl_vmpage_page(vmpage, obj);
151 cl_page_delete(env, page);
152 cl_page_put(env, page);
155 LASSERT(vmpage->private == 0);
157 cl_env_percpu_put(env);
160 if (CFS_FAIL_PRECHECK(OBD_FAIL_LLITE_PAGE_INVALIDATE_PAUSE)) {
162 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_PAGE_INVALIDATE_PAUSE,
169 static bool do_release_page(struct page *vmpage, gfp_t wait)
171 struct address_space *mapping;
172 struct cl_object *obj;
173 struct cl_page *page;
179 LASSERT(PageLocked(vmpage));
180 if (PageWriteback(vmpage) || PageDirty(vmpage))
183 mapping = vmpage->mapping;
187 obj = ll_i2info(mapping->host)->lli_clob;
191 page = cl_vmpage_page(vmpage, obj);
195 env = cl_env_percpu_get();
196 LASSERT(!IS_ERR(env));
198 if (!cl_page_in_use(page)) {
200 cl_page_delete(env, page);
203 /* To use percpu env array, the call path can not be rescheduled;
204 * otherwise percpu array will be messed if ll_releaspage() called
205 * again on the same CPU.
207 * If this page holds the last refc of cl_object, the following
208 * call path may cause reschedule:
209 * cl_page_put -> cl_page_free -> cl_object_put ->
210 * lu_object_put -> lu_object_free -> lov_delete_raid0.
212 * However, the kernel can't get rid of this inode until all pages have
213 * been cleaned up. Now that we hold page lock here, it's pretty safe
214 * that we won't get into object delete path.
216 LASSERT(cl_object_refc(obj) > 1);
217 cl_page_put(env, page);
219 cl_env_percpu_put(env);
223 #ifdef HAVE_AOPS_RELEASE_FOLIO
224 static bool ll_release_folio(struct folio *folio, gfp_t wait)
226 struct page *vmpage = folio_page(folio, 0);
228 /* folio_nr_pages(folio) == 1 is fixed with grab_cache_page* */
229 BUG_ON(folio_nr_pages(folio) != 1);
231 return do_release_page(vmpage, wait);
233 #else /* !HAVE_AOPS_RELEASE_FOLIO */
234 #ifdef HAVE_RELEASEPAGE_WITH_INT
235 #define RELEASEPAGE_ARG_TYPE int
237 #define RELEASEPAGE_ARG_TYPE gfp_t
239 static int ll_releasepage(struct page *vmpage, RELEASEPAGE_ARG_TYPE gfp_mask)
241 return do_release_page(vmpage, gfp_mask);
243 #endif /* HAVE_AOPS_RELEASE_FOLIO */
245 static ssize_t ll_get_user_pages(int rw, struct iov_iter *iter,
246 struct ll_dio_pages *pvec,
249 #if defined(HAVE_DIO_ITER)
253 result = iov_iter_get_pages_alloc2(iter, &pvec->ldp_pages, maxsize,
256 pvec->ldp_count = DIV_ROUND_UP(result + start, PAGE_SIZE);
271 addr = (unsigned long)iter->iov->iov_base + iter->iov_offset;
272 if (addr & ~PAGE_MASK)
275 size = min_t(size_t, maxsize, iter->iov->iov_len);
276 page_count = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
277 OBD_ALLOC_PTR_ARRAY_LARGE(pvec->ldp_pages, page_count);
278 if (pvec->ldp_pages == NULL)
281 mmap_read_lock(current->mm);
282 result = get_user_pages(current, current->mm, addr, page_count,
283 rw == READ, 0, pvec->ldp_pages, NULL);
284 mmap_read_unlock(current->mm);
286 if (unlikely(result != page_count)) {
287 ll_release_user_pages(pvec->ldp_pages, page_count);
288 pvec->ldp_pages = NULL;
295 pvec->ldp_count = page_count;
301 /* iov_iter_alignment() is introduced in 3.16 similar to HAVE_DIO_ITER */
302 #if defined(HAVE_DIO_ITER)
303 static unsigned long iov_iter_alignment_vfs(const struct iov_iter *i)
305 return iov_iter_alignment(i);
307 #else /* copied from alignment_iovec() */
308 static unsigned long iov_iter_alignment_vfs(const struct iov_iter *i)
310 const struct iovec *iov = i->iov;
312 size_t size = i->count;
318 res = (unsigned long)iov->iov_base + i->iov_offset;
319 n = iov->iov_len - i->iov_offset;
325 while (size > (++iov)->iov_len) {
326 res |= (unsigned long)iov->iov_base | iov->iov_len;
327 size -= iov->iov_len;
329 res |= (unsigned long)iov->iov_base | size;
336 * Lustre could relax a bit for alignment, io count is not
337 * necessary page alignment.
339 static unsigned long ll_iov_iter_alignment(struct iov_iter *i)
341 size_t orig_size = i->count;
342 size_t count = orig_size & ~PAGE_MASK;
346 return iov_iter_alignment_vfs(i);
348 if (orig_size > PAGE_SIZE) {
349 iov_iter_truncate(i, orig_size - count);
350 res = iov_iter_alignment_vfs(i);
351 iov_iter_reexpand(i, orig_size);
356 res = iov_iter_alignment_vfs(i);
357 /* start address is page aligned */
358 if ((res & ~PAGE_MASK) == orig_size)
365 ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io, size_t size,
366 int rw, struct inode *inode, struct cl_sub_dio *sdio)
368 struct ll_dio_pages *pv = &sdio->csd_dio_pages;
369 struct cl_page *page;
370 struct cl_2queue *queue = &io->ci_queue;
371 struct cl_object *obj = io->ci_obj;
372 struct cl_sync_io *anchor = &sdio->csd_sync;
373 loff_t offset = pv->ldp_file_offset;
380 cl_2queue_init(queue);
381 for (i = 0; i < pv->ldp_count; i++) {
382 LASSERT(!(offset & (PAGE_SIZE - 1)));
383 page = cl_page_find(env, obj, offset >> PAGE_SHIFT,
384 pv->ldp_pages[i], CPT_TRANSIENT);
389 LASSERT(page->cp_type == CPT_TRANSIENT);
390 rc = cl_page_own(env, io, page);
392 cl_page_put(env, page);
396 page->cp_sync_io = anchor;
397 if (inode && IS_ENCRYPTED(inode)) {
398 /* In case of Direct IO on encrypted file, we need to
399 * add a reference to the inode on the cl_page.
400 * This info is required by llcrypt to proceed
401 * to encryption/decryption.
402 * This is safe because we know these pages are private
403 * to the thread doing the Direct IO.
405 page->cp_inode = inode;
407 /* We keep the refcount from cl_page_find, so we don't need
410 cl_page_list_add(&queue->c2_qin, page, false);
412 * Set page clip to tell transfer formation engine
413 * that page has to be sent even if it is beyond KMS.
415 if (size < PAGE_SIZE)
416 cl_page_clip(env, page, 0, size);
422 if (rc == 0 && io_pages > 0) {
423 int iot = rw == READ ? CRT_READ : CRT_WRITE;
425 atomic_add(io_pages, &anchor->csi_sync_nr);
427 * Avoid out-of-order execution of adding inflight
428 * modifications count and io submit.
431 rc = cl_io_submit_rw(env, io, iot, queue);
433 cl_page_list_splice(&queue->c2_qout, &sdio->csd_pages);
435 atomic_add(-queue->c2_qin.pl_nr,
436 &anchor->csi_sync_nr);
437 cl_page_list_for_each(page, &queue->c2_qin)
438 page->cp_sync_io = NULL;
440 /* handle partially submitted reqs */
441 if (queue->c2_qin.pl_nr > 0) {
442 CERROR(DFID " failed to submit %d dio pages: %zd\n",
443 PFID(lu_object_fid(&obj->co_lu)),
444 queue->c2_qin.pl_nr, rc);
450 cl_2queue_discard(env, io, queue);
451 cl_2queue_disown(env, queue);
452 cl_2queue_fini(env, queue);
456 #ifdef KMALLOC_MAX_SIZE
457 #define MAX_MALLOC KMALLOC_MAX_SIZE
459 #define MAX_MALLOC (128 * 1024)
462 /* This is the maximum size of a single O_DIRECT request, based on the
463 * kmalloc limit. We need to fit all of the brw_page structs, each one
464 * representing PAGE_SIZE worth of user data, into a single buffer, and
465 * then truncate this to be a full-sized RPC. For 4kB PAGE_SIZE this is
466 * up to 22MB for 128kB kmalloc and up to 682MB for 4MB kmalloc. */
467 #define MAX_DIO_SIZE ((MAX_MALLOC / sizeof(struct brw_page) * PAGE_SIZE) & \
468 ~((size_t)DT_MAX_BRW_SIZE - 1))
471 ll_direct_IO_impl(struct kiocb *iocb, struct iov_iter *iter, int rw)
473 struct ll_cl_context *lcc;
474 const struct lu_env *env;
476 struct file *file = iocb->ki_filp;
477 struct inode *inode = file->f_mapping->host;
478 struct cl_dio_aio *ll_dio_aio;
479 struct cl_sub_dio *sdio;
480 size_t count = iov_iter_count(iter);
481 ssize_t tot_bytes = 0, result = 0;
482 loff_t file_offset = iocb->ki_pos;
483 bool sync_submit = false;
487 /* Check EOF by ourselves */
488 if (rw == READ && file_offset >= i_size_read(inode))
491 /* FIXME: io smaller than PAGE_SIZE is broken on ia64 ??? */
492 if (file_offset & ~PAGE_MASK)
495 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), size=%zd (max %lu), "
496 "offset=%lld=%llx, pages %zd (max %lu)\n",
497 PFID(ll_inode2fid(inode)), inode, count, MAX_DIO_SIZE,
498 file_offset, file_offset, count >> PAGE_SHIFT,
499 MAX_DIO_SIZE >> PAGE_SHIFT);
501 /* Check that all user buffers are aligned as well */
502 if (ll_iov_iter_alignment(iter) & ~PAGE_MASK)
505 lcc = ll_cl_find(inode);
510 LASSERT(!IS_ERR(env));
511 vio = vvp_env_io(env);
515 ll_dio_aio = io->ci_dio_aio;
517 LASSERT(ll_dio_aio->cda_iocb == iocb);
519 /* We cannot do parallel submission of sub-I/Os - for AIO or regular
520 * DIO - unless lockless because it causes us to release the lock
523 * There are also several circumstances in which we must disable
524 * parallel DIO, so we check if it is enabled.
526 * The check for "is_sync_kiocb" excludes AIO, which does not need to
527 * be disabled in these situations.
529 if (io->ci_dio_lock || (is_sync_kiocb(iocb) && !io->ci_parallel_dio))
532 while (iov_iter_count(iter)) {
533 struct ll_dio_pages *pvec;
535 count = min_t(size_t, iov_iter_count(iter), MAX_DIO_SIZE);
537 if (file_offset >= i_size_read(inode))
540 if (file_offset + count > i_size_read(inode))
541 count = i_size_read(inode) - file_offset;
544 /* if we are doing sync_submit, then we free this below,
545 * otherwise it is freed on the final call to cl_sync_io_note
546 * (either in this function or from a ptlrpcd daemon)
548 sdio = cl_sub_dio_alloc(ll_dio_aio, iter, rw == WRITE,
551 GOTO(out, result = -ENOMEM);
553 pvec = &sdio->csd_dio_pages;
554 pvec->ldp_file_offset = file_offset;
556 result = ll_get_user_pages(rw, iter, pvec, count);
558 if (unlikely(result <= 0)) {
559 cl_sync_io_note(env, &sdio->csd_sync, result);
561 LASSERT(sdio->csd_creator_free);
562 cl_sub_dio_free(sdio);
568 result = ll_direct_rw_pages(env, io, count,
570 /* We've submitted pages and can now remove the extra
573 cl_sync_io_note(env, &sdio->csd_sync, result);
576 rc2 = cl_sync_io_wait(env, &sdio->csd_sync,
578 if (result == 0 && rc2)
580 LASSERT(sdio->csd_creator_free);
581 cl_sub_dio_free(sdio);
583 if (unlikely(result < 0))
586 iov_iter_advance(iter, count);
588 file_offset += count;
594 vio->u.readwrite.vui_written += tot_bytes;
596 vio->u.readwrite.vui_read += tot_bytes;
598 /* AIO is not supported on pipes, so we cannot return EIOCBQEUED like
599 * we normally would for both DIO and AIO here
601 if (result == 0 && !iov_iter_is_pipe(iter))
602 result = -EIOCBQUEUED;
607 #if defined(HAVE_DIO_ITER)
608 static ssize_t ll_direct_IO(
609 #ifndef HAVE_IOV_ITER_RW
612 struct kiocb *iocb, struct iov_iter *iter
613 #ifndef HAVE_DIRECTIO_2ARGS
620 #ifndef HAVE_IOV_ITER_RW
623 nrw = iov_iter_rw(iter);
626 return ll_direct_IO_impl(iocb, iter, nrw);
629 #else /* !defined(HAVE_DIO_ITER) */
632 ll_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
633 loff_t file_offset, unsigned long nr_segs)
635 struct iov_iter iter;
637 iov_iter_init(&iter, iov, nr_segs, iov_length(iov, nr_segs), 0);
638 return ll_direct_IO_impl(iocb, &iter, rw);
641 #endif /* !defined(HAVE_DIO_ITER) */
644 * Prepare partially written-to page for a write.
645 * @pg is owned when passed in and disowned when it returns non-zero result to
648 static int ll_prepare_partial_page(const struct lu_env *env, struct cl_io *io,
649 struct cl_page *pg, struct file *file)
651 struct cl_attr *attr = vvp_env_thread_attr(env);
652 struct cl_object *obj = io->ci_obj;
653 loff_t offset = cl_page_index(pg) << PAGE_SHIFT;
657 cl_object_attr_lock(obj);
658 result = cl_object_attr_get(env, obj, attr);
659 cl_object_attr_unlock(obj);
661 cl_page_disown(env, io, pg);
666 * If are writing to a new page, no need to read old data.
667 * The extent locking will have updated the KMS, and for our
668 * purposes here we can treat it like i_size.
670 if (attr->cat_kms <= offset) {
671 char *kaddr = kmap_atomic(pg->cp_vmpage);
673 memset(kaddr, 0, PAGE_SIZE);
674 kunmap_atomic(kaddr);
675 GOTO(out, result = 0);
678 if (pg->cp_defer_uptodate) {
680 GOTO(out, result = 0);
683 result = ll_io_read_page(env, io, pg, file);
687 /* ll_io_read_page() disowns the page */
688 result = cl_page_own(env, io, pg);
690 if (!PageUptodate(cl_page_vmpage(pg))) {
691 cl_page_disown(env, io, pg);
694 } else if (result == -ENOENT) {
695 /* page was truncated */
704 static int ll_tiny_write_begin(struct page *vmpage, struct address_space *mapping)
706 /* Page must be present, up to date, dirty, and not in writeback. */
707 if (!vmpage || !PageUptodate(vmpage) || !PageDirty(vmpage) ||
708 PageWriteback(vmpage) || vmpage->mapping != mapping)
714 static int ll_write_begin(struct file *file, struct address_space *mapping,
715 loff_t pos, unsigned int len,
716 #ifdef HAVE_GRAB_CACHE_PAGE_WRITE_BEGIN_WITH_FLAGS
719 struct page **pagep, void **fsdata)
721 struct ll_cl_context *lcc = NULL;
722 const struct lu_env *env = NULL;
723 struct cl_io *io = NULL;
724 struct cl_page *page = NULL;
725 struct inode *inode = file_inode(file);
726 struct cl_object *clob = ll_i2info(mapping->host)->lli_clob;
727 pgoff_t index = pos >> PAGE_SHIFT;
728 struct page *vmpage = NULL;
729 unsigned from = pos & (PAGE_SIZE - 1);
730 unsigned to = from + len;
734 CDEBUG(D_VFSTRACE, "Writing %lu of %d to %d bytes\n", index, from, len);
736 lcc = ll_cl_find(inode);
738 vmpage = grab_cache_page_nowait(mapping, index);
739 result = ll_tiny_write_begin(vmpage, mapping);
746 if (file->f_flags & O_DIRECT) {
747 /* direct IO failed because it couldn't clean up cached pages,
748 * this causes a problem for mirror write because the cached
749 * page may belong to another mirror, which will result in
750 * problem submitting the I/O. */
751 if (io->ci_designated_mirror > 0)
752 GOTO(out, result = -EBUSY);
755 * Direct write can fall back to buffered read, but DIO is done
756 * with lockless i/o, and buffered requires LDLM locking, so
757 * in this case we must restart without lockless.
759 if (!io->ci_dio_lock) {
761 io->ci_need_restart = 1;
762 GOTO(out, result = -ENOLCK);
766 /* To avoid deadlock, try to lock page first. */
767 vmpage = grab_cache_page_nowait(mapping, index);
769 if (unlikely(vmpage == NULL ||
770 PageDirty(vmpage) || PageWriteback(vmpage))) {
771 struct vvp_io *vio = vvp_env_io(env);
772 struct cl_page_list *plist = &vio->u.readwrite.vui_queue;
774 /* if the page is already in dirty cache, we have to commit
775 * the pages right now; otherwise, it may cause deadlock
776 * because it holds page lock of a dirty page and request for
777 * more grants. It's okay for the dirty page to be the first
778 * one in commit page list, though. */
779 if (vmpage != NULL && plist->pl_nr > 0) {
785 /* commit pages and then wait for page lock */
786 result = vvp_io_write_commit(env, io);
790 if (vmpage == NULL) {
791 vmpage = grab_cache_page_write_begin(mapping, index
792 #ifdef HAVE_GRAB_CACHE_PAGE_WRITE_BEGIN_WITH_FLAGS
797 GOTO(out, result = -ENOMEM);
801 /* page was truncated */
802 if (mapping != vmpage->mapping) {
803 CDEBUG(D_VFSTRACE, "page: %lu was truncated\n", index);
810 page = cl_page_find(env, clob, vmpage->index, vmpage, CPT_CACHEABLE);
812 GOTO(out, result = PTR_ERR(page));
814 lcc->lcc_page = page;
815 lu_ref_add(&page->cp_reference, "cl_io", io);
817 cl_page_assume(env, io, page);
818 if (!PageUptodate(vmpage)) {
820 * We're completely overwriting an existing page,
821 * so _don't_ set it up to date until commit_write
823 if (from == 0 && to == PAGE_SIZE) {
824 CL_PAGE_HEADER(D_PAGE, env, page, "full page write\n");
825 POISON_PAGE(vmpage, 0x11);
827 /* TODO: can be optimized at OSC layer to check if it
828 * is a lockless IO. In that case, it's not necessary
829 * to read the data. */
830 result = ll_prepare_partial_page(env, io, page, file);
832 /* vmpage should have been unlocked */
836 if (result == -EAGAIN)
845 if (vmpage != NULL) {
849 /* On tiny_write failure, page and io are always null. */
850 if (!IS_ERR_OR_NULL(page)) {
851 lu_ref_del(&page->cp_reference, "cl_io", io);
852 cl_page_put(env, page);
855 io->ci_result = result;
863 static int ll_tiny_write_end(struct file *file, struct address_space *mapping,
864 loff_t pos, unsigned int len, unsigned int copied,
867 struct cl_page *clpage = (struct cl_page *) vmpage->private;
868 loff_t kms = pos+copied;
869 loff_t to = kms & (PAGE_SIZE-1) ? kms & (PAGE_SIZE-1) : PAGE_SIZE;
871 struct lu_env *env = cl_env_get(&refcheck);
881 /* This page is dirty in cache, so it should have a cl_page pointer
882 * set in vmpage->private.
884 LASSERT(clpage != NULL);
889 /* Update the underlying size information in the OSC/LOV objects this
892 cl_page_touch(env, clpage, to);
895 cl_env_put(env, &refcheck);
898 /* Must return page unlocked. */
904 static int ll_write_end(struct file *file, struct address_space *mapping,
905 loff_t pos, unsigned len, unsigned copied,
906 struct page *vmpage, void *fsdata)
908 struct ll_cl_context *lcc = fsdata;
909 const struct lu_env *env;
912 struct cl_page *page;
913 unsigned from = pos & (PAGE_SIZE - 1);
920 CDEBUG(D_VFSTRACE, "pos %llu, len %u, copied %u\n", pos, len, copied);
923 result = ll_tiny_write_end(file, mapping, pos, len, copied,
928 LASSERT(lcc != NULL);
930 page = lcc->lcc_page;
932 vio = vvp_env_io(env);
934 LASSERT(cl_page_is_owned(page, io));
936 struct cl_page_list *plist = &vio->u.readwrite.vui_queue;
938 lcc->lcc_page = NULL; /* page will be queued */
940 /* Add it into write queue */
941 cl_page_list_add(plist, page, true);
942 if (plist->pl_nr == 1) /* first page */
943 vio->u.readwrite.vui_from = from;
946 vio->u.readwrite.vui_to = from + copied;
948 /* To address the deadlock in balance_dirty_pages() where
949 * this dirty page may be written back in the same thread. */
950 if (PageDirty(vmpage))
953 /* We may have one full RPC, commit it soon */
954 if (plist->pl_nr >= PTLRPC_MAX_BRW_PAGES)
957 CL_PAGE_DEBUG(D_VFSTRACE, env, page,
958 "queued page: %d.\n", plist->pl_nr);
960 cl_page_disown(env, io, page);
962 lcc->lcc_page = NULL;
963 lu_ref_del(&page->cp_reference, "cl_io", io);
964 cl_page_put(env, page);
966 /* page list is not contiguous now, commit it now */
969 if (unplug || io->u.ci_wr.wr_sync)
970 result = vvp_io_write_commit(env, io);
973 io->ci_result = result;
977 RETURN(result >= 0 ? copied : result);
980 #ifdef CONFIG_MIGRATION
981 static int ll_migrate_folio(struct address_space *mapping,
982 struct folio_migr *newpage, struct folio_migr *page,
983 enum migrate_mode mode)
985 /* Always fail page migration until we have a proper implementation */
990 const struct address_space_operations ll_aops = {
991 #ifdef HAVE_DIRTY_FOLIO
992 .dirty_folio = filemap_dirty_folio,
994 .set_page_dirty = __set_page_dirty_nobuffers,
996 #ifdef HAVE_INVALIDATE_FOLIO
997 .invalidate_folio = ll_invalidate_folio,
999 .invalidatepage = ll_invalidatepage,
1001 #ifdef HAVE_AOPS_READ_FOLIO
1002 .read_folio = ll_read_folio,
1004 .readpage = ll_readpage,
1006 #ifdef HAVE_AOPS_RELEASE_FOLIO
1007 .release_folio = ll_release_folio,
1009 .releasepage = (void *)ll_releasepage,
1011 .direct_IO = ll_direct_IO,
1012 .writepage = ll_writepage,
1013 .writepages = ll_writepages,
1014 .write_begin = ll_write_begin,
1015 .write_end = ll_write_end,
1016 #ifdef CONFIG_MIGRATION
1017 .migrate_folio = ll_migrate_folio,