inode.c 31 KB

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