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. struct iov_iter saved = *iter;
  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. *iter = saved;
  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. SetMtimeFlag(orangefs_inode);
  347. inode->i_mtime = current_time(inode);
  348. mark_inode_dirty_sync(inode);
  349. }
  350. }
  351. gossip_debug(GOSSIP_FILE_DEBUG,
  352. "%s(%pU): Value(%d) returned.\n",
  353. __func__,
  354. handle,
  355. (int)ret);
  356. return ret;
  357. }
  358. /*
  359. * Read data from a specified offset in a file (referenced by inode).
  360. * Data may be placed either in a user or kernel buffer.
  361. */
  362. ssize_t orangefs_inode_read(struct inode *inode,
  363. struct iov_iter *iter,
  364. loff_t *offset,
  365. loff_t readahead_size)
  366. {
  367. struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
  368. size_t count = iov_iter_count(iter);
  369. size_t bufmap_size;
  370. ssize_t ret = -EINVAL;
  371. orangefs_stats.reads++;
  372. bufmap_size = orangefs_bufmap_size_query();
  373. if (count > bufmap_size) {
  374. gossip_debug(GOSSIP_FILE_DEBUG,
  375. "%s: count is too large (%zd/%zd)!\n",
  376. __func__, count, bufmap_size);
  377. return -EINVAL;
  378. }
  379. gossip_debug(GOSSIP_FILE_DEBUG,
  380. "%s(%pU) %zd@%llu\n",
  381. __func__,
  382. &orangefs_inode->refn.khandle,
  383. count,
  384. llu(*offset));
  385. ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, offset, iter,
  386. count, readahead_size);
  387. if (ret > 0)
  388. *offset += ret;
  389. gossip_debug(GOSSIP_FILE_DEBUG,
  390. "%s(%pU): Value(%zd) returned.\n",
  391. __func__,
  392. &orangefs_inode->refn.khandle,
  393. ret);
  394. return ret;
  395. }
  396. static ssize_t orangefs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
  397. {
  398. struct file *file = iocb->ki_filp;
  399. loff_t pos = iocb->ki_pos;
  400. ssize_t rc = 0;
  401. BUG_ON(iocb->private);
  402. gossip_debug(GOSSIP_FILE_DEBUG, "orangefs_file_read_iter\n");
  403. orangefs_stats.reads++;
  404. rc = do_readv_writev(ORANGEFS_IO_READ, file, &pos, iter);
  405. iocb->ki_pos = pos;
  406. return rc;
  407. }
  408. static ssize_t orangefs_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
  409. {
  410. struct file *file = iocb->ki_filp;
  411. loff_t pos;
  412. ssize_t rc;
  413. BUG_ON(iocb->private);
  414. gossip_debug(GOSSIP_FILE_DEBUG, "orangefs_file_write_iter\n");
  415. inode_lock(file->f_mapping->host);
  416. /* Make sure generic_write_checks sees an up to date inode size. */
  417. if (file->f_flags & O_APPEND) {
  418. rc = orangefs_inode_getattr(file->f_mapping->host, 0, 1);
  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. rc = generic_write_checks(iocb, iter);
  428. if (rc <= 0) {
  429. gossip_err("%s: generic_write_checks failed, rc:%zd:.\n",
  430. __func__, rc);
  431. goto out;
  432. }
  433. /*
  434. * if we are appending, generic_write_checks would have updated
  435. * pos to the end of the file, so we will wait till now to set
  436. * pos...
  437. */
  438. pos = iocb->ki_pos;
  439. rc = do_readv_writev(ORANGEFS_IO_WRITE,
  440. file,
  441. &pos,
  442. iter);
  443. if (rc < 0) {
  444. gossip_err("%s: do_readv_writev failed, rc:%zd:.\n",
  445. __func__, rc);
  446. goto out;
  447. }
  448. iocb->ki_pos = pos;
  449. orangefs_stats.writes++;
  450. out:
  451. inode_unlock(file->f_mapping->host);
  452. return rc;
  453. }
  454. /*
  455. * Perform a miscellaneous operation on a file.
  456. */
  457. static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  458. {
  459. int ret = -ENOTTY;
  460. __u64 val = 0;
  461. unsigned long uval;
  462. gossip_debug(GOSSIP_FILE_DEBUG,
  463. "orangefs_ioctl: called with cmd %d\n",
  464. cmd);
  465. /*
  466. * we understand some general ioctls on files, such as the immutable
  467. * and append flags
  468. */
  469. if (cmd == FS_IOC_GETFLAGS) {
  470. val = 0;
  471. ret = orangefs_inode_getxattr(file_inode(file),
  472. "user.pvfs2.meta_hint",
  473. &val, sizeof(val));
  474. if (ret < 0 && ret != -ENODATA)
  475. return ret;
  476. else if (ret == -ENODATA)
  477. val = 0;
  478. uval = val;
  479. gossip_debug(GOSSIP_FILE_DEBUG,
  480. "orangefs_ioctl: FS_IOC_GETFLAGS: %llu\n",
  481. (unsigned long long)uval);
  482. return put_user(uval, (int __user *)arg);
  483. } else if (cmd == FS_IOC_SETFLAGS) {
  484. ret = 0;
  485. if (get_user(uval, (int __user *)arg))
  486. return -EFAULT;
  487. /*
  488. * ORANGEFS_MIRROR_FL is set internally when the mirroring mode
  489. * is turned on for a file. The user is not allowed to turn
  490. * on this bit, but the bit is present if the user first gets
  491. * the flags and then updates the flags with some new
  492. * settings. So, we ignore it in the following edit. bligon.
  493. */
  494. if ((uval & ~ORANGEFS_MIRROR_FL) &
  495. (~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NOATIME_FL))) {
  496. gossip_err("orangefs_ioctl: the FS_IOC_SETFLAGS only supports setting one of FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NOATIME_FL\n");
  497. return -EINVAL;
  498. }
  499. val = uval;
  500. gossip_debug(GOSSIP_FILE_DEBUG,
  501. "orangefs_ioctl: FS_IOC_SETFLAGS: %llu\n",
  502. (unsigned long long)val);
  503. ret = orangefs_inode_setxattr(file_inode(file),
  504. "user.pvfs2.meta_hint",
  505. &val, sizeof(val), 0);
  506. }
  507. return ret;
  508. }
  509. /*
  510. * Memory map a region of a file.
  511. */
  512. static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma)
  513. {
  514. gossip_debug(GOSSIP_FILE_DEBUG,
  515. "orangefs_file_mmap: called on %s\n",
  516. (file ?
  517. (char *)file->f_path.dentry->d_name.name :
  518. (char *)"Unknown"));
  519. /* set the sequential readahead hint */
  520. vma->vm_flags |= VM_SEQ_READ;
  521. vma->vm_flags &= ~VM_RAND_READ;
  522. /* Use readonly mmap since we cannot support writable maps. */
  523. return generic_file_readonly_mmap(file, vma);
  524. }
  525. #define mapping_nrpages(idata) ((idata)->nrpages)
  526. /*
  527. * Called to notify the module that there are no more references to
  528. * this file (i.e. no processes have it open).
  529. *
  530. * \note Not called when each file is closed.
  531. */
  532. static int orangefs_file_release(struct inode *inode, struct file *file)
  533. {
  534. gossip_debug(GOSSIP_FILE_DEBUG,
  535. "orangefs_file_release: called on %pD\n",
  536. file);
  537. orangefs_flush_inode(inode);
  538. /*
  539. * remove all associated inode pages from the page cache and
  540. * readahead cache (if any); this forces an expensive refresh of
  541. * data for the next caller of mmap (or 'get_block' accesses)
  542. */
  543. if (file_inode(file) &&
  544. file_inode(file)->i_mapping &&
  545. mapping_nrpages(&file_inode(file)->i_data)) {
  546. if (orangefs_features & ORANGEFS_FEATURE_READAHEAD) {
  547. gossip_debug(GOSSIP_INODE_DEBUG,
  548. "calling flush_racache on %pU\n",
  549. get_khandle_from_ino(inode));
  550. flush_racache(inode);
  551. gossip_debug(GOSSIP_INODE_DEBUG,
  552. "flush_racache finished\n");
  553. }
  554. truncate_inode_pages(file_inode(file)->i_mapping,
  555. 0);
  556. }
  557. return 0;
  558. }
  559. /*
  560. * Push all data for a specific file onto permanent storage.
  561. */
  562. static int orangefs_fsync(struct file *file,
  563. loff_t start,
  564. loff_t end,
  565. int datasync)
  566. {
  567. int ret = -EINVAL;
  568. struct orangefs_inode_s *orangefs_inode =
  569. ORANGEFS_I(file_inode(file));
  570. struct orangefs_kernel_op_s *new_op = NULL;
  571. /* required call */
  572. filemap_write_and_wait_range(file->f_mapping, start, end);
  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. if (ret == -ESTALE)
  608. ret = -EIO;
  609. if (ret) {
  610. gossip_debug(GOSSIP_FILE_DEBUG,
  611. "%s:%s:%d calling make bad inode\n",
  612. __FILE__,
  613. __func__,
  614. __LINE__);
  615. return ret;
  616. }
  617. }
  618. gossip_debug(GOSSIP_FILE_DEBUG,
  619. "orangefs_file_llseek: offset is %ld | origin is %d"
  620. " | inode size is %lu\n",
  621. (long)offset,
  622. origin,
  623. (unsigned long)i_size_read(inode));
  624. return generic_file_llseek(file, offset, origin);
  625. }
  626. /*
  627. * Support local locks (locks that only this kernel knows about)
  628. * if Orangefs was mounted -o local_lock.
  629. */
  630. static int orangefs_lock(struct file *filp, int cmd, struct file_lock *fl)
  631. {
  632. int rc = -EINVAL;
  633. if (ORANGEFS_SB(filp->f_inode->i_sb)->flags & ORANGEFS_OPT_LOCAL_LOCK) {
  634. if (cmd == F_GETLK) {
  635. rc = 0;
  636. posix_test_lock(filp, fl);
  637. } else {
  638. rc = posix_lock_file(filp, fl, NULL);
  639. }
  640. }
  641. return rc;
  642. }
  643. /** ORANGEFS implementation of VFS file operations */
  644. const struct file_operations orangefs_file_operations = {
  645. .llseek = orangefs_file_llseek,
  646. .read_iter = orangefs_file_read_iter,
  647. .write_iter = orangefs_file_write_iter,
  648. .lock = orangefs_lock,
  649. .unlocked_ioctl = orangefs_ioctl,
  650. .mmap = orangefs_file_mmap,
  651. .open = generic_file_open,
  652. .release = orangefs_file_release,
  653. .fsync = orangefs_fsync,
  654. };