file.c 19 KB

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