ops_inode.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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. dentry->d_op = &gfs2_dops;
  96. inode = gfs2_lookupi(dir, &dentry->d_name, 0);
  97. if (inode && IS_ERR(inode))
  98. return ERR_CAST(inode);
  99. if (inode) {
  100. struct gfs2_glock *gl = GFS2_I(inode)->i_gl;
  101. struct gfs2_holder gh;
  102. int error;
  103. error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
  104. if (error) {
  105. iput(inode);
  106. return ERR_PTR(error);
  107. }
  108. gfs2_glock_dq_uninit(&gh);
  109. return d_splice_alias(inode, dentry);
  110. }
  111. d_add(dentry, inode);
  112. return NULL;
  113. }
  114. /**
  115. * gfs2_link - Link to a file
  116. * @old_dentry: The inode to link
  117. * @dir: Add link to this directory
  118. * @dentry: The name of the link
  119. *
  120. * Link the inode in "old_dentry" into the directory "dir" with the
  121. * name in "dentry".
  122. *
  123. * Returns: errno
  124. */
  125. static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
  126. struct dentry *dentry)
  127. {
  128. struct gfs2_inode *dip = GFS2_I(dir);
  129. struct gfs2_sbd *sdp = GFS2_SB(dir);
  130. struct inode *inode = old_dentry->d_inode;
  131. struct gfs2_inode *ip = GFS2_I(inode);
  132. struct gfs2_holder ghs[2];
  133. int alloc_required;
  134. int error;
  135. if (S_ISDIR(inode->i_mode))
  136. return -EPERM;
  137. gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  138. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
  139. error = gfs2_glock_nq(ghs); /* parent */
  140. if (error)
  141. goto out_parent;
  142. error = gfs2_glock_nq(ghs + 1); /* child */
  143. if (error)
  144. goto out_child;
  145. error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC);
  146. if (error)
  147. goto out_gunlock;
  148. error = gfs2_dir_check(dir, &dentry->d_name, NULL);
  149. switch (error) {
  150. case -ENOENT:
  151. break;
  152. case 0:
  153. error = -EEXIST;
  154. default:
  155. goto out_gunlock;
  156. }
  157. error = -EINVAL;
  158. if (!dip->i_inode.i_nlink)
  159. goto out_gunlock;
  160. error = -EFBIG;
  161. if (dip->i_entries == (u32)-1)
  162. goto out_gunlock;
  163. error = -EPERM;
  164. if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  165. goto out_gunlock;
  166. error = -EINVAL;
  167. if (!ip->i_inode.i_nlink)
  168. goto out_gunlock;
  169. error = -EMLINK;
  170. if (ip->i_inode.i_nlink == (u32)-1)
  171. goto out_gunlock;
  172. alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
  173. if (error < 0)
  174. goto out_gunlock;
  175. error = 0;
  176. if (alloc_required) {
  177. struct gfs2_alloc *al = gfs2_alloc_get(dip);
  178. if (!al) {
  179. error = -ENOMEM;
  180. goto out_gunlock;
  181. }
  182. error = gfs2_quota_lock_check(dip);
  183. if (error)
  184. goto out_alloc;
  185. al->al_requested = sdp->sd_max_dirres;
  186. error = gfs2_inplace_reserve(dip);
  187. if (error)
  188. goto out_gunlock_q;
  189. error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
  190. al->al_rgd->rd_length +
  191. 2 * RES_DINODE + RES_STATFS +
  192. RES_QUOTA, 0);
  193. if (error)
  194. goto out_ipres;
  195. } else {
  196. error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
  197. if (error)
  198. goto out_ipres;
  199. }
  200. error = gfs2_dir_add(dir, &dentry->d_name, ip, IF2DT(inode->i_mode));
  201. if (error)
  202. goto out_end_trans;
  203. error = gfs2_change_nlink(ip, +1);
  204. out_end_trans:
  205. gfs2_trans_end(sdp);
  206. out_ipres:
  207. if (alloc_required)
  208. gfs2_inplace_release(dip);
  209. out_gunlock_q:
  210. if (alloc_required)
  211. gfs2_quota_unlock(dip);
  212. out_alloc:
  213. if (alloc_required)
  214. gfs2_alloc_put(dip);
  215. out_gunlock:
  216. gfs2_glock_dq(ghs + 1);
  217. out_child:
  218. gfs2_glock_dq(ghs);
  219. out_parent:
  220. gfs2_holder_uninit(ghs);
  221. gfs2_holder_uninit(ghs + 1);
  222. if (!error) {
  223. atomic_inc(&inode->i_count);
  224. d_instantiate(dentry, inode);
  225. mark_inode_dirty(inode);
  226. }
  227. return error;
  228. }
  229. /*
  230. * gfs2_unlink_ok - check to see that a inode is still in a directory
  231. * @dip: the directory
  232. * @name: the name of the file
  233. * @ip: the inode
  234. *
  235. * Assumes that the lock on (at least) @dip is held.
  236. *
  237. * Returns: 0 if the parent/child relationship is correct, errno if it isn't
  238. */
  239. static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
  240. const struct gfs2_inode *ip)
  241. {
  242. int error;
  243. if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
  244. return -EPERM;
  245. if ((dip->i_inode.i_mode & S_ISVTX) &&
  246. dip->i_inode.i_uid != current_fsuid() &&
  247. ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER))
  248. return -EPERM;
  249. if (IS_APPEND(&dip->i_inode))
  250. return -EPERM;
  251. error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
  252. if (error)
  253. return error;
  254. error = gfs2_dir_check(&dip->i_inode, name, ip);
  255. if (error)
  256. return error;
  257. return 0;
  258. }
  259. /**
  260. * gfs2_unlink - Unlink a file
  261. * @dir: The inode of the directory containing the file to unlink
  262. * @dentry: The file itself
  263. *
  264. * Unlink a file. Call gfs2_unlinki()
  265. *
  266. * Returns: errno
  267. */
  268. static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
  269. {
  270. struct gfs2_inode *dip = GFS2_I(dir);
  271. struct gfs2_sbd *sdp = GFS2_SB(dir);
  272. struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
  273. struct gfs2_holder ghs[3];
  274. struct gfs2_rgrpd *rgd;
  275. struct gfs2_holder ri_gh;
  276. int error;
  277. error = gfs2_rindex_hold(sdp, &ri_gh);
  278. if (error)
  279. return error;
  280. gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  281. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
  282. rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
  283. gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
  284. error = gfs2_glock_nq(ghs); /* parent */
  285. if (error)
  286. goto out_parent;
  287. error = gfs2_glock_nq(ghs + 1); /* child */
  288. if (error)
  289. goto out_child;
  290. error = gfs2_glock_nq(ghs + 2); /* rgrp */
  291. if (error)
  292. goto out_rgrp;
  293. error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
  294. if (error)
  295. goto out_gunlock;
  296. error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
  297. if (error)
  298. goto out_gunlock;
  299. error = gfs2_dir_del(dip, &dentry->d_name);
  300. if (error)
  301. goto out_end_trans;
  302. error = gfs2_change_nlink(ip, -1);
  303. out_end_trans:
  304. gfs2_trans_end(sdp);
  305. out_gunlock:
  306. gfs2_glock_dq(ghs + 2);
  307. out_rgrp:
  308. gfs2_holder_uninit(ghs + 2);
  309. gfs2_glock_dq(ghs + 1);
  310. out_child:
  311. gfs2_holder_uninit(ghs + 1);
  312. gfs2_glock_dq(ghs);
  313. out_parent:
  314. gfs2_holder_uninit(ghs);
  315. gfs2_glock_dq_uninit(&ri_gh);
  316. return error;
  317. }
  318. /**
  319. * gfs2_symlink - Create a symlink
  320. * @dir: The directory to create the symlink in
  321. * @dentry: The dentry to put the symlink in
  322. * @symname: The thing which the link points to
  323. *
  324. * Returns: errno
  325. */
  326. static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
  327. const char *symname)
  328. {
  329. struct gfs2_inode *dip = GFS2_I(dir), *ip;
  330. struct gfs2_sbd *sdp = GFS2_SB(dir);
  331. struct gfs2_holder ghs[2];
  332. struct inode *inode;
  333. struct buffer_head *dibh;
  334. int size;
  335. int error;
  336. /* Must be stuffed with a null terminator for gfs2_follow_link() */
  337. size = strlen(symname);
  338. if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
  339. return -ENAMETOOLONG;
  340. gfs2_holder_init(dip->i_gl, 0, 0, ghs);
  341. inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0);
  342. if (IS_ERR(inode)) {
  343. gfs2_holder_uninit(ghs);
  344. return PTR_ERR(inode);
  345. }
  346. ip = ghs[1].gh_gl->gl_object;
  347. i_size_write(inode, size);
  348. error = gfs2_meta_inode_buffer(ip, &dibh);
  349. if (!gfs2_assert_withdraw(sdp, !error)) {
  350. gfs2_dinode_out(ip, dibh->b_data);
  351. memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
  352. size);
  353. brelse(dibh);
  354. }
  355. gfs2_trans_end(sdp);
  356. if (dip->i_alloc->al_rgd)
  357. gfs2_inplace_release(dip);
  358. gfs2_quota_unlock(dip);
  359. gfs2_alloc_put(dip);
  360. gfs2_glock_dq_uninit_m(2, ghs);
  361. d_instantiate(dentry, inode);
  362. mark_inode_dirty(inode);
  363. return 0;
  364. }
  365. /**
  366. * gfs2_mkdir - Make a directory
  367. * @dir: The parent directory of the new one
  368. * @dentry: The dentry of the new directory
  369. * @mode: The mode of the new directory
  370. *
  371. * Returns: errno
  372. */
  373. static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
  374. {
  375. struct gfs2_inode *dip = GFS2_I(dir), *ip;
  376. struct gfs2_sbd *sdp = GFS2_SB(dir);
  377. struct gfs2_holder ghs[2];
  378. struct inode *inode;
  379. struct buffer_head *dibh;
  380. int error;
  381. gfs2_holder_init(dip->i_gl, 0, 0, ghs);
  382. inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0);
  383. if (IS_ERR(inode)) {
  384. gfs2_holder_uninit(ghs);
  385. return PTR_ERR(inode);
  386. }
  387. ip = ghs[1].gh_gl->gl_object;
  388. ip->i_inode.i_nlink = 2;
  389. i_size_write(inode, sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode));
  390. ip->i_diskflags |= GFS2_DIF_JDATA;
  391. ip->i_entries = 2;
  392. error = gfs2_meta_inode_buffer(ip, &dibh);
  393. if (!gfs2_assert_withdraw(sdp, !error)) {
  394. struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
  395. struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
  396. struct qstr str;
  397. gfs2_str2qstr(&str, ".");
  398. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  399. gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
  400. dent->de_inum = di->di_num; /* already GFS2 endian */
  401. dent->de_type = cpu_to_be16(DT_DIR);
  402. di->di_entries = cpu_to_be32(1);
  403. gfs2_str2qstr(&str, "..");
  404. dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
  405. gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
  406. gfs2_inum_out(dip, dent);
  407. dent->de_type = cpu_to_be16(DT_DIR);
  408. gfs2_dinode_out(ip, di);
  409. brelse(dibh);
  410. }
  411. error = gfs2_change_nlink(dip, +1);
  412. gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
  413. gfs2_trans_end(sdp);
  414. if (dip->i_alloc->al_rgd)
  415. gfs2_inplace_release(dip);
  416. gfs2_quota_unlock(dip);
  417. gfs2_alloc_put(dip);
  418. gfs2_glock_dq_uninit_m(2, ghs);
  419. d_instantiate(dentry, inode);
  420. mark_inode_dirty(inode);
  421. return 0;
  422. }
  423. /**
  424. * gfs2_rmdiri - Remove a directory
  425. * @dip: The parent directory of the directory to be removed
  426. * @name: The name of the directory to be removed
  427. * @ip: The GFS2 inode of the directory to be removed
  428. *
  429. * Assumes Glocks on dip and ip are held
  430. *
  431. * Returns: errno
  432. */
  433. static int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name,
  434. struct gfs2_inode *ip)
  435. {
  436. struct qstr dotname;
  437. int error;
  438. if (ip->i_entries != 2) {
  439. if (gfs2_consist_inode(ip))
  440. gfs2_dinode_print(ip);
  441. return -EIO;
  442. }
  443. error = gfs2_dir_del(dip, name);
  444. if (error)
  445. return error;
  446. error = gfs2_change_nlink(dip, -1);
  447. if (error)
  448. return error;
  449. gfs2_str2qstr(&dotname, ".");
  450. error = gfs2_dir_del(ip, &dotname);
  451. if (error)
  452. return error;
  453. gfs2_str2qstr(&dotname, "..");
  454. error = gfs2_dir_del(ip, &dotname);
  455. if (error)
  456. return error;
  457. /* It looks odd, but it really should be done twice */
  458. error = gfs2_change_nlink(ip, -1);
  459. if (error)
  460. return error;
  461. error = gfs2_change_nlink(ip, -1);
  462. if (error)
  463. return error;
  464. return error;
  465. }
  466. /**
  467. * gfs2_rmdir - Remove a directory
  468. * @dir: The parent directory of the directory to be removed
  469. * @dentry: The dentry of the directory to remove
  470. *
  471. * Remove a directory. Call gfs2_rmdiri()
  472. *
  473. * Returns: errno
  474. */
  475. static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
  476. {
  477. struct gfs2_inode *dip = GFS2_I(dir);
  478. struct gfs2_sbd *sdp = GFS2_SB(dir);
  479. struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
  480. struct gfs2_holder ghs[3];
  481. struct gfs2_rgrpd *rgd;
  482. struct gfs2_holder ri_gh;
  483. int error;
  484. error = gfs2_rindex_hold(sdp, &ri_gh);
  485. if (error)
  486. return error;
  487. gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  488. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
  489. rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
  490. gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
  491. error = gfs2_glock_nq(ghs); /* parent */
  492. if (error)
  493. goto out_parent;
  494. error = gfs2_glock_nq(ghs + 1); /* child */
  495. if (error)
  496. goto out_child;
  497. error = gfs2_glock_nq(ghs + 2); /* rgrp */
  498. if (error)
  499. goto out_rgrp;
  500. error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
  501. if (error)
  502. goto out_gunlock;
  503. if (ip->i_entries < 2) {
  504. if (gfs2_consist_inode(ip))
  505. gfs2_dinode_print(ip);
  506. error = -EIO;
  507. goto out_gunlock;
  508. }
  509. if (ip->i_entries > 2) {
  510. error = -ENOTEMPTY;
  511. goto out_gunlock;
  512. }
  513. error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
  514. if (error)
  515. goto out_gunlock;
  516. error = gfs2_rmdiri(dip, &dentry->d_name, ip);
  517. gfs2_trans_end(sdp);
  518. out_gunlock:
  519. gfs2_glock_dq(ghs + 2);
  520. out_rgrp:
  521. gfs2_holder_uninit(ghs + 2);
  522. gfs2_glock_dq(ghs + 1);
  523. out_child:
  524. gfs2_holder_uninit(ghs + 1);
  525. gfs2_glock_dq(ghs);
  526. out_parent:
  527. gfs2_holder_uninit(ghs);
  528. gfs2_glock_dq_uninit(&ri_gh);
  529. return error;
  530. }
  531. /**
  532. * gfs2_mknod - Make a special file
  533. * @dir: The directory in which the special file will reside
  534. * @dentry: The dentry of the special file
  535. * @mode: The mode of the special file
  536. * @rdev: The device specification of the special file
  537. *
  538. */
  539. static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
  540. dev_t dev)
  541. {
  542. struct gfs2_inode *dip = GFS2_I(dir);
  543. struct gfs2_sbd *sdp = GFS2_SB(dir);
  544. struct gfs2_holder ghs[2];
  545. struct inode *inode;
  546. gfs2_holder_init(dip->i_gl, 0, 0, ghs);
  547. inode = gfs2_createi(ghs, &dentry->d_name, mode, dev);
  548. if (IS_ERR(inode)) {
  549. gfs2_holder_uninit(ghs);
  550. return PTR_ERR(inode);
  551. }
  552. gfs2_trans_end(sdp);
  553. if (dip->i_alloc->al_rgd)
  554. gfs2_inplace_release(dip);
  555. gfs2_quota_unlock(dip);
  556. gfs2_alloc_put(dip);
  557. gfs2_glock_dq_uninit_m(2, ghs);
  558. d_instantiate(dentry, inode);
  559. mark_inode_dirty(inode);
  560. return 0;
  561. }
  562. /*
  563. * gfs2_ok_to_move - check if it's ok to move a directory to another directory
  564. * @this: move this
  565. * @to: to here
  566. *
  567. * Follow @to back to the root and make sure we don't encounter @this
  568. * Assumes we already hold the rename lock.
  569. *
  570. * Returns: errno
  571. */
  572. static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
  573. {
  574. struct inode *dir = &to->i_inode;
  575. struct super_block *sb = dir->i_sb;
  576. struct inode *tmp;
  577. struct qstr dotdot;
  578. int error = 0;
  579. gfs2_str2qstr(&dotdot, "..");
  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, &dotdot, 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, };
  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. if (odip != ndip) {
  631. error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
  632. 0, &r_gh);
  633. if (error)
  634. goto out;
  635. if (S_ISDIR(ip->i_inode.i_mode)) {
  636. dir_rename = 1;
  637. /* don't move a dirctory into it's subdir */
  638. error = gfs2_ok_to_move(ip, ndip);
  639. if (error)
  640. goto out_gunlock_r;
  641. }
  642. }
  643. num_gh = 1;
  644. gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  645. if (odip != ndip) {
  646. gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
  647. num_gh++;
  648. }
  649. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
  650. num_gh++;
  651. if (nip) {
  652. gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
  653. num_gh++;
  654. /* grab the resource lock for unlink flag twiddling
  655. * this is the case of the target file already existing
  656. * so we unlink before doing the rename
  657. */
  658. nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr);
  659. if (nrgd)
  660. gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
  661. }
  662. for (x = 0; x < num_gh; x++) {
  663. error = gfs2_glock_nq(ghs + x);
  664. if (error)
  665. goto out_gunlock;
  666. }
  667. /* Check out the old directory */
  668. error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
  669. if (error)
  670. goto out_gunlock;
  671. /* Check out the new directory */
  672. if (nip) {
  673. error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
  674. if (error)
  675. goto out_gunlock;
  676. if (S_ISDIR(nip->i_inode.i_mode)) {
  677. if (nip->i_entries < 2) {
  678. if (gfs2_consist_inode(nip))
  679. gfs2_dinode_print(nip);
  680. error = -EIO;
  681. goto out_gunlock;
  682. }
  683. if (nip->i_entries > 2) {
  684. error = -ENOTEMPTY;
  685. goto out_gunlock;
  686. }
  687. }
  688. } else {
  689. error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC);
  690. if (error)
  691. goto out_gunlock;
  692. error = gfs2_dir_check(ndir, &ndentry->d_name, NULL);
  693. switch (error) {
  694. case -ENOENT:
  695. error = 0;
  696. break;
  697. case 0:
  698. error = -EEXIST;
  699. default:
  700. goto out_gunlock;
  701. };
  702. if (odip != ndip) {
  703. if (!ndip->i_inode.i_nlink) {
  704. error = -EINVAL;
  705. goto out_gunlock;
  706. }
  707. if (ndip->i_entries == (u32)-1) {
  708. error = -EFBIG;
  709. goto out_gunlock;
  710. }
  711. if (S_ISDIR(ip->i_inode.i_mode) &&
  712. ndip->i_inode.i_nlink == (u32)-1) {
  713. error = -EMLINK;
  714. goto out_gunlock;
  715. }
  716. }
  717. }
  718. /* Check out the dir to be renamed */
  719. if (dir_rename) {
  720. error = gfs2_permission(odentry->d_inode, MAY_WRITE);
  721. if (error)
  722. goto out_gunlock;
  723. }
  724. if (nip == NULL)
  725. alloc_required = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
  726. error = alloc_required;
  727. if (error < 0)
  728. goto out_gunlock;
  729. error = 0;
  730. if (alloc_required) {
  731. struct gfs2_alloc *al = gfs2_alloc_get(ndip);
  732. if (!al) {
  733. error = -ENOMEM;
  734. goto out_gunlock;
  735. }
  736. error = gfs2_quota_lock_check(ndip);
  737. if (error)
  738. goto out_alloc;
  739. al->al_requested = sdp->sd_max_dirres;
  740. error = gfs2_inplace_reserve(ndip);
  741. if (error)
  742. goto out_gunlock_q;
  743. error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
  744. al->al_rgd->rd_length +
  745. 4 * RES_DINODE + 4 * RES_LEAF +
  746. RES_STATFS + RES_QUOTA + 4, 0);
  747. if (error)
  748. goto out_ipreserv;
  749. } else {
  750. error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
  751. 5 * RES_LEAF + 4, 0);
  752. if (error)
  753. goto out_gunlock;
  754. }
  755. /* Remove the target file, if it exists */
  756. if (nip) {
  757. if (S_ISDIR(nip->i_inode.i_mode))
  758. error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
  759. else {
  760. error = gfs2_dir_del(ndip, &ndentry->d_name);
  761. if (error)
  762. goto out_end_trans;
  763. error = gfs2_change_nlink(nip, -1);
  764. }
  765. if (error)
  766. goto out_end_trans;
  767. }
  768. if (dir_rename) {
  769. struct qstr name;
  770. gfs2_str2qstr(&name, "..");
  771. error = gfs2_change_nlink(ndip, +1);
  772. if (error)
  773. goto out_end_trans;
  774. error = gfs2_change_nlink(odip, -1);
  775. if (error)
  776. goto out_end_trans;
  777. error = gfs2_dir_mvino(ip, &name, ndip, DT_DIR);
  778. if (error)
  779. goto out_end_trans;
  780. } else {
  781. struct buffer_head *dibh;
  782. error = gfs2_meta_inode_buffer(ip, &dibh);
  783. if (error)
  784. goto out_end_trans;
  785. ip->i_inode.i_ctime = CURRENT_TIME;
  786. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  787. gfs2_dinode_out(ip, dibh->b_data);
  788. brelse(dibh);
  789. }
  790. error = gfs2_dir_del(odip, &odentry->d_name);
  791. if (error)
  792. goto out_end_trans;
  793. error = gfs2_dir_add(ndir, &ndentry->d_name, ip, IF2DT(ip->i_inode.i_mode));
  794. if (error)
  795. goto out_end_trans;
  796. out_end_trans:
  797. gfs2_trans_end(sdp);
  798. out_ipreserv:
  799. if (alloc_required)
  800. gfs2_inplace_release(ndip);
  801. out_gunlock_q:
  802. if (alloc_required)
  803. gfs2_quota_unlock(ndip);
  804. out_alloc:
  805. if (alloc_required)
  806. gfs2_alloc_put(ndip);
  807. out_gunlock:
  808. while (x--) {
  809. gfs2_glock_dq(ghs + x);
  810. gfs2_holder_uninit(ghs + x);
  811. }
  812. out_gunlock_r:
  813. if (r_gh.gh_gl)
  814. gfs2_glock_dq_uninit(&r_gh);
  815. out:
  816. return error;
  817. }
  818. /**
  819. * gfs2_follow_link - Follow a symbolic link
  820. * @dentry: The dentry of the link
  821. * @nd: Data that we pass to vfs_follow_link()
  822. *
  823. * This can handle symlinks of any size.
  824. *
  825. * Returns: 0 on success or error code
  826. */
  827. static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
  828. {
  829. struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
  830. struct gfs2_holder i_gh;
  831. struct buffer_head *dibh;
  832. unsigned int x, size;
  833. char *buf;
  834. int error;
  835. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
  836. error = gfs2_glock_nq(&i_gh);
  837. if (error) {
  838. gfs2_holder_uninit(&i_gh);
  839. nd_set_link(nd, ERR_PTR(error));
  840. return NULL;
  841. }
  842. size = (unsigned int)i_size_read(&ip->i_inode);
  843. if (size == 0) {
  844. gfs2_consist_inode(ip);
  845. buf = ERR_PTR(-EIO);
  846. goto out;
  847. }
  848. error = gfs2_meta_inode_buffer(ip, &dibh);
  849. if (error) {
  850. buf = ERR_PTR(error);
  851. goto out;
  852. }
  853. x = size + 1;
  854. buf = kmalloc(x, GFP_NOFS);
  855. if (!buf)
  856. buf = ERR_PTR(-ENOMEM);
  857. else
  858. memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), x);
  859. brelse(dibh);
  860. out:
  861. gfs2_glock_dq_uninit(&i_gh);
  862. nd_set_link(nd, buf);
  863. return NULL;
  864. }
  865. static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
  866. {
  867. char *s = nd_get_link(nd);
  868. if (!IS_ERR(s))
  869. kfree(s);
  870. }
  871. /**
  872. * gfs2_permission -
  873. * @inode:
  874. * @mask:
  875. * @nd: passed from Linux VFS, ignored by us
  876. *
  877. * This may be called from the VFS directly, or from within GFS2 with the
  878. * inode locked, so we look to see if the glock is already locked and only
  879. * lock the glock if its not already been done.
  880. *
  881. * Returns: errno
  882. */
  883. int gfs2_permission(struct inode *inode, int mask)
  884. {
  885. struct gfs2_inode *ip = GFS2_I(inode);
  886. struct gfs2_holder i_gh;
  887. int error;
  888. int unlock = 0;
  889. if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
  890. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
  891. if (error)
  892. return error;
  893. unlock = 1;
  894. }
  895. if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode))
  896. error = -EACCES;
  897. else
  898. error = generic_permission(inode, mask, gfs2_check_acl);
  899. if (unlock)
  900. gfs2_glock_dq_uninit(&i_gh);
  901. return error;
  902. }
  903. static int setattr_chown(struct inode *inode, struct iattr *attr)
  904. {
  905. struct gfs2_inode *ip = GFS2_I(inode);
  906. struct gfs2_sbd *sdp = GFS2_SB(inode);
  907. struct buffer_head *dibh;
  908. u32 ouid, ogid, nuid, ngid;
  909. int error;
  910. ouid = inode->i_uid;
  911. ogid = inode->i_gid;
  912. nuid = attr->ia_uid;
  913. ngid = attr->ia_gid;
  914. if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
  915. ouid = nuid = NO_QUOTA_CHANGE;
  916. if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
  917. ogid = ngid = NO_QUOTA_CHANGE;
  918. if (!gfs2_alloc_get(ip))
  919. return -ENOMEM;
  920. error = gfs2_quota_lock(ip, nuid, ngid);
  921. if (error)
  922. goto out_alloc;
  923. if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
  924. error = gfs2_quota_check(ip, nuid, ngid);
  925. if (error)
  926. goto out_gunlock_q;
  927. }
  928. error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
  929. if (error)
  930. goto out_gunlock_q;
  931. error = gfs2_meta_inode_buffer(ip, &dibh);
  932. if (error)
  933. goto out_end_trans;
  934. if ((attr->ia_valid & ATTR_SIZE) &&
  935. attr->ia_size != i_size_read(inode)) {
  936. int error;
  937. error = vmtruncate(inode, attr->ia_size);
  938. gfs2_assert_warn(sdp, !error);
  939. }
  940. setattr_copy(inode, attr);
  941. mark_inode_dirty(inode);
  942. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  943. gfs2_dinode_out(ip, dibh->b_data);
  944. brelse(dibh);
  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. };