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