summaryrefslogtreecommitdiffstats
path: root/fs/cifs/file.c
diff options
context:
space:
mode:
authorPavel Shilovsky <pshilovsky@samba.org>2014-06-24 05:42:03 -0400
committerSteve French <smfrench@gmail.com>2014-08-02 02:23:03 -0400
commit69cebd75606f8b9162ad5d0104367370ceabeeba (patch)
tree7f7056934a1879fa266be7d9c116c39fd94ab857 /fs/cifs/file.c
parent387eb92ac6892518fb67e423f65fcaca76e256a8 (diff)
CIFS: Fix rsize usage in readpages
If a server changes maximum buffer size for read (rsize) requests on reconnect we can fail on repeating with a big size buffer on -EAGAIN error in readpages. Fix this by checking rsize all the time before repeating requests. Reviewed-by: Shirish Pargaonkar <spargaonkar@suse.com> Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org> Signed-off-by: Steve French <smfrench@gmail.com>
Diffstat (limited to 'fs/cifs/file.c')
-rw-r--r--fs/cifs/file.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index bec48f1bc3ca..d6279185e2f0 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -3349,6 +3349,8 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
3349 unsigned int expected_index; 3349 unsigned int expected_index;
3350 int rc; 3350 int rc;
3351 3351
3352 INIT_LIST_HEAD(tmplist);
3353
3352 page = list_entry(page_list->prev, struct page, lru); 3354 page = list_entry(page_list->prev, struct page, lru);
3353 3355
3354 /* 3356 /*
@@ -3404,19 +3406,10 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
3404 struct list_head tmplist; 3406 struct list_head tmplist;
3405 struct cifsFileInfo *open_file = file->private_data; 3407 struct cifsFileInfo *open_file = file->private_data;
3406 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 3408 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
3407 unsigned int rsize = cifs_sb->rsize; 3409 struct TCP_Server_Info *server;
3408 pid_t pid; 3410 pid_t pid;
3409 3411
3410 /* 3412 /*
3411 * Give up immediately if rsize is too small to read an entire page.
3412 * The VFS will fall back to readpage. We should never reach this
3413 * point however since we set ra_pages to 0 when the rsize is smaller
3414 * than a cache page.
3415 */
3416 if (unlikely(rsize < PAGE_CACHE_SIZE))
3417 return 0;
3418
3419 /*
3420 * Reads as many pages as possible from fscache. Returns -ENOBUFS 3413 * Reads as many pages as possible from fscache. Returns -ENOBUFS
3421 * immediately if the cookie is negative 3414 * immediately if the cookie is negative
3422 * 3415 *
@@ -3434,7 +3427,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
3434 pid = current->tgid; 3427 pid = current->tgid;
3435 3428
3436 rc = 0; 3429 rc = 0;
3437 INIT_LIST_HEAD(&tmplist); 3430 server = tlink_tcon(open_file->tlink)->ses->server;
3438 3431
3439 cifs_dbg(FYI, "%s: file=%p mapping=%p num_pages=%u\n", 3432 cifs_dbg(FYI, "%s: file=%p mapping=%p num_pages=%u\n",
3440 __func__, file, mapping, num_pages); 3433 __func__, file, mapping, num_pages);
@@ -3456,8 +3449,17 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
3456 struct page *page, *tpage; 3449 struct page *page, *tpage;
3457 struct cifs_readdata *rdata; 3450 struct cifs_readdata *rdata;
3458 3451
3459 rc = readpages_get_pages(mapping, page_list, rsize, &tmplist, 3452 /*
3460 &nr_pages, &offset, &bytes); 3453 * Give up immediately if rsize is too small to read an entire
3454 * page. The VFS will fall back to readpage. We should never
3455 * reach this point however since we set ra_pages to 0 when the
3456 * rsize is smaller than a cache page.
3457 */
3458 if (unlikely(cifs_sb->rsize < PAGE_CACHE_SIZE))
3459 return 0;
3460
3461 rc = readpages_get_pages(mapping, page_list, cifs_sb->rsize,
3462 &tmplist, &nr_pages, &offset, &bytes);
3461 if (rc) 3463 if (rc)
3462 break; 3464 break;
3463 3465
@@ -3487,15 +3489,24 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
3487 rdata->pages[rdata->nr_pages++] = page; 3489 rdata->pages[rdata->nr_pages++] = page;
3488 } 3490 }
3489 3491
3490 rc = cifs_retry_async_readv(rdata); 3492 if (!rdata->cfile->invalidHandle ||
3491 if (rc != 0) { 3493 !cifs_reopen_file(rdata->cfile, true))
3494 rc = server->ops->async_readv(rdata);
3495 if (rc) {
3492 for (i = 0; i < rdata->nr_pages; i++) { 3496 for (i = 0; i < rdata->nr_pages; i++) {
3493 page = rdata->pages[i]; 3497 page = rdata->pages[i];
3494 lru_cache_add_file(page); 3498 lru_cache_add_file(page);
3495 unlock_page(page); 3499 unlock_page(page);
3496 page_cache_release(page); 3500 page_cache_release(page);
3501 if (rc == -EAGAIN)
3502 list_add_tail(&page->lru, &tmplist);
3497 } 3503 }
3498 kref_put(&rdata->refcount, cifs_readdata_release); 3504 kref_put(&rdata->refcount, cifs_readdata_release);
3505 if (rc == -EAGAIN) {
3506 /* Re-add pages to the page_list and retry */
3507 list_splice(&tmplist, page_list);
3508 continue;
3509 }
3499 break; 3510 break;
3500 } 3511 }
3501 3512