inode.c 33 KB

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