namei.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * namei.c
  5. *
  6. * Create and rename file, directory, symlinks
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. *
  10. * Portions of this code from linux/fs/ext3/dir.c
  11. *
  12. * Copyright (C) 1992, 1993, 1994, 1995
  13. * Remy Card (card@masi.ibp.fr)
  14. * Laboratoire MASI - Institut Blaise pascal
  15. * Universite Pierre et Marie Curie (Paris VI)
  16. *
  17. * from
  18. *
  19. * linux/fs/minix/dir.c
  20. *
  21. * Copyright (C) 1991, 1992 Linux Torvalds
  22. *
  23. * This program is free software; you can redistribute it and/or
  24. * modify it under the terms of the GNU General Public
  25. * License as published by the Free Software Foundation; either
  26. * version 2 of the License, or (at your option) any later version.
  27. *
  28. * This program is distributed in the hope that it will be useful,
  29. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. * General Public License for more details.
  32. *
  33. * You should have received a copy of the GNU General Public
  34. * License along with this program; if not, write to the
  35. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  36. * Boston, MA 021110-1307, USA.
  37. */
  38. #include <linux/fs.h>
  39. #include <linux/types.h>
  40. #include <linux/slab.h>
  41. #include <linux/highmem.h>
  42. #define MLOG_MASK_PREFIX ML_NAMEI
  43. #include <cluster/masklog.h>
  44. #include "ocfs2.h"
  45. #include "alloc.h"
  46. #include "dcache.h"
  47. #include "dir.h"
  48. #include "dlmglue.h"
  49. #include "extent_map.h"
  50. #include "file.h"
  51. #include "inode.h"
  52. #include "journal.h"
  53. #include "namei.h"
  54. #include "suballoc.h"
  55. #include "super.h"
  56. #include "symlink.h"
  57. #include "sysfile.h"
  58. #include "uptodate.h"
  59. #include "buffer_head_io.h"
  60. static int ocfs2_mknod_locked(struct ocfs2_super *osb,
  61. struct inode *dir,
  62. struct dentry *dentry, int mode,
  63. dev_t dev,
  64. struct buffer_head **new_fe_bh,
  65. struct buffer_head *parent_fe_bh,
  66. handle_t *handle,
  67. struct inode **ret_inode,
  68. struct ocfs2_alloc_context *inode_ac);
  69. static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
  70. struct inode **ret_orphan_dir,
  71. struct inode *inode,
  72. char *name,
  73. struct buffer_head **de_bh);
  74. static int ocfs2_orphan_add(struct ocfs2_super *osb,
  75. handle_t *handle,
  76. struct inode *inode,
  77. struct ocfs2_dinode *fe,
  78. char *name,
  79. struct buffer_head *de_bh,
  80. struct inode *orphan_dir_inode);
  81. static int ocfs2_create_symlink_data(struct ocfs2_super *osb,
  82. handle_t *handle,
  83. struct inode *inode,
  84. const char *symname);
  85. /* An orphan dir name is an 8 byte value, printed as a hex string */
  86. #define OCFS2_ORPHAN_NAMELEN ((int)(2 * sizeof(u64)))
  87. static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry,
  88. struct nameidata *nd)
  89. {
  90. int status;
  91. u64 blkno;
  92. struct inode *inode = NULL;
  93. struct dentry *ret;
  94. struct ocfs2_inode_info *oi;
  95. mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry,
  96. dentry->d_name.len, dentry->d_name.name);
  97. if (dentry->d_name.len > OCFS2_MAX_FILENAME_LEN) {
  98. ret = ERR_PTR(-ENAMETOOLONG);
  99. goto bail;
  100. }
  101. mlog(0, "find name %.*s in directory %llu\n", dentry->d_name.len,
  102. dentry->d_name.name, (unsigned long long)OCFS2_I(dir)->ip_blkno);
  103. status = ocfs2_inode_lock(dir, NULL, 0);
  104. if (status < 0) {
  105. if (status != -ENOENT)
  106. mlog_errno(status);
  107. ret = ERR_PTR(status);
  108. goto bail;
  109. }
  110. status = ocfs2_lookup_ino_from_name(dir, dentry->d_name.name,
  111. dentry->d_name.len, &blkno);
  112. if (status < 0)
  113. goto bail_add;
  114. inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0);
  115. if (IS_ERR(inode)) {
  116. ret = ERR_PTR(-EACCES);
  117. goto bail_unlock;
  118. }
  119. oi = OCFS2_I(inode);
  120. /* Clear any orphaned state... If we were able to look up the
  121. * inode from a directory, it certainly can't be orphaned. We
  122. * might have the bad state from a node which intended to
  123. * orphan this inode but crashed before it could commit the
  124. * unlink. */
  125. spin_lock(&oi->ip_lock);
  126. oi->ip_flags &= ~OCFS2_INODE_MAYBE_ORPHANED;
  127. spin_unlock(&oi->ip_lock);
  128. bail_add:
  129. dentry->d_op = &ocfs2_dentry_ops;
  130. ret = d_splice_alias(inode, dentry);
  131. if (inode) {
  132. /*
  133. * If d_splice_alias() finds a DCACHE_DISCONNECTED
  134. * dentry, it will d_move() it on top of ourse. The
  135. * return value will indicate this however, so in
  136. * those cases, we switch them around for the locking
  137. * code.
  138. *
  139. * NOTE: This dentry already has ->d_op set from
  140. * ocfs2_get_parent() and ocfs2_get_dentry()
  141. */
  142. if (ret)
  143. dentry = ret;
  144. status = ocfs2_dentry_attach_lock(dentry, inode,
  145. OCFS2_I(dir)->ip_blkno);
  146. if (status) {
  147. mlog_errno(status);
  148. ret = ERR_PTR(status);
  149. goto bail_unlock;
  150. }
  151. }
  152. bail_unlock:
  153. /* Don't drop the cluster lock until *after* the d_add --
  154. * unlink on another node will message us to remove that
  155. * dentry under this lock so otherwise we can race this with
  156. * the downconvert thread and have a stale dentry. */
  157. ocfs2_inode_unlock(dir, 0);
  158. bail:
  159. mlog_exit_ptr(ret);
  160. return ret;
  161. }
  162. static int ocfs2_mknod(struct inode *dir,
  163. struct dentry *dentry,
  164. int mode,
  165. dev_t dev)
  166. {
  167. int status = 0;
  168. struct buffer_head *parent_fe_bh = NULL;
  169. handle_t *handle = NULL;
  170. struct ocfs2_super *osb;
  171. struct ocfs2_dinode *dirfe;
  172. struct buffer_head *new_fe_bh = NULL;
  173. struct buffer_head *de_bh = NULL;
  174. struct inode *inode = NULL;
  175. struct ocfs2_alloc_context *inode_ac = NULL;
  176. struct ocfs2_alloc_context *data_ac = NULL;
  177. mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
  178. (unsigned long)dev, dentry->d_name.len,
  179. dentry->d_name.name);
  180. /* get our super block */
  181. osb = OCFS2_SB(dir->i_sb);
  182. status = ocfs2_inode_lock(dir, &parent_fe_bh, 1);
  183. if (status < 0) {
  184. if (status != -ENOENT)
  185. mlog_errno(status);
  186. return status;
  187. }
  188. if (S_ISDIR(mode) && (dir->i_nlink >= OCFS2_LINK_MAX)) {
  189. status = -EMLINK;
  190. goto leave;
  191. }
  192. dirfe = (struct ocfs2_dinode *) parent_fe_bh->b_data;
  193. if (!dirfe->i_links_count) {
  194. /* can't make a file in a deleted directory. */
  195. status = -ENOENT;
  196. goto leave;
  197. }
  198. status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
  199. dentry->d_name.len);
  200. if (status)
  201. goto leave;
  202. /* get a spot inside the dir. */
  203. status = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,
  204. dentry->d_name.name,
  205. dentry->d_name.len, &de_bh);
  206. if (status < 0) {
  207. mlog_errno(status);
  208. goto leave;
  209. }
  210. /* reserve an inode spot */
  211. status = ocfs2_reserve_new_inode(osb, &inode_ac);
  212. if (status < 0) {
  213. if (status != -ENOSPC)
  214. mlog_errno(status);
  215. goto leave;
  216. }
  217. /* Reserve a cluster if creating an extent based directory. */
  218. if (S_ISDIR(mode) && !ocfs2_supports_inline_data(osb)) {
  219. status = ocfs2_reserve_clusters(osb, 1, &data_ac);
  220. if (status < 0) {
  221. if (status != -ENOSPC)
  222. mlog_errno(status);
  223. goto leave;
  224. }
  225. }
  226. handle = ocfs2_start_trans(osb, OCFS2_MKNOD_CREDITS);
  227. if (IS_ERR(handle)) {
  228. status = PTR_ERR(handle);
  229. handle = NULL;
  230. mlog_errno(status);
  231. goto leave;
  232. }
  233. /* do the real work now. */
  234. status = ocfs2_mknod_locked(osb, dir, dentry, mode, dev,
  235. &new_fe_bh, parent_fe_bh, handle,
  236. &inode, inode_ac);
  237. if (status < 0) {
  238. mlog_errno(status);
  239. goto leave;
  240. }
  241. if (S_ISDIR(mode)) {
  242. status = ocfs2_fill_new_dir(osb, handle, dir, inode,
  243. new_fe_bh, data_ac);
  244. if (status < 0) {
  245. mlog_errno(status);
  246. goto leave;
  247. }
  248. status = ocfs2_journal_access(handle, dir, parent_fe_bh,
  249. OCFS2_JOURNAL_ACCESS_WRITE);
  250. if (status < 0) {
  251. mlog_errno(status);
  252. goto leave;
  253. }
  254. le16_add_cpu(&dirfe->i_links_count, 1);
  255. status = ocfs2_journal_dirty(handle, parent_fe_bh);
  256. if (status < 0) {
  257. mlog_errno(status);
  258. goto leave;
  259. }
  260. inc_nlink(dir);
  261. }
  262. status = ocfs2_add_entry(handle, dentry, inode,
  263. OCFS2_I(inode)->ip_blkno, parent_fe_bh,
  264. de_bh);
  265. if (status < 0) {
  266. mlog_errno(status);
  267. goto leave;
  268. }
  269. status = ocfs2_dentry_attach_lock(dentry, inode,
  270. OCFS2_I(dir)->ip_blkno);
  271. if (status) {
  272. mlog_errno(status);
  273. goto leave;
  274. }
  275. insert_inode_hash(inode);
  276. dentry->d_op = &ocfs2_dentry_ops;
  277. d_instantiate(dentry, inode);
  278. status = 0;
  279. leave:
  280. if (handle)
  281. ocfs2_commit_trans(osb, handle);
  282. ocfs2_inode_unlock(dir, 1);
  283. if (status == -ENOSPC)
  284. mlog(0, "Disk is full\n");
  285. if (new_fe_bh)
  286. brelse(new_fe_bh);
  287. if (de_bh)
  288. brelse(de_bh);
  289. if (parent_fe_bh)
  290. brelse(parent_fe_bh);
  291. if ((status < 0) && inode)
  292. iput(inode);
  293. if (inode_ac)
  294. ocfs2_free_alloc_context(inode_ac);
  295. if (data_ac)
  296. ocfs2_free_alloc_context(data_ac);
  297. mlog_exit(status);
  298. return status;
  299. }
  300. static int ocfs2_mknod_locked(struct ocfs2_super *osb,
  301. struct inode *dir,
  302. struct dentry *dentry, int mode,
  303. dev_t dev,
  304. struct buffer_head **new_fe_bh,
  305. struct buffer_head *parent_fe_bh,
  306. handle_t *handle,
  307. struct inode **ret_inode,
  308. struct ocfs2_alloc_context *inode_ac)
  309. {
  310. int status = 0;
  311. struct ocfs2_dinode *fe = NULL;
  312. struct ocfs2_extent_list *fel;
  313. u64 fe_blkno = 0;
  314. u16 suballoc_bit;
  315. struct inode *inode = NULL;
  316. mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
  317. (unsigned long)dev, dentry->d_name.len,
  318. dentry->d_name.name);
  319. *new_fe_bh = NULL;
  320. *ret_inode = NULL;
  321. status = ocfs2_claim_new_inode(osb, handle, inode_ac, &suballoc_bit,
  322. &fe_blkno);
  323. if (status < 0) {
  324. mlog_errno(status);
  325. goto leave;
  326. }
  327. inode = new_inode(dir->i_sb);
  328. if (IS_ERR(inode)) {
  329. status = PTR_ERR(inode);
  330. mlog(ML_ERROR, "new_inode failed!\n");
  331. goto leave;
  332. }
  333. /* populate as many fields early on as possible - many of
  334. * these are used by the support functions here and in
  335. * callers. */
  336. inode->i_ino = ino_from_blkno(osb->sb, fe_blkno);
  337. OCFS2_I(inode)->ip_blkno = fe_blkno;
  338. if (S_ISDIR(mode))
  339. inode->i_nlink = 2;
  340. else
  341. inode->i_nlink = 1;
  342. inode->i_mode = mode;
  343. spin_lock(&osb->osb_lock);
  344. inode->i_generation = osb->s_next_generation++;
  345. spin_unlock(&osb->osb_lock);
  346. *new_fe_bh = sb_getblk(osb->sb, fe_blkno);
  347. if (!*new_fe_bh) {
  348. status = -EIO;
  349. mlog_errno(status);
  350. goto leave;
  351. }
  352. ocfs2_set_new_buffer_uptodate(inode, *new_fe_bh);
  353. status = ocfs2_journal_access(handle, inode, *new_fe_bh,
  354. OCFS2_JOURNAL_ACCESS_CREATE);
  355. if (status < 0) {
  356. mlog_errno(status);
  357. goto leave;
  358. }
  359. fe = (struct ocfs2_dinode *) (*new_fe_bh)->b_data;
  360. memset(fe, 0, osb->sb->s_blocksize);
  361. fe->i_generation = cpu_to_le32(inode->i_generation);
  362. fe->i_fs_generation = cpu_to_le32(osb->fs_generation);
  363. fe->i_blkno = cpu_to_le64(fe_blkno);
  364. fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
  365. fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
  366. fe->i_uid = cpu_to_le32(current->fsuid);
  367. if (dir->i_mode & S_ISGID) {
  368. fe->i_gid = cpu_to_le32(dir->i_gid);
  369. if (S_ISDIR(mode))
  370. mode |= S_ISGID;
  371. } else
  372. fe->i_gid = cpu_to_le32(current->fsgid);
  373. fe->i_mode = cpu_to_le16(mode);
  374. if (S_ISCHR(mode) || S_ISBLK(mode))
  375. fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
  376. fe->i_links_count = cpu_to_le16(inode->i_nlink);
  377. fe->i_last_eb_blk = 0;
  378. strcpy(fe->i_signature, OCFS2_INODE_SIGNATURE);
  379. le32_add_cpu(&fe->i_flags, OCFS2_VALID_FL);
  380. fe->i_atime = fe->i_ctime = fe->i_mtime =
  381. cpu_to_le64(CURRENT_TIME.tv_sec);
  382. fe->i_mtime_nsec = fe->i_ctime_nsec = fe->i_atime_nsec =
  383. cpu_to_le32(CURRENT_TIME.tv_nsec);
  384. fe->i_dtime = 0;
  385. /*
  386. * If supported, directories start with inline data.
  387. */
  388. if (S_ISDIR(mode) && ocfs2_supports_inline_data(osb)) {
  389. u16 feat = le16_to_cpu(fe->i_dyn_features);
  390. fe->i_dyn_features = cpu_to_le16(feat | OCFS2_INLINE_DATA_FL);
  391. fe->id2.i_data.id_count = cpu_to_le16(ocfs2_max_inline_data(osb->sb));
  392. } else {
  393. fel = &fe->id2.i_list;
  394. fel->l_tree_depth = 0;
  395. fel->l_next_free_rec = 0;
  396. fel->l_count = cpu_to_le16(ocfs2_extent_recs_per_inode(osb->sb));
  397. }
  398. status = ocfs2_journal_dirty(handle, *new_fe_bh);
  399. if (status < 0) {
  400. mlog_errno(status);
  401. goto leave;
  402. }
  403. if (ocfs2_populate_inode(inode, fe, 1) < 0) {
  404. mlog(ML_ERROR, "populate inode failed! bh->b_blocknr=%llu, "
  405. "i_blkno=%llu, i_ino=%lu\n",
  406. (unsigned long long)(*new_fe_bh)->b_blocknr,
  407. (unsigned long long)le64_to_cpu(fe->i_blkno),
  408. inode->i_ino);
  409. BUG();
  410. }
  411. ocfs2_inode_set_new(osb, inode);
  412. if (!ocfs2_mount_local(osb)) {
  413. status = ocfs2_create_new_inode_locks(inode);
  414. if (status < 0)
  415. mlog_errno(status);
  416. }
  417. status = 0; /* error in ocfs2_create_new_inode_locks is not
  418. * critical */
  419. *ret_inode = inode;
  420. leave:
  421. if (status < 0) {
  422. if (*new_fe_bh) {
  423. brelse(*new_fe_bh);
  424. *new_fe_bh = NULL;
  425. }
  426. if (inode)
  427. iput(inode);
  428. }
  429. mlog_exit(status);
  430. return status;
  431. }
  432. static int ocfs2_mkdir(struct inode *dir,
  433. struct dentry *dentry,
  434. int mode)
  435. {
  436. int ret;
  437. mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, mode,
  438. dentry->d_name.len, dentry->d_name.name);
  439. ret = ocfs2_mknod(dir, dentry, mode | S_IFDIR, 0);
  440. mlog_exit(ret);
  441. return ret;
  442. }
  443. static int ocfs2_create(struct inode *dir,
  444. struct dentry *dentry,
  445. int mode,
  446. struct nameidata *nd)
  447. {
  448. int ret;
  449. mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, mode,
  450. dentry->d_name.len, dentry->d_name.name);
  451. ret = ocfs2_mknod(dir, dentry, mode | S_IFREG, 0);
  452. mlog_exit(ret);
  453. return ret;
  454. }
  455. static int ocfs2_link(struct dentry *old_dentry,
  456. struct inode *dir,
  457. struct dentry *dentry)
  458. {
  459. handle_t *handle;
  460. struct inode *inode = old_dentry->d_inode;
  461. int err;
  462. struct buffer_head *fe_bh = NULL;
  463. struct buffer_head *parent_fe_bh = NULL;
  464. struct buffer_head *de_bh = NULL;
  465. struct ocfs2_dinode *fe = NULL;
  466. struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
  467. mlog_entry("(inode=%lu, old='%.*s' new='%.*s')\n", inode->i_ino,
  468. old_dentry->d_name.len, old_dentry->d_name.name,
  469. dentry->d_name.len, dentry->d_name.name);
  470. if (S_ISDIR(inode->i_mode))
  471. return -EPERM;
  472. err = ocfs2_inode_lock(dir, &parent_fe_bh, 1);
  473. if (err < 0) {
  474. if (err != -ENOENT)
  475. mlog_errno(err);
  476. return err;
  477. }
  478. if (!dir->i_nlink) {
  479. err = -ENOENT;
  480. goto out;
  481. }
  482. err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
  483. dentry->d_name.len);
  484. if (err)
  485. goto out;
  486. err = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,
  487. dentry->d_name.name,
  488. dentry->d_name.len, &de_bh);
  489. if (err < 0) {
  490. mlog_errno(err);
  491. goto out;
  492. }
  493. err = ocfs2_inode_lock(inode, &fe_bh, 1);
  494. if (err < 0) {
  495. if (err != -ENOENT)
  496. mlog_errno(err);
  497. goto out;
  498. }
  499. fe = (struct ocfs2_dinode *) fe_bh->b_data;
  500. if (le16_to_cpu(fe->i_links_count) >= OCFS2_LINK_MAX) {
  501. err = -EMLINK;
  502. goto out_unlock_inode;
  503. }
  504. handle = ocfs2_start_trans(osb, OCFS2_LINK_CREDITS);
  505. if (IS_ERR(handle)) {
  506. err = PTR_ERR(handle);
  507. handle = NULL;
  508. mlog_errno(err);
  509. goto out_unlock_inode;
  510. }
  511. err = ocfs2_journal_access(handle, inode, fe_bh,
  512. OCFS2_JOURNAL_ACCESS_WRITE);
  513. if (err < 0) {
  514. mlog_errno(err);
  515. goto out_commit;
  516. }
  517. inc_nlink(inode);
  518. inode->i_ctime = CURRENT_TIME;
  519. fe->i_links_count = cpu_to_le16(inode->i_nlink);
  520. fe->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);
  521. fe->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
  522. err = ocfs2_journal_dirty(handle, fe_bh);
  523. if (err < 0) {
  524. le16_add_cpu(&fe->i_links_count, -1);
  525. drop_nlink(inode);
  526. mlog_errno(err);
  527. goto out_commit;
  528. }
  529. err = ocfs2_add_entry(handle, dentry, inode,
  530. OCFS2_I(inode)->ip_blkno,
  531. parent_fe_bh, de_bh);
  532. if (err) {
  533. le16_add_cpu(&fe->i_links_count, -1);
  534. drop_nlink(inode);
  535. mlog_errno(err);
  536. goto out_commit;
  537. }
  538. err = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(dir)->ip_blkno);
  539. if (err) {
  540. mlog_errno(err);
  541. goto out_commit;
  542. }
  543. atomic_inc(&inode->i_count);
  544. dentry->d_op = &ocfs2_dentry_ops;
  545. d_instantiate(dentry, inode);
  546. out_commit:
  547. ocfs2_commit_trans(osb, handle);
  548. out_unlock_inode:
  549. ocfs2_inode_unlock(inode, 1);
  550. out:
  551. ocfs2_inode_unlock(dir, 1);
  552. if (de_bh)
  553. brelse(de_bh);
  554. if (fe_bh)
  555. brelse(fe_bh);
  556. if (parent_fe_bh)
  557. brelse(parent_fe_bh);
  558. mlog_exit(err);
  559. return err;
  560. }
  561. /*
  562. * Takes and drops an exclusive lock on the given dentry. This will
  563. * force other nodes to drop it.
  564. */
  565. static int ocfs2_remote_dentry_delete(struct dentry *dentry)
  566. {
  567. int ret;
  568. ret = ocfs2_dentry_lock(dentry, 1);
  569. if (ret)
  570. mlog_errno(ret);
  571. else
  572. ocfs2_dentry_unlock(dentry, 1);
  573. return ret;
  574. }
  575. static inline int inode_is_unlinkable(struct inode *inode)
  576. {
  577. if (S_ISDIR(inode->i_mode)) {
  578. if (inode->i_nlink == 2)
  579. return 1;
  580. return 0;
  581. }
  582. if (inode->i_nlink == 1)
  583. return 1;
  584. return 0;
  585. }
  586. static int ocfs2_unlink(struct inode *dir,
  587. struct dentry *dentry)
  588. {
  589. int status;
  590. int child_locked = 0;
  591. struct inode *inode = dentry->d_inode;
  592. struct inode *orphan_dir = NULL;
  593. struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
  594. u64 blkno;
  595. struct ocfs2_dinode *fe = NULL;
  596. struct buffer_head *fe_bh = NULL;
  597. struct buffer_head *parent_node_bh = NULL;
  598. handle_t *handle = NULL;
  599. struct ocfs2_dir_entry *dirent = NULL;
  600. struct buffer_head *dirent_bh = NULL;
  601. char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
  602. struct buffer_head *orphan_entry_bh = NULL;
  603. mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry,
  604. dentry->d_name.len, dentry->d_name.name);
  605. BUG_ON(dentry->d_parent->d_inode != dir);
  606. mlog(0, "ino = %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno);
  607. if (inode == osb->root_inode) {
  608. mlog(0, "Cannot delete the root directory\n");
  609. return -EPERM;
  610. }
  611. status = ocfs2_inode_lock(dir, &parent_node_bh, 1);
  612. if (status < 0) {
  613. if (status != -ENOENT)
  614. mlog_errno(status);
  615. return status;
  616. }
  617. status = ocfs2_find_files_on_disk(dentry->d_name.name,
  618. dentry->d_name.len, &blkno,
  619. dir, &dirent_bh, &dirent);
  620. if (status < 0) {
  621. if (status != -ENOENT)
  622. mlog_errno(status);
  623. goto leave;
  624. }
  625. if (OCFS2_I(inode)->ip_blkno != blkno) {
  626. status = -ENOENT;
  627. mlog(0, "ip_blkno %llu != dirent blkno %llu ip_flags = %x\n",
  628. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  629. (unsigned long long)blkno, OCFS2_I(inode)->ip_flags);
  630. goto leave;
  631. }
  632. status = ocfs2_inode_lock(inode, &fe_bh, 1);
  633. if (status < 0) {
  634. if (status != -ENOENT)
  635. mlog_errno(status);
  636. goto leave;
  637. }
  638. child_locked = 1;
  639. if (S_ISDIR(inode->i_mode)) {
  640. if (!ocfs2_empty_dir(inode)) {
  641. status = -ENOTEMPTY;
  642. goto leave;
  643. } else if (inode->i_nlink != 2) {
  644. status = -ENOTEMPTY;
  645. goto leave;
  646. }
  647. }
  648. status = ocfs2_remote_dentry_delete(dentry);
  649. if (status < 0) {
  650. /* This remote delete should succeed under all normal
  651. * circumstances. */
  652. mlog_errno(status);
  653. goto leave;
  654. }
  655. if (inode_is_unlinkable(inode)) {
  656. status = ocfs2_prepare_orphan_dir(osb, &orphan_dir, inode,
  657. orphan_name,
  658. &orphan_entry_bh);
  659. if (status < 0) {
  660. mlog_errno(status);
  661. goto leave;
  662. }
  663. }
  664. handle = ocfs2_start_trans(osb, OCFS2_UNLINK_CREDITS);
  665. if (IS_ERR(handle)) {
  666. status = PTR_ERR(handle);
  667. handle = NULL;
  668. mlog_errno(status);
  669. goto leave;
  670. }
  671. status = ocfs2_journal_access(handle, inode, fe_bh,
  672. OCFS2_JOURNAL_ACCESS_WRITE);
  673. if (status < 0) {
  674. mlog_errno(status);
  675. goto leave;
  676. }
  677. fe = (struct ocfs2_dinode *) fe_bh->b_data;
  678. if (inode_is_unlinkable(inode)) {
  679. status = ocfs2_orphan_add(osb, handle, inode, fe, orphan_name,
  680. orphan_entry_bh, orphan_dir);
  681. if (status < 0) {
  682. mlog_errno(status);
  683. goto leave;
  684. }
  685. }
  686. /* delete the name from the parent dir */
  687. status = ocfs2_delete_entry(handle, dir, dirent, dirent_bh);
  688. if (status < 0) {
  689. mlog_errno(status);
  690. goto leave;
  691. }
  692. if (S_ISDIR(inode->i_mode))
  693. drop_nlink(inode);
  694. drop_nlink(inode);
  695. fe->i_links_count = cpu_to_le16(inode->i_nlink);
  696. status = ocfs2_journal_dirty(handle, fe_bh);
  697. if (status < 0) {
  698. mlog_errno(status);
  699. goto leave;
  700. }
  701. dir->i_ctime = dir->i_mtime = CURRENT_TIME;
  702. if (S_ISDIR(inode->i_mode))
  703. drop_nlink(dir);
  704. status = ocfs2_mark_inode_dirty(handle, dir, parent_node_bh);
  705. if (status < 0) {
  706. mlog_errno(status);
  707. if (S_ISDIR(inode->i_mode))
  708. inc_nlink(dir);
  709. }
  710. leave:
  711. if (handle)
  712. ocfs2_commit_trans(osb, handle);
  713. if (child_locked)
  714. ocfs2_inode_unlock(inode, 1);
  715. ocfs2_inode_unlock(dir, 1);
  716. if (orphan_dir) {
  717. /* This was locked for us in ocfs2_prepare_orphan_dir() */
  718. ocfs2_inode_unlock(orphan_dir, 1);
  719. mutex_unlock(&orphan_dir->i_mutex);
  720. iput(orphan_dir);
  721. }
  722. if (fe_bh)
  723. brelse(fe_bh);
  724. if (dirent_bh)
  725. brelse(dirent_bh);
  726. if (parent_node_bh)
  727. brelse(parent_node_bh);
  728. if (orphan_entry_bh)
  729. brelse(orphan_entry_bh);
  730. mlog_exit(status);
  731. return status;
  732. }
  733. /*
  734. * The only place this should be used is rename!
  735. * if they have the same id, then the 1st one is the only one locked.
  736. */
  737. static int ocfs2_double_lock(struct ocfs2_super *osb,
  738. struct buffer_head **bh1,
  739. struct inode *inode1,
  740. struct buffer_head **bh2,
  741. struct inode *inode2)
  742. {
  743. int status;
  744. struct ocfs2_inode_info *oi1 = OCFS2_I(inode1);
  745. struct ocfs2_inode_info *oi2 = OCFS2_I(inode2);
  746. struct buffer_head **tmpbh;
  747. struct inode *tmpinode;
  748. mlog_entry("(inode1 = %llu, inode2 = %llu)\n",
  749. (unsigned long long)oi1->ip_blkno,
  750. (unsigned long long)oi2->ip_blkno);
  751. if (*bh1)
  752. *bh1 = NULL;
  753. if (*bh2)
  754. *bh2 = NULL;
  755. /* we always want to lock the one with the lower lockid first. */
  756. if (oi1->ip_blkno != oi2->ip_blkno) {
  757. if (oi1->ip_blkno < oi2->ip_blkno) {
  758. /* switch id1 and id2 around */
  759. mlog(0, "switching them around...\n");
  760. tmpbh = bh2;
  761. bh2 = bh1;
  762. bh1 = tmpbh;
  763. tmpinode = inode2;
  764. inode2 = inode1;
  765. inode1 = tmpinode;
  766. }
  767. /* lock id2 */
  768. status = ocfs2_inode_lock(inode2, bh2, 1);
  769. if (status < 0) {
  770. if (status != -ENOENT)
  771. mlog_errno(status);
  772. goto bail;
  773. }
  774. }
  775. /* lock id1 */
  776. status = ocfs2_inode_lock(inode1, bh1, 1);
  777. if (status < 0) {
  778. /*
  779. * An error return must mean that no cluster locks
  780. * were held on function exit.
  781. */
  782. if (oi1->ip_blkno != oi2->ip_blkno)
  783. ocfs2_inode_unlock(inode2, 1);
  784. if (status != -ENOENT)
  785. mlog_errno(status);
  786. }
  787. bail:
  788. mlog_exit(status);
  789. return status;
  790. }
  791. static void ocfs2_double_unlock(struct inode *inode1, struct inode *inode2)
  792. {
  793. ocfs2_inode_unlock(inode1, 1);
  794. if (inode1 != inode2)
  795. ocfs2_inode_unlock(inode2, 1);
  796. }
  797. static int ocfs2_rename(struct inode *old_dir,
  798. struct dentry *old_dentry,
  799. struct inode *new_dir,
  800. struct dentry *new_dentry)
  801. {
  802. int status = 0, rename_lock = 0, parents_locked = 0;
  803. int old_child_locked = 0, new_child_locked = 0;
  804. struct inode *old_inode = old_dentry->d_inode;
  805. struct inode *new_inode = new_dentry->d_inode;
  806. struct inode *orphan_dir = NULL;
  807. struct ocfs2_dinode *newfe = NULL;
  808. char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
  809. struct buffer_head *orphan_entry_bh = NULL;
  810. struct buffer_head *newfe_bh = NULL;
  811. struct buffer_head *old_inode_bh = NULL;
  812. struct buffer_head *insert_entry_bh = NULL;
  813. struct ocfs2_super *osb = NULL;
  814. u64 newfe_blkno, old_de_ino;
  815. handle_t *handle = NULL;
  816. struct buffer_head *old_dir_bh = NULL;
  817. struct buffer_head *new_dir_bh = NULL;
  818. struct ocfs2_dir_entry *old_inode_dot_dot_de = NULL, *old_de = NULL,
  819. *new_de = NULL;
  820. struct buffer_head *new_de_bh = NULL, *old_de_bh = NULL; // bhs for above
  821. struct buffer_head *old_inode_de_bh = NULL; // if old_dentry is a dir,
  822. // this is the 1st dirent bh
  823. nlink_t old_dir_nlink = old_dir->i_nlink;
  824. struct ocfs2_dinode *old_di;
  825. /* At some point it might be nice to break this function up a
  826. * bit. */
  827. mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p, from='%.*s' to='%.*s')\n",
  828. old_dir, old_dentry, new_dir, new_dentry,
  829. old_dentry->d_name.len, old_dentry->d_name.name,
  830. new_dentry->d_name.len, new_dentry->d_name.name);
  831. osb = OCFS2_SB(old_dir->i_sb);
  832. if (new_inode) {
  833. if (!igrab(new_inode))
  834. BUG();
  835. }
  836. /* Assume a directory hierarchy thusly:
  837. * a/b/c
  838. * a/d
  839. * a,b,c, and d are all directories.
  840. *
  841. * from cwd of 'a' on both nodes:
  842. * node1: mv b/c d
  843. * node2: mv d b/c
  844. *
  845. * And that's why, just like the VFS, we need a file system
  846. * rename lock. */
  847. if (old_dentry != new_dentry) {
  848. status = ocfs2_rename_lock(osb);
  849. if (status < 0) {
  850. mlog_errno(status);
  851. goto bail;
  852. }
  853. rename_lock = 1;
  854. }
  855. /* if old and new are the same, this'll just do one lock. */
  856. status = ocfs2_double_lock(osb, &old_dir_bh, old_dir,
  857. &new_dir_bh, new_dir);
  858. if (status < 0) {
  859. mlog_errno(status);
  860. goto bail;
  861. }
  862. parents_locked = 1;
  863. /* make sure both dirs have bhs
  864. * get an extra ref on old_dir_bh if old==new */
  865. if (!new_dir_bh) {
  866. if (old_dir_bh) {
  867. new_dir_bh = old_dir_bh;
  868. get_bh(new_dir_bh);
  869. } else {
  870. mlog(ML_ERROR, "no old_dir_bh!\n");
  871. status = -EIO;
  872. goto bail;
  873. }
  874. }
  875. /*
  876. * Aside from allowing a meta data update, the locking here
  877. * also ensures that the downconvert thread on other nodes
  878. * won't have to concurrently downconvert the inode and the
  879. * dentry locks.
  880. */
  881. status = ocfs2_inode_lock(old_inode, &old_inode_bh, 1);
  882. if (status < 0) {
  883. if (status != -ENOENT)
  884. mlog_errno(status);
  885. goto bail;
  886. }
  887. old_child_locked = 1;
  888. status = ocfs2_remote_dentry_delete(old_dentry);
  889. if (status < 0) {
  890. mlog_errno(status);
  891. goto bail;
  892. }
  893. if (S_ISDIR(old_inode->i_mode)) {
  894. u64 old_inode_parent;
  895. status = ocfs2_find_files_on_disk("..", 2, &old_inode_parent,
  896. old_inode, &old_inode_de_bh,
  897. &old_inode_dot_dot_de);
  898. if (status) {
  899. status = -EIO;
  900. goto bail;
  901. }
  902. if (old_inode_parent != OCFS2_I(old_dir)->ip_blkno) {
  903. status = -EIO;
  904. goto bail;
  905. }
  906. if (!new_inode && new_dir != old_dir &&
  907. new_dir->i_nlink >= OCFS2_LINK_MAX) {
  908. status = -EMLINK;
  909. goto bail;
  910. }
  911. }
  912. status = ocfs2_lookup_ino_from_name(old_dir, old_dentry->d_name.name,
  913. old_dentry->d_name.len,
  914. &old_de_ino);
  915. if (status) {
  916. status = -ENOENT;
  917. goto bail;
  918. }
  919. /*
  920. * Check for inode number is _not_ due to possible IO errors.
  921. * We might rmdir the source, keep it as pwd of some process
  922. * and merrily kill the link to whatever was created under the
  923. * same name. Goodbye sticky bit ;-<
  924. */
  925. if (old_de_ino != OCFS2_I(old_inode)->ip_blkno) {
  926. status = -ENOENT;
  927. goto bail;
  928. }
  929. /* check if the target already exists (in which case we need
  930. * to delete it */
  931. status = ocfs2_find_files_on_disk(new_dentry->d_name.name,
  932. new_dentry->d_name.len,
  933. &newfe_blkno, new_dir, &new_de_bh,
  934. &new_de);
  935. /* The only error we allow here is -ENOENT because the new
  936. * file not existing is perfectly valid. */
  937. if ((status < 0) && (status != -ENOENT)) {
  938. /* If we cannot find the file specified we should just */
  939. /* return the error... */
  940. mlog_errno(status);
  941. goto bail;
  942. }
  943. if (!new_de && new_inode) {
  944. /*
  945. * Target was unlinked by another node while we were
  946. * waiting to get to ocfs2_rename(). There isn't
  947. * anything we can do here to help the situation, so
  948. * bubble up the appropriate error.
  949. */
  950. status = -ENOENT;
  951. goto bail;
  952. }
  953. /* In case we need to overwrite an existing file, we blow it
  954. * away first */
  955. if (new_de) {
  956. /* VFS didn't think there existed an inode here, but
  957. * someone else in the cluster must have raced our
  958. * rename to create one. Today we error cleanly, in
  959. * the future we should consider calling iget to build
  960. * a new struct inode for this entry. */
  961. if (!new_inode) {
  962. status = -EACCES;
  963. mlog(0, "We found an inode for name %.*s but VFS "
  964. "didn't give us one.\n", new_dentry->d_name.len,
  965. new_dentry->d_name.name);
  966. goto bail;
  967. }
  968. if (OCFS2_I(new_inode)->ip_blkno != newfe_blkno) {
  969. status = -EACCES;
  970. mlog(0, "Inode %llu and dir %llu disagree. flags = %x\n",
  971. (unsigned long long)OCFS2_I(new_inode)->ip_blkno,
  972. (unsigned long long)newfe_blkno,
  973. OCFS2_I(new_inode)->ip_flags);
  974. goto bail;
  975. }
  976. status = ocfs2_inode_lock(new_inode, &newfe_bh, 1);
  977. if (status < 0) {
  978. if (status != -ENOENT)
  979. mlog_errno(status);
  980. goto bail;
  981. }
  982. new_child_locked = 1;
  983. status = ocfs2_remote_dentry_delete(new_dentry);
  984. if (status < 0) {
  985. mlog_errno(status);
  986. goto bail;
  987. }
  988. newfe = (struct ocfs2_dinode *) newfe_bh->b_data;
  989. mlog(0, "aha rename over existing... new_de=%p new_blkno=%llu "
  990. "newfebh=%p bhblocknr=%llu\n", new_de,
  991. (unsigned long long)newfe_blkno, newfe_bh, newfe_bh ?
  992. (unsigned long long)newfe_bh->b_blocknr : 0ULL);
  993. if (S_ISDIR(new_inode->i_mode) || (new_inode->i_nlink == 1)) {
  994. status = ocfs2_prepare_orphan_dir(osb, &orphan_dir,
  995. new_inode,
  996. orphan_name,
  997. &orphan_entry_bh);
  998. if (status < 0) {
  999. mlog_errno(status);
  1000. goto bail;
  1001. }
  1002. }
  1003. } else {
  1004. BUG_ON(new_dentry->d_parent->d_inode != new_dir);
  1005. status = ocfs2_check_dir_for_entry(new_dir,
  1006. new_dentry->d_name.name,
  1007. new_dentry->d_name.len);
  1008. if (status)
  1009. goto bail;
  1010. status = ocfs2_prepare_dir_for_insert(osb, new_dir, new_dir_bh,
  1011. new_dentry->d_name.name,
  1012. new_dentry->d_name.len,
  1013. &insert_entry_bh);
  1014. if (status < 0) {
  1015. mlog_errno(status);
  1016. goto bail;
  1017. }
  1018. }
  1019. handle = ocfs2_start_trans(osb, OCFS2_RENAME_CREDITS);
  1020. if (IS_ERR(handle)) {
  1021. status = PTR_ERR(handle);
  1022. handle = NULL;
  1023. mlog_errno(status);
  1024. goto bail;
  1025. }
  1026. if (new_de) {
  1027. if (S_ISDIR(new_inode->i_mode)) {
  1028. if (!ocfs2_empty_dir(new_inode) ||
  1029. new_inode->i_nlink != 2) {
  1030. status = -ENOTEMPTY;
  1031. goto bail;
  1032. }
  1033. }
  1034. status = ocfs2_journal_access(handle, new_inode, newfe_bh,
  1035. OCFS2_JOURNAL_ACCESS_WRITE);
  1036. if (status < 0) {
  1037. mlog_errno(status);
  1038. goto bail;
  1039. }
  1040. if (S_ISDIR(new_inode->i_mode) ||
  1041. (newfe->i_links_count == cpu_to_le16(1))){
  1042. status = ocfs2_orphan_add(osb, handle, new_inode,
  1043. newfe, orphan_name,
  1044. orphan_entry_bh, orphan_dir);
  1045. if (status < 0) {
  1046. mlog_errno(status);
  1047. goto bail;
  1048. }
  1049. }
  1050. /* change the dirent to point to the correct inode */
  1051. status = ocfs2_update_entry(new_dir, handle, new_de_bh,
  1052. new_de, old_inode);
  1053. if (status < 0) {
  1054. mlog_errno(status);
  1055. goto bail;
  1056. }
  1057. new_dir->i_version++;
  1058. if (S_ISDIR(new_inode->i_mode))
  1059. newfe->i_links_count = 0;
  1060. else
  1061. le16_add_cpu(&newfe->i_links_count, -1);
  1062. status = ocfs2_journal_dirty(handle, newfe_bh);
  1063. if (status < 0) {
  1064. mlog_errno(status);
  1065. goto bail;
  1066. }
  1067. } else {
  1068. /* if the name was not found in new_dir, add it now */
  1069. status = ocfs2_add_entry(handle, new_dentry, old_inode,
  1070. OCFS2_I(old_inode)->ip_blkno,
  1071. new_dir_bh, insert_entry_bh);
  1072. }
  1073. old_inode->i_ctime = CURRENT_TIME;
  1074. mark_inode_dirty(old_inode);
  1075. status = ocfs2_journal_access(handle, old_inode, old_inode_bh,
  1076. OCFS2_JOURNAL_ACCESS_WRITE);
  1077. if (status >= 0) {
  1078. old_di = (struct ocfs2_dinode *) old_inode_bh->b_data;
  1079. old_di->i_ctime = cpu_to_le64(old_inode->i_ctime.tv_sec);
  1080. old_di->i_ctime_nsec = cpu_to_le32(old_inode->i_ctime.tv_nsec);
  1081. status = ocfs2_journal_dirty(handle, old_inode_bh);
  1082. if (status < 0)
  1083. mlog_errno(status);
  1084. } else
  1085. mlog_errno(status);
  1086. /*
  1087. * Now that the name has been added to new_dir, remove the old name.
  1088. *
  1089. * We don't keep any directory entry context around until now
  1090. * because the insert might have changed the type of directory
  1091. * we're dealing with.
  1092. */
  1093. old_de_bh = ocfs2_find_entry(old_dentry->d_name.name,
  1094. old_dentry->d_name.len,
  1095. old_dir, &old_de);
  1096. if (!old_de_bh) {
  1097. status = -EIO;
  1098. goto bail;
  1099. }
  1100. status = ocfs2_delete_entry(handle, old_dir, old_de, old_de_bh);
  1101. if (status < 0) {
  1102. mlog_errno(status);
  1103. goto bail;
  1104. }
  1105. if (new_inode) {
  1106. new_inode->i_nlink--;
  1107. new_inode->i_ctime = CURRENT_TIME;
  1108. }
  1109. old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
  1110. if (old_inode_de_bh) {
  1111. status = ocfs2_update_entry(old_inode, handle, old_inode_de_bh,
  1112. old_inode_dot_dot_de, new_dir);
  1113. old_dir->i_nlink--;
  1114. if (new_inode) {
  1115. new_inode->i_nlink--;
  1116. } else {
  1117. inc_nlink(new_dir);
  1118. mark_inode_dirty(new_dir);
  1119. }
  1120. }
  1121. mark_inode_dirty(old_dir);
  1122. ocfs2_mark_inode_dirty(handle, old_dir, old_dir_bh);
  1123. if (new_inode) {
  1124. mark_inode_dirty(new_inode);
  1125. ocfs2_mark_inode_dirty(handle, new_inode, newfe_bh);
  1126. }
  1127. if (old_dir != new_dir) {
  1128. /* Keep the same times on both directories.*/
  1129. new_dir->i_ctime = new_dir->i_mtime = old_dir->i_ctime;
  1130. /*
  1131. * This will also pick up the i_nlink change from the
  1132. * block above.
  1133. */
  1134. ocfs2_mark_inode_dirty(handle, new_dir, new_dir_bh);
  1135. }
  1136. if (old_dir_nlink != old_dir->i_nlink) {
  1137. if (!old_dir_bh) {
  1138. mlog(ML_ERROR, "need to change nlink for old dir "
  1139. "%llu from %d to %d but bh is NULL!\n",
  1140. (unsigned long long)OCFS2_I(old_dir)->ip_blkno,
  1141. (int)old_dir_nlink, old_dir->i_nlink);
  1142. } else {
  1143. struct ocfs2_dinode *fe;
  1144. status = ocfs2_journal_access(handle, old_dir,
  1145. old_dir_bh,
  1146. OCFS2_JOURNAL_ACCESS_WRITE);
  1147. fe = (struct ocfs2_dinode *) old_dir_bh->b_data;
  1148. fe->i_links_count = cpu_to_le16(old_dir->i_nlink);
  1149. status = ocfs2_journal_dirty(handle, old_dir_bh);
  1150. }
  1151. }
  1152. ocfs2_dentry_move(old_dentry, new_dentry, old_dir, new_dir);
  1153. status = 0;
  1154. bail:
  1155. if (rename_lock)
  1156. ocfs2_rename_unlock(osb);
  1157. if (handle)
  1158. ocfs2_commit_trans(osb, handle);
  1159. if (parents_locked)
  1160. ocfs2_double_unlock(old_dir, new_dir);
  1161. if (old_child_locked)
  1162. ocfs2_inode_unlock(old_inode, 1);
  1163. if (new_child_locked)
  1164. ocfs2_inode_unlock(new_inode, 1);
  1165. if (orphan_dir) {
  1166. /* This was locked for us in ocfs2_prepare_orphan_dir() */
  1167. ocfs2_inode_unlock(orphan_dir, 1);
  1168. mutex_unlock(&orphan_dir->i_mutex);
  1169. iput(orphan_dir);
  1170. }
  1171. if (new_inode)
  1172. sync_mapping_buffers(old_inode->i_mapping);
  1173. if (new_inode)
  1174. iput(new_inode);
  1175. if (newfe_bh)
  1176. brelse(newfe_bh);
  1177. if (old_inode_bh)
  1178. brelse(old_inode_bh);
  1179. if (old_dir_bh)
  1180. brelse(old_dir_bh);
  1181. if (new_dir_bh)
  1182. brelse(new_dir_bh);
  1183. if (new_de_bh)
  1184. brelse(new_de_bh);
  1185. if (old_de_bh)
  1186. brelse(old_de_bh);
  1187. if (old_inode_de_bh)
  1188. brelse(old_inode_de_bh);
  1189. if (orphan_entry_bh)
  1190. brelse(orphan_entry_bh);
  1191. if (insert_entry_bh)
  1192. brelse(insert_entry_bh);
  1193. mlog_exit(status);
  1194. return status;
  1195. }
  1196. /*
  1197. * we expect i_size = strlen(symname). Copy symname into the file
  1198. * data, including the null terminator.
  1199. */
  1200. static int ocfs2_create_symlink_data(struct ocfs2_super *osb,
  1201. handle_t *handle,
  1202. struct inode *inode,
  1203. const char *symname)
  1204. {
  1205. struct buffer_head **bhs = NULL;
  1206. const char *c;
  1207. struct super_block *sb = osb->sb;
  1208. u64 p_blkno, p_blocks;
  1209. int virtual, blocks, status, i, bytes_left;
  1210. bytes_left = i_size_read(inode) + 1;
  1211. /* we can't trust i_blocks because we're actually going to
  1212. * write i_size + 1 bytes. */
  1213. blocks = (bytes_left + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
  1214. mlog_entry("i_blocks = %llu, i_size = %llu, blocks = %d\n",
  1215. (unsigned long long)inode->i_blocks,
  1216. i_size_read(inode), blocks);
  1217. /* Sanity check -- make sure we're going to fit. */
  1218. if (bytes_left >
  1219. ocfs2_clusters_to_bytes(sb, OCFS2_I(inode)->ip_clusters)) {
  1220. status = -EIO;
  1221. mlog_errno(status);
  1222. goto bail;
  1223. }
  1224. bhs = kcalloc(blocks, sizeof(struct buffer_head *), GFP_KERNEL);
  1225. if (!bhs) {
  1226. status = -ENOMEM;
  1227. mlog_errno(status);
  1228. goto bail;
  1229. }
  1230. status = ocfs2_extent_map_get_blocks(inode, 0, &p_blkno, &p_blocks,
  1231. NULL);
  1232. if (status < 0) {
  1233. mlog_errno(status);
  1234. goto bail;
  1235. }
  1236. /* links can never be larger than one cluster so we know this
  1237. * is all going to be contiguous, but do a sanity check
  1238. * anyway. */
  1239. if ((p_blocks << sb->s_blocksize_bits) < bytes_left) {
  1240. status = -EIO;
  1241. mlog_errno(status);
  1242. goto bail;
  1243. }
  1244. virtual = 0;
  1245. while(bytes_left > 0) {
  1246. c = &symname[virtual * sb->s_blocksize];
  1247. bhs[virtual] = sb_getblk(sb, p_blkno);
  1248. if (!bhs[virtual]) {
  1249. status = -ENOMEM;
  1250. mlog_errno(status);
  1251. goto bail;
  1252. }
  1253. ocfs2_set_new_buffer_uptodate(inode, bhs[virtual]);
  1254. status = ocfs2_journal_access(handle, inode, bhs[virtual],
  1255. OCFS2_JOURNAL_ACCESS_CREATE);
  1256. if (status < 0) {
  1257. mlog_errno(status);
  1258. goto bail;
  1259. }
  1260. memset(bhs[virtual]->b_data, 0, sb->s_blocksize);
  1261. memcpy(bhs[virtual]->b_data, c,
  1262. (bytes_left > sb->s_blocksize) ? sb->s_blocksize :
  1263. bytes_left);
  1264. status = ocfs2_journal_dirty(handle, bhs[virtual]);
  1265. if (status < 0) {
  1266. mlog_errno(status);
  1267. goto bail;
  1268. }
  1269. virtual++;
  1270. p_blkno++;
  1271. bytes_left -= sb->s_blocksize;
  1272. }
  1273. status = 0;
  1274. bail:
  1275. if (bhs) {
  1276. for(i = 0; i < blocks; i++)
  1277. if (bhs[i])
  1278. brelse(bhs[i]);
  1279. kfree(bhs);
  1280. }
  1281. mlog_exit(status);
  1282. return status;
  1283. }
  1284. static int ocfs2_symlink(struct inode *dir,
  1285. struct dentry *dentry,
  1286. const char *symname)
  1287. {
  1288. int status, l, credits;
  1289. u64 newsize;
  1290. struct ocfs2_super *osb = NULL;
  1291. struct inode *inode = NULL;
  1292. struct super_block *sb;
  1293. struct buffer_head *new_fe_bh = NULL;
  1294. struct buffer_head *de_bh = NULL;
  1295. struct buffer_head *parent_fe_bh = NULL;
  1296. struct ocfs2_dinode *fe = NULL;
  1297. struct ocfs2_dinode *dirfe;
  1298. handle_t *handle = NULL;
  1299. struct ocfs2_alloc_context *inode_ac = NULL;
  1300. struct ocfs2_alloc_context *data_ac = NULL;
  1301. mlog_entry("(0x%p, 0x%p, symname='%s' actual='%.*s')\n", dir,
  1302. dentry, symname, dentry->d_name.len, dentry->d_name.name);
  1303. sb = dir->i_sb;
  1304. osb = OCFS2_SB(sb);
  1305. l = strlen(symname) + 1;
  1306. credits = ocfs2_calc_symlink_credits(sb);
  1307. /* lock the parent directory */
  1308. status = ocfs2_inode_lock(dir, &parent_fe_bh, 1);
  1309. if (status < 0) {
  1310. if (status != -ENOENT)
  1311. mlog_errno(status);
  1312. return status;
  1313. }
  1314. dirfe = (struct ocfs2_dinode *) parent_fe_bh->b_data;
  1315. if (!dirfe->i_links_count) {
  1316. /* can't make a file in a deleted directory. */
  1317. status = -ENOENT;
  1318. goto bail;
  1319. }
  1320. status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
  1321. dentry->d_name.len);
  1322. if (status)
  1323. goto bail;
  1324. status = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,
  1325. dentry->d_name.name,
  1326. dentry->d_name.len, &de_bh);
  1327. if (status < 0) {
  1328. mlog_errno(status);
  1329. goto bail;
  1330. }
  1331. status = ocfs2_reserve_new_inode(osb, &inode_ac);
  1332. if (status < 0) {
  1333. if (status != -ENOSPC)
  1334. mlog_errno(status);
  1335. goto bail;
  1336. }
  1337. /* don't reserve bitmap space for fast symlinks. */
  1338. if (l > ocfs2_fast_symlink_chars(sb)) {
  1339. status = ocfs2_reserve_clusters(osb, 1, &data_ac);
  1340. if (status < 0) {
  1341. if (status != -ENOSPC)
  1342. mlog_errno(status);
  1343. goto bail;
  1344. }
  1345. }
  1346. handle = ocfs2_start_trans(osb, credits);
  1347. if (IS_ERR(handle)) {
  1348. status = PTR_ERR(handle);
  1349. handle = NULL;
  1350. mlog_errno(status);
  1351. goto bail;
  1352. }
  1353. status = ocfs2_mknod_locked(osb, dir, dentry,
  1354. S_IFLNK | S_IRWXUGO, 0,
  1355. &new_fe_bh, parent_fe_bh, handle,
  1356. &inode, inode_ac);
  1357. if (status < 0) {
  1358. mlog_errno(status);
  1359. goto bail;
  1360. }
  1361. fe = (struct ocfs2_dinode *) new_fe_bh->b_data;
  1362. inode->i_rdev = 0;
  1363. newsize = l - 1;
  1364. if (l > ocfs2_fast_symlink_chars(sb)) {
  1365. u32 offset = 0;
  1366. inode->i_op = &ocfs2_symlink_inode_operations;
  1367. status = ocfs2_do_extend_allocation(osb, inode, &offset, 1, 0,
  1368. new_fe_bh,
  1369. handle, data_ac, NULL,
  1370. NULL);
  1371. if (status < 0) {
  1372. if (status != -ENOSPC && status != -EINTR) {
  1373. mlog(ML_ERROR,
  1374. "Failed to extend file to %llu\n",
  1375. (unsigned long long)newsize);
  1376. mlog_errno(status);
  1377. status = -ENOSPC;
  1378. }
  1379. goto bail;
  1380. }
  1381. i_size_write(inode, newsize);
  1382. inode->i_blocks = ocfs2_inode_sector_count(inode);
  1383. } else {
  1384. inode->i_op = &ocfs2_fast_symlink_inode_operations;
  1385. memcpy((char *) fe->id2.i_symlink, symname, l);
  1386. i_size_write(inode, newsize);
  1387. inode->i_blocks = 0;
  1388. }
  1389. status = ocfs2_mark_inode_dirty(handle, inode, new_fe_bh);
  1390. if (status < 0) {
  1391. mlog_errno(status);
  1392. goto bail;
  1393. }
  1394. if (!ocfs2_inode_is_fast_symlink(inode)) {
  1395. status = ocfs2_create_symlink_data(osb, handle, inode,
  1396. symname);
  1397. if (status < 0) {
  1398. mlog_errno(status);
  1399. goto bail;
  1400. }
  1401. }
  1402. status = ocfs2_add_entry(handle, dentry, inode,
  1403. le64_to_cpu(fe->i_blkno), parent_fe_bh,
  1404. de_bh);
  1405. if (status < 0) {
  1406. mlog_errno(status);
  1407. goto bail;
  1408. }
  1409. status = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(dir)->ip_blkno);
  1410. if (status) {
  1411. mlog_errno(status);
  1412. goto bail;
  1413. }
  1414. insert_inode_hash(inode);
  1415. dentry->d_op = &ocfs2_dentry_ops;
  1416. d_instantiate(dentry, inode);
  1417. bail:
  1418. if (handle)
  1419. ocfs2_commit_trans(osb, handle);
  1420. ocfs2_inode_unlock(dir, 1);
  1421. if (new_fe_bh)
  1422. brelse(new_fe_bh);
  1423. if (parent_fe_bh)
  1424. brelse(parent_fe_bh);
  1425. if (de_bh)
  1426. brelse(de_bh);
  1427. if (inode_ac)
  1428. ocfs2_free_alloc_context(inode_ac);
  1429. if (data_ac)
  1430. ocfs2_free_alloc_context(data_ac);
  1431. if ((status < 0) && inode)
  1432. iput(inode);
  1433. mlog_exit(status);
  1434. return status;
  1435. }
  1436. static int ocfs2_blkno_stringify(u64 blkno, char *name)
  1437. {
  1438. int status, namelen;
  1439. mlog_entry_void();
  1440. namelen = snprintf(name, OCFS2_ORPHAN_NAMELEN + 1, "%016llx",
  1441. (long long)blkno);
  1442. if (namelen <= 0) {
  1443. if (namelen)
  1444. status = namelen;
  1445. else
  1446. status = -EINVAL;
  1447. mlog_errno(status);
  1448. goto bail;
  1449. }
  1450. if (namelen != OCFS2_ORPHAN_NAMELEN) {
  1451. status = -EINVAL;
  1452. mlog_errno(status);
  1453. goto bail;
  1454. }
  1455. mlog(0, "built filename '%s' for orphan dir (len=%d)\n", name,
  1456. namelen);
  1457. status = 0;
  1458. bail:
  1459. mlog_exit(status);
  1460. return status;
  1461. }
  1462. static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
  1463. struct inode **ret_orphan_dir,
  1464. struct inode *inode,
  1465. char *name,
  1466. struct buffer_head **de_bh)
  1467. {
  1468. struct inode *orphan_dir_inode;
  1469. struct buffer_head *orphan_dir_bh = NULL;
  1470. int status = 0;
  1471. status = ocfs2_blkno_stringify(OCFS2_I(inode)->ip_blkno, name);
  1472. if (status < 0) {
  1473. mlog_errno(status);
  1474. return status;
  1475. }
  1476. orphan_dir_inode = ocfs2_get_system_file_inode(osb,
  1477. ORPHAN_DIR_SYSTEM_INODE,
  1478. osb->slot_num);
  1479. if (!orphan_dir_inode) {
  1480. status = -ENOENT;
  1481. mlog_errno(status);
  1482. return status;
  1483. }
  1484. mutex_lock(&orphan_dir_inode->i_mutex);
  1485. status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1);
  1486. if (status < 0) {
  1487. mlog_errno(status);
  1488. goto leave;
  1489. }
  1490. status = ocfs2_prepare_dir_for_insert(osb, orphan_dir_inode,
  1491. orphan_dir_bh, name,
  1492. OCFS2_ORPHAN_NAMELEN, de_bh);
  1493. if (status < 0) {
  1494. ocfs2_inode_unlock(orphan_dir_inode, 1);
  1495. mlog_errno(status);
  1496. goto leave;
  1497. }
  1498. *ret_orphan_dir = orphan_dir_inode;
  1499. leave:
  1500. if (status) {
  1501. mutex_unlock(&orphan_dir_inode->i_mutex);
  1502. iput(orphan_dir_inode);
  1503. }
  1504. if (orphan_dir_bh)
  1505. brelse(orphan_dir_bh);
  1506. mlog_exit(status);
  1507. return status;
  1508. }
  1509. static int ocfs2_orphan_add(struct ocfs2_super *osb,
  1510. handle_t *handle,
  1511. struct inode *inode,
  1512. struct ocfs2_dinode *fe,
  1513. char *name,
  1514. struct buffer_head *de_bh,
  1515. struct inode *orphan_dir_inode)
  1516. {
  1517. struct buffer_head *orphan_dir_bh = NULL;
  1518. int status = 0;
  1519. struct ocfs2_dinode *orphan_fe;
  1520. mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino);
  1521. status = ocfs2_read_block(osb,
  1522. OCFS2_I(orphan_dir_inode)->ip_blkno,
  1523. &orphan_dir_bh, OCFS2_BH_CACHED,
  1524. orphan_dir_inode);
  1525. if (status < 0) {
  1526. mlog_errno(status);
  1527. goto leave;
  1528. }
  1529. status = ocfs2_journal_access(handle, orphan_dir_inode, orphan_dir_bh,
  1530. OCFS2_JOURNAL_ACCESS_WRITE);
  1531. if (status < 0) {
  1532. mlog_errno(status);
  1533. goto leave;
  1534. }
  1535. /* we're a cluster, and nlink can change on disk from
  1536. * underneath us... */
  1537. orphan_fe = (struct ocfs2_dinode *) orphan_dir_bh->b_data;
  1538. if (S_ISDIR(inode->i_mode))
  1539. le16_add_cpu(&orphan_fe->i_links_count, 1);
  1540. orphan_dir_inode->i_nlink = le16_to_cpu(orphan_fe->i_links_count);
  1541. status = ocfs2_journal_dirty(handle, orphan_dir_bh);
  1542. if (status < 0) {
  1543. mlog_errno(status);
  1544. goto leave;
  1545. }
  1546. status = __ocfs2_add_entry(handle, orphan_dir_inode, name,
  1547. OCFS2_ORPHAN_NAMELEN, inode,
  1548. OCFS2_I(inode)->ip_blkno,
  1549. orphan_dir_bh, de_bh);
  1550. if (status < 0) {
  1551. mlog_errno(status);
  1552. goto leave;
  1553. }
  1554. le32_add_cpu(&fe->i_flags, OCFS2_ORPHANED_FL);
  1555. /* Record which orphan dir our inode now resides
  1556. * in. delete_inode will use this to determine which orphan
  1557. * dir to lock. */
  1558. fe->i_orphaned_slot = cpu_to_le16(osb->slot_num);
  1559. mlog(0, "Inode %llu orphaned in slot %d\n",
  1560. (unsigned long long)OCFS2_I(inode)->ip_blkno, osb->slot_num);
  1561. leave:
  1562. if (orphan_dir_bh)
  1563. brelse(orphan_dir_bh);
  1564. mlog_exit(status);
  1565. return status;
  1566. }
  1567. /* unlike orphan_add, we expect the orphan dir to already be locked here. */
  1568. int ocfs2_orphan_del(struct ocfs2_super *osb,
  1569. handle_t *handle,
  1570. struct inode *orphan_dir_inode,
  1571. struct inode *inode,
  1572. struct buffer_head *orphan_dir_bh)
  1573. {
  1574. char name[OCFS2_ORPHAN_NAMELEN + 1];
  1575. struct ocfs2_dinode *orphan_fe;
  1576. int status = 0;
  1577. struct buffer_head *target_de_bh = NULL;
  1578. struct ocfs2_dir_entry *target_de = NULL;
  1579. mlog_entry_void();
  1580. status = ocfs2_blkno_stringify(OCFS2_I(inode)->ip_blkno, name);
  1581. if (status < 0) {
  1582. mlog_errno(status);
  1583. goto leave;
  1584. }
  1585. mlog(0, "removing '%s' from orphan dir %llu (namelen=%d)\n",
  1586. name, (unsigned long long)OCFS2_I(orphan_dir_inode)->ip_blkno,
  1587. OCFS2_ORPHAN_NAMELEN);
  1588. /* find it's spot in the orphan directory */
  1589. target_de_bh = ocfs2_find_entry(name, OCFS2_ORPHAN_NAMELEN,
  1590. orphan_dir_inode, &target_de);
  1591. if (!target_de_bh) {
  1592. status = -ENOENT;
  1593. mlog_errno(status);
  1594. goto leave;
  1595. }
  1596. /* remove it from the orphan directory */
  1597. status = ocfs2_delete_entry(handle, orphan_dir_inode, target_de,
  1598. target_de_bh);
  1599. if (status < 0) {
  1600. mlog_errno(status);
  1601. goto leave;
  1602. }
  1603. status = ocfs2_journal_access(handle,orphan_dir_inode, orphan_dir_bh,
  1604. OCFS2_JOURNAL_ACCESS_WRITE);
  1605. if (status < 0) {
  1606. mlog_errno(status);
  1607. goto leave;
  1608. }
  1609. /* do the i_nlink dance! :) */
  1610. orphan_fe = (struct ocfs2_dinode *) orphan_dir_bh->b_data;
  1611. if (S_ISDIR(inode->i_mode))
  1612. le16_add_cpu(&orphan_fe->i_links_count, -1);
  1613. orphan_dir_inode->i_nlink = le16_to_cpu(orphan_fe->i_links_count);
  1614. status = ocfs2_journal_dirty(handle, orphan_dir_bh);
  1615. if (status < 0) {
  1616. mlog_errno(status);
  1617. goto leave;
  1618. }
  1619. leave:
  1620. if (target_de_bh)
  1621. brelse(target_de_bh);
  1622. mlog_exit(status);
  1623. return status;
  1624. }
  1625. const struct inode_operations ocfs2_dir_iops = {
  1626. .create = ocfs2_create,
  1627. .lookup = ocfs2_lookup,
  1628. .link = ocfs2_link,
  1629. .unlink = ocfs2_unlink,
  1630. .rmdir = ocfs2_unlink,
  1631. .symlink = ocfs2_symlink,
  1632. .mkdir = ocfs2_mkdir,
  1633. .mknod = ocfs2_mknod,
  1634. .rename = ocfs2_rename,
  1635. .setattr = ocfs2_setattr,
  1636. .getattr = ocfs2_getattr,
  1637. .permission = ocfs2_permission,
  1638. };