inode.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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_blocks = di->di_blocks <<
  69. (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT);
  70. if (di->di_flags & GFS2_DIF_IMMUTABLE)
  71. inode->i_flags |= S_IMMUTABLE;
  72. else
  73. inode->i_flags &= ~S_IMMUTABLE;
  74. if (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->i_private = 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. u32 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. clear_nlink(&ip->i_inode);
  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. struct gfs2_dinode *di;
  972. error = gfs2_trans_begin(sdp, RES_DINODE, 0);
  973. if (error == -EROFS)
  974. return 0;
  975. if (error)
  976. goto fail;
  977. error = gfs2_meta_inode_buffer(ip, &dibh);
  978. if (error)
  979. goto fail_end_trans;
  980. ip->i_di.di_atime = curtime;
  981. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  982. di = (struct gfs2_dinode *)dibh->b_data;
  983. di->di_atime = cpu_to_be64(ip->i_di.di_atime);
  984. brelse(dibh);
  985. gfs2_trans_end(sdp);
  986. }
  987. /* If someone else has asked for the glock,
  988. unlock and let them have it. Then reacquire
  989. in the original state. */
  990. if (gfs2_glock_is_blocking(gl)) {
  991. gfs2_glock_dq(gh);
  992. gfs2_holder_reinit(state, flags, gh);
  993. return gfs2_glock_nq(gh);
  994. }
  995. }
  996. return 0;
  997. fail_end_trans:
  998. gfs2_trans_end(sdp);
  999. fail:
  1000. gfs2_glock_dq(gh);
  1001. return error;
  1002. }
  1003. /**
  1004. * glock_compare_atime - Compare two struct gfs2_glock structures for sort
  1005. * @arg_a: the first structure
  1006. * @arg_b: the second structure
  1007. *
  1008. * Returns: 1 if A > B
  1009. * -1 if A < B
  1010. * 0 if A == B
  1011. */
  1012. static int glock_compare_atime(const void *arg_a, const void *arg_b)
  1013. {
  1014. const struct gfs2_holder *gh_a = *(const struct gfs2_holder **)arg_a;
  1015. const struct gfs2_holder *gh_b = *(const struct gfs2_holder **)arg_b;
  1016. const struct lm_lockname *a = &gh_a->gh_gl->gl_name;
  1017. const struct lm_lockname *b = &gh_b->gh_gl->gl_name;
  1018. if (a->ln_number > b->ln_number)
  1019. return 1;
  1020. if (a->ln_number < b->ln_number)
  1021. return -1;
  1022. if (gh_a->gh_state == LM_ST_SHARED && gh_b->gh_state == LM_ST_EXCLUSIVE)
  1023. return 1;
  1024. if (gh_a->gh_state == LM_ST_SHARED && (gh_b->gh_flags & GL_ATIME))
  1025. return 1;
  1026. return 0;
  1027. }
  1028. /**
  1029. * gfs2_glock_nq_m_atime - acquire multiple glocks where one may need an
  1030. * atime update
  1031. * @num_gh: the number of structures
  1032. * @ghs: an array of struct gfs2_holder structures
  1033. *
  1034. * Returns: 0 on success (all glocks acquired),
  1035. * errno on failure (no glocks acquired)
  1036. */
  1037. int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs)
  1038. {
  1039. struct gfs2_holder **p;
  1040. unsigned int x;
  1041. int error = 0;
  1042. if (!num_gh)
  1043. return 0;
  1044. if (num_gh == 1) {
  1045. ghs->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC);
  1046. if (ghs->gh_flags & GL_ATIME)
  1047. error = gfs2_glock_nq_atime(ghs);
  1048. else
  1049. error = gfs2_glock_nq(ghs);
  1050. return error;
  1051. }
  1052. p = kcalloc(num_gh, sizeof(struct gfs2_holder *), GFP_KERNEL);
  1053. if (!p)
  1054. return -ENOMEM;
  1055. for (x = 0; x < num_gh; x++)
  1056. p[x] = &ghs[x];
  1057. sort(p, num_gh, sizeof(struct gfs2_holder *), glock_compare_atime,NULL);
  1058. for (x = 0; x < num_gh; x++) {
  1059. p[x]->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC);
  1060. if (p[x]->gh_flags & GL_ATIME)
  1061. error = gfs2_glock_nq_atime(p[x]);
  1062. else
  1063. error = gfs2_glock_nq(p[x]);
  1064. if (error) {
  1065. while (x--)
  1066. gfs2_glock_dq(p[x]);
  1067. break;
  1068. }
  1069. }
  1070. kfree(p);
  1071. return error;
  1072. }
  1073. static int
  1074. __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
  1075. {
  1076. struct buffer_head *dibh;
  1077. int error;
  1078. error = gfs2_meta_inode_buffer(ip, &dibh);
  1079. if (!error) {
  1080. error = inode_setattr(&ip->i_inode, attr);
  1081. gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error);
  1082. gfs2_inode_attr_out(ip);
  1083. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  1084. gfs2_dinode_out(&ip->i_di, dibh->b_data);
  1085. brelse(dibh);
  1086. }
  1087. return error;
  1088. }
  1089. /**
  1090. * gfs2_setattr_simple -
  1091. * @ip:
  1092. * @attr:
  1093. *
  1094. * Called with a reference on the vnode.
  1095. *
  1096. * Returns: errno
  1097. */
  1098. int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
  1099. {
  1100. int error;
  1101. if (current->journal_info)
  1102. return __gfs2_setattr_simple(ip, attr);
  1103. error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0);
  1104. if (error)
  1105. return error;
  1106. error = __gfs2_setattr_simple(ip, attr);
  1107. gfs2_trans_end(GFS2_SB(&ip->i_inode));
  1108. return error;
  1109. }