ops_inode.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  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/slab.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/namei.h>
  14. #include <linux/mm.h>
  15. #include <linux/xattr.h>
  16. #include <linux/posix_acl.h>
  17. #include <linux/gfs2_ondisk.h>
  18. #include <linux/crc32.h>
  19. #include <linux/fiemap.h>
  20. #include <asm/uaccess.h>
  21. #include "gfs2.h"
  22. #include "incore.h"
  23. #include "acl.h"
  24. #include "bmap.h"
  25. #include "dir.h"
  26. #include "xattr.h"
  27. #include "glock.h"
  28. #include "inode.h"
  29. #include "meta_io.h"
  30. #include "quota.h"
  31. #include "rgrp.h"
  32. #include "trans.h"
  33. #include "util.h"
  34. #include "super.h"
  35. /**
  36. * gfs2_create - Create a file
  37. * @dir: The directory in which to create the file
  38. * @dentry: The dentry of the new file
  39. * @mode: The mode of the new file
  40. *
  41. * Returns: errno
  42. */
  43. static int gfs2_create(struct inode *dir, struct dentry *dentry,
  44. int mode, struct nameidata *nd)
  45. {
  46. struct gfs2_inode *dip = GFS2_I(dir);
  47. struct gfs2_sbd *sdp = GFS2_SB(dir);
  48. struct gfs2_holder ghs[2];
  49. struct inode *inode;
  50. gfs2_holder_init(dip->i_gl, 0, 0, ghs);
  51. for (;;) {
  52. inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0);
  53. if (!IS_ERR(inode)) {
  54. gfs2_trans_end(sdp);
  55. if (dip->i_alloc->al_rgd)
  56. gfs2_inplace_release(dip);
  57. gfs2_quota_unlock(dip);
  58. gfs2_alloc_put(dip);
  59. gfs2_glock_dq_uninit_m(2, ghs);
  60. mark_inode_dirty(inode);
  61. break;
  62. } else if (PTR_ERR(inode) != -EEXIST ||
  63. (nd && nd->flags & LOOKUP_EXCL)) {
  64. gfs2_holder_uninit(ghs);
  65. return PTR_ERR(inode);
  66. }
  67. inode = gfs2_lookupi(dir, &dentry->d_name, 0);
  68. if (inode) {
  69. if (!IS_ERR(inode)) {
  70. gfs2_holder_uninit(ghs);
  71. break;
  72. } else {
  73. gfs2_holder_uninit(ghs);
  74. return PTR_ERR(inode);
  75. }
  76. }
  77. }
  78. d_instantiate(dentry, inode);
  79. return 0;
  80. }
  81. /**
  82. * gfs2_lookup - Look up a filename in a directory and return its inode
  83. * @dir: The directory inode
  84. * @dentry: The dentry of the new inode
  85. * @nd: passed from Linux VFS, ignored by us
  86. *
  87. * Called by the VFS layer. Lock dir and call gfs2_lookupi()
  88. *
  89. * Returns: errno
  90. */
  91. static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
  92. struct nameidata *nd)
  93. {
  94. struct inode *inode = NULL;
  95. inode = gfs2_lookupi(dir, &dentry->d_name, 0);
  96. if (inode && IS_ERR(inode))
  97. return ERR_CAST(inode);
  98. if (inode) {
  99. struct gfs2_glock *gl = GFS2_I(inode)->i_gl;
  100. struct gfs2_holder gh;
  101. int error;
  102. error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
  103. if (error) {
  104. iput(inode);
  105. return ERR_PTR(error);
  106. }
  107. gfs2_glock_dq_uninit(&gh);
  108. return d_splice_alias(inode, dentry);
  109. }
  110. d_add(dentry, inode);
  111. return NULL;
  112. }
  113. /**
  114. * gfs2_link - Link to a file
  115. * @old_dentry: The inode to link
  116. * @dir: Add link to this directory
  117. * @dentry: The name of the link
  118. *
  119. * Link the inode in "old_dentry" into the directory "dir" with the
  120. * name in "dentry".
  121. *
  122. * Returns: errno
  123. */
  124. static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
  125. struct dentry *dentry)
  126. {
  127. struct gfs2_inode *dip = GFS2_I(dir);
  128. struct gfs2_sbd *sdp = GFS2_SB(dir);
  129. struct inode *inode = old_dentry->d_inode;
  130. struct gfs2_inode *ip = GFS2_I(inode);
  131. struct gfs2_holder ghs[2];
  132. int alloc_required;
  133. int error;
  134. if (S_ISDIR(inode->i_mode))
  135. return -EPERM;
  136. gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  137. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
  138. error = gfs2_glock_nq(ghs); /* parent */
  139. if (error)
  140. goto out_parent;
  141. error = gfs2_glock_nq(ghs + 1); /* child */
  142. if (error)
  143. goto out_child;
  144. error = -ENOENT;
  145. if (inode->i_nlink == 0)
  146. goto out_gunlock;
  147. error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC, 0);
  148. if (error)
  149. goto out_gunlock;
  150. error = gfs2_dir_check(dir, &dentry->d_name, NULL);
  151. switch (error) {
  152. case -ENOENT:
  153. break;
  154. case 0:
  155. error = -EEXIST;
  156. default:
  157. goto out_gunlock;
  158. }
  159. error = -EINVAL;
  160. if (!dip->i_inode.i_nlink)
  161. goto out_gunlock;
  162. error = -EFBIG;
  163. if (dip->i_entries == (u32)-1)
  164. goto out_gunlock;
  165. error = -EPERM;
  166. if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  167. goto out_gunlock;
  168. error = -EINVAL;
  169. if (!ip->i_inode.i_nlink)
  170. goto out_gunlock;
  171. error = -EMLINK;
  172. if (ip->i_inode.i_nlink == (u32)-1)
  173. goto out_gunlock;
  174. alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
  175. if (error < 0)
  176. goto out_gunlock;
  177. error = 0;
  178. if (alloc_required) {
  179. struct gfs2_alloc *al = gfs2_alloc_get(dip);
  180. if (!al) {
  181. error = -ENOMEM;
  182. goto out_gunlock;
  183. }
  184. error = gfs2_quota_lock_check(dip);
  185. if (error)
  186. goto out_alloc;
  187. al->al_requested = sdp->sd_max_dirres;
  188. error = gfs2_inplace_reserve(dip);
  189. if (error)
  190. goto out_gunlock_q;
  191. error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
  192. gfs2_rg_blocks(al) +
  193. 2 * RES_DINODE + RES_STATFS +
  194. RES_QUOTA, 0);
  195. if (error)
  196. goto out_ipres;
  197. } else {
  198. error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
  199. if (error)
  200. goto out_ipres;
  201. }
  202. error = gfs2_dir_add(dir, &dentry->d_name, ip, IF2DT(inode->i_mode));
  203. if (error)
  204. goto out_end_trans;
  205. error = gfs2_change_nlink(ip, +1);
  206. out_end_trans:
  207. gfs2_trans_end(sdp);
  208. out_ipres:
  209. if (alloc_required)
  210. gfs2_inplace_release(dip);
  211. out_gunlock_q:
  212. if (alloc_required)
  213. gfs2_quota_unlock(dip);
  214. out_alloc:
  215. if (alloc_required)
  216. gfs2_alloc_put(dip);
  217. out_gunlock:
  218. gfs2_glock_dq(ghs + 1);
  219. out_child:
  220. gfs2_glock_dq(ghs);
  221. out_parent:
  222. gfs2_holder_uninit(ghs);
  223. gfs2_holder_uninit(ghs + 1);
  224. if (!error) {
  225. ihold(inode);
  226. d_instantiate(dentry, inode);
  227. mark_inode_dirty(inode);
  228. }
  229. return error;
  230. }
  231. /*
  232. * gfs2_unlink_ok - check to see that a inode is still in a directory
  233. * @dip: the directory
  234. * @name: the name of the file
  235. * @ip: the inode
  236. *
  237. * Assumes that the lock on (at least) @dip is held.
  238. *
  239. * Returns: 0 if the parent/child relationship is correct, errno if it isn't
  240. */
  241. static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
  242. const struct gfs2_inode *ip)
  243. {
  244. int error;
  245. if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
  246. return -EPERM;
  247. if ((dip->i_inode.i_mode & S_ISVTX) &&
  248. dip->i_inode.i_uid != current_fsuid() &&
  249. ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER))
  250. return -EPERM;
  251. if (IS_APPEND(&dip->i_inode))
  252. return -EPERM;
  253. error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC, 0);
  254. if (error)
  255. return error;
  256. error = gfs2_dir_check(&dip->i_inode, name, ip);
  257. if (error)
  258. return error;
  259. return 0;
  260. }
  261. /**
  262. * gfs2_unlink - Unlink a file
  263. * @dir: The inode of the directory containing the file to unlink
  264. * @dentry: The file itself
  265. *
  266. * Unlink a file. Call gfs2_unlinki()
  267. *
  268. * Returns: errno
  269. */
  270. static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
  271. {
  272. struct gfs2_inode *dip = GFS2_I(dir);
  273. struct gfs2_sbd *sdp = GFS2_SB(dir);
  274. struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
  275. struct gfs2_holder ghs[3];
  276. struct gfs2_rgrpd *rgd;
  277. struct gfs2_holder ri_gh;
  278. int error;
  279. error = gfs2_rindex_hold(sdp, &ri_gh);
  280. if (error)
  281. return error;
  282. gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  283. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
  284. rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
  285. gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
  286. error = gfs2_glock_nq(ghs); /* parent */
  287. if (error)
  288. goto out_parent;
  289. error = gfs2_glock_nq(ghs + 1); /* child */
  290. if (error)
  291. goto out_child;
  292. error = -ENOENT;
  293. if (ip->i_inode.i_nlink == 0)
  294. goto out_rgrp;
  295. error = gfs2_glock_nq(ghs + 2); /* rgrp */
  296. if (error)
  297. goto out_rgrp;
  298. error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
  299. if (error)
  300. goto out_gunlock;
  301. error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
  302. if (error)
  303. goto out_gunlock;
  304. error = gfs2_dir_del(dip, &dentry->d_name);
  305. if (error)
  306. goto out_end_trans;
  307. error = gfs2_change_nlink(ip, -1);
  308. out_end_trans:
  309. gfs2_trans_end(sdp);
  310. out_gunlock:
  311. gfs2_glock_dq(ghs + 2);
  312. out_rgrp:
  313. gfs2_holder_uninit(ghs + 2);
  314. gfs2_glock_dq(ghs + 1);
  315. out_child:
  316. gfs2_holder_uninit(ghs + 1);
  317. gfs2_glock_dq(ghs);
  318. out_parent:
  319. gfs2_holder_uninit(ghs);
  320. gfs2_glock_dq_uninit(&ri_gh);
  321. return error;
  322. }
  323. /**
  324. * gfs2_symlink - Create a symlink
  325. * @dir: The directory to create the symlink in
  326. * @dentry: The dentry to put the symlink in
  327. * @symname: The thing which the link points to
  328. *
  329. * Returns: errno
  330. */
  331. static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
  332. const char *symname)
  333. {
  334. struct gfs2_inode *dip = GFS2_I(dir), *ip;
  335. struct gfs2_sbd *sdp = GFS2_SB(dir);
  336. struct gfs2_holder ghs[2];
  337. struct inode *inode;
  338. struct buffer_head *dibh;
  339. int size;
  340. int error;
  341. /* Must be stuffed with a null terminator for gfs2_follow_link() */
  342. size = strlen(symname);
  343. if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
  344. return -ENAMETOOLONG;
  345. gfs2_holder_init(dip->i_gl, 0, 0, ghs);
  346. inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0);
  347. if (IS_ERR(inode)) {
  348. gfs2_holder_uninit(ghs);
  349. return PTR_ERR(inode);
  350. }
  351. ip = ghs[1].gh_gl->gl_object;
  352. i_size_write(inode, size);
  353. error = gfs2_meta_inode_buffer(ip, &dibh);
  354. if (!gfs2_assert_withdraw(sdp, !error)) {
  355. gfs2_dinode_out(ip, dibh->b_data);
  356. memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
  357. size);
  358. brelse(dibh);
  359. }
  360. gfs2_trans_end(sdp);
  361. if (dip->i_alloc->al_rgd)
  362. gfs2_inplace_release(dip);
  363. gfs2_quota_unlock(dip);
  364. gfs2_alloc_put(dip);
  365. gfs2_glock_dq_uninit_m(2, ghs);
  366. d_instantiate(dentry, inode);
  367. mark_inode_dirty(inode);
  368. return 0;
  369. }
  370. /**
  371. * gfs2_mkdir - Make a directory
  372. * @dir: The parent directory of the new one
  373. * @dentry: The dentry of the new directory
  374. * @mode: The mode of the new directory
  375. *
  376. * Returns: errno
  377. */
  378. static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
  379. {
  380. struct gfs2_inode *dip = GFS2_I(dir), *ip;
  381. struct gfs2_sbd *sdp = GFS2_SB(dir);
  382. struct gfs2_holder ghs[2];
  383. struct inode *inode;
  384. struct buffer_head *dibh;
  385. int error;
  386. gfs2_holder_init(dip->i_gl, 0, 0, ghs);
  387. inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0);
  388. if (IS_ERR(inode)) {
  389. gfs2_holder_uninit(ghs);
  390. return PTR_ERR(inode);
  391. }
  392. ip = ghs[1].gh_gl->gl_object;
  393. ip->i_inode.i_nlink = 2;
  394. i_size_write(inode, sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode));
  395. ip->i_diskflags |= GFS2_DIF_JDATA;
  396. ip->i_entries = 2;
  397. error = gfs2_meta_inode_buffer(ip, &dibh);
  398. if (!gfs2_assert_withdraw(sdp, !error)) {
  399. struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
  400. struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
  401. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  402. gfs2_qstr2dirent(&gfs2_qdot, GFS2_DIRENT_SIZE(gfs2_qdot.len), dent);
  403. dent->de_inum = di->di_num; /* already GFS2 endian */
  404. dent->de_type = cpu_to_be16(DT_DIR);
  405. di->di_entries = cpu_to_be32(1);
  406. dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
  407. gfs2_qstr2dirent(&gfs2_qdotdot, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
  408. gfs2_inum_out(dip, dent);
  409. dent->de_type = cpu_to_be16(DT_DIR);
  410. gfs2_dinode_out(ip, di);
  411. brelse(dibh);
  412. }
  413. error = gfs2_change_nlink(dip, +1);
  414. gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
  415. gfs2_trans_end(sdp);
  416. if (dip->i_alloc->al_rgd)
  417. gfs2_inplace_release(dip);
  418. gfs2_quota_unlock(dip);
  419. gfs2_alloc_put(dip);
  420. gfs2_glock_dq_uninit_m(2, ghs);
  421. d_instantiate(dentry, inode);
  422. mark_inode_dirty(inode);
  423. return 0;
  424. }
  425. /**
  426. * gfs2_rmdiri - Remove a directory
  427. * @dip: The parent directory of the directory to be removed
  428. * @name: The name of the directory to be removed
  429. * @ip: The GFS2 inode of the directory to be removed
  430. *
  431. * Assumes Glocks on dip and ip are held
  432. *
  433. * Returns: errno
  434. */
  435. static int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name,
  436. struct gfs2_inode *ip)
  437. {
  438. int error;
  439. if (ip->i_entries != 2) {
  440. if (gfs2_consist_inode(ip))
  441. gfs2_dinode_print(ip);
  442. return -EIO;
  443. }
  444. error = gfs2_dir_del(dip, name);
  445. if (error)
  446. return error;
  447. error = gfs2_change_nlink(dip, -1);
  448. if (error)
  449. return error;
  450. error = gfs2_dir_del(ip, &gfs2_qdot);
  451. if (error)
  452. return error;
  453. error = gfs2_dir_del(ip, &gfs2_qdotdot);
  454. if (error)
  455. return error;
  456. /* It looks odd, but it really should be done twice */
  457. error = gfs2_change_nlink(ip, -1);
  458. if (error)
  459. return error;
  460. error = gfs2_change_nlink(ip, -1);
  461. if (error)
  462. return error;
  463. return error;
  464. }
  465. /**
  466. * gfs2_rmdir - Remove a directory
  467. * @dir: The parent directory of the directory to be removed
  468. * @dentry: The dentry of the directory to remove
  469. *
  470. * Remove a directory. Call gfs2_rmdiri()
  471. *
  472. * Returns: errno
  473. */
  474. static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
  475. {
  476. struct gfs2_inode *dip = GFS2_I(dir);
  477. struct gfs2_sbd *sdp = GFS2_SB(dir);
  478. struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
  479. struct gfs2_holder ghs[3];
  480. struct gfs2_rgrpd *rgd;
  481. struct gfs2_holder ri_gh;
  482. int error;
  483. error = gfs2_rindex_hold(sdp, &ri_gh);
  484. if (error)
  485. return error;
  486. gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  487. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
  488. rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
  489. gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
  490. error = gfs2_glock_nq(ghs); /* parent */
  491. if (error)
  492. goto out_parent;
  493. error = gfs2_glock_nq(ghs + 1); /* child */
  494. if (error)
  495. goto out_child;
  496. error = -ENOENT;
  497. if (ip->i_inode.i_nlink == 0)
  498. goto out_rgrp;
  499. error = gfs2_glock_nq(ghs + 2); /* rgrp */
  500. if (error)
  501. goto out_rgrp;
  502. error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
  503. if (error)
  504. goto out_gunlock;
  505. if (ip->i_entries < 2) {
  506. if (gfs2_consist_inode(ip))
  507. gfs2_dinode_print(ip);
  508. error = -EIO;
  509. goto out_gunlock;
  510. }
  511. if (ip->i_entries > 2) {
  512. error = -ENOTEMPTY;
  513. goto out_gunlock;
  514. }
  515. error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
  516. if (error)
  517. goto out_gunlock;
  518. error = gfs2_rmdiri(dip, &dentry->d_name, ip);
  519. gfs2_trans_end(sdp);
  520. out_gunlock:
  521. gfs2_glock_dq(ghs + 2);
  522. out_rgrp:
  523. gfs2_holder_uninit(ghs + 2);
  524. gfs2_glock_dq(ghs + 1);
  525. out_child:
  526. gfs2_holder_uninit(ghs + 1);
  527. gfs2_glock_dq(ghs);
  528. out_parent:
  529. gfs2_holder_uninit(ghs);
  530. gfs2_glock_dq_uninit(&ri_gh);
  531. return error;
  532. }
  533. /**
  534. * gfs2_mknod - Make a special file
  535. * @dir: The directory in which the special file will reside
  536. * @dentry: The dentry of the special file
  537. * @mode: The mode of the special file
  538. * @rdev: The device specification of the special file
  539. *
  540. */
  541. static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
  542. dev_t dev)
  543. {
  544. struct gfs2_inode *dip = GFS2_I(dir);
  545. struct gfs2_sbd *sdp = GFS2_SB(dir);
  546. struct gfs2_holder ghs[2];
  547. struct inode *inode;
  548. gfs2_holder_init(dip->i_gl, 0, 0, ghs);
  549. inode = gfs2_createi(ghs, &dentry->d_name, mode, dev);
  550. if (IS_ERR(inode)) {
  551. gfs2_holder_uninit(ghs);
  552. return PTR_ERR(inode);
  553. }
  554. gfs2_trans_end(sdp);
  555. if (dip->i_alloc->al_rgd)
  556. gfs2_inplace_release(dip);
  557. gfs2_quota_unlock(dip);
  558. gfs2_alloc_put(dip);
  559. gfs2_glock_dq_uninit_m(2, ghs);
  560. d_instantiate(dentry, inode);
  561. mark_inode_dirty(inode);
  562. return 0;
  563. }
  564. /*
  565. * gfs2_ok_to_move - check if it's ok to move a directory to another directory
  566. * @this: move this
  567. * @to: to here
  568. *
  569. * Follow @to back to the root and make sure we don't encounter @this
  570. * Assumes we already hold the rename lock.
  571. *
  572. * Returns: errno
  573. */
  574. static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
  575. {
  576. struct inode *dir = &to->i_inode;
  577. struct super_block *sb = dir->i_sb;
  578. struct inode *tmp;
  579. int error = 0;
  580. igrab(dir);
  581. for (;;) {
  582. if (dir == &this->i_inode) {
  583. error = -EINVAL;
  584. break;
  585. }
  586. if (dir == sb->s_root->d_inode) {
  587. error = 0;
  588. break;
  589. }
  590. tmp = gfs2_lookupi(dir, &gfs2_qdotdot, 1);
  591. if (IS_ERR(tmp)) {
  592. error = PTR_ERR(tmp);
  593. break;
  594. }
  595. iput(dir);
  596. dir = tmp;
  597. }
  598. iput(dir);
  599. return error;
  600. }
  601. /**
  602. * gfs2_rename - Rename a file
  603. * @odir: Parent directory of old file name
  604. * @odentry: The old dentry of the file
  605. * @ndir: Parent directory of new file name
  606. * @ndentry: The new dentry of the file
  607. *
  608. * Returns: errno
  609. */
  610. static int gfs2_rename(struct inode *odir, struct dentry *odentry,
  611. struct inode *ndir, struct dentry *ndentry)
  612. {
  613. struct gfs2_inode *odip = GFS2_I(odir);
  614. struct gfs2_inode *ndip = GFS2_I(ndir);
  615. struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
  616. struct gfs2_inode *nip = NULL;
  617. struct gfs2_sbd *sdp = GFS2_SB(odir);
  618. struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, }, ri_gh;
  619. struct gfs2_rgrpd *nrgd;
  620. unsigned int num_gh;
  621. int dir_rename = 0;
  622. int alloc_required = 0;
  623. unsigned int x;
  624. int error;
  625. if (ndentry->d_inode) {
  626. nip = GFS2_I(ndentry->d_inode);
  627. if (ip == nip)
  628. return 0;
  629. }
  630. error = gfs2_rindex_hold(sdp, &ri_gh);
  631. if (error)
  632. return error;
  633. if (odip != ndip) {
  634. error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
  635. 0, &r_gh);
  636. if (error)
  637. goto out;
  638. if (S_ISDIR(ip->i_inode.i_mode)) {
  639. dir_rename = 1;
  640. /* don't move a dirctory into it's subdir */
  641. error = gfs2_ok_to_move(ip, ndip);
  642. if (error)
  643. goto out_gunlock_r;
  644. }
  645. }
  646. num_gh = 1;
  647. gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  648. if (odip != ndip) {
  649. gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
  650. num_gh++;
  651. }
  652. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
  653. num_gh++;
  654. if (nip) {
  655. gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
  656. num_gh++;
  657. /* grab the resource lock for unlink flag twiddling
  658. * this is the case of the target file already existing
  659. * so we unlink before doing the rename
  660. */
  661. nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr);
  662. if (nrgd)
  663. gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
  664. }
  665. for (x = 0; x < num_gh; x++) {
  666. error = gfs2_glock_nq(ghs + x);
  667. if (error)
  668. goto out_gunlock;
  669. }
  670. error = -ENOENT;
  671. if (ip->i_inode.i_nlink == 0)
  672. goto out_gunlock;
  673. /* Check out the old directory */
  674. error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
  675. if (error)
  676. goto out_gunlock;
  677. /* Check out the new directory */
  678. if (nip) {
  679. error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
  680. if (error)
  681. goto out_gunlock;
  682. if (nip->i_inode.i_nlink == 0) {
  683. error = -EAGAIN;
  684. goto out_gunlock;
  685. }
  686. if (S_ISDIR(nip->i_inode.i_mode)) {
  687. if (nip->i_entries < 2) {
  688. if (gfs2_consist_inode(nip))
  689. gfs2_dinode_print(nip);
  690. error = -EIO;
  691. goto out_gunlock;
  692. }
  693. if (nip->i_entries > 2) {
  694. error = -ENOTEMPTY;
  695. goto out_gunlock;
  696. }
  697. }
  698. } else {
  699. error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC, 0);
  700. if (error)
  701. goto out_gunlock;
  702. error = gfs2_dir_check(ndir, &ndentry->d_name, NULL);
  703. switch (error) {
  704. case -ENOENT:
  705. error = 0;
  706. break;
  707. case 0:
  708. error = -EEXIST;
  709. default:
  710. goto out_gunlock;
  711. };
  712. if (odip != ndip) {
  713. if (!ndip->i_inode.i_nlink) {
  714. error = -ENOENT;
  715. goto out_gunlock;
  716. }
  717. if (ndip->i_entries == (u32)-1) {
  718. error = -EFBIG;
  719. goto out_gunlock;
  720. }
  721. if (S_ISDIR(ip->i_inode.i_mode) &&
  722. ndip->i_inode.i_nlink == (u32)-1) {
  723. error = -EMLINK;
  724. goto out_gunlock;
  725. }
  726. }
  727. }
  728. /* Check out the dir to be renamed */
  729. if (dir_rename) {
  730. error = gfs2_permission(odentry->d_inode, MAY_WRITE, 0);
  731. if (error)
  732. goto out_gunlock;
  733. }
  734. if (nip == NULL)
  735. alloc_required = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
  736. error = alloc_required;
  737. if (error < 0)
  738. goto out_gunlock;
  739. error = 0;
  740. if (alloc_required) {
  741. struct gfs2_alloc *al = gfs2_alloc_get(ndip);
  742. if (!al) {
  743. error = -ENOMEM;
  744. goto out_gunlock;
  745. }
  746. error = gfs2_quota_lock_check(ndip);
  747. if (error)
  748. goto out_alloc;
  749. al->al_requested = sdp->sd_max_dirres;
  750. error = gfs2_inplace_reserve_ri(ndip);
  751. if (error)
  752. goto out_gunlock_q;
  753. error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
  754. gfs2_rg_blocks(al) +
  755. 4 * RES_DINODE + 4 * RES_LEAF +
  756. RES_STATFS + RES_QUOTA + 4, 0);
  757. if (error)
  758. goto out_ipreserv;
  759. } else {
  760. error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
  761. 5 * RES_LEAF + 4, 0);
  762. if (error)
  763. goto out_gunlock;
  764. }
  765. /* Remove the target file, if it exists */
  766. if (nip) {
  767. if (S_ISDIR(nip->i_inode.i_mode))
  768. error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
  769. else {
  770. error = gfs2_dir_del(ndip, &ndentry->d_name);
  771. if (error)
  772. goto out_end_trans;
  773. error = gfs2_change_nlink(nip, -1);
  774. }
  775. if (error)
  776. goto out_end_trans;
  777. }
  778. if (dir_rename) {
  779. error = gfs2_change_nlink(ndip, +1);
  780. if (error)
  781. goto out_end_trans;
  782. error = gfs2_change_nlink(odip, -1);
  783. if (error)
  784. goto out_end_trans;
  785. error = gfs2_dir_mvino(ip, &gfs2_qdotdot, ndip, DT_DIR);
  786. if (error)
  787. goto out_end_trans;
  788. } else {
  789. struct buffer_head *dibh;
  790. error = gfs2_meta_inode_buffer(ip, &dibh);
  791. if (error)
  792. goto out_end_trans;
  793. ip->i_inode.i_ctime = CURRENT_TIME;
  794. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  795. gfs2_dinode_out(ip, dibh->b_data);
  796. brelse(dibh);
  797. }
  798. error = gfs2_dir_del(odip, &odentry->d_name);
  799. if (error)
  800. goto out_end_trans;
  801. error = gfs2_dir_add(ndir, &ndentry->d_name, ip, IF2DT(ip->i_inode.i_mode));
  802. if (error)
  803. goto out_end_trans;
  804. out_end_trans:
  805. gfs2_trans_end(sdp);
  806. out_ipreserv:
  807. if (alloc_required)
  808. gfs2_inplace_release(ndip);
  809. out_gunlock_q:
  810. if (alloc_required)
  811. gfs2_quota_unlock(ndip);
  812. out_alloc:
  813. if (alloc_required)
  814. gfs2_alloc_put(ndip);
  815. out_gunlock:
  816. while (x--) {
  817. gfs2_glock_dq(ghs + x);
  818. gfs2_holder_uninit(ghs + x);
  819. }
  820. out_gunlock_r:
  821. if (r_gh.gh_gl)
  822. gfs2_glock_dq_uninit(&r_gh);
  823. out:
  824. gfs2_glock_dq_uninit(&ri_gh);
  825. return error;
  826. }
  827. /**
  828. * gfs2_follow_link - Follow a symbolic link
  829. * @dentry: The dentry of the link
  830. * @nd: Data that we pass to vfs_follow_link()
  831. *
  832. * This can handle symlinks of any size.
  833. *
  834. * Returns: 0 on success or error code
  835. */
  836. static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
  837. {
  838. struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
  839. struct gfs2_holder i_gh;
  840. struct buffer_head *dibh;
  841. unsigned int x, size;
  842. char *buf;
  843. int error;
  844. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
  845. error = gfs2_glock_nq(&i_gh);
  846. if (error) {
  847. gfs2_holder_uninit(&i_gh);
  848. nd_set_link(nd, ERR_PTR(error));
  849. return NULL;
  850. }
  851. size = (unsigned int)i_size_read(&ip->i_inode);
  852. if (size == 0) {
  853. gfs2_consist_inode(ip);
  854. buf = ERR_PTR(-EIO);
  855. goto out;
  856. }
  857. error = gfs2_meta_inode_buffer(ip, &dibh);
  858. if (error) {
  859. buf = ERR_PTR(error);
  860. goto out;
  861. }
  862. x = size + 1;
  863. buf = kmalloc(x, GFP_NOFS);
  864. if (!buf)
  865. buf = ERR_PTR(-ENOMEM);
  866. else
  867. memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), x);
  868. brelse(dibh);
  869. out:
  870. gfs2_glock_dq_uninit(&i_gh);
  871. nd_set_link(nd, buf);
  872. return NULL;
  873. }
  874. static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
  875. {
  876. char *s = nd_get_link(nd);
  877. if (!IS_ERR(s))
  878. kfree(s);
  879. }
  880. /**
  881. * gfs2_permission -
  882. * @inode: The inode
  883. * @mask: The mask to be tested
  884. * @flags: Indicates whether this is an RCU path walk or not
  885. *
  886. * This may be called from the VFS directly, or from within GFS2 with the
  887. * inode locked, so we look to see if the glock is already locked and only
  888. * lock the glock if its not already been done.
  889. *
  890. * Returns: errno
  891. */
  892. int gfs2_permission(struct inode *inode, int mask, unsigned int flags)
  893. {
  894. struct gfs2_inode *ip;
  895. struct gfs2_holder i_gh;
  896. int error;
  897. int unlock = 0;
  898. ip = GFS2_I(inode);
  899. if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
  900. if (flags & IPERM_FLAG_RCU)
  901. return -ECHILD;
  902. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
  903. if (error)
  904. return error;
  905. unlock = 1;
  906. }
  907. if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode))
  908. error = -EACCES;
  909. else
  910. error = generic_permission(inode, mask, flags, gfs2_check_acl);
  911. if (unlock)
  912. gfs2_glock_dq_uninit(&i_gh);
  913. return error;
  914. }
  915. static int setattr_chown(struct inode *inode, struct iattr *attr)
  916. {
  917. struct gfs2_inode *ip = GFS2_I(inode);
  918. struct gfs2_sbd *sdp = GFS2_SB(inode);
  919. u32 ouid, ogid, nuid, ngid;
  920. int error;
  921. ouid = inode->i_uid;
  922. ogid = inode->i_gid;
  923. nuid = attr->ia_uid;
  924. ngid = attr->ia_gid;
  925. if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
  926. ouid = nuid = NO_QUOTA_CHANGE;
  927. if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
  928. ogid = ngid = NO_QUOTA_CHANGE;
  929. if (!gfs2_alloc_get(ip))
  930. return -ENOMEM;
  931. error = gfs2_quota_lock(ip, nuid, ngid);
  932. if (error)
  933. goto out_alloc;
  934. if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
  935. error = gfs2_quota_check(ip, nuid, ngid);
  936. if (error)
  937. goto out_gunlock_q;
  938. }
  939. error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
  940. if (error)
  941. goto out_gunlock_q;
  942. error = gfs2_setattr_simple(ip, attr);
  943. if (error)
  944. goto out_end_trans;
  945. if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
  946. u64 blocks = gfs2_get_inode_blocks(&ip->i_inode);
  947. gfs2_quota_change(ip, -blocks, ouid, ogid);
  948. gfs2_quota_change(ip, blocks, nuid, ngid);
  949. }
  950. out_end_trans:
  951. gfs2_trans_end(sdp);
  952. out_gunlock_q:
  953. gfs2_quota_unlock(ip);
  954. out_alloc:
  955. gfs2_alloc_put(ip);
  956. return error;
  957. }
  958. /**
  959. * gfs2_setattr - Change attributes on an inode
  960. * @dentry: The dentry which is changing
  961. * @attr: The structure describing the change
  962. *
  963. * The VFS layer wants to change one or more of an inodes attributes. Write
  964. * that change out to disk.
  965. *
  966. * Returns: errno
  967. */
  968. static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
  969. {
  970. struct inode *inode = dentry->d_inode;
  971. struct gfs2_inode *ip = GFS2_I(inode);
  972. struct gfs2_holder i_gh;
  973. int error;
  974. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
  975. if (error)
  976. return error;
  977. error = -EPERM;
  978. if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  979. goto out;
  980. error = inode_change_ok(inode, attr);
  981. if (error)
  982. goto out;
  983. if (attr->ia_valid & ATTR_SIZE)
  984. error = gfs2_setattr_size(inode, attr->ia_size);
  985. else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
  986. error = setattr_chown(inode, attr);
  987. else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
  988. error = gfs2_acl_chmod(ip, attr);
  989. else
  990. error = gfs2_setattr_simple(ip, attr);
  991. out:
  992. gfs2_glock_dq_uninit(&i_gh);
  993. if (!error)
  994. mark_inode_dirty(inode);
  995. return error;
  996. }
  997. /**
  998. * gfs2_getattr - Read out an inode's attributes
  999. * @mnt: The vfsmount the inode is being accessed from
  1000. * @dentry: The dentry to stat
  1001. * @stat: The inode's stats
  1002. *
  1003. * This may be called from the VFS directly, or from within GFS2 with the
  1004. * inode locked, so we look to see if the glock is already locked and only
  1005. * lock the glock if its not already been done. Note that its the NFS
  1006. * readdirplus operation which causes this to be called (from filldir)
  1007. * with the glock already held.
  1008. *
  1009. * Returns: errno
  1010. */
  1011. static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
  1012. struct kstat *stat)
  1013. {
  1014. struct inode *inode = dentry->d_inode;
  1015. struct gfs2_inode *ip = GFS2_I(inode);
  1016. struct gfs2_holder gh;
  1017. int error;
  1018. int unlock = 0;
  1019. if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
  1020. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
  1021. if (error)
  1022. return error;
  1023. unlock = 1;
  1024. }
  1025. generic_fillattr(inode, stat);
  1026. if (unlock)
  1027. gfs2_glock_dq_uninit(&gh);
  1028. return 0;
  1029. }
  1030. static int gfs2_setxattr(struct dentry *dentry, const char *name,
  1031. const void *data, size_t size, int flags)
  1032. {
  1033. struct inode *inode = dentry->d_inode;
  1034. struct gfs2_inode *ip = GFS2_I(inode);
  1035. struct gfs2_holder gh;
  1036. int ret;
  1037. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  1038. ret = gfs2_glock_nq(&gh);
  1039. if (ret == 0) {
  1040. ret = generic_setxattr(dentry, name, data, size, flags);
  1041. gfs2_glock_dq(&gh);
  1042. }
  1043. gfs2_holder_uninit(&gh);
  1044. return ret;
  1045. }
  1046. static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
  1047. void *data, size_t size)
  1048. {
  1049. struct inode *inode = dentry->d_inode;
  1050. struct gfs2_inode *ip = GFS2_I(inode);
  1051. struct gfs2_holder gh;
  1052. int ret;
  1053. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
  1054. ret = gfs2_glock_nq(&gh);
  1055. if (ret == 0) {
  1056. ret = generic_getxattr(dentry, name, data, size);
  1057. gfs2_glock_dq(&gh);
  1058. }
  1059. gfs2_holder_uninit(&gh);
  1060. return ret;
  1061. }
  1062. static int gfs2_removexattr(struct dentry *dentry, const char *name)
  1063. {
  1064. struct inode *inode = dentry->d_inode;
  1065. struct gfs2_inode *ip = GFS2_I(inode);
  1066. struct gfs2_holder gh;
  1067. int ret;
  1068. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  1069. ret = gfs2_glock_nq(&gh);
  1070. if (ret == 0) {
  1071. ret = generic_removexattr(dentry, name);
  1072. gfs2_glock_dq(&gh);
  1073. }
  1074. gfs2_holder_uninit(&gh);
  1075. return ret;
  1076. }
  1077. static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  1078. u64 start, u64 len)
  1079. {
  1080. struct gfs2_inode *ip = GFS2_I(inode);
  1081. struct gfs2_holder gh;
  1082. int ret;
  1083. ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
  1084. if (ret)
  1085. return ret;
  1086. mutex_lock(&inode->i_mutex);
  1087. ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
  1088. if (ret)
  1089. goto out;
  1090. if (gfs2_is_stuffed(ip)) {
  1091. u64 phys = ip->i_no_addr << inode->i_blkbits;
  1092. u64 size = i_size_read(inode);
  1093. u32 flags = FIEMAP_EXTENT_LAST|FIEMAP_EXTENT_NOT_ALIGNED|
  1094. FIEMAP_EXTENT_DATA_INLINE;
  1095. phys += sizeof(struct gfs2_dinode);
  1096. phys += start;
  1097. if (start + len > size)
  1098. len = size - start;
  1099. if (start < size)
  1100. ret = fiemap_fill_next_extent(fieinfo, start, phys,
  1101. len, flags);
  1102. if (ret == 1)
  1103. ret = 0;
  1104. } else {
  1105. ret = __generic_block_fiemap(inode, fieinfo, start, len,
  1106. gfs2_block_map);
  1107. }
  1108. gfs2_glock_dq_uninit(&gh);
  1109. out:
  1110. mutex_unlock(&inode->i_mutex);
  1111. return ret;
  1112. }
  1113. const struct inode_operations gfs2_file_iops = {
  1114. .permission = gfs2_permission,
  1115. .setattr = gfs2_setattr,
  1116. .getattr = gfs2_getattr,
  1117. .setxattr = gfs2_setxattr,
  1118. .getxattr = gfs2_getxattr,
  1119. .listxattr = gfs2_listxattr,
  1120. .removexattr = gfs2_removexattr,
  1121. .fiemap = gfs2_fiemap,
  1122. };
  1123. const struct inode_operations gfs2_dir_iops = {
  1124. .create = gfs2_create,
  1125. .lookup = gfs2_lookup,
  1126. .link = gfs2_link,
  1127. .unlink = gfs2_unlink,
  1128. .symlink = gfs2_symlink,
  1129. .mkdir = gfs2_mkdir,
  1130. .rmdir = gfs2_rmdir,
  1131. .mknod = gfs2_mknod,
  1132. .rename = gfs2_rename,
  1133. .permission = gfs2_permission,
  1134. .setattr = gfs2_setattr,
  1135. .getattr = gfs2_getattr,
  1136. .setxattr = gfs2_setxattr,
  1137. .getxattr = gfs2_getxattr,
  1138. .listxattr = gfs2_listxattr,
  1139. .removexattr = gfs2_removexattr,
  1140. .fiemap = gfs2_fiemap,
  1141. };
  1142. const struct inode_operations gfs2_symlink_iops = {
  1143. .readlink = generic_readlink,
  1144. .follow_link = gfs2_follow_link,
  1145. .put_link = gfs2_put_link,
  1146. .permission = gfs2_permission,
  1147. .setattr = gfs2_setattr,
  1148. .getattr = gfs2_getattr,
  1149. .setxattr = gfs2_setxattr,
  1150. .getxattr = gfs2_getxattr,
  1151. .listxattr = gfs2_listxattr,
  1152. .removexattr = gfs2_removexattr,
  1153. .fiemap = gfs2_fiemap,
  1154. };