inode.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/posix_acl.h>
  15. #include <linux/sort.h>
  16. #include <linux/gfs2_ondisk.h>
  17. #include <linux/crc32.h>
  18. #include <linux/lm_interface.h>
  19. #include <linux/security.h>
  20. #include <linux/time.h>
  21. #include "gfs2.h"
  22. #include "incore.h"
  23. #include "acl.h"
  24. #include "bmap.h"
  25. #include "dir.h"
  26. #include "eattr.h"
  27. #include "glock.h"
  28. #include "glops.h"
  29. #include "inode.h"
  30. #include "log.h"
  31. #include "meta_io.h"
  32. #include "ops_address.h"
  33. #include "ops_inode.h"
  34. #include "quota.h"
  35. #include "rgrp.h"
  36. #include "trans.h"
  37. #include "util.h"
  38. struct gfs2_inum_range_host {
  39. u64 ir_start;
  40. u64 ir_length;
  41. };
  42. static int iget_test(struct inode *inode, void *opaque)
  43. {
  44. struct gfs2_inode *ip = GFS2_I(inode);
  45. u64 *no_addr = opaque;
  46. if (ip->i_no_addr == *no_addr && test_bit(GIF_USER, &ip->i_flags))
  47. return 1;
  48. return 0;
  49. }
  50. static int iget_set(struct inode *inode, void *opaque)
  51. {
  52. struct gfs2_inode *ip = GFS2_I(inode);
  53. u64 *no_addr = opaque;
  54. inode->i_ino = (unsigned long)*no_addr;
  55. ip->i_no_addr = *no_addr;
  56. set_bit(GIF_USER, &ip->i_flags);
  57. return 0;
  58. }
  59. struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr)
  60. {
  61. unsigned long hash = (unsigned long)no_addr;
  62. return ilookup5(sb, hash, iget_test, &no_addr);
  63. }
  64. static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr)
  65. {
  66. unsigned long hash = (unsigned long)no_addr;
  67. return iget5_locked(sb, hash, iget_test, iget_set, &no_addr);
  68. }
  69. struct gfs2_skip_data {
  70. u64 no_addr;
  71. int skipped;
  72. };
  73. static int iget_skip_test(struct inode *inode, void *opaque)
  74. {
  75. struct gfs2_inode *ip = GFS2_I(inode);
  76. struct gfs2_skip_data *data = opaque;
  77. if (ip->i_no_addr == data->no_addr && test_bit(GIF_USER, &ip->i_flags)){
  78. if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)){
  79. data->skipped = 1;
  80. return 0;
  81. }
  82. return 1;
  83. }
  84. return 0;
  85. }
  86. static int iget_skip_set(struct inode *inode, void *opaque)
  87. {
  88. struct gfs2_inode *ip = GFS2_I(inode);
  89. struct gfs2_skip_data *data = opaque;
  90. if (data->skipped)
  91. return 1;
  92. inode->i_ino = (unsigned long)(data->no_addr);
  93. ip->i_no_addr = data->no_addr;
  94. set_bit(GIF_USER, &ip->i_flags);
  95. return 0;
  96. }
  97. static struct inode *gfs2_iget_skip(struct super_block *sb,
  98. u64 no_addr)
  99. {
  100. struct gfs2_skip_data data;
  101. unsigned long hash = (unsigned long)no_addr;
  102. data.no_addr = no_addr;
  103. data.skipped = 0;
  104. return iget5_locked(sb, hash, iget_skip_test, iget_skip_set, &data);
  105. }
  106. /**
  107. * GFS2 lookup code fills in vfs inode contents based on info obtained
  108. * from directory entry inside gfs2_inode_lookup(). This has caused issues
  109. * with NFS code path since its get_dentry routine doesn't have the relevant
  110. * directory entry when gfs2_inode_lookup() is invoked. Part of the code
  111. * segment inside gfs2_inode_lookup code needs to get moved around.
  112. *
  113. * Clean up I_LOCK and I_NEW as well.
  114. **/
  115. void gfs2_set_iop(struct inode *inode)
  116. {
  117. struct gfs2_sbd *sdp = GFS2_SB(inode);
  118. umode_t mode = inode->i_mode;
  119. if (S_ISREG(mode)) {
  120. inode->i_op = &gfs2_file_iops;
  121. if (sdp->sd_args.ar_localflocks)
  122. inode->i_fop = &gfs2_file_fops_nolock;
  123. else
  124. inode->i_fop = &gfs2_file_fops;
  125. } else if (S_ISDIR(mode)) {
  126. inode->i_op = &gfs2_dir_iops;
  127. if (sdp->sd_args.ar_localflocks)
  128. inode->i_fop = &gfs2_dir_fops_nolock;
  129. else
  130. inode->i_fop = &gfs2_dir_fops;
  131. } else if (S_ISLNK(mode)) {
  132. inode->i_op = &gfs2_symlink_iops;
  133. } else {
  134. inode->i_op = &gfs2_file_iops;
  135. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  136. }
  137. unlock_new_inode(inode);
  138. }
  139. /**
  140. * gfs2_inode_lookup - Lookup an inode
  141. * @sb: The super block
  142. * @no_addr: The inode number
  143. * @type: The type of the inode
  144. * @skip_freeing: set this not return an inode if it is currently being freed.
  145. *
  146. * Returns: A VFS inode, or an error
  147. */
  148. struct inode *gfs2_inode_lookup(struct super_block *sb,
  149. unsigned int type,
  150. u64 no_addr,
  151. u64 no_formal_ino, int skip_freeing)
  152. {
  153. struct inode *inode;
  154. struct gfs2_inode *ip;
  155. struct gfs2_glock *io_gl;
  156. int error;
  157. if (skip_freeing)
  158. inode = gfs2_iget_skip(sb, no_addr);
  159. else
  160. inode = gfs2_iget(sb, no_addr);
  161. ip = GFS2_I(inode);
  162. if (!inode)
  163. return ERR_PTR(-ENOBUFS);
  164. if (inode->i_state & I_NEW) {
  165. struct gfs2_sbd *sdp = GFS2_SB(inode);
  166. ip->i_no_formal_ino = no_formal_ino;
  167. error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
  168. if (unlikely(error))
  169. goto fail;
  170. ip->i_gl->gl_object = ip;
  171. error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
  172. if (unlikely(error))
  173. goto fail_put;
  174. set_bit(GIF_INVALID, &ip->i_flags);
  175. error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
  176. if (unlikely(error))
  177. goto fail_iopen;
  178. ip->i_iopen_gh.gh_gl->gl_object = ip;
  179. gfs2_glock_put(io_gl);
  180. if ((type == DT_UNKNOWN) && (no_formal_ino == 0))
  181. goto gfs2_nfsbypass;
  182. inode->i_mode = DT2IF(type);
  183. /*
  184. * We must read the inode in order to work out its type in
  185. * this case. Note that this doesn't happen often as we normally
  186. * know the type beforehand. This code path only occurs during
  187. * unlinked inode recovery (where it is safe to do this glock,
  188. * which is not true in the general case).
  189. */
  190. if (type == DT_UNKNOWN) {
  191. struct gfs2_holder gh;
  192. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  193. if (unlikely(error))
  194. goto fail_glock;
  195. /* Inode is now uptodate */
  196. gfs2_glock_dq_uninit(&gh);
  197. }
  198. gfs2_set_iop(inode);
  199. }
  200. gfs2_nfsbypass:
  201. return inode;
  202. fail_glock:
  203. gfs2_glock_dq(&ip->i_iopen_gh);
  204. fail_iopen:
  205. gfs2_glock_put(io_gl);
  206. fail_put:
  207. ip->i_gl->gl_object = NULL;
  208. gfs2_glock_put(ip->i_gl);
  209. fail:
  210. iget_failed(inode);
  211. return ERR_PTR(error);
  212. }
  213. static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
  214. {
  215. struct gfs2_dinode_host *di = &ip->i_di;
  216. const struct gfs2_dinode *str = buf;
  217. struct timespec atime;
  218. u16 height, depth;
  219. if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr)))
  220. goto corrupt;
  221. ip->i_no_formal_ino = be64_to_cpu(str->di_num.no_formal_ino);
  222. ip->i_inode.i_mode = be32_to_cpu(str->di_mode);
  223. ip->i_inode.i_rdev = 0;
  224. switch (ip->i_inode.i_mode & S_IFMT) {
  225. case S_IFBLK:
  226. case S_IFCHR:
  227. ip->i_inode.i_rdev = MKDEV(be32_to_cpu(str->di_major),
  228. be32_to_cpu(str->di_minor));
  229. break;
  230. };
  231. ip->i_inode.i_uid = be32_to_cpu(str->di_uid);
  232. ip->i_inode.i_gid = be32_to_cpu(str->di_gid);
  233. /*
  234. * We will need to review setting the nlink count here in the
  235. * light of the forthcoming ro bind mount work. This is a reminder
  236. * to do that.
  237. */
  238. ip->i_inode.i_nlink = be32_to_cpu(str->di_nlink);
  239. di->di_size = be64_to_cpu(str->di_size);
  240. i_size_write(&ip->i_inode, di->di_size);
  241. gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks));
  242. atime.tv_sec = be64_to_cpu(str->di_atime);
  243. atime.tv_nsec = be32_to_cpu(str->di_atime_nsec);
  244. if (timespec_compare(&ip->i_inode.i_atime, &atime) < 0)
  245. ip->i_inode.i_atime = atime;
  246. ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime);
  247. ip->i_inode.i_mtime.tv_nsec = be32_to_cpu(str->di_mtime_nsec);
  248. ip->i_inode.i_ctime.tv_sec = be64_to_cpu(str->di_ctime);
  249. ip->i_inode.i_ctime.tv_nsec = be32_to_cpu(str->di_ctime_nsec);
  250. ip->i_goal = be64_to_cpu(str->di_goal_meta);
  251. di->di_generation = be64_to_cpu(str->di_generation);
  252. di->di_flags = be32_to_cpu(str->di_flags);
  253. gfs2_set_inode_flags(&ip->i_inode);
  254. height = be16_to_cpu(str->di_height);
  255. if (unlikely(height > GFS2_MAX_META_HEIGHT))
  256. goto corrupt;
  257. ip->i_height = (u8)height;
  258. depth = be16_to_cpu(str->di_depth);
  259. if (unlikely(depth > GFS2_DIR_MAX_DEPTH))
  260. goto corrupt;
  261. ip->i_depth = (u8)depth;
  262. di->di_entries = be32_to_cpu(str->di_entries);
  263. di->di_eattr = be64_to_cpu(str->di_eattr);
  264. if (S_ISREG(ip->i_inode.i_mode))
  265. gfs2_set_aops(&ip->i_inode);
  266. return 0;
  267. corrupt:
  268. if (gfs2_consist_inode(ip))
  269. gfs2_dinode_print(ip);
  270. return -EIO;
  271. }
  272. /**
  273. * gfs2_inode_refresh - Refresh the incore copy of the dinode
  274. * @ip: The GFS2 inode
  275. *
  276. * Returns: errno
  277. */
  278. int gfs2_inode_refresh(struct gfs2_inode *ip)
  279. {
  280. struct buffer_head *dibh;
  281. int error;
  282. error = gfs2_meta_inode_buffer(ip, &dibh);
  283. if (error)
  284. return error;
  285. if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), dibh, GFS2_METATYPE_DI)) {
  286. brelse(dibh);
  287. return -EIO;
  288. }
  289. error = gfs2_dinode_in(ip, dibh->b_data);
  290. brelse(dibh);
  291. clear_bit(GIF_INVALID, &ip->i_flags);
  292. return error;
  293. }
  294. int gfs2_dinode_dealloc(struct gfs2_inode *ip)
  295. {
  296. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  297. struct gfs2_alloc *al;
  298. struct gfs2_rgrpd *rgd;
  299. int error;
  300. if (gfs2_get_inode_blocks(&ip->i_inode) != 1) {
  301. if (gfs2_consist_inode(ip))
  302. gfs2_dinode_print(ip);
  303. return -EIO;
  304. }
  305. al = gfs2_alloc_get(ip);
  306. if (!al)
  307. return -ENOMEM;
  308. error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
  309. if (error)
  310. goto out;
  311. error = gfs2_rindex_hold(sdp, &al->al_ri_gh);
  312. if (error)
  313. goto out_qs;
  314. rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
  315. if (!rgd) {
  316. gfs2_consist_inode(ip);
  317. error = -EIO;
  318. goto out_rindex_relse;
  319. }
  320. error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0,
  321. &al->al_rgd_gh);
  322. if (error)
  323. goto out_rindex_relse;
  324. error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1);
  325. if (error)
  326. goto out_rg_gunlock;
  327. set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
  328. set_bit(GLF_LFLUSH, &ip->i_gl->gl_flags);
  329. gfs2_free_di(rgd, ip);
  330. gfs2_trans_end(sdp);
  331. clear_bit(GLF_STICKY, &ip->i_gl->gl_flags);
  332. out_rg_gunlock:
  333. gfs2_glock_dq_uninit(&al->al_rgd_gh);
  334. out_rindex_relse:
  335. gfs2_glock_dq_uninit(&al->al_ri_gh);
  336. out_qs:
  337. gfs2_quota_unhold(ip);
  338. out:
  339. gfs2_alloc_put(ip);
  340. return error;
  341. }
  342. /**
  343. * gfs2_change_nlink - Change nlink count on inode
  344. * @ip: The GFS2 inode
  345. * @diff: The change in the nlink count required
  346. *
  347. * Returns: errno
  348. */
  349. int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
  350. {
  351. struct buffer_head *dibh;
  352. u32 nlink;
  353. int error;
  354. BUG_ON(diff != 1 && diff != -1);
  355. nlink = ip->i_inode.i_nlink + diff;
  356. /* If we are reducing the nlink count, but the new value ends up being
  357. bigger than the old one, we must have underflowed. */
  358. if (diff < 0 && nlink > ip->i_inode.i_nlink) {
  359. if (gfs2_consist_inode(ip))
  360. gfs2_dinode_print(ip);
  361. return -EIO;
  362. }
  363. error = gfs2_meta_inode_buffer(ip, &dibh);
  364. if (error)
  365. return error;
  366. if (diff > 0)
  367. inc_nlink(&ip->i_inode);
  368. else
  369. drop_nlink(&ip->i_inode);
  370. ip->i_inode.i_ctime = CURRENT_TIME;
  371. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  372. gfs2_dinode_out(ip, dibh->b_data);
  373. brelse(dibh);
  374. mark_inode_dirty(&ip->i_inode);
  375. if (ip->i_inode.i_nlink == 0)
  376. gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */
  377. return error;
  378. }
  379. struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
  380. {
  381. struct qstr qstr;
  382. struct inode *inode;
  383. gfs2_str2qstr(&qstr, name);
  384. inode = gfs2_lookupi(dip, &qstr, 1);
  385. /* gfs2_lookupi has inconsistent callers: vfs
  386. * related routines expect NULL for no entry found,
  387. * gfs2_lookup_simple callers expect ENOENT
  388. * and do not check for NULL.
  389. */
  390. if (inode == NULL)
  391. return ERR_PTR(-ENOENT);
  392. else
  393. return inode;
  394. }
  395. /**
  396. * gfs2_lookupi - Look up a filename in a directory and return its inode
  397. * @d_gh: An initialized holder for the directory glock
  398. * @name: The name of the inode to look for
  399. * @is_root: If 1, ignore the caller's permissions
  400. * @i_gh: An uninitialized holder for the new inode glock
  401. *
  402. * This can be called via the VFS filldir function when NFS is doing
  403. * a readdirplus and the inode which its intending to stat isn't
  404. * already in cache. In this case we must not take the directory glock
  405. * again, since the readdir call will have already taken that lock.
  406. *
  407. * Returns: errno
  408. */
  409. struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
  410. int is_root)
  411. {
  412. struct super_block *sb = dir->i_sb;
  413. struct gfs2_inode *dip = GFS2_I(dir);
  414. struct gfs2_holder d_gh;
  415. int error = 0;
  416. struct inode *inode = NULL;
  417. int unlock = 0;
  418. if (!name->len || name->len > GFS2_FNAMESIZE)
  419. return ERR_PTR(-ENAMETOOLONG);
  420. if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) ||
  421. (name->len == 2 && memcmp(name->name, "..", 2) == 0 &&
  422. dir == sb->s_root->d_inode)) {
  423. igrab(dir);
  424. return dir;
  425. }
  426. if (gfs2_glock_is_locked_by_me(dip->i_gl) == NULL) {
  427. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  428. if (error)
  429. return ERR_PTR(error);
  430. unlock = 1;
  431. }
  432. if (!is_root) {
  433. error = gfs2_permission(dir, MAY_EXEC);
  434. if (error)
  435. goto out;
  436. }
  437. inode = gfs2_dir_search(dir, name);
  438. if (IS_ERR(inode))
  439. error = PTR_ERR(inode);
  440. out:
  441. if (unlock)
  442. gfs2_glock_dq_uninit(&d_gh);
  443. if (error == -ENOENT)
  444. return NULL;
  445. return inode ? inode : ERR_PTR(error);
  446. }
  447. static void gfs2_inum_range_in(struct gfs2_inum_range_host *ir, const void *buf)
  448. {
  449. const struct gfs2_inum_range *str = buf;
  450. ir->ir_start = be64_to_cpu(str->ir_start);
  451. ir->ir_length = be64_to_cpu(str->ir_length);
  452. }
  453. static void gfs2_inum_range_out(const struct gfs2_inum_range_host *ir, void *buf)
  454. {
  455. struct gfs2_inum_range *str = buf;
  456. str->ir_start = cpu_to_be64(ir->ir_start);
  457. str->ir_length = cpu_to_be64(ir->ir_length);
  458. }
  459. static int pick_formal_ino_1(struct gfs2_sbd *sdp, u64 *formal_ino)
  460. {
  461. struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode);
  462. struct buffer_head *bh;
  463. struct gfs2_inum_range_host ir;
  464. int error;
  465. error = gfs2_trans_begin(sdp, RES_DINODE, 0);
  466. if (error)
  467. return error;
  468. mutex_lock(&sdp->sd_inum_mutex);
  469. error = gfs2_meta_inode_buffer(ip, &bh);
  470. if (error) {
  471. mutex_unlock(&sdp->sd_inum_mutex);
  472. gfs2_trans_end(sdp);
  473. return error;
  474. }
  475. gfs2_inum_range_in(&ir, bh->b_data + sizeof(struct gfs2_dinode));
  476. if (ir.ir_length) {
  477. *formal_ino = ir.ir_start++;
  478. ir.ir_length--;
  479. gfs2_trans_add_bh(ip->i_gl, bh, 1);
  480. gfs2_inum_range_out(&ir,
  481. bh->b_data + sizeof(struct gfs2_dinode));
  482. brelse(bh);
  483. mutex_unlock(&sdp->sd_inum_mutex);
  484. gfs2_trans_end(sdp);
  485. return 0;
  486. }
  487. brelse(bh);
  488. mutex_unlock(&sdp->sd_inum_mutex);
  489. gfs2_trans_end(sdp);
  490. return 1;
  491. }
  492. static int pick_formal_ino_2(struct gfs2_sbd *sdp, u64 *formal_ino)
  493. {
  494. struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode);
  495. struct gfs2_inode *m_ip = GFS2_I(sdp->sd_inum_inode);
  496. struct gfs2_holder gh;
  497. struct buffer_head *bh;
  498. struct gfs2_inum_range_host ir;
  499. int error;
  500. error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  501. if (error)
  502. return error;
  503. error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0);
  504. if (error)
  505. goto out;
  506. mutex_lock(&sdp->sd_inum_mutex);
  507. error = gfs2_meta_inode_buffer(ip, &bh);
  508. if (error)
  509. goto out_end_trans;
  510. gfs2_inum_range_in(&ir, bh->b_data + sizeof(struct gfs2_dinode));
  511. if (!ir.ir_length) {
  512. struct buffer_head *m_bh;
  513. u64 x, y;
  514. __be64 z;
  515. error = gfs2_meta_inode_buffer(m_ip, &m_bh);
  516. if (error)
  517. goto out_brelse;
  518. z = *(__be64 *)(m_bh->b_data + sizeof(struct gfs2_dinode));
  519. x = y = be64_to_cpu(z);
  520. ir.ir_start = x;
  521. ir.ir_length = GFS2_INUM_QUANTUM;
  522. x += GFS2_INUM_QUANTUM;
  523. if (x < y)
  524. gfs2_consist_inode(m_ip);
  525. z = cpu_to_be64(x);
  526. gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1);
  527. *(__be64 *)(m_bh->b_data + sizeof(struct gfs2_dinode)) = z;
  528. brelse(m_bh);
  529. }
  530. *formal_ino = ir.ir_start++;
  531. ir.ir_length--;
  532. gfs2_trans_add_bh(ip->i_gl, bh, 1);
  533. gfs2_inum_range_out(&ir, bh->b_data + sizeof(struct gfs2_dinode));
  534. out_brelse:
  535. brelse(bh);
  536. out_end_trans:
  537. mutex_unlock(&sdp->sd_inum_mutex);
  538. gfs2_trans_end(sdp);
  539. out:
  540. gfs2_glock_dq_uninit(&gh);
  541. return error;
  542. }
  543. static int pick_formal_ino(struct gfs2_sbd *sdp, u64 *inum)
  544. {
  545. int error;
  546. error = pick_formal_ino_1(sdp, inum);
  547. if (error <= 0)
  548. return error;
  549. error = pick_formal_ino_2(sdp, inum);
  550. return error;
  551. }
  552. /**
  553. * create_ok - OK to create a new on-disk inode here?
  554. * @dip: Directory in which dinode is to be created
  555. * @name: Name of new dinode
  556. * @mode:
  557. *
  558. * Returns: errno
  559. */
  560. static int create_ok(struct gfs2_inode *dip, const struct qstr *name,
  561. unsigned int mode)
  562. {
  563. int error;
  564. error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
  565. if (error)
  566. return error;
  567. /* Don't create entries in an unlinked directory */
  568. if (!dip->i_inode.i_nlink)
  569. return -EPERM;
  570. error = gfs2_dir_check(&dip->i_inode, name, NULL);
  571. switch (error) {
  572. case -ENOENT:
  573. error = 0;
  574. break;
  575. case 0:
  576. return -EEXIST;
  577. default:
  578. return error;
  579. }
  580. if (dip->i_di.di_entries == (u32)-1)
  581. return -EFBIG;
  582. if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1)
  583. return -EMLINK;
  584. return 0;
  585. }
  586. static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode,
  587. unsigned int *uid, unsigned int *gid)
  588. {
  589. if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir &&
  590. (dip->i_inode.i_mode & S_ISUID) && dip->i_inode.i_uid) {
  591. if (S_ISDIR(*mode))
  592. *mode |= S_ISUID;
  593. else if (dip->i_inode.i_uid != current_fsuid())
  594. *mode &= ~07111;
  595. *uid = dip->i_inode.i_uid;
  596. } else
  597. *uid = current_fsuid();
  598. if (dip->i_inode.i_mode & S_ISGID) {
  599. if (S_ISDIR(*mode))
  600. *mode |= S_ISGID;
  601. *gid = dip->i_inode.i_gid;
  602. } else
  603. *gid = current_fsgid();
  604. }
  605. static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation)
  606. {
  607. struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
  608. int error;
  609. if (gfs2_alloc_get(dip) == NULL)
  610. return -ENOMEM;
  611. dip->i_alloc->al_requested = RES_DINODE;
  612. error = gfs2_inplace_reserve(dip);
  613. if (error)
  614. goto out;
  615. error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS, 0);
  616. if (error)
  617. goto out_ipreserv;
  618. *no_addr = gfs2_alloc_di(dip, generation);
  619. gfs2_trans_end(sdp);
  620. out_ipreserv:
  621. gfs2_inplace_release(dip);
  622. out:
  623. gfs2_alloc_put(dip);
  624. return error;
  625. }
  626. /**
  627. * init_dinode - Fill in a new dinode structure
  628. * @dip: the directory this inode is being created in
  629. * @gl: The glock covering the new inode
  630. * @inum: the inode number
  631. * @mode: the file permissions
  632. * @uid:
  633. * @gid:
  634. *
  635. */
  636. static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
  637. const struct gfs2_inum_host *inum, unsigned int mode,
  638. unsigned int uid, unsigned int gid,
  639. const u64 *generation, dev_t dev, struct buffer_head **bhp)
  640. {
  641. struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
  642. struct gfs2_dinode *di;
  643. struct buffer_head *dibh;
  644. struct timespec tv = CURRENT_TIME;
  645. dibh = gfs2_meta_new(gl, inum->no_addr);
  646. gfs2_trans_add_bh(gl, dibh, 1);
  647. gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI);
  648. gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
  649. di = (struct gfs2_dinode *)dibh->b_data;
  650. di->di_num.no_formal_ino = cpu_to_be64(inum->no_formal_ino);
  651. di->di_num.no_addr = cpu_to_be64(inum->no_addr);
  652. di->di_mode = cpu_to_be32(mode);
  653. di->di_uid = cpu_to_be32(uid);
  654. di->di_gid = cpu_to_be32(gid);
  655. di->di_nlink = 0;
  656. di->di_size = 0;
  657. di->di_blocks = cpu_to_be64(1);
  658. di->di_atime = di->di_mtime = di->di_ctime = cpu_to_be64(tv.tv_sec);
  659. di->di_major = cpu_to_be32(MAJOR(dev));
  660. di->di_minor = cpu_to_be32(MINOR(dev));
  661. di->di_goal_meta = di->di_goal_data = cpu_to_be64(inum->no_addr);
  662. di->di_generation = cpu_to_be64(*generation);
  663. di->di_flags = 0;
  664. if (S_ISREG(mode)) {
  665. if ((dip->i_di.di_flags & GFS2_DIF_INHERIT_JDATA) ||
  666. gfs2_tune_get(sdp, gt_new_files_jdata))
  667. di->di_flags |= cpu_to_be32(GFS2_DIF_JDATA);
  668. } else if (S_ISDIR(mode)) {
  669. di->di_flags |= cpu_to_be32(dip->i_di.di_flags &
  670. GFS2_DIF_INHERIT_JDATA);
  671. }
  672. di->__pad1 = 0;
  673. di->di_payload_format = cpu_to_be32(S_ISDIR(mode) ? GFS2_FORMAT_DE : 0);
  674. di->di_height = 0;
  675. di->__pad2 = 0;
  676. di->__pad3 = 0;
  677. di->di_depth = 0;
  678. di->di_entries = 0;
  679. memset(&di->__pad4, 0, sizeof(di->__pad4));
  680. di->di_eattr = 0;
  681. di->di_atime_nsec = cpu_to_be32(tv.tv_nsec);
  682. di->di_mtime_nsec = cpu_to_be32(tv.tv_nsec);
  683. di->di_ctime_nsec = cpu_to_be32(tv.tv_nsec);
  684. memset(&di->di_reserved, 0, sizeof(di->di_reserved));
  685. set_buffer_uptodate(dibh);
  686. *bhp = dibh;
  687. }
  688. static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
  689. unsigned int mode, const struct gfs2_inum_host *inum,
  690. const u64 *generation, dev_t dev, struct buffer_head **bhp)
  691. {
  692. struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
  693. unsigned int uid, gid;
  694. int error;
  695. munge_mode_uid_gid(dip, &mode, &uid, &gid);
  696. if (!gfs2_alloc_get(dip))
  697. return -ENOMEM;
  698. error = gfs2_quota_lock(dip, uid, gid);
  699. if (error)
  700. goto out;
  701. error = gfs2_quota_check(dip, uid, gid);
  702. if (error)
  703. goto out_quota;
  704. error = gfs2_trans_begin(sdp, RES_DINODE + RES_QUOTA, 0);
  705. if (error)
  706. goto out_quota;
  707. init_dinode(dip, gl, inum, mode, uid, gid, generation, dev, bhp);
  708. gfs2_quota_change(dip, +1, uid, gid);
  709. gfs2_trans_end(sdp);
  710. out_quota:
  711. gfs2_quota_unlock(dip);
  712. out:
  713. gfs2_alloc_put(dip);
  714. return error;
  715. }
  716. static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
  717. struct gfs2_inode *ip)
  718. {
  719. struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
  720. struct gfs2_alloc *al;
  721. int alloc_required;
  722. struct buffer_head *dibh;
  723. int error;
  724. al = gfs2_alloc_get(dip);
  725. if (!al)
  726. return -ENOMEM;
  727. error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
  728. if (error)
  729. goto fail;
  730. error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name);
  731. if (alloc_required < 0)
  732. goto fail_quota_locks;
  733. if (alloc_required) {
  734. error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
  735. if (error)
  736. goto fail_quota_locks;
  737. al->al_requested = sdp->sd_max_dirres;
  738. error = gfs2_inplace_reserve(dip);
  739. if (error)
  740. goto fail_quota_locks;
  741. error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
  742. al->al_rgd->rd_length +
  743. 2 * RES_DINODE +
  744. RES_STATFS + RES_QUOTA, 0);
  745. if (error)
  746. goto fail_ipreserv;
  747. } else {
  748. error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0);
  749. if (error)
  750. goto fail_quota_locks;
  751. }
  752. error = gfs2_dir_add(&dip->i_inode, name, ip, IF2DT(ip->i_inode.i_mode));
  753. if (error)
  754. goto fail_end_trans;
  755. error = gfs2_meta_inode_buffer(ip, &dibh);
  756. if (error)
  757. goto fail_end_trans;
  758. ip->i_inode.i_nlink = 1;
  759. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  760. gfs2_dinode_out(ip, dibh->b_data);
  761. brelse(dibh);
  762. return 0;
  763. fail_end_trans:
  764. gfs2_trans_end(sdp);
  765. fail_ipreserv:
  766. if (dip->i_alloc->al_rgd)
  767. gfs2_inplace_release(dip);
  768. fail_quota_locks:
  769. gfs2_quota_unlock(dip);
  770. fail:
  771. gfs2_alloc_put(dip);
  772. return error;
  773. }
  774. static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip)
  775. {
  776. int err;
  777. size_t len;
  778. void *value;
  779. char *name;
  780. struct gfs2_ea_request er;
  781. err = security_inode_init_security(&ip->i_inode, &dip->i_inode,
  782. &name, &value, &len);
  783. if (err) {
  784. if (err == -EOPNOTSUPP)
  785. return 0;
  786. return err;
  787. }
  788. memset(&er, 0, sizeof(struct gfs2_ea_request));
  789. er.er_type = GFS2_EATYPE_SECURITY;
  790. er.er_name = name;
  791. er.er_data = value;
  792. er.er_name_len = strlen(name);
  793. er.er_data_len = len;
  794. err = gfs2_ea_set_i(ip, &er);
  795. kfree(value);
  796. kfree(name);
  797. return err;
  798. }
  799. /**
  800. * gfs2_createi - Create a new inode
  801. * @ghs: An array of two holders
  802. * @name: The name of the new file
  803. * @mode: the permissions on the new inode
  804. *
  805. * @ghs[0] is an initialized holder for the directory
  806. * @ghs[1] is the holder for the inode lock
  807. *
  808. * If the return value is not NULL, the glocks on both the directory and the new
  809. * file are held. A transaction has been started and an inplace reservation
  810. * is held, as well.
  811. *
  812. * Returns: An inode
  813. */
  814. struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
  815. unsigned int mode, dev_t dev)
  816. {
  817. struct inode *inode = NULL;
  818. struct gfs2_inode *dip = ghs->gh_gl->gl_object;
  819. struct inode *dir = &dip->i_inode;
  820. struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
  821. struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 };
  822. int error;
  823. u64 generation;
  824. struct buffer_head *bh = NULL;
  825. if (!name->len || name->len > GFS2_FNAMESIZE)
  826. return ERR_PTR(-ENAMETOOLONG);
  827. gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs);
  828. error = gfs2_glock_nq(ghs);
  829. if (error)
  830. goto fail;
  831. error = create_ok(dip, name, mode);
  832. if (error)
  833. goto fail_gunlock;
  834. error = pick_formal_ino(sdp, &inum.no_formal_ino);
  835. if (error)
  836. goto fail_gunlock;
  837. error = alloc_dinode(dip, &inum.no_addr, &generation);
  838. if (error)
  839. goto fail_gunlock;
  840. error = gfs2_glock_nq_num(sdp, inum.no_addr, &gfs2_inode_glops,
  841. LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1);
  842. if (error)
  843. goto fail_gunlock;
  844. error = make_dinode(dip, ghs[1].gh_gl, mode, &inum, &generation, dev, &bh);
  845. if (error)
  846. goto fail_gunlock2;
  847. inode = gfs2_inode_lookup(dir->i_sb, IF2DT(mode),
  848. inum.no_addr,
  849. inum.no_formal_ino, 0);
  850. if (IS_ERR(inode))
  851. goto fail_gunlock2;
  852. error = gfs2_inode_refresh(GFS2_I(inode));
  853. if (error)
  854. goto fail_gunlock2;
  855. error = gfs2_acl_create(dip, GFS2_I(inode));
  856. if (error)
  857. goto fail_gunlock2;
  858. error = gfs2_security_init(dip, GFS2_I(inode));
  859. if (error)
  860. goto fail_gunlock2;
  861. error = link_dinode(dip, name, GFS2_I(inode));
  862. if (error)
  863. goto fail_gunlock2;
  864. if (bh)
  865. brelse(bh);
  866. return inode;
  867. fail_gunlock2:
  868. gfs2_glock_dq_uninit(ghs + 1);
  869. if (inode && !IS_ERR(inode))
  870. iput(inode);
  871. fail_gunlock:
  872. gfs2_glock_dq(ghs);
  873. fail:
  874. if (bh)
  875. brelse(bh);
  876. return ERR_PTR(error);
  877. }
  878. /**
  879. * gfs2_rmdiri - Remove a directory
  880. * @dip: The parent directory of the directory to be removed
  881. * @name: The name of the directory to be removed
  882. * @ip: The GFS2 inode of the directory to be removed
  883. *
  884. * Assumes Glocks on dip and ip are held
  885. *
  886. * Returns: errno
  887. */
  888. int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name,
  889. struct gfs2_inode *ip)
  890. {
  891. struct qstr dotname;
  892. int error;
  893. if (ip->i_di.di_entries != 2) {
  894. if (gfs2_consist_inode(ip))
  895. gfs2_dinode_print(ip);
  896. return -EIO;
  897. }
  898. error = gfs2_dir_del(dip, name);
  899. if (error)
  900. return error;
  901. error = gfs2_change_nlink(dip, -1);
  902. if (error)
  903. return error;
  904. gfs2_str2qstr(&dotname, ".");
  905. error = gfs2_dir_del(ip, &dotname);
  906. if (error)
  907. return error;
  908. gfs2_str2qstr(&dotname, "..");
  909. error = gfs2_dir_del(ip, &dotname);
  910. if (error)
  911. return error;
  912. /* It looks odd, but it really should be done twice */
  913. error = gfs2_change_nlink(ip, -1);
  914. if (error)
  915. return error;
  916. error = gfs2_change_nlink(ip, -1);
  917. if (error)
  918. return error;
  919. return error;
  920. }
  921. /*
  922. * gfs2_unlink_ok - check to see that a inode is still in a directory
  923. * @dip: the directory
  924. * @name: the name of the file
  925. * @ip: the inode
  926. *
  927. * Assumes that the lock on (at least) @dip is held.
  928. *
  929. * Returns: 0 if the parent/child relationship is correct, errno if it isn't
  930. */
  931. int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
  932. const struct gfs2_inode *ip)
  933. {
  934. int error;
  935. if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
  936. return -EPERM;
  937. if ((dip->i_inode.i_mode & S_ISVTX) &&
  938. dip->i_inode.i_uid != current_fsuid() &&
  939. ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER))
  940. return -EPERM;
  941. if (IS_APPEND(&dip->i_inode))
  942. return -EPERM;
  943. error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
  944. if (error)
  945. return error;
  946. error = gfs2_dir_check(&dip->i_inode, name, ip);
  947. if (error)
  948. return error;
  949. return 0;
  950. }
  951. /**
  952. * gfs2_readlinki - return the contents of a symlink
  953. * @ip: the symlink's inode
  954. * @buf: a pointer to the buffer to be filled
  955. * @len: a pointer to the length of @buf
  956. *
  957. * If @buf is too small, a piece of memory is kmalloc()ed and needs
  958. * to be freed by the caller.
  959. *
  960. * Returns: errno
  961. */
  962. int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len)
  963. {
  964. struct gfs2_holder i_gh;
  965. struct buffer_head *dibh;
  966. unsigned int x;
  967. int error;
  968. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
  969. error = gfs2_glock_nq(&i_gh);
  970. if (error) {
  971. gfs2_holder_uninit(&i_gh);
  972. return error;
  973. }
  974. if (!ip->i_di.di_size) {
  975. gfs2_consist_inode(ip);
  976. error = -EIO;
  977. goto out;
  978. }
  979. error = gfs2_meta_inode_buffer(ip, &dibh);
  980. if (error)
  981. goto out;
  982. x = ip->i_di.di_size + 1;
  983. if (x > *len) {
  984. *buf = kmalloc(x, GFP_NOFS);
  985. if (!*buf) {
  986. error = -ENOMEM;
  987. goto out_brelse;
  988. }
  989. }
  990. memcpy(*buf, dibh->b_data + sizeof(struct gfs2_dinode), x);
  991. *len = x;
  992. out_brelse:
  993. brelse(dibh);
  994. out:
  995. gfs2_glock_dq_uninit(&i_gh);
  996. return error;
  997. }
  998. static int
  999. __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
  1000. {
  1001. struct buffer_head *dibh;
  1002. int error;
  1003. error = gfs2_meta_inode_buffer(ip, &dibh);
  1004. if (!error) {
  1005. error = inode_setattr(&ip->i_inode, attr);
  1006. gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error);
  1007. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  1008. gfs2_dinode_out(ip, dibh->b_data);
  1009. brelse(dibh);
  1010. }
  1011. return error;
  1012. }
  1013. /**
  1014. * gfs2_setattr_simple -
  1015. * @ip:
  1016. * @attr:
  1017. *
  1018. * Called with a reference on the vnode.
  1019. *
  1020. * Returns: errno
  1021. */
  1022. int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
  1023. {
  1024. int error;
  1025. if (current->journal_info)
  1026. return __gfs2_setattr_simple(ip, attr);
  1027. error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0);
  1028. if (error)
  1029. return error;
  1030. error = __gfs2_setattr_simple(ip, attr);
  1031. gfs2_trans_end(GFS2_SB(&ip->i_inode));
  1032. return error;
  1033. }
  1034. void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf)
  1035. {
  1036. const struct gfs2_dinode_host *di = &ip->i_di;
  1037. struct gfs2_dinode *str = buf;
  1038. str->di_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
  1039. str->di_header.mh_type = cpu_to_be32(GFS2_METATYPE_DI);
  1040. str->di_header.__pad0 = 0;
  1041. str->di_header.mh_format = cpu_to_be32(GFS2_FORMAT_DI);
  1042. str->di_header.__pad1 = 0;
  1043. str->di_num.no_addr = cpu_to_be64(ip->i_no_addr);
  1044. str->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino);
  1045. str->di_mode = cpu_to_be32(ip->i_inode.i_mode);
  1046. str->di_uid = cpu_to_be32(ip->i_inode.i_uid);
  1047. str->di_gid = cpu_to_be32(ip->i_inode.i_gid);
  1048. str->di_nlink = cpu_to_be32(ip->i_inode.i_nlink);
  1049. str->di_size = cpu_to_be64(di->di_size);
  1050. str->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode));
  1051. str->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec);
  1052. str->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec);
  1053. str->di_ctime = cpu_to_be64(ip->i_inode.i_ctime.tv_sec);
  1054. str->di_goal_meta = cpu_to_be64(ip->i_goal);
  1055. str->di_goal_data = cpu_to_be64(ip->i_goal);
  1056. str->di_generation = cpu_to_be64(di->di_generation);
  1057. str->di_flags = cpu_to_be32(di->di_flags);
  1058. str->di_height = cpu_to_be16(ip->i_height);
  1059. str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) &&
  1060. !(ip->i_di.di_flags & GFS2_DIF_EXHASH) ?
  1061. GFS2_FORMAT_DE : 0);
  1062. str->di_depth = cpu_to_be16(ip->i_depth);
  1063. str->di_entries = cpu_to_be32(di->di_entries);
  1064. str->di_eattr = cpu_to_be64(di->di_eattr);
  1065. str->di_atime_nsec = cpu_to_be32(ip->i_inode.i_atime.tv_nsec);
  1066. str->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec);
  1067. str->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec);
  1068. }
  1069. void gfs2_dinode_print(const struct gfs2_inode *ip)
  1070. {
  1071. const struct gfs2_dinode_host *di = &ip->i_di;
  1072. printk(KERN_INFO " no_formal_ino = %llu\n",
  1073. (unsigned long long)ip->i_no_formal_ino);
  1074. printk(KERN_INFO " no_addr = %llu\n",
  1075. (unsigned long long)ip->i_no_addr);
  1076. printk(KERN_INFO " di_size = %llu\n", (unsigned long long)di->di_size);
  1077. printk(KERN_INFO " blocks = %llu\n",
  1078. (unsigned long long)gfs2_get_inode_blocks(&ip->i_inode));
  1079. printk(KERN_INFO " i_goal = %llu\n",
  1080. (unsigned long long)ip->i_goal);
  1081. printk(KERN_INFO " di_flags = 0x%.8X\n", di->di_flags);
  1082. printk(KERN_INFO " i_height = %u\n", ip->i_height);
  1083. printk(KERN_INFO " i_depth = %u\n", ip->i_depth);
  1084. printk(KERN_INFO " di_entries = %u\n", di->di_entries);
  1085. printk(KERN_INFO " di_eattr = %llu\n",
  1086. (unsigned long long)di->di_eattr);
  1087. }