inode.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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 (reada)
  893. readflags |= OCFS2_BH_READAHEAD;
  894. if (((u64)block << inode->i_sb->s_blocksize_bits) >=
  895. i_size_read(inode)) {
  896. BUG_ON(!reada);
  897. return NULL;
  898. }
  899. tmperr = ocfs2_extent_map_get_blocks(inode, block, 1,
  900. &p_blkno, NULL);
  901. if (tmperr < 0) {
  902. mlog_errno(tmperr);
  903. goto fail;
  904. }
  905. tmperr = ocfs2_read_block(OCFS2_SB(inode->i_sb), p_blkno, &bh,
  906. readflags, inode);
  907. if (tmperr < 0)
  908. goto fail;
  909. tmperr = 0;
  910. *err = 0;
  911. return bh;
  912. fail:
  913. if (bh) {
  914. brelse(bh);
  915. bh = NULL;
  916. }
  917. *err = -EIO;
  918. return NULL;
  919. }
  920. /*
  921. * This is called from our getattr.
  922. */
  923. int ocfs2_inode_revalidate(struct dentry *dentry)
  924. {
  925. struct inode *inode = dentry->d_inode;
  926. int status = 0;
  927. mlog_entry("(inode = 0x%p, ino = %llu)\n", inode,
  928. inode ? (unsigned long long)OCFS2_I(inode)->ip_blkno : 0ULL);
  929. if (!inode) {
  930. mlog(0, "eep, no inode!\n");
  931. status = -ENOENT;
  932. goto bail;
  933. }
  934. spin_lock(&OCFS2_I(inode)->ip_lock);
  935. if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED) {
  936. spin_unlock(&OCFS2_I(inode)->ip_lock);
  937. mlog(0, "inode deleted!\n");
  938. status = -ENOENT;
  939. goto bail;
  940. }
  941. spin_unlock(&OCFS2_I(inode)->ip_lock);
  942. /* Let ocfs2_meta_lock do the work of updating our struct
  943. * inode for us. */
  944. status = ocfs2_meta_lock(inode, NULL, NULL, 0);
  945. if (status < 0) {
  946. if (status != -ENOENT)
  947. mlog_errno(status);
  948. goto bail;
  949. }
  950. ocfs2_meta_unlock(inode, 0);
  951. bail:
  952. mlog_exit(status);
  953. return status;
  954. }
  955. /*
  956. * Updates a disk inode from a
  957. * struct inode.
  958. * Only takes ip_lock.
  959. */
  960. int ocfs2_mark_inode_dirty(struct ocfs2_journal_handle *handle,
  961. struct inode *inode,
  962. struct buffer_head *bh)
  963. {
  964. int status;
  965. struct ocfs2_dinode *fe = (struct ocfs2_dinode *) bh->b_data;
  966. mlog_entry("(inode %llu)\n",
  967. (unsigned long long)OCFS2_I(inode)->ip_blkno);
  968. status = ocfs2_journal_access(handle, inode, bh,
  969. OCFS2_JOURNAL_ACCESS_WRITE);
  970. if (status < 0) {
  971. mlog_errno(status);
  972. goto leave;
  973. }
  974. spin_lock(&OCFS2_I(inode)->ip_lock);
  975. fe->i_clusters = cpu_to_le32(OCFS2_I(inode)->ip_clusters);
  976. fe->i_attr = cpu_to_le32(OCFS2_I(inode)->ip_attr);
  977. spin_unlock(&OCFS2_I(inode)->ip_lock);
  978. fe->i_size = cpu_to_le64(i_size_read(inode));
  979. fe->i_links_count = cpu_to_le16(inode->i_nlink);
  980. fe->i_uid = cpu_to_le32(inode->i_uid);
  981. fe->i_gid = cpu_to_le32(inode->i_gid);
  982. fe->i_mode = cpu_to_le16(inode->i_mode);
  983. fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
  984. fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
  985. fe->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);
  986. fe->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
  987. fe->i_mtime = cpu_to_le64(inode->i_mtime.tv_sec);
  988. fe->i_mtime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
  989. status = ocfs2_journal_dirty(handle, bh);
  990. if (status < 0)
  991. mlog_errno(status);
  992. status = 0;
  993. leave:
  994. mlog_exit(status);
  995. return status;
  996. }
  997. /*
  998. *
  999. * Updates a struct inode from a disk inode.
  1000. * does no i/o, only takes ip_lock.
  1001. */
  1002. void ocfs2_refresh_inode(struct inode *inode,
  1003. struct ocfs2_dinode *fe)
  1004. {
  1005. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  1006. spin_lock(&OCFS2_I(inode)->ip_lock);
  1007. OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
  1008. OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
  1009. ocfs2_set_inode_flags(inode);
  1010. i_size_write(inode, le64_to_cpu(fe->i_size));
  1011. inode->i_nlink = le16_to_cpu(fe->i_links_count);
  1012. inode->i_uid = le32_to_cpu(fe->i_uid);
  1013. inode->i_gid = le32_to_cpu(fe->i_gid);
  1014. inode->i_mode = le16_to_cpu(fe->i_mode);
  1015. inode->i_blksize = (u32) osb->s_clustersize;
  1016. if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
  1017. inode->i_blocks = 0;
  1018. else
  1019. inode->i_blocks = ocfs2_align_bytes_to_sectors(i_size_read(inode));
  1020. inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime);
  1021. inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec);
  1022. inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime);
  1023. inode->i_mtime.tv_nsec = le32_to_cpu(fe->i_mtime_nsec);
  1024. inode->i_ctime.tv_sec = le64_to_cpu(fe->i_ctime);
  1025. inode->i_ctime.tv_nsec = le32_to_cpu(fe->i_ctime_nsec);
  1026. spin_unlock(&OCFS2_I(inode)->ip_lock);
  1027. }