inode.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * inode.c
  5. *
  6. * vfs' aops, fops, dops and iops
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. */
  25. #include <linux/fs.h>
  26. #include <linux/types.h>
  27. #include <linux/slab.h>
  28. #include <linux/highmem.h>
  29. #include <linux/pagemap.h>
  30. #include <linux/smp_lock.h>
  31. #include <asm/byteorder.h>
  32. #define MLOG_MASK_PREFIX ML_INODE
  33. #include <cluster/masklog.h>
  34. #include "ocfs2.h"
  35. #include "alloc.h"
  36. #include "dlmglue.h"
  37. #include "extent_map.h"
  38. #include "file.h"
  39. #include "heartbeat.h"
  40. #include "inode.h"
  41. #include "journal.h"
  42. #include "namei.h"
  43. #include "suballoc.h"
  44. #include "super.h"
  45. #include "symlink.h"
  46. #include "sysfile.h"
  47. #include "uptodate.h"
  48. #include "vote.h"
  49. #include "buffer_head_io.h"
  50. struct ocfs2_find_inode_args
  51. {
  52. u64 fi_blkno;
  53. unsigned long fi_ino;
  54. unsigned int fi_flags;
  55. };
  56. static int ocfs2_read_locked_inode(struct inode *inode,
  57. struct ocfs2_find_inode_args *args);
  58. static int ocfs2_init_locked_inode(struct inode *inode, void *opaque);
  59. static int ocfs2_find_actor(struct inode *inode, void *opaque);
  60. static int ocfs2_truncate_for_delete(struct ocfs2_super *osb,
  61. struct inode *inode,
  62. struct buffer_head *fe_bh);
  63. void ocfs2_set_inode_flags(struct inode *inode)
  64. {
  65. unsigned int flags = OCFS2_I(inode)->ip_attr;
  66. inode->i_flags &= ~(S_IMMUTABLE |
  67. S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
  68. if (flags & OCFS2_IMMUTABLE_FL)
  69. inode->i_flags |= S_IMMUTABLE;
  70. if (flags & OCFS2_SYNC_FL)
  71. inode->i_flags |= S_SYNC;
  72. if (flags & OCFS2_APPEND_FL)
  73. inode->i_flags |= S_APPEND;
  74. if (flags & OCFS2_NOATIME_FL)
  75. inode->i_flags |= S_NOATIME;
  76. if (flags & OCFS2_DIRSYNC_FL)
  77. inode->i_flags |= S_DIRSYNC;
  78. }
  79. struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, int flags)
  80. {
  81. struct inode *inode = NULL;
  82. struct super_block *sb = osb->sb;
  83. struct ocfs2_find_inode_args args;
  84. mlog_entry("(blkno = %llu)\n", (unsigned long long)blkno);
  85. /* Ok. By now we've either got the offsets passed to us by the
  86. * caller, or we just pulled them off the bh. Lets do some
  87. * sanity checks to make sure they're OK. */
  88. if (blkno == 0) {
  89. inode = ERR_PTR(-EINVAL);
  90. mlog_errno(PTR_ERR(inode));
  91. goto bail;
  92. }
  93. args.fi_blkno = blkno;
  94. args.fi_flags = flags;
  95. args.fi_ino = ino_from_blkno(sb, blkno);
  96. inode = iget5_locked(sb, args.fi_ino, ocfs2_find_actor,
  97. ocfs2_init_locked_inode, &args);
  98. /* inode was *not* in the inode cache. 2.6.x requires
  99. * us to do our own read_inode call and unlock it
  100. * afterwards. */
  101. if (inode && inode->i_state & I_NEW) {
  102. mlog(0, "Inode was not in inode cache, reading it.\n");
  103. ocfs2_read_locked_inode(inode, &args);
  104. unlock_new_inode(inode);
  105. }
  106. if (inode == NULL) {
  107. inode = ERR_PTR(-ENOMEM);
  108. mlog_errno(PTR_ERR(inode));
  109. goto bail;
  110. }
  111. if (is_bad_inode(inode)) {
  112. iput(inode);
  113. inode = ERR_PTR(-ESTALE);
  114. goto bail;
  115. }
  116. bail:
  117. if (!IS_ERR(inode)) {
  118. mlog(0, "returning inode with number %llu\n",
  119. (unsigned long long)OCFS2_I(inode)->ip_blkno);
  120. mlog_exit_ptr(inode);
  121. }
  122. return inode;
  123. }
  124. /*
  125. * here's how inodes get read from disk:
  126. * iget5_locked -> find_actor -> OCFS2_FIND_ACTOR
  127. * found? : return the in-memory inode
  128. * not found? : get_new_inode -> OCFS2_INIT_LOCKED_INODE
  129. */
  130. static int ocfs2_find_actor(struct inode *inode, void *opaque)
  131. {
  132. struct ocfs2_find_inode_args *args = NULL;
  133. struct ocfs2_inode_info *oi = OCFS2_I(inode);
  134. int ret = 0;
  135. mlog_entry("(0x%p, %lu, 0x%p)\n", inode, inode->i_ino, opaque);
  136. args = opaque;
  137. mlog_bug_on_msg(!inode, "No inode in find actor!\n");
  138. if (oi->ip_blkno != args->fi_blkno)
  139. goto bail;
  140. ret = 1;
  141. bail:
  142. mlog_exit(ret);
  143. return ret;
  144. }
  145. /*
  146. * initialize the new inode, but don't do anything that would cause
  147. * us to sleep.
  148. * return 0 on success, 1 on failure
  149. */
  150. static int ocfs2_init_locked_inode(struct inode *inode, void *opaque)
  151. {
  152. struct ocfs2_find_inode_args *args = opaque;
  153. mlog_entry("inode = %p, opaque = %p\n", inode, opaque);
  154. inode->i_ino = args->fi_ino;
  155. OCFS2_I(inode)->ip_blkno = args->fi_blkno;
  156. mlog_exit(0);
  157. return 0;
  158. }
  159. int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
  160. int create_ino)
  161. {
  162. struct super_block *sb;
  163. struct ocfs2_super *osb;
  164. int status = -EINVAL;
  165. mlog_entry("(0x%p, size:%llu)\n", inode,
  166. (unsigned long long)fe->i_size);
  167. sb = inode->i_sb;
  168. osb = OCFS2_SB(sb);
  169. /* this means that read_inode cannot create a superblock inode
  170. * today. change if needed. */
  171. if (!OCFS2_IS_VALID_DINODE(fe) ||
  172. !(fe->i_flags & cpu_to_le32(OCFS2_VALID_FL))) {
  173. mlog(0, "Invalid dinode: i_ino=%lu, i_blkno=%llu, "
  174. "signature = %.*s, flags = 0x%x\n",
  175. inode->i_ino,
  176. (unsigned long long)le64_to_cpu(fe->i_blkno), 7,
  177. fe->i_signature, le32_to_cpu(fe->i_flags));
  178. goto bail;
  179. }
  180. if (le32_to_cpu(fe->i_fs_generation) != osb->fs_generation) {
  181. mlog(ML_ERROR, "file entry generation does not match "
  182. "superblock! osb->fs_generation=%x, "
  183. "fe->i_fs_generation=%x\n",
  184. osb->fs_generation, le32_to_cpu(fe->i_fs_generation));
  185. goto bail;
  186. }
  187. inode->i_version = 1;
  188. inode->i_generation = le32_to_cpu(fe->i_generation);
  189. inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
  190. inode->i_mode = le16_to_cpu(fe->i_mode);
  191. inode->i_uid = le32_to_cpu(fe->i_uid);
  192. inode->i_gid = le32_to_cpu(fe->i_gid);
  193. /* Fast symlinks will have i_size but no allocated clusters. */
  194. if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
  195. inode->i_blocks = 0;
  196. else
  197. inode->i_blocks =
  198. ocfs2_align_bytes_to_sectors(le64_to_cpu(fe->i_size));
  199. inode->i_mapping->a_ops = &ocfs2_aops;
  200. inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime);
  201. inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec);
  202. inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime);
  203. inode->i_mtime.tv_nsec = le32_to_cpu(fe->i_mtime_nsec);
  204. inode->i_ctime.tv_sec = le64_to_cpu(fe->i_ctime);
  205. inode->i_ctime.tv_nsec = le32_to_cpu(fe->i_ctime_nsec);
  206. if (OCFS2_I(inode)->ip_blkno != le64_to_cpu(fe->i_blkno))
  207. mlog(ML_ERROR,
  208. "ip_blkno %llu != i_blkno %llu!\n",
  209. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  210. (unsigned long long)fe->i_blkno);
  211. OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
  212. OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
  213. inode->i_nlink = le16_to_cpu(fe->i_links_count);
  214. if (fe->i_flags & cpu_to_le32(OCFS2_SYSTEM_FL))
  215. OCFS2_I(inode)->ip_flags |= OCFS2_INODE_SYSTEM_FILE;
  216. if (fe->i_flags & cpu_to_le32(OCFS2_LOCAL_ALLOC_FL)) {
  217. OCFS2_I(inode)->ip_flags |= OCFS2_INODE_BITMAP;
  218. mlog(0, "local alloc inode: i_ino=%lu\n", inode->i_ino);
  219. } else if (fe->i_flags & cpu_to_le32(OCFS2_BITMAP_FL)) {
  220. OCFS2_I(inode)->ip_flags |= OCFS2_INODE_BITMAP;
  221. } else if (fe->i_flags & cpu_to_le32(OCFS2_SUPER_BLOCK_FL)) {
  222. mlog(0, "superblock inode: i_ino=%lu\n", inode->i_ino);
  223. /* we can't actually hit this as read_inode can't
  224. * handle superblocks today ;-) */
  225. BUG();
  226. }
  227. switch (inode->i_mode & S_IFMT) {
  228. case S_IFREG:
  229. inode->i_fop = &ocfs2_fops;
  230. inode->i_op = &ocfs2_file_iops;
  231. i_size_write(inode, le64_to_cpu(fe->i_size));
  232. break;
  233. case S_IFDIR:
  234. inode->i_op = &ocfs2_dir_iops;
  235. inode->i_fop = &ocfs2_dops;
  236. i_size_write(inode, le64_to_cpu(fe->i_size));
  237. break;
  238. case S_IFLNK:
  239. if (ocfs2_inode_is_fast_symlink(inode))
  240. inode->i_op = &ocfs2_fast_symlink_inode_operations;
  241. else
  242. inode->i_op = &ocfs2_symlink_inode_operations;
  243. i_size_write(inode, le64_to_cpu(fe->i_size));
  244. break;
  245. default:
  246. inode->i_op = &ocfs2_special_file_iops;
  247. init_special_inode(inode, inode->i_mode,
  248. inode->i_rdev);
  249. break;
  250. }
  251. if (create_ino) {
  252. inode->i_ino = ino_from_blkno(inode->i_sb,
  253. le64_to_cpu(fe->i_blkno));
  254. /*
  255. * If we ever want to create system files from kernel,
  256. * the generation argument to
  257. * ocfs2_inode_lock_res_init() will have to change.
  258. */
  259. BUG_ON(fe->i_flags & cpu_to_le32(OCFS2_SYSTEM_FL));
  260. ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_meta_lockres,
  261. OCFS2_LOCK_TYPE_META, 0, inode);
  262. ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_open_lockres,
  263. OCFS2_LOCK_TYPE_OPEN, 0, inode);
  264. }
  265. ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_rw_lockres,
  266. OCFS2_LOCK_TYPE_RW, inode->i_generation,
  267. inode);
  268. ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_data_lockres,
  269. OCFS2_LOCK_TYPE_DATA, inode->i_generation,
  270. inode);
  271. ocfs2_set_inode_flags(inode);
  272. status = 0;
  273. bail:
  274. mlog_exit(status);
  275. return status;
  276. }
  277. static int ocfs2_read_locked_inode(struct inode *inode,
  278. struct ocfs2_find_inode_args *args)
  279. {
  280. struct super_block *sb;
  281. struct ocfs2_super *osb;
  282. struct ocfs2_dinode *fe;
  283. struct buffer_head *bh = NULL;
  284. int status, can_lock;
  285. u32 generation = 0;
  286. mlog_entry("(0x%p, 0x%p)\n", inode, args);
  287. status = -EINVAL;
  288. if (inode == NULL || inode->i_sb == NULL) {
  289. mlog(ML_ERROR, "bad inode\n");
  290. return status;
  291. }
  292. sb = inode->i_sb;
  293. osb = OCFS2_SB(sb);
  294. if (!args) {
  295. mlog(ML_ERROR, "bad inode args\n");
  296. make_bad_inode(inode);
  297. return status;
  298. }
  299. /*
  300. * To improve performance of cold-cache inode stats, we take
  301. * the cluster lock here if possible.
  302. *
  303. * Generally, OCFS2 never trusts the contents of an inode
  304. * unless it's holding a cluster lock, so taking it here isn't
  305. * a correctness issue as much as it is a performance
  306. * improvement.
  307. *
  308. * There are three times when taking the lock is not a good idea:
  309. *
  310. * 1) During startup, before we have initialized the DLM.
  311. *
  312. * 2) If we are reading certain system files which never get
  313. * cluster locks (local alloc, truncate log).
  314. *
  315. * 3) If the process doing the iget() is responsible for
  316. * orphan dir recovery. We're holding the orphan dir lock and
  317. * can get into a deadlock with another process on another
  318. * node in ->delete_inode().
  319. *
  320. * #1 and #2 can be simply solved by never taking the lock
  321. * here for system files (which are the only type we read
  322. * during mount). It's a heavier approach, but our main
  323. * concern is user-accesible files anyway.
  324. *
  325. * #3 works itself out because we'll eventually take the
  326. * cluster lock before trusting anything anyway.
  327. */
  328. can_lock = !(args->fi_flags & OCFS2_FI_FLAG_SYSFILE)
  329. && !(args->fi_flags & OCFS2_FI_FLAG_ORPHAN_RECOVERY)
  330. && !ocfs2_mount_local(osb);
  331. /*
  332. * To maintain backwards compatibility with older versions of
  333. * ocfs2-tools, we still store the generation value for system
  334. * files. The only ones that actually matter to userspace are
  335. * the journals, but it's easier and inexpensive to just flag
  336. * all system files similarly.
  337. */
  338. if (args->fi_flags & OCFS2_FI_FLAG_SYSFILE)
  339. generation = osb->fs_generation;
  340. ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_meta_lockres,
  341. OCFS2_LOCK_TYPE_META,
  342. generation, inode);
  343. ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_open_lockres,
  344. OCFS2_LOCK_TYPE_OPEN,
  345. 0, inode);
  346. if (can_lock) {
  347. status = ocfs2_open_lock(inode);
  348. if (status) {
  349. make_bad_inode(inode);
  350. mlog_errno(status);
  351. return status;
  352. }
  353. status = ocfs2_meta_lock(inode, NULL, 0);
  354. if (status) {
  355. make_bad_inode(inode);
  356. mlog_errno(status);
  357. return status;
  358. }
  359. }
  360. if (args->fi_flags & OCFS2_FI_FLAG_ORPHAN_RECOVERY) {
  361. status = ocfs2_try_open_lock(inode, 0);
  362. if (status) {
  363. make_bad_inode(inode);
  364. return status;
  365. }
  366. }
  367. status = ocfs2_read_block(osb, args->fi_blkno, &bh, 0,
  368. can_lock ? inode : NULL);
  369. if (status < 0) {
  370. mlog_errno(status);
  371. goto bail;
  372. }
  373. status = -EINVAL;
  374. fe = (struct ocfs2_dinode *) bh->b_data;
  375. if (!OCFS2_IS_VALID_DINODE(fe)) {
  376. mlog(ML_ERROR, "Invalid dinode #%llu: signature = %.*s\n",
  377. (unsigned long long)fe->i_blkno, 7, fe->i_signature);
  378. goto bail;
  379. }
  380. /*
  381. * This is a code bug. Right now the caller needs to
  382. * understand whether it is asking for a system file inode or
  383. * not so the proper lock names can be built.
  384. */
  385. mlog_bug_on_msg(!!(fe->i_flags & cpu_to_le32(OCFS2_SYSTEM_FL)) !=
  386. !!(args->fi_flags & OCFS2_FI_FLAG_SYSFILE),
  387. "Inode %llu: system file state is ambigous\n",
  388. (unsigned long long)args->fi_blkno);
  389. if (S_ISCHR(le16_to_cpu(fe->i_mode)) ||
  390. S_ISBLK(le16_to_cpu(fe->i_mode)))
  391. inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
  392. if (ocfs2_populate_inode(inode, fe, 0) < 0)
  393. goto bail;
  394. BUG_ON(args->fi_blkno != le64_to_cpu(fe->i_blkno));
  395. status = 0;
  396. bail:
  397. if (can_lock)
  398. ocfs2_meta_unlock(inode, 0);
  399. if (status < 0)
  400. make_bad_inode(inode);
  401. if (args && bh)
  402. brelse(bh);
  403. mlog_exit(status);
  404. return status;
  405. }
  406. void ocfs2_sync_blockdev(struct super_block *sb)
  407. {
  408. sync_blockdev(sb->s_bdev);
  409. }
  410. static int ocfs2_truncate_for_delete(struct ocfs2_super *osb,
  411. struct inode *inode,
  412. struct buffer_head *fe_bh)
  413. {
  414. int status = 0;
  415. handle_t *handle = NULL;
  416. struct ocfs2_truncate_context *tc = NULL;
  417. struct ocfs2_dinode *fe;
  418. mlog_entry_void();
  419. fe = (struct ocfs2_dinode *) fe_bh->b_data;
  420. /* zero allocation, zero truncate :) */
  421. if (!fe->i_clusters)
  422. goto bail;
  423. handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
  424. if (IS_ERR(handle)) {
  425. status = PTR_ERR(handle);
  426. handle = NULL;
  427. mlog_errno(status);
  428. goto bail;
  429. }
  430. status = ocfs2_set_inode_size(handle, inode, fe_bh, 0ULL);
  431. if (status < 0) {
  432. mlog_errno(status);
  433. goto bail;
  434. }
  435. ocfs2_commit_trans(osb, handle);
  436. handle = NULL;
  437. status = ocfs2_prepare_truncate(osb, inode, fe_bh, &tc);
  438. if (status < 0) {
  439. mlog_errno(status);
  440. goto bail;
  441. }
  442. status = ocfs2_commit_truncate(osb, inode, fe_bh, tc);
  443. if (status < 0) {
  444. mlog_errno(status);
  445. goto bail;
  446. }
  447. bail:
  448. if (handle)
  449. ocfs2_commit_trans(osb, handle);
  450. mlog_exit(status);
  451. return status;
  452. }
  453. static int ocfs2_remove_inode(struct inode *inode,
  454. struct buffer_head *di_bh,
  455. struct inode *orphan_dir_inode,
  456. struct buffer_head *orphan_dir_bh)
  457. {
  458. int status;
  459. struct inode *inode_alloc_inode = NULL;
  460. struct buffer_head *inode_alloc_bh = NULL;
  461. handle_t *handle;
  462. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  463. struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data;
  464. inode_alloc_inode =
  465. ocfs2_get_system_file_inode(osb, INODE_ALLOC_SYSTEM_INODE,
  466. le16_to_cpu(di->i_suballoc_slot));
  467. if (!inode_alloc_inode) {
  468. status = -EEXIST;
  469. mlog_errno(status);
  470. goto bail;
  471. }
  472. mutex_lock(&inode_alloc_inode->i_mutex);
  473. status = ocfs2_meta_lock(inode_alloc_inode, &inode_alloc_bh, 1);
  474. if (status < 0) {
  475. mutex_unlock(&inode_alloc_inode->i_mutex);
  476. mlog_errno(status);
  477. goto bail;
  478. }
  479. handle = ocfs2_start_trans(osb, OCFS2_DELETE_INODE_CREDITS);
  480. if (IS_ERR(handle)) {
  481. status = PTR_ERR(handle);
  482. mlog_errno(status);
  483. goto bail_unlock;
  484. }
  485. status = ocfs2_orphan_del(osb, handle, orphan_dir_inode, inode,
  486. orphan_dir_bh);
  487. if (status < 0) {
  488. mlog_errno(status);
  489. goto bail_commit;
  490. }
  491. /* set the inodes dtime */
  492. status = ocfs2_journal_access(handle, inode, di_bh,
  493. OCFS2_JOURNAL_ACCESS_WRITE);
  494. if (status < 0) {
  495. mlog_errno(status);
  496. goto bail_commit;
  497. }
  498. di->i_dtime = cpu_to_le64(CURRENT_TIME.tv_sec);
  499. le32_and_cpu(&di->i_flags, ~(OCFS2_VALID_FL | OCFS2_ORPHANED_FL));
  500. status = ocfs2_journal_dirty(handle, di_bh);
  501. if (status < 0) {
  502. mlog_errno(status);
  503. goto bail_commit;
  504. }
  505. ocfs2_remove_from_cache(inode, di_bh);
  506. status = ocfs2_free_dinode(handle, inode_alloc_inode,
  507. inode_alloc_bh, di);
  508. if (status < 0)
  509. mlog_errno(status);
  510. bail_commit:
  511. ocfs2_commit_trans(osb, handle);
  512. bail_unlock:
  513. ocfs2_meta_unlock(inode_alloc_inode, 1);
  514. mutex_unlock(&inode_alloc_inode->i_mutex);
  515. brelse(inode_alloc_bh);
  516. bail:
  517. iput(inode_alloc_inode);
  518. return status;
  519. }
  520. /*
  521. * Serialize with orphan dir recovery. If the process doing
  522. * recovery on this orphan dir does an iget() with the dir
  523. * i_mutex held, we'll deadlock here. Instead we detect this
  524. * and exit early - recovery will wipe this inode for us.
  525. */
  526. static int ocfs2_check_orphan_recovery_state(struct ocfs2_super *osb,
  527. int slot)
  528. {
  529. int ret = 0;
  530. spin_lock(&osb->osb_lock);
  531. if (ocfs2_node_map_test_bit(osb, &osb->osb_recovering_orphan_dirs, slot)) {
  532. mlog(0, "Recovery is happening on orphan dir %d, will skip "
  533. "this inode\n", slot);
  534. ret = -EDEADLK;
  535. goto out;
  536. }
  537. /* This signals to the orphan recovery process that it should
  538. * wait for us to handle the wipe. */
  539. osb->osb_orphan_wipes[slot]++;
  540. out:
  541. spin_unlock(&osb->osb_lock);
  542. return ret;
  543. }
  544. static void ocfs2_signal_wipe_completion(struct ocfs2_super *osb,
  545. int slot)
  546. {
  547. spin_lock(&osb->osb_lock);
  548. osb->osb_orphan_wipes[slot]--;
  549. spin_unlock(&osb->osb_lock);
  550. wake_up(&osb->osb_wipe_event);
  551. }
  552. static int ocfs2_wipe_inode(struct inode *inode,
  553. struct buffer_head *di_bh)
  554. {
  555. int status, orphaned_slot;
  556. struct inode *orphan_dir_inode = NULL;
  557. struct buffer_head *orphan_dir_bh = NULL;
  558. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  559. struct ocfs2_dinode *di;
  560. di = (struct ocfs2_dinode *) di_bh->b_data;
  561. orphaned_slot = le16_to_cpu(di->i_orphaned_slot);
  562. status = ocfs2_check_orphan_recovery_state(osb, orphaned_slot);
  563. if (status)
  564. return status;
  565. orphan_dir_inode = ocfs2_get_system_file_inode(osb,
  566. ORPHAN_DIR_SYSTEM_INODE,
  567. orphaned_slot);
  568. if (!orphan_dir_inode) {
  569. status = -EEXIST;
  570. mlog_errno(status);
  571. goto bail;
  572. }
  573. /* Lock the orphan dir. The lock will be held for the entire
  574. * delete_inode operation. We do this now to avoid races with
  575. * recovery completion on other nodes. */
  576. mutex_lock(&orphan_dir_inode->i_mutex);
  577. status = ocfs2_meta_lock(orphan_dir_inode, &orphan_dir_bh, 1);
  578. if (status < 0) {
  579. mutex_unlock(&orphan_dir_inode->i_mutex);
  580. mlog_errno(status);
  581. goto bail;
  582. }
  583. /* we do this while holding the orphan dir lock because we
  584. * don't want recovery being run from another node to vote for
  585. * an inode delete on us -- this will result in two nodes
  586. * truncating the same file! */
  587. status = ocfs2_truncate_for_delete(osb, inode, di_bh);
  588. if (status < 0) {
  589. mlog_errno(status);
  590. goto bail_unlock_dir;
  591. }
  592. status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode,
  593. orphan_dir_bh);
  594. if (status < 0)
  595. mlog_errno(status);
  596. bail_unlock_dir:
  597. ocfs2_meta_unlock(orphan_dir_inode, 1);
  598. mutex_unlock(&orphan_dir_inode->i_mutex);
  599. brelse(orphan_dir_bh);
  600. bail:
  601. iput(orphan_dir_inode);
  602. ocfs2_signal_wipe_completion(osb, orphaned_slot);
  603. return status;
  604. }
  605. /* There is a series of simple checks that should be done before a
  606. * vote is even considered. Encapsulate those in this function. */
  607. static int ocfs2_inode_is_valid_to_delete(struct inode *inode)
  608. {
  609. int ret = 0;
  610. struct ocfs2_inode_info *oi = OCFS2_I(inode);
  611. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  612. /* We shouldn't be getting here for the root directory
  613. * inode.. */
  614. if (inode == osb->root_inode) {
  615. mlog(ML_ERROR, "Skipping delete of root inode.\n");
  616. goto bail;
  617. }
  618. /* If we're coming from process_vote we can't go into our own
  619. * voting [hello, deadlock city!], so unforuntately we just
  620. * have to skip deleting this guy. That's OK though because
  621. * the node who's doing the actual deleting should handle it
  622. * anyway. */
  623. if (current == osb->vote_task) {
  624. mlog(0, "Skipping delete of %lu because we're currently "
  625. "in process_vote\n", inode->i_ino);
  626. goto bail;
  627. }
  628. spin_lock(&oi->ip_lock);
  629. /* OCFS2 *never* deletes system files. This should technically
  630. * never get here as system file inodes should always have a
  631. * positive link count. */
  632. if (oi->ip_flags & OCFS2_INODE_SYSTEM_FILE) {
  633. mlog(ML_ERROR, "Skipping delete of system file %llu\n",
  634. (unsigned long long)oi->ip_blkno);
  635. goto bail_unlock;
  636. }
  637. /* If we have voted "yes" on the wipe of this inode for
  638. * another node, it will be marked here so we can safely skip
  639. * it. Recovery will cleanup any inodes we might inadvertantly
  640. * skip here. */
  641. if (oi->ip_flags & OCFS2_INODE_SKIP_DELETE) {
  642. mlog(0, "Skipping delete of %lu because another node "
  643. "has done this for us.\n", inode->i_ino);
  644. goto bail_unlock;
  645. }
  646. ret = 1;
  647. bail_unlock:
  648. spin_unlock(&oi->ip_lock);
  649. bail:
  650. return ret;
  651. }
  652. /* Query the cluster to determine whether we should wipe an inode from
  653. * disk or not.
  654. *
  655. * Requires the inode to have the cluster lock. */
  656. static int ocfs2_query_inode_wipe(struct inode *inode,
  657. struct buffer_head *di_bh,
  658. int *wipe)
  659. {
  660. int status = 0;
  661. struct ocfs2_inode_info *oi = OCFS2_I(inode);
  662. struct ocfs2_dinode *di;
  663. *wipe = 0;
  664. /* While we were waiting for the cluster lock in
  665. * ocfs2_delete_inode, another node might have asked to delete
  666. * the inode. Recheck our flags to catch this. */
  667. if (!ocfs2_inode_is_valid_to_delete(inode)) {
  668. mlog(0, "Skipping delete of %llu because flags changed\n",
  669. (unsigned long long)oi->ip_blkno);
  670. goto bail;
  671. }
  672. /* Now that we have an up to date inode, we can double check
  673. * the link count. */
  674. if (inode->i_nlink) {
  675. mlog(0, "Skipping delete of %llu because nlink = %u\n",
  676. (unsigned long long)oi->ip_blkno, inode->i_nlink);
  677. goto bail;
  678. }
  679. /* Do some basic inode verification... */
  680. di = (struct ocfs2_dinode *) di_bh->b_data;
  681. if (!(di->i_flags & cpu_to_le32(OCFS2_ORPHANED_FL))) {
  682. /* for lack of a better error? */
  683. status = -EEXIST;
  684. mlog(ML_ERROR,
  685. "Inode %llu (on-disk %llu) not orphaned! "
  686. "Disk flags 0x%x, inode flags 0x%x\n",
  687. (unsigned long long)oi->ip_blkno,
  688. (unsigned long long)di->i_blkno, di->i_flags,
  689. oi->ip_flags);
  690. goto bail;
  691. }
  692. /* has someone already deleted us?! baaad... */
  693. if (di->i_dtime) {
  694. status = -EEXIST;
  695. mlog_errno(status);
  696. goto bail;
  697. }
  698. /*
  699. * This is how ocfs2 determines whether an inode is still live
  700. * within the cluster. Every node takes a shared read lock on
  701. * the inode open lock in ocfs2_read_locked_inode(). When we
  702. * get to ->delete_inode(), each node tries to convert it's
  703. * lock to an exclusive. Trylocks are serialized by the inode
  704. * meta data lock. If the upconvert suceeds, we know the inode
  705. * is no longer live and can be deleted.
  706. *
  707. * Though we call this with the meta data lock held, the
  708. * trylock keeps us from ABBA deadlock.
  709. */
  710. status = ocfs2_try_open_lock(inode, 1);
  711. if (status == -EAGAIN) {
  712. status = 0;
  713. mlog(0, "Skipping delete of %llu because it is in use on"
  714. "other nodes\n", (unsigned long long)oi->ip_blkno);
  715. goto bail;
  716. }
  717. if (status < 0) {
  718. mlog_errno(status);
  719. goto bail;
  720. }
  721. *wipe = 1;
  722. mlog(0, "Inode %llu is ok to wipe from orphan dir %u\n",
  723. (unsigned long long)oi->ip_blkno,
  724. le16_to_cpu(di->i_orphaned_slot));
  725. bail:
  726. return status;
  727. }
  728. /* Support function for ocfs2_delete_inode. Will help us keep the
  729. * inode data in a consistent state for clear_inode. Always truncates
  730. * pages, optionally sync's them first. */
  731. static void ocfs2_cleanup_delete_inode(struct inode *inode,
  732. int sync_data)
  733. {
  734. mlog(0, "Cleanup inode %llu, sync = %d\n",
  735. (unsigned long long)OCFS2_I(inode)->ip_blkno, sync_data);
  736. if (sync_data)
  737. write_inode_now(inode, 1);
  738. truncate_inode_pages(&inode->i_data, 0);
  739. }
  740. void ocfs2_delete_inode(struct inode *inode)
  741. {
  742. int wipe, status;
  743. sigset_t blocked, oldset;
  744. struct buffer_head *di_bh = NULL;
  745. mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino);
  746. if (is_bad_inode(inode)) {
  747. mlog(0, "Skipping delete of bad inode\n");
  748. goto bail;
  749. }
  750. if (!ocfs2_inode_is_valid_to_delete(inode)) {
  751. /* It's probably not necessary to truncate_inode_pages
  752. * here but we do it for safety anyway (it will most
  753. * likely be a no-op anyway) */
  754. ocfs2_cleanup_delete_inode(inode, 0);
  755. goto bail;
  756. }
  757. /* We want to block signals in delete_inode as the lock and
  758. * messaging paths may return us -ERESTARTSYS. Which would
  759. * cause us to exit early, resulting in inodes being orphaned
  760. * forever. */
  761. sigfillset(&blocked);
  762. status = sigprocmask(SIG_BLOCK, &blocked, &oldset);
  763. if (status < 0) {
  764. mlog_errno(status);
  765. ocfs2_cleanup_delete_inode(inode, 1);
  766. goto bail;
  767. }
  768. /* Lock down the inode. This gives us an up to date view of
  769. * it's metadata (for verification), and allows us to
  770. * serialize delete_inode votes.
  771. *
  772. * Even though we might be doing a truncate, we don't take the
  773. * allocation lock here as it won't be needed - nobody will
  774. * have the file open.
  775. */
  776. status = ocfs2_meta_lock(inode, &di_bh, 1);
  777. if (status < 0) {
  778. if (status != -ENOENT)
  779. mlog_errno(status);
  780. ocfs2_cleanup_delete_inode(inode, 0);
  781. goto bail_unblock;
  782. }
  783. /* Query the cluster. This will be the final decision made
  784. * before we go ahead and wipe the inode. */
  785. status = ocfs2_query_inode_wipe(inode, di_bh, &wipe);
  786. if (!wipe || status < 0) {
  787. /* Error and inode busy vote both mean we won't be
  788. * removing the inode, so they take almost the same
  789. * path. */
  790. if (status < 0)
  791. mlog_errno(status);
  792. /* Someone in the cluster has voted to not wipe this
  793. * inode, or it was never completely orphaned. Write
  794. * out the pages and exit now. */
  795. ocfs2_cleanup_delete_inode(inode, 1);
  796. goto bail_unlock_inode;
  797. }
  798. ocfs2_cleanup_delete_inode(inode, 0);
  799. status = ocfs2_wipe_inode(inode, di_bh);
  800. if (status < 0) {
  801. if (status != -EDEADLK)
  802. mlog_errno(status);
  803. goto bail_unlock_inode;
  804. }
  805. /*
  806. * Mark the inode as successfully deleted.
  807. *
  808. * This is important for ocfs2_clear_inode() as it will check
  809. * this flag and skip any checkpointing work
  810. *
  811. * ocfs2_stuff_meta_lvb() also uses this flag to invalidate
  812. * the LVB for other nodes.
  813. */
  814. OCFS2_I(inode)->ip_flags |= OCFS2_INODE_DELETED;
  815. bail_unlock_inode:
  816. ocfs2_meta_unlock(inode, 1);
  817. brelse(di_bh);
  818. bail_unblock:
  819. status = sigprocmask(SIG_SETMASK, &oldset, NULL);
  820. if (status < 0)
  821. mlog_errno(status);
  822. bail:
  823. clear_inode(inode);
  824. mlog_exit_void();
  825. }
  826. void ocfs2_clear_inode(struct inode *inode)
  827. {
  828. int status;
  829. struct ocfs2_inode_info *oi = OCFS2_I(inode);
  830. mlog_entry_void();
  831. if (!inode)
  832. goto bail;
  833. mlog(0, "Clearing inode: %llu, nlink = %u\n",
  834. (unsigned long long)OCFS2_I(inode)->ip_blkno, inode->i_nlink);
  835. mlog_bug_on_msg(OCFS2_SB(inode->i_sb) == NULL,
  836. "Inode=%lu\n", inode->i_ino);
  837. /* For remove delete_inode vote, we hold open lock before,
  838. * now it is time to unlock PR and EX open locks. */
  839. ocfs2_open_unlock(inode);
  840. /* Do these before all the other work so that we don't bounce
  841. * the vote thread while waiting to destroy the locks. */
  842. ocfs2_mark_lockres_freeing(&oi->ip_rw_lockres);
  843. ocfs2_mark_lockres_freeing(&oi->ip_meta_lockres);
  844. ocfs2_mark_lockres_freeing(&oi->ip_data_lockres);
  845. ocfs2_mark_lockres_freeing(&oi->ip_open_lockres);
  846. /* We very well may get a clear_inode before all an inodes
  847. * metadata has hit disk. Of course, we can't drop any cluster
  848. * locks until the journal has finished with it. The only
  849. * exception here are successfully wiped inodes - their
  850. * metadata can now be considered to be part of the system
  851. * inodes from which it came. */
  852. if (!(OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED))
  853. ocfs2_checkpoint_inode(inode);
  854. mlog_bug_on_msg(!list_empty(&oi->ip_io_markers),
  855. "Clear inode of %llu, inode has io markers\n",
  856. (unsigned long long)oi->ip_blkno);
  857. status = ocfs2_drop_inode_locks(inode);
  858. if (status < 0)
  859. mlog_errno(status);
  860. ocfs2_lock_res_free(&oi->ip_rw_lockres);
  861. ocfs2_lock_res_free(&oi->ip_meta_lockres);
  862. ocfs2_lock_res_free(&oi->ip_data_lockres);
  863. ocfs2_lock_res_free(&oi->ip_open_lockres);
  864. ocfs2_metadata_cache_purge(inode);
  865. mlog_bug_on_msg(oi->ip_metadata_cache.ci_num_cached,
  866. "Clear inode of %llu, inode has %u cache items\n",
  867. (unsigned long long)oi->ip_blkno, oi->ip_metadata_cache.ci_num_cached);
  868. mlog_bug_on_msg(!(oi->ip_flags & OCFS2_INODE_CACHE_INLINE),
  869. "Clear inode of %llu, inode has a bad flag\n",
  870. (unsigned long long)oi->ip_blkno);
  871. mlog_bug_on_msg(spin_is_locked(&oi->ip_lock),
  872. "Clear inode of %llu, inode is locked\n",
  873. (unsigned long long)oi->ip_blkno);
  874. mlog_bug_on_msg(!mutex_trylock(&oi->ip_io_mutex),
  875. "Clear inode of %llu, io_mutex is locked\n",
  876. (unsigned long long)oi->ip_blkno);
  877. mutex_unlock(&oi->ip_io_mutex);
  878. /*
  879. * down_trylock() returns 0, down_write_trylock() returns 1
  880. * kernel 1, world 0
  881. */
  882. mlog_bug_on_msg(!down_write_trylock(&oi->ip_alloc_sem),
  883. "Clear inode of %llu, alloc_sem is locked\n",
  884. (unsigned long long)oi->ip_blkno);
  885. up_write(&oi->ip_alloc_sem);
  886. mlog_bug_on_msg(oi->ip_open_count,
  887. "Clear inode of %llu has open count %d\n",
  888. (unsigned long long)oi->ip_blkno, oi->ip_open_count);
  889. /* Clear all other flags. */
  890. oi->ip_flags = OCFS2_INODE_CACHE_INLINE;
  891. oi->ip_created_trans = 0;
  892. oi->ip_last_trans = 0;
  893. oi->ip_dir_start_lookup = 0;
  894. oi->ip_blkno = 0ULL;
  895. bail:
  896. mlog_exit_void();
  897. }
  898. /* Called under inode_lock, with no more references on the
  899. * struct inode, so it's safe here to check the flags field
  900. * and to manipulate i_nlink without any other locks. */
  901. void ocfs2_drop_inode(struct inode *inode)
  902. {
  903. struct ocfs2_inode_info *oi = OCFS2_I(inode);
  904. mlog_entry_void();
  905. mlog(0, "Drop inode %llu, nlink = %u, ip_flags = 0x%x\n",
  906. (unsigned long long)oi->ip_blkno, inode->i_nlink, oi->ip_flags);
  907. if (oi->ip_flags & OCFS2_INODE_MAYBE_ORPHANED)
  908. generic_delete_inode(inode);
  909. else
  910. generic_drop_inode(inode);
  911. mlog_exit_void();
  912. }
  913. /*
  914. * TODO: this should probably be merged into ocfs2_get_block
  915. *
  916. * However, you now need to pay attention to the cont_prepare_write()
  917. * stuff in ocfs2_get_block (that is, ocfs2_get_block pretty much
  918. * expects never to extend).
  919. */
  920. struct buffer_head *ocfs2_bread(struct inode *inode,
  921. int block, int *err, int reada)
  922. {
  923. struct buffer_head *bh = NULL;
  924. int tmperr;
  925. u64 p_blkno;
  926. int readflags = OCFS2_BH_CACHED;
  927. if (reada)
  928. readflags |= OCFS2_BH_READAHEAD;
  929. if (((u64)block << inode->i_sb->s_blocksize_bits) >=
  930. i_size_read(inode)) {
  931. BUG_ON(!reada);
  932. return NULL;
  933. }
  934. tmperr = ocfs2_extent_map_get_blocks(inode, block, &p_blkno, NULL);
  935. if (tmperr < 0) {
  936. mlog_errno(tmperr);
  937. goto fail;
  938. }
  939. tmperr = ocfs2_read_block(OCFS2_SB(inode->i_sb), p_blkno, &bh,
  940. readflags, inode);
  941. if (tmperr < 0)
  942. goto fail;
  943. tmperr = 0;
  944. *err = 0;
  945. return bh;
  946. fail:
  947. if (bh) {
  948. brelse(bh);
  949. bh = NULL;
  950. }
  951. *err = -EIO;
  952. return NULL;
  953. }
  954. /*
  955. * This is called from our getattr.
  956. */
  957. int ocfs2_inode_revalidate(struct dentry *dentry)
  958. {
  959. struct inode *inode = dentry->d_inode;
  960. int status = 0;
  961. mlog_entry("(inode = 0x%p, ino = %llu)\n", inode,
  962. inode ? (unsigned long long)OCFS2_I(inode)->ip_blkno : 0ULL);
  963. if (!inode) {
  964. mlog(0, "eep, no inode!\n");
  965. status = -ENOENT;
  966. goto bail;
  967. }
  968. spin_lock(&OCFS2_I(inode)->ip_lock);
  969. if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED) {
  970. spin_unlock(&OCFS2_I(inode)->ip_lock);
  971. mlog(0, "inode deleted!\n");
  972. status = -ENOENT;
  973. goto bail;
  974. }
  975. spin_unlock(&OCFS2_I(inode)->ip_lock);
  976. /* Let ocfs2_meta_lock do the work of updating our struct
  977. * inode for us. */
  978. status = ocfs2_meta_lock(inode, NULL, 0);
  979. if (status < 0) {
  980. if (status != -ENOENT)
  981. mlog_errno(status);
  982. goto bail;
  983. }
  984. ocfs2_meta_unlock(inode, 0);
  985. bail:
  986. mlog_exit(status);
  987. return status;
  988. }
  989. /*
  990. * Updates a disk inode from a
  991. * struct inode.
  992. * Only takes ip_lock.
  993. */
  994. int ocfs2_mark_inode_dirty(handle_t *handle,
  995. struct inode *inode,
  996. struct buffer_head *bh)
  997. {
  998. int status;
  999. struct ocfs2_dinode *fe = (struct ocfs2_dinode *) bh->b_data;
  1000. mlog_entry("(inode %llu)\n",
  1001. (unsigned long long)OCFS2_I(inode)->ip_blkno);
  1002. status = ocfs2_journal_access(handle, inode, bh,
  1003. OCFS2_JOURNAL_ACCESS_WRITE);
  1004. if (status < 0) {
  1005. mlog_errno(status);
  1006. goto leave;
  1007. }
  1008. spin_lock(&OCFS2_I(inode)->ip_lock);
  1009. fe->i_clusters = cpu_to_le32(OCFS2_I(inode)->ip_clusters);
  1010. fe->i_attr = cpu_to_le32(OCFS2_I(inode)->ip_attr);
  1011. spin_unlock(&OCFS2_I(inode)->ip_lock);
  1012. fe->i_size = cpu_to_le64(i_size_read(inode));
  1013. fe->i_links_count = cpu_to_le16(inode->i_nlink);
  1014. fe->i_uid = cpu_to_le32(inode->i_uid);
  1015. fe->i_gid = cpu_to_le32(inode->i_gid);
  1016. fe->i_mode = cpu_to_le16(inode->i_mode);
  1017. fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
  1018. fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
  1019. fe->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);
  1020. fe->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
  1021. fe->i_mtime = cpu_to_le64(inode->i_mtime.tv_sec);
  1022. fe->i_mtime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
  1023. status = ocfs2_journal_dirty(handle, bh);
  1024. if (status < 0)
  1025. mlog_errno(status);
  1026. status = 0;
  1027. leave:
  1028. mlog_exit(status);
  1029. return status;
  1030. }
  1031. /*
  1032. *
  1033. * Updates a struct inode from a disk inode.
  1034. * does no i/o, only takes ip_lock.
  1035. */
  1036. void ocfs2_refresh_inode(struct inode *inode,
  1037. struct ocfs2_dinode *fe)
  1038. {
  1039. spin_lock(&OCFS2_I(inode)->ip_lock);
  1040. OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
  1041. OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
  1042. ocfs2_set_inode_flags(inode);
  1043. i_size_write(inode, le64_to_cpu(fe->i_size));
  1044. inode->i_nlink = le16_to_cpu(fe->i_links_count);
  1045. inode->i_uid = le32_to_cpu(fe->i_uid);
  1046. inode->i_gid = le32_to_cpu(fe->i_gid);
  1047. inode->i_mode = le16_to_cpu(fe->i_mode);
  1048. if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
  1049. inode->i_blocks = 0;
  1050. else
  1051. inode->i_blocks = ocfs2_align_bytes_to_sectors(i_size_read(inode));
  1052. inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime);
  1053. inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec);
  1054. inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime);
  1055. inode->i_mtime.tv_nsec = le32_to_cpu(fe->i_mtime_nsec);
  1056. inode->i_ctime.tv_sec = le64_to_cpu(fe->i_ctime);
  1057. inode->i_ctime.tv_nsec = le32_to_cpu(fe->i_ctime_nsec);
  1058. spin_unlock(&OCFS2_I(inode)->ip_lock);
  1059. }