inode.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2011 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 <linux/security.h>
  21. #include <asm/uaccess.h>
  22. #include "gfs2.h"
  23. #include "incore.h"
  24. #include "acl.h"
  25. #include "bmap.h"
  26. #include "dir.h"
  27. #include "xattr.h"
  28. #include "glock.h"
  29. #include "inode.h"
  30. #include "meta_io.h"
  31. #include "quota.h"
  32. #include "rgrp.h"
  33. #include "trans.h"
  34. #include "util.h"
  35. #include "super.h"
  36. #include "glops.h"
  37. struct gfs2_skip_data {
  38. u64 no_addr;
  39. int skipped;
  40. int non_block;
  41. };
  42. static int iget_test(struct inode *inode, void *opaque)
  43. {
  44. struct gfs2_inode *ip = GFS2_I(inode);
  45. struct gfs2_skip_data *data = opaque;
  46. if (ip->i_no_addr == data->no_addr) {
  47. if (data->non_block &&
  48. inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) {
  49. data->skipped = 1;
  50. return 0;
  51. }
  52. return 1;
  53. }
  54. return 0;
  55. }
  56. static int iget_set(struct inode *inode, void *opaque)
  57. {
  58. struct gfs2_inode *ip = GFS2_I(inode);
  59. struct gfs2_skip_data *data = opaque;
  60. if (data->skipped)
  61. return -ENOENT;
  62. inode->i_ino = (unsigned long)(data->no_addr);
  63. ip->i_no_addr = data->no_addr;
  64. return 0;
  65. }
  66. struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr, int non_block)
  67. {
  68. unsigned long hash = (unsigned long)no_addr;
  69. struct gfs2_skip_data data;
  70. data.no_addr = no_addr;
  71. data.skipped = 0;
  72. data.non_block = non_block;
  73. return ilookup5(sb, hash, iget_test, &data);
  74. }
  75. static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr,
  76. int non_block)
  77. {
  78. struct gfs2_skip_data data;
  79. unsigned long hash = (unsigned long)no_addr;
  80. data.no_addr = no_addr;
  81. data.skipped = 0;
  82. data.non_block = non_block;
  83. return iget5_locked(sb, hash, iget_test, iget_set, &data);
  84. }
  85. /**
  86. * gfs2_set_iop - Sets inode operations
  87. * @inode: The inode with correct i_mode filled in
  88. *
  89. * GFS2 lookup code fills in vfs inode contents based on info obtained
  90. * from directory entry inside gfs2_inode_lookup().
  91. */
  92. static void gfs2_set_iop(struct inode *inode)
  93. {
  94. struct gfs2_sbd *sdp = GFS2_SB(inode);
  95. umode_t mode = inode->i_mode;
  96. if (S_ISREG(mode)) {
  97. inode->i_op = &gfs2_file_iops;
  98. if (gfs2_localflocks(sdp))
  99. inode->i_fop = &gfs2_file_fops_nolock;
  100. else
  101. inode->i_fop = &gfs2_file_fops;
  102. } else if (S_ISDIR(mode)) {
  103. inode->i_op = &gfs2_dir_iops;
  104. if (gfs2_localflocks(sdp))
  105. inode->i_fop = &gfs2_dir_fops_nolock;
  106. else
  107. inode->i_fop = &gfs2_dir_fops;
  108. } else if (S_ISLNK(mode)) {
  109. inode->i_op = &gfs2_symlink_iops;
  110. } else {
  111. inode->i_op = &gfs2_file_iops;
  112. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  113. }
  114. }
  115. /**
  116. * gfs2_inode_lookup - Lookup an inode
  117. * @sb: The super block
  118. * @no_addr: The inode number
  119. * @type: The type of the inode
  120. * non_block: Can we block on inodes that are being freed?
  121. *
  122. * Returns: A VFS inode, or an error
  123. */
  124. struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
  125. u64 no_addr, u64 no_formal_ino, int non_block)
  126. {
  127. struct inode *inode;
  128. struct gfs2_inode *ip;
  129. struct gfs2_glock *io_gl = NULL;
  130. int error;
  131. inode = gfs2_iget(sb, no_addr, non_block);
  132. ip = GFS2_I(inode);
  133. if (!inode)
  134. return ERR_PTR(-ENOMEM);
  135. if (inode->i_state & I_NEW) {
  136. struct gfs2_sbd *sdp = GFS2_SB(inode);
  137. ip->i_no_formal_ino = no_formal_ino;
  138. error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
  139. if (unlikely(error))
  140. goto fail;
  141. ip->i_gl->gl_object = ip;
  142. error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
  143. if (unlikely(error))
  144. goto fail_put;
  145. set_bit(GIF_INVALID, &ip->i_flags);
  146. error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
  147. if (unlikely(error))
  148. goto fail_iopen;
  149. ip->i_iopen_gh.gh_gl->gl_object = ip;
  150. gfs2_glock_put(io_gl);
  151. io_gl = NULL;
  152. if (type == DT_UNKNOWN) {
  153. /* Inode glock must be locked already */
  154. error = gfs2_inode_refresh(GFS2_I(inode));
  155. if (error)
  156. goto fail_refresh;
  157. } else {
  158. inode->i_mode = DT2IF(type);
  159. }
  160. gfs2_set_iop(inode);
  161. unlock_new_inode(inode);
  162. }
  163. return inode;
  164. fail_refresh:
  165. ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
  166. ip->i_iopen_gh.gh_gl->gl_object = NULL;
  167. gfs2_glock_dq_uninit(&ip->i_iopen_gh);
  168. fail_iopen:
  169. if (io_gl)
  170. gfs2_glock_put(io_gl);
  171. fail_put:
  172. ip->i_gl->gl_object = NULL;
  173. gfs2_glock_put(ip->i_gl);
  174. fail:
  175. iget_failed(inode);
  176. return ERR_PTR(error);
  177. }
  178. struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
  179. u64 *no_formal_ino, unsigned int blktype)
  180. {
  181. struct super_block *sb = sdp->sd_vfs;
  182. struct gfs2_holder i_gh;
  183. struct inode *inode = NULL;
  184. int error;
  185. /* Must not read in block until block type is verified */
  186. error = gfs2_glock_nq_num(sdp, no_addr, &gfs2_inode_glops,
  187. LM_ST_EXCLUSIVE, GL_SKIP, &i_gh);
  188. if (error)
  189. return ERR_PTR(error);
  190. error = gfs2_check_blk_type(sdp, no_addr, blktype);
  191. if (error)
  192. goto fail;
  193. inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0, 1);
  194. if (IS_ERR(inode))
  195. goto fail;
  196. /* Two extra checks for NFS only */
  197. if (no_formal_ino) {
  198. error = -ESTALE;
  199. if (GFS2_I(inode)->i_no_formal_ino != *no_formal_ino)
  200. goto fail_iput;
  201. error = -EIO;
  202. if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM)
  203. goto fail_iput;
  204. error = 0;
  205. }
  206. fail:
  207. gfs2_glock_dq_uninit(&i_gh);
  208. return error ? ERR_PTR(error) : inode;
  209. fail_iput:
  210. iput(inode);
  211. goto fail;
  212. }
  213. struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
  214. {
  215. struct qstr qstr;
  216. struct inode *inode;
  217. gfs2_str2qstr(&qstr, name);
  218. inode = gfs2_lookupi(dip, &qstr, 1);
  219. /* gfs2_lookupi has inconsistent callers: vfs
  220. * related routines expect NULL for no entry found,
  221. * gfs2_lookup_simple callers expect ENOENT
  222. * and do not check for NULL.
  223. */
  224. if (inode == NULL)
  225. return ERR_PTR(-ENOENT);
  226. else
  227. return inode;
  228. }
  229. /**
  230. * gfs2_lookupi - Look up a filename in a directory and return its inode
  231. * @d_gh: An initialized holder for the directory glock
  232. * @name: The name of the inode to look for
  233. * @is_root: If 1, ignore the caller's permissions
  234. * @i_gh: An uninitialized holder for the new inode glock
  235. *
  236. * This can be called via the VFS filldir function when NFS is doing
  237. * a readdirplus and the inode which its intending to stat isn't
  238. * already in cache. In this case we must not take the directory glock
  239. * again, since the readdir call will have already taken that lock.
  240. *
  241. * Returns: errno
  242. */
  243. struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
  244. int is_root)
  245. {
  246. struct super_block *sb = dir->i_sb;
  247. struct gfs2_inode *dip = GFS2_I(dir);
  248. struct gfs2_holder d_gh;
  249. int error = 0;
  250. struct inode *inode = NULL;
  251. int unlock = 0;
  252. if (!name->len || name->len > GFS2_FNAMESIZE)
  253. return ERR_PTR(-ENAMETOOLONG);
  254. if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) ||
  255. (name->len == 2 && memcmp(name->name, "..", 2) == 0 &&
  256. dir == sb->s_root->d_inode)) {
  257. igrab(dir);
  258. return dir;
  259. }
  260. if (gfs2_glock_is_locked_by_me(dip->i_gl) == NULL) {
  261. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  262. if (error)
  263. return ERR_PTR(error);
  264. unlock = 1;
  265. }
  266. if (!is_root) {
  267. error = gfs2_permission(dir, MAY_EXEC);
  268. if (error)
  269. goto out;
  270. }
  271. inode = gfs2_dir_search(dir, name, false);
  272. if (IS_ERR(inode))
  273. error = PTR_ERR(inode);
  274. out:
  275. if (unlock)
  276. gfs2_glock_dq_uninit(&d_gh);
  277. if (error == -ENOENT)
  278. return NULL;
  279. return inode ? inode : ERR_PTR(error);
  280. }
  281. /**
  282. * create_ok - OK to create a new on-disk inode here?
  283. * @dip: Directory in which dinode is to be created
  284. * @name: Name of new dinode
  285. * @mode:
  286. *
  287. * Returns: errno
  288. */
  289. static int create_ok(struct gfs2_inode *dip, const struct qstr *name,
  290. umode_t mode)
  291. {
  292. int error;
  293. error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
  294. if (error)
  295. return error;
  296. /* Don't create entries in an unlinked directory */
  297. if (!dip->i_inode.i_nlink)
  298. return -ENOENT;
  299. if (dip->i_entries == (u32)-1)
  300. return -EFBIG;
  301. if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1)
  302. return -EMLINK;
  303. return 0;
  304. }
  305. static void munge_mode_uid_gid(const struct gfs2_inode *dip,
  306. struct inode *inode)
  307. {
  308. if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir &&
  309. (dip->i_inode.i_mode & S_ISUID) &&
  310. !uid_eq(dip->i_inode.i_uid, GLOBAL_ROOT_UID)) {
  311. if (S_ISDIR(inode->i_mode))
  312. inode->i_mode |= S_ISUID;
  313. else if (!uid_eq(dip->i_inode.i_uid, current_fsuid()))
  314. inode->i_mode &= ~07111;
  315. inode->i_uid = dip->i_inode.i_uid;
  316. } else
  317. inode->i_uid = current_fsuid();
  318. if (dip->i_inode.i_mode & S_ISGID) {
  319. if (S_ISDIR(inode->i_mode))
  320. inode->i_mode |= S_ISGID;
  321. inode->i_gid = dip->i_inode.i_gid;
  322. } else
  323. inode->i_gid = current_fsgid();
  324. }
  325. static int alloc_dinode(struct gfs2_inode *ip, u32 flags)
  326. {
  327. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  328. struct gfs2_alloc_parms ap = { .target = RES_DINODE, .aflags = flags, };
  329. int error;
  330. int dblocks = 1;
  331. error = gfs2_quota_lock_check(ip);
  332. if (error)
  333. goto out;
  334. error = gfs2_inplace_reserve(ip, &ap);
  335. if (error)
  336. goto out_quota;
  337. error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 0);
  338. if (error)
  339. goto out_ipreserv;
  340. error = gfs2_alloc_blocks(ip, &ip->i_no_addr, &dblocks, 1, &ip->i_generation);
  341. ip->i_no_formal_ino = ip->i_generation;
  342. ip->i_inode.i_ino = ip->i_no_addr;
  343. ip->i_goal = ip->i_no_addr;
  344. gfs2_trans_end(sdp);
  345. out_ipreserv:
  346. gfs2_inplace_release(ip);
  347. out_quota:
  348. gfs2_quota_unlock(ip);
  349. out:
  350. return error;
  351. }
  352. static void gfs2_init_dir(struct buffer_head *dibh,
  353. const struct gfs2_inode *parent)
  354. {
  355. struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
  356. struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
  357. gfs2_qstr2dirent(&gfs2_qdot, GFS2_DIRENT_SIZE(gfs2_qdot.len), dent);
  358. dent->de_inum = di->di_num; /* already GFS2 endian */
  359. dent->de_type = cpu_to_be16(DT_DIR);
  360. dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
  361. gfs2_qstr2dirent(&gfs2_qdotdot, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
  362. gfs2_inum_out(parent, dent);
  363. dent->de_type = cpu_to_be16(DT_DIR);
  364. }
  365. /**
  366. * init_dinode - Fill in a new dinode structure
  367. * @dip: The directory this inode is being created in
  368. * @ip: The inode
  369. * @symname: The symlink destination (if a symlink)
  370. * @bhp: The buffer head (returned to caller)
  371. *
  372. */
  373. static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
  374. const char *symname)
  375. {
  376. struct gfs2_dinode *di;
  377. struct buffer_head *dibh;
  378. dibh = gfs2_meta_new(ip->i_gl, ip->i_no_addr);
  379. gfs2_trans_add_meta(ip->i_gl, dibh);
  380. di = (struct gfs2_dinode *)dibh->b_data;
  381. gfs2_dinode_out(ip, di);
  382. di->di_major = cpu_to_be32(MAJOR(ip->i_inode.i_rdev));
  383. di->di_minor = cpu_to_be32(MINOR(ip->i_inode.i_rdev));
  384. di->__pad1 = 0;
  385. di->__pad2 = 0;
  386. di->__pad3 = 0;
  387. memset(&di->__pad4, 0, sizeof(di->__pad4));
  388. memset(&di->di_reserved, 0, sizeof(di->di_reserved));
  389. gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
  390. switch(ip->i_inode.i_mode & S_IFMT) {
  391. case S_IFDIR:
  392. gfs2_init_dir(dibh, dip);
  393. break;
  394. case S_IFLNK:
  395. memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, ip->i_inode.i_size);
  396. break;
  397. }
  398. set_buffer_uptodate(dibh);
  399. brelse(dibh);
  400. }
  401. /**
  402. * gfs2_trans_da_blocks - Calculate number of blocks to link inode
  403. * @dip: The directory we are linking into
  404. * @da: The dir add information
  405. * @nr_inodes: The number of inodes involved
  406. *
  407. * This calculate the number of blocks we need to reserve in a
  408. * transaction to link @nr_inodes into a directory. In most cases
  409. * @nr_inodes will be 2 (the directory plus the inode being linked in)
  410. * but in case of rename, 4 may be required.
  411. *
  412. * Returns: Number of blocks
  413. */
  414. static unsigned gfs2_trans_da_blks(const struct gfs2_inode *dip,
  415. const struct gfs2_diradd *da,
  416. unsigned nr_inodes)
  417. {
  418. return da->nr_blocks + gfs2_rg_blocks(dip, da->nr_blocks) +
  419. (nr_inodes * RES_DINODE) + RES_QUOTA + RES_STATFS;
  420. }
  421. static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
  422. struct gfs2_inode *ip, struct gfs2_diradd *da)
  423. {
  424. struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
  425. struct gfs2_alloc_parms ap = { .target = da->nr_blocks, };
  426. int error;
  427. if (da->nr_blocks) {
  428. error = gfs2_quota_lock_check(dip);
  429. if (error)
  430. goto fail_quota_locks;
  431. error = gfs2_inplace_reserve(dip, &ap);
  432. if (error)
  433. goto fail_quota_locks;
  434. error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, da, 2), 0);
  435. if (error)
  436. goto fail_ipreserv;
  437. } else {
  438. error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0);
  439. if (error)
  440. goto fail_quota_locks;
  441. }
  442. error = gfs2_dir_add(&dip->i_inode, name, ip, da);
  443. if (error)
  444. goto fail_end_trans;
  445. fail_end_trans:
  446. gfs2_trans_end(sdp);
  447. fail_ipreserv:
  448. gfs2_inplace_release(dip);
  449. fail_quota_locks:
  450. gfs2_quota_unlock(dip);
  451. return error;
  452. }
  453. static int gfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
  454. void *fs_info)
  455. {
  456. const struct xattr *xattr;
  457. int err = 0;
  458. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  459. err = __gfs2_xattr_set(inode, xattr->name, xattr->value,
  460. xattr->value_len, 0,
  461. GFS2_EATYPE_SECURITY);
  462. if (err < 0)
  463. break;
  464. }
  465. return err;
  466. }
  467. static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip,
  468. const struct qstr *qstr)
  469. {
  470. return security_inode_init_security(&ip->i_inode, &dip->i_inode, qstr,
  471. &gfs2_initxattrs, NULL);
  472. }
  473. /**
  474. * gfs2_create_inode - Create a new inode
  475. * @dir: The parent directory
  476. * @dentry: The new dentry
  477. * @file: If non-NULL, the file which is being opened
  478. * @mode: The permissions on the new inode
  479. * @dev: For device nodes, this is the device number
  480. * @symname: For symlinks, this is the link destination
  481. * @size: The initial size of the inode (ignored for directories)
  482. *
  483. * Returns: 0 on success, or error code
  484. */
  485. static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
  486. struct file *file,
  487. umode_t mode, dev_t dev, const char *symname,
  488. unsigned int size, int excl, int *opened)
  489. {
  490. const struct qstr *name = &dentry->d_name;
  491. struct posix_acl *default_acl, *acl;
  492. struct gfs2_holder ghs[2];
  493. struct inode *inode = NULL;
  494. struct gfs2_inode *dip = GFS2_I(dir), *ip;
  495. struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
  496. struct gfs2_glock *io_gl;
  497. struct dentry *d;
  498. int error;
  499. u32 aflags = 0;
  500. struct gfs2_diradd da = { .bh = NULL, };
  501. if (!name->len || name->len > GFS2_FNAMESIZE)
  502. return -ENAMETOOLONG;
  503. error = gfs2_rs_alloc(dip);
  504. if (error)
  505. return error;
  506. error = gfs2_rindex_update(sdp);
  507. if (error)
  508. return error;
  509. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  510. if (error)
  511. goto fail;
  512. error = create_ok(dip, name, mode);
  513. if (error)
  514. goto fail_gunlock;
  515. inode = gfs2_dir_search(dir, &dentry->d_name, !S_ISREG(mode) || excl);
  516. error = PTR_ERR(inode);
  517. if (!IS_ERR(inode)) {
  518. d = d_splice_alias(inode, dentry);
  519. error = PTR_ERR(d);
  520. if (IS_ERR(d))
  521. goto fail_gunlock;
  522. error = 0;
  523. if (file) {
  524. if (S_ISREG(inode->i_mode)) {
  525. WARN_ON(d != NULL);
  526. error = finish_open(file, dentry, gfs2_open_common, opened);
  527. } else {
  528. error = finish_no_open(file, d);
  529. }
  530. } else {
  531. dput(d);
  532. }
  533. gfs2_glock_dq_uninit(ghs);
  534. return error;
  535. } else if (error != -ENOENT) {
  536. goto fail_gunlock;
  537. }
  538. error = gfs2_diradd_alloc_required(dir, name, &da);
  539. if (error < 0)
  540. goto fail_gunlock;
  541. inode = new_inode(sdp->sd_vfs);
  542. error = -ENOMEM;
  543. if (!inode)
  544. goto fail_gunlock;
  545. error = posix_acl_create(dir, &mode, &default_acl, &acl);
  546. if (error)
  547. goto fail_free_vfs_inode;
  548. ip = GFS2_I(inode);
  549. error = gfs2_rs_alloc(ip);
  550. if (error)
  551. goto fail_free_acls;
  552. inode->i_mode = mode;
  553. set_nlink(inode, S_ISDIR(mode) ? 2 : 1);
  554. inode->i_rdev = dev;
  555. inode->i_size = size;
  556. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  557. gfs2_set_inode_blocks(inode, 1);
  558. munge_mode_uid_gid(dip, inode);
  559. ip->i_goal = dip->i_goal;
  560. ip->i_diskflags = 0;
  561. ip->i_eattr = 0;
  562. ip->i_height = 0;
  563. ip->i_depth = 0;
  564. ip->i_entries = 0;
  565. switch(mode & S_IFMT) {
  566. case S_IFREG:
  567. if ((dip->i_diskflags & GFS2_DIF_INHERIT_JDATA) ||
  568. gfs2_tune_get(sdp, gt_new_files_jdata))
  569. ip->i_diskflags |= GFS2_DIF_JDATA;
  570. gfs2_set_aops(inode);
  571. break;
  572. case S_IFDIR:
  573. ip->i_diskflags |= (dip->i_diskflags & GFS2_DIF_INHERIT_JDATA);
  574. ip->i_diskflags |= GFS2_DIF_JDATA;
  575. ip->i_entries = 2;
  576. break;
  577. }
  578. gfs2_set_inode_flags(inode);
  579. if ((GFS2_I(sdp->sd_root_dir->d_inode) == dip) ||
  580. (dip->i_diskflags & GFS2_DIF_TOPDIR))
  581. aflags |= GFS2_AF_ORLOV;
  582. error = alloc_dinode(ip, aflags);
  583. if (error)
  584. goto fail_free_inode;
  585. error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
  586. if (error)
  587. goto fail_free_inode;
  588. ip->i_gl->gl_object = ip;
  589. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1);
  590. if (error)
  591. goto fail_free_inode;
  592. error = gfs2_trans_begin(sdp, RES_DINODE, 0);
  593. if (error)
  594. goto fail_gunlock2;
  595. init_dinode(dip, ip, symname);
  596. gfs2_trans_end(sdp);
  597. error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
  598. if (error)
  599. goto fail_gunlock2;
  600. error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
  601. if (error)
  602. goto fail_gunlock2;
  603. ip->i_iopen_gh.gh_gl->gl_object = ip;
  604. gfs2_glock_put(io_gl);
  605. gfs2_set_iop(inode);
  606. insert_inode_hash(inode);
  607. if (default_acl) {
  608. error = gfs2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
  609. posix_acl_release(default_acl);
  610. }
  611. if (acl) {
  612. if (!error)
  613. error = gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
  614. posix_acl_release(acl);
  615. }
  616. if (error)
  617. goto fail_gunlock3;
  618. error = gfs2_security_init(dip, ip, name);
  619. if (error)
  620. goto fail_gunlock3;
  621. error = link_dinode(dip, name, ip, &da);
  622. if (error)
  623. goto fail_gunlock3;
  624. mark_inode_dirty(inode);
  625. d_instantiate(dentry, inode);
  626. if (file) {
  627. *opened |= FILE_CREATED;
  628. error = finish_open(file, dentry, gfs2_open_common, opened);
  629. }
  630. gfs2_glock_dq_uninit(ghs);
  631. gfs2_glock_dq_uninit(ghs + 1);
  632. return error;
  633. fail_gunlock3:
  634. gfs2_glock_dq_uninit(ghs + 1);
  635. if (ip->i_gl)
  636. gfs2_glock_put(ip->i_gl);
  637. goto fail_gunlock;
  638. fail_gunlock2:
  639. gfs2_glock_dq_uninit(ghs + 1);
  640. fail_free_inode:
  641. if (ip->i_gl)
  642. gfs2_glock_put(ip->i_gl);
  643. gfs2_rs_delete(ip, NULL);
  644. fail_free_acls:
  645. if (default_acl)
  646. posix_acl_release(default_acl);
  647. if (acl)
  648. posix_acl_release(acl);
  649. fail_free_vfs_inode:
  650. free_inode_nonrcu(inode);
  651. inode = NULL;
  652. fail_gunlock:
  653. gfs2_dir_no_add(&da);
  654. gfs2_glock_dq_uninit(ghs);
  655. if (inode && !IS_ERR(inode)) {
  656. clear_nlink(inode);
  657. mark_inode_dirty(inode);
  658. set_bit(GIF_ALLOC_FAILED, &GFS2_I(inode)->i_flags);
  659. iput(inode);
  660. }
  661. fail:
  662. return error;
  663. }
  664. /**
  665. * gfs2_create - Create a file
  666. * @dir: The directory in which to create the file
  667. * @dentry: The dentry of the new file
  668. * @mode: The mode of the new file
  669. *
  670. * Returns: errno
  671. */
  672. static int gfs2_create(struct inode *dir, struct dentry *dentry,
  673. umode_t mode, bool excl)
  674. {
  675. return gfs2_create_inode(dir, dentry, NULL, S_IFREG | mode, 0, NULL, 0, excl, NULL);
  676. }
  677. /**
  678. * __gfs2_lookup - Look up a filename in a directory and return its inode
  679. * @dir: The directory inode
  680. * @dentry: The dentry of the new inode
  681. * @file: File to be opened
  682. * @opened: atomic_open flags
  683. *
  684. *
  685. * Returns: errno
  686. */
  687. static struct dentry *__gfs2_lookup(struct inode *dir, struct dentry *dentry,
  688. struct file *file, int *opened)
  689. {
  690. struct inode *inode;
  691. struct dentry *d;
  692. struct gfs2_holder gh;
  693. struct gfs2_glock *gl;
  694. int error;
  695. inode = gfs2_lookupi(dir, &dentry->d_name, 0);
  696. if (!inode)
  697. return NULL;
  698. if (IS_ERR(inode))
  699. return ERR_CAST(inode);
  700. gl = GFS2_I(inode)->i_gl;
  701. error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
  702. if (error) {
  703. iput(inode);
  704. return ERR_PTR(error);
  705. }
  706. d = d_splice_alias(inode, dentry);
  707. if (IS_ERR(d)) {
  708. iput(inode);
  709. gfs2_glock_dq_uninit(&gh);
  710. return d;
  711. }
  712. if (file && S_ISREG(inode->i_mode))
  713. error = finish_open(file, dentry, gfs2_open_common, opened);
  714. gfs2_glock_dq_uninit(&gh);
  715. if (error) {
  716. dput(d);
  717. return ERR_PTR(error);
  718. }
  719. return d;
  720. }
  721. static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
  722. unsigned flags)
  723. {
  724. return __gfs2_lookup(dir, dentry, NULL, NULL);
  725. }
  726. /**
  727. * gfs2_link - Link to a file
  728. * @old_dentry: The inode to link
  729. * @dir: Add link to this directory
  730. * @dentry: The name of the link
  731. *
  732. * Link the inode in "old_dentry" into the directory "dir" with the
  733. * name in "dentry".
  734. *
  735. * Returns: errno
  736. */
  737. static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
  738. struct dentry *dentry)
  739. {
  740. struct gfs2_inode *dip = GFS2_I(dir);
  741. struct gfs2_sbd *sdp = GFS2_SB(dir);
  742. struct inode *inode = old_dentry->d_inode;
  743. struct gfs2_inode *ip = GFS2_I(inode);
  744. struct gfs2_holder ghs[2];
  745. struct buffer_head *dibh;
  746. struct gfs2_diradd da = { .bh = NULL, };
  747. int error;
  748. if (S_ISDIR(inode->i_mode))
  749. return -EPERM;
  750. error = gfs2_rs_alloc(dip);
  751. if (error)
  752. return error;
  753. gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  754. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
  755. error = gfs2_glock_nq(ghs); /* parent */
  756. if (error)
  757. goto out_parent;
  758. error = gfs2_glock_nq(ghs + 1); /* child */
  759. if (error)
  760. goto out_child;
  761. error = -ENOENT;
  762. if (inode->i_nlink == 0)
  763. goto out_gunlock;
  764. error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC);
  765. if (error)
  766. goto out_gunlock;
  767. error = gfs2_dir_check(dir, &dentry->d_name, NULL);
  768. switch (error) {
  769. case -ENOENT:
  770. break;
  771. case 0:
  772. error = -EEXIST;
  773. default:
  774. goto out_gunlock;
  775. }
  776. error = -EINVAL;
  777. if (!dip->i_inode.i_nlink)
  778. goto out_gunlock;
  779. error = -EFBIG;
  780. if (dip->i_entries == (u32)-1)
  781. goto out_gunlock;
  782. error = -EPERM;
  783. if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  784. goto out_gunlock;
  785. error = -EINVAL;
  786. if (!ip->i_inode.i_nlink)
  787. goto out_gunlock;
  788. error = -EMLINK;
  789. if (ip->i_inode.i_nlink == (u32)-1)
  790. goto out_gunlock;
  791. error = gfs2_diradd_alloc_required(dir, &dentry->d_name, &da);
  792. if (error < 0)
  793. goto out_gunlock;
  794. if (da.nr_blocks) {
  795. struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
  796. error = gfs2_quota_lock_check(dip);
  797. if (error)
  798. goto out_gunlock;
  799. error = gfs2_inplace_reserve(dip, &ap);
  800. if (error)
  801. goto out_gunlock_q;
  802. error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, &da, 2), 0);
  803. if (error)
  804. goto out_ipres;
  805. } else {
  806. error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
  807. if (error)
  808. goto out_ipres;
  809. }
  810. error = gfs2_meta_inode_buffer(ip, &dibh);
  811. if (error)
  812. goto out_end_trans;
  813. error = gfs2_dir_add(dir, &dentry->d_name, ip, &da);
  814. if (error)
  815. goto out_brelse;
  816. gfs2_trans_add_meta(ip->i_gl, dibh);
  817. inc_nlink(&ip->i_inode);
  818. ip->i_inode.i_ctime = CURRENT_TIME;
  819. ihold(inode);
  820. d_instantiate(dentry, inode);
  821. mark_inode_dirty(inode);
  822. out_brelse:
  823. brelse(dibh);
  824. out_end_trans:
  825. gfs2_trans_end(sdp);
  826. out_ipres:
  827. if (da.nr_blocks)
  828. gfs2_inplace_release(dip);
  829. out_gunlock_q:
  830. if (da.nr_blocks)
  831. gfs2_quota_unlock(dip);
  832. out_gunlock:
  833. gfs2_dir_no_add(&da);
  834. gfs2_glock_dq(ghs + 1);
  835. out_child:
  836. gfs2_glock_dq(ghs);
  837. out_parent:
  838. gfs2_holder_uninit(ghs);
  839. gfs2_holder_uninit(ghs + 1);
  840. return error;
  841. }
  842. /*
  843. * gfs2_unlink_ok - check to see that a inode is still in a directory
  844. * @dip: the directory
  845. * @name: the name of the file
  846. * @ip: the inode
  847. *
  848. * Assumes that the lock on (at least) @dip is held.
  849. *
  850. * Returns: 0 if the parent/child relationship is correct, errno if it isn't
  851. */
  852. static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
  853. const struct gfs2_inode *ip)
  854. {
  855. int error;
  856. if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
  857. return -EPERM;
  858. if ((dip->i_inode.i_mode & S_ISVTX) &&
  859. !uid_eq(dip->i_inode.i_uid, current_fsuid()) &&
  860. !uid_eq(ip->i_inode.i_uid, current_fsuid()) && !capable(CAP_FOWNER))
  861. return -EPERM;
  862. if (IS_APPEND(&dip->i_inode))
  863. return -EPERM;
  864. error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
  865. if (error)
  866. return error;
  867. error = gfs2_dir_check(&dip->i_inode, name, ip);
  868. if (error)
  869. return error;
  870. return 0;
  871. }
  872. /**
  873. * gfs2_unlink_inode - Removes an inode from its parent dir and unlinks it
  874. * @dip: The parent directory
  875. * @name: The name of the entry in the parent directory
  876. * @inode: The inode to be removed
  877. *
  878. * Called with all the locks and in a transaction. This will only be
  879. * called for a directory after it has been checked to ensure it is empty.
  880. *
  881. * Returns: 0 on success, or an error
  882. */
  883. static int gfs2_unlink_inode(struct gfs2_inode *dip,
  884. const struct dentry *dentry)
  885. {
  886. struct inode *inode = dentry->d_inode;
  887. struct gfs2_inode *ip = GFS2_I(inode);
  888. int error;
  889. error = gfs2_dir_del(dip, dentry);
  890. if (error)
  891. return error;
  892. ip->i_entries = 0;
  893. inode->i_ctime = CURRENT_TIME;
  894. if (S_ISDIR(inode->i_mode))
  895. clear_nlink(inode);
  896. else
  897. drop_nlink(inode);
  898. mark_inode_dirty(inode);
  899. if (inode->i_nlink == 0)
  900. gfs2_unlink_di(inode);
  901. return 0;
  902. }
  903. /**
  904. * gfs2_unlink - Unlink an inode (this does rmdir as well)
  905. * @dir: The inode of the directory containing the inode to unlink
  906. * @dentry: The file itself
  907. *
  908. * This routine uses the type of the inode as a flag to figure out
  909. * whether this is an unlink or an rmdir.
  910. *
  911. * Returns: errno
  912. */
  913. static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
  914. {
  915. struct gfs2_inode *dip = GFS2_I(dir);
  916. struct gfs2_sbd *sdp = GFS2_SB(dir);
  917. struct inode *inode = dentry->d_inode;
  918. struct gfs2_inode *ip = GFS2_I(inode);
  919. struct gfs2_holder ghs[3];
  920. struct gfs2_rgrpd *rgd;
  921. int error;
  922. error = gfs2_rindex_update(sdp);
  923. if (error)
  924. return error;
  925. error = -EROFS;
  926. gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  927. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
  928. rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1);
  929. if (!rgd)
  930. goto out_inodes;
  931. gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
  932. error = gfs2_glock_nq(ghs); /* parent */
  933. if (error)
  934. goto out_parent;
  935. error = gfs2_glock_nq(ghs + 1); /* child */
  936. if (error)
  937. goto out_child;
  938. error = -ENOENT;
  939. if (inode->i_nlink == 0)
  940. goto out_rgrp;
  941. if (S_ISDIR(inode->i_mode)) {
  942. error = -ENOTEMPTY;
  943. if (ip->i_entries > 2 || inode->i_nlink > 2)
  944. goto out_rgrp;
  945. }
  946. error = gfs2_glock_nq(ghs + 2); /* rgrp */
  947. if (error)
  948. goto out_rgrp;
  949. error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
  950. if (error)
  951. goto out_gunlock;
  952. error = gfs2_trans_begin(sdp, 2*RES_DINODE + 3*RES_LEAF + RES_RG_BIT, 0);
  953. if (error)
  954. goto out_end_trans;
  955. error = gfs2_unlink_inode(dip, dentry);
  956. out_end_trans:
  957. gfs2_trans_end(sdp);
  958. out_gunlock:
  959. gfs2_glock_dq(ghs + 2);
  960. out_rgrp:
  961. gfs2_glock_dq(ghs + 1);
  962. out_child:
  963. gfs2_glock_dq(ghs);
  964. out_parent:
  965. gfs2_holder_uninit(ghs + 2);
  966. out_inodes:
  967. gfs2_holder_uninit(ghs + 1);
  968. gfs2_holder_uninit(ghs);
  969. return error;
  970. }
  971. /**
  972. * gfs2_symlink - Create a symlink
  973. * @dir: The directory to create the symlink in
  974. * @dentry: The dentry to put the symlink in
  975. * @symname: The thing which the link points to
  976. *
  977. * Returns: errno
  978. */
  979. static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
  980. const char *symname)
  981. {
  982. struct gfs2_sbd *sdp = GFS2_SB(dir);
  983. unsigned int size;
  984. size = strlen(symname);
  985. if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
  986. return -ENAMETOOLONG;
  987. return gfs2_create_inode(dir, dentry, NULL, S_IFLNK | S_IRWXUGO, 0, symname, size, 0, NULL);
  988. }
  989. /**
  990. * gfs2_mkdir - Make a directory
  991. * @dir: The parent directory of the new one
  992. * @dentry: The dentry of the new directory
  993. * @mode: The mode of the new directory
  994. *
  995. * Returns: errno
  996. */
  997. static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  998. {
  999. struct gfs2_sbd *sdp = GFS2_SB(dir);
  1000. unsigned dsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
  1001. return gfs2_create_inode(dir, dentry, NULL, S_IFDIR | mode, 0, NULL, dsize, 0, NULL);
  1002. }
  1003. /**
  1004. * gfs2_mknod - Make a special file
  1005. * @dir: The directory in which the special file will reside
  1006. * @dentry: The dentry of the special file
  1007. * @mode: The mode of the special file
  1008. * @dev: The device specification of the special file
  1009. *
  1010. */
  1011. static int gfs2_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
  1012. dev_t dev)
  1013. {
  1014. return gfs2_create_inode(dir, dentry, NULL, mode, dev, NULL, 0, 0, NULL);
  1015. }
  1016. /**
  1017. * gfs2_atomic_open - Atomically open a file
  1018. * @dir: The directory
  1019. * @dentry: The proposed new entry
  1020. * @file: The proposed new struct file
  1021. * @flags: open flags
  1022. * @mode: File mode
  1023. * @opened: Flag to say whether the file has been opened or not
  1024. *
  1025. * Returns: error code or 0 for success
  1026. */
  1027. static int gfs2_atomic_open(struct inode *dir, struct dentry *dentry,
  1028. struct file *file, unsigned flags,
  1029. umode_t mode, int *opened)
  1030. {
  1031. struct dentry *d;
  1032. bool excl = !!(flags & O_EXCL);
  1033. d = __gfs2_lookup(dir, dentry, file, opened);
  1034. if (IS_ERR(d))
  1035. return PTR_ERR(d);
  1036. if (d != NULL)
  1037. dentry = d;
  1038. if (dentry->d_inode) {
  1039. if (!(*opened & FILE_OPENED)) {
  1040. if (d == NULL)
  1041. dget(dentry);
  1042. return finish_no_open(file, dentry);
  1043. }
  1044. dput(d);
  1045. return 0;
  1046. }
  1047. BUG_ON(d != NULL);
  1048. if (!(flags & O_CREAT))
  1049. return -ENOENT;
  1050. return gfs2_create_inode(dir, dentry, file, S_IFREG | mode, 0, NULL, 0, excl, opened);
  1051. }
  1052. /*
  1053. * gfs2_ok_to_move - check if it's ok to move a directory to another directory
  1054. * @this: move this
  1055. * @to: to here
  1056. *
  1057. * Follow @to back to the root and make sure we don't encounter @this
  1058. * Assumes we already hold the rename lock.
  1059. *
  1060. * Returns: errno
  1061. */
  1062. static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
  1063. {
  1064. struct inode *dir = &to->i_inode;
  1065. struct super_block *sb = dir->i_sb;
  1066. struct inode *tmp;
  1067. int error = 0;
  1068. igrab(dir);
  1069. for (;;) {
  1070. if (dir == &this->i_inode) {
  1071. error = -EINVAL;
  1072. break;
  1073. }
  1074. if (dir == sb->s_root->d_inode) {
  1075. error = 0;
  1076. break;
  1077. }
  1078. tmp = gfs2_lookupi(dir, &gfs2_qdotdot, 1);
  1079. if (IS_ERR(tmp)) {
  1080. error = PTR_ERR(tmp);
  1081. break;
  1082. }
  1083. iput(dir);
  1084. dir = tmp;
  1085. }
  1086. iput(dir);
  1087. return error;
  1088. }
  1089. /**
  1090. * gfs2_rename - Rename a file
  1091. * @odir: Parent directory of old file name
  1092. * @odentry: The old dentry of the file
  1093. * @ndir: Parent directory of new file name
  1094. * @ndentry: The new dentry of the file
  1095. *
  1096. * Returns: errno
  1097. */
  1098. static int gfs2_rename(struct inode *odir, struct dentry *odentry,
  1099. struct inode *ndir, struct dentry *ndentry)
  1100. {
  1101. struct gfs2_inode *odip = GFS2_I(odir);
  1102. struct gfs2_inode *ndip = GFS2_I(ndir);
  1103. struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
  1104. struct gfs2_inode *nip = NULL;
  1105. struct gfs2_sbd *sdp = GFS2_SB(odir);
  1106. struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, };
  1107. struct gfs2_rgrpd *nrgd;
  1108. unsigned int num_gh;
  1109. int dir_rename = 0;
  1110. struct gfs2_diradd da = { .nr_blocks = 0, };
  1111. unsigned int x;
  1112. int error;
  1113. if (ndentry->d_inode) {
  1114. nip = GFS2_I(ndentry->d_inode);
  1115. if (ip == nip)
  1116. return 0;
  1117. }
  1118. error = gfs2_rindex_update(sdp);
  1119. if (error)
  1120. return error;
  1121. error = gfs2_rs_alloc(ndip);
  1122. if (error)
  1123. return error;
  1124. if (odip != ndip) {
  1125. error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
  1126. 0, &r_gh);
  1127. if (error)
  1128. goto out;
  1129. if (S_ISDIR(ip->i_inode.i_mode)) {
  1130. dir_rename = 1;
  1131. /* don't move a dirctory into it's subdir */
  1132. error = gfs2_ok_to_move(ip, ndip);
  1133. if (error)
  1134. goto out_gunlock_r;
  1135. }
  1136. }
  1137. num_gh = 1;
  1138. gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
  1139. if (odip != ndip) {
  1140. gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
  1141. num_gh++;
  1142. }
  1143. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
  1144. num_gh++;
  1145. if (nip) {
  1146. gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
  1147. num_gh++;
  1148. /* grab the resource lock for unlink flag twiddling
  1149. * this is the case of the target file already existing
  1150. * so we unlink before doing the rename
  1151. */
  1152. nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr, 1);
  1153. if (nrgd)
  1154. gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
  1155. }
  1156. for (x = 0; x < num_gh; x++) {
  1157. error = gfs2_glock_nq(ghs + x);
  1158. if (error)
  1159. goto out_gunlock;
  1160. }
  1161. error = -ENOENT;
  1162. if (ip->i_inode.i_nlink == 0)
  1163. goto out_gunlock;
  1164. /* Check out the old directory */
  1165. error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
  1166. if (error)
  1167. goto out_gunlock;
  1168. /* Check out the new directory */
  1169. if (nip) {
  1170. error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
  1171. if (error)
  1172. goto out_gunlock;
  1173. if (nip->i_inode.i_nlink == 0) {
  1174. error = -EAGAIN;
  1175. goto out_gunlock;
  1176. }
  1177. if (S_ISDIR(nip->i_inode.i_mode)) {
  1178. if (nip->i_entries < 2) {
  1179. gfs2_consist_inode(nip);
  1180. error = -EIO;
  1181. goto out_gunlock;
  1182. }
  1183. if (nip->i_entries > 2) {
  1184. error = -ENOTEMPTY;
  1185. goto out_gunlock;
  1186. }
  1187. }
  1188. } else {
  1189. error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC);
  1190. if (error)
  1191. goto out_gunlock;
  1192. error = gfs2_dir_check(ndir, &ndentry->d_name, NULL);
  1193. switch (error) {
  1194. case -ENOENT:
  1195. error = 0;
  1196. break;
  1197. case 0:
  1198. error = -EEXIST;
  1199. default:
  1200. goto out_gunlock;
  1201. };
  1202. if (odip != ndip) {
  1203. if (!ndip->i_inode.i_nlink) {
  1204. error = -ENOENT;
  1205. goto out_gunlock;
  1206. }
  1207. if (ndip->i_entries == (u32)-1) {
  1208. error = -EFBIG;
  1209. goto out_gunlock;
  1210. }
  1211. if (S_ISDIR(ip->i_inode.i_mode) &&
  1212. ndip->i_inode.i_nlink == (u32)-1) {
  1213. error = -EMLINK;
  1214. goto out_gunlock;
  1215. }
  1216. }
  1217. }
  1218. /* Check out the dir to be renamed */
  1219. if (dir_rename) {
  1220. error = gfs2_permission(odentry->d_inode, MAY_WRITE);
  1221. if (error)
  1222. goto out_gunlock;
  1223. }
  1224. if (nip == NULL) {
  1225. error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name, &da);
  1226. if (error)
  1227. goto out_gunlock;
  1228. }
  1229. if (da.nr_blocks) {
  1230. struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
  1231. error = gfs2_quota_lock_check(ndip);
  1232. if (error)
  1233. goto out_gunlock;
  1234. error = gfs2_inplace_reserve(ndip, &ap);
  1235. if (error)
  1236. goto out_gunlock_q;
  1237. error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(ndip, &da, 4) +
  1238. 4 * RES_LEAF + 4, 0);
  1239. if (error)
  1240. goto out_ipreserv;
  1241. } else {
  1242. error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
  1243. 5 * RES_LEAF + 4, 0);
  1244. if (error)
  1245. goto out_gunlock;
  1246. }
  1247. /* Remove the target file, if it exists */
  1248. if (nip)
  1249. error = gfs2_unlink_inode(ndip, ndentry);
  1250. if (dir_rename) {
  1251. error = gfs2_dir_mvino(ip, &gfs2_qdotdot, ndip, DT_DIR);
  1252. if (error)
  1253. goto out_end_trans;
  1254. } else {
  1255. struct buffer_head *dibh;
  1256. error = gfs2_meta_inode_buffer(ip, &dibh);
  1257. if (error)
  1258. goto out_end_trans;
  1259. ip->i_inode.i_ctime = CURRENT_TIME;
  1260. gfs2_trans_add_meta(ip->i_gl, dibh);
  1261. gfs2_dinode_out(ip, dibh->b_data);
  1262. brelse(dibh);
  1263. }
  1264. error = gfs2_dir_del(odip, odentry);
  1265. if (error)
  1266. goto out_end_trans;
  1267. error = gfs2_dir_add(ndir, &ndentry->d_name, ip, &da);
  1268. if (error)
  1269. goto out_end_trans;
  1270. out_end_trans:
  1271. gfs2_trans_end(sdp);
  1272. out_ipreserv:
  1273. if (da.nr_blocks)
  1274. gfs2_inplace_release(ndip);
  1275. out_gunlock_q:
  1276. if (da.nr_blocks)
  1277. gfs2_quota_unlock(ndip);
  1278. out_gunlock:
  1279. gfs2_dir_no_add(&da);
  1280. while (x--) {
  1281. gfs2_glock_dq(ghs + x);
  1282. gfs2_holder_uninit(ghs + x);
  1283. }
  1284. out_gunlock_r:
  1285. if (r_gh.gh_gl)
  1286. gfs2_glock_dq_uninit(&r_gh);
  1287. out:
  1288. return error;
  1289. }
  1290. /**
  1291. * gfs2_follow_link - Follow a symbolic link
  1292. * @dentry: The dentry of the link
  1293. * @nd: Data that we pass to vfs_follow_link()
  1294. *
  1295. * This can handle symlinks of any size.
  1296. *
  1297. * Returns: 0 on success or error code
  1298. */
  1299. static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
  1300. {
  1301. struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
  1302. struct gfs2_holder i_gh;
  1303. struct buffer_head *dibh;
  1304. unsigned int size;
  1305. char *buf;
  1306. int error;
  1307. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
  1308. error = gfs2_glock_nq(&i_gh);
  1309. if (error) {
  1310. gfs2_holder_uninit(&i_gh);
  1311. nd_set_link(nd, ERR_PTR(error));
  1312. return NULL;
  1313. }
  1314. size = (unsigned int)i_size_read(&ip->i_inode);
  1315. if (size == 0) {
  1316. gfs2_consist_inode(ip);
  1317. buf = ERR_PTR(-EIO);
  1318. goto out;
  1319. }
  1320. error = gfs2_meta_inode_buffer(ip, &dibh);
  1321. if (error) {
  1322. buf = ERR_PTR(error);
  1323. goto out;
  1324. }
  1325. buf = kzalloc(size + 1, GFP_NOFS);
  1326. if (!buf)
  1327. buf = ERR_PTR(-ENOMEM);
  1328. else
  1329. memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), size);
  1330. brelse(dibh);
  1331. out:
  1332. gfs2_glock_dq_uninit(&i_gh);
  1333. nd_set_link(nd, buf);
  1334. return NULL;
  1335. }
  1336. /**
  1337. * gfs2_permission -
  1338. * @inode: The inode
  1339. * @mask: The mask to be tested
  1340. * @flags: Indicates whether this is an RCU path walk or not
  1341. *
  1342. * This may be called from the VFS directly, or from within GFS2 with the
  1343. * inode locked, so we look to see if the glock is already locked and only
  1344. * lock the glock if its not already been done.
  1345. *
  1346. * Returns: errno
  1347. */
  1348. int gfs2_permission(struct inode *inode, int mask)
  1349. {
  1350. struct gfs2_inode *ip;
  1351. struct gfs2_holder i_gh;
  1352. int error;
  1353. int unlock = 0;
  1354. ip = GFS2_I(inode);
  1355. if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
  1356. if (mask & MAY_NOT_BLOCK)
  1357. return -ECHILD;
  1358. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
  1359. if (error)
  1360. return error;
  1361. unlock = 1;
  1362. }
  1363. if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode))
  1364. error = -EACCES;
  1365. else
  1366. error = generic_permission(inode, mask);
  1367. if (unlock)
  1368. gfs2_glock_dq_uninit(&i_gh);
  1369. return error;
  1370. }
  1371. static int __gfs2_setattr_simple(struct inode *inode, struct iattr *attr)
  1372. {
  1373. setattr_copy(inode, attr);
  1374. mark_inode_dirty(inode);
  1375. return 0;
  1376. }
  1377. /**
  1378. * gfs2_setattr_simple -
  1379. * @ip:
  1380. * @attr:
  1381. *
  1382. * Returns: errno
  1383. */
  1384. int gfs2_setattr_simple(struct inode *inode, struct iattr *attr)
  1385. {
  1386. int error;
  1387. if (current->journal_info)
  1388. return __gfs2_setattr_simple(inode, attr);
  1389. error = gfs2_trans_begin(GFS2_SB(inode), RES_DINODE, 0);
  1390. if (error)
  1391. return error;
  1392. error = __gfs2_setattr_simple(inode, attr);
  1393. gfs2_trans_end(GFS2_SB(inode));
  1394. return error;
  1395. }
  1396. static int setattr_chown(struct inode *inode, struct iattr *attr)
  1397. {
  1398. struct gfs2_inode *ip = GFS2_I(inode);
  1399. struct gfs2_sbd *sdp = GFS2_SB(inode);
  1400. kuid_t ouid, nuid;
  1401. kgid_t ogid, ngid;
  1402. int error;
  1403. ouid = inode->i_uid;
  1404. ogid = inode->i_gid;
  1405. nuid = attr->ia_uid;
  1406. ngid = attr->ia_gid;
  1407. if (!(attr->ia_valid & ATTR_UID) || uid_eq(ouid, nuid))
  1408. ouid = nuid = NO_UID_QUOTA_CHANGE;
  1409. if (!(attr->ia_valid & ATTR_GID) || gid_eq(ogid, ngid))
  1410. ogid = ngid = NO_GID_QUOTA_CHANGE;
  1411. error = get_write_access(inode);
  1412. if (error)
  1413. return error;
  1414. error = gfs2_rs_alloc(ip);
  1415. if (error)
  1416. goto out;
  1417. error = gfs2_rindex_update(sdp);
  1418. if (error)
  1419. goto out;
  1420. error = gfs2_quota_lock(ip, nuid, ngid);
  1421. if (error)
  1422. goto out;
  1423. if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
  1424. !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
  1425. error = gfs2_quota_check(ip, nuid, ngid);
  1426. if (error)
  1427. goto out_gunlock_q;
  1428. }
  1429. error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
  1430. if (error)
  1431. goto out_gunlock_q;
  1432. error = gfs2_setattr_simple(inode, attr);
  1433. if (error)
  1434. goto out_end_trans;
  1435. if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
  1436. !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
  1437. u64 blocks = gfs2_get_inode_blocks(&ip->i_inode);
  1438. gfs2_quota_change(ip, -blocks, ouid, ogid);
  1439. gfs2_quota_change(ip, blocks, nuid, ngid);
  1440. }
  1441. out_end_trans:
  1442. gfs2_trans_end(sdp);
  1443. out_gunlock_q:
  1444. gfs2_quota_unlock(ip);
  1445. out:
  1446. put_write_access(inode);
  1447. return error;
  1448. }
  1449. /**
  1450. * gfs2_setattr - Change attributes on an inode
  1451. * @dentry: The dentry which is changing
  1452. * @attr: The structure describing the change
  1453. *
  1454. * The VFS layer wants to change one or more of an inodes attributes. Write
  1455. * that change out to disk.
  1456. *
  1457. * Returns: errno
  1458. */
  1459. static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
  1460. {
  1461. struct inode *inode = dentry->d_inode;
  1462. struct gfs2_inode *ip = GFS2_I(inode);
  1463. struct gfs2_holder i_gh;
  1464. int error;
  1465. error = gfs2_rs_alloc(ip);
  1466. if (error)
  1467. return error;
  1468. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
  1469. if (error)
  1470. return error;
  1471. error = -EPERM;
  1472. if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  1473. goto out;
  1474. error = inode_change_ok(inode, attr);
  1475. if (error)
  1476. goto out;
  1477. if (attr->ia_valid & ATTR_SIZE)
  1478. error = gfs2_setattr_size(inode, attr->ia_size);
  1479. else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
  1480. error = setattr_chown(inode, attr);
  1481. else {
  1482. error = gfs2_setattr_simple(inode, attr);
  1483. if (!error && attr->ia_valid & ATTR_MODE)
  1484. error = posix_acl_chmod(inode, inode->i_mode);
  1485. }
  1486. out:
  1487. if (!error)
  1488. mark_inode_dirty(inode);
  1489. gfs2_glock_dq_uninit(&i_gh);
  1490. return error;
  1491. }
  1492. /**
  1493. * gfs2_getattr - Read out an inode's attributes
  1494. * @mnt: The vfsmount the inode is being accessed from
  1495. * @dentry: The dentry to stat
  1496. * @stat: The inode's stats
  1497. *
  1498. * This may be called from the VFS directly, or from within GFS2 with the
  1499. * inode locked, so we look to see if the glock is already locked and only
  1500. * lock the glock if its not already been done. Note that its the NFS
  1501. * readdirplus operation which causes this to be called (from filldir)
  1502. * with the glock already held.
  1503. *
  1504. * Returns: errno
  1505. */
  1506. static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
  1507. struct kstat *stat)
  1508. {
  1509. struct inode *inode = dentry->d_inode;
  1510. struct gfs2_inode *ip = GFS2_I(inode);
  1511. struct gfs2_holder gh;
  1512. int error;
  1513. int unlock = 0;
  1514. if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
  1515. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
  1516. if (error)
  1517. return error;
  1518. unlock = 1;
  1519. }
  1520. generic_fillattr(inode, stat);
  1521. if (unlock)
  1522. gfs2_glock_dq_uninit(&gh);
  1523. return 0;
  1524. }
  1525. static int gfs2_setxattr(struct dentry *dentry, const char *name,
  1526. const void *data, size_t size, int flags)
  1527. {
  1528. struct inode *inode = dentry->d_inode;
  1529. struct gfs2_inode *ip = GFS2_I(inode);
  1530. struct gfs2_holder gh;
  1531. int ret;
  1532. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  1533. ret = gfs2_glock_nq(&gh);
  1534. if (ret == 0) {
  1535. ret = gfs2_rs_alloc(ip);
  1536. if (ret == 0)
  1537. ret = generic_setxattr(dentry, name, data, size, flags);
  1538. gfs2_glock_dq(&gh);
  1539. }
  1540. gfs2_holder_uninit(&gh);
  1541. return ret;
  1542. }
  1543. static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
  1544. void *data, size_t size)
  1545. {
  1546. struct inode *inode = dentry->d_inode;
  1547. struct gfs2_inode *ip = GFS2_I(inode);
  1548. struct gfs2_holder gh;
  1549. int ret;
  1550. /* For selinux during lookup */
  1551. if (gfs2_glock_is_locked_by_me(ip->i_gl))
  1552. return generic_getxattr(dentry, name, data, size);
  1553. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
  1554. ret = gfs2_glock_nq(&gh);
  1555. if (ret == 0) {
  1556. ret = generic_getxattr(dentry, name, data, size);
  1557. gfs2_glock_dq(&gh);
  1558. }
  1559. gfs2_holder_uninit(&gh);
  1560. return ret;
  1561. }
  1562. static int gfs2_removexattr(struct dentry *dentry, const char *name)
  1563. {
  1564. struct inode *inode = dentry->d_inode;
  1565. struct gfs2_inode *ip = GFS2_I(inode);
  1566. struct gfs2_holder gh;
  1567. int ret;
  1568. gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  1569. ret = gfs2_glock_nq(&gh);
  1570. if (ret == 0) {
  1571. ret = gfs2_rs_alloc(ip);
  1572. if (ret == 0)
  1573. ret = generic_removexattr(dentry, name);
  1574. gfs2_glock_dq(&gh);
  1575. }
  1576. gfs2_holder_uninit(&gh);
  1577. return ret;
  1578. }
  1579. static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  1580. u64 start, u64 len)
  1581. {
  1582. struct gfs2_inode *ip = GFS2_I(inode);
  1583. struct gfs2_holder gh;
  1584. int ret;
  1585. ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
  1586. if (ret)
  1587. return ret;
  1588. mutex_lock(&inode->i_mutex);
  1589. ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
  1590. if (ret)
  1591. goto out;
  1592. if (gfs2_is_stuffed(ip)) {
  1593. u64 phys = ip->i_no_addr << inode->i_blkbits;
  1594. u64 size = i_size_read(inode);
  1595. u32 flags = FIEMAP_EXTENT_LAST|FIEMAP_EXTENT_NOT_ALIGNED|
  1596. FIEMAP_EXTENT_DATA_INLINE;
  1597. phys += sizeof(struct gfs2_dinode);
  1598. phys += start;
  1599. if (start + len > size)
  1600. len = size - start;
  1601. if (start < size)
  1602. ret = fiemap_fill_next_extent(fieinfo, start, phys,
  1603. len, flags);
  1604. if (ret == 1)
  1605. ret = 0;
  1606. } else {
  1607. ret = __generic_block_fiemap(inode, fieinfo, start, len,
  1608. gfs2_block_map);
  1609. }
  1610. gfs2_glock_dq_uninit(&gh);
  1611. out:
  1612. mutex_unlock(&inode->i_mutex);
  1613. return ret;
  1614. }
  1615. const struct inode_operations gfs2_file_iops = {
  1616. .permission = gfs2_permission,
  1617. .setattr = gfs2_setattr,
  1618. .getattr = gfs2_getattr,
  1619. .setxattr = gfs2_setxattr,
  1620. .getxattr = gfs2_getxattr,
  1621. .listxattr = gfs2_listxattr,
  1622. .removexattr = gfs2_removexattr,
  1623. .fiemap = gfs2_fiemap,
  1624. .get_acl = gfs2_get_acl,
  1625. .set_acl = gfs2_set_acl,
  1626. };
  1627. const struct inode_operations gfs2_dir_iops = {
  1628. .create = gfs2_create,
  1629. .lookup = gfs2_lookup,
  1630. .link = gfs2_link,
  1631. .unlink = gfs2_unlink,
  1632. .symlink = gfs2_symlink,
  1633. .mkdir = gfs2_mkdir,
  1634. .rmdir = gfs2_unlink,
  1635. .mknod = gfs2_mknod,
  1636. .rename = gfs2_rename,
  1637. .permission = gfs2_permission,
  1638. .setattr = gfs2_setattr,
  1639. .getattr = gfs2_getattr,
  1640. .setxattr = gfs2_setxattr,
  1641. .getxattr = gfs2_getxattr,
  1642. .listxattr = gfs2_listxattr,
  1643. .removexattr = gfs2_removexattr,
  1644. .fiemap = gfs2_fiemap,
  1645. .get_acl = gfs2_get_acl,
  1646. .set_acl = gfs2_set_acl,
  1647. .atomic_open = gfs2_atomic_open,
  1648. };
  1649. const struct inode_operations gfs2_symlink_iops = {
  1650. .readlink = generic_readlink,
  1651. .follow_link = gfs2_follow_link,
  1652. .put_link = kfree_put_link,
  1653. .permission = gfs2_permission,
  1654. .setattr = gfs2_setattr,
  1655. .getattr = gfs2_getattr,
  1656. .setxattr = gfs2_setxattr,
  1657. .getxattr = gfs2_getxattr,
  1658. .listxattr = gfs2_listxattr,
  1659. .removexattr = gfs2_removexattr,
  1660. .fiemap = gfs2_fiemap,
  1661. };