file.c 19 KB

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