inode.c 34 KB

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