inode.c 31 KB

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