aops.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  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. #include <linux/swap.h>
  27. #include <linux/pipe_fs_i.h>
  28. #define MLOG_MASK_PREFIX ML_FILE_IO
  29. #include <cluster/masklog.h>
  30. #include "ocfs2.h"
  31. #include "alloc.h"
  32. #include "aops.h"
  33. #include "dlmglue.h"
  34. #include "extent_map.h"
  35. #include "file.h"
  36. #include "inode.h"
  37. #include "journal.h"
  38. #include "suballoc.h"
  39. #include "super.h"
  40. #include "symlink.h"
  41. #include "buffer_head_io.h"
  42. static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock,
  43. struct buffer_head *bh_result, int create)
  44. {
  45. int err = -EIO;
  46. int status;
  47. struct ocfs2_dinode *fe = NULL;
  48. struct buffer_head *bh = NULL;
  49. struct buffer_head *buffer_cache_bh = NULL;
  50. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  51. void *kaddr;
  52. mlog_entry("(0x%p, %llu, 0x%p, %d)\n", inode,
  53. (unsigned long long)iblock, bh_result, create);
  54. BUG_ON(ocfs2_inode_is_fast_symlink(inode));
  55. if ((iblock << inode->i_sb->s_blocksize_bits) > PATH_MAX + 1) {
  56. mlog(ML_ERROR, "block offset > PATH_MAX: %llu",
  57. (unsigned long long)iblock);
  58. goto bail;
  59. }
  60. status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
  61. OCFS2_I(inode)->ip_blkno,
  62. &bh, OCFS2_BH_CACHED, inode);
  63. if (status < 0) {
  64. mlog_errno(status);
  65. goto bail;
  66. }
  67. fe = (struct ocfs2_dinode *) bh->b_data;
  68. if (!OCFS2_IS_VALID_DINODE(fe)) {
  69. mlog(ML_ERROR, "Invalid dinode #%llu: signature = %.*s\n",
  70. (unsigned long long)le64_to_cpu(fe->i_blkno), 7,
  71. fe->i_signature);
  72. goto bail;
  73. }
  74. if ((u64)iblock >= ocfs2_clusters_to_blocks(inode->i_sb,
  75. le32_to_cpu(fe->i_clusters))) {
  76. mlog(ML_ERROR, "block offset is outside the allocated size: "
  77. "%llu\n", (unsigned long long)iblock);
  78. goto bail;
  79. }
  80. /* We don't use the page cache to create symlink data, so if
  81. * need be, copy it over from the buffer cache. */
  82. if (!buffer_uptodate(bh_result) && ocfs2_inode_is_new(inode)) {
  83. u64 blkno = le64_to_cpu(fe->id2.i_list.l_recs[0].e_blkno) +
  84. iblock;
  85. buffer_cache_bh = sb_getblk(osb->sb, blkno);
  86. if (!buffer_cache_bh) {
  87. mlog(ML_ERROR, "couldn't getblock for symlink!\n");
  88. goto bail;
  89. }
  90. /* we haven't locked out transactions, so a commit
  91. * could've happened. Since we've got a reference on
  92. * the bh, even if it commits while we're doing the
  93. * copy, the data is still good. */
  94. if (buffer_jbd(buffer_cache_bh)
  95. && ocfs2_inode_is_new(inode)) {
  96. kaddr = kmap_atomic(bh_result->b_page, KM_USER0);
  97. if (!kaddr) {
  98. mlog(ML_ERROR, "couldn't kmap!\n");
  99. goto bail;
  100. }
  101. memcpy(kaddr + (bh_result->b_size * iblock),
  102. buffer_cache_bh->b_data,
  103. bh_result->b_size);
  104. kunmap_atomic(kaddr, KM_USER0);
  105. set_buffer_uptodate(bh_result);
  106. }
  107. brelse(buffer_cache_bh);
  108. }
  109. map_bh(bh_result, inode->i_sb,
  110. le64_to_cpu(fe->id2.i_list.l_recs[0].e_blkno) + iblock);
  111. err = 0;
  112. bail:
  113. if (bh)
  114. brelse(bh);
  115. mlog_exit(err);
  116. return err;
  117. }
  118. static int ocfs2_get_block(struct inode *inode, sector_t iblock,
  119. struct buffer_head *bh_result, int create)
  120. {
  121. int err = 0;
  122. unsigned int ext_flags;
  123. u64 p_blkno, past_eof;
  124. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  125. mlog_entry("(0x%p, %llu, 0x%p, %d)\n", inode,
  126. (unsigned long long)iblock, bh_result, create);
  127. if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE)
  128. mlog(ML_NOTICE, "get_block on system inode 0x%p (%lu)\n",
  129. inode, inode->i_ino);
  130. if (S_ISLNK(inode->i_mode)) {
  131. /* this always does I/O for some reason. */
  132. err = ocfs2_symlink_get_block(inode, iblock, bh_result, create);
  133. goto bail;
  134. }
  135. err = ocfs2_extent_map_get_blocks(inode, iblock, &p_blkno, NULL,
  136. &ext_flags);
  137. if (err) {
  138. mlog(ML_ERROR, "Error %d from get_blocks(0x%p, %llu, 1, "
  139. "%llu, NULL)\n", err, inode, (unsigned long long)iblock,
  140. (unsigned long long)p_blkno);
  141. goto bail;
  142. }
  143. /*
  144. * ocfs2 never allocates in this function - the only time we
  145. * need to use BH_New is when we're extending i_size on a file
  146. * system which doesn't support holes, in which case BH_New
  147. * allows block_prepare_write() to zero.
  148. */
  149. mlog_bug_on_msg(create && p_blkno == 0 && ocfs2_sparse_alloc(osb),
  150. "ino %lu, iblock %llu\n", inode->i_ino,
  151. (unsigned long long)iblock);
  152. /* Treat the unwritten extent as a hole for zeroing purposes. */
  153. if (p_blkno && !(ext_flags & OCFS2_EXT_UNWRITTEN))
  154. map_bh(bh_result, inode->i_sb, p_blkno);
  155. if (!ocfs2_sparse_alloc(osb)) {
  156. if (p_blkno == 0) {
  157. err = -EIO;
  158. mlog(ML_ERROR,
  159. "iblock = %llu p_blkno = %llu blkno=(%llu)\n",
  160. (unsigned long long)iblock,
  161. (unsigned long long)p_blkno,
  162. (unsigned long long)OCFS2_I(inode)->ip_blkno);
  163. mlog(ML_ERROR, "Size %llu, clusters %u\n", (unsigned long long)i_size_read(inode), OCFS2_I(inode)->ip_clusters);
  164. dump_stack();
  165. }
  166. past_eof = ocfs2_blocks_for_bytes(inode->i_sb, i_size_read(inode));
  167. mlog(0, "Inode %lu, past_eof = %llu\n", inode->i_ino,
  168. (unsigned long long)past_eof);
  169. if (create && (iblock >= past_eof))
  170. set_buffer_new(bh_result);
  171. }
  172. bail:
  173. if (err < 0)
  174. err = -EIO;
  175. mlog_exit(err);
  176. return err;
  177. }
  178. static int ocfs2_readpage(struct file *file, struct page *page)
  179. {
  180. struct inode *inode = page->mapping->host;
  181. loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT;
  182. int ret, unlock = 1;
  183. mlog_entry("(0x%p, %lu)\n", file, (page ? page->index : 0));
  184. ret = ocfs2_meta_lock_with_page(inode, NULL, 0, page);
  185. if (ret != 0) {
  186. if (ret == AOP_TRUNCATED_PAGE)
  187. unlock = 0;
  188. mlog_errno(ret);
  189. goto out;
  190. }
  191. down_read(&OCFS2_I(inode)->ip_alloc_sem);
  192. /*
  193. * i_size might have just been updated as we grabed the meta lock. We
  194. * might now be discovering a truncate that hit on another node.
  195. * block_read_full_page->get_block freaks out if it is asked to read
  196. * beyond the end of a file, so we check here. Callers
  197. * (generic_file_read, fault->nopage) are clever enough to check i_size
  198. * and notice that the page they just read isn't needed.
  199. *
  200. * XXX sys_readahead() seems to get that wrong?
  201. */
  202. if (start >= i_size_read(inode)) {
  203. char *addr = kmap(page);
  204. memset(addr, 0, PAGE_SIZE);
  205. flush_dcache_page(page);
  206. kunmap(page);
  207. SetPageUptodate(page);
  208. ret = 0;
  209. goto out_alloc;
  210. }
  211. ret = ocfs2_data_lock_with_page(inode, 0, page);
  212. if (ret != 0) {
  213. if (ret == AOP_TRUNCATED_PAGE)
  214. unlock = 0;
  215. mlog_errno(ret);
  216. goto out_alloc;
  217. }
  218. ret = block_read_full_page(page, ocfs2_get_block);
  219. unlock = 0;
  220. ocfs2_data_unlock(inode, 0);
  221. out_alloc:
  222. up_read(&OCFS2_I(inode)->ip_alloc_sem);
  223. ocfs2_meta_unlock(inode, 0);
  224. out:
  225. if (unlock)
  226. unlock_page(page);
  227. mlog_exit(ret);
  228. return ret;
  229. }
  230. /* Note: Because we don't support holes, our allocation has
  231. * already happened (allocation writes zeros to the file data)
  232. * so we don't have to worry about ordered writes in
  233. * ocfs2_writepage.
  234. *
  235. * ->writepage is called during the process of invalidating the page cache
  236. * during blocked lock processing. It can't block on any cluster locks
  237. * to during block mapping. It's relying on the fact that the block
  238. * mapping can't have disappeared under the dirty pages that it is
  239. * being asked to write back.
  240. */
  241. static int ocfs2_writepage(struct page *page, struct writeback_control *wbc)
  242. {
  243. int ret;
  244. mlog_entry("(0x%p)\n", page);
  245. ret = block_write_full_page(page, ocfs2_get_block, wbc);
  246. mlog_exit(ret);
  247. return ret;
  248. }
  249. /*
  250. * This is called from ocfs2_write_zero_page() which has handled it's
  251. * own cluster locking and has ensured allocation exists for those
  252. * blocks to be written.
  253. */
  254. int ocfs2_prepare_write_nolock(struct inode *inode, struct page *page,
  255. unsigned from, unsigned to)
  256. {
  257. int ret;
  258. down_read(&OCFS2_I(inode)->ip_alloc_sem);
  259. ret = block_prepare_write(page, from, to, ocfs2_get_block);
  260. up_read(&OCFS2_I(inode)->ip_alloc_sem);
  261. return ret;
  262. }
  263. /* Taken from ext3. We don't necessarily need the full blown
  264. * functionality yet, but IMHO it's better to cut and paste the whole
  265. * thing so we can avoid introducing our own bugs (and easily pick up
  266. * their fixes when they happen) --Mark */
  267. int walk_page_buffers( handle_t *handle,
  268. struct buffer_head *head,
  269. unsigned from,
  270. unsigned to,
  271. int *partial,
  272. int (*fn)( handle_t *handle,
  273. struct buffer_head *bh))
  274. {
  275. struct buffer_head *bh;
  276. unsigned block_start, block_end;
  277. unsigned blocksize = head->b_size;
  278. int err, ret = 0;
  279. struct buffer_head *next;
  280. for ( bh = head, block_start = 0;
  281. ret == 0 && (bh != head || !block_start);
  282. block_start = block_end, bh = next)
  283. {
  284. next = bh->b_this_page;
  285. block_end = block_start + blocksize;
  286. if (block_end <= from || block_start >= to) {
  287. if (partial && !buffer_uptodate(bh))
  288. *partial = 1;
  289. continue;
  290. }
  291. err = (*fn)(handle, bh);
  292. if (!ret)
  293. ret = err;
  294. }
  295. return ret;
  296. }
  297. handle_t *ocfs2_start_walk_page_trans(struct inode *inode,
  298. struct page *page,
  299. unsigned from,
  300. unsigned to)
  301. {
  302. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  303. handle_t *handle = NULL;
  304. int ret = 0;
  305. handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
  306. if (!handle) {
  307. ret = -ENOMEM;
  308. mlog_errno(ret);
  309. goto out;
  310. }
  311. if (ocfs2_should_order_data(inode)) {
  312. ret = walk_page_buffers(handle,
  313. page_buffers(page),
  314. from, to, NULL,
  315. ocfs2_journal_dirty_data);
  316. if (ret < 0)
  317. mlog_errno(ret);
  318. }
  319. out:
  320. if (ret) {
  321. if (handle)
  322. ocfs2_commit_trans(osb, handle);
  323. handle = ERR_PTR(ret);
  324. }
  325. return handle;
  326. }
  327. static sector_t ocfs2_bmap(struct address_space *mapping, sector_t block)
  328. {
  329. sector_t status;
  330. u64 p_blkno = 0;
  331. int err = 0;
  332. struct inode *inode = mapping->host;
  333. mlog_entry("(block = %llu)\n", (unsigned long long)block);
  334. /* We don't need to lock journal system files, since they aren't
  335. * accessed concurrently from multiple nodes.
  336. */
  337. if (!INODE_JOURNAL(inode)) {
  338. err = ocfs2_meta_lock(inode, NULL, 0);
  339. if (err) {
  340. if (err != -ENOENT)
  341. mlog_errno(err);
  342. goto bail;
  343. }
  344. down_read(&OCFS2_I(inode)->ip_alloc_sem);
  345. }
  346. err = ocfs2_extent_map_get_blocks(inode, block, &p_blkno, NULL, NULL);
  347. if (!INODE_JOURNAL(inode)) {
  348. up_read(&OCFS2_I(inode)->ip_alloc_sem);
  349. ocfs2_meta_unlock(inode, 0);
  350. }
  351. if (err) {
  352. mlog(ML_ERROR, "get_blocks() failed, block = %llu\n",
  353. (unsigned long long)block);
  354. mlog_errno(err);
  355. goto bail;
  356. }
  357. bail:
  358. status = err ? 0 : p_blkno;
  359. mlog_exit((int)status);
  360. return status;
  361. }
  362. /*
  363. * TODO: Make this into a generic get_blocks function.
  364. *
  365. * From do_direct_io in direct-io.c:
  366. * "So what we do is to permit the ->get_blocks function to populate
  367. * bh.b_size with the size of IO which is permitted at this offset and
  368. * this i_blkbits."
  369. *
  370. * This function is called directly from get_more_blocks in direct-io.c.
  371. *
  372. * called like this: dio->get_blocks(dio->inode, fs_startblk,
  373. * fs_count, map_bh, dio->rw == WRITE);
  374. */
  375. static int ocfs2_direct_IO_get_blocks(struct inode *inode, sector_t iblock,
  376. struct buffer_head *bh_result, int create)
  377. {
  378. int ret;
  379. u64 p_blkno, inode_blocks, contig_blocks;
  380. unsigned int ext_flags;
  381. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  382. unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits;
  383. /* This function won't even be called if the request isn't all
  384. * nicely aligned and of the right size, so there's no need
  385. * for us to check any of that. */
  386. inode_blocks = ocfs2_blocks_for_bytes(inode->i_sb, i_size_read(inode));
  387. /*
  388. * Any write past EOF is not allowed because we'd be extending.
  389. */
  390. if (create && (iblock + max_blocks) > inode_blocks) {
  391. ret = -EIO;
  392. goto bail;
  393. }
  394. /* This figures out the size of the next contiguous block, and
  395. * our logical offset */
  396. ret = ocfs2_extent_map_get_blocks(inode, iblock, &p_blkno,
  397. &contig_blocks, &ext_flags);
  398. if (ret) {
  399. mlog(ML_ERROR, "get_blocks() failed iblock=%llu\n",
  400. (unsigned long long)iblock);
  401. ret = -EIO;
  402. goto bail;
  403. }
  404. if (!ocfs2_sparse_alloc(OCFS2_SB(inode->i_sb)) && !p_blkno) {
  405. ocfs2_error(inode->i_sb,
  406. "Inode %llu has a hole at block %llu\n",
  407. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  408. (unsigned long long)iblock);
  409. ret = -EROFS;
  410. goto bail;
  411. }
  412. /*
  413. * get_more_blocks() expects us to describe a hole by clearing
  414. * the mapped bit on bh_result().
  415. *
  416. * Consider an unwritten extent as a hole.
  417. */
  418. if (p_blkno && !(ext_flags & OCFS2_EXT_UNWRITTEN))
  419. map_bh(bh_result, inode->i_sb, p_blkno);
  420. else {
  421. /*
  422. * ocfs2_prepare_inode_for_write() should have caught
  423. * the case where we'd be filling a hole and triggered
  424. * a buffered write instead.
  425. */
  426. if (create) {
  427. ret = -EIO;
  428. mlog_errno(ret);
  429. goto bail;
  430. }
  431. clear_buffer_mapped(bh_result);
  432. }
  433. /* make sure we don't map more than max_blocks blocks here as
  434. that's all the kernel will handle at this point. */
  435. if (max_blocks < contig_blocks)
  436. contig_blocks = max_blocks;
  437. bh_result->b_size = contig_blocks << blocksize_bits;
  438. bail:
  439. return ret;
  440. }
  441. /*
  442. * ocfs2_dio_end_io is called by the dio core when a dio is finished. We're
  443. * particularly interested in the aio/dio case. Like the core uses
  444. * i_alloc_sem, we use the rw_lock DLM lock to protect io on one node from
  445. * truncation on another.
  446. */
  447. static void ocfs2_dio_end_io(struct kiocb *iocb,
  448. loff_t offset,
  449. ssize_t bytes,
  450. void *private)
  451. {
  452. struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
  453. int level;
  454. /* this io's submitter should not have unlocked this before we could */
  455. BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
  456. ocfs2_iocb_clear_rw_locked(iocb);
  457. level = ocfs2_iocb_rw_locked_level(iocb);
  458. if (!level)
  459. up_read(&inode->i_alloc_sem);
  460. ocfs2_rw_unlock(inode, level);
  461. }
  462. /*
  463. * ocfs2_invalidatepage() and ocfs2_releasepage() are shamelessly stolen
  464. * from ext3. PageChecked() bits have been removed as OCFS2 does not
  465. * do journalled data.
  466. */
  467. static void ocfs2_invalidatepage(struct page *page, unsigned long offset)
  468. {
  469. journal_t *journal = OCFS2_SB(page->mapping->host->i_sb)->journal->j_journal;
  470. journal_invalidatepage(journal, page, offset);
  471. }
  472. static int ocfs2_releasepage(struct page *page, gfp_t wait)
  473. {
  474. journal_t *journal = OCFS2_SB(page->mapping->host->i_sb)->journal->j_journal;
  475. if (!page_has_buffers(page))
  476. return 0;
  477. return journal_try_to_free_buffers(journal, page, wait);
  478. }
  479. static ssize_t ocfs2_direct_IO(int rw,
  480. struct kiocb *iocb,
  481. const struct iovec *iov,
  482. loff_t offset,
  483. unsigned long nr_segs)
  484. {
  485. struct file *file = iocb->ki_filp;
  486. struct inode *inode = file->f_path.dentry->d_inode->i_mapping->host;
  487. int ret;
  488. mlog_entry_void();
  489. if (!ocfs2_sparse_alloc(OCFS2_SB(inode->i_sb))) {
  490. /*
  491. * We get PR data locks even for O_DIRECT. This
  492. * allows concurrent O_DIRECT I/O but doesn't let
  493. * O_DIRECT with extending and buffered zeroing writes
  494. * race. If they did race then the buffered zeroing
  495. * could be written back after the O_DIRECT I/O. It's
  496. * one thing to tell people not to mix buffered and
  497. * O_DIRECT writes, but expecting them to understand
  498. * that file extension is also an implicit buffered
  499. * write is too much. By getting the PR we force
  500. * writeback of the buffered zeroing before
  501. * proceeding.
  502. */
  503. ret = ocfs2_data_lock(inode, 0);
  504. if (ret < 0) {
  505. mlog_errno(ret);
  506. goto out;
  507. }
  508. ocfs2_data_unlock(inode, 0);
  509. }
  510. ret = blockdev_direct_IO_no_locking(rw, iocb, inode,
  511. inode->i_sb->s_bdev, iov, offset,
  512. nr_segs,
  513. ocfs2_direct_IO_get_blocks,
  514. ocfs2_dio_end_io);
  515. out:
  516. mlog_exit(ret);
  517. return ret;
  518. }
  519. static void ocfs2_figure_cluster_boundaries(struct ocfs2_super *osb,
  520. u32 cpos,
  521. unsigned int *start,
  522. unsigned int *end)
  523. {
  524. unsigned int cluster_start = 0, cluster_end = PAGE_CACHE_SIZE;
  525. if (unlikely(PAGE_CACHE_SHIFT > osb->s_clustersize_bits)) {
  526. unsigned int cpp;
  527. cpp = 1 << (PAGE_CACHE_SHIFT - osb->s_clustersize_bits);
  528. cluster_start = cpos % cpp;
  529. cluster_start = cluster_start << osb->s_clustersize_bits;
  530. cluster_end = cluster_start + osb->s_clustersize;
  531. }
  532. BUG_ON(cluster_start > PAGE_SIZE);
  533. BUG_ON(cluster_end > PAGE_SIZE);
  534. if (start)
  535. *start = cluster_start;
  536. if (end)
  537. *end = cluster_end;
  538. }
  539. /*
  540. * 'from' and 'to' are the region in the page to avoid zeroing.
  541. *
  542. * If pagesize > clustersize, this function will avoid zeroing outside
  543. * of the cluster boundary.
  544. *
  545. * from == to == 0 is code for "zero the entire cluster region"
  546. */
  547. static void ocfs2_clear_page_regions(struct page *page,
  548. struct ocfs2_super *osb, u32 cpos,
  549. unsigned from, unsigned to)
  550. {
  551. void *kaddr;
  552. unsigned int cluster_start, cluster_end;
  553. ocfs2_figure_cluster_boundaries(osb, cpos, &cluster_start, &cluster_end);
  554. kaddr = kmap_atomic(page, KM_USER0);
  555. if (from || to) {
  556. if (from > cluster_start)
  557. memset(kaddr + cluster_start, 0, from - cluster_start);
  558. if (to < cluster_end)
  559. memset(kaddr + to, 0, cluster_end - to);
  560. } else {
  561. memset(kaddr + cluster_start, 0, cluster_end - cluster_start);
  562. }
  563. kunmap_atomic(kaddr, KM_USER0);
  564. }
  565. /*
  566. * Some of this taken from block_prepare_write(). We already have our
  567. * mapping by now though, and the entire write will be allocating or
  568. * it won't, so not much need to use BH_New.
  569. *
  570. * This will also skip zeroing, which is handled externally.
  571. */
  572. int ocfs2_map_page_blocks(struct page *page, u64 *p_blkno,
  573. struct inode *inode, unsigned int from,
  574. unsigned int to, int new)
  575. {
  576. int ret = 0;
  577. struct buffer_head *head, *bh, *wait[2], **wait_bh = wait;
  578. unsigned int block_end, block_start;
  579. unsigned int bsize = 1 << inode->i_blkbits;
  580. if (!page_has_buffers(page))
  581. create_empty_buffers(page, bsize, 0);
  582. head = page_buffers(page);
  583. for (bh = head, block_start = 0; bh != head || !block_start;
  584. bh = bh->b_this_page, block_start += bsize) {
  585. block_end = block_start + bsize;
  586. /*
  587. * Ignore blocks outside of our i/o range -
  588. * they may belong to unallocated clusters.
  589. */
  590. if (block_start >= to || block_end <= from) {
  591. if (PageUptodate(page))
  592. set_buffer_uptodate(bh);
  593. continue;
  594. }
  595. /*
  596. * For an allocating write with cluster size >= page
  597. * size, we always write the entire page.
  598. */
  599. if (buffer_new(bh))
  600. clear_buffer_new(bh);
  601. if (!buffer_mapped(bh)) {
  602. map_bh(bh, inode->i_sb, *p_blkno);
  603. unmap_underlying_metadata(bh->b_bdev, bh->b_blocknr);
  604. }
  605. if (PageUptodate(page)) {
  606. if (!buffer_uptodate(bh))
  607. set_buffer_uptodate(bh);
  608. } else if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
  609. (block_start < from || block_end > to)) {
  610. ll_rw_block(READ, 1, &bh);
  611. *wait_bh++=bh;
  612. }
  613. *p_blkno = *p_blkno + 1;
  614. }
  615. /*
  616. * If we issued read requests - let them complete.
  617. */
  618. while(wait_bh > wait) {
  619. wait_on_buffer(*--wait_bh);
  620. if (!buffer_uptodate(*wait_bh))
  621. ret = -EIO;
  622. }
  623. if (ret == 0 || !new)
  624. return ret;
  625. /*
  626. * If we get -EIO above, zero out any newly allocated blocks
  627. * to avoid exposing stale data.
  628. */
  629. bh = head;
  630. block_start = 0;
  631. do {
  632. void *kaddr;
  633. block_end = block_start + bsize;
  634. if (block_end <= from)
  635. goto next_bh;
  636. if (block_start >= to)
  637. break;
  638. kaddr = kmap_atomic(page, KM_USER0);
  639. memset(kaddr+block_start, 0, bh->b_size);
  640. flush_dcache_page(page);
  641. kunmap_atomic(kaddr, KM_USER0);
  642. set_buffer_uptodate(bh);
  643. mark_buffer_dirty(bh);
  644. next_bh:
  645. block_start = block_end;
  646. bh = bh->b_this_page;
  647. } while (bh != head);
  648. return ret;
  649. }
  650. /*
  651. * This will copy user data from the buffer page in the splice
  652. * context.
  653. *
  654. * For now, we ignore SPLICE_F_MOVE as that would require some extra
  655. * communication out all the way to ocfs2_write().
  656. */
  657. int ocfs2_map_and_write_splice_data(struct inode *inode,
  658. struct ocfs2_write_ctxt *wc, u64 *p_blkno,
  659. unsigned int *ret_from, unsigned int *ret_to)
  660. {
  661. int ret;
  662. unsigned int to, from, cluster_start, cluster_end;
  663. char *src, *dst;
  664. struct ocfs2_splice_write_priv *sp = wc->w_private;
  665. struct pipe_buffer *buf = sp->s_buf;
  666. unsigned long bytes, src_from;
  667. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  668. ocfs2_figure_cluster_boundaries(osb, wc->w_cpos, &cluster_start,
  669. &cluster_end);
  670. from = sp->s_offset;
  671. src_from = sp->s_buf_offset;
  672. bytes = wc->w_count;
  673. if (wc->w_large_pages) {
  674. /*
  675. * For cluster size < page size, we have to
  676. * calculate pos within the cluster and obey
  677. * the rightmost boundary.
  678. */
  679. bytes = min(bytes, (unsigned long)(osb->s_clustersize
  680. - (wc->w_pos & (osb->s_clustersize - 1))));
  681. }
  682. to = from + bytes;
  683. if (wc->w_this_page_new)
  684. ret = ocfs2_map_page_blocks(wc->w_this_page, p_blkno, inode,
  685. cluster_start, cluster_end, 1);
  686. else
  687. ret = ocfs2_map_page_blocks(wc->w_this_page, p_blkno, inode,
  688. from, to, 0);
  689. if (ret) {
  690. mlog_errno(ret);
  691. goto out;
  692. }
  693. BUG_ON(from > PAGE_CACHE_SIZE);
  694. BUG_ON(to > PAGE_CACHE_SIZE);
  695. BUG_ON(from > osb->s_clustersize);
  696. BUG_ON(to > osb->s_clustersize);
  697. src = buf->ops->map(sp->s_pipe, buf, 1);
  698. dst = kmap_atomic(wc->w_this_page, KM_USER1);
  699. memcpy(dst + from, src + src_from, bytes);
  700. kunmap_atomic(wc->w_this_page, KM_USER1);
  701. buf->ops->unmap(sp->s_pipe, buf, src);
  702. wc->w_finished_copy = 1;
  703. *ret_from = from;
  704. *ret_to = to;
  705. out:
  706. return bytes ? (unsigned int)bytes : ret;
  707. }
  708. /*
  709. * This will copy user data from the iovec in the buffered write
  710. * context.
  711. */
  712. int ocfs2_map_and_write_user_data(struct inode *inode,
  713. struct ocfs2_write_ctxt *wc, u64 *p_blkno,
  714. unsigned int *ret_from, unsigned int *ret_to)
  715. {
  716. int ret;
  717. unsigned int to, from, cluster_start, cluster_end;
  718. unsigned long bytes, src_from;
  719. char *dst;
  720. struct ocfs2_buffered_write_priv *bp = wc->w_private;
  721. const struct iovec *cur_iov = bp->b_cur_iov;
  722. char __user *buf;
  723. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  724. ocfs2_figure_cluster_boundaries(osb, wc->w_cpos, &cluster_start,
  725. &cluster_end);
  726. buf = cur_iov->iov_base + bp->b_cur_off;
  727. src_from = (unsigned long)buf & ~PAGE_CACHE_MASK;
  728. from = wc->w_pos & (PAGE_CACHE_SIZE - 1);
  729. /*
  730. * This is a lot of comparisons, but it reads quite
  731. * easily, which is important here.
  732. */
  733. /* Stay within the src page */
  734. bytes = PAGE_SIZE - src_from;
  735. /* Stay within the vector */
  736. bytes = min(bytes,
  737. (unsigned long)(cur_iov->iov_len - bp->b_cur_off));
  738. /* Stay within count */
  739. bytes = min(bytes, (unsigned long)wc->w_count);
  740. /*
  741. * For clustersize > page size, just stay within
  742. * target page, otherwise we have to calculate pos
  743. * within the cluster and obey the rightmost
  744. * boundary.
  745. */
  746. if (wc->w_large_pages) {
  747. /*
  748. * For cluster size < page size, we have to
  749. * calculate pos within the cluster and obey
  750. * the rightmost boundary.
  751. */
  752. bytes = min(bytes, (unsigned long)(osb->s_clustersize
  753. - (wc->w_pos & (osb->s_clustersize - 1))));
  754. } else {
  755. /*
  756. * cluster size > page size is the most common
  757. * case - we just stay within the target page
  758. * boundary.
  759. */
  760. bytes = min(bytes, PAGE_CACHE_SIZE - from);
  761. }
  762. to = from + bytes;
  763. if (wc->w_this_page_new)
  764. ret = ocfs2_map_page_blocks(wc->w_this_page, p_blkno, inode,
  765. cluster_start, cluster_end, 1);
  766. else
  767. ret = ocfs2_map_page_blocks(wc->w_this_page, p_blkno, inode,
  768. from, to, 0);
  769. if (ret) {
  770. mlog_errno(ret);
  771. goto out;
  772. }
  773. BUG_ON(from > PAGE_CACHE_SIZE);
  774. BUG_ON(to > PAGE_CACHE_SIZE);
  775. BUG_ON(from > osb->s_clustersize);
  776. BUG_ON(to > osb->s_clustersize);
  777. dst = kmap(wc->w_this_page);
  778. memcpy(dst + from, bp->b_src_buf + src_from, bytes);
  779. kunmap(wc->w_this_page);
  780. /*
  781. * XXX: This is slow, but simple. The caller of
  782. * ocfs2_buffered_write_cluster() is responsible for
  783. * passing through the iovecs, so it's difficult to
  784. * predict what our next step is in here after our
  785. * initial write. A future version should be pushing
  786. * that iovec manipulation further down.
  787. *
  788. * By setting this, we indicate that a copy from user
  789. * data was done, and subsequent calls for this
  790. * cluster will skip copying more data.
  791. */
  792. wc->w_finished_copy = 1;
  793. *ret_from = from;
  794. *ret_to = to;
  795. out:
  796. return bytes ? (unsigned int)bytes : ret;
  797. }
  798. /*
  799. * Map, fill and write a page to disk.
  800. *
  801. * The work of copying data is done via callback. Newly allocated
  802. * pages which don't take user data will be zero'd (set 'new' to
  803. * indicate an allocating write)
  804. *
  805. * Returns a negative error code or the number of bytes copied into
  806. * the page.
  807. */
  808. static int ocfs2_write_data_page(struct inode *inode, handle_t *handle,
  809. u64 *p_blkno, struct page *page,
  810. struct ocfs2_write_ctxt *wc, int new)
  811. {
  812. int ret, copied = 0;
  813. unsigned int from = 0, to = 0;
  814. unsigned int cluster_start, cluster_end;
  815. unsigned int zero_from = 0, zero_to = 0;
  816. ocfs2_figure_cluster_boundaries(OCFS2_SB(inode->i_sb), wc->w_cpos,
  817. &cluster_start, &cluster_end);
  818. if ((wc->w_pos >> PAGE_CACHE_SHIFT) == page->index
  819. && !wc->w_finished_copy) {
  820. wc->w_this_page = page;
  821. wc->w_this_page_new = new;
  822. ret = wc->w_write_data_page(inode, wc, p_blkno, &from, &to);
  823. if (ret < 0) {
  824. mlog_errno(ret);
  825. goto out;
  826. }
  827. copied = ret;
  828. zero_from = from;
  829. zero_to = to;
  830. if (new) {
  831. from = cluster_start;
  832. to = cluster_end;
  833. }
  834. } else {
  835. /*
  836. * If we haven't allocated the new page yet, we
  837. * shouldn't be writing it out without copying user
  838. * data. This is likely a math error from the caller.
  839. */
  840. BUG_ON(!new);
  841. from = cluster_start;
  842. to = cluster_end;
  843. ret = ocfs2_map_page_blocks(page, p_blkno, inode,
  844. cluster_start, cluster_end, 1);
  845. if (ret) {
  846. mlog_errno(ret);
  847. goto out;
  848. }
  849. }
  850. /*
  851. * Parts of newly allocated pages need to be zero'd.
  852. *
  853. * Above, we have also rewritten 'to' and 'from' - as far as
  854. * the rest of the function is concerned, the entire cluster
  855. * range inside of a page needs to be written.
  856. *
  857. * We can skip this if the page is up to date - it's already
  858. * been zero'd from being read in as a hole.
  859. */
  860. if (new && !PageUptodate(page))
  861. ocfs2_clear_page_regions(page, OCFS2_SB(inode->i_sb),
  862. wc->w_cpos, zero_from, zero_to);
  863. flush_dcache_page(page);
  864. if (ocfs2_should_order_data(inode)) {
  865. ret = walk_page_buffers(handle,
  866. page_buffers(page),
  867. from, to, NULL,
  868. ocfs2_journal_dirty_data);
  869. if (ret < 0)
  870. mlog_errno(ret);
  871. }
  872. /*
  873. * We don't use generic_commit_write() because we need to
  874. * handle our own i_size update.
  875. */
  876. ret = block_commit_write(page, from, to);
  877. if (ret)
  878. mlog_errno(ret);
  879. out:
  880. return copied ? copied : ret;
  881. }
  882. /*
  883. * Do the actual write of some data into an inode. Optionally allocate
  884. * in order to fulfill the write.
  885. *
  886. * cpos is the logical cluster offset within the file to write at
  887. *
  888. * 'phys' is the physical mapping of that offset. a 'phys' value of
  889. * zero indicates that allocation is required. In this case, data_ac
  890. * and meta_ac should be valid (meta_ac can be null if metadata
  891. * allocation isn't required).
  892. */
  893. static ssize_t ocfs2_write(struct file *file, u32 phys, handle_t *handle,
  894. struct buffer_head *di_bh,
  895. struct ocfs2_alloc_context *data_ac,
  896. struct ocfs2_alloc_context *meta_ac,
  897. struct ocfs2_write_ctxt *wc)
  898. {
  899. int ret, i, numpages = 1, new;
  900. unsigned int copied = 0;
  901. u32 tmp_pos;
  902. u64 v_blkno, p_blkno;
  903. struct address_space *mapping = file->f_mapping;
  904. struct inode *inode = mapping->host;
  905. unsigned long index, start;
  906. struct page **cpages;
  907. new = phys == 0 ? 1 : 0;
  908. /*
  909. * Figure out how many pages we'll be manipulating here. For
  910. * non allocating write, we just change the one
  911. * page. Otherwise, we'll need a whole clusters worth.
  912. */
  913. if (new)
  914. numpages = ocfs2_pages_per_cluster(inode->i_sb);
  915. cpages = kzalloc(sizeof(*cpages) * numpages, GFP_NOFS);
  916. if (!cpages) {
  917. ret = -ENOMEM;
  918. mlog_errno(ret);
  919. return ret;
  920. }
  921. /*
  922. * Fill our page array first. That way we've grabbed enough so
  923. * that we can zero and flush if we error after adding the
  924. * extent.
  925. */
  926. if (new) {
  927. start = ocfs2_align_clusters_to_page_index(inode->i_sb,
  928. wc->w_cpos);
  929. v_blkno = ocfs2_clusters_to_blocks(inode->i_sb, wc->w_cpos);
  930. } else {
  931. start = wc->w_pos >> PAGE_CACHE_SHIFT;
  932. v_blkno = wc->w_pos >> inode->i_sb->s_blocksize_bits;
  933. }
  934. for(i = 0; i < numpages; i++) {
  935. index = start + i;
  936. cpages[i] = find_or_create_page(mapping, index, GFP_NOFS);
  937. if (!cpages[i]) {
  938. ret = -ENOMEM;
  939. mlog_errno(ret);
  940. goto out;
  941. }
  942. }
  943. if (new) {
  944. /*
  945. * This is safe to call with the page locks - it won't take
  946. * any additional semaphores or cluster locks.
  947. */
  948. tmp_pos = wc->w_cpos;
  949. ret = ocfs2_do_extend_allocation(OCFS2_SB(inode->i_sb), inode,
  950. &tmp_pos, 1, di_bh, handle,
  951. data_ac, meta_ac, NULL);
  952. /*
  953. * This shouldn't happen because we must have already
  954. * calculated the correct meta data allocation required. The
  955. * internal tree allocation code should know how to increase
  956. * transaction credits itself.
  957. *
  958. * If need be, we could handle -EAGAIN for a
  959. * RESTART_TRANS here.
  960. */
  961. mlog_bug_on_msg(ret == -EAGAIN,
  962. "Inode %llu: EAGAIN return during allocation.\n",
  963. (unsigned long long)OCFS2_I(inode)->ip_blkno);
  964. if (ret < 0) {
  965. mlog_errno(ret);
  966. goto out;
  967. }
  968. }
  969. ret = ocfs2_extent_map_get_blocks(inode, v_blkno, &p_blkno, NULL,
  970. NULL);
  971. if (ret < 0) {
  972. /*
  973. * XXX: Should we go readonly here?
  974. */
  975. mlog_errno(ret);
  976. goto out;
  977. }
  978. BUG_ON(p_blkno == 0);
  979. for(i = 0; i < numpages; i++) {
  980. ret = ocfs2_write_data_page(inode, handle, &p_blkno, cpages[i],
  981. wc, new);
  982. if (ret < 0) {
  983. mlog_errno(ret);
  984. goto out;
  985. }
  986. copied += ret;
  987. }
  988. out:
  989. for(i = 0; i < numpages; i++) {
  990. unlock_page(cpages[i]);
  991. mark_page_accessed(cpages[i]);
  992. page_cache_release(cpages[i]);
  993. }
  994. kfree(cpages);
  995. return copied ? copied : ret;
  996. }
  997. static void ocfs2_write_ctxt_init(struct ocfs2_write_ctxt *wc,
  998. struct ocfs2_super *osb, loff_t pos,
  999. size_t count, ocfs2_page_writer *cb,
  1000. void *cb_priv)
  1001. {
  1002. wc->w_count = count;
  1003. wc->w_pos = pos;
  1004. wc->w_cpos = wc->w_pos >> osb->s_clustersize_bits;
  1005. wc->w_finished_copy = 0;
  1006. if (unlikely(PAGE_CACHE_SHIFT > osb->s_clustersize_bits))
  1007. wc->w_large_pages = 1;
  1008. else
  1009. wc->w_large_pages = 0;
  1010. wc->w_write_data_page = cb;
  1011. wc->w_private = cb_priv;
  1012. }
  1013. /*
  1014. * Write a cluster to an inode. The cluster may not be allocated yet,
  1015. * in which case it will be. This only exists for buffered writes -
  1016. * O_DIRECT takes a more "traditional" path through the kernel.
  1017. *
  1018. * The caller is responsible for incrementing pos, written counts, etc
  1019. *
  1020. * For file systems that don't support sparse files, pre-allocation
  1021. * and page zeroing up until cpos should be done prior to this
  1022. * function call.
  1023. *
  1024. * Callers should be holding i_sem, and the rw cluster lock.
  1025. *
  1026. * Returns the number of user bytes written, or less than zero for
  1027. * error.
  1028. */
  1029. ssize_t ocfs2_buffered_write_cluster(struct file *file, loff_t pos,
  1030. size_t count, ocfs2_page_writer *actor,
  1031. void *priv)
  1032. {
  1033. int ret, credits = OCFS2_INODE_UPDATE_CREDITS;
  1034. ssize_t written = 0;
  1035. u32 phys;
  1036. struct inode *inode = file->f_mapping->host;
  1037. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  1038. struct buffer_head *di_bh = NULL;
  1039. struct ocfs2_dinode *di;
  1040. struct ocfs2_alloc_context *data_ac = NULL;
  1041. struct ocfs2_alloc_context *meta_ac = NULL;
  1042. handle_t *handle;
  1043. struct ocfs2_write_ctxt wc;
  1044. ocfs2_write_ctxt_init(&wc, osb, pos, count, actor, priv);
  1045. ret = ocfs2_meta_lock(inode, &di_bh, 1);
  1046. if (ret) {
  1047. mlog_errno(ret);
  1048. goto out;
  1049. }
  1050. di = (struct ocfs2_dinode *)di_bh->b_data;
  1051. /*
  1052. * Take alloc sem here to prevent concurrent lookups. That way
  1053. * the mapping, zeroing and tree manipulation within
  1054. * ocfs2_write() will be safe against ->readpage(). This
  1055. * should also serve to lock out allocation from a shared
  1056. * writeable region.
  1057. */
  1058. down_write(&OCFS2_I(inode)->ip_alloc_sem);
  1059. ret = ocfs2_get_clusters(inode, wc.w_cpos, &phys, NULL, NULL);
  1060. if (ret) {
  1061. mlog_errno(ret);
  1062. goto out_meta;
  1063. }
  1064. /* phys == 0 means that allocation is required. */
  1065. if (phys == 0) {
  1066. ret = ocfs2_lock_allocators(inode, di, 1, &data_ac, &meta_ac);
  1067. if (ret) {
  1068. mlog_errno(ret);
  1069. goto out_meta;
  1070. }
  1071. credits = ocfs2_calc_extend_credits(inode->i_sb, di, 1);
  1072. }
  1073. ret = ocfs2_data_lock(inode, 1);
  1074. if (ret) {
  1075. mlog_errno(ret);
  1076. goto out_meta;
  1077. }
  1078. handle = ocfs2_start_trans(osb, credits);
  1079. if (IS_ERR(handle)) {
  1080. ret = PTR_ERR(handle);
  1081. mlog_errno(ret);
  1082. goto out_data;
  1083. }
  1084. written = ocfs2_write(file, phys, handle, di_bh, data_ac,
  1085. meta_ac, &wc);
  1086. if (written < 0) {
  1087. ret = written;
  1088. mlog_errno(ret);
  1089. goto out_commit;
  1090. }
  1091. ret = ocfs2_journal_access(handle, inode, di_bh,
  1092. OCFS2_JOURNAL_ACCESS_WRITE);
  1093. if (ret) {
  1094. mlog_errno(ret);
  1095. goto out_commit;
  1096. }
  1097. pos += written;
  1098. if (pos > inode->i_size) {
  1099. i_size_write(inode, pos);
  1100. mark_inode_dirty(inode);
  1101. }
  1102. inode->i_blocks = ocfs2_inode_sector_count(inode);
  1103. di->i_size = cpu_to_le64((u64)i_size_read(inode));
  1104. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  1105. di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
  1106. di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
  1107. ret = ocfs2_journal_dirty(handle, di_bh);
  1108. if (ret)
  1109. mlog_errno(ret);
  1110. out_commit:
  1111. ocfs2_commit_trans(osb, handle);
  1112. out_data:
  1113. ocfs2_data_unlock(inode, 1);
  1114. out_meta:
  1115. up_write(&OCFS2_I(inode)->ip_alloc_sem);
  1116. ocfs2_meta_unlock(inode, 1);
  1117. out:
  1118. brelse(di_bh);
  1119. if (data_ac)
  1120. ocfs2_free_alloc_context(data_ac);
  1121. if (meta_ac)
  1122. ocfs2_free_alloc_context(meta_ac);
  1123. return written ? written : ret;
  1124. }
  1125. const struct address_space_operations ocfs2_aops = {
  1126. .readpage = ocfs2_readpage,
  1127. .writepage = ocfs2_writepage,
  1128. .bmap = ocfs2_bmap,
  1129. .sync_page = block_sync_page,
  1130. .direct_IO = ocfs2_direct_IO,
  1131. .invalidatepage = ocfs2_invalidatepage,
  1132. .releasepage = ocfs2_releasepage,
  1133. .migratepage = buffer_migrate_page,
  1134. };