4 * Copyright (C) 1994-1999 Linus Torvalds
8 * This file handles the generic file mmap semantics used by
9 * most "normal" filesystems (but you don't /have/ to use this:
10 * the NFS filesystem used to do this differently, for example)
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/compiler.h>
17 #include <linux/aio.h>
18 #include <linux/kernel_stat.h>
20 #include <linux/swap.h>
21 #include <linux/mman.h>
22 #include <linux/pagemap.h>
23 #include <linux/file.h>
24 #include <linux/uio.h>
25 #include <linux/hash.h>
26 #include <linux/writeback.h>
27 #include <linux/pagevec.h>
28 #include <linux/blkdev.h>
29 #include <linux/security.h>
31 * This is needed for the following functions:
32 * - try_to_release_page
33 * - block_invalidatepage
34 * - generic_osync_inode
36 * FIXME: remove all knowledge of the buffer layer from the core VM
38 #include <linux/buffer_head.h> /* for generic_osync_inode */
40 #include <asm/uaccess.h>
44 * Shared mappings implemented 30.11.1994. It's not fully working yet,
47 * Shared mappings now work. 15.8.1995 Bruno.
49 * finished 'unifying' the page and buffer cache and SMP-threaded the
50 * page-cache, 21.05.1999, Ingo Molnar <mingo@redhat.com>
52 * SMP-threaded pagemap-LRU 1999, Andrea Arcangeli <andrea@suse.de>
58 * ->i_mmap_lock (vmtruncate)
59 * ->private_lock (__free_pte->__set_page_dirty_buffers)
61 * ->swap_device_lock (exclusive_swap_page, others)
62 * ->mapping->tree_lock
65 * ->i_mmap_lock (truncate->unmap_mapping_range)
69 * ->page_table_lock (various places, mainly in mmap.c)
70 * ->mapping->tree_lock (arch-dependent flush_dcache_mmap_lock)
73 * ->lock_page (access_process_vm)
79 * ->i_alloc_sem (various)
82 * ->sb_lock (fs/fs-writeback.c)
83 * ->mapping->tree_lock (__sync_single_inode)
86 * ->swap_device_lock (try_to_unmap_one)
87 * ->private_lock (try_to_unmap_one)
88 * ->tree_lock (try_to_unmap_one)
89 * ->zone.lru_lock (follow_page->mark_page_accessed)
92 * ->dcache_lock (proc_pid_lookup)
96 * Remove a page from the page cache and free it. Caller has to make
97 * sure the page is locked and that nobody else uses it - or that usage
98 * is safe. The caller must hold a write_lock on the mapping's tree_lock.
100 void __remove_from_page_cache(struct page *page)
102 struct address_space *mapping = page->mapping;
104 radix_tree_delete(&mapping->page_tree, page->index);
105 page->mapping = NULL;
110 void remove_from_page_cache(struct page *page)
112 struct address_space *mapping = page->mapping;
114 if (unlikely(!PageLocked(page)))
117 spin_lock_irq(&mapping->tree_lock);
118 __remove_from_page_cache(page);
119 spin_unlock_irq(&mapping->tree_lock);
122 static inline int sync_page(struct page *page)
124 struct address_space *mapping;
127 * FIXME, fercrissake. What is this barrier here for?
130 mapping = page_mapping(page);
131 if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
132 return mapping->a_ops->sync_page(page);
137 * filemap_fdatawrite - start writeback against all of a mapping's dirty pages
138 * @mapping: address space structure to write
140 * If sync_mode is WB_SYNC_ALL then this is a "data integrity" operation, as
141 * opposed to a regular memory * cleansing writeback. The difference between
142 * these two operations is that if a dirty page/buffer is encountered, it must
143 * be waited upon, and not just skipped over.
145 static int __filemap_fdatawrite(struct address_space *mapping, int sync_mode)
148 struct writeback_control wbc = {
149 .sync_mode = sync_mode,
150 .nr_to_write = mapping->nrpages * 2,
153 if (mapping->backing_dev_info->memory_backed)
156 ret = do_writepages(mapping, &wbc);
160 int filemap_fdatawrite(struct address_space *mapping)
162 return __filemap_fdatawrite(mapping, WB_SYNC_ALL);
164 EXPORT_SYMBOL(filemap_fdatawrite);
167 * This is a mostly non-blocking flush. Not suitable for data-integrity
168 * purposes - I/O may not be started against all dirty pages.
170 int filemap_flush(struct address_space *mapping)
172 return __filemap_fdatawrite(mapping, WB_SYNC_NONE);
174 EXPORT_SYMBOL(filemap_flush);
177 * Wait for writeback to complete against pages indexed by start->end
180 static int wait_on_page_writeback_range(struct address_space *mapping,
181 pgoff_t start, pgoff_t end)
191 pagevec_init(&pvec, 0);
193 while ((nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
194 PAGECACHE_TAG_WRITEBACK,
195 min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
198 for (i = 0; i < nr_pages; i++) {
199 struct page *page = pvec.pages[i];
201 wait_on_page_writeback(page);
205 pagevec_release(&pvec);
209 /* Check for outstanding write errors */
210 if (test_and_clear_bit(AS_ENOSPC, &mapping->flags))
212 if (test_and_clear_bit(AS_EIO, &mapping->flags))
219 * filemap_fdatawait - walk the list of under-writeback pages of the given
220 * address space and wait for all of them.
222 * @mapping: address space structure to wait for
224 int filemap_fdatawait(struct address_space *mapping)
226 return wait_on_page_writeback_range(mapping, 0, -1);
229 EXPORT_SYMBOL(filemap_fdatawait);
231 int filemap_write_and_wait(struct address_space *mapping)
235 if (mapping->nrpages) {
236 retval = filemap_fdatawrite(mapping);
238 retval = filemap_fdatawait(mapping);
244 * This function is used to add newly allocated pagecache pages:
245 * the page is new, so we can just run SetPageLocked() against it.
246 * The other page state flags were set by rmqueue().
248 * This function does not add the page to the LRU. The caller must do that.
250 int add_to_page_cache(struct page *page, struct address_space *mapping,
251 pgoff_t offset, int gfp_mask)
253 int error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM);
256 spin_lock_irq(&mapping->tree_lock);
257 error = radix_tree_insert(&mapping->page_tree, offset, page);
259 page_cache_get(page);
261 page->mapping = mapping;
262 page->index = offset;
266 spin_unlock_irq(&mapping->tree_lock);
267 radix_tree_preload_end();
272 EXPORT_SYMBOL(add_to_page_cache);
274 int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
275 pgoff_t offset, int gfp_mask)
277 int ret = add_to_page_cache(page, mapping, offset, gfp_mask);
284 * In order to wait for pages to become available there must be
285 * waitqueues associated with pages. By using a hash table of
286 * waitqueues where the bucket discipline is to maintain all
287 * waiters on the same queue and wake all when any of the pages
288 * become available, and for the woken contexts to check to be
289 * sure the appropriate page became available, this saves space
290 * at a cost of "thundering herd" phenomena during rare hash
293 struct page_wait_queue {
299 static int page_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key)
301 struct page *page = key;
302 struct page_wait_queue *wq;
304 wq = container_of(wait, struct page_wait_queue, wait);
305 if (wq->page != page || test_bit(wq->bit, &page->flags))
308 return autoremove_wake_function(wait, mode, sync, NULL);
311 #define __DEFINE_PAGE_WAIT(name, p, b, f) \
312 struct page_wait_queue name = { \
317 .func = page_wake_function, \
319 .task_list = LIST_HEAD_INIT(name.wait.task_list),\
323 #define DEFINE_PAGE_WAIT(name, p, b) __DEFINE_PAGE_WAIT(name, p, b, 0)
324 #define DEFINE_PAGE_WAIT_EXCLUSIVE(name, p, b) \
325 __DEFINE_PAGE_WAIT(name, p, b, WQ_FLAG_EXCLUSIVE)
327 static wait_queue_head_t *page_waitqueue(struct page *page)
329 const struct zone *zone = page_zone(page);
331 return &zone->wait_table[hash_ptr(page, zone->wait_table_bits)];
334 static void wake_up_page(struct page *page)
336 const unsigned int mode = TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE;
337 wait_queue_head_t *waitqueue = page_waitqueue(page);
339 if (waitqueue_active(waitqueue))
340 __wake_up(waitqueue, mode, 1, page);
343 void fastcall wait_on_page_bit(struct page *page, int bit_nr)
345 wait_queue_head_t *waitqueue = page_waitqueue(page);
346 DEFINE_PAGE_WAIT(wait, page, bit_nr);
349 prepare_to_wait(waitqueue, &wait.wait, TASK_UNINTERRUPTIBLE);
350 if (test_bit(bit_nr, &page->flags)) {
354 } while (test_bit(bit_nr, &page->flags));
355 finish_wait(waitqueue, &wait.wait);
358 EXPORT_SYMBOL(wait_on_page_bit);
361 * unlock_page() - unlock a locked page
365 * Unlocks the page and wakes up sleepers in ___wait_on_page_locked().
366 * Also wakes sleepers in wait_on_page_writeback() because the wakeup
367 * mechananism between PageLocked pages and PageWriteback pages is shared.
368 * But that's OK - sleepers in wait_on_page_writeback() just go back to sleep.
370 * The first mb is necessary to safely close the critical section opened by the
371 * TestSetPageLocked(), the second mb is necessary to enforce ordering between
372 * the clear_bit and the read of the waitqueue (to avoid SMP races with a
373 * parallel wait_on_page_locked()).
375 void fastcall unlock_page(struct page *page)
377 smp_mb__before_clear_bit();
378 if (!TestClearPageLocked(page))
380 smp_mb__after_clear_bit();
384 EXPORT_SYMBOL(unlock_page);
385 EXPORT_SYMBOL(lock_page);
388 * End writeback against a page.
390 void end_page_writeback(struct page *page)
392 if (!TestClearPageReclaim(page) || rotate_reclaimable_page(page)) {
393 if (!test_clear_page_writeback(page))
395 smp_mb__after_clear_bit();
400 EXPORT_SYMBOL(end_page_writeback);
403 * Get a lock on the page, assuming we need to sleep to get it.
405 * Ugly: running sync_page() in state TASK_UNINTERRUPTIBLE is scary. If some
406 * random driver's requestfn sets TASK_RUNNING, we could busywait. However
407 * chances are that on the second loop, the block layer's plug list is empty,
408 * so sync_page() will then return in state TASK_UNINTERRUPTIBLE.
410 void fastcall __lock_page(struct page *page)
412 wait_queue_head_t *wqh = page_waitqueue(page);
413 DEFINE_PAGE_WAIT_EXCLUSIVE(wait, page, PG_locked);
415 while (TestSetPageLocked(page)) {
416 prepare_to_wait_exclusive(wqh, &wait.wait, TASK_UNINTERRUPTIBLE);
417 if (PageLocked(page)) {
422 finish_wait(wqh, &wait.wait);
425 EXPORT_SYMBOL(__lock_page);
428 * a rather lightweight function, finding and getting a reference to a
429 * hashed page atomically.
431 struct page * find_get_page(struct address_space *mapping, unsigned long offset)
436 * We scan the hash list read-only. Addition to and removal from
437 * the hash-list needs a held write-lock.
439 spin_lock_irq(&mapping->tree_lock);
440 page = radix_tree_lookup(&mapping->page_tree, offset);
442 page_cache_get(page);
443 spin_unlock_irq(&mapping->tree_lock);
447 EXPORT_SYMBOL(find_get_page);
450 * Same as above, but trylock it instead of incrementing the count.
452 struct page *find_trylock_page(struct address_space *mapping, unsigned long offset)
456 spin_lock_irq(&mapping->tree_lock);
457 page = radix_tree_lookup(&mapping->page_tree, offset);
458 if (page && TestSetPageLocked(page))
460 spin_unlock_irq(&mapping->tree_lock);
464 EXPORT_SYMBOL(find_trylock_page);
467 * find_lock_page - locate, pin and lock a pagecache page
469 * @mapping - the address_space to search
470 * @offset - the page index
472 * Locates the desired pagecache page, locks it, increments its reference
473 * count and returns its address.
475 * Returns zero if the page was not present. find_lock_page() may sleep.
477 struct page *find_lock_page(struct address_space *mapping,
478 unsigned long offset)
482 spin_lock_irq(&mapping->tree_lock);
484 page = radix_tree_lookup(&mapping->page_tree, offset);
486 page_cache_get(page);
487 if (TestSetPageLocked(page)) {
488 spin_unlock_irq(&mapping->tree_lock);
490 spin_lock_irq(&mapping->tree_lock);
492 /* Has the page been truncated while we slept? */
493 if (page->mapping != mapping || page->index != offset) {
495 page_cache_release(page);
500 spin_unlock_irq(&mapping->tree_lock);
504 EXPORT_SYMBOL(find_lock_page);
507 * find_or_create_page - locate or add a pagecache page
509 * @mapping - the page's address_space
510 * @index - the page's index into the mapping
511 * @gfp_mask - page allocation mode
513 * Locates a page in the pagecache. If the page is not present, a new page
514 * is allocated using @gfp_mask and is added to the pagecache and to the VM's
515 * LRU list. The returned page is locked and has its reference count
518 * find_or_create_page() may sleep, even if @gfp_flags specifies an atomic
521 * find_or_create_page() returns the desired page's address, or zero on
524 struct page *find_or_create_page(struct address_space *mapping,
525 unsigned long index, unsigned int gfp_mask)
527 struct page *page, *cached_page = NULL;
530 page = find_lock_page(mapping, index);
533 cached_page = alloc_page(gfp_mask);
537 err = add_to_page_cache_lru(cached_page, mapping,
542 } else if (err == -EEXIST)
546 page_cache_release(cached_page);
550 EXPORT_SYMBOL(find_or_create_page);
553 * find_get_pages - gang pagecache lookup
554 * @mapping: The address_space to search
555 * @start: The starting page index
556 * @nr_pages: The maximum number of pages
557 * @pages: Where the resulting pages are placed
559 * find_get_pages() will search for and return a group of up to
560 * @nr_pages pages in the mapping. The pages are placed at @pages.
561 * find_get_pages() takes a reference against the returned pages.
563 * The search returns a group of mapping-contiguous pages with ascending
564 * indexes. There may be holes in the indices due to not-present pages.
566 * find_get_pages() returns the number of pages which were found.
568 unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
569 unsigned int nr_pages, struct page **pages)
574 spin_lock_irq(&mapping->tree_lock);
575 ret = radix_tree_gang_lookup(&mapping->page_tree,
576 (void **)pages, start, nr_pages);
577 for (i = 0; i < ret; i++)
578 page_cache_get(pages[i]);
579 spin_unlock_irq(&mapping->tree_lock);
584 * Like find_get_pages, except we only return pages which are tagged with
585 * `tag'. We update *index to index the next page for the traversal.
587 unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
588 int tag, unsigned int nr_pages, struct page **pages)
593 spin_lock_irq(&mapping->tree_lock);
594 ret = radix_tree_gang_lookup_tag(&mapping->page_tree,
595 (void **)pages, *index, nr_pages, tag);
596 for (i = 0; i < ret; i++)
597 page_cache_get(pages[i]);
599 *index = pages[ret - 1]->index + 1;
600 spin_unlock_irq(&mapping->tree_lock);
605 * Same as grab_cache_page, but do not wait if the page is unavailable.
606 * This is intended for speculative data generators, where the data can
607 * be regenerated if the page couldn't be grabbed. This routine should
608 * be safe to call while holding the lock for another page.
610 * Clear __GFP_FS when allocating the page to avoid recursion into the fs
611 * and deadlock against the caller's locked page.
614 grab_cache_page_nowait(struct address_space *mapping, unsigned long index)
616 struct page *page = find_get_page(mapping, index);
620 if (!TestSetPageLocked(page))
622 page_cache_release(page);
625 gfp_mask = mapping_gfp_mask(mapping) & ~__GFP_FS;
626 page = alloc_pages(gfp_mask, 0);
627 if (page && add_to_page_cache_lru(page, mapping, index, gfp_mask)) {
628 page_cache_release(page);
634 EXPORT_SYMBOL(grab_cache_page_nowait);
637 * This is a generic file read routine, and uses the
638 * mapping->a_ops->readpage() function for the actual low-level
641 * This is really ugly. But the goto's actually try to clarify some
642 * of the logic when it comes to error handling etc.
643 * - note the struct file * is only passed for the use of readpage
645 void do_generic_mapping_read(struct address_space *mapping,
646 struct file_ra_state *_ra,
649 read_descriptor_t * desc,
653 struct inode *inode = mapping->host;
654 unsigned long index, end_index, offset;
656 struct page *cached_page;
658 struct file_ra_state ra = *_ra;
661 index = *ppos >> PAGE_CACHE_SHIFT;
662 offset = *ppos & ~PAGE_CACHE_MASK;
664 isize = i_size_read(inode);
665 end_index = isize >> PAGE_CACHE_SHIFT;
666 if (index > end_index)
671 unsigned long nr, ret;
674 page_cache_readahead(mapping, &ra, filp, index);
677 page = find_get_page(mapping, index);
678 if (unlikely(page == NULL)) {
680 desc->error = -EWOULDBLOCKIO;
683 handle_ra_miss(mapping, &ra, index);
686 if (!PageUptodate(page)) {
688 page_cache_release(page);
689 desc->error = -EWOULDBLOCKIO;
692 goto page_not_up_to_date;
695 /* nr is the maximum number of bytes to copy from this page */
696 nr = PAGE_CACHE_SIZE;
697 if (index == end_index) {
698 nr = isize & ~PAGE_CACHE_MASK;
700 page_cache_release(page);
706 /* If users can be writing to this page using arbitrary
707 * virtual addresses, take care about potential aliasing
708 * before reading the page on the kernel side.
710 if (mapping_writably_mapped(mapping))
711 flush_dcache_page(page);
714 * Mark the page accessed if we read the beginning.
717 mark_page_accessed(page);
720 * Ok, we have the page, and it's up-to-date, so
721 * now we can copy it to user space...
723 * The actor routine returns how many bytes were actually used..
724 * NOTE! This may not be the same as how much of a user buffer
725 * we filled up (we may be padding etc), so we can only update
726 * "pos" here (the actor routine has to update the user buffer
727 * pointers and the remaining count).
729 ret = actor(desc, page, offset, nr);
731 index += offset >> PAGE_CACHE_SHIFT;
732 offset &= ~PAGE_CACHE_MASK;
734 page_cache_release(page);
735 if (ret == nr && desc->count)
740 /* Get exclusive access to the page ... */
743 /* Did it get unhashed before we got the lock? */
744 if (!page->mapping) {
746 page_cache_release(page);
750 /* Did somebody else fill it already? */
751 if (PageUptodate(page)) {
757 /* Start the actual read. The read will unlock the page. */
758 error = mapping->a_ops->readpage(filp, page);
763 if (!PageUptodate(page)) {
764 wait_on_page_locked(page);
765 if (!PageUptodate(page)) {
772 * i_size must be checked after we have done ->readpage.
774 * Checking i_size after the readpage allows us to calculate
775 * the correct value for "nr", which means the zero-filled
776 * part of the page is not copied back to userspace (unless
777 * another truncate extends the file - this is desired though).
779 isize = i_size_read(inode);
780 end_index = isize >> PAGE_CACHE_SHIFT;
781 if (index > end_index) {
782 page_cache_release(page);
788 /* UHHUH! A synchronous read error occurred. Report it */
790 page_cache_release(page);
795 * Ok, it wasn't cached, so we need to create a new
799 cached_page = page_cache_alloc_cold(mapping);
801 desc->error = -ENOMEM;
805 error = add_to_page_cache_lru(cached_page, mapping,
808 if (error == -EEXIST)
821 *ppos = ((loff_t) index << PAGE_CACHE_SHIFT) + offset;
823 page_cache_release(cached_page);
827 EXPORT_SYMBOL(do_generic_mapping_read);
829 int file_read_actor(read_descriptor_t *desc, struct page *page,
830 unsigned long offset, unsigned long size)
833 unsigned long left, count = desc->count;
839 * Faults on the destination of a read are common, so do it before
842 if (!fault_in_pages_writeable(desc->buf, size)) {
843 kaddr = kmap_atomic(page, KM_USER0);
844 left = __copy_to_user(desc->buf, kaddr + offset, size);
845 kunmap_atomic(kaddr, KM_USER0);
850 /* Do it the slow way */
852 left = __copy_to_user(desc->buf, kaddr + offset, size);
857 desc->error = -EFAULT;
860 desc->count = count - size;
861 desc->written += size;
867 * This is the "read()" routine for all filesystems
868 * that can use the page cache directly.
871 __generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
872 unsigned long nr_segs, loff_t *ppos)
874 struct file *filp = iocb->ki_filp;
880 for (seg = 0; seg < nr_segs; seg++) {
881 const struct iovec *iv = &iov[seg];
884 * If any segment has a negative length, or the cumulative
885 * length ever wraps negative then return -EINVAL.
887 count += iv->iov_len;
888 if (unlikely((ssize_t)(count|iv->iov_len) < 0))
890 if (access_ok(VERIFY_WRITE, iv->iov_base, iv->iov_len))
895 count -= iv->iov_len; /* This segment is no good */
899 /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */
900 if (filp->f_flags & O_DIRECT) {
901 loff_t pos = *ppos, size;
902 struct address_space *mapping;
905 mapping = filp->f_mapping;
906 inode = mapping->host;
909 goto out; /* skip atime */
910 size = i_size_read(inode);
912 retval = generic_file_direct_IO(READ, iocb,
914 if (retval >= 0 && !is_sync_kiocb(iocb))
915 retval = -EIOCBQUEUED;
917 *ppos = pos + retval;
925 for (seg = 0; seg < nr_segs; seg++) {
926 read_descriptor_t desc;
929 desc.buf = iov[seg].iov_base;
930 desc.count = iov[seg].iov_len;
934 do_generic_file_read(filp,ppos,&desc,file_read_actor,0);
935 retval += desc.written;
946 EXPORT_SYMBOL(__generic_file_aio_read);
949 generic_file_aio_read(struct kiocb *iocb, char __user *buf, size_t count, loff_t pos)
951 struct iovec local_iov = { .iov_base = buf, .iov_len = count };
953 BUG_ON(iocb->ki_pos != pos);
954 return __generic_file_aio_read(iocb, &local_iov, 1, &iocb->ki_pos);
957 EXPORT_SYMBOL(generic_file_aio_read);
960 generic_file_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
962 struct iovec local_iov = { .iov_base = buf, .iov_len = count };
966 init_sync_kiocb(&kiocb, filp);
967 ret = __generic_file_aio_read(&kiocb, &local_iov, 1, ppos);
968 if (-EIOCBQUEUED == ret)
969 ret = wait_on_sync_kiocb(&kiocb);
973 EXPORT_SYMBOL(generic_file_read);
975 int file_send_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size)
978 unsigned long count = desc->count;
979 struct file *file = (struct file *) desc->buf;
984 written = file->f_op->sendpage(file, page, offset,
985 size, &file->f_pos, size<count);
987 desc->error = written;
990 desc->count = count - written;
991 desc->written += written;
995 ssize_t generic_file_sendfile(struct file *in_file, loff_t *ppos,
996 size_t count, read_actor_t actor, void __user *target)
998 read_descriptor_t desc;
1008 do_generic_file_read(in_file, ppos, &desc, actor, 0);
1010 return desc.written;
1014 EXPORT_SYMBOL(generic_file_sendfile);
1017 do_readahead(struct address_space *mapping, struct file *filp,
1018 unsigned long index, unsigned long nr)
1020 if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage)
1023 force_page_cache_readahead(mapping, filp, index,
1024 max_sane_readahead(nr));
1028 asmlinkage ssize_t sys_readahead(int fd, loff_t offset, size_t count)
1036 if (file->f_mode & FMODE_READ) {
1037 struct address_space *mapping = file->f_mapping;
1038 unsigned long start = offset >> PAGE_CACHE_SHIFT;
1039 unsigned long end = (offset + count - 1) >> PAGE_CACHE_SHIFT;
1040 unsigned long len = end - start + 1;
1041 ret = do_readahead(mapping, file, start, len);
1050 * This adds the requested page to the page cache if it isn't already there,
1051 * and schedules an I/O to read in its contents from disk.
1053 static int FASTCALL(page_cache_read(struct file * file, unsigned long offset));
1054 static int fastcall page_cache_read(struct file * file, unsigned long offset)
1056 struct address_space *mapping = file->f_mapping;
1060 page = page_cache_alloc_cold(mapping);
1064 error = add_to_page_cache_lru(page, mapping, offset, GFP_KERNEL);
1066 error = mapping->a_ops->readpage(file, page);
1067 page_cache_release(page);
1072 * We arrive here in the unlikely event that someone
1073 * raced with us and added our page to the cache first
1074 * or we are out of memory for radix-tree nodes.
1076 page_cache_release(page);
1077 return error == -EEXIST ? 0 : error;
1080 #define MMAP_LOTSAMISS (100)
1083 * filemap_nopage() is invoked via the vma operations vector for a
1084 * mapped memory region to read in file data during a page fault.
1086 * The goto's are kind of ugly, but this streamlines the normal case of having
1087 * it in the page cache, and handles the special cases reasonably without
1088 * having a lot of duplicated code.
1090 struct page * filemap_nopage(struct vm_area_struct * area, unsigned long address, int *type)
1093 struct file *file = area->vm_file;
1094 struct address_space *mapping = file->f_mapping;
1095 struct file_ra_state *ra = &file->f_ra;
1096 struct inode *inode = mapping->host;
1098 unsigned long size, pgoff, endoff;
1099 int did_readaround = 0, majmin = VM_FAULT_MINOR;
1101 pgoff = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) + area->vm_pgoff;
1102 endoff = ((area->vm_end - area->vm_start) >> PAGE_CACHE_SHIFT) + area->vm_pgoff;
1105 size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
1107 goto outside_data_content;
1109 /* If we don't want any read-ahead, don't bother */
1110 if (VM_RandomReadHint(area))
1111 goto no_cached_page;
1114 * The "size" of the file, as far as mmap is concerned, isn't bigger
1121 * The readahead code wants to be told about each and every page
1122 * so it can build and shrink its windows appropriately
1124 * For sequential accesses, we use the generic readahead logic.
1126 if (VM_SequentialReadHint(area))
1127 page_cache_readahead(mapping, ra, file, pgoff);
1130 * Do we have something in the page cache already?
1133 page = find_get_page(mapping, pgoff);
1135 unsigned long ra_pages;
1137 if (VM_SequentialReadHint(area)) {
1138 handle_ra_miss(mapping, ra, pgoff);
1139 goto no_cached_page;
1144 * Do we miss much more than hit in this file? If so,
1145 * stop bothering with read-ahead. It will only hurt.
1147 if (ra->mmap_miss > ra->mmap_hit + MMAP_LOTSAMISS)
1148 goto no_cached_page;
1151 * To keep the pgmajfault counter straight, we need to
1152 * check did_readaround, as this is an inner loop.
1154 if (!did_readaround) {
1155 majmin = VM_FAULT_MAJOR;
1156 inc_page_state(pgmajfault);
1159 ra_pages = max_sane_readahead(file->f_ra.ra_pages);
1163 start = pgoff - ra_pages / 2;
1166 do_page_cache_readahead(mapping, file, pgoff, ra_pages);
1168 page = find_get_page(mapping, pgoff);
1170 goto no_cached_page;
1173 if (!did_readaround)
1177 * Ok, found a page in the page cache, now we need to check
1178 * that it's up-to-date.
1180 if (!PageUptodate(page))
1181 goto page_not_uptodate;
1185 * Found the page and have a reference on it.
1187 mark_page_accessed(page);
1192 outside_data_content:
1194 * An external ptracer can access pages that normally aren't
1197 if (area->vm_mm == current->mm)
1199 /* Fall through to the non-read-ahead case */
1202 * We're only likely to ever get here if MADV_RANDOM is in
1205 error = page_cache_read(file, pgoff);
1208 * The page we want has now been added to the page cache.
1209 * In the unlikely event that someone removed it in the
1210 * meantime, we'll just come back here and read it again.
1216 * An error return from page_cache_read can result if the
1217 * system is low on memory, or a problem occurs while trying
1220 if (error == -ENOMEM)
1225 if (!did_readaround) {
1226 majmin = VM_FAULT_MAJOR;
1227 inc_page_state(pgmajfault);
1231 /* Did it get unhashed while we waited for it? */
1232 if (!page->mapping) {
1234 page_cache_release(page);
1238 /* Did somebody else get it up-to-date? */
1239 if (PageUptodate(page)) {
1244 if (!mapping->a_ops->readpage(file, page)) {
1245 wait_on_page_locked(page);
1246 if (PageUptodate(page))
1251 * Umm, take care of errors if the page isn't up-to-date.
1252 * Try to re-read it _once_. We do this synchronously,
1253 * because there really aren't any performance issues here
1254 * and we need to check for errors.
1258 /* Somebody truncated the page on us? */
1259 if (!page->mapping) {
1261 page_cache_release(page);
1265 /* Somebody else successfully read it in? */
1266 if (PageUptodate(page)) {
1270 ClearPageError(page);
1271 if (!mapping->a_ops->readpage(file, page)) {
1272 wait_on_page_locked(page);
1273 if (PageUptodate(page))
1278 * Things didn't work out. Return zero to tell the
1279 * mm layer so, possibly freeing the page cache page first.
1281 page_cache_release(page);
1285 EXPORT_SYMBOL(filemap_nopage);
1287 static struct page * filemap_getpage(struct file *file, unsigned long pgoff,
1290 struct address_space *mapping = file->f_mapping;
1295 * Do we have something in the page cache already?
1298 page = find_get_page(mapping, pgoff);
1302 goto no_cached_page;
1306 * Ok, found a page in the page cache, now we need to check
1307 * that it's up-to-date.
1309 if (!PageUptodate(page))
1310 goto page_not_uptodate;
1314 * Found the page and have a reference on it.
1316 mark_page_accessed(page);
1320 error = page_cache_read(file, pgoff);
1323 * The page we want has now been added to the page cache.
1324 * In the unlikely event that someone removed it in the
1325 * meantime, we'll just come back here and read it again.
1331 * An error return from page_cache_read can result if the
1332 * system is low on memory, or a problem occurs while trying
1340 /* Did it get unhashed while we waited for it? */
1341 if (!page->mapping) {
1346 /* Did somebody else get it up-to-date? */
1347 if (PageUptodate(page)) {
1352 if (!mapping->a_ops->readpage(file, page)) {
1353 wait_on_page_locked(page);
1354 if (PageUptodate(page))
1359 * Umm, take care of errors if the page isn't up-to-date.
1360 * Try to re-read it _once_. We do this synchronously,
1361 * because there really aren't any performance issues here
1362 * and we need to check for errors.
1366 /* Somebody truncated the page on us? */
1367 if (!page->mapping) {
1371 /* Somebody else successfully read it in? */
1372 if (PageUptodate(page)) {
1377 ClearPageError(page);
1378 if (!mapping->a_ops->readpage(file, page)) {
1379 wait_on_page_locked(page);
1380 if (PageUptodate(page))
1385 * Things didn't work out. Return zero to tell the
1386 * mm layer so, possibly freeing the page cache page first.
1389 page_cache_release(page);
1394 static int filemap_populate(struct vm_area_struct *vma,
1398 unsigned long pgoff,
1401 struct file *file = vma->vm_file;
1402 struct address_space *mapping = file->f_mapping;
1403 struct inode *inode = mapping->host;
1405 struct mm_struct *mm = vma->vm_mm;
1410 force_page_cache_readahead(mapping, vma->vm_file,
1411 pgoff, len >> PAGE_CACHE_SHIFT);
1414 size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
1415 if (pgoff + (len >> PAGE_CACHE_SHIFT) > size)
1418 page = filemap_getpage(file, pgoff, nonblock);
1419 if (!page && !nonblock)
1422 err = install_page(mm, vma, addr, page, prot);
1424 page_cache_release(page);
1429 * If a nonlinear mapping then store the file page offset
1432 if (pgoff != linear_page_index(vma, addr)) {
1433 err = install_file_pte(mm, vma, addr, pgoff, prot);
1448 static struct vm_operations_struct generic_file_vm_ops = {
1449 .nopage = filemap_nopage,
1450 .populate = filemap_populate,
1453 /* This is used for a general mmap of a disk file */
1455 int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
1457 struct address_space *mapping = file->f_mapping;
1459 if (!mapping->a_ops->readpage)
1461 file_accessed(file);
1462 vma->vm_ops = &generic_file_vm_ops;
1467 * This is for filesystems which do not implement ->writepage.
1469 int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
1471 if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
1473 return generic_file_mmap(file, vma);
1476 int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
1480 int generic_file_readonly_mmap(struct file * file, struct vm_area_struct * vma)
1484 #endif /* CONFIG_MMU */
1486 EXPORT_SYMBOL(generic_file_mmap);
1487 EXPORT_SYMBOL(generic_file_readonly_mmap);
1489 static inline struct page *__read_cache_page(struct address_space *mapping,
1490 unsigned long index,
1491 int (*filler)(void *,struct page*),
1494 struct page *page, *cached_page = NULL;
1497 page = find_get_page(mapping, index);
1500 cached_page = page_cache_alloc_cold(mapping);
1502 return ERR_PTR(-ENOMEM);
1504 err = add_to_page_cache_lru(cached_page, mapping,
1509 /* Presumably ENOMEM for radix tree node */
1510 page_cache_release(cached_page);
1511 return ERR_PTR(err);
1515 err = filler(data, page);
1517 page_cache_release(page);
1518 page = ERR_PTR(err);
1522 page_cache_release(cached_page);
1527 * Read into the page cache. If a page already exists,
1528 * and PageUptodate() is not set, try to fill the page.
1530 struct page *read_cache_page(struct address_space *mapping,
1531 unsigned long index,
1532 int (*filler)(void *,struct page*),
1539 page = __read_cache_page(mapping, index, filler, data);
1542 mark_page_accessed(page);
1543 if (PageUptodate(page))
1547 if (!page->mapping) {
1549 page_cache_release(page);
1552 if (PageUptodate(page)) {
1556 err = filler(data, page);
1558 page_cache_release(page);
1559 page = ERR_PTR(err);
1565 EXPORT_SYMBOL(read_cache_page);
1568 * If the page was newly created, increment its refcount and add it to the
1569 * caller's lru-buffering pagevec. This function is specifically for
1570 * generic_file_write().
1572 static inline struct page *
1573 __grab_cache_page(struct address_space *mapping, unsigned long index,
1574 struct page **cached_page, struct pagevec *lru_pvec)
1579 page = find_lock_page(mapping, index);
1581 if (!*cached_page) {
1582 *cached_page = page_cache_alloc(mapping);
1586 err = add_to_page_cache(*cached_page, mapping,
1591 page = *cached_page;
1592 page_cache_get(page);
1593 if (!pagevec_add(lru_pvec, page))
1594 __pagevec_lru_add(lru_pvec);
1595 *cached_page = NULL;
1602 * The logic we want is
1604 * if suid or (sgid and xgrp)
1607 int remove_suid(struct dentry *dentry)
1609 mode_t mode = dentry->d_inode->i_mode;
1613 /* suid always must be killed */
1614 if (unlikely(mode & S_ISUID))
1615 kill = ATTR_KILL_SUID;
1618 * sgid without any exec bits is just a mandatory locking mark; leave
1619 * it alone. If some exec bits are set, it's a real sgid; kill it.
1621 if (unlikely((mode & S_ISGID) && (mode & S_IXGRP)))
1622 kill |= ATTR_KILL_SGID;
1624 if (unlikely(kill && !capable(CAP_FSETID))) {
1625 struct iattr newattrs;
1627 newattrs.ia_valid = ATTR_FORCE | kill;
1628 result = notify_change(dentry, &newattrs);
1632 EXPORT_SYMBOL(remove_suid);
1635 * Copy as much as we can into the page and return the number of bytes which
1636 * were sucessfully copied. If a fault is encountered then clear the page
1637 * out to (offset+bytes) and return the number of bytes which were copied.
1639 static inline size_t
1640 filemap_copy_from_user(struct page *page, unsigned long offset,
1641 const char __user *buf, unsigned bytes)
1646 kaddr = kmap_atomic(page, KM_USER0);
1647 left = __copy_from_user(kaddr + offset, buf, bytes);
1648 kunmap_atomic(kaddr, KM_USER0);
1651 /* Do it the slow way */
1653 left = __copy_from_user(kaddr + offset, buf, bytes);
1656 return bytes - left;
1660 __filemap_copy_from_user_iovec(char *vaddr,
1661 const struct iovec *iov, size_t base, size_t bytes)
1663 size_t copied = 0, left = 0;
1666 char __user *buf = iov->iov_base + base;
1667 int copy = min(bytes, iov->iov_len - base);
1670 left = __copy_from_user(vaddr, buf, copy);
1676 if (unlikely(left)) {
1677 /* zero the rest of the target like __copy_from_user */
1679 memset(vaddr, 0, bytes);
1683 return copied - left;
1687 * This has the same sideeffects and return value as filemap_copy_from_user().
1688 * The difference is that on a fault we need to memset the remainder of the
1689 * page (out to offset+bytes), to emulate filemap_copy_from_user()'s
1690 * single-segment behaviour.
1692 static inline size_t
1693 filemap_copy_from_user_iovec(struct page *page, unsigned long offset,
1694 const struct iovec *iov, size_t base, size_t bytes)
1699 kaddr = kmap_atomic(page, KM_USER0);
1700 copied = __filemap_copy_from_user_iovec(kaddr + offset, iov,
1702 kunmap_atomic(kaddr, KM_USER0);
1703 if (copied != bytes) {
1705 copied = __filemap_copy_from_user_iovec(kaddr + offset, iov,
1713 filemap_set_next_iovec(const struct iovec **iovp, size_t *basep, size_t bytes)
1715 const struct iovec *iov = *iovp;
1716 size_t base = *basep;
1719 int copy = min(bytes, iov->iov_len - base);
1723 if (iov->iov_len == base) {
1733 * Performs necessary checks before doing a write
1735 * Can adjust writing position aor amount of bytes to write.
1736 * Returns appropriate error code that caller should return or
1737 * zero in case that write should be allowed.
1739 inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk)
1741 struct inode *inode = file->f_mapping->host;
1742 unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
1744 if (unlikely(*pos < 0))
1747 if (unlikely(file->f_error)) {
1748 int err = file->f_error;
1754 /* FIXME: this is for backwards compatibility with 2.4 */
1755 if (file->f_flags & O_APPEND)
1756 *pos = i_size_read(inode);
1758 if (limit != RLIM_INFINITY) {
1759 if (*pos >= limit) {
1760 send_sig(SIGXFSZ, current, 0);
1763 if (*count > limit - (typeof(limit))*pos) {
1764 *count = limit - (typeof(limit))*pos;
1772 if (unlikely(*pos + *count > MAX_NON_LFS &&
1773 !(file->f_flags & O_LARGEFILE))) {
1774 if (*pos >= MAX_NON_LFS) {
1775 send_sig(SIGXFSZ, current, 0);
1778 if (*count > MAX_NON_LFS - (unsigned long)*pos) {
1779 *count = MAX_NON_LFS - (unsigned long)*pos;
1784 * Are we about to exceed the fs block limit ?
1786 * If we have written data it becomes a short write. If we have
1787 * exceeded without writing data we send a signal and return EFBIG.
1788 * Linus frestrict idea will clean these up nicely..
1790 if (likely(!isblk)) {
1791 if (unlikely(*pos >= inode->i_sb->s_maxbytes)) {
1792 if (*count || *pos > inode->i_sb->s_maxbytes) {
1793 send_sig(SIGXFSZ, current, 0);
1796 /* zero-length writes at ->s_maxbytes are OK */
1799 if (unlikely(*pos + *count > inode->i_sb->s_maxbytes))
1800 *count = inode->i_sb->s_maxbytes - *pos;
1803 if (bdev_read_only(I_BDEV(inode)))
1805 isize = i_size_read(inode);
1806 if (*pos >= isize) {
1807 if (*count || *pos > isize)
1811 if (*pos + *count > isize)
1812 *count = isize - *pos;
1817 EXPORT_SYMBOL(generic_write_checks);
1820 * Write to a file through the page cache.
1821 * Called under i_sem for S_ISREG files.
1823 * We put everything into the page cache prior to writing it. This is not a
1824 * problem when writing full pages. With partial pages, however, we first have
1825 * to read the data into the cache, then dirty the page, and finally schedule
1826 * it for writing by marking it dirty.
1830 generic_file_aio_write_nolock(struct kiocb *iocb, const struct iovec *iov,
1831 unsigned long nr_segs, loff_t *ppos)
1833 struct file *file = iocb->ki_filp;
1834 struct address_space * mapping = file->f_mapping;
1835 struct address_space_operations *a_ops = mapping->a_ops;
1836 size_t ocount; /* original count */
1837 size_t count; /* after file limit checks */
1838 struct inode *inode = mapping->host;
1842 struct page *cached_page = NULL;
1843 const int isblk = S_ISBLK(inode->i_mode);
1847 struct pagevec lru_pvec;
1848 const struct iovec *cur_iov = iov; /* current iovec */
1849 size_t iov_base = 0; /* offset in the current iovec */
1854 for (seg = 0; seg < nr_segs; seg++) {
1855 const struct iovec *iv = &iov[seg];
1858 * If any segment has a negative length, or the cumulative
1859 * length ever wraps negative then return -EINVAL.
1861 ocount += iv->iov_len;
1862 if (unlikely((ssize_t)(ocount|iv->iov_len) < 0))
1864 if (access_ok(VERIFY_READ, iv->iov_base, iv->iov_len))
1869 ocount -= iv->iov_len; /* This segment is no good */
1875 pagevec_init(&lru_pvec, 0);
1877 /* We can write back this queue in page reclaim */
1878 current->backing_dev_info = mapping->backing_dev_info;
1881 err = generic_write_checks(file, &pos, &count, isblk);
1888 err = remove_suid(file->f_dentry);
1892 inode_update_time(inode, 1);
1894 /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */
1895 if (unlikely(file->f_flags & O_DIRECT)) {
1896 if (count != ocount)
1897 nr_segs = iov_shorten((struct iovec *)iov,
1899 written = generic_file_direct_IO(WRITE, iocb,
1902 loff_t end = pos + written;
1903 if (end > i_size_read(inode) && !isblk) {
1904 i_size_write(inode, end);
1905 mark_inode_dirty(inode);
1910 * Sync the fs metadata but not the minor inode changes and
1911 * of course not the data as we did direct DMA for the IO.
1912 * i_sem is held, which protects generic_osync_inode() from
1915 if (written >= 0 && file->f_flags & O_SYNC)
1916 status = generic_osync_inode(inode, mapping, OSYNC_METADATA);
1917 if (written == count && !is_sync_kiocb(iocb))
1918 written = -EIOCBQUEUED;
1919 if (written < 0 || written == count)
1922 * direct-io write to a hole: fall through to buffered I/O
1923 * for completing the rest of the request.
1929 buf = iov->iov_base + written; /* handle partial DIO write */
1931 unsigned long index;
1932 unsigned long offset;
1935 offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
1936 index = pos >> PAGE_CACHE_SHIFT;
1937 bytes = PAGE_CACHE_SIZE - offset;
1942 * Bring in the user page that we will copy from _first_.
1943 * Otherwise there's a nasty deadlock on copying from the
1944 * same page as we're writing to, without it being marked
1947 fault_in_pages_readable(buf, bytes);
1949 page = __grab_cache_page(mapping,index,&cached_page,&lru_pvec);
1955 status = a_ops->prepare_write(file, page, offset, offset+bytes);
1956 if (unlikely(status)) {
1957 loff_t isize = i_size_read(inode);
1959 * prepare_write() may have instantiated a few blocks
1960 * outside i_size. Trim these off again.
1963 page_cache_release(page);
1964 if (pos + bytes > isize)
1965 vmtruncate(inode, isize);
1968 if (likely(nr_segs == 1))
1969 copied = filemap_copy_from_user(page, offset,
1972 copied = filemap_copy_from_user_iovec(page, offset,
1973 cur_iov, iov_base, bytes);
1974 flush_dcache_page(page);
1975 status = a_ops->commit_write(file, page, offset, offset+bytes);
1976 if (likely(copied > 0)) {
1985 if (unlikely(nr_segs > 1))
1986 filemap_set_next_iovec(&cur_iov,
1990 if (unlikely(copied != bytes))
1994 mark_page_accessed(page);
1995 page_cache_release(page);
1998 balance_dirty_pages_ratelimited(mapping);
2004 page_cache_release(cached_page);
2007 * For now, when the user asks for O_SYNC, we'll actually give O_DSYNC
2010 if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
2011 status = generic_osync_inode(inode, mapping,
2012 OSYNC_METADATA|OSYNC_DATA);
2016 * If we get here for O_DIRECT writes then we must have fallen through
2017 * to buffered writes (block instantiation inside i_size). So we sync
2018 * the file data here, to try to honour O_DIRECT expectations.
2020 if (unlikely(file->f_flags & O_DIRECT) && written)
2021 status = filemap_write_and_wait(mapping);
2024 err = written ? written : status;
2026 pagevec_lru_add(&lru_pvec);
2027 current->backing_dev_info = 0;
2031 EXPORT_SYMBOL(generic_file_aio_write_nolock);
2034 generic_file_write_nolock(struct file *file, const struct iovec *iov,
2035 unsigned long nr_segs, loff_t *ppos)
2040 init_sync_kiocb(&kiocb, file);
2041 ret = generic_file_aio_write_nolock(&kiocb, iov, nr_segs, ppos);
2042 if (-EIOCBQUEUED == ret)
2043 ret = wait_on_sync_kiocb(&kiocb);
2047 EXPORT_SYMBOL(generic_file_write_nolock);
2049 ssize_t generic_file_aio_write(struct kiocb *iocb, const char __user *buf,
2050 size_t count, loff_t pos)
2052 struct file *file = iocb->ki_filp;
2053 struct inode *inode = file->f_mapping->host;
2055 struct iovec local_iov = { .iov_base = (void __user *)buf, .iov_len = count };
2057 BUG_ON(iocb->ki_pos != pos);
2059 down(&inode->i_sem);
2060 err = generic_file_aio_write_nolock(iocb, &local_iov, 1,
2067 EXPORT_SYMBOL(generic_file_aio_write);
2069 ssize_t generic_file_write(struct file *file, const char __user *buf,
2070 size_t count, loff_t *ppos)
2072 struct inode *inode = file->f_mapping->host;
2074 struct iovec local_iov = { .iov_base = (void __user *)buf, .iov_len = count };
2076 down(&inode->i_sem);
2077 err = generic_file_write_nolock(file, &local_iov, 1, ppos);
2083 EXPORT_SYMBOL(generic_file_write);
2085 ssize_t generic_file_readv(struct file *filp, const struct iovec *iov,
2086 unsigned long nr_segs, loff_t *ppos)
2091 init_sync_kiocb(&kiocb, filp);
2092 ret = __generic_file_aio_read(&kiocb, iov, nr_segs, ppos);
2093 if (-EIOCBQUEUED == ret)
2094 ret = wait_on_sync_kiocb(&kiocb);
2098 EXPORT_SYMBOL(generic_file_readv);
2100 ssize_t generic_file_writev(struct file *file, const struct iovec *iov,
2101 unsigned long nr_segs, loff_t * ppos)
2103 struct inode *inode = file->f_mapping->host;
2106 down(&inode->i_sem);
2107 ret = generic_file_write_nolock(file, iov, nr_segs, ppos);
2112 EXPORT_SYMBOL(generic_file_writev);
2115 * Called under i_sem for writes to S_ISREG files
2118 generic_file_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
2119 loff_t offset, unsigned long nr_segs)
2121 struct file *file = iocb->ki_filp;
2122 struct address_space *mapping = file->f_mapping;
2125 retval = filemap_write_and_wait(mapping);
2127 retval = mapping->a_ops->direct_IO(rw, iocb, iov,
2129 if (rw == WRITE && mapping->nrpages)
2130 invalidate_inode_pages2(mapping);
2135 EXPORT_SYMBOL_GPL(generic_file_direct_IO);