aops.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public
  17. * License along with this program; if not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 021110-1307, USA.
  20. */
  21. #include <linux/fs.h>
  22. #include <linux/slab.h>
  23. #include <linux/highmem.h>
  24. #include <linux/pagemap.h>
  25. #include <asm/byteorder.h>
  26. #define MLOG_MASK_PREFIX ML_FILE_IO
  27. #include <cluster/masklog.h>
  28. #include "ocfs2.h"
  29. #include "alloc.h"
  30. #include "aops.h"
  31. #include "dlmglue.h"
  32. #include "extent_map.h"
  33. #include "file.h"
  34. #include "inode.h"
  35. #include "journal.h"
  36. #include "super.h"
  37. #include "symlink.h"
  38. #include "buffer_head_io.h"
  39. static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock,
  40. struct buffer_head *bh_result, int create)
  41. {
  42. int err = -EIO;
  43. int status;
  44. struct ocfs2_dinode *fe = NULL;
  45. struct buffer_head *bh = NULL;
  46. struct buffer_head *buffer_cache_bh = NULL;
  47. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  48. void *kaddr;
  49. mlog_entry("(0x%p, %llu, 0x%p, %d)\n", inode,
  50. (unsigned long long)iblock, bh_result, create);
  51. BUG_ON(ocfs2_inode_is_fast_symlink(inode));
  52. if ((iblock << inode->i_sb->s_blocksize_bits) > PATH_MAX + 1) {
  53. mlog(ML_ERROR, "block offset > PATH_MAX: %llu",
  54. (unsigned long long)iblock);
  55. goto bail;
  56. }
  57. status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
  58. OCFS2_I(inode)->ip_blkno,
  59. &bh, OCFS2_BH_CACHED, inode);
  60. if (status < 0) {
  61. mlog_errno(status);
  62. goto bail;
  63. }
  64. fe = (struct ocfs2_dinode *) bh->b_data;
  65. if (!OCFS2_IS_VALID_DINODE(fe)) {
  66. mlog(ML_ERROR, "Invalid dinode #%llu: signature = %.*s\n",
  67. (unsigned long long)fe->i_blkno, 7, fe->i_signature);
  68. goto bail;
  69. }
  70. if ((u64)iblock >= ocfs2_clusters_to_blocks(inode->i_sb,
  71. le32_to_cpu(fe->i_clusters))) {
  72. mlog(ML_ERROR, "block offset is outside the allocated size: "
  73. "%llu\n", (unsigned long long)iblock);
  74. goto bail;
  75. }
  76. /* We don't use the page cache to create symlink data, so if
  77. * need be, copy it over from the buffer cache. */
  78. if (!buffer_uptodate(bh_result) && ocfs2_inode_is_new(inode)) {
  79. u64 blkno = le64_to_cpu(fe->id2.i_list.l_recs[0].e_blkno) +
  80. iblock;
  81. buffer_cache_bh = sb_getblk(osb->sb, blkno);
  82. if (!buffer_cache_bh) {
  83. mlog(ML_ERROR, "couldn't getblock for symlink!\n");
  84. goto bail;
  85. }
  86. /* we haven't locked out transactions, so a commit
  87. * could've happened. Since we've got a reference on
  88. * the bh, even if it commits while we're doing the
  89. * copy, the data is still good. */
  90. if (buffer_jbd(buffer_cache_bh)
  91. && ocfs2_inode_is_new(inode)) {
  92. kaddr = kmap_atomic(bh_result->b_page, KM_USER0);
  93. if (!kaddr) {
  94. mlog(ML_ERROR, "couldn't kmap!\n");
  95. goto bail;
  96. }
  97. memcpy(kaddr + (bh_result->b_size * iblock),
  98. buffer_cache_bh->b_data,
  99. bh_result->b_size);
  100. kunmap_atomic(kaddr, KM_USER0);
  101. set_buffer_uptodate(bh_result);
  102. }
  103. brelse(buffer_cache_bh);
  104. }
  105. map_bh(bh_result, inode->i_sb,
  106. le64_to_cpu(fe->id2.i_list.l_recs[0].e_blkno) + iblock);
  107. err = 0;
  108. bail:
  109. if (bh)
  110. brelse(bh);
  111. mlog_exit(err);
  112. return err;
  113. }
  114. static int ocfs2_get_block(struct inode *inode, sector_t iblock,
  115. struct buffer_head *bh_result, int create)
  116. {
  117. int err = 0;
  118. u64 p_blkno, past_eof;
  119. mlog_entry("(0x%p, %llu, 0x%p, %d)\n", inode,
  120. (unsigned long long)iblock, bh_result, create);
  121. if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE)
  122. mlog(ML_NOTICE, "get_block on system inode 0x%p (%lu)\n",
  123. inode, inode->i_ino);
  124. if (S_ISLNK(inode->i_mode)) {
  125. /* this always does I/O for some reason. */
  126. err = ocfs2_symlink_get_block(inode, iblock, bh_result, create);
  127. goto bail;
  128. }
  129. /* this can happen if another node truncs after our extend! */
  130. spin_lock(&OCFS2_I(inode)->ip_lock);
  131. if (iblock >= ocfs2_clusters_to_blocks(inode->i_sb,
  132. OCFS2_I(inode)->ip_clusters))
  133. err = -EIO;
  134. spin_unlock(&OCFS2_I(inode)->ip_lock);
  135. if (err)
  136. goto bail;
  137. err = ocfs2_extent_map_get_blocks(inode, iblock, 1, &p_blkno,
  138. NULL);
  139. if (err) {
  140. mlog(ML_ERROR, "Error %d from get_blocks(0x%p, %llu, 1, "
  141. "%llu, NULL)\n", err, inode, (unsigned long long)iblock,
  142. (unsigned long long)p_blkno);
  143. goto bail;
  144. }
  145. map_bh(bh_result, inode->i_sb, p_blkno);
  146. if (bh_result->b_blocknr == 0) {
  147. err = -EIO;
  148. mlog(ML_ERROR, "iblock = %llu p_blkno = %llu blkno=(%llu)\n",
  149. (unsigned long long)iblock,
  150. (unsigned long long)p_blkno,
  151. (unsigned long long)OCFS2_I(inode)->ip_blkno);
  152. }
  153. past_eof = ocfs2_blocks_for_bytes(inode->i_sb, i_size_read(inode));
  154. mlog(0, "Inode %lu, past_eof = %llu\n", inode->i_ino,
  155. (unsigned long long)past_eof);
  156. if (create && (iblock >= past_eof))
  157. set_buffer_new(bh_result);
  158. bail:
  159. if (err < 0)
  160. err = -EIO;
  161. mlog_exit(err);
  162. return err;
  163. }
  164. static int ocfs2_readpage(struct file *file, struct page *page)
  165. {
  166. struct inode *inode = page->mapping->host;
  167. loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT;
  168. int ret, unlock = 1;
  169. mlog_entry("(0x%p, %lu)\n", file, (page ? page->index : 0));
  170. ret = ocfs2_meta_lock_with_page(inode, NULL, NULL, 0, page);
  171. if (ret != 0) {
  172. if (ret == AOP_TRUNCATED_PAGE)
  173. unlock = 0;
  174. mlog_errno(ret);
  175. goto out;
  176. }
  177. down_read(&OCFS2_I(inode)->ip_alloc_sem);
  178. /*
  179. * i_size might have just been updated as we grabed the meta lock. We
  180. * might now be discovering a truncate that hit on another node.
  181. * block_read_full_page->get_block freaks out if it is asked to read
  182. * beyond the end of a file, so we check here. Callers
  183. * (generic_file_read, fault->nopage) are clever enough to check i_size
  184. * and notice that the page they just read isn't needed.
  185. *
  186. * XXX sys_readahead() seems to get that wrong?
  187. */
  188. if (start >= i_size_read(inode)) {
  189. char *addr = kmap(page);
  190. memset(addr, 0, PAGE_SIZE);
  191. flush_dcache_page(page);
  192. kunmap(page);
  193. SetPageUptodate(page);
  194. ret = 0;
  195. goto out_alloc;
  196. }
  197. ret = ocfs2_data_lock_with_page(inode, 0, page);
  198. if (ret != 0) {
  199. if (ret == AOP_TRUNCATED_PAGE)
  200. unlock = 0;
  201. mlog_errno(ret);
  202. goto out_alloc;
  203. }
  204. ret = block_read_full_page(page, ocfs2_get_block);
  205. unlock = 0;
  206. ocfs2_data_unlock(inode, 0);
  207. out_alloc:
  208. up_read(&OCFS2_I(inode)->ip_alloc_sem);
  209. ocfs2_meta_unlock(inode, 0);
  210. out:
  211. if (unlock)
  212. unlock_page(page);
  213. mlog_exit(ret);
  214. return ret;
  215. }
  216. /* Note: Because we don't support holes, our allocation has
  217. * already happened (allocation writes zeros to the file data)
  218. * so we don't have to worry about ordered writes in
  219. * ocfs2_writepage.
  220. *
  221. * ->writepage is called during the process of invalidating the page cache
  222. * during blocked lock processing. It can't block on any cluster locks
  223. * to during block mapping. It's relying on the fact that the block
  224. * mapping can't have disappeared under the dirty pages that it is
  225. * being asked to write back.
  226. */
  227. static int ocfs2_writepage(struct page *page, struct writeback_control *wbc)
  228. {
  229. int ret;
  230. mlog_entry("(0x%p)\n", page);
  231. ret = block_write_full_page(page, ocfs2_get_block, wbc);
  232. mlog_exit(ret);
  233. return ret;
  234. }
  235. /* This can also be called from ocfs2_write_zero_page() which has done
  236. * it's own cluster locking. */
  237. int ocfs2_prepare_write_nolock(struct inode *inode, struct page *page,
  238. unsigned from, unsigned to)
  239. {
  240. int ret;
  241. down_read(&OCFS2_I(inode)->ip_alloc_sem);
  242. ret = block_prepare_write(page, from, to, ocfs2_get_block);
  243. up_read(&OCFS2_I(inode)->ip_alloc_sem);
  244. return ret;
  245. }
  246. /*
  247. * ocfs2_prepare_write() can be an outer-most ocfs2 call when it is called
  248. * from loopback. It must be able to perform its own locking around
  249. * ocfs2_get_block().
  250. */
  251. static int ocfs2_prepare_write(struct file *file, struct page *page,
  252. unsigned from, unsigned to)
  253. {
  254. struct inode *inode = page->mapping->host;
  255. int ret;
  256. mlog_entry("(0x%p, 0x%p, %u, %u)\n", file, page, from, to);
  257. ret = ocfs2_meta_lock_with_page(inode, NULL, NULL, 0, page);
  258. if (ret != 0) {
  259. mlog_errno(ret);
  260. goto out;
  261. }
  262. ret = ocfs2_prepare_write_nolock(inode, page, from, to);
  263. ocfs2_meta_unlock(inode, 0);
  264. out:
  265. mlog_exit(ret);
  266. return ret;
  267. }
  268. /* Taken from ext3. We don't necessarily need the full blown
  269. * functionality yet, but IMHO it's better to cut and paste the whole
  270. * thing so we can avoid introducing our own bugs (and easily pick up
  271. * their fixes when they happen) --Mark */
  272. static int walk_page_buffers( handle_t *handle,
  273. struct buffer_head *head,
  274. unsigned from,
  275. unsigned to,
  276. int *partial,
  277. int (*fn)( handle_t *handle,
  278. struct buffer_head *bh))
  279. {
  280. struct buffer_head *bh;
  281. unsigned block_start, block_end;
  282. unsigned blocksize = head->b_size;
  283. int err, ret = 0;
  284. struct buffer_head *next;
  285. for ( bh = head, block_start = 0;
  286. ret == 0 && (bh != head || !block_start);
  287. block_start = block_end, bh = next)
  288. {
  289. next = bh->b_this_page;
  290. block_end = block_start + blocksize;
  291. if (block_end <= from || block_start >= to) {
  292. if (partial && !buffer_uptodate(bh))
  293. *partial = 1;
  294. continue;
  295. }
  296. err = (*fn)(handle, bh);
  297. if (!ret)
  298. ret = err;
  299. }
  300. return ret;
  301. }
  302. struct ocfs2_journal_handle *ocfs2_start_walk_page_trans(struct inode *inode,
  303. struct page *page,
  304. unsigned from,
  305. unsigned to)
  306. {
  307. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  308. struct ocfs2_journal_handle *handle = NULL;
  309. int ret = 0;
  310. handle = ocfs2_start_trans(osb, NULL, OCFS2_INODE_UPDATE_CREDITS);
  311. if (!handle) {
  312. ret = -ENOMEM;
  313. mlog_errno(ret);
  314. goto out;
  315. }
  316. if (ocfs2_should_order_data(inode)) {
  317. ret = walk_page_buffers(handle->k_handle,
  318. page_buffers(page),
  319. from, to, NULL,
  320. ocfs2_journal_dirty_data);
  321. if (ret < 0)
  322. mlog_errno(ret);
  323. }
  324. out:
  325. if (ret) {
  326. if (handle)
  327. ocfs2_commit_trans(handle);
  328. handle = ERR_PTR(ret);
  329. }
  330. return handle;
  331. }
  332. static int ocfs2_commit_write(struct file *file, struct page *page,
  333. unsigned from, unsigned to)
  334. {
  335. int ret;
  336. struct buffer_head *di_bh = NULL;
  337. struct inode *inode = page->mapping->host;
  338. struct ocfs2_journal_handle *handle = NULL;
  339. struct ocfs2_dinode *di;
  340. mlog_entry("(0x%p, 0x%p, %u, %u)\n", file, page, from, to);
  341. /* NOTE: ocfs2_file_aio_write has ensured that it's safe for
  342. * us to continue here without rechecking the I/O against
  343. * changed inode values.
  344. *
  345. * 1) We're currently holding the inode alloc lock, so no
  346. * nodes can change it underneath us.
  347. *
  348. * 2) We've had to take the metadata lock at least once
  349. * already to check for extending writes, suid removal, etc.
  350. * The meta data update code then ensures that we don't get a
  351. * stale inode allocation image (i_size, i_clusters, etc).
  352. */
  353. ret = ocfs2_meta_lock_with_page(inode, NULL, &di_bh, 1, page);
  354. if (ret != 0) {
  355. mlog_errno(ret);
  356. goto out;
  357. }
  358. ret = ocfs2_data_lock_with_page(inode, 1, page);
  359. if (ret != 0) {
  360. mlog_errno(ret);
  361. goto out_unlock_meta;
  362. }
  363. handle = ocfs2_start_walk_page_trans(inode, page, from, to);
  364. if (IS_ERR(handle)) {
  365. ret = PTR_ERR(handle);
  366. goto out_unlock_data;
  367. }
  368. /* Mark our buffer early. We'd rather catch this error up here
  369. * as opposed to after a successful commit_write which would
  370. * require us to set back inode->i_size. */
  371. ret = ocfs2_journal_access(handle, inode, di_bh,
  372. OCFS2_JOURNAL_ACCESS_WRITE);
  373. if (ret < 0) {
  374. mlog_errno(ret);
  375. goto out_commit;
  376. }
  377. /* might update i_size */
  378. ret = generic_commit_write(file, page, from, to);
  379. if (ret < 0) {
  380. mlog_errno(ret);
  381. goto out_commit;
  382. }
  383. di = (struct ocfs2_dinode *)di_bh->b_data;
  384. /* ocfs2_mark_inode_dirty() is too heavy to use here. */
  385. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  386. di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
  387. di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
  388. inode->i_blocks = ocfs2_align_bytes_to_sectors((u64)(i_size_read(inode)));
  389. di->i_size = cpu_to_le64((u64)i_size_read(inode));
  390. ret = ocfs2_journal_dirty(handle, di_bh);
  391. if (ret < 0) {
  392. mlog_errno(ret);
  393. goto out_commit;
  394. }
  395. out_commit:
  396. ocfs2_commit_trans(handle);
  397. out_unlock_data:
  398. ocfs2_data_unlock(inode, 1);
  399. out_unlock_meta:
  400. ocfs2_meta_unlock(inode, 1);
  401. out:
  402. if (di_bh)
  403. brelse(di_bh);
  404. mlog_exit(ret);
  405. return ret;
  406. }
  407. static sector_t ocfs2_bmap(struct address_space *mapping, sector_t block)
  408. {
  409. sector_t status;
  410. u64 p_blkno = 0;
  411. int err = 0;
  412. struct inode *inode = mapping->host;
  413. mlog_entry("(block = %llu)\n", (unsigned long long)block);
  414. /* We don't need to lock journal system files, since they aren't
  415. * accessed concurrently from multiple nodes.
  416. */
  417. if (!INODE_JOURNAL(inode)) {
  418. err = ocfs2_meta_lock(inode, NULL, NULL, 0);
  419. if (err) {
  420. if (err != -ENOENT)
  421. mlog_errno(err);
  422. goto bail;
  423. }
  424. down_read(&OCFS2_I(inode)->ip_alloc_sem);
  425. }
  426. err = ocfs2_extent_map_get_blocks(inode, block, 1, &p_blkno,
  427. NULL);
  428. if (!INODE_JOURNAL(inode)) {
  429. up_read(&OCFS2_I(inode)->ip_alloc_sem);
  430. ocfs2_meta_unlock(inode, 0);
  431. }
  432. if (err) {
  433. mlog(ML_ERROR, "get_blocks() failed, block = %llu\n",
  434. (unsigned long long)block);
  435. mlog_errno(err);
  436. goto bail;
  437. }
  438. bail:
  439. status = err ? 0 : p_blkno;
  440. mlog_exit((int)status);
  441. return status;
  442. }
  443. /*
  444. * TODO: Make this into a generic get_blocks function.
  445. *
  446. * From do_direct_io in direct-io.c:
  447. * "So what we do is to permit the ->get_blocks function to populate
  448. * bh.b_size with the size of IO which is permitted at this offset and
  449. * this i_blkbits."
  450. *
  451. * This function is called directly from get_more_blocks in direct-io.c.
  452. *
  453. * called like this: dio->get_blocks(dio->inode, fs_startblk,
  454. * fs_count, map_bh, dio->rw == WRITE);
  455. */
  456. static int ocfs2_direct_IO_get_blocks(struct inode *inode, sector_t iblock,
  457. struct buffer_head *bh_result, int create)
  458. {
  459. int ret;
  460. u64 vbo_max; /* file offset, max_blocks from iblock */
  461. u64 p_blkno;
  462. int contig_blocks;
  463. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  464. unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits;
  465. /* This function won't even be called if the request isn't all
  466. * nicely aligned and of the right size, so there's no need
  467. * for us to check any of that. */
  468. vbo_max = ((u64)iblock + max_blocks) << blocksize_bits;
  469. spin_lock(&OCFS2_I(inode)->ip_lock);
  470. if ((iblock + max_blocks) >
  471. ocfs2_clusters_to_blocks(inode->i_sb,
  472. OCFS2_I(inode)->ip_clusters)) {
  473. spin_unlock(&OCFS2_I(inode)->ip_lock);
  474. ret = -EIO;
  475. goto bail;
  476. }
  477. spin_unlock(&OCFS2_I(inode)->ip_lock);
  478. /* This figures out the size of the next contiguous block, and
  479. * our logical offset */
  480. ret = ocfs2_extent_map_get_blocks(inode, iblock, 1, &p_blkno,
  481. &contig_blocks);
  482. if (ret) {
  483. mlog(ML_ERROR, "get_blocks() failed iblock=%llu\n",
  484. (unsigned long long)iblock);
  485. ret = -EIO;
  486. goto bail;
  487. }
  488. map_bh(bh_result, inode->i_sb, p_blkno);
  489. /* make sure we don't map more than max_blocks blocks here as
  490. that's all the kernel will handle at this point. */
  491. if (max_blocks < contig_blocks)
  492. contig_blocks = max_blocks;
  493. bh_result->b_size = contig_blocks << blocksize_bits;
  494. bail:
  495. return ret;
  496. }
  497. /*
  498. * ocfs2_dio_end_io is called by the dio core when a dio is finished. We're
  499. * particularly interested in the aio/dio case. Like the core uses
  500. * i_alloc_sem, we use the rw_lock DLM lock to protect io on one node from
  501. * truncation on another.
  502. */
  503. static void ocfs2_dio_end_io(struct kiocb *iocb,
  504. loff_t offset,
  505. ssize_t bytes,
  506. void *private)
  507. {
  508. struct inode *inode = iocb->ki_filp->f_dentry->d_inode;
  509. /* this io's submitter should not have unlocked this before we could */
  510. BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
  511. ocfs2_iocb_clear_rw_locked(iocb);
  512. up_read(&inode->i_alloc_sem);
  513. ocfs2_rw_unlock(inode, 0);
  514. }
  515. static ssize_t ocfs2_direct_IO(int rw,
  516. struct kiocb *iocb,
  517. const struct iovec *iov,
  518. loff_t offset,
  519. unsigned long nr_segs)
  520. {
  521. struct file *file = iocb->ki_filp;
  522. struct inode *inode = file->f_dentry->d_inode->i_mapping->host;
  523. int ret;
  524. mlog_entry_void();
  525. /*
  526. * We get PR data locks even for O_DIRECT. This allows
  527. * concurrent O_DIRECT I/O but doesn't let O_DIRECT with
  528. * extending and buffered zeroing writes race. If they did
  529. * race then the buffered zeroing could be written back after
  530. * the O_DIRECT I/O. It's one thing to tell people not to mix
  531. * buffered and O_DIRECT writes, but expecting them to
  532. * understand that file extension is also an implicit buffered
  533. * write is too much. By getting the PR we force writeback of
  534. * the buffered zeroing before proceeding.
  535. */
  536. ret = ocfs2_data_lock(inode, 0);
  537. if (ret < 0) {
  538. mlog_errno(ret);
  539. goto out;
  540. }
  541. ocfs2_data_unlock(inode, 0);
  542. ret = blockdev_direct_IO_no_locking(rw, iocb, inode,
  543. inode->i_sb->s_bdev, iov, offset,
  544. nr_segs,
  545. ocfs2_direct_IO_get_blocks,
  546. ocfs2_dio_end_io);
  547. out:
  548. mlog_exit(ret);
  549. return ret;
  550. }
  551. const struct address_space_operations ocfs2_aops = {
  552. .readpage = ocfs2_readpage,
  553. .writepage = ocfs2_writepage,
  554. .prepare_write = ocfs2_prepare_write,
  555. .commit_write = ocfs2_commit_write,
  556. .bmap = ocfs2_bmap,
  557. .sync_page = block_sync_page,
  558. .direct_IO = ocfs2_direct_IO
  559. };