file.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. loff_t loff;
  155. /* origin == SEEK_END => we must revalidate the cached file length */
  156. if (origin == SEEK_END) {
  157. struct inode *inode = filp->f_mapping->host;
  158. int retval = nfs_revalidate_file_size(inode, filp);
  159. if (retval < 0)
  160. return (loff_t)retval;
  161. }
  162. lock_kernel(); /* BKL needed? */
  163. loff = generic_file_llseek_unlocked(filp, offset, origin);
  164. unlock_kernel();
  165. return loff;
  166. }
  167. /*
  168. * Helper for nfs_file_flush() and nfs_fsync()
  169. *
  170. * Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to
  171. * disk, but it retrieves and clears ctx->error after synching, despite
  172. * the two being set at the same time in nfs_context_set_write_error().
  173. * This is because the former is used to notify the _next_ call to
  174. * nfs_file_write() that a write error occured, and hence cause it to
  175. * fall back to doing a synchronous write.
  176. */
  177. static int nfs_do_fsync(struct nfs_open_context *ctx, struct inode *inode)
  178. {
  179. int have_error, status;
  180. int ret = 0;
  181. have_error = test_and_clear_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
  182. status = nfs_wb_all(inode);
  183. have_error |= test_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
  184. if (have_error)
  185. ret = xchg(&ctx->error, 0);
  186. if (!ret)
  187. ret = status;
  188. return ret;
  189. }
  190. /*
  191. * Flush all dirty pages, and check for write errors.
  192. *
  193. */
  194. static int
  195. nfs_file_flush(struct file *file, fl_owner_t id)
  196. {
  197. struct nfs_open_context *ctx = nfs_file_open_context(file);
  198. struct inode *inode = file->f_path.dentry->d_inode;
  199. int status;
  200. dfprintk(VFS, "nfs: flush(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
  201. if ((file->f_mode & FMODE_WRITE) == 0)
  202. return 0;
  203. nfs_inc_stats(inode, NFSIOS_VFSFLUSH);
  204. /* Ensure that data+attribute caches are up to date after close() */
  205. status = nfs_do_fsync(ctx, inode);
  206. if (!status)
  207. nfs_revalidate_inode(NFS_SERVER(inode), inode);
  208. return status;
  209. }
  210. static ssize_t
  211. nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
  212. unsigned long nr_segs, loff_t pos)
  213. {
  214. struct dentry * dentry = iocb->ki_filp->f_path.dentry;
  215. struct inode * inode = dentry->d_inode;
  216. ssize_t result;
  217. size_t count = iov_length(iov, nr_segs);
  218. if (iocb->ki_filp->f_flags & O_DIRECT)
  219. return nfs_file_direct_read(iocb, iov, nr_segs, pos);
  220. dfprintk(VFS, "nfs: read(%s/%s, %lu@%lu)\n",
  221. dentry->d_parent->d_name.name, dentry->d_name.name,
  222. (unsigned long) count, (unsigned long) pos);
  223. result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
  224. nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, count);
  225. if (!result)
  226. result = generic_file_aio_read(iocb, iov, nr_segs, pos);
  227. return result;
  228. }
  229. static ssize_t
  230. nfs_file_splice_read(struct file *filp, loff_t *ppos,
  231. struct pipe_inode_info *pipe, size_t count,
  232. unsigned int flags)
  233. {
  234. struct dentry *dentry = filp->f_path.dentry;
  235. struct inode *inode = dentry->d_inode;
  236. ssize_t res;
  237. dfprintk(VFS, "nfs: splice_read(%s/%s, %lu@%Lu)\n",
  238. dentry->d_parent->d_name.name, dentry->d_name.name,
  239. (unsigned long) count, (unsigned long long) *ppos);
  240. res = nfs_revalidate_mapping(inode, filp->f_mapping);
  241. if (!res)
  242. res = generic_file_splice_read(filp, ppos, pipe, count, flags);
  243. return res;
  244. }
  245. static int
  246. nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
  247. {
  248. struct dentry *dentry = file->f_path.dentry;
  249. struct inode *inode = dentry->d_inode;
  250. int status;
  251. dfprintk(VFS, "nfs: mmap(%s/%s)\n",
  252. dentry->d_parent->d_name.name, dentry->d_name.name);
  253. status = nfs_revalidate_mapping(inode, file->f_mapping);
  254. if (!status) {
  255. vma->vm_ops = &nfs_file_vm_ops;
  256. vma->vm_flags |= VM_CAN_NONLINEAR;
  257. file_accessed(file);
  258. }
  259. return status;
  260. }
  261. /*
  262. * Flush any dirty pages for this process, and check for write errors.
  263. * The return status from this call provides a reliable indication of
  264. * whether any write errors occurred for this process.
  265. */
  266. static int
  267. nfs_fsync(struct file *file, struct dentry *dentry, int datasync)
  268. {
  269. struct nfs_open_context *ctx = nfs_file_open_context(file);
  270. struct inode *inode = dentry->d_inode;
  271. dfprintk(VFS, "nfs: fsync(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
  272. nfs_inc_stats(inode, NFSIOS_VFSFSYNC);
  273. return nfs_do_fsync(ctx, inode);
  274. }
  275. /*
  276. * This does the "real" work of the write. We must allocate and lock the
  277. * page to be sent back to the generic routine, which then copies the
  278. * data from user space.
  279. *
  280. * If the writer ends up delaying the write, the writer needs to
  281. * increment the page use counts until he is done with the page.
  282. */
  283. static int nfs_write_begin(struct file *file, struct address_space *mapping,
  284. loff_t pos, unsigned len, unsigned flags,
  285. struct page **pagep, void **fsdata)
  286. {
  287. int ret;
  288. pgoff_t index;
  289. struct page *page;
  290. index = pos >> PAGE_CACHE_SHIFT;
  291. page = __grab_cache_page(mapping, index);
  292. if (!page)
  293. return -ENOMEM;
  294. *pagep = page;
  295. ret = nfs_flush_incompatible(file, page);
  296. if (ret) {
  297. unlock_page(page);
  298. page_cache_release(page);
  299. }
  300. return ret;
  301. }
  302. static int nfs_write_end(struct file *file, struct address_space *mapping,
  303. loff_t pos, unsigned len, unsigned copied,
  304. struct page *page, void *fsdata)
  305. {
  306. unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
  307. int status;
  308. lock_kernel();
  309. status = nfs_updatepage(file, page, offset, copied);
  310. unlock_kernel();
  311. unlock_page(page);
  312. page_cache_release(page);
  313. if (status < 0)
  314. return status;
  315. return copied;
  316. }
  317. static void nfs_invalidate_page(struct page *page, unsigned long offset)
  318. {
  319. if (offset != 0)
  320. return;
  321. /* Cancel any unstarted writes on this page */
  322. nfs_wb_page_cancel(page->mapping->host, page);
  323. }
  324. static int nfs_release_page(struct page *page, gfp_t gfp)
  325. {
  326. /* If PagePrivate() is set, then the page is not freeable */
  327. return 0;
  328. }
  329. static int nfs_launder_page(struct page *page)
  330. {
  331. return nfs_wb_page(page->mapping->host, page);
  332. }
  333. const struct address_space_operations nfs_file_aops = {
  334. .readpage = nfs_readpage,
  335. .readpages = nfs_readpages,
  336. .set_page_dirty = __set_page_dirty_nobuffers,
  337. .writepage = nfs_writepage,
  338. .writepages = nfs_writepages,
  339. .write_begin = nfs_write_begin,
  340. .write_end = nfs_write_end,
  341. .invalidatepage = nfs_invalidate_page,
  342. .releasepage = nfs_release_page,
  343. .direct_IO = nfs_direct_IO,
  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. if (iocb->ki_filp->f_flags & O_DIRECT)
  392. return nfs_file_direct_write(iocb, iov, nr_segs, pos);
  393. dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%Ld)\n",
  394. dentry->d_parent->d_name.name, dentry->d_name.name,
  395. inode->i_ino, (unsigned long) count, (long long) pos);
  396. result = -EBUSY;
  397. if (IS_SWAPFILE(inode))
  398. goto out_swapfile;
  399. /*
  400. * O_APPEND implies that we must revalidate the file length.
  401. */
  402. if (iocb->ki_filp->f_flags & O_APPEND) {
  403. result = nfs_revalidate_file_size(inode, iocb->ki_filp);
  404. if (result)
  405. goto out;
  406. }
  407. result = count;
  408. if (!count)
  409. goto out;
  410. nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, count);
  411. result = generic_file_aio_write(iocb, iov, nr_segs, pos);
  412. /* Return error values for O_SYNC and IS_SYNC() */
  413. if (result >= 0 && nfs_need_sync_write(iocb->ki_filp, inode)) {
  414. int err = nfs_do_fsync(nfs_file_open_context(iocb->ki_filp), inode);
  415. if (err < 0)
  416. result = err;
  417. }
  418. out:
  419. return result;
  420. out_swapfile:
  421. printk(KERN_INFO "NFS: attempt to write to active swap file!\n");
  422. goto out;
  423. }
  424. static int do_getlk(struct file *filp, int cmd, struct file_lock *fl)
  425. {
  426. struct inode *inode = filp->f_mapping->host;
  427. int status = 0;
  428. lock_kernel();
  429. /* Try local locking first */
  430. posix_test_lock(filp, fl);
  431. if (fl->fl_type != F_UNLCK) {
  432. /* found a conflict */
  433. goto out;
  434. }
  435. if (nfs_have_delegation(inode, FMODE_READ))
  436. goto out_noconflict;
  437. if (NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)
  438. goto out_noconflict;
  439. status = NFS_PROTO(inode)->lock(filp, cmd, fl);
  440. out:
  441. unlock_kernel();
  442. return status;
  443. out_noconflict:
  444. fl->fl_type = F_UNLCK;
  445. goto out;
  446. }
  447. static int do_vfs_lock(struct file *file, struct file_lock *fl)
  448. {
  449. int res = 0;
  450. switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
  451. case FL_POSIX:
  452. res = posix_lock_file_wait(file, fl);
  453. break;
  454. case FL_FLOCK:
  455. res = flock_lock_file_wait(file, fl);
  456. break;
  457. default:
  458. BUG();
  459. }
  460. if (res < 0)
  461. dprintk(KERN_WARNING "%s: VFS is out of sync with lock manager"
  462. " - error %d!\n",
  463. __func__, res);
  464. return res;
  465. }
  466. static int do_unlk(struct file *filp, int cmd, struct file_lock *fl)
  467. {
  468. struct inode *inode = filp->f_mapping->host;
  469. int status;
  470. /*
  471. * Flush all pending writes before doing anything
  472. * with locks..
  473. */
  474. nfs_sync_mapping(filp->f_mapping);
  475. /* NOTE: special case
  476. * If we're signalled while cleaning up locks on process exit, we
  477. * still need to complete the unlock.
  478. */
  479. lock_kernel();
  480. /* Use local locking if mounted with "-onolock" */
  481. if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM))
  482. status = NFS_PROTO(inode)->lock(filp, cmd, fl);
  483. else
  484. status = do_vfs_lock(filp, fl);
  485. unlock_kernel();
  486. return status;
  487. }
  488. static int do_setlk(struct file *filp, int cmd, struct file_lock *fl)
  489. {
  490. struct inode *inode = filp->f_mapping->host;
  491. int status;
  492. /*
  493. * Flush all pending writes before doing anything
  494. * with locks..
  495. */
  496. status = nfs_sync_mapping(filp->f_mapping);
  497. if (status != 0)
  498. goto out;
  499. lock_kernel();
  500. /* Use local locking if mounted with "-onolock" */
  501. if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM))
  502. status = NFS_PROTO(inode)->lock(filp, cmd, fl);
  503. else
  504. status = do_vfs_lock(filp, fl);
  505. unlock_kernel();
  506. if (status < 0)
  507. goto out;
  508. /*
  509. * Make sure we clear the cache whenever we try to get the lock.
  510. * This makes locking act as a cache coherency point.
  511. */
  512. nfs_sync_mapping(filp->f_mapping);
  513. nfs_zap_caches(inode);
  514. out:
  515. return status;
  516. }
  517. /*
  518. * Lock a (portion of) a file
  519. */
  520. static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
  521. {
  522. struct inode * inode = filp->f_mapping->host;
  523. dprintk("NFS: nfs_lock(f=%s/%ld, t=%x, fl=%x, r=%Ld:%Ld)\n",
  524. inode->i_sb->s_id, inode->i_ino,
  525. fl->fl_type, fl->fl_flags,
  526. (long long)fl->fl_start, (long long)fl->fl_end);
  527. nfs_inc_stats(inode, NFSIOS_VFSLOCK);
  528. /* No mandatory locks over NFS */
  529. if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
  530. return -ENOLCK;
  531. if (IS_GETLK(cmd))
  532. return do_getlk(filp, cmd, fl);
  533. if (fl->fl_type == F_UNLCK)
  534. return do_unlk(filp, cmd, fl);
  535. return do_setlk(filp, cmd, fl);
  536. }
  537. /*
  538. * Lock a (portion of) a file
  539. */
  540. static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
  541. {
  542. dprintk("NFS: nfs_flock(f=%s/%ld, t=%x, fl=%x)\n",
  543. filp->f_path.dentry->d_inode->i_sb->s_id,
  544. filp->f_path.dentry->d_inode->i_ino,
  545. fl->fl_type, fl->fl_flags);
  546. /*
  547. * No BSD flocks over NFS allowed.
  548. * Note: we could try to fake a POSIX lock request here by
  549. * using ((u32) filp | 0x80000000) or some such as the pid.
  550. * Not sure whether that would be unique, though, or whether
  551. * that would break in other places.
  552. */
  553. if (!(fl->fl_flags & FL_FLOCK))
  554. return -ENOLCK;
  555. /* We're simulating flock() locks using posix locks on the server */
  556. fl->fl_owner = (fl_owner_t)filp;
  557. fl->fl_start = 0;
  558. fl->fl_end = OFFSET_MAX;
  559. if (fl->fl_type == F_UNLCK)
  560. return do_unlk(filp, cmd, fl);
  561. return do_setlk(filp, cmd, fl);
  562. }
  563. static int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
  564. {
  565. /*
  566. * There is no protocol support for leases, so we have no way
  567. * to implement them correctly in the face of opens by other
  568. * clients.
  569. */
  570. return -EINVAL;
  571. }