aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/file.c
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2008-07-15 18:34:16 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2008-07-15 18:34:16 -0400
commite89e896d31b11a51a54ddcd3f72a76bd286dd86c (patch)
tree105a9a93a4021caeeba76e479778ad2dd2b87b57 /fs/nfs/file.c
parent3a628b0fd42f7eaf9d052447784d48ceae9ffb8e (diff)
parentd67d1c7bf948341fd8678c8e337ec27f4b46b206 (diff)
Merge branch 'devel' into next
Conflicts: fs/nfs/file.c Fix up the conflict with Jon Corbet's bkl-removal tree
Diffstat (limited to 'fs/nfs/file.c')
-rw-r--r--fs/nfs/file.c151
1 files changed, 116 insertions, 35 deletions
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 4e98a56a1777..43164fe86069 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -50,7 +50,7 @@ static ssize_t nfs_file_read(struct kiocb *, const struct iovec *iov,
50static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov, 50static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov,
51 unsigned long nr_segs, loff_t pos); 51 unsigned long nr_segs, loff_t pos);
52static int nfs_file_flush(struct file *, fl_owner_t id); 52static int nfs_file_flush(struct file *, fl_owner_t id);
53static int nfs_fsync(struct file *, struct dentry *dentry, int datasync); 53static int nfs_file_fsync(struct file *, struct dentry *dentry, int datasync);
54static int nfs_check_flags(int flags); 54static int nfs_check_flags(int flags);
55static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl); 55static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl);
56static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl); 56static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl);
@@ -72,7 +72,7 @@ const struct file_operations nfs_file_operations = {
72 .open = nfs_file_open, 72 .open = nfs_file_open,
73 .flush = nfs_file_flush, 73 .flush = nfs_file_flush,
74 .release = nfs_file_release, 74 .release = nfs_file_release,
75 .fsync = nfs_fsync, 75 .fsync = nfs_file_fsync,
76 .lock = nfs_lock, 76 .lock = nfs_lock,
77 .flock = nfs_flock, 77 .flock = nfs_flock,
78 .splice_read = nfs_file_splice_read, 78 .splice_read = nfs_file_splice_read,
@@ -119,13 +119,17 @@ nfs_file_open(struct inode *inode, struct file *filp)
119{ 119{
120 int res; 120 int res;
121 121
122 dprintk("NFS: open file(%s/%s)\n",
123 filp->f_path.dentry->d_parent->d_name.name,
124 filp->f_path.dentry->d_name.name);
125
122 res = nfs_check_flags(filp->f_flags); 126 res = nfs_check_flags(filp->f_flags);
123 if (res) 127 if (res)
124 return res; 128 return res;
125 129
126 nfs_inc_stats(inode, NFSIOS_VFSOPEN); 130 nfs_inc_stats(inode, NFSIOS_VFSOPEN);
127 lock_kernel(); 131 lock_kernel();
128 res = NFS_PROTO(inode)->file_open(inode, filp); 132 res = nfs_open(inode, filp);
129 unlock_kernel(); 133 unlock_kernel();
130 return res; 134 return res;
131} 135}
@@ -133,11 +137,17 @@ nfs_file_open(struct inode *inode, struct file *filp)
133static int 137static int
134nfs_file_release(struct inode *inode, struct file *filp) 138nfs_file_release(struct inode *inode, struct file *filp)
135{ 139{
140 struct dentry *dentry = filp->f_path.dentry;
141
142 dprintk("NFS: release(%s/%s)\n",
143 dentry->d_parent->d_name.name,
144 dentry->d_name.name);
145
136 /* Ensure that dirty pages are flushed out with the right creds */ 146 /* Ensure that dirty pages are flushed out with the right creds */
137 if (filp->f_mode & FMODE_WRITE) 147 if (filp->f_mode & FMODE_WRITE)
138 nfs_wb_all(filp->f_path.dentry->d_inode); 148 nfs_wb_all(dentry->d_inode);
139 nfs_inc_stats(inode, NFSIOS_VFSRELEASE); 149 nfs_inc_stats(inode, NFSIOS_VFSRELEASE);
140 return NFS_PROTO(inode)->file_release(inode, filp); 150 return nfs_release(inode, filp);
141} 151}
142 152
143/** 153/**
@@ -171,6 +181,12 @@ force_reval:
171static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin) 181static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
172{ 182{
173 loff_t loff; 183 loff_t loff;
184
185 dprintk("NFS: llseek file(%s/%s, %lld, %d)\n",
186 filp->f_path.dentry->d_parent->d_name.name,
187 filp->f_path.dentry->d_name.name,
188 offset, origin);
189
174 /* origin == SEEK_END => we must revalidate the cached file length */ 190 /* origin == SEEK_END => we must revalidate the cached file length */
175 if (origin == SEEK_END) { 191 if (origin == SEEK_END) {
176 struct inode *inode = filp->f_mapping->host; 192 struct inode *inode = filp->f_mapping->host;
@@ -185,7 +201,7 @@ static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
185} 201}
186 202
187/* 203/*
188 * Helper for nfs_file_flush() and nfs_fsync() 204 * Helper for nfs_file_flush() and nfs_file_fsync()
189 * 205 *
190 * Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to 206 * Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to
191 * disk, but it retrieves and clears ctx->error after synching, despite 207 * disk, but it retrieves and clears ctx->error after synching, despite
@@ -211,16 +227,18 @@ static int nfs_do_fsync(struct nfs_open_context *ctx, struct inode *inode)
211 227
212/* 228/*
213 * Flush all dirty pages, and check for write errors. 229 * Flush all dirty pages, and check for write errors.
214 *
215 */ 230 */
216static int 231static int
217nfs_file_flush(struct file *file, fl_owner_t id) 232nfs_file_flush(struct file *file, fl_owner_t id)
218{ 233{
219 struct nfs_open_context *ctx = nfs_file_open_context(file); 234 struct nfs_open_context *ctx = nfs_file_open_context(file);
220 struct inode *inode = file->f_path.dentry->d_inode; 235 struct dentry *dentry = file->f_path.dentry;
236 struct inode *inode = dentry->d_inode;
221 int status; 237 int status;
222 238
223 dfprintk(VFS, "nfs: flush(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino); 239 dprintk("NFS: flush(%s/%s)\n",
240 dentry->d_parent->d_name.name,
241 dentry->d_name.name);
224 242
225 if ((file->f_mode & FMODE_WRITE) == 0) 243 if ((file->f_mode & FMODE_WRITE) == 0)
226 return 0; 244 return 0;
@@ -245,7 +263,7 @@ nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
245 if (iocb->ki_filp->f_flags & O_DIRECT) 263 if (iocb->ki_filp->f_flags & O_DIRECT)
246 return nfs_file_direct_read(iocb, iov, nr_segs, pos); 264 return nfs_file_direct_read(iocb, iov, nr_segs, pos);
247 265
248 dfprintk(VFS, "nfs: read(%s/%s, %lu@%lu)\n", 266 dprintk("NFS: read(%s/%s, %lu@%lu)\n",
249 dentry->d_parent->d_name.name, dentry->d_name.name, 267 dentry->d_parent->d_name.name, dentry->d_name.name,
250 (unsigned long) count, (unsigned long) pos); 268 (unsigned long) count, (unsigned long) pos);
251 269
@@ -265,7 +283,7 @@ nfs_file_splice_read(struct file *filp, loff_t *ppos,
265 struct inode *inode = dentry->d_inode; 283 struct inode *inode = dentry->d_inode;
266 ssize_t res; 284 ssize_t res;
267 285
268 dfprintk(VFS, "nfs: splice_read(%s/%s, %lu@%Lu)\n", 286 dprintk("NFS: splice_read(%s/%s, %lu@%Lu)\n",
269 dentry->d_parent->d_name.name, dentry->d_name.name, 287 dentry->d_parent->d_name.name, dentry->d_name.name,
270 (unsigned long) count, (unsigned long long) *ppos); 288 (unsigned long) count, (unsigned long long) *ppos);
271 289
@@ -282,7 +300,7 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
282 struct inode *inode = dentry->d_inode; 300 struct inode *inode = dentry->d_inode;
283 int status; 301 int status;
284 302
285 dfprintk(VFS, "nfs: mmap(%s/%s)\n", 303 dprintk("NFS: mmap(%s/%s)\n",
286 dentry->d_parent->d_name.name, dentry->d_name.name); 304 dentry->d_parent->d_name.name, dentry->d_name.name);
287 305
288 status = nfs_revalidate_mapping(inode, file->f_mapping); 306 status = nfs_revalidate_mapping(inode, file->f_mapping);
@@ -300,12 +318,14 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
300 * whether any write errors occurred for this process. 318 * whether any write errors occurred for this process.
301 */ 319 */
302static int 320static int
303nfs_fsync(struct file *file, struct dentry *dentry, int datasync) 321nfs_file_fsync(struct file *file, struct dentry *dentry, int datasync)
304{ 322{
305 struct nfs_open_context *ctx = nfs_file_open_context(file); 323 struct nfs_open_context *ctx = nfs_file_open_context(file);
306 struct inode *inode = dentry->d_inode; 324 struct inode *inode = dentry->d_inode;
307 325
308 dfprintk(VFS, "nfs: fsync(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino); 326 dprintk("NFS: fsync file(%s/%s) datasync %d\n",
327 dentry->d_parent->d_name.name, dentry->d_name.name,
328 datasync);
309 329
310 nfs_inc_stats(inode, NFSIOS_VFSFSYNC); 330 nfs_inc_stats(inode, NFSIOS_VFSFSYNC);
311 return nfs_do_fsync(ctx, inode); 331 return nfs_do_fsync(ctx, inode);
@@ -328,6 +348,11 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,
328 struct page *page; 348 struct page *page;
329 index = pos >> PAGE_CACHE_SHIFT; 349 index = pos >> PAGE_CACHE_SHIFT;
330 350
351 dfprintk(PAGECACHE, "NFS: write_begin(%s/%s(%ld), %u@%lld)\n",
352 file->f_path.dentry->d_parent->d_name.name,
353 file->f_path.dentry->d_name.name,
354 mapping->host->i_ino, len, (long long) pos);
355
331 page = __grab_cache_page(mapping, index); 356 page = __grab_cache_page(mapping, index);
332 if (!page) 357 if (!page)
333 return -ENOMEM; 358 return -ENOMEM;
@@ -348,6 +373,31 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,
348 unsigned offset = pos & (PAGE_CACHE_SIZE - 1); 373 unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
349 int status; 374 int status;
350 375
376 dfprintk(PAGECACHE, "NFS: write_end(%s/%s(%ld), %u@%lld)\n",
377 file->f_path.dentry->d_parent->d_name.name,
378 file->f_path.dentry->d_name.name,
379 mapping->host->i_ino, len, (long long) pos);
380
381 /*
382 * Zero any uninitialised parts of the page, and then mark the page
383 * as up to date if it turns out that we're extending the file.
384 */
385 if (!PageUptodate(page)) {
386 unsigned pglen = nfs_page_length(page);
387 unsigned end = offset + len;
388
389 if (pglen == 0) {
390 zero_user_segments(page, 0, offset,
391 end, PAGE_CACHE_SIZE);
392 SetPageUptodate(page);
393 } else if (end >= pglen) {
394 zero_user_segment(page, end, PAGE_CACHE_SIZE);
395 if (offset == 0)
396 SetPageUptodate(page);
397 } else
398 zero_user_segment(page, pglen, PAGE_CACHE_SIZE);
399 }
400
351 lock_kernel(); 401 lock_kernel();
352 status = nfs_updatepage(file, page, offset, copied); 402 status = nfs_updatepage(file, page, offset, copied);
353 unlock_kernel(); 403 unlock_kernel();
@@ -362,6 +412,8 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,
362 412
363static void nfs_invalidate_page(struct page *page, unsigned long offset) 413static void nfs_invalidate_page(struct page *page, unsigned long offset)
364{ 414{
415 dfprintk(PAGECACHE, "NFS: invalidate_page(%p, %lu)\n", page, offset);
416
365 if (offset != 0) 417 if (offset != 0)
366 return; 418 return;
367 /* Cancel any unstarted writes on this page */ 419 /* Cancel any unstarted writes on this page */
@@ -370,13 +422,20 @@ static void nfs_invalidate_page(struct page *page, unsigned long offset)
370 422
371static int nfs_release_page(struct page *page, gfp_t gfp) 423static int nfs_release_page(struct page *page, gfp_t gfp)
372{ 424{
425 dfprintk(PAGECACHE, "NFS: release_page(%p)\n", page);
426
373 /* If PagePrivate() is set, then the page is not freeable */ 427 /* If PagePrivate() is set, then the page is not freeable */
374 return 0; 428 return 0;
375} 429}
376 430
377static int nfs_launder_page(struct page *page) 431static int nfs_launder_page(struct page *page)
378{ 432{
379 return nfs_wb_page(page->mapping->host, page); 433 struct inode *inode = page->mapping->host;
434
435 dfprintk(PAGECACHE, "NFS: launder_page(%ld, %llu)\n",
436 inode->i_ino, (long long)page_offset(page));
437
438 return nfs_wb_page(inode, page);
380} 439}
381 440
382const struct address_space_operations nfs_file_aops = { 441const struct address_space_operations nfs_file_aops = {
@@ -396,13 +455,19 @@ const struct address_space_operations nfs_file_aops = {
396static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct page *page) 455static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct page *page)
397{ 456{
398 struct file *filp = vma->vm_file; 457 struct file *filp = vma->vm_file;
458 struct dentry *dentry = filp->f_path.dentry;
399 unsigned pagelen; 459 unsigned pagelen;
400 int ret = -EINVAL; 460 int ret = -EINVAL;
401 struct address_space *mapping; 461 struct address_space *mapping;
402 462
463 dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%s/%s(%ld), offset %lld)\n",
464 dentry->d_parent->d_name.name, dentry->d_name.name,
465 filp->f_mapping->host->i_ino,
466 (long long)page_offset(page));
467
403 lock_page(page); 468 lock_page(page);
404 mapping = page->mapping; 469 mapping = page->mapping;
405 if (mapping != vma->vm_file->f_path.dentry->d_inode->i_mapping) 470 if (mapping != dentry->d_inode->i_mapping)
406 goto out_unlock; 471 goto out_unlock;
407 472
408 ret = 0; 473 ret = 0;
@@ -450,9 +515,9 @@ static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
450 if (iocb->ki_filp->f_flags & O_DIRECT) 515 if (iocb->ki_filp->f_flags & O_DIRECT)
451 return nfs_file_direct_write(iocb, iov, nr_segs, pos); 516 return nfs_file_direct_write(iocb, iov, nr_segs, pos);
452 517
453 dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%Ld)\n", 518 dprintk("NFS: write(%s/%s, %lu@%Ld)\n",
454 dentry->d_parent->d_name.name, dentry->d_name.name, 519 dentry->d_parent->d_name.name, dentry->d_name.name,
455 inode->i_ino, (unsigned long) count, (long long) pos); 520 (unsigned long) count, (long long) pos);
456 521
457 result = -EBUSY; 522 result = -EBUSY;
458 if (IS_SWAPFILE(inode)) 523 if (IS_SWAPFILE(inode))
@@ -586,7 +651,8 @@ static int do_setlk(struct file *filp, int cmd, struct file_lock *fl)
586 * This makes locking act as a cache coherency point. 651 * This makes locking act as a cache coherency point.
587 */ 652 */
588 nfs_sync_mapping(filp->f_mapping); 653 nfs_sync_mapping(filp->f_mapping);
589 nfs_zap_caches(inode); 654 if (!nfs_have_delegation(inode, FMODE_READ))
655 nfs_zap_caches(inode);
590out: 656out:
591 return status; 657 return status;
592} 658}
@@ -596,23 +662,35 @@ out:
596 */ 662 */
597static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl) 663static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
598{ 664{
599 struct inode * inode = filp->f_mapping->host; 665 struct inode *inode = filp->f_mapping->host;
666 int ret = -ENOLCK;
600 667
601 dprintk("NFS: nfs_lock(f=%s/%ld, t=%x, fl=%x, r=%Ld:%Ld)\n", 668 dprintk("NFS: lock(%s/%s, t=%x, fl=%x, r=%lld:%lld)\n",
602 inode->i_sb->s_id, inode->i_ino, 669 filp->f_path.dentry->d_parent->d_name.name,
670 filp->f_path.dentry->d_name.name,
603 fl->fl_type, fl->fl_flags, 671 fl->fl_type, fl->fl_flags,
604 (long long)fl->fl_start, (long long)fl->fl_end); 672 (long long)fl->fl_start, (long long)fl->fl_end);
673
605 nfs_inc_stats(inode, NFSIOS_VFSLOCK); 674 nfs_inc_stats(inode, NFSIOS_VFSLOCK);
606 675
607 /* No mandatory locks over NFS */ 676 /* No mandatory locks over NFS */
608 if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK) 677 if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
609 return -ENOLCK; 678 goto out_err;
679
680 if (NFS_PROTO(inode)->lock_check_bounds != NULL) {
681 ret = NFS_PROTO(inode)->lock_check_bounds(fl);
682 if (ret < 0)
683 goto out_err;
684 }
610 685
611 if (IS_GETLK(cmd)) 686 if (IS_GETLK(cmd))
612 return do_getlk(filp, cmd, fl); 687 ret = do_getlk(filp, cmd, fl);
613 if (fl->fl_type == F_UNLCK) 688 else if (fl->fl_type == F_UNLCK)
614 return do_unlk(filp, cmd, fl); 689 ret = do_unlk(filp, cmd, fl);
615 return do_setlk(filp, cmd, fl); 690 else
691 ret = do_setlk(filp, cmd, fl);
692out_err:
693 return ret;
616} 694}
617 695
618/* 696/*
@@ -620,9 +698,9 @@ static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
620 */ 698 */
621static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl) 699static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
622{ 700{
623 dprintk("NFS: nfs_flock(f=%s/%ld, t=%x, fl=%x)\n", 701 dprintk("NFS: flock(%s/%s, t=%x, fl=%x)\n",
624 filp->f_path.dentry->d_inode->i_sb->s_id, 702 filp->f_path.dentry->d_parent->d_name.name,
625 filp->f_path.dentry->d_inode->i_ino, 703 filp->f_path.dentry->d_name.name,
626 fl->fl_type, fl->fl_flags); 704 fl->fl_type, fl->fl_flags);
627 705
628 /* 706 /*
@@ -645,12 +723,15 @@ static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
645 return do_setlk(filp, cmd, fl); 723 return do_setlk(filp, cmd, fl);
646} 724}
647 725
726/*
727 * There is no protocol support for leases, so we have no way to implement
728 * them correctly in the face of opens by other clients.
729 */
648static int nfs_setlease(struct file *file, long arg, struct file_lock **fl) 730static int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
649{ 731{
650 /* 732 dprintk("NFS: setlease(%s/%s, arg=%ld)\n",
651 * There is no protocol support for leases, so we have no way 733 file->f_path.dentry->d_parent->d_name.name,
652 * to implement them correctly in the face of opens by other 734 file->f_path.dentry->d_name.name, arg);
653 * clients. 735
654 */
655 return -EINVAL; 736 return -EINVAL;
656} 737}