ops_address.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License v.2.
  8. */
  9. #include <linux/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/pagemap.h>
  15. #include <linux/pagevec.h>
  16. #include <linux/mpage.h>
  17. #include <linux/fs.h>
  18. #include <linux/gfs2_ondisk.h>
  19. #include "gfs2.h"
  20. #include "lm_interface.h"
  21. #include "incore.h"
  22. #include "bmap.h"
  23. #include "glock.h"
  24. #include "inode.h"
  25. #include "log.h"
  26. #include "meta_io.h"
  27. #include "ops_address.h"
  28. #include "page.h"
  29. #include "quota.h"
  30. #include "trans.h"
  31. #include "rgrp.h"
  32. #include "ops_file.h"
  33. #include "util.h"
  34. /**
  35. * gfs2_get_block - Fills in a buffer head with details about a block
  36. * @inode: The inode
  37. * @lblock: The block number to look up
  38. * @bh_result: The buffer head to return the result in
  39. * @create: Non-zero if we may add block to the file
  40. *
  41. * Returns: errno
  42. */
  43. int gfs2_get_block(struct inode *inode, sector_t lblock,
  44. struct buffer_head *bh_result, int create)
  45. {
  46. int new = create;
  47. uint64_t dblock;
  48. int error;
  49. int boundary;
  50. error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary);
  51. if (error)
  52. return error;
  53. if (!dblock)
  54. return 0;
  55. map_bh(bh_result, inode->i_sb, dblock);
  56. if (new)
  57. set_buffer_new(bh_result);
  58. if (boundary)
  59. set_buffer_boundary(bh_result);
  60. return 0;
  61. }
  62. /**
  63. * get_block_noalloc - Fills in a buffer head with details about a block
  64. * @inode: The inode
  65. * @lblock: The block number to look up
  66. * @bh_result: The buffer head to return the result in
  67. * @create: Non-zero if we may add block to the file
  68. *
  69. * Returns: errno
  70. */
  71. static int get_block_noalloc(struct inode *inode, sector_t lblock,
  72. struct buffer_head *bh_result, int create)
  73. {
  74. int new = 0;
  75. uint64_t dblock;
  76. int error;
  77. int boundary;
  78. error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary);
  79. if (error)
  80. return error;
  81. if (dblock)
  82. map_bh(bh_result, inode->i_sb, dblock);
  83. else if (gfs2_assert_withdraw(GFS2_SB(inode), !create))
  84. error = -EIO;
  85. if (boundary)
  86. set_buffer_boundary(bh_result);
  87. return error;
  88. }
  89. /**
  90. * gfs2_writepage - Write complete page
  91. * @page: Page to write
  92. *
  93. * Returns: errno
  94. *
  95. * Some of this is copied from block_write_full_page() although we still
  96. * call it to do most of the work.
  97. */
  98. static int gfs2_writepage(struct page *page, struct writeback_control *wbc)
  99. {
  100. struct inode *inode = page->mapping->host;
  101. struct gfs2_inode *ip = GFS2_I(page->mapping->host);
  102. struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
  103. loff_t i_size = i_size_read(inode);
  104. pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
  105. unsigned offset;
  106. int error;
  107. int done_trans = 0;
  108. if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl))) {
  109. unlock_page(page);
  110. return -EIO;
  111. }
  112. if (current->journal_info)
  113. goto out_ignore;
  114. /* Is the page fully outside i_size? (truncate in progress) */
  115. offset = i_size & (PAGE_CACHE_SIZE-1);
  116. if (page->index > end_index || (page->index == end_index && !offset)) {
  117. page->mapping->a_ops->invalidatepage(page, 0);
  118. unlock_page(page);
  119. return 0; /* don't care */
  120. }
  121. if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) {
  122. error = gfs2_trans_begin(sdp, RES_DINODE + 1, 0);
  123. if (error)
  124. goto out_ignore;
  125. gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1);
  126. done_trans = 1;
  127. }
  128. error = block_write_full_page(page, get_block_noalloc, wbc);
  129. if (done_trans)
  130. gfs2_trans_end(sdp);
  131. gfs2_meta_cache_flush(ip);
  132. return error;
  133. out_ignore:
  134. redirty_page_for_writepage(wbc, page);
  135. unlock_page(page);
  136. return 0;
  137. }
  138. static int zero_readpage(struct page *page)
  139. {
  140. void *kaddr;
  141. kaddr = kmap_atomic(page, KM_USER0);
  142. memset(kaddr, 0, PAGE_CACHE_SIZE);
  143. kunmap_atomic(page, KM_USER0);
  144. SetPageUptodate(page);
  145. return 0;
  146. }
  147. /**
  148. * stuffed_readpage - Fill in a Linux page with stuffed file data
  149. * @ip: the inode
  150. * @page: the page
  151. *
  152. * Returns: errno
  153. */
  154. static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
  155. {
  156. struct buffer_head *dibh;
  157. void *kaddr;
  158. int error;
  159. /* Only the first page of a stuffed file might contain data */
  160. if (unlikely(page->index))
  161. return zero_readpage(page);
  162. error = gfs2_meta_inode_buffer(ip, &dibh);
  163. if (error)
  164. return error;
  165. kaddr = kmap_atomic(page, KM_USER0);
  166. memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode),
  167. ip->i_di.di_size);
  168. memset(kaddr + ip->i_di.di_size, 0, PAGE_CACHE_SIZE - ip->i_di.di_size);
  169. kunmap_atomic(page, KM_USER0);
  170. brelse(dibh);
  171. SetPageUptodate(page);
  172. return 0;
  173. }
  174. /**
  175. * gfs2_readpage - readpage with locking
  176. * @file: The file to read a page for. N.B. This may be NULL if we are
  177. * reading an internal file.
  178. * @page: The page to read
  179. *
  180. * Returns: errno
  181. */
  182. static int gfs2_readpage(struct file *file, struct page *page)
  183. {
  184. struct gfs2_inode *ip = GFS2_I(page->mapping->host);
  185. struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
  186. struct gfs2_holder gh;
  187. int error;
  188. if (likely(file != &gfs2_internal_file_sentinal)) {
  189. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|GL_AOP, &gh);
  190. error = gfs2_glock_nq_m_atime(1, &gh);
  191. if (unlikely(error))
  192. goto out_unlock;
  193. }
  194. if (gfs2_is_stuffed(ip)) {
  195. error = stuffed_readpage(ip, page);
  196. unlock_page(page);
  197. } else
  198. error = mpage_readpage(page, gfs2_get_block);
  199. if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  200. error = -EIO;
  201. if (file != &gfs2_internal_file_sentinal) {
  202. gfs2_glock_dq_m(1, &gh);
  203. gfs2_holder_uninit(&gh);
  204. }
  205. out:
  206. return error;
  207. out_unlock:
  208. unlock_page(page);
  209. if (file != &gfs2_internal_file_sentinal)
  210. gfs2_holder_uninit(&gh);
  211. goto out;
  212. }
  213. #define list_to_page(head) (list_entry((head)->prev, struct page, lru))
  214. /**
  215. * gfs2_readpages - Read a bunch of pages at once
  216. *
  217. * Some notes:
  218. * 1. This is only for readahead, so we can simply ignore any things
  219. * which are slightly inconvenient (such as locking conflicts between
  220. * the page lock and the glock) and return having done no I/O. Its
  221. * obviously not something we'd want to do on too regular a basis.
  222. * Any I/O we ignore at this time will be done via readpage later.
  223. * 2. We have to handle stuffed files here too.
  224. * 3. mpage_readpages() does most of the heavy lifting in the common case.
  225. * 4. gfs2_get_block() is relied upon to set BH_Boundary in the right places.
  226. * 5. We use LM_FLAG_TRY_1CB here, effectively we then have lock-ahead as
  227. * well as read-ahead.
  228. */
  229. static int gfs2_readpages(struct file *file, struct address_space *mapping,
  230. struct list_head *pages, unsigned nr_pages)
  231. {
  232. struct inode *inode = mapping->host;
  233. struct gfs2_inode *ip = GFS2_I(inode);
  234. struct gfs2_sbd *sdp = GFS2_SB(inode);
  235. struct gfs2_holder gh;
  236. unsigned page_idx;
  237. int ret;
  238. if (likely(file != &gfs2_internal_file_sentinal)) {
  239. gfs2_holder_init(ip->i_gl, LM_ST_SHARED,
  240. LM_FLAG_TRY_1CB|GL_ATIME|GL_AOP, &gh);
  241. ret = gfs2_glock_nq_m_atime(1, &gh);
  242. if (ret == GLR_TRYFAILED)
  243. goto out_noerror;
  244. if (unlikely(ret))
  245. goto out_unlock;
  246. }
  247. if (gfs2_is_stuffed(ip)) {
  248. struct pagevec lru_pvec;
  249. pagevec_init(&lru_pvec, 0);
  250. for (page_idx = 0; page_idx < nr_pages; page_idx++) {
  251. struct page *page = list_to_page(pages);
  252. list_del(&page->lru);
  253. if (!add_to_page_cache(page, mapping,
  254. page->index, GFP_KERNEL)) {
  255. ret = stuffed_readpage(ip, page);
  256. unlock_page(page);
  257. if (!pagevec_add(&lru_pvec, page))
  258. __pagevec_lru_add(&lru_pvec);
  259. }
  260. page_cache_release(page);
  261. }
  262. pagevec_lru_add(&lru_pvec);
  263. ret = 0;
  264. } else {
  265. /* What we really want to do .... */
  266. ret = mpage_readpages(mapping, pages, nr_pages, gfs2_get_block);
  267. }
  268. if (likely(file != &gfs2_internal_file_sentinal)) {
  269. gfs2_glock_dq_m(1, &gh);
  270. gfs2_holder_uninit(&gh);
  271. }
  272. out:
  273. if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
  274. ret = -EIO;
  275. return ret;
  276. out_noerror:
  277. ret = 0;
  278. out_unlock:
  279. /* unlock all pages, we can't do any I/O right now */
  280. for (page_idx = 0; page_idx < nr_pages; page_idx++) {
  281. struct page *page = list_to_page(pages);
  282. list_del(&page->lru);
  283. unlock_page(page);
  284. page_cache_release(page);
  285. }
  286. if (likely(file != &gfs2_internal_file_sentinal))
  287. gfs2_holder_uninit(&gh);
  288. goto out;
  289. }
  290. /**
  291. * gfs2_prepare_write - Prepare to write a page to a file
  292. * @file: The file to write to
  293. * @page: The page which is to be prepared for writing
  294. * @from: From (byte range within page)
  295. * @to: To (byte range within page)
  296. *
  297. * Returns: errno
  298. */
  299. static int gfs2_prepare_write(struct file *file, struct page *page,
  300. unsigned from, unsigned to)
  301. {
  302. struct gfs2_inode *ip = GFS2_I(page->mapping->host);
  303. struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
  304. unsigned int data_blocks, ind_blocks, rblocks;
  305. int alloc_required;
  306. int error = 0;
  307. loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + from;
  308. loff_t end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
  309. struct gfs2_alloc *al;
  310. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME|GL_AOP, &ip->i_gh);
  311. error = gfs2_glock_nq_m_atime(1, &ip->i_gh);
  312. if (error)
  313. goto out_uninit;
  314. gfs2_write_calc_reserv(ip, to - from, &data_blocks, &ind_blocks);
  315. error = gfs2_write_alloc_required(ip, pos, from - to, &alloc_required);
  316. if (error)
  317. goto out_unlock;
  318. if (alloc_required) {
  319. al = gfs2_alloc_get(ip);
  320. error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
  321. if (error)
  322. goto out_alloc_put;
  323. error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid);
  324. if (error)
  325. goto out_qunlock;
  326. al->al_requested = data_blocks + ind_blocks;
  327. error = gfs2_inplace_reserve(ip);
  328. if (error)
  329. goto out_qunlock;
  330. }
  331. rblocks = RES_DINODE + ind_blocks;
  332. if (gfs2_is_jdata(ip))
  333. rblocks += data_blocks ? data_blocks : 1;
  334. if (ind_blocks || data_blocks)
  335. rblocks += RES_STATFS + RES_QUOTA;
  336. error = gfs2_trans_begin(sdp, rblocks, 0);
  337. if (error)
  338. goto out;
  339. if (gfs2_is_stuffed(ip)) {
  340. if (end > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) {
  341. error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page,
  342. page);
  343. if (error == 0)
  344. goto prepare_write;
  345. } else if (!PageUptodate(page))
  346. error = stuffed_readpage(ip, page);
  347. goto out;
  348. }
  349. prepare_write:
  350. error = block_prepare_write(page, from, to, gfs2_get_block);
  351. out:
  352. if (error) {
  353. gfs2_trans_end(sdp);
  354. if (alloc_required) {
  355. gfs2_inplace_release(ip);
  356. out_qunlock:
  357. gfs2_quota_unlock(ip);
  358. out_alloc_put:
  359. gfs2_alloc_put(ip);
  360. }
  361. out_unlock:
  362. gfs2_glock_dq_m(1, &ip->i_gh);
  363. out_uninit:
  364. gfs2_holder_uninit(&ip->i_gh);
  365. }
  366. return error;
  367. }
  368. /**
  369. * gfs2_commit_write - Commit write to a file
  370. * @file: The file to write to
  371. * @page: The page containing the data
  372. * @from: From (byte range within page)
  373. * @to: To (byte range within page)
  374. *
  375. * Returns: errno
  376. */
  377. static int gfs2_commit_write(struct file *file, struct page *page,
  378. unsigned from, unsigned to)
  379. {
  380. struct inode *inode = page->mapping->host;
  381. struct gfs2_inode *ip = GFS2_I(inode);
  382. struct gfs2_sbd *sdp = GFS2_SB(inode);
  383. int error = -EOPNOTSUPP;
  384. struct buffer_head *dibh;
  385. struct gfs2_alloc *al = &ip->i_alloc;;
  386. if (gfs2_assert_withdraw(sdp, gfs2_glock_is_locked_by_me(ip->i_gl)))
  387. goto fail_nounlock;
  388. error = gfs2_meta_inode_buffer(ip, &dibh);
  389. if (error)
  390. goto fail_endtrans;
  391. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  392. if (gfs2_is_stuffed(ip)) {
  393. uint64_t file_size;
  394. void *kaddr;
  395. file_size = ((uint64_t)page->index << PAGE_CACHE_SHIFT) + to;
  396. kaddr = kmap_atomic(page, KM_USER0);
  397. memcpy(dibh->b_data + sizeof(struct gfs2_dinode) + from,
  398. (char *)kaddr + from, to - from);
  399. kunmap_atomic(page, KM_USER0);
  400. SetPageUptodate(page);
  401. if (inode->i_size < file_size)
  402. i_size_write(inode, file_size);
  403. } else {
  404. if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED ||
  405. gfs2_is_jdata(ip))
  406. gfs2_page_add_databufs(ip, page, from, to);
  407. error = generic_commit_write(file, page, from, to);
  408. if (error)
  409. goto fail;
  410. }
  411. if (ip->i_di.di_size < inode->i_size)
  412. ip->i_di.di_size = inode->i_size;
  413. gfs2_dinode_out(&ip->i_di, dibh->b_data);
  414. brelse(dibh);
  415. gfs2_trans_end(sdp);
  416. if (al->al_requested) {
  417. gfs2_inplace_release(ip);
  418. gfs2_quota_unlock(ip);
  419. gfs2_alloc_put(ip);
  420. }
  421. gfs2_glock_dq_m(1, &ip->i_gh);
  422. gfs2_holder_uninit(&ip->i_gh);
  423. return 0;
  424. fail:
  425. brelse(dibh);
  426. fail_endtrans:
  427. gfs2_trans_end(sdp);
  428. if (al->al_requested) {
  429. gfs2_inplace_release(ip);
  430. gfs2_quota_unlock(ip);
  431. gfs2_alloc_put(ip);
  432. }
  433. gfs2_glock_dq_m(1, &ip->i_gh);
  434. gfs2_holder_uninit(&ip->i_gh);
  435. fail_nounlock:
  436. ClearPageUptodate(page);
  437. return error;
  438. }
  439. /**
  440. * gfs2_bmap - Block map function
  441. * @mapping: Address space info
  442. * @lblock: The block to map
  443. *
  444. * Returns: The disk address for the block or 0 on hole or error
  445. */
  446. static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock)
  447. {
  448. struct gfs2_inode *ip = GFS2_I(mapping->host);
  449. struct gfs2_holder i_gh;
  450. sector_t dblock = 0;
  451. int error;
  452. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
  453. if (error)
  454. return 0;
  455. if (!gfs2_is_stuffed(ip))
  456. dblock = generic_block_bmap(mapping, lblock, gfs2_get_block);
  457. gfs2_glock_dq_uninit(&i_gh);
  458. return dblock;
  459. }
  460. static void discard_buffer(struct gfs2_sbd *sdp, struct buffer_head *bh)
  461. {
  462. struct gfs2_bufdata *bd;
  463. gfs2_log_lock(sdp);
  464. bd = bh->b_private;
  465. if (bd) {
  466. bd->bd_bh = NULL;
  467. bh->b_private = NULL;
  468. gfs2_log_unlock(sdp);
  469. brelse(bh);
  470. } else
  471. gfs2_log_unlock(sdp);
  472. lock_buffer(bh);
  473. clear_buffer_dirty(bh);
  474. bh->b_bdev = NULL;
  475. clear_buffer_mapped(bh);
  476. clear_buffer_req(bh);
  477. clear_buffer_new(bh);
  478. clear_buffer_delay(bh);
  479. unlock_buffer(bh);
  480. }
  481. static void gfs2_invalidatepage(struct page *page, unsigned long offset)
  482. {
  483. struct gfs2_sbd *sdp = page->mapping->host->i_sb->s_fs_info;
  484. struct buffer_head *head, *bh, *next;
  485. unsigned int curr_off = 0;
  486. BUG_ON(!PageLocked(page));
  487. if (!page_has_buffers(page))
  488. return;
  489. bh = head = page_buffers(page);
  490. do {
  491. unsigned int next_off = curr_off + bh->b_size;
  492. next = bh->b_this_page;
  493. if (offset <= curr_off)
  494. discard_buffer(sdp, bh);
  495. curr_off = next_off;
  496. bh = next;
  497. } while (bh != head);
  498. if (!offset)
  499. try_to_release_page(page, 0);
  500. return;
  501. }
  502. static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov,
  503. loff_t offset, unsigned long nr_segs)
  504. {
  505. struct file *file = iocb->ki_filp;
  506. struct inode *inode = file->f_mapping->host;
  507. struct gfs2_inode *ip = GFS2_I(inode);
  508. struct gfs2_holder gh;
  509. int rv;
  510. /*
  511. * Shared lock, even though its write, since we do no allocation
  512. * on this path. All we need change is atime.
  513. */
  514. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh);
  515. rv = gfs2_glock_nq_m_atime(1, &gh);
  516. if (rv)
  517. goto out;
  518. /*
  519. * Should we return an error here? I can't see that O_DIRECT for
  520. * a journaled file makes any sense. For now we'll silently fall
  521. * back to buffered I/O, likewise we do the same for stuffed
  522. * files since they are (a) small and (b) unaligned.
  523. */
  524. if (gfs2_is_jdata(ip))
  525. goto out;
  526. if (gfs2_is_stuffed(ip))
  527. goto out;
  528. rv = __blockdev_direct_IO(WRITE, iocb, inode, inode->i_sb->s_bdev,
  529. iov, offset, nr_segs, gfs2_get_block,
  530. NULL, DIO_OWN_LOCKING);
  531. out:
  532. gfs2_glock_dq_m(1, &gh);
  533. gfs2_holder_uninit(&gh);
  534. return rv;
  535. }
  536. /**
  537. * gfs2_direct_IO
  538. *
  539. * This is called with a shared lock already held for the read path.
  540. * Currently, no locks are held when the write path is called.
  541. */
  542. static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb,
  543. const struct iovec *iov, loff_t offset,
  544. unsigned long nr_segs)
  545. {
  546. struct file *file = iocb->ki_filp;
  547. struct inode *inode = file->f_mapping->host;
  548. struct gfs2_inode *ip = GFS2_I(inode);
  549. struct gfs2_sbd *sdp = GFS2_SB(inode);
  550. int ret;
  551. if (rw == WRITE)
  552. return gfs2_direct_IO_write(iocb, iov, offset, nr_segs);
  553. if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl)) ||
  554. gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip)))
  555. return -EINVAL;
  556. mutex_lock(&inode->i_mutex);
  557. ret = __blockdev_direct_IO(READ, iocb, inode, inode->i_sb->s_bdev, iov,
  558. offset, nr_segs, gfs2_get_block, NULL,
  559. DIO_OWN_LOCKING);
  560. mutex_unlock(&inode->i_mutex);
  561. return ret;
  562. }
  563. const struct address_space_operations gfs2_file_aops = {
  564. .writepage = gfs2_writepage,
  565. .readpage = gfs2_readpage,
  566. .readpages = gfs2_readpages,
  567. .sync_page = block_sync_page,
  568. .prepare_write = gfs2_prepare_write,
  569. .commit_write = gfs2_commit_write,
  570. .bmap = gfs2_bmap,
  571. .invalidatepage = gfs2_invalidatepage,
  572. .direct_IO = gfs2_direct_IO,
  573. };