inode.c 31 KB

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