inode.c 29 KB

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