inode.c 30 KB

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