shmem.c (d1f5323370fceaed43a7ee38f4c7bfc7e70f28d0) shmem.c (19938e350adc60f3b9381ae6fc68da40f7d1a9f6)
1/*
2 * Resizable virtual memory filesystem for Linux.
3 *
4 * Copyright (C) 2000 Linus Torvalds.
5 * 2000 Transmeta Corp.
6 * 2000-2001 Christoph Rohland
7 * 2000-2001 SAP AG
8 * 2002 Red Hat Inc.

--- 2297 unchanged lines hidden (view full) ---

2306 cond_resched();
2307 }
2308
2309 *ppos = ((loff_t) index << PAGE_SHIFT) + offset;
2310 file_accessed(file);
2311 return retval ? retval : error;
2312}
2313
1/*
2 * Resizable virtual memory filesystem for Linux.
3 *
4 * Copyright (C) 2000 Linus Torvalds.
5 * 2000 Transmeta Corp.
6 * 2000-2001 Christoph Rohland
7 * 2000-2001 SAP AG
8 * 2002 Red Hat Inc.

--- 2297 unchanged lines hidden (view full) ---

2306 cond_resched();
2307 }
2308
2309 *ppos = ((loff_t) index << PAGE_SHIFT) + offset;
2310 file_accessed(file);
2311 return retval ? retval : error;
2312}
2313
2314static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
2315 struct pipe_inode_info *pipe, size_t len,
2316 unsigned int flags)
2317{
2318 struct address_space *mapping = in->f_mapping;
2319 struct inode *inode = mapping->host;
2320 unsigned int loff, nr_pages, req_pages;
2321 struct page *pages[PIPE_DEF_BUFFERS];
2322 struct partial_page partial[PIPE_DEF_BUFFERS];
2323 struct page *page;
2324 pgoff_t index, end_index;
2325 loff_t isize, left;
2326 int error, page_nr;
2327 struct splice_pipe_desc spd = {
2328 .pages = pages,
2329 .partial = partial,
2330 .nr_pages_max = PIPE_DEF_BUFFERS,
2331 .flags = flags,
2332 .ops = &page_cache_pipe_buf_ops,
2333 .spd_release = spd_release_page,
2334 };
2335
2336 isize = i_size_read(inode);
2337 if (unlikely(*ppos >= isize))
2338 return 0;
2339
2340 left = isize - *ppos;
2341 if (unlikely(left < len))
2342 len = left;
2343
2344 if (splice_grow_spd(pipe, &spd))
2345 return -ENOMEM;
2346
2347 index = *ppos >> PAGE_SHIFT;
2348 loff = *ppos & ~PAGE_MASK;
2349 req_pages = (len + loff + PAGE_SIZE - 1) >> PAGE_SHIFT;
2350 nr_pages = min(req_pages, spd.nr_pages_max);
2351
2352 spd.nr_pages = find_get_pages_contig(mapping, index,
2353 nr_pages, spd.pages);
2354 index += spd.nr_pages;
2355 error = 0;
2356
2357 while (spd.nr_pages < nr_pages) {
2358 error = shmem_getpage(inode, index, &page, SGP_CACHE);
2359 if (error)
2360 break;
2361 unlock_page(page);
2362 spd.pages[spd.nr_pages++] = page;
2363 index++;
2364 }
2365
2366 index = *ppos >> PAGE_SHIFT;
2367 nr_pages = spd.nr_pages;
2368 spd.nr_pages = 0;
2369
2370 for (page_nr = 0; page_nr < nr_pages; page_nr++) {
2371 unsigned int this_len;
2372
2373 if (!len)
2374 break;
2375
2376 this_len = min_t(unsigned long, len, PAGE_SIZE - loff);
2377 page = spd.pages[page_nr];
2378
2379 if (!PageUptodate(page) || page->mapping != mapping) {
2380 error = shmem_getpage(inode, index, &page, SGP_CACHE);
2381 if (error)
2382 break;
2383 unlock_page(page);
2384 put_page(spd.pages[page_nr]);
2385 spd.pages[page_nr] = page;
2386 }
2387
2388 isize = i_size_read(inode);
2389 end_index = (isize - 1) >> PAGE_SHIFT;
2390 if (unlikely(!isize || index > end_index))
2391 break;
2392
2393 if (end_index == index) {
2394 unsigned int plen;
2395
2396 plen = ((isize - 1) & ~PAGE_MASK) + 1;
2397 if (plen <= loff)
2398 break;
2399
2400 this_len = min(this_len, plen - loff);
2401 len = this_len;
2402 }
2403
2404 spd.partial[page_nr].offset = loff;
2405 spd.partial[page_nr].len = this_len;
2406 len -= this_len;
2407 loff = 0;
2408 spd.nr_pages++;
2409 index++;
2410 }
2411
2412 while (page_nr < nr_pages)
2413 put_page(spd.pages[page_nr++]);
2414
2415 if (spd.nr_pages)
2416 error = splice_to_pipe(pipe, &spd);
2417
2418 splice_shrink_spd(&spd);
2419
2420 if (error > 0) {
2421 *ppos += error;
2422 file_accessed(in);
2423 }
2424 return error;
2425}
2426
2314/*
2315 * llseek SEEK_DATA or SEEK_HOLE through the radix_tree.
2316 */
2317static pgoff_t shmem_seek_hole_data(struct address_space *mapping,
2318 pgoff_t index, pgoff_t end, int whence)
2319{
2320 struct page *page;
2321 struct pagevec pvec;

--- 1346 unchanged lines hidden (view full) ---

3668static const struct file_operations shmem_file_operations = {
3669 .mmap = shmem_mmap,
3670 .get_unmapped_area = shmem_get_unmapped_area,
3671#ifdef CONFIG_TMPFS
3672 .llseek = shmem_file_llseek,
3673 .read_iter = shmem_file_read_iter,
3674 .write_iter = generic_file_write_iter,
3675 .fsync = noop_fsync,
2427/*
2428 * llseek SEEK_DATA or SEEK_HOLE through the radix_tree.
2429 */
2430static pgoff_t shmem_seek_hole_data(struct address_space *mapping,
2431 pgoff_t index, pgoff_t end, int whence)
2432{
2433 struct page *page;
2434 struct pagevec pvec;

--- 1346 unchanged lines hidden (view full) ---

3781static const struct file_operations shmem_file_operations = {
3782 .mmap = shmem_mmap,
3783 .get_unmapped_area = shmem_get_unmapped_area,
3784#ifdef CONFIG_TMPFS
3785 .llseek = shmem_file_llseek,
3786 .read_iter = shmem_file_read_iter,
3787 .write_iter = generic_file_write_iter,
3788 .fsync = noop_fsync,
3676 .splice_read = generic_file_splice_read,
3789 .splice_read = shmem_file_splice_read,
3677 .splice_write = iter_file_splice_write,
3678 .fallocate = shmem_fallocate,
3679#endif
3680};
3681
3682static const struct inode_operations shmem_inode_operations = {
3683 .getattr = shmem_getattr,
3684 .setattr = shmem_setattr,

--- 275 unchanged lines hidden (view full) ---

3960#define shmem_get_inode(sb, dir, mode, dev, flags) ramfs_get_inode(sb, dir, mode, dev)
3961#define shmem_acct_size(flags, size) 0
3962#define shmem_unacct_size(flags, size) do {} while (0)
3963
3964#endif /* CONFIG_SHMEM */
3965
3966/* common code */
3967
3790 .splice_write = iter_file_splice_write,
3791 .fallocate = shmem_fallocate,
3792#endif
3793};
3794
3795static const struct inode_operations shmem_inode_operations = {
3796 .getattr = shmem_getattr,
3797 .setattr = shmem_setattr,

--- 275 unchanged lines hidden (view full) ---

4073#define shmem_get_inode(sb, dir, mode, dev, flags) ramfs_get_inode(sb, dir, mode, dev)
4074#define shmem_acct_size(flags, size) 0
4075#define shmem_unacct_size(flags, size) do {} while (0)
4076
4077#endif /* CONFIG_SHMEM */
4078
4079/* common code */
4080
3968static struct dentry_operations anon_ops = {
4081static const struct dentry_operations anon_ops = {
3969 .d_dname = simple_dname
3970};
3971
3972static struct file *__shmem_file_setup(const char *name, loff_t size,
3973 unsigned long flags, unsigned int i_flags)
3974{
3975 struct file *res;
3976 struct inode *inode;

--- 150 unchanged lines hidden ---
4082 .d_dname = simple_dname
4083};
4084
4085static struct file *__shmem_file_setup(const char *name, loff_t size,
4086 unsigned long flags, unsigned int i_flags)
4087{
4088 struct file *res;
4089 struct inode *inode;

--- 150 unchanged lines hidden ---