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. .mmap = nfs_file_mmap,
  61. .open = nfs_file_open,
  62. .flush = nfs_file_flush,
  63. .release = nfs_file_release,
  64. .fsync = nfs_fsync,
  65. .lock = nfs_lock,
  66. .flock = nfs_flock,
  67. .splice_read = nfs_file_splice_read,
  68. .check_flags = nfs_check_flags,
  69. .setlease = nfs_setlease,
  70. };
  71. const struct inode_operations nfs_file_inode_operations = {
  72. .permission = nfs_permission,
  73. .getattr = nfs_getattr,
  74. .setattr = nfs_setattr,
  75. };
  76. #ifdef CONFIG_NFS_V3
  77. const struct inode_operations nfs3_file_inode_operations = {
  78. .permission = nfs_permission,
  79. .getattr = nfs_getattr,
  80. .setattr = nfs_setattr,
  81. .listxattr = nfs3_listxattr,
  82. .getxattr = nfs3_getxattr,
  83. .setxattr = nfs3_setxattr,
  84. .removexattr = nfs3_removexattr,
  85. };
  86. #endif /* CONFIG_NFS_v3 */
  87. /* Hack for future NFS swap support */
  88. #ifndef IS_SWAPFILE
  89. # define IS_SWAPFILE(inode) (0)
  90. #endif
  91. static int nfs_check_flags(int flags)
  92. {
  93. if ((flags & (O_APPEND | O_DIRECT)) == (O_APPEND | O_DIRECT))
  94. return -EINVAL;
  95. return 0;
  96. }
  97. /*
  98. * Open file
  99. */
  100. static int
  101. nfs_file_open(struct inode *inode, struct file *filp)
  102. {
  103. int res;
  104. res = nfs_check_flags(filp->f_flags);
  105. if (res)
  106. return res;
  107. nfs_inc_stats(inode, NFSIOS_VFSOPEN);
  108. lock_kernel();
  109. res = NFS_PROTO(inode)->file_open(inode, filp);
  110. unlock_kernel();
  111. return res;
  112. }
  113. static int
  114. nfs_file_release(struct inode *inode, struct file *filp)
  115. {
  116. /* Ensure that dirty pages are flushed out with the right creds */
  117. if (filp->f_mode & FMODE_WRITE)
  118. nfs_wb_all(filp->f_path.dentry->d_inode);
  119. nfs_inc_stats(inode, NFSIOS_VFSRELEASE);
  120. return NFS_PROTO(inode)->file_release(inode, filp);
  121. }
  122. /**
  123. * nfs_revalidate_size - Revalidate the file size
  124. * @inode - pointer to inode struct
  125. * @file - pointer to struct file
  126. *
  127. * Revalidates the file length. This is basically a wrapper around
  128. * nfs_revalidate_inode() that takes into account the fact that we may
  129. * have cached writes (in which case we don't care about the server's
  130. * idea of what the file length is), or O_DIRECT (in which case we
  131. * shouldn't trust the cache).
  132. */
  133. static int nfs_revalidate_file_size(struct inode *inode, struct file *filp)
  134. {
  135. struct nfs_server *server = NFS_SERVER(inode);
  136. struct nfs_inode *nfsi = NFS_I(inode);
  137. if (server->flags & NFS_MOUNT_NOAC)
  138. goto force_reval;
  139. if (filp->f_flags & O_DIRECT)
  140. goto force_reval;
  141. if (nfsi->npages != 0)
  142. return 0;
  143. if (!(nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) && !nfs_attribute_timeout(inode))
  144. return 0;
  145. force_reval:
  146. return __nfs_revalidate_inode(server, inode);
  147. }
  148. static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
  149. {
  150. /* origin == SEEK_END => we must revalidate the cached file length */
  151. if (origin == SEEK_END) {
  152. struct inode *inode = filp->f_mapping->host;
  153. int retval = nfs_revalidate_file_size(inode, filp);
  154. if (retval < 0)
  155. return (loff_t)retval;
  156. }
  157. return remote_llseek(filp, offset, origin);
  158. }
  159. /*
  160. * Helper for nfs_file_flush() and nfs_fsync()
  161. *
  162. * Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to
  163. * disk, but it retrieves and clears ctx->error after synching, despite
  164. * the two being set at the same time in nfs_context_set_write_error().
  165. * This is because the former is used to notify the _next_ call to
  166. * nfs_file_write() that a write error occured, and hence cause it to
  167. * fall back to doing a synchronous write.
  168. */
  169. static int nfs_do_fsync(struct nfs_open_context *ctx, struct inode *inode)
  170. {
  171. int have_error, status;
  172. int ret = 0;
  173. have_error = test_and_clear_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
  174. status = nfs_wb_all(inode);
  175. have_error |= test_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
  176. if (have_error)
  177. ret = xchg(&ctx->error, 0);
  178. if (!ret)
  179. ret = status;
  180. return ret;
  181. }
  182. /*
  183. * Flush all dirty pages, and check for write errors.
  184. *
  185. */
  186. static int
  187. nfs_file_flush(struct file *file, fl_owner_t id)
  188. {
  189. struct nfs_open_context *ctx = nfs_file_open_context(file);
  190. struct inode *inode = file->f_path.dentry->d_inode;
  191. int status;
  192. dfprintk(VFS, "nfs: flush(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
  193. if ((file->f_mode & FMODE_WRITE) == 0)
  194. return 0;
  195. nfs_inc_stats(inode, NFSIOS_VFSFLUSH);
  196. /* Ensure that data+attribute caches are up to date after close() */
  197. status = nfs_do_fsync(ctx, inode);
  198. if (!status)
  199. nfs_revalidate_inode(NFS_SERVER(inode), inode);
  200. return status;
  201. }
  202. static ssize_t
  203. nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
  204. unsigned long nr_segs, loff_t pos)
  205. {
  206. struct dentry * dentry = iocb->ki_filp->f_path.dentry;
  207. struct inode * inode = dentry->d_inode;
  208. ssize_t result;
  209. size_t count = iov_length(iov, nr_segs);
  210. if (iocb->ki_filp->f_flags & O_DIRECT)
  211. return nfs_file_direct_read(iocb, iov, nr_segs, pos);
  212. dfprintk(VFS, "nfs: read(%s/%s, %lu@%lu)\n",
  213. dentry->d_parent->d_name.name, dentry->d_name.name,
  214. (unsigned long) count, (unsigned long) pos);
  215. result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
  216. nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, count);
  217. if (!result)
  218. result = generic_file_aio_read(iocb, iov, nr_segs, pos);
  219. return result;
  220. }
  221. static ssize_t
  222. nfs_file_splice_read(struct file *filp, loff_t *ppos,
  223. struct pipe_inode_info *pipe, size_t count,
  224. unsigned int flags)
  225. {
  226. struct dentry *dentry = filp->f_path.dentry;
  227. struct inode *inode = dentry->d_inode;
  228. ssize_t res;
  229. dfprintk(VFS, "nfs: splice_read(%s/%s, %lu@%Lu)\n",
  230. dentry->d_parent->d_name.name, dentry->d_name.name,
  231. (unsigned long) count, (unsigned long long) *ppos);
  232. res = nfs_revalidate_mapping(inode, filp->f_mapping);
  233. if (!res)
  234. res = generic_file_splice_read(filp, ppos, pipe, count, flags);
  235. return res;
  236. }
  237. static int
  238. nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
  239. {
  240. struct dentry *dentry = file->f_path.dentry;
  241. struct inode *inode = dentry->d_inode;
  242. int status;
  243. dfprintk(VFS, "nfs: mmap(%s/%s)\n",
  244. dentry->d_parent->d_name.name, dentry->d_name.name);
  245. status = nfs_revalidate_mapping(inode, file->f_mapping);
  246. if (!status) {
  247. vma->vm_ops = &nfs_file_vm_ops;
  248. vma->vm_flags |= VM_CAN_NONLINEAR;
  249. file_accessed(file);
  250. }
  251. return status;
  252. }
  253. /*
  254. * Flush any dirty pages for this process, and check for write errors.
  255. * The return status from this call provides a reliable indication of
  256. * whether any write errors occurred for this process.
  257. */
  258. static int
  259. nfs_fsync(struct file *file, struct dentry *dentry, int datasync)
  260. {
  261. struct nfs_open_context *ctx = nfs_file_open_context(file);
  262. struct inode *inode = dentry->d_inode;
  263. dfprintk(VFS, "nfs: fsync(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
  264. nfs_inc_stats(inode, NFSIOS_VFSFSYNC);
  265. return nfs_do_fsync(ctx, inode);
  266. }
  267. /*
  268. * This does the "real" work of the write. We must allocate and lock the
  269. * page to be sent back to the generic routine, which then copies the
  270. * data from user space.
  271. *
  272. * If the writer ends up delaying the write, the writer needs to
  273. * increment the page use counts until he is done with the page.
  274. */
  275. static int nfs_write_begin(struct file *file, struct address_space *mapping,
  276. loff_t pos, unsigned len, unsigned flags,
  277. struct page **pagep, void **fsdata)
  278. {
  279. int ret;
  280. pgoff_t index;
  281. struct page *page;
  282. index = pos >> PAGE_CACHE_SHIFT;
  283. page = __grab_cache_page(mapping, index);
  284. if (!page)
  285. return -ENOMEM;
  286. *pagep = page;
  287. ret = nfs_flush_incompatible(file, page);
  288. if (ret) {
  289. unlock_page(page);
  290. page_cache_release(page);
  291. }
  292. return ret;
  293. }
  294. static int nfs_write_end(struct file *file, struct address_space *mapping,
  295. loff_t pos, unsigned len, unsigned copied,
  296. struct page *page, void *fsdata)
  297. {
  298. unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
  299. int status;
  300. lock_kernel();
  301. status = nfs_updatepage(file, page, offset, copied);
  302. unlock_kernel();
  303. unlock_page(page);
  304. page_cache_release(page);
  305. if (status < 0)
  306. return status;
  307. return copied;
  308. }
  309. static void nfs_invalidate_page(struct page *page, unsigned long offset)
  310. {
  311. if (offset != 0)
  312. return;
  313. /* Cancel any unstarted writes on this page */
  314. nfs_wb_page_cancel(page->mapping->host, page);
  315. }
  316. static int nfs_release_page(struct page *page, gfp_t gfp)
  317. {
  318. /* If PagePrivate() is set, then the page is not freeable */
  319. return 0;
  320. }
  321. static int nfs_launder_page(struct page *page)
  322. {
  323. return nfs_wb_page(page->mapping->host, page);
  324. }
  325. const struct address_space_operations nfs_file_aops = {
  326. .readpage = nfs_readpage,
  327. .readpages = nfs_readpages,
  328. .set_page_dirty = __set_page_dirty_nobuffers,
  329. .writepage = nfs_writepage,
  330. .writepages = nfs_writepages,
  331. .write_begin = nfs_write_begin,
  332. .write_end = nfs_write_end,
  333. .invalidatepage = nfs_invalidate_page,
  334. .releasepage = nfs_release_page,
  335. .direct_IO = nfs_direct_IO,
  336. .launder_page = nfs_launder_page,
  337. };
  338. static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct page *page)
  339. {
  340. struct file *filp = vma->vm_file;
  341. unsigned pagelen;
  342. int ret = -EINVAL;
  343. struct address_space *mapping;
  344. lock_page(page);
  345. mapping = page->mapping;
  346. if (mapping != vma->vm_file->f_path.dentry->d_inode->i_mapping)
  347. goto out_unlock;
  348. ret = 0;
  349. pagelen = nfs_page_length(page);
  350. if (pagelen == 0)
  351. goto out_unlock;
  352. ret = nfs_flush_incompatible(filp, page);
  353. if (ret != 0)
  354. goto out_unlock;
  355. ret = nfs_updatepage(filp, page, 0, pagelen);
  356. if (ret == 0)
  357. ret = pagelen;
  358. out_unlock:
  359. unlock_page(page);
  360. return ret;
  361. }
  362. static struct vm_operations_struct nfs_file_vm_ops = {
  363. .fault = filemap_fault,
  364. .page_mkwrite = nfs_vm_page_mkwrite,
  365. };
  366. static int nfs_need_sync_write(struct file *filp, struct inode *inode)
  367. {
  368. struct nfs_open_context *ctx;
  369. if (IS_SYNC(inode) || (filp->f_flags & O_SYNC))
  370. return 1;
  371. ctx = nfs_file_open_context(filp);
  372. if (test_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags))
  373. return 1;
  374. return 0;
  375. }
  376. static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
  377. unsigned long nr_segs, loff_t pos)
  378. {
  379. struct dentry * dentry = iocb->ki_filp->f_path.dentry;
  380. struct inode * inode = dentry->d_inode;
  381. ssize_t result;
  382. size_t count = iov_length(iov, nr_segs);
  383. if (iocb->ki_filp->f_flags & O_DIRECT)
  384. return nfs_file_direct_write(iocb, iov, nr_segs, pos);
  385. dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%Ld)\n",
  386. dentry->d_parent->d_name.name, dentry->d_name.name,
  387. inode->i_ino, (unsigned long) count, (long long) pos);
  388. result = -EBUSY;
  389. if (IS_SWAPFILE(inode))
  390. goto out_swapfile;
  391. /*
  392. * O_APPEND implies that we must revalidate the file length.
  393. */
  394. if (iocb->ki_filp->f_flags & O_APPEND) {
  395. result = nfs_revalidate_file_size(inode, iocb->ki_filp);
  396. if (result)
  397. goto out;
  398. }
  399. result = count;
  400. if (!count)
  401. goto out;
  402. nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, count);
  403. result = generic_file_aio_write(iocb, iov, nr_segs, pos);
  404. /* Return error values for O_SYNC and IS_SYNC() */
  405. if (result >= 0 && nfs_need_sync_write(iocb->ki_filp, inode)) {
  406. int err = nfs_do_fsync(nfs_file_open_context(iocb->ki_filp), inode);
  407. if (err < 0)
  408. result = err;
  409. }
  410. out:
  411. return result;
  412. out_swapfile:
  413. printk(KERN_INFO "NFS: attempt to write to active swap file!\n");
  414. goto out;
  415. }
  416. static int do_getlk(struct file *filp, int cmd, struct file_lock *fl)
  417. {
  418. struct inode *inode = filp->f_mapping->host;
  419. int status = 0;
  420. lock_kernel();
  421. /* Try local locking first */
  422. posix_test_lock(filp, fl);
  423. if (fl->fl_type != F_UNLCK) {
  424. /* found a conflict */
  425. goto out;
  426. }
  427. if (nfs_have_delegation(inode, FMODE_READ))
  428. goto out_noconflict;
  429. if (NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)
  430. goto out_noconflict;
  431. status = NFS_PROTO(inode)->lock(filp, cmd, fl);
  432. out:
  433. unlock_kernel();
  434. return status;
  435. out_noconflict:
  436. fl->fl_type = F_UNLCK;
  437. goto out;
  438. }
  439. static int do_vfs_lock(struct file *file, struct file_lock *fl)
  440. {
  441. int res = 0;
  442. switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
  443. case FL_POSIX:
  444. res = posix_lock_file_wait(file, fl);
  445. break;
  446. case FL_FLOCK:
  447. res = flock_lock_file_wait(file, fl);
  448. break;
  449. default:
  450. BUG();
  451. }
  452. if (res < 0)
  453. dprintk(KERN_WARNING "%s: VFS is out of sync with lock manager"
  454. " - error %d!\n",
  455. __FUNCTION__, res);
  456. return res;
  457. }
  458. static int do_unlk(struct file *filp, int cmd, struct file_lock *fl)
  459. {
  460. struct inode *inode = filp->f_mapping->host;
  461. int status;
  462. /*
  463. * Flush all pending writes before doing anything
  464. * with locks..
  465. */
  466. nfs_sync_mapping(filp->f_mapping);
  467. /* NOTE: special case
  468. * If we're signalled while cleaning up locks on process exit, we
  469. * still need to complete the unlock.
  470. */
  471. lock_kernel();
  472. /* Use local locking if mounted with "-onolock" */
  473. if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM))
  474. status = NFS_PROTO(inode)->lock(filp, cmd, fl);
  475. else
  476. status = do_vfs_lock(filp, fl);
  477. unlock_kernel();
  478. return status;
  479. }
  480. static int do_setlk(struct file *filp, int cmd, struct file_lock *fl)
  481. {
  482. struct inode *inode = filp->f_mapping->host;
  483. int status;
  484. /*
  485. * Flush all pending writes before doing anything
  486. * with locks..
  487. */
  488. status = nfs_sync_mapping(filp->f_mapping);
  489. if (status != 0)
  490. goto out;
  491. lock_kernel();
  492. /* Use local locking if mounted with "-onolock" */
  493. if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)) {
  494. status = NFS_PROTO(inode)->lock(filp, cmd, fl);
  495. /* If we were signalled we still need to ensure that
  496. * we clean up any state on the server. We therefore
  497. * record the lock call as having succeeded in order to
  498. * ensure that locks_remove_posix() cleans it out when
  499. * the process exits.
  500. */
  501. if (status == -EINTR || status == -ERESTARTSYS)
  502. do_vfs_lock(filp, 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. }