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