file.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * (C) 2001 Clemson University and The University of Chicago
  4. *
  5. * See COPYING in top-level directory.
  6. */
  7. /*
  8. * Linux VFS file operations.
  9. */
  10. #include "protocol.h"
  11. #include "orangefs-kernel.h"
  12. #include "orangefs-bufmap.h"
  13. #include <linux/fs.h>
  14. #include <linux/pagemap.h>
  15. static int flush_racache(struct inode *inode)
  16. {
  17. struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
  18. struct orangefs_kernel_op_s *new_op;
  19. int ret;
  20. gossip_debug(GOSSIP_UTILS_DEBUG,
  21. "%s: %pU: Handle is %pU | fs_id %d\n", __func__,
  22. get_khandle_from_ino(inode), &orangefs_inode->refn.khandle,
  23. orangefs_inode->refn.fs_id);
  24. new_op = op_alloc(ORANGEFS_VFS_OP_RA_FLUSH);
  25. if (!new_op)
  26. return -ENOMEM;
  27. new_op->upcall.req.ra_cache_flush.refn = orangefs_inode->refn;
  28. ret = service_operation(new_op, "orangefs_flush_racache",
  29. get_interruptible_flag(inode));
  30. gossip_debug(GOSSIP_UTILS_DEBUG, "%s: got return value of %d\n",
  31. __func__, ret);
  32. op_release(new_op);
  33. return ret;
  34. }
  35. /*
  36. * Post and wait for the I/O upcall to finish
  37. */
  38. static ssize_t wait_for_direct_io(enum ORANGEFS_io_type type, struct inode *inode,
  39. loff_t *offset, struct iov_iter *iter,
  40. size_t total_size, loff_t readahead_size)
  41. {
  42. struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
  43. struct orangefs_khandle *handle = &orangefs_inode->refn.khandle;
  44. struct orangefs_kernel_op_s *new_op = NULL;
  45. int buffer_index = -1;
  46. ssize_t ret;
  47. new_op = op_alloc(ORANGEFS_VFS_OP_FILE_IO);
  48. if (!new_op)
  49. return -ENOMEM;
  50. /* synchronous I/O */
  51. new_op->upcall.req.io.readahead_size = readahead_size;
  52. new_op->upcall.req.io.io_type = type;
  53. new_op->upcall.req.io.refn = orangefs_inode->refn;
  54. populate_shared_memory:
  55. /* get a shared buffer index */
  56. buffer_index = orangefs_bufmap_get();
  57. if (buffer_index < 0) {
  58. ret = buffer_index;
  59. gossip_debug(GOSSIP_FILE_DEBUG,
  60. "%s: orangefs_bufmap_get failure (%zd)\n",
  61. __func__, ret);
  62. goto out;
  63. }
  64. gossip_debug(GOSSIP_FILE_DEBUG,
  65. "%s(%pU): GET op %p -> buffer_index %d\n",
  66. __func__,
  67. handle,
  68. new_op,
  69. buffer_index);
  70. new_op->uses_shared_memory = 1;
  71. new_op->upcall.req.io.buf_index = buffer_index;
  72. new_op->upcall.req.io.count = total_size;
  73. new_op->upcall.req.io.offset = *offset;
  74. gossip_debug(GOSSIP_FILE_DEBUG,
  75. "%s(%pU): offset: %llu total_size: %zd\n",
  76. __func__,
  77. handle,
  78. llu(*offset),
  79. total_size);
  80. /*
  81. * Stage 1: copy the buffers into client-core's address space
  82. */
  83. if (type == ORANGEFS_IO_WRITE && total_size) {
  84. ret = orangefs_bufmap_copy_from_iovec(iter, buffer_index,
  85. total_size);
  86. if (ret < 0) {
  87. gossip_err("%s: Failed to copy-in buffers. Please make sure that the pvfs2-client is running. %ld\n",
  88. __func__, (long)ret);
  89. goto out;
  90. }
  91. }
  92. gossip_debug(GOSSIP_FILE_DEBUG,
  93. "%s(%pU): Calling post_io_request with tag (%llu)\n",
  94. __func__,
  95. handle,
  96. llu(new_op->tag));
  97. /* Stage 2: Service the I/O operation */
  98. ret = service_operation(new_op,
  99. type == ORANGEFS_IO_WRITE ?
  100. "file_write" :
  101. "file_read",
  102. get_interruptible_flag(inode));
  103. /*
  104. * If service_operation() returns -EAGAIN #and# the operation was
  105. * purged from orangefs_request_list or htable_ops_in_progress, then
  106. * we know that the client was restarted, causing the shared memory
  107. * area to be wiped clean. To restart a write operation in this
  108. * case, we must re-copy the data from the user's iovec to a NEW
  109. * shared memory location. To restart a read operation, we must get
  110. * a new shared memory location.
  111. */
  112. if (ret == -EAGAIN && op_state_purged(new_op)) {
  113. orangefs_bufmap_put(buffer_index);
  114. buffer_index = -1;
  115. if (type == ORANGEFS_IO_WRITE)
  116. iov_iter_revert(iter, total_size);
  117. gossip_debug(GOSSIP_FILE_DEBUG,
  118. "%s:going to repopulate_shared_memory.\n",
  119. __func__);
  120. goto populate_shared_memory;
  121. }
  122. if (ret < 0) {
  123. if (ret == -EINTR) {
  124. /*
  125. * We can't return EINTR if any data was written,
  126. * it's not POSIX. It is minimally acceptable
  127. * to give a partial write, the way NFS does.
  128. *
  129. * It would be optimal to return all or nothing,
  130. * but if a userspace write is bigger than
  131. * an IO buffer, and the interrupt occurs
  132. * between buffer writes, that would not be
  133. * possible.
  134. */
  135. switch (new_op->op_state - OP_VFS_STATE_GIVEN_UP) {
  136. /*
  137. * If the op was waiting when the interrupt
  138. * occurred, then the client-core did not
  139. * trigger the write.
  140. */
  141. case OP_VFS_STATE_WAITING:
  142. if (*offset == 0)
  143. ret = -EINTR;
  144. else
  145. ret = 0;
  146. break;
  147. /*
  148. * If the op was in progress when the interrupt
  149. * occurred, then the client-core was able to
  150. * trigger the write.
  151. */
  152. case OP_VFS_STATE_INPROGR:
  153. ret = total_size;
  154. break;
  155. default:
  156. gossip_err("%s: unexpected op state :%d:.\n",
  157. __func__,
  158. new_op->op_state);
  159. ret = 0;
  160. break;
  161. }
  162. gossip_debug(GOSSIP_FILE_DEBUG,
  163. "%s: got EINTR, state:%d: %p\n",
  164. __func__,
  165. new_op->op_state,
  166. new_op);
  167. } else {
  168. gossip_err("%s: error in %s handle %pU, returning %zd\n",
  169. __func__,
  170. type == ORANGEFS_IO_READ ?
  171. "read from" : "write to",
  172. handle, ret);
  173. }
  174. if (orangefs_cancel_op_in_progress(new_op))
  175. return ret;
  176. goto out;
  177. }
  178. /*
  179. * Stage 3: Post copy buffers from client-core's address space
  180. */
  181. if (type == ORANGEFS_IO_READ && new_op->downcall.resp.io.amt_complete) {
  182. /*
  183. * NOTE: the iovector can either contain addresses which
  184. * can futher be kernel-space or user-space addresses.
  185. * or it can pointers to struct page's
  186. */
  187. ret = orangefs_bufmap_copy_to_iovec(iter, buffer_index,
  188. new_op->downcall.resp.io.amt_complete);
  189. if (ret < 0) {
  190. gossip_err("%s: Failed to copy-out buffers. Please make sure that the pvfs2-client is running (%ld)\n",
  191. __func__, (long)ret);
  192. goto out;
  193. }
  194. }
  195. gossip_debug(GOSSIP_FILE_DEBUG,
  196. "%s(%pU): Amount %s, returned by the sys-io call:%d\n",
  197. __func__,
  198. handle,
  199. type == ORANGEFS_IO_READ ? "read" : "written",
  200. (int)new_op->downcall.resp.io.amt_complete);
  201. ret = new_op->downcall.resp.io.amt_complete;
  202. out:
  203. if (buffer_index >= 0) {
  204. orangefs_bufmap_put(buffer_index);
  205. gossip_debug(GOSSIP_FILE_DEBUG,
  206. "%s(%pU): PUT buffer_index %d\n",
  207. __func__, handle, buffer_index);
  208. buffer_index = -1;
  209. }
  210. op_release(new_op);
  211. return ret;
  212. }
  213. /*
  214. * Common entry point for read/write/readv/writev
  215. * This function will dispatch it to either the direct I/O
  216. * or buffered I/O path depending on the mount options and/or
  217. * augmented/extended metadata attached to the file.
  218. * Note: File extended attributes override any mount options.
  219. */
  220. static ssize_t do_readv_writev(enum ORANGEFS_io_type type, struct file *file,
  221. loff_t *offset, struct iov_iter *iter)
  222. {
  223. struct inode *inode = file->f_mapping->host;
  224. struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
  225. struct orangefs_khandle *handle = &orangefs_inode->refn.khandle;
  226. size_t count = iov_iter_count(iter);
  227. ssize_t total_count = 0;
  228. ssize_t ret = -EINVAL;
  229. gossip_debug(GOSSIP_FILE_DEBUG,
  230. "%s-BEGIN(%pU): count(%d) after estimate_max_iovecs.\n",
  231. __func__,
  232. handle,
  233. (int)count);
  234. if (type == ORANGEFS_IO_WRITE) {
  235. gossip_debug(GOSSIP_FILE_DEBUG,
  236. "%s(%pU): proceeding with offset : %llu, "
  237. "size %d\n",
  238. __func__,
  239. handle,
  240. llu(*offset),
  241. (int)count);
  242. }
  243. if (count == 0) {
  244. ret = 0;
  245. goto out;
  246. }
  247. while (iov_iter_count(iter)) {
  248. size_t each_count = iov_iter_count(iter);
  249. size_t amt_complete;
  250. /* how much to transfer in this loop iteration */
  251. if (each_count > orangefs_bufmap_size_query())
  252. each_count = orangefs_bufmap_size_query();
  253. gossip_debug(GOSSIP_FILE_DEBUG,
  254. "%s(%pU): size of each_count(%d)\n",
  255. __func__,
  256. handle,
  257. (int)each_count);
  258. gossip_debug(GOSSIP_FILE_DEBUG,
  259. "%s(%pU): BEFORE wait_for_io: offset is %d\n",
  260. __func__,
  261. handle,
  262. (int)*offset);
  263. ret = wait_for_direct_io(type, inode, offset, iter,
  264. each_count, 0);
  265. gossip_debug(GOSSIP_FILE_DEBUG,
  266. "%s(%pU): return from wait_for_io:%d\n",
  267. __func__,
  268. handle,
  269. (int)ret);
  270. if (ret < 0)
  271. goto out;
  272. *offset += ret;
  273. total_count += ret;
  274. amt_complete = ret;
  275. gossip_debug(GOSSIP_FILE_DEBUG,
  276. "%s(%pU): AFTER wait_for_io: offset is %d\n",
  277. __func__,
  278. handle,
  279. (int)*offset);
  280. /*
  281. * if we got a short I/O operations,
  282. * fall out and return what we got so far
  283. */
  284. if (amt_complete < each_count)
  285. break;
  286. } /*end while */
  287. out:
  288. if (total_count > 0)
  289. ret = total_count;
  290. if (ret > 0) {
  291. if (type == ORANGEFS_IO_READ) {
  292. file_accessed(file);
  293. } else {
  294. file_update_time(file);
  295. /*
  296. * Must invalidate to ensure write loop doesn't
  297. * prevent kernel from reading updated
  298. * attribute. Size probably changed because of
  299. * the write, and other clients could update
  300. * any other attribute.
  301. */
  302. orangefs_inode->getattr_time = jiffies - 1;
  303. }
  304. }
  305. gossip_debug(GOSSIP_FILE_DEBUG,
  306. "%s(%pU): Value(%d) returned.\n",
  307. __func__,
  308. handle,
  309. (int)ret);
  310. return ret;
  311. }
  312. /*
  313. * Read data from a specified offset in a file (referenced by inode).
  314. * Data may be placed either in a user or kernel buffer.
  315. */
  316. ssize_t orangefs_inode_read(struct inode *inode,
  317. struct iov_iter *iter,
  318. loff_t *offset,
  319. loff_t readahead_size)
  320. {
  321. struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
  322. size_t count = iov_iter_count(iter);
  323. size_t bufmap_size;
  324. ssize_t ret = -EINVAL;
  325. orangefs_stats.reads++;
  326. bufmap_size = orangefs_bufmap_size_query();
  327. if (count > bufmap_size) {
  328. gossip_debug(GOSSIP_FILE_DEBUG,
  329. "%s: count is too large (%zd/%zd)!\n",
  330. __func__, count, bufmap_size);
  331. return -EINVAL;
  332. }
  333. gossip_debug(GOSSIP_FILE_DEBUG,
  334. "%s(%pU) %zd@%llu\n",
  335. __func__,
  336. &orangefs_inode->refn.khandle,
  337. count,
  338. llu(*offset));
  339. ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, offset, iter,
  340. count, readahead_size);
  341. if (ret > 0)
  342. *offset += ret;
  343. gossip_debug(GOSSIP_FILE_DEBUG,
  344. "%s(%pU): Value(%zd) returned.\n",
  345. __func__,
  346. &orangefs_inode->refn.khandle,
  347. ret);
  348. return ret;
  349. }
  350. static ssize_t orangefs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
  351. {
  352. struct file *file = iocb->ki_filp;
  353. loff_t pos = iocb->ki_pos;
  354. ssize_t rc = 0;
  355. BUG_ON(iocb->private);
  356. gossip_debug(GOSSIP_FILE_DEBUG, "orangefs_file_read_iter\n");
  357. orangefs_stats.reads++;
  358. rc = do_readv_writev(ORANGEFS_IO_READ, file, &pos, iter);
  359. iocb->ki_pos = pos;
  360. return rc;
  361. }
  362. static ssize_t orangefs_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
  363. {
  364. struct file *file = iocb->ki_filp;
  365. loff_t pos;
  366. ssize_t rc;
  367. BUG_ON(iocb->private);
  368. gossip_debug(GOSSIP_FILE_DEBUG, "orangefs_file_write_iter\n");
  369. inode_lock(file->f_mapping->host);
  370. /* Make sure generic_write_checks sees an up to date inode size. */
  371. if (file->f_flags & O_APPEND) {
  372. rc = orangefs_inode_getattr(file->f_mapping->host, 0, 1,
  373. STATX_SIZE);
  374. if (rc == -ESTALE)
  375. rc = -EIO;
  376. if (rc) {
  377. gossip_err("%s: orangefs_inode_getattr failed, "
  378. "rc:%zd:.\n", __func__, rc);
  379. goto out;
  380. }
  381. }
  382. rc = generic_write_checks(iocb, iter);
  383. if (rc <= 0) {
  384. gossip_err("%s: generic_write_checks failed, rc:%zd:.\n",
  385. __func__, rc);
  386. goto out;
  387. }
  388. /*
  389. * if we are appending, generic_write_checks would have updated
  390. * pos to the end of the file, so we will wait till now to set
  391. * pos...
  392. */
  393. pos = iocb->ki_pos;
  394. rc = do_readv_writev(ORANGEFS_IO_WRITE,
  395. file,
  396. &pos,
  397. iter);
  398. if (rc < 0) {
  399. gossip_err("%s: do_readv_writev failed, rc:%zd:.\n",
  400. __func__, rc);
  401. goto out;
  402. }
  403. iocb->ki_pos = pos;
  404. orangefs_stats.writes++;
  405. out:
  406. inode_unlock(file->f_mapping->host);
  407. return rc;
  408. }
  409. /*
  410. * Perform a miscellaneous operation on a file.
  411. */
  412. static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  413. {
  414. int ret = -ENOTTY;
  415. __u64 val = 0;
  416. unsigned long uval;
  417. gossip_debug(GOSSIP_FILE_DEBUG,
  418. "orangefs_ioctl: called with cmd %d\n",
  419. cmd);
  420. /*
  421. * we understand some general ioctls on files, such as the immutable
  422. * and append flags
  423. */
  424. if (cmd == FS_IOC_GETFLAGS) {
  425. val = 0;
  426. ret = orangefs_inode_getxattr(file_inode(file),
  427. "user.pvfs2.meta_hint",
  428. &val, sizeof(val));
  429. if (ret < 0 && ret != -ENODATA)
  430. return ret;
  431. else if (ret == -ENODATA)
  432. val = 0;
  433. uval = val;
  434. gossip_debug(GOSSIP_FILE_DEBUG,
  435. "orangefs_ioctl: FS_IOC_GETFLAGS: %llu\n",
  436. (unsigned long long)uval);
  437. return put_user(uval, (int __user *)arg);
  438. } else if (cmd == FS_IOC_SETFLAGS) {
  439. ret = 0;
  440. if (get_user(uval, (int __user *)arg))
  441. return -EFAULT;
  442. /*
  443. * ORANGEFS_MIRROR_FL is set internally when the mirroring mode
  444. * is turned on for a file. The user is not allowed to turn
  445. * on this bit, but the bit is present if the user first gets
  446. * the flags and then updates the flags with some new
  447. * settings. So, we ignore it in the following edit. bligon.
  448. */
  449. if ((uval & ~ORANGEFS_MIRROR_FL) &
  450. (~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NOATIME_FL))) {
  451. gossip_err("orangefs_ioctl: the FS_IOC_SETFLAGS only supports setting one of FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NOATIME_FL\n");
  452. return -EINVAL;
  453. }
  454. val = uval;
  455. gossip_debug(GOSSIP_FILE_DEBUG,
  456. "orangefs_ioctl: FS_IOC_SETFLAGS: %llu\n",
  457. (unsigned long long)val);
  458. ret = orangefs_inode_setxattr(file_inode(file),
  459. "user.pvfs2.meta_hint",
  460. &val, sizeof(val), 0);
  461. }
  462. return ret;
  463. }
  464. static vm_fault_t orangefs_fault(struct vm_fault *vmf)
  465. {
  466. struct file *file = vmf->vma->vm_file;
  467. int ret;
  468. ret = orangefs_inode_getattr(file->f_mapping->host, 0, 1,
  469. STATX_SIZE);
  470. if (ret == -ESTALE)
  471. ret = -EIO;
  472. if (ret) {
  473. gossip_err("%s: orangefs_inode_getattr failed, ret:%d:.\n",
  474. __func__, ret);
  475. return VM_FAULT_SIGBUS;
  476. }
  477. return filemap_fault(vmf);
  478. }
  479. static const struct vm_operations_struct orangefs_file_vm_ops = {
  480. .fault = orangefs_fault,
  481. .map_pages = filemap_map_pages,
  482. .page_mkwrite = filemap_page_mkwrite,
  483. };
  484. /*
  485. * Memory map a region of a file.
  486. */
  487. static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma)
  488. {
  489. gossip_debug(GOSSIP_FILE_DEBUG,
  490. "orangefs_file_mmap: called on %s\n",
  491. (file ?
  492. (char *)file->f_path.dentry->d_name.name :
  493. (char *)"Unknown"));
  494. if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
  495. return -EINVAL;
  496. /* set the sequential readahead hint */
  497. vma->vm_flags |= VM_SEQ_READ;
  498. vma->vm_flags &= ~VM_RAND_READ;
  499. file_accessed(file);
  500. vma->vm_ops = &orangefs_file_vm_ops;
  501. return 0;
  502. }
  503. #define mapping_nrpages(idata) ((idata)->nrpages)
  504. /*
  505. * Called to notify the module that there are no more references to
  506. * this file (i.e. no processes have it open).
  507. *
  508. * \note Not called when each file is closed.
  509. */
  510. static int orangefs_file_release(struct inode *inode, struct file *file)
  511. {
  512. gossip_debug(GOSSIP_FILE_DEBUG,
  513. "orangefs_file_release: called on %pD\n",
  514. file);
  515. /*
  516. * remove all associated inode pages from the page cache and
  517. * readahead cache (if any); this forces an expensive refresh of
  518. * data for the next caller of mmap (or 'get_block' accesses)
  519. */
  520. if (file_inode(file) &&
  521. file_inode(file)->i_mapping &&
  522. mapping_nrpages(&file_inode(file)->i_data)) {
  523. if (orangefs_features & ORANGEFS_FEATURE_READAHEAD) {
  524. gossip_debug(GOSSIP_INODE_DEBUG,
  525. "calling flush_racache on %pU\n",
  526. get_khandle_from_ino(inode));
  527. flush_racache(inode);
  528. gossip_debug(GOSSIP_INODE_DEBUG,
  529. "flush_racache finished\n");
  530. }
  531. truncate_inode_pages(file_inode(file)->i_mapping,
  532. 0);
  533. }
  534. return 0;
  535. }
  536. /*
  537. * Push all data for a specific file onto permanent storage.
  538. */
  539. static int orangefs_fsync(struct file *file,
  540. loff_t start,
  541. loff_t end,
  542. int datasync)
  543. {
  544. int ret;
  545. struct orangefs_inode_s *orangefs_inode =
  546. ORANGEFS_I(file_inode(file));
  547. struct orangefs_kernel_op_s *new_op = NULL;
  548. new_op = op_alloc(ORANGEFS_VFS_OP_FSYNC);
  549. if (!new_op)
  550. return -ENOMEM;
  551. new_op->upcall.req.fsync.refn = orangefs_inode->refn;
  552. ret = service_operation(new_op,
  553. "orangefs_fsync",
  554. get_interruptible_flag(file_inode(file)));
  555. gossip_debug(GOSSIP_FILE_DEBUG,
  556. "orangefs_fsync got return value of %d\n",
  557. ret);
  558. op_release(new_op);
  559. return ret;
  560. }
  561. /*
  562. * Change the file pointer position for an instance of an open file.
  563. *
  564. * \note If .llseek is overriden, we must acquire lock as described in
  565. * Documentation/filesystems/Locking.
  566. *
  567. * Future upgrade could support SEEK_DATA and SEEK_HOLE but would
  568. * require much changes to the FS
  569. */
  570. static loff_t orangefs_file_llseek(struct file *file, loff_t offset, int origin)
  571. {
  572. int ret = -EINVAL;
  573. struct inode *inode = file_inode(file);
  574. if (origin == SEEK_END) {
  575. /*
  576. * revalidate the inode's file size.
  577. * NOTE: We are only interested in file size here,
  578. * so we set mask accordingly.
  579. */
  580. ret = orangefs_inode_getattr(file->f_mapping->host, 0, 1,
  581. STATX_SIZE);
  582. if (ret == -ESTALE)
  583. ret = -EIO;
  584. if (ret) {
  585. gossip_debug(GOSSIP_FILE_DEBUG,
  586. "%s:%s:%d calling make bad inode\n",
  587. __FILE__,
  588. __func__,
  589. __LINE__);
  590. return ret;
  591. }
  592. }
  593. gossip_debug(GOSSIP_FILE_DEBUG,
  594. "orangefs_file_llseek: offset is %ld | origin is %d"
  595. " | inode size is %lu\n",
  596. (long)offset,
  597. origin,
  598. (unsigned long)i_size_read(inode));
  599. return generic_file_llseek(file, offset, origin);
  600. }
  601. /*
  602. * Support local locks (locks that only this kernel knows about)
  603. * if Orangefs was mounted -o local_lock.
  604. */
  605. static int orangefs_lock(struct file *filp, int cmd, struct file_lock *fl)
  606. {
  607. int rc = -EINVAL;
  608. if (ORANGEFS_SB(file_inode(filp)->i_sb)->flags & ORANGEFS_OPT_LOCAL_LOCK) {
  609. if (cmd == F_GETLK) {
  610. rc = 0;
  611. posix_test_lock(filp, fl);
  612. } else {
  613. rc = posix_lock_file(filp, fl, NULL);
  614. }
  615. }
  616. return rc;
  617. }
  618. /** ORANGEFS implementation of VFS file operations */
  619. const struct file_operations orangefs_file_operations = {
  620. .llseek = orangefs_file_llseek,
  621. .read_iter = orangefs_file_read_iter,
  622. .write_iter = orangefs_file_write_iter,
  623. .lock = orangefs_lock,
  624. .unlocked_ioctl = orangefs_ioctl,
  625. .mmap = orangefs_file_mmap,
  626. .open = generic_file_open,
  627. .release = orangefs_file_release,
  628. .fsync = orangefs_fsync,
  629. };