file.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * linux/fs/nfs/file.c
  3. *
  4. * Copyright (C) 1992 Rick Sladkey
  5. *
  6. * Changes Copyright (C) 1994 by Florian La Roche
  7. * - Do not copy data too often around in the kernel.
  8. * - In nfs_file_read the return value of kmalloc wasn't checked.
  9. * - Put in a better version of read look-ahead buffering. Original idea
  10. * and implementation by Wai S Kok elekokws@ee.nus.sg.
  11. *
  12. * Expire cache on write to a file by Wai S Kok (Oct 1994).
  13. *
  14. * Total rewrite of read side for new NFS buffer cache.. Linus.
  15. *
  16. * nfs regular file handling functions
  17. */
  18. #include <linux/time.h>
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/fcntl.h>
  22. #include <linux/stat.h>
  23. #include <linux/nfs_fs.h>
  24. #include <linux/nfs_mount.h>
  25. #include <linux/mm.h>
  26. #include <linux/slab.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/smp_lock.h>
  29. #include <linux/aio.h>
  30. #include <asm/uaccess.h>
  31. #include <asm/system.h>
  32. #include "delegation.h"
  33. #include "internal.h"
  34. #include "iostat.h"
  35. #define NFSDBG_FACILITY NFSDBG_FILE
  36. static int nfs_file_open(struct inode *, struct file *);
  37. static int nfs_file_release(struct inode *, struct file *);
  38. static loff_t nfs_file_llseek(struct file *file, loff_t offset, int origin);
  39. static int nfs_file_mmap(struct file *, struct vm_area_struct *);
  40. static ssize_t nfs_file_splice_read(struct file *filp, loff_t *ppos,
  41. struct pipe_inode_info *pipe,
  42. size_t count, unsigned int flags);
  43. static ssize_t nfs_file_read(struct kiocb *, const struct iovec *iov,
  44. unsigned long nr_segs, loff_t pos);
  45. static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov,
  46. unsigned long nr_segs, loff_t pos);
  47. static int nfs_file_flush(struct file *, fl_owner_t id);
  48. static int nfs_fsync(struct file *, struct dentry *dentry, int datasync);
  49. static int nfs_check_flags(int flags);
  50. static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl);
  51. static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl);
  52. static int nfs_setlease(struct file *file, long arg, struct file_lock **fl);
  53. static struct vm_operations_struct nfs_file_vm_ops;
  54. const struct file_operations nfs_file_operations = {
  55. .llseek = nfs_file_llseek,
  56. .read = do_sync_read,
  57. .write = do_sync_write,
  58. .aio_read = nfs_file_read,
  59. .aio_write = nfs_file_write,
  60. #ifdef CONFIG_MMU
  61. .mmap = nfs_file_mmap,
  62. #else
  63. .mmap = generic_file_mmap,
  64. #endif
  65. .open = nfs_file_open,
  66. .flush = nfs_file_flush,
  67. .release = nfs_file_release,
  68. .fsync = nfs_fsync,
  69. .lock = nfs_lock,
  70. .flock = nfs_flock,
  71. .splice_read = nfs_file_splice_read,
  72. .check_flags = nfs_check_flags,
  73. .setlease = nfs_setlease,
  74. };
  75. const struct inode_operations nfs_file_inode_operations = {
  76. .permission = nfs_permission,
  77. .getattr = nfs_getattr,
  78. .setattr = nfs_setattr,
  79. };
  80. #ifdef CONFIG_NFS_V3
  81. const struct inode_operations nfs3_file_inode_operations = {
  82. .permission = nfs_permission,
  83. .getattr = nfs_getattr,
  84. .setattr = nfs_setattr,
  85. .listxattr = nfs3_listxattr,
  86. .getxattr = nfs3_getxattr,
  87. .setxattr = nfs3_setxattr,
  88. .removexattr = nfs3_removexattr,
  89. };
  90. #endif /* CONFIG_NFS_v3 */
  91. /* Hack for future NFS swap support */
  92. #ifndef IS_SWAPFILE
  93. # define IS_SWAPFILE(inode) (0)
  94. #endif
  95. static int nfs_check_flags(int flags)
  96. {
  97. if ((flags & (O_APPEND | O_DIRECT)) == (O_APPEND | O_DIRECT))
  98. return -EINVAL;
  99. return 0;
  100. }
  101. /*
  102. * Open file
  103. */
  104. static int
  105. nfs_file_open(struct inode *inode, struct file *filp)
  106. {
  107. int res;
  108. res = nfs_check_flags(filp->f_flags);
  109. if (res)
  110. return res;
  111. nfs_inc_stats(inode, NFSIOS_VFSOPEN);
  112. lock_kernel();
  113. res = NFS_PROTO(inode)->file_open(inode, filp);
  114. unlock_kernel();
  115. return res;
  116. }
  117. static int
  118. nfs_file_release(struct inode *inode, struct file *filp)
  119. {
  120. /* Ensure that dirty pages are flushed out with the right creds */
  121. if (filp->f_mode & FMODE_WRITE)
  122. nfs_wb_all(filp->f_path.dentry->d_inode);
  123. nfs_inc_stats(inode, NFSIOS_VFSRELEASE);
  124. return NFS_PROTO(inode)->file_release(inode, filp);
  125. }
  126. /**
  127. * nfs_revalidate_size - Revalidate the file size
  128. * @inode - pointer to inode struct
  129. * @file - pointer to struct file
  130. *
  131. * Revalidates the file length. This is basically a wrapper around
  132. * nfs_revalidate_inode() that takes into account the fact that we may
  133. * have cached writes (in which case we don't care about the server's
  134. * idea of what the file length is), or O_DIRECT (in which case we
  135. * shouldn't trust the cache).
  136. */
  137. static int nfs_revalidate_file_size(struct inode *inode, struct file *filp)
  138. {
  139. struct nfs_server *server = NFS_SERVER(inode);
  140. struct nfs_inode *nfsi = NFS_I(inode);
  141. if (server->flags & NFS_MOUNT_NOAC)
  142. goto force_reval;
  143. if (filp->f_flags & O_DIRECT)
  144. goto force_reval;
  145. if (nfsi->npages != 0)
  146. return 0;
  147. if (!(nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) && !nfs_attribute_timeout(inode))
  148. return 0;
  149. force_reval:
  150. return __nfs_revalidate_inode(server, inode);
  151. }
  152. static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
  153. {
  154. /* origin == SEEK_END => we must revalidate the cached file length */
  155. if (origin == SEEK_END) {
  156. struct inode *inode = filp->f_mapping->host;
  157. int retval = nfs_revalidate_file_size(inode, filp);
  158. if (retval < 0)
  159. return (loff_t)retval;
  160. }
  161. return remote_llseek(filp, offset, origin);
  162. }
  163. /*
  164. * Helper for nfs_file_flush() and nfs_fsync()
  165. *
  166. * Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to
  167. * disk, but it retrieves and clears ctx->error after synching, despite
  168. * the two being set at the same time in nfs_context_set_write_error().
  169. * This is because the former is used to notify the _next_ call to
  170. * nfs_file_write() that a write error occured, and hence cause it to
  171. * fall back to doing a synchronous write.
  172. */
  173. static int nfs_do_fsync(struct nfs_open_context *ctx, struct inode *inode)
  174. {
  175. int have_error, status;
  176. int ret = 0;
  177. have_error = test_and_clear_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
  178. status = nfs_wb_all(inode);
  179. have_error |= test_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
  180. if (have_error)
  181. ret = xchg(&ctx->error, 0);
  182. if (!ret)
  183. ret = status;
  184. return ret;
  185. }
  186. /*
  187. * Flush all dirty pages, and check for write errors.
  188. *
  189. */
  190. static int
  191. nfs_file_flush(struct file *file, fl_owner_t id)
  192. {
  193. struct nfs_open_context *ctx = nfs_file_open_context(file);
  194. struct inode *inode = file->f_path.dentry->d_inode;
  195. int status;
  196. dfprintk(VFS, "nfs: flush(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
  197. if ((file->f_mode & FMODE_WRITE) == 0)
  198. return 0;
  199. nfs_inc_stats(inode, NFSIOS_VFSFLUSH);
  200. /* Ensure that data+attribute caches are up to date after close() */
  201. status = nfs_do_fsync(ctx, inode);
  202. if (!status)
  203. nfs_revalidate_inode(NFS_SERVER(inode), inode);
  204. return status;
  205. }
  206. static ssize_t
  207. nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
  208. unsigned long nr_segs, loff_t pos)
  209. {
  210. struct dentry * dentry = iocb->ki_filp->f_path.dentry;
  211. struct inode * inode = dentry->d_inode;
  212. ssize_t result;
  213. size_t count = iov_length(iov, nr_segs);
  214. #ifdef CONFIG_NFS_DIRECTIO
  215. if (iocb->ki_filp->f_flags & O_DIRECT)
  216. return nfs_file_direct_read(iocb, iov, nr_segs, pos);
  217. #endif
  218. dfprintk(VFS, "nfs: read(%s/%s, %lu@%lu)\n",
  219. dentry->d_parent->d_name.name, dentry->d_name.name,
  220. (unsigned long) count, (unsigned long) pos);
  221. result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
  222. nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, count);
  223. if (!result)
  224. result = generic_file_aio_read(iocb, iov, nr_segs, pos);
  225. return result;
  226. }
  227. static ssize_t
  228. nfs_file_splice_read(struct file *filp, loff_t *ppos,
  229. struct pipe_inode_info *pipe, size_t count,
  230. unsigned int flags)
  231. {
  232. struct dentry *dentry = filp->f_path.dentry;
  233. struct inode *inode = dentry->d_inode;
  234. ssize_t res;
  235. dfprintk(VFS, "nfs: splice_read(%s/%s, %lu@%Lu)\n",
  236. dentry->d_parent->d_name.name, dentry->d_name.name,
  237. (unsigned long) count, (unsigned long long) *ppos);
  238. res = nfs_revalidate_mapping(inode, filp->f_mapping);
  239. if (!res)
  240. res = generic_file_splice_read(filp, ppos, pipe, count, flags);
  241. return res;
  242. }
  243. static int
  244. nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
  245. {
  246. struct dentry *dentry = file->f_path.dentry;
  247. struct inode *inode = dentry->d_inode;
  248. int status;
  249. dfprintk(VFS, "nfs: mmap(%s/%s)\n",
  250. dentry->d_parent->d_name.name, dentry->d_name.name);
  251. status = nfs_revalidate_mapping(inode, file->f_mapping);
  252. if (!status) {
  253. vma->vm_ops = &nfs_file_vm_ops;
  254. vma->vm_flags |= VM_CAN_NONLINEAR;
  255. file_accessed(file);
  256. }
  257. return status;
  258. }
  259. /*
  260. * Flush any dirty pages for this process, and check for write errors.
  261. * The return status from this call provides a reliable indication of
  262. * whether any write errors occurred for this process.
  263. */
  264. static int
  265. nfs_fsync(struct file *file, struct dentry *dentry, int datasync)
  266. {
  267. struct nfs_open_context *ctx = nfs_file_open_context(file);
  268. struct inode *inode = dentry->d_inode;
  269. dfprintk(VFS, "nfs: fsync(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
  270. nfs_inc_stats(inode, NFSIOS_VFSFSYNC);
  271. return nfs_do_fsync(ctx, inode);
  272. }
  273. /*
  274. * This does the "real" work of the write. We must allocate and lock the
  275. * page to be sent back to the generic routine, which then copies the
  276. * data from user space.
  277. *
  278. * If the writer ends up delaying the write, the writer needs to
  279. * increment the page use counts until he is done with the page.
  280. */
  281. static int nfs_write_begin(struct file *file, struct address_space *mapping,
  282. loff_t pos, unsigned len, unsigned flags,
  283. struct page **pagep, void **fsdata)
  284. {
  285. int ret;
  286. pgoff_t index;
  287. struct page *page;
  288. index = pos >> PAGE_CACHE_SHIFT;
  289. page = __grab_cache_page(mapping, index);
  290. if (!page)
  291. return -ENOMEM;
  292. *pagep = page;
  293. ret = nfs_flush_incompatible(file, page);
  294. if (ret) {
  295. unlock_page(page);
  296. page_cache_release(page);
  297. }
  298. return ret;
  299. }
  300. static int nfs_write_end(struct file *file, struct address_space *mapping,
  301. loff_t pos, unsigned len, unsigned copied,
  302. struct page *page, void *fsdata)
  303. {
  304. unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
  305. int status;
  306. lock_kernel();
  307. status = nfs_updatepage(file, page, offset, copied);
  308. unlock_kernel();
  309. unlock_page(page);
  310. page_cache_release(page);
  311. if (status < 0)
  312. return status;
  313. return copied;
  314. }
  315. static void nfs_invalidate_page(struct page *page, unsigned long offset)
  316. {
  317. if (offset != 0)
  318. return;
  319. /* Cancel any unstarted writes on this page */
  320. nfs_wb_page_cancel(page->mapping->host, page);
  321. }
  322. static int nfs_release_page(struct page *page, gfp_t gfp)
  323. {
  324. /* If PagePrivate() is set, then the page is not freeable */
  325. return 0;
  326. }
  327. static int nfs_launder_page(struct page *page)
  328. {
  329. return nfs_wb_page(page->mapping->host, page);
  330. }
  331. const struct address_space_operations nfs_file_aops = {
  332. .readpage = nfs_readpage,
  333. .readpages = nfs_readpages,
  334. .set_page_dirty = __set_page_dirty_nobuffers,
  335. .writepage = nfs_writepage,
  336. .writepages = nfs_writepages,
  337. .write_begin = nfs_write_begin,
  338. .write_end = nfs_write_end,
  339. .invalidatepage = nfs_invalidate_page,
  340. .releasepage = nfs_release_page,
  341. #ifdef CONFIG_NFS_DIRECTIO
  342. .direct_IO = nfs_direct_IO,
  343. #endif
  344. .launder_page = nfs_launder_page,
  345. };
  346. static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct page *page)
  347. {
  348. struct file *filp = vma->vm_file;
  349. unsigned pagelen;
  350. int ret = -EINVAL;
  351. struct address_space *mapping;
  352. lock_page(page);
  353. mapping = page->mapping;
  354. if (mapping != vma->vm_file->f_path.dentry->d_inode->i_mapping)
  355. goto out_unlock;
  356. ret = 0;
  357. pagelen = nfs_page_length(page);
  358. if (pagelen == 0)
  359. goto out_unlock;
  360. ret = nfs_flush_incompatible(filp, page);
  361. if (ret != 0)
  362. goto out_unlock;
  363. ret = nfs_updatepage(filp, page, 0, pagelen);
  364. if (ret == 0)
  365. ret = pagelen;
  366. out_unlock:
  367. unlock_page(page);
  368. return ret;
  369. }
  370. static struct vm_operations_struct nfs_file_vm_ops = {
  371. .fault = filemap_fault,
  372. .page_mkwrite = nfs_vm_page_mkwrite,
  373. };
  374. static int nfs_need_sync_write(struct file *filp, struct inode *inode)
  375. {
  376. struct nfs_open_context *ctx;
  377. if (IS_SYNC(inode) || (filp->f_flags & O_SYNC))
  378. return 1;
  379. ctx = nfs_file_open_context(filp);
  380. if (test_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags))
  381. return 1;
  382. return 0;
  383. }
  384. static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
  385. unsigned long nr_segs, loff_t pos)
  386. {
  387. struct dentry * dentry = iocb->ki_filp->f_path.dentry;
  388. struct inode * inode = dentry->d_inode;
  389. ssize_t result;
  390. size_t count = iov_length(iov, nr_segs);
  391. #ifdef CONFIG_NFS_DIRECTIO
  392. if (iocb->ki_filp->f_flags & O_DIRECT)
  393. return nfs_file_direct_write(iocb, iov, nr_segs, pos);
  394. #endif
  395. dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%Ld)\n",
  396. dentry->d_parent->d_name.name, dentry->d_name.name,
  397. inode->i_ino, (unsigned long) count, (long long) pos);
  398. result = -EBUSY;
  399. if (IS_SWAPFILE(inode))
  400. goto out_swapfile;
  401. /*
  402. * O_APPEND implies that we must revalidate the file length.
  403. */
  404. if (iocb->ki_filp->f_flags & O_APPEND) {
  405. result = nfs_revalidate_file_size(inode, iocb->ki_filp);
  406. if (result)
  407. goto out;
  408. }
  409. result = count;
  410. if (!count)
  411. goto out;
  412. nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, count);
  413. result = generic_file_aio_write(iocb, iov, nr_segs, pos);
  414. /* Return error values for O_SYNC and IS_SYNC() */
  415. if (result >= 0 && nfs_need_sync_write(iocb->ki_filp, inode)) {
  416. int err = nfs_do_fsync(nfs_file_open_context(iocb->ki_filp), inode);
  417. if (err < 0)
  418. result = err;
  419. }
  420. out:
  421. return result;
  422. out_swapfile:
  423. printk(KERN_INFO "NFS: attempt to write to active swap file!\n");
  424. goto out;
  425. }
  426. static int do_getlk(struct file *filp, int cmd, struct file_lock *fl)
  427. {
  428. struct inode *inode = filp->f_mapping->host;
  429. int status = 0;
  430. lock_kernel();
  431. /* Try local locking first */
  432. posix_test_lock(filp, fl);
  433. if (fl->fl_type != F_UNLCK) {
  434. /* found a conflict */
  435. goto out;
  436. }
  437. if (nfs_have_delegation(inode, FMODE_READ))
  438. goto out_noconflict;
  439. if (NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)
  440. goto out_noconflict;
  441. status = NFS_PROTO(inode)->lock(filp, cmd, fl);
  442. out:
  443. unlock_kernel();
  444. return status;
  445. out_noconflict:
  446. fl->fl_type = F_UNLCK;
  447. goto out;
  448. }
  449. static int do_vfs_lock(struct file *file, struct file_lock *fl)
  450. {
  451. int res = 0;
  452. switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
  453. case FL_POSIX:
  454. res = posix_lock_file_wait(file, fl);
  455. break;
  456. case FL_FLOCK:
  457. res = flock_lock_file_wait(file, fl);
  458. break;
  459. default:
  460. BUG();
  461. }
  462. if (res < 0)
  463. dprintk(KERN_WARNING "%s: VFS is out of sync with lock manager"
  464. " - error %d!\n",
  465. __FUNCTION__, res);
  466. return res;
  467. }
  468. static int do_unlk(struct file *filp, int cmd, struct file_lock *fl)
  469. {
  470. struct inode *inode = filp->f_mapping->host;
  471. int status;
  472. /*
  473. * Flush all pending writes before doing anything
  474. * with locks..
  475. */
  476. nfs_sync_mapping(filp->f_mapping);
  477. /* NOTE: special case
  478. * If we're signalled while cleaning up locks on process exit, we
  479. * still need to complete the unlock.
  480. */
  481. lock_kernel();
  482. /* Use local locking if mounted with "-onolock" */
  483. if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM))
  484. status = NFS_PROTO(inode)->lock(filp, cmd, fl);
  485. else
  486. status = do_vfs_lock(filp, fl);
  487. unlock_kernel();
  488. return status;
  489. }
  490. static int do_setlk(struct file *filp, int cmd, struct file_lock *fl)
  491. {
  492. struct inode *inode = filp->f_mapping->host;
  493. int status;
  494. /*
  495. * Flush all pending writes before doing anything
  496. * with locks..
  497. */
  498. status = nfs_sync_mapping(filp->f_mapping);
  499. if (status != 0)
  500. goto out;
  501. lock_kernel();
  502. /* Use local locking if mounted with "-onolock" */
  503. if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)) {
  504. status = NFS_PROTO(inode)->lock(filp, cmd, fl);
  505. /* If we were signalled we still need to ensure that
  506. * we clean up any state on the server. We therefore
  507. * record the lock call as having succeeded in order to
  508. * ensure that locks_remove_posix() cleans it out when
  509. * the process exits.
  510. */
  511. if (status == -EINTR || status == -ERESTARTSYS)
  512. do_vfs_lock(filp, fl);
  513. } else
  514. status = do_vfs_lock(filp, fl);
  515. unlock_kernel();
  516. if (status < 0)
  517. goto out;
  518. /*
  519. * Make sure we clear the cache whenever we try to get the lock.
  520. * This makes locking act as a cache coherency point.
  521. */
  522. nfs_sync_mapping(filp->f_mapping);
  523. nfs_zap_caches(inode);
  524. out:
  525. return status;
  526. }
  527. /*
  528. * Lock a (portion of) a file
  529. */
  530. static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
  531. {
  532. struct inode * inode = filp->f_mapping->host;
  533. dprintk("NFS: nfs_lock(f=%s/%ld, t=%x, fl=%x, r=%Ld:%Ld)\n",
  534. inode->i_sb->s_id, inode->i_ino,
  535. fl->fl_type, fl->fl_flags,
  536. (long long)fl->fl_start, (long long)fl->fl_end);
  537. nfs_inc_stats(inode, NFSIOS_VFSLOCK);
  538. /* No mandatory locks over NFS */
  539. if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
  540. return -ENOLCK;
  541. if (IS_GETLK(cmd))
  542. return do_getlk(filp, cmd, fl);
  543. if (fl->fl_type == F_UNLCK)
  544. return do_unlk(filp, cmd, fl);
  545. return do_setlk(filp, cmd, fl);
  546. }
  547. /*
  548. * Lock a (portion of) a file
  549. */
  550. static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
  551. {
  552. dprintk("NFS: nfs_flock(f=%s/%ld, t=%x, fl=%x)\n",
  553. filp->f_path.dentry->d_inode->i_sb->s_id,
  554. filp->f_path.dentry->d_inode->i_ino,
  555. fl->fl_type, fl->fl_flags);
  556. /*
  557. * No BSD flocks over NFS allowed.
  558. * Note: we could try to fake a POSIX lock request here by
  559. * using ((u32) filp | 0x80000000) or some such as the pid.
  560. * Not sure whether that would be unique, though, or whether
  561. * that would break in other places.
  562. */
  563. if (!(fl->fl_flags & FL_FLOCK))
  564. return -ENOLCK;
  565. /* We're simulating flock() locks using posix locks on the server */
  566. fl->fl_owner = (fl_owner_t)filp;
  567. fl->fl_start = 0;
  568. fl->fl_end = OFFSET_MAX;
  569. if (fl->fl_type == F_UNLCK)
  570. return do_unlk(filp, cmd, fl);
  571. return do_setlk(filp, cmd, fl);
  572. }
  573. static int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
  574. {
  575. /*
  576. * There is no protocol support for leases, so we have no way
  577. * to implement them correctly in the face of opens by other
  578. * clients.
  579. */
  580. return -EINVAL;
  581. }