namei.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503
  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. #include <linux/quotaops.h>
  43. #define MLOG_MASK_PREFIX ML_NAMEI
  44. #include <cluster/masklog.h>
  45. #include "ocfs2.h"
  46. #include "alloc.h"
  47. #include "dcache.h"
  48. #include "dir.h"
  49. #include "dlmglue.h"
  50. #include "extent_map.h"
  51. #include "file.h"
  52. #include "inode.h"
  53. #include "journal.h"
  54. #include "namei.h"
  55. #include "suballoc.h"
  56. #include "super.h"
  57. #include "symlink.h"
  58. #include "sysfile.h"
  59. #include "uptodate.h"
  60. #include "xattr.h"
  61. #include "acl.h"
  62. #include "buffer_head_io.h"
  63. static int ocfs2_mknod_locked(struct ocfs2_super *osb,
  64. struct inode *dir,
  65. struct inode *inode,
  66. dev_t dev,
  67. struct buffer_head **new_fe_bh,
  68. struct buffer_head *parent_fe_bh,
  69. handle_t *handle,
  70. struct ocfs2_alloc_context *inode_ac);
  71. static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
  72. struct inode **ret_orphan_dir,
  73. u64 blkno,
  74. char *name,
  75. struct ocfs2_dir_lookup_result *lookup);
  76. static int ocfs2_orphan_add(struct ocfs2_super *osb,
  77. handle_t *handle,
  78. struct inode *inode,
  79. struct buffer_head *fe_bh,
  80. char *name,
  81. struct ocfs2_dir_lookup_result *lookup,
  82. struct inode *orphan_dir_inode);
  83. static int ocfs2_create_symlink_data(struct ocfs2_super *osb,
  84. handle_t *handle,
  85. struct inode *inode,
  86. const char *symname);
  87. /* An orphan dir name is an 8 byte value, printed as a hex string */
  88. #define OCFS2_ORPHAN_NAMELEN ((int)(2 * sizeof(u64)))
  89. static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry,
  90. struct nameidata *nd)
  91. {
  92. int status;
  93. u64 blkno;
  94. struct inode *inode = NULL;
  95. struct dentry *ret;
  96. struct ocfs2_inode_info *oi;
  97. mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry,
  98. dentry->d_name.len, dentry->d_name.name);
  99. if (dentry->d_name.len > OCFS2_MAX_FILENAME_LEN) {
  100. ret = ERR_PTR(-ENAMETOOLONG);
  101. goto bail;
  102. }
  103. mlog(0, "find name %.*s in directory %llu\n", dentry->d_name.len,
  104. dentry->d_name.name, (unsigned long long)OCFS2_I(dir)->ip_blkno);
  105. status = ocfs2_inode_lock_nested(dir, NULL, 0, OI_LS_PARENT);
  106. if (status < 0) {
  107. if (status != -ENOENT)
  108. mlog_errno(status);
  109. ret = ERR_PTR(status);
  110. goto bail;
  111. }
  112. status = ocfs2_lookup_ino_from_name(dir, dentry->d_name.name,
  113. dentry->d_name.len, &blkno);
  114. if (status < 0)
  115. goto bail_add;
  116. inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0);
  117. if (IS_ERR(inode)) {
  118. ret = ERR_PTR(-EACCES);
  119. goto bail_unlock;
  120. }
  121. oi = OCFS2_I(inode);
  122. /* Clear any orphaned state... If we were able to look up the
  123. * inode from a directory, it certainly can't be orphaned. We
  124. * might have the bad state from a node which intended to
  125. * orphan this inode but crashed before it could commit the
  126. * unlink. */
  127. spin_lock(&oi->ip_lock);
  128. oi->ip_flags &= ~OCFS2_INODE_MAYBE_ORPHANED;
  129. spin_unlock(&oi->ip_lock);
  130. bail_add:
  131. dentry->d_op = &ocfs2_dentry_ops;
  132. ret = d_splice_alias(inode, dentry);
  133. if (inode) {
  134. /*
  135. * If d_splice_alias() finds a DCACHE_DISCONNECTED
  136. * dentry, it will d_move() it on top of ourse. The
  137. * return value will indicate this however, so in
  138. * those cases, we switch them around for the locking
  139. * code.
  140. *
  141. * NOTE: This dentry already has ->d_op set from
  142. * ocfs2_get_parent() and ocfs2_get_dentry()
  143. */
  144. if (ret)
  145. dentry = ret;
  146. status = ocfs2_dentry_attach_lock(dentry, inode,
  147. OCFS2_I(dir)->ip_blkno);
  148. if (status) {
  149. mlog_errno(status);
  150. ret = ERR_PTR(status);
  151. goto bail_unlock;
  152. }
  153. }
  154. bail_unlock:
  155. /* Don't drop the cluster lock until *after* the d_add --
  156. * unlink on another node will message us to remove that
  157. * dentry under this lock so otherwise we can race this with
  158. * the downconvert thread and have a stale dentry. */
  159. ocfs2_inode_unlock(dir, 0);
  160. bail:
  161. mlog_exit_ptr(ret);
  162. return ret;
  163. }
  164. static struct inode *ocfs2_get_init_inode(struct inode *dir, int mode)
  165. {
  166. struct inode *inode;
  167. inode = new_inode(dir->i_sb);
  168. if (!inode) {
  169. mlog(ML_ERROR, "new_inode failed!\n");
  170. return NULL;
  171. }
  172. /* populate as many fields early on as possible - many of
  173. * these are used by the support functions here and in
  174. * callers. */
  175. if (S_ISDIR(mode))
  176. inode->i_nlink = 2;
  177. else
  178. inode->i_nlink = 1;
  179. inode_init_owner(inode, dir, mode);
  180. dquot_initialize(inode);
  181. return inode;
  182. }
  183. static int ocfs2_mknod(struct inode *dir,
  184. struct dentry *dentry,
  185. int mode,
  186. dev_t dev)
  187. {
  188. int status = 0;
  189. struct buffer_head *parent_fe_bh = NULL;
  190. handle_t *handle = NULL;
  191. struct ocfs2_super *osb;
  192. struct ocfs2_dinode *dirfe;
  193. struct buffer_head *new_fe_bh = NULL;
  194. struct inode *inode = NULL;
  195. struct ocfs2_alloc_context *inode_ac = NULL;
  196. struct ocfs2_alloc_context *data_ac = NULL;
  197. struct ocfs2_alloc_context *meta_ac = NULL;
  198. int want_clusters = 0;
  199. int want_meta = 0;
  200. int xattr_credits = 0;
  201. struct ocfs2_security_xattr_info si = {
  202. .enable = 1,
  203. };
  204. int did_quota_inode = 0;
  205. struct ocfs2_dir_lookup_result lookup = { NULL, };
  206. sigset_t oldset;
  207. int did_block_signals = 0;
  208. mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
  209. (unsigned long)dev, dentry->d_name.len,
  210. dentry->d_name.name);
  211. dquot_initialize(dir);
  212. /* get our super block */
  213. osb = OCFS2_SB(dir->i_sb);
  214. status = ocfs2_inode_lock(dir, &parent_fe_bh, 1);
  215. if (status < 0) {
  216. if (status != -ENOENT)
  217. mlog_errno(status);
  218. return status;
  219. }
  220. if (S_ISDIR(mode) && (dir->i_nlink >= ocfs2_link_max(osb))) {
  221. status = -EMLINK;
  222. goto leave;
  223. }
  224. dirfe = (struct ocfs2_dinode *) parent_fe_bh->b_data;
  225. if (!ocfs2_read_links_count(dirfe)) {
  226. /* can't make a file in a deleted directory. */
  227. status = -ENOENT;
  228. goto leave;
  229. }
  230. status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
  231. dentry->d_name.len);
  232. if (status)
  233. goto leave;
  234. /* get a spot inside the dir. */
  235. status = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,
  236. dentry->d_name.name,
  237. dentry->d_name.len, &lookup);
  238. if (status < 0) {
  239. mlog_errno(status);
  240. goto leave;
  241. }
  242. /* reserve an inode spot */
  243. status = ocfs2_reserve_new_inode(osb, &inode_ac);
  244. if (status < 0) {
  245. if (status != -ENOSPC)
  246. mlog_errno(status);
  247. goto leave;
  248. }
  249. inode = ocfs2_get_init_inode(dir, mode);
  250. if (!inode) {
  251. status = -ENOMEM;
  252. mlog_errno(status);
  253. goto leave;
  254. }
  255. /* get security xattr */
  256. status = ocfs2_init_security_get(inode, dir, &si);
  257. if (status) {
  258. if (status == -EOPNOTSUPP)
  259. si.enable = 0;
  260. else {
  261. mlog_errno(status);
  262. goto leave;
  263. }
  264. }
  265. /* calculate meta data/clusters for setting security and acl xattr */
  266. status = ocfs2_calc_xattr_init(dir, parent_fe_bh, mode,
  267. &si, &want_clusters,
  268. &xattr_credits, &want_meta);
  269. if (status < 0) {
  270. mlog_errno(status);
  271. goto leave;
  272. }
  273. /* Reserve a cluster if creating an extent based directory. */
  274. if (S_ISDIR(mode) && !ocfs2_supports_inline_data(osb)) {
  275. want_clusters += 1;
  276. /* Dir indexing requires extra space as well */
  277. if (ocfs2_supports_indexed_dirs(osb))
  278. want_meta++;
  279. }
  280. status = ocfs2_reserve_new_metadata_blocks(osb, want_meta, &meta_ac);
  281. if (status < 0) {
  282. if (status != -ENOSPC)
  283. mlog_errno(status);
  284. goto leave;
  285. }
  286. status = ocfs2_reserve_clusters(osb, want_clusters, &data_ac);
  287. if (status < 0) {
  288. if (status != -ENOSPC)
  289. mlog_errno(status);
  290. goto leave;
  291. }
  292. handle = ocfs2_start_trans(osb, ocfs2_mknod_credits(osb->sb,
  293. S_ISDIR(mode),
  294. xattr_credits));
  295. if (IS_ERR(handle)) {
  296. status = PTR_ERR(handle);
  297. handle = NULL;
  298. mlog_errno(status);
  299. goto leave;
  300. }
  301. /* Starting to change things, restart is no longer possible. */
  302. ocfs2_block_signals(&oldset);
  303. did_block_signals = 1;
  304. status = dquot_alloc_inode(inode);
  305. if (status)
  306. goto leave;
  307. did_quota_inode = 1;
  308. mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry,
  309. inode->i_mode, (unsigned long)dev, dentry->d_name.len,
  310. dentry->d_name.name);
  311. /* do the real work now. */
  312. status = ocfs2_mknod_locked(osb, dir, inode, dev,
  313. &new_fe_bh, parent_fe_bh, handle,
  314. inode_ac);
  315. if (status < 0) {
  316. mlog_errno(status);
  317. goto leave;
  318. }
  319. if (S_ISDIR(mode)) {
  320. status = ocfs2_fill_new_dir(osb, handle, dir, inode,
  321. new_fe_bh, data_ac, meta_ac);
  322. if (status < 0) {
  323. mlog_errno(status);
  324. goto leave;
  325. }
  326. status = ocfs2_journal_access_di(handle, INODE_CACHE(dir),
  327. parent_fe_bh,
  328. OCFS2_JOURNAL_ACCESS_WRITE);
  329. if (status < 0) {
  330. mlog_errno(status);
  331. goto leave;
  332. }
  333. ocfs2_add_links_count(dirfe, 1);
  334. ocfs2_journal_dirty(handle, parent_fe_bh);
  335. inc_nlink(dir);
  336. }
  337. status = ocfs2_init_acl(handle, inode, dir, new_fe_bh, parent_fe_bh,
  338. meta_ac, data_ac);
  339. if (status < 0) {
  340. mlog_errno(status);
  341. goto leave;
  342. }
  343. if (si.enable) {
  344. status = ocfs2_init_security_set(handle, inode, new_fe_bh, &si,
  345. meta_ac, data_ac);
  346. if (status < 0) {
  347. mlog_errno(status);
  348. goto leave;
  349. }
  350. }
  351. /*
  352. * Do this before adding the entry to the directory. We add
  353. * also set d_op after success so that ->d_iput() will cleanup
  354. * the dentry lock even if ocfs2_add_entry() fails below.
  355. */
  356. status = ocfs2_dentry_attach_lock(dentry, inode,
  357. OCFS2_I(dir)->ip_blkno);
  358. if (status) {
  359. mlog_errno(status);
  360. goto leave;
  361. }
  362. dentry->d_op = &ocfs2_dentry_ops;
  363. status = ocfs2_add_entry(handle, dentry, inode,
  364. OCFS2_I(inode)->ip_blkno, parent_fe_bh,
  365. &lookup);
  366. if (status < 0) {
  367. mlog_errno(status);
  368. goto leave;
  369. }
  370. insert_inode_hash(inode);
  371. d_instantiate(dentry, inode);
  372. status = 0;
  373. leave:
  374. if (status < 0 && did_quota_inode)
  375. dquot_free_inode(inode);
  376. if (handle)
  377. ocfs2_commit_trans(osb, handle);
  378. ocfs2_inode_unlock(dir, 1);
  379. if (did_block_signals)
  380. ocfs2_unblock_signals(&oldset);
  381. if (status == -ENOSPC)
  382. mlog(0, "Disk is full\n");
  383. brelse(new_fe_bh);
  384. brelse(parent_fe_bh);
  385. kfree(si.name);
  386. kfree(si.value);
  387. ocfs2_free_dir_lookup_result(&lookup);
  388. if (inode_ac)
  389. ocfs2_free_alloc_context(inode_ac);
  390. if (data_ac)
  391. ocfs2_free_alloc_context(data_ac);
  392. if (meta_ac)
  393. ocfs2_free_alloc_context(meta_ac);
  394. /*
  395. * We should call iput after the i_mutex of the bitmap been
  396. * unlocked in ocfs2_free_alloc_context, or the
  397. * ocfs2_delete_inode will mutex_lock again.
  398. */
  399. if ((status < 0) && inode) {
  400. OCFS2_I(inode)->ip_flags |= OCFS2_INODE_SKIP_ORPHAN_DIR;
  401. clear_nlink(inode);
  402. iput(inode);
  403. }
  404. mlog_exit(status);
  405. return status;
  406. }
  407. static int __ocfs2_mknod_locked(struct inode *dir,
  408. struct inode *inode,
  409. dev_t dev,
  410. struct buffer_head **new_fe_bh,
  411. struct buffer_head *parent_fe_bh,
  412. handle_t *handle,
  413. struct ocfs2_alloc_context *inode_ac,
  414. u64 fe_blkno, u64 suballoc_loc, u16 suballoc_bit)
  415. {
  416. int status = 0;
  417. struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
  418. struct ocfs2_dinode *fe = NULL;
  419. struct ocfs2_extent_list *fel;
  420. u16 feat;
  421. *new_fe_bh = NULL;
  422. /* populate as many fields early on as possible - many of
  423. * these are used by the support functions here and in
  424. * callers. */
  425. inode->i_ino = ino_from_blkno(osb->sb, fe_blkno);
  426. OCFS2_I(inode)->ip_blkno = fe_blkno;
  427. spin_lock(&osb->osb_lock);
  428. inode->i_generation = osb->s_next_generation++;
  429. spin_unlock(&osb->osb_lock);
  430. *new_fe_bh = sb_getblk(osb->sb, fe_blkno);
  431. if (!*new_fe_bh) {
  432. status = -EIO;
  433. mlog_errno(status);
  434. goto leave;
  435. }
  436. ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), *new_fe_bh);
  437. status = ocfs2_journal_access_di(handle, INODE_CACHE(inode),
  438. *new_fe_bh,
  439. OCFS2_JOURNAL_ACCESS_CREATE);
  440. if (status < 0) {
  441. mlog_errno(status);
  442. goto leave;
  443. }
  444. fe = (struct ocfs2_dinode *) (*new_fe_bh)->b_data;
  445. memset(fe, 0, osb->sb->s_blocksize);
  446. fe->i_generation = cpu_to_le32(inode->i_generation);
  447. fe->i_fs_generation = cpu_to_le32(osb->fs_generation);
  448. fe->i_blkno = cpu_to_le64(fe_blkno);
  449. fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
  450. fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
  451. fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
  452. fe->i_uid = cpu_to_le32(inode->i_uid);
  453. fe->i_gid = cpu_to_le32(inode->i_gid);
  454. fe->i_mode = cpu_to_le16(inode->i_mode);
  455. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
  456. fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
  457. ocfs2_set_links_count(fe, inode->i_nlink);
  458. fe->i_last_eb_blk = 0;
  459. strcpy(fe->i_signature, OCFS2_INODE_SIGNATURE);
  460. le32_add_cpu(&fe->i_flags, OCFS2_VALID_FL);
  461. fe->i_atime = fe->i_ctime = fe->i_mtime =
  462. cpu_to_le64(CURRENT_TIME.tv_sec);
  463. fe->i_mtime_nsec = fe->i_ctime_nsec = fe->i_atime_nsec =
  464. cpu_to_le32(CURRENT_TIME.tv_nsec);
  465. fe->i_dtime = 0;
  466. /*
  467. * If supported, directories start with inline data. If inline
  468. * isn't supported, but indexing is, we start them as indexed.
  469. */
  470. feat = le16_to_cpu(fe->i_dyn_features);
  471. if (S_ISDIR(inode->i_mode) && ocfs2_supports_inline_data(osb)) {
  472. fe->i_dyn_features = cpu_to_le16(feat | OCFS2_INLINE_DATA_FL);
  473. fe->id2.i_data.id_count = cpu_to_le16(
  474. ocfs2_max_inline_data_with_xattr(osb->sb, fe));
  475. } else {
  476. fel = &fe->id2.i_list;
  477. fel->l_tree_depth = 0;
  478. fel->l_next_free_rec = 0;
  479. fel->l_count = cpu_to_le16(ocfs2_extent_recs_per_inode(osb->sb));
  480. }
  481. ocfs2_journal_dirty(handle, *new_fe_bh);
  482. ocfs2_populate_inode(inode, fe, 1);
  483. ocfs2_ci_set_new(osb, INODE_CACHE(inode));
  484. if (!ocfs2_mount_local(osb)) {
  485. status = ocfs2_create_new_inode_locks(inode);
  486. if (status < 0)
  487. mlog_errno(status);
  488. }
  489. status = 0; /* error in ocfs2_create_new_inode_locks is not
  490. * critical */
  491. leave:
  492. if (status < 0) {
  493. if (*new_fe_bh) {
  494. brelse(*new_fe_bh);
  495. *new_fe_bh = NULL;
  496. }
  497. }
  498. mlog_exit(status);
  499. return status;
  500. }
  501. static int ocfs2_mknod_locked(struct ocfs2_super *osb,
  502. struct inode *dir,
  503. struct inode *inode,
  504. dev_t dev,
  505. struct buffer_head **new_fe_bh,
  506. struct buffer_head *parent_fe_bh,
  507. handle_t *handle,
  508. struct ocfs2_alloc_context *inode_ac)
  509. {
  510. int status = 0;
  511. u64 suballoc_loc, fe_blkno = 0;
  512. u16 suballoc_bit;
  513. *new_fe_bh = NULL;
  514. status = ocfs2_claim_new_inode(handle, dir, parent_fe_bh,
  515. inode_ac, &suballoc_loc,
  516. &suballoc_bit, &fe_blkno);
  517. if (status < 0) {
  518. mlog_errno(status);
  519. return status;
  520. }
  521. return __ocfs2_mknod_locked(dir, inode, dev, new_fe_bh,
  522. parent_fe_bh, handle, inode_ac,
  523. fe_blkno, suballoc_loc, suballoc_bit);
  524. }
  525. static int ocfs2_mkdir(struct inode *dir,
  526. struct dentry *dentry,
  527. int mode)
  528. {
  529. int ret;
  530. mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, mode,
  531. dentry->d_name.len, dentry->d_name.name);
  532. ret = ocfs2_mknod(dir, dentry, mode | S_IFDIR, 0);
  533. mlog_exit(ret);
  534. return ret;
  535. }
  536. static int ocfs2_create(struct inode *dir,
  537. struct dentry *dentry,
  538. int mode,
  539. struct nameidata *nd)
  540. {
  541. int ret;
  542. mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, mode,
  543. dentry->d_name.len, dentry->d_name.name);
  544. ret = ocfs2_mknod(dir, dentry, mode | S_IFREG, 0);
  545. mlog_exit(ret);
  546. return ret;
  547. }
  548. static int ocfs2_link(struct dentry *old_dentry,
  549. struct inode *dir,
  550. struct dentry *dentry)
  551. {
  552. handle_t *handle;
  553. struct inode *inode = old_dentry->d_inode;
  554. int err;
  555. struct buffer_head *fe_bh = NULL;
  556. struct buffer_head *parent_fe_bh = NULL;
  557. struct ocfs2_dinode *fe = NULL;
  558. struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
  559. struct ocfs2_dir_lookup_result lookup = { NULL, };
  560. sigset_t oldset;
  561. mlog_entry("(inode=%lu, old='%.*s' new='%.*s')\n", inode->i_ino,
  562. old_dentry->d_name.len, old_dentry->d_name.name,
  563. dentry->d_name.len, dentry->d_name.name);
  564. if (S_ISDIR(inode->i_mode))
  565. return -EPERM;
  566. dquot_initialize(dir);
  567. err = ocfs2_inode_lock_nested(dir, &parent_fe_bh, 1, OI_LS_PARENT);
  568. if (err < 0) {
  569. if (err != -ENOENT)
  570. mlog_errno(err);
  571. return err;
  572. }
  573. if (!dir->i_nlink) {
  574. err = -ENOENT;
  575. goto out;
  576. }
  577. err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
  578. dentry->d_name.len);
  579. if (err)
  580. goto out;
  581. err = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,
  582. dentry->d_name.name,
  583. dentry->d_name.len, &lookup);
  584. if (err < 0) {
  585. mlog_errno(err);
  586. goto out;
  587. }
  588. err = ocfs2_inode_lock(inode, &fe_bh, 1);
  589. if (err < 0) {
  590. if (err != -ENOENT)
  591. mlog_errno(err);
  592. goto out;
  593. }
  594. fe = (struct ocfs2_dinode *) fe_bh->b_data;
  595. if (ocfs2_read_links_count(fe) >= ocfs2_link_max(osb)) {
  596. err = -EMLINK;
  597. goto out_unlock_inode;
  598. }
  599. handle = ocfs2_start_trans(osb, ocfs2_link_credits(osb->sb));
  600. if (IS_ERR(handle)) {
  601. err = PTR_ERR(handle);
  602. handle = NULL;
  603. mlog_errno(err);
  604. goto out_unlock_inode;
  605. }
  606. /* Starting to change things, restart is no longer possible. */
  607. ocfs2_block_signals(&oldset);
  608. err = ocfs2_journal_access_di(handle, INODE_CACHE(inode), fe_bh,
  609. OCFS2_JOURNAL_ACCESS_WRITE);
  610. if (err < 0) {
  611. mlog_errno(err);
  612. goto out_commit;
  613. }
  614. inc_nlink(inode);
  615. inode->i_ctime = CURRENT_TIME;
  616. ocfs2_set_links_count(fe, inode->i_nlink);
  617. fe->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);
  618. fe->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
  619. ocfs2_journal_dirty(handle, fe_bh);
  620. err = ocfs2_add_entry(handle, dentry, inode,
  621. OCFS2_I(inode)->ip_blkno,
  622. parent_fe_bh, &lookup);
  623. if (err) {
  624. ocfs2_add_links_count(fe, -1);
  625. drop_nlink(inode);
  626. mlog_errno(err);
  627. goto out_commit;
  628. }
  629. err = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(dir)->ip_blkno);
  630. if (err) {
  631. mlog_errno(err);
  632. goto out_commit;
  633. }
  634. atomic_inc(&inode->i_count);
  635. dentry->d_op = &ocfs2_dentry_ops;
  636. d_instantiate(dentry, inode);
  637. out_commit:
  638. ocfs2_commit_trans(osb, handle);
  639. ocfs2_unblock_signals(&oldset);
  640. out_unlock_inode:
  641. ocfs2_inode_unlock(inode, 1);
  642. out:
  643. ocfs2_inode_unlock(dir, 1);
  644. brelse(fe_bh);
  645. brelse(parent_fe_bh);
  646. ocfs2_free_dir_lookup_result(&lookup);
  647. mlog_exit(err);
  648. return err;
  649. }
  650. /*
  651. * Takes and drops an exclusive lock on the given dentry. This will
  652. * force other nodes to drop it.
  653. */
  654. static int ocfs2_remote_dentry_delete(struct dentry *dentry)
  655. {
  656. int ret;
  657. ret = ocfs2_dentry_lock(dentry, 1);
  658. if (ret)
  659. mlog_errno(ret);
  660. else
  661. ocfs2_dentry_unlock(dentry, 1);
  662. return ret;
  663. }
  664. static inline int inode_is_unlinkable(struct inode *inode)
  665. {
  666. if (S_ISDIR(inode->i_mode)) {
  667. if (inode->i_nlink == 2)
  668. return 1;
  669. return 0;
  670. }
  671. if (inode->i_nlink == 1)
  672. return 1;
  673. return 0;
  674. }
  675. static int ocfs2_unlink(struct inode *dir,
  676. struct dentry *dentry)
  677. {
  678. int status;
  679. int child_locked = 0;
  680. struct inode *inode = dentry->d_inode;
  681. struct inode *orphan_dir = NULL;
  682. struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
  683. u64 blkno;
  684. struct ocfs2_dinode *fe = NULL;
  685. struct buffer_head *fe_bh = NULL;
  686. struct buffer_head *parent_node_bh = NULL;
  687. handle_t *handle = NULL;
  688. char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
  689. struct ocfs2_dir_lookup_result lookup = { NULL, };
  690. struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
  691. mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry,
  692. dentry->d_name.len, dentry->d_name.name);
  693. dquot_initialize(dir);
  694. BUG_ON(dentry->d_parent->d_inode != dir);
  695. mlog(0, "ino = %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno);
  696. if (inode == osb->root_inode) {
  697. mlog(0, "Cannot delete the root directory\n");
  698. return -EPERM;
  699. }
  700. status = ocfs2_inode_lock_nested(dir, &parent_node_bh, 1,
  701. OI_LS_PARENT);
  702. if (status < 0) {
  703. if (status != -ENOENT)
  704. mlog_errno(status);
  705. return status;
  706. }
  707. status = ocfs2_find_files_on_disk(dentry->d_name.name,
  708. dentry->d_name.len, &blkno, dir,
  709. &lookup);
  710. if (status < 0) {
  711. if (status != -ENOENT)
  712. mlog_errno(status);
  713. goto leave;
  714. }
  715. if (OCFS2_I(inode)->ip_blkno != blkno) {
  716. status = -ENOENT;
  717. mlog(0, "ip_blkno %llu != dirent blkno %llu ip_flags = %x\n",
  718. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  719. (unsigned long long)blkno, OCFS2_I(inode)->ip_flags);
  720. goto leave;
  721. }
  722. status = ocfs2_inode_lock(inode, &fe_bh, 1);
  723. if (status < 0) {
  724. if (status != -ENOENT)
  725. mlog_errno(status);
  726. goto leave;
  727. }
  728. child_locked = 1;
  729. if (S_ISDIR(inode->i_mode)) {
  730. if (inode->i_nlink != 2 || !ocfs2_empty_dir(inode)) {
  731. status = -ENOTEMPTY;
  732. goto leave;
  733. }
  734. }
  735. status = ocfs2_remote_dentry_delete(dentry);
  736. if (status < 0) {
  737. /* This remote delete should succeed under all normal
  738. * circumstances. */
  739. mlog_errno(status);
  740. goto leave;
  741. }
  742. if (inode_is_unlinkable(inode)) {
  743. status = ocfs2_prepare_orphan_dir(osb, &orphan_dir,
  744. OCFS2_I(inode)->ip_blkno,
  745. orphan_name, &orphan_insert);
  746. if (status < 0) {
  747. mlog_errno(status);
  748. goto leave;
  749. }
  750. }
  751. handle = ocfs2_start_trans(osb, ocfs2_unlink_credits(osb->sb));
  752. if (IS_ERR(handle)) {
  753. status = PTR_ERR(handle);
  754. handle = NULL;
  755. mlog_errno(status);
  756. goto leave;
  757. }
  758. status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), fe_bh,
  759. OCFS2_JOURNAL_ACCESS_WRITE);
  760. if (status < 0) {
  761. mlog_errno(status);
  762. goto leave;
  763. }
  764. fe = (struct ocfs2_dinode *) fe_bh->b_data;
  765. if (inode_is_unlinkable(inode)) {
  766. status = ocfs2_orphan_add(osb, handle, inode, fe_bh, orphan_name,
  767. &orphan_insert, orphan_dir);
  768. if (status < 0) {
  769. mlog_errno(status);
  770. goto leave;
  771. }
  772. }
  773. /* delete the name from the parent dir */
  774. status = ocfs2_delete_entry(handle, dir, &lookup);
  775. if (status < 0) {
  776. mlog_errno(status);
  777. goto leave;
  778. }
  779. if (S_ISDIR(inode->i_mode))
  780. drop_nlink(inode);
  781. drop_nlink(inode);
  782. ocfs2_set_links_count(fe, inode->i_nlink);
  783. ocfs2_journal_dirty(handle, fe_bh);
  784. dir->i_ctime = dir->i_mtime = CURRENT_TIME;
  785. if (S_ISDIR(inode->i_mode))
  786. drop_nlink(dir);
  787. status = ocfs2_mark_inode_dirty(handle, dir, parent_node_bh);
  788. if (status < 0) {
  789. mlog_errno(status);
  790. if (S_ISDIR(inode->i_mode))
  791. inc_nlink(dir);
  792. }
  793. leave:
  794. if (handle)
  795. ocfs2_commit_trans(osb, handle);
  796. if (child_locked)
  797. ocfs2_inode_unlock(inode, 1);
  798. ocfs2_inode_unlock(dir, 1);
  799. if (orphan_dir) {
  800. /* This was locked for us in ocfs2_prepare_orphan_dir() */
  801. ocfs2_inode_unlock(orphan_dir, 1);
  802. mutex_unlock(&orphan_dir->i_mutex);
  803. iput(orphan_dir);
  804. }
  805. brelse(fe_bh);
  806. brelse(parent_node_bh);
  807. ocfs2_free_dir_lookup_result(&orphan_insert);
  808. ocfs2_free_dir_lookup_result(&lookup);
  809. mlog_exit(status);
  810. return status;
  811. }
  812. /*
  813. * The only place this should be used is rename!
  814. * if they have the same id, then the 1st one is the only one locked.
  815. */
  816. static int ocfs2_double_lock(struct ocfs2_super *osb,
  817. struct buffer_head **bh1,
  818. struct inode *inode1,
  819. struct buffer_head **bh2,
  820. struct inode *inode2)
  821. {
  822. int status;
  823. struct ocfs2_inode_info *oi1 = OCFS2_I(inode1);
  824. struct ocfs2_inode_info *oi2 = OCFS2_I(inode2);
  825. struct buffer_head **tmpbh;
  826. struct inode *tmpinode;
  827. mlog_entry("(inode1 = %llu, inode2 = %llu)\n",
  828. (unsigned long long)oi1->ip_blkno,
  829. (unsigned long long)oi2->ip_blkno);
  830. if (*bh1)
  831. *bh1 = NULL;
  832. if (*bh2)
  833. *bh2 = NULL;
  834. /* we always want to lock the one with the lower lockid first. */
  835. if (oi1->ip_blkno != oi2->ip_blkno) {
  836. if (oi1->ip_blkno < oi2->ip_blkno) {
  837. /* switch id1 and id2 around */
  838. mlog(0, "switching them around...\n");
  839. tmpbh = bh2;
  840. bh2 = bh1;
  841. bh1 = tmpbh;
  842. tmpinode = inode2;
  843. inode2 = inode1;
  844. inode1 = tmpinode;
  845. }
  846. /* lock id2 */
  847. status = ocfs2_inode_lock_nested(inode2, bh2, 1,
  848. OI_LS_RENAME1);
  849. if (status < 0) {
  850. if (status != -ENOENT)
  851. mlog_errno(status);
  852. goto bail;
  853. }
  854. }
  855. /* lock id1 */
  856. status = ocfs2_inode_lock_nested(inode1, bh1, 1, OI_LS_RENAME2);
  857. if (status < 0) {
  858. /*
  859. * An error return must mean that no cluster locks
  860. * were held on function exit.
  861. */
  862. if (oi1->ip_blkno != oi2->ip_blkno)
  863. ocfs2_inode_unlock(inode2, 1);
  864. if (status != -ENOENT)
  865. mlog_errno(status);
  866. }
  867. bail:
  868. mlog_exit(status);
  869. return status;
  870. }
  871. static void ocfs2_double_unlock(struct inode *inode1, struct inode *inode2)
  872. {
  873. ocfs2_inode_unlock(inode1, 1);
  874. if (inode1 != inode2)
  875. ocfs2_inode_unlock(inode2, 1);
  876. }
  877. static int ocfs2_rename(struct inode *old_dir,
  878. struct dentry *old_dentry,
  879. struct inode *new_dir,
  880. struct dentry *new_dentry)
  881. {
  882. int status = 0, rename_lock = 0, parents_locked = 0, target_exists = 0;
  883. int old_child_locked = 0, new_child_locked = 0, update_dot_dot = 0;
  884. struct inode *old_inode = old_dentry->d_inode;
  885. struct inode *new_inode = new_dentry->d_inode;
  886. struct inode *orphan_dir = NULL;
  887. struct ocfs2_dinode *newfe = NULL;
  888. char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
  889. struct buffer_head *newfe_bh = NULL;
  890. struct buffer_head *old_inode_bh = NULL;
  891. struct ocfs2_super *osb = NULL;
  892. u64 newfe_blkno, old_de_ino;
  893. handle_t *handle = NULL;
  894. struct buffer_head *old_dir_bh = NULL;
  895. struct buffer_head *new_dir_bh = NULL;
  896. nlink_t old_dir_nlink = old_dir->i_nlink;
  897. struct ocfs2_dinode *old_di;
  898. struct ocfs2_dir_lookup_result old_inode_dot_dot_res = { NULL, };
  899. struct ocfs2_dir_lookup_result target_lookup_res = { NULL, };
  900. struct ocfs2_dir_lookup_result old_entry_lookup = { NULL, };
  901. struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
  902. struct ocfs2_dir_lookup_result target_insert = { NULL, };
  903. /* At some point it might be nice to break this function up a
  904. * bit. */
  905. mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p, from='%.*s' to='%.*s')\n",
  906. old_dir, old_dentry, new_dir, new_dentry,
  907. old_dentry->d_name.len, old_dentry->d_name.name,
  908. new_dentry->d_name.len, new_dentry->d_name.name);
  909. dquot_initialize(old_dir);
  910. dquot_initialize(new_dir);
  911. osb = OCFS2_SB(old_dir->i_sb);
  912. if (new_inode) {
  913. if (!igrab(new_inode))
  914. BUG();
  915. }
  916. /* Assume a directory hierarchy thusly:
  917. * a/b/c
  918. * a/d
  919. * a,b,c, and d are all directories.
  920. *
  921. * from cwd of 'a' on both nodes:
  922. * node1: mv b/c d
  923. * node2: mv d b/c
  924. *
  925. * And that's why, just like the VFS, we need a file system
  926. * rename lock. */
  927. if (old_dir != new_dir && S_ISDIR(old_inode->i_mode)) {
  928. status = ocfs2_rename_lock(osb);
  929. if (status < 0) {
  930. mlog_errno(status);
  931. goto bail;
  932. }
  933. rename_lock = 1;
  934. }
  935. /* if old and new are the same, this'll just do one lock. */
  936. status = ocfs2_double_lock(osb, &old_dir_bh, old_dir,
  937. &new_dir_bh, new_dir);
  938. if (status < 0) {
  939. mlog_errno(status);
  940. goto bail;
  941. }
  942. parents_locked = 1;
  943. /* make sure both dirs have bhs
  944. * get an extra ref on old_dir_bh if old==new */
  945. if (!new_dir_bh) {
  946. if (old_dir_bh) {
  947. new_dir_bh = old_dir_bh;
  948. get_bh(new_dir_bh);
  949. } else {
  950. mlog(ML_ERROR, "no old_dir_bh!\n");
  951. status = -EIO;
  952. goto bail;
  953. }
  954. }
  955. /*
  956. * Aside from allowing a meta data update, the locking here
  957. * also ensures that the downconvert thread on other nodes
  958. * won't have to concurrently downconvert the inode and the
  959. * dentry locks.
  960. */
  961. status = ocfs2_inode_lock_nested(old_inode, &old_inode_bh, 1,
  962. OI_LS_PARENT);
  963. if (status < 0) {
  964. if (status != -ENOENT)
  965. mlog_errno(status);
  966. goto bail;
  967. }
  968. old_child_locked = 1;
  969. status = ocfs2_remote_dentry_delete(old_dentry);
  970. if (status < 0) {
  971. mlog_errno(status);
  972. goto bail;
  973. }
  974. if (S_ISDIR(old_inode->i_mode)) {
  975. u64 old_inode_parent;
  976. update_dot_dot = 1;
  977. status = ocfs2_find_files_on_disk("..", 2, &old_inode_parent,
  978. old_inode,
  979. &old_inode_dot_dot_res);
  980. if (status) {
  981. status = -EIO;
  982. goto bail;
  983. }
  984. if (old_inode_parent != OCFS2_I(old_dir)->ip_blkno) {
  985. status = -EIO;
  986. goto bail;
  987. }
  988. if (!new_inode && new_dir != old_dir &&
  989. new_dir->i_nlink >= ocfs2_link_max(osb)) {
  990. status = -EMLINK;
  991. goto bail;
  992. }
  993. }
  994. status = ocfs2_lookup_ino_from_name(old_dir, old_dentry->d_name.name,
  995. old_dentry->d_name.len,
  996. &old_de_ino);
  997. if (status) {
  998. status = -ENOENT;
  999. goto bail;
  1000. }
  1001. /*
  1002. * Check for inode number is _not_ due to possible IO errors.
  1003. * We might rmdir the source, keep it as pwd of some process
  1004. * and merrily kill the link to whatever was created under the
  1005. * same name. Goodbye sticky bit ;-<
  1006. */
  1007. if (old_de_ino != OCFS2_I(old_inode)->ip_blkno) {
  1008. status = -ENOENT;
  1009. goto bail;
  1010. }
  1011. /* check if the target already exists (in which case we need
  1012. * to delete it */
  1013. status = ocfs2_find_files_on_disk(new_dentry->d_name.name,
  1014. new_dentry->d_name.len,
  1015. &newfe_blkno, new_dir,
  1016. &target_lookup_res);
  1017. /* The only error we allow here is -ENOENT because the new
  1018. * file not existing is perfectly valid. */
  1019. if ((status < 0) && (status != -ENOENT)) {
  1020. /* If we cannot find the file specified we should just */
  1021. /* return the error... */
  1022. mlog_errno(status);
  1023. goto bail;
  1024. }
  1025. if (status == 0)
  1026. target_exists = 1;
  1027. if (!target_exists && new_inode) {
  1028. /*
  1029. * Target was unlinked by another node while we were
  1030. * waiting to get to ocfs2_rename(). There isn't
  1031. * anything we can do here to help the situation, so
  1032. * bubble up the appropriate error.
  1033. */
  1034. status = -ENOENT;
  1035. goto bail;
  1036. }
  1037. /* In case we need to overwrite an existing file, we blow it
  1038. * away first */
  1039. if (target_exists) {
  1040. /* VFS didn't think there existed an inode here, but
  1041. * someone else in the cluster must have raced our
  1042. * rename to create one. Today we error cleanly, in
  1043. * the future we should consider calling iget to build
  1044. * a new struct inode for this entry. */
  1045. if (!new_inode) {
  1046. status = -EACCES;
  1047. mlog(0, "We found an inode for name %.*s but VFS "
  1048. "didn't give us one.\n", new_dentry->d_name.len,
  1049. new_dentry->d_name.name);
  1050. goto bail;
  1051. }
  1052. if (OCFS2_I(new_inode)->ip_blkno != newfe_blkno) {
  1053. status = -EACCES;
  1054. mlog(0, "Inode %llu and dir %llu disagree. flags = %x\n",
  1055. (unsigned long long)OCFS2_I(new_inode)->ip_blkno,
  1056. (unsigned long long)newfe_blkno,
  1057. OCFS2_I(new_inode)->ip_flags);
  1058. goto bail;
  1059. }
  1060. status = ocfs2_inode_lock(new_inode, &newfe_bh, 1);
  1061. if (status < 0) {
  1062. if (status != -ENOENT)
  1063. mlog_errno(status);
  1064. goto bail;
  1065. }
  1066. new_child_locked = 1;
  1067. status = ocfs2_remote_dentry_delete(new_dentry);
  1068. if (status < 0) {
  1069. mlog_errno(status);
  1070. goto bail;
  1071. }
  1072. newfe = (struct ocfs2_dinode *) newfe_bh->b_data;
  1073. mlog(0, "aha rename over existing... new_blkno=%llu "
  1074. "newfebh=%p bhblocknr=%llu\n",
  1075. (unsigned long long)newfe_blkno, newfe_bh, newfe_bh ?
  1076. (unsigned long long)newfe_bh->b_blocknr : 0ULL);
  1077. if (S_ISDIR(new_inode->i_mode) || (new_inode->i_nlink == 1)) {
  1078. status = ocfs2_prepare_orphan_dir(osb, &orphan_dir,
  1079. OCFS2_I(new_inode)->ip_blkno,
  1080. orphan_name, &orphan_insert);
  1081. if (status < 0) {
  1082. mlog_errno(status);
  1083. goto bail;
  1084. }
  1085. }
  1086. } else {
  1087. BUG_ON(new_dentry->d_parent->d_inode != new_dir);
  1088. status = ocfs2_check_dir_for_entry(new_dir,
  1089. new_dentry->d_name.name,
  1090. new_dentry->d_name.len);
  1091. if (status)
  1092. goto bail;
  1093. status = ocfs2_prepare_dir_for_insert(osb, new_dir, new_dir_bh,
  1094. new_dentry->d_name.name,
  1095. new_dentry->d_name.len,
  1096. &target_insert);
  1097. if (status < 0) {
  1098. mlog_errno(status);
  1099. goto bail;
  1100. }
  1101. }
  1102. handle = ocfs2_start_trans(osb, ocfs2_rename_credits(osb->sb));
  1103. if (IS_ERR(handle)) {
  1104. status = PTR_ERR(handle);
  1105. handle = NULL;
  1106. mlog_errno(status);
  1107. goto bail;
  1108. }
  1109. if (target_exists) {
  1110. if (S_ISDIR(new_inode->i_mode)) {
  1111. if (new_inode->i_nlink != 2 ||
  1112. !ocfs2_empty_dir(new_inode)) {
  1113. status = -ENOTEMPTY;
  1114. goto bail;
  1115. }
  1116. }
  1117. status = ocfs2_journal_access_di(handle, INODE_CACHE(new_inode),
  1118. newfe_bh,
  1119. OCFS2_JOURNAL_ACCESS_WRITE);
  1120. if (status < 0) {
  1121. mlog_errno(status);
  1122. goto bail;
  1123. }
  1124. if (S_ISDIR(new_inode->i_mode) ||
  1125. (ocfs2_read_links_count(newfe) == 1)) {
  1126. status = ocfs2_orphan_add(osb, handle, new_inode,
  1127. newfe_bh, orphan_name,
  1128. &orphan_insert, orphan_dir);
  1129. if (status < 0) {
  1130. mlog_errno(status);
  1131. goto bail;
  1132. }
  1133. }
  1134. /* change the dirent to point to the correct inode */
  1135. status = ocfs2_update_entry(new_dir, handle, &target_lookup_res,
  1136. old_inode);
  1137. if (status < 0) {
  1138. mlog_errno(status);
  1139. goto bail;
  1140. }
  1141. new_dir->i_version++;
  1142. if (S_ISDIR(new_inode->i_mode))
  1143. ocfs2_set_links_count(newfe, 0);
  1144. else
  1145. ocfs2_add_links_count(newfe, -1);
  1146. ocfs2_journal_dirty(handle, newfe_bh);
  1147. } else {
  1148. /* if the name was not found in new_dir, add it now */
  1149. status = ocfs2_add_entry(handle, new_dentry, old_inode,
  1150. OCFS2_I(old_inode)->ip_blkno,
  1151. new_dir_bh, &target_insert);
  1152. }
  1153. old_inode->i_ctime = CURRENT_TIME;
  1154. mark_inode_dirty(old_inode);
  1155. status = ocfs2_journal_access_di(handle, INODE_CACHE(old_inode),
  1156. old_inode_bh,
  1157. OCFS2_JOURNAL_ACCESS_WRITE);
  1158. if (status >= 0) {
  1159. old_di = (struct ocfs2_dinode *) old_inode_bh->b_data;
  1160. old_di->i_ctime = cpu_to_le64(old_inode->i_ctime.tv_sec);
  1161. old_di->i_ctime_nsec = cpu_to_le32(old_inode->i_ctime.tv_nsec);
  1162. ocfs2_journal_dirty(handle, old_inode_bh);
  1163. } else
  1164. mlog_errno(status);
  1165. /*
  1166. * Now that the name has been added to new_dir, remove the old name.
  1167. *
  1168. * We don't keep any directory entry context around until now
  1169. * because the insert might have changed the type of directory
  1170. * we're dealing with.
  1171. */
  1172. status = ocfs2_find_entry(old_dentry->d_name.name,
  1173. old_dentry->d_name.len, old_dir,
  1174. &old_entry_lookup);
  1175. if (status)
  1176. goto bail;
  1177. status = ocfs2_delete_entry(handle, old_dir, &old_entry_lookup);
  1178. if (status < 0) {
  1179. mlog_errno(status);
  1180. goto bail;
  1181. }
  1182. if (new_inode) {
  1183. new_inode->i_nlink--;
  1184. new_inode->i_ctime = CURRENT_TIME;
  1185. }
  1186. old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
  1187. if (update_dot_dot) {
  1188. status = ocfs2_update_entry(old_inode, handle,
  1189. &old_inode_dot_dot_res, new_dir);
  1190. old_dir->i_nlink--;
  1191. if (new_inode) {
  1192. new_inode->i_nlink--;
  1193. } else {
  1194. inc_nlink(new_dir);
  1195. mark_inode_dirty(new_dir);
  1196. }
  1197. }
  1198. mark_inode_dirty(old_dir);
  1199. ocfs2_mark_inode_dirty(handle, old_dir, old_dir_bh);
  1200. if (new_inode) {
  1201. mark_inode_dirty(new_inode);
  1202. ocfs2_mark_inode_dirty(handle, new_inode, newfe_bh);
  1203. }
  1204. if (old_dir != new_dir) {
  1205. /* Keep the same times on both directories.*/
  1206. new_dir->i_ctime = new_dir->i_mtime = old_dir->i_ctime;
  1207. /*
  1208. * This will also pick up the i_nlink change from the
  1209. * block above.
  1210. */
  1211. ocfs2_mark_inode_dirty(handle, new_dir, new_dir_bh);
  1212. }
  1213. if (old_dir_nlink != old_dir->i_nlink) {
  1214. if (!old_dir_bh) {
  1215. mlog(ML_ERROR, "need to change nlink for old dir "
  1216. "%llu from %d to %d but bh is NULL!\n",
  1217. (unsigned long long)OCFS2_I(old_dir)->ip_blkno,
  1218. (int)old_dir_nlink, old_dir->i_nlink);
  1219. } else {
  1220. struct ocfs2_dinode *fe;
  1221. status = ocfs2_journal_access_di(handle,
  1222. INODE_CACHE(old_dir),
  1223. old_dir_bh,
  1224. OCFS2_JOURNAL_ACCESS_WRITE);
  1225. fe = (struct ocfs2_dinode *) old_dir_bh->b_data;
  1226. ocfs2_set_links_count(fe, old_dir->i_nlink);
  1227. ocfs2_journal_dirty(handle, old_dir_bh);
  1228. }
  1229. }
  1230. ocfs2_dentry_move(old_dentry, new_dentry, old_dir, new_dir);
  1231. status = 0;
  1232. bail:
  1233. if (rename_lock)
  1234. ocfs2_rename_unlock(osb);
  1235. if (handle)
  1236. ocfs2_commit_trans(osb, handle);
  1237. if (parents_locked)
  1238. ocfs2_double_unlock(old_dir, new_dir);
  1239. if (old_child_locked)
  1240. ocfs2_inode_unlock(old_inode, 1);
  1241. if (new_child_locked)
  1242. ocfs2_inode_unlock(new_inode, 1);
  1243. if (orphan_dir) {
  1244. /* This was locked for us in ocfs2_prepare_orphan_dir() */
  1245. ocfs2_inode_unlock(orphan_dir, 1);
  1246. mutex_unlock(&orphan_dir->i_mutex);
  1247. iput(orphan_dir);
  1248. }
  1249. if (new_inode)
  1250. sync_mapping_buffers(old_inode->i_mapping);
  1251. if (new_inode)
  1252. iput(new_inode);
  1253. ocfs2_free_dir_lookup_result(&target_lookup_res);
  1254. ocfs2_free_dir_lookup_result(&old_entry_lookup);
  1255. ocfs2_free_dir_lookup_result(&old_inode_dot_dot_res);
  1256. ocfs2_free_dir_lookup_result(&orphan_insert);
  1257. ocfs2_free_dir_lookup_result(&target_insert);
  1258. brelse(newfe_bh);
  1259. brelse(old_inode_bh);
  1260. brelse(old_dir_bh);
  1261. brelse(new_dir_bh);
  1262. mlog_exit(status);
  1263. return status;
  1264. }
  1265. /*
  1266. * we expect i_size = strlen(symname). Copy symname into the file
  1267. * data, including the null terminator.
  1268. */
  1269. static int ocfs2_create_symlink_data(struct ocfs2_super *osb,
  1270. handle_t *handle,
  1271. struct inode *inode,
  1272. const char *symname)
  1273. {
  1274. struct buffer_head **bhs = NULL;
  1275. const char *c;
  1276. struct super_block *sb = osb->sb;
  1277. u64 p_blkno, p_blocks;
  1278. int virtual, blocks, status, i, bytes_left;
  1279. bytes_left = i_size_read(inode) + 1;
  1280. /* we can't trust i_blocks because we're actually going to
  1281. * write i_size + 1 bytes. */
  1282. blocks = (bytes_left + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
  1283. mlog_entry("i_blocks = %llu, i_size = %llu, blocks = %d\n",
  1284. (unsigned long long)inode->i_blocks,
  1285. i_size_read(inode), blocks);
  1286. /* Sanity check -- make sure we're going to fit. */
  1287. if (bytes_left >
  1288. ocfs2_clusters_to_bytes(sb, OCFS2_I(inode)->ip_clusters)) {
  1289. status = -EIO;
  1290. mlog_errno(status);
  1291. goto bail;
  1292. }
  1293. bhs = kcalloc(blocks, sizeof(struct buffer_head *), GFP_KERNEL);
  1294. if (!bhs) {
  1295. status = -ENOMEM;
  1296. mlog_errno(status);
  1297. goto bail;
  1298. }
  1299. status = ocfs2_extent_map_get_blocks(inode, 0, &p_blkno, &p_blocks,
  1300. NULL);
  1301. if (status < 0) {
  1302. mlog_errno(status);
  1303. goto bail;
  1304. }
  1305. /* links can never be larger than one cluster so we know this
  1306. * is all going to be contiguous, but do a sanity check
  1307. * anyway. */
  1308. if ((p_blocks << sb->s_blocksize_bits) < bytes_left) {
  1309. status = -EIO;
  1310. mlog_errno(status);
  1311. goto bail;
  1312. }
  1313. virtual = 0;
  1314. while(bytes_left > 0) {
  1315. c = &symname[virtual * sb->s_blocksize];
  1316. bhs[virtual] = sb_getblk(sb, p_blkno);
  1317. if (!bhs[virtual]) {
  1318. status = -ENOMEM;
  1319. mlog_errno(status);
  1320. goto bail;
  1321. }
  1322. ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode),
  1323. bhs[virtual]);
  1324. status = ocfs2_journal_access(handle, INODE_CACHE(inode),
  1325. bhs[virtual],
  1326. OCFS2_JOURNAL_ACCESS_CREATE);
  1327. if (status < 0) {
  1328. mlog_errno(status);
  1329. goto bail;
  1330. }
  1331. memset(bhs[virtual]->b_data, 0, sb->s_blocksize);
  1332. memcpy(bhs[virtual]->b_data, c,
  1333. (bytes_left > sb->s_blocksize) ? sb->s_blocksize :
  1334. bytes_left);
  1335. ocfs2_journal_dirty(handle, bhs[virtual]);
  1336. virtual++;
  1337. p_blkno++;
  1338. bytes_left -= sb->s_blocksize;
  1339. }
  1340. status = 0;
  1341. bail:
  1342. if (bhs) {
  1343. for(i = 0; i < blocks; i++)
  1344. brelse(bhs[i]);
  1345. kfree(bhs);
  1346. }
  1347. mlog_exit(status);
  1348. return status;
  1349. }
  1350. static int ocfs2_symlink(struct inode *dir,
  1351. struct dentry *dentry,
  1352. const char *symname)
  1353. {
  1354. int status, l, credits;
  1355. u64 newsize;
  1356. struct ocfs2_super *osb = NULL;
  1357. struct inode *inode = NULL;
  1358. struct super_block *sb;
  1359. struct buffer_head *new_fe_bh = NULL;
  1360. struct buffer_head *parent_fe_bh = NULL;
  1361. struct ocfs2_dinode *fe = NULL;
  1362. struct ocfs2_dinode *dirfe;
  1363. handle_t *handle = NULL;
  1364. struct ocfs2_alloc_context *inode_ac = NULL;
  1365. struct ocfs2_alloc_context *data_ac = NULL;
  1366. struct ocfs2_alloc_context *xattr_ac = NULL;
  1367. int want_clusters = 0;
  1368. int xattr_credits = 0;
  1369. struct ocfs2_security_xattr_info si = {
  1370. .enable = 1,
  1371. };
  1372. int did_quota = 0, did_quota_inode = 0;
  1373. struct ocfs2_dir_lookup_result lookup = { NULL, };
  1374. sigset_t oldset;
  1375. int did_block_signals = 0;
  1376. mlog_entry("(0x%p, 0x%p, symname='%s' actual='%.*s')\n", dir,
  1377. dentry, symname, dentry->d_name.len, dentry->d_name.name);
  1378. dquot_initialize(dir);
  1379. sb = dir->i_sb;
  1380. osb = OCFS2_SB(sb);
  1381. l = strlen(symname) + 1;
  1382. credits = ocfs2_calc_symlink_credits(sb);
  1383. /* lock the parent directory */
  1384. status = ocfs2_inode_lock(dir, &parent_fe_bh, 1);
  1385. if (status < 0) {
  1386. if (status != -ENOENT)
  1387. mlog_errno(status);
  1388. return status;
  1389. }
  1390. dirfe = (struct ocfs2_dinode *) parent_fe_bh->b_data;
  1391. if (!ocfs2_read_links_count(dirfe)) {
  1392. /* can't make a file in a deleted directory. */
  1393. status = -ENOENT;
  1394. goto bail;
  1395. }
  1396. status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
  1397. dentry->d_name.len);
  1398. if (status)
  1399. goto bail;
  1400. status = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,
  1401. dentry->d_name.name,
  1402. dentry->d_name.len, &lookup);
  1403. if (status < 0) {
  1404. mlog_errno(status);
  1405. goto bail;
  1406. }
  1407. status = ocfs2_reserve_new_inode(osb, &inode_ac);
  1408. if (status < 0) {
  1409. if (status != -ENOSPC)
  1410. mlog_errno(status);
  1411. goto bail;
  1412. }
  1413. inode = ocfs2_get_init_inode(dir, S_IFLNK | S_IRWXUGO);
  1414. if (!inode) {
  1415. status = -ENOMEM;
  1416. mlog_errno(status);
  1417. goto bail;
  1418. }
  1419. /* get security xattr */
  1420. status = ocfs2_init_security_get(inode, dir, &si);
  1421. if (status) {
  1422. if (status == -EOPNOTSUPP)
  1423. si.enable = 0;
  1424. else {
  1425. mlog_errno(status);
  1426. goto bail;
  1427. }
  1428. }
  1429. /* calculate meta data/clusters for setting security xattr */
  1430. if (si.enable) {
  1431. status = ocfs2_calc_security_init(dir, &si, &want_clusters,
  1432. &xattr_credits, &xattr_ac);
  1433. if (status < 0) {
  1434. mlog_errno(status);
  1435. goto bail;
  1436. }
  1437. }
  1438. /* don't reserve bitmap space for fast symlinks. */
  1439. if (l > ocfs2_fast_symlink_chars(sb))
  1440. want_clusters += 1;
  1441. status = ocfs2_reserve_clusters(osb, want_clusters, &data_ac);
  1442. if (status < 0) {
  1443. if (status != -ENOSPC)
  1444. mlog_errno(status);
  1445. goto bail;
  1446. }
  1447. handle = ocfs2_start_trans(osb, credits + xattr_credits);
  1448. if (IS_ERR(handle)) {
  1449. status = PTR_ERR(handle);
  1450. handle = NULL;
  1451. mlog_errno(status);
  1452. goto bail;
  1453. }
  1454. /* Starting to change things, restart is no longer possible. */
  1455. ocfs2_block_signals(&oldset);
  1456. did_block_signals = 1;
  1457. status = dquot_alloc_inode(inode);
  1458. if (status)
  1459. goto bail;
  1460. did_quota_inode = 1;
  1461. mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry,
  1462. inode->i_mode, dentry->d_name.len,
  1463. dentry->d_name.name);
  1464. status = ocfs2_mknod_locked(osb, dir, inode,
  1465. 0, &new_fe_bh, parent_fe_bh, handle,
  1466. inode_ac);
  1467. if (status < 0) {
  1468. mlog_errno(status);
  1469. goto bail;
  1470. }
  1471. fe = (struct ocfs2_dinode *) new_fe_bh->b_data;
  1472. inode->i_rdev = 0;
  1473. newsize = l - 1;
  1474. if (l > ocfs2_fast_symlink_chars(sb)) {
  1475. u32 offset = 0;
  1476. inode->i_op = &ocfs2_symlink_inode_operations;
  1477. status = dquot_alloc_space_nodirty(inode,
  1478. ocfs2_clusters_to_bytes(osb->sb, 1));
  1479. if (status)
  1480. goto bail;
  1481. did_quota = 1;
  1482. status = ocfs2_add_inode_data(osb, inode, &offset, 1, 0,
  1483. new_fe_bh,
  1484. handle, data_ac, NULL,
  1485. NULL);
  1486. if (status < 0) {
  1487. if (status != -ENOSPC && status != -EINTR) {
  1488. mlog(ML_ERROR,
  1489. "Failed to extend file to %llu\n",
  1490. (unsigned long long)newsize);
  1491. mlog_errno(status);
  1492. status = -ENOSPC;
  1493. }
  1494. goto bail;
  1495. }
  1496. i_size_write(inode, newsize);
  1497. inode->i_blocks = ocfs2_inode_sector_count(inode);
  1498. } else {
  1499. inode->i_op = &ocfs2_fast_symlink_inode_operations;
  1500. memcpy((char *) fe->id2.i_symlink, symname, l);
  1501. i_size_write(inode, newsize);
  1502. inode->i_blocks = 0;
  1503. }
  1504. status = ocfs2_mark_inode_dirty(handle, inode, new_fe_bh);
  1505. if (status < 0) {
  1506. mlog_errno(status);
  1507. goto bail;
  1508. }
  1509. if (!ocfs2_inode_is_fast_symlink(inode)) {
  1510. status = ocfs2_create_symlink_data(osb, handle, inode,
  1511. symname);
  1512. if (status < 0) {
  1513. mlog_errno(status);
  1514. goto bail;
  1515. }
  1516. }
  1517. if (si.enable) {
  1518. status = ocfs2_init_security_set(handle, inode, new_fe_bh, &si,
  1519. xattr_ac, data_ac);
  1520. if (status < 0) {
  1521. mlog_errno(status);
  1522. goto bail;
  1523. }
  1524. }
  1525. /*
  1526. * Do this before adding the entry to the directory. We add
  1527. * also set d_op after success so that ->d_iput() will cleanup
  1528. * the dentry lock even if ocfs2_add_entry() fails below.
  1529. */
  1530. status = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(dir)->ip_blkno);
  1531. if (status) {
  1532. mlog_errno(status);
  1533. goto bail;
  1534. }
  1535. dentry->d_op = &ocfs2_dentry_ops;
  1536. status = ocfs2_add_entry(handle, dentry, inode,
  1537. le64_to_cpu(fe->i_blkno), parent_fe_bh,
  1538. &lookup);
  1539. if (status < 0) {
  1540. mlog_errno(status);
  1541. goto bail;
  1542. }
  1543. insert_inode_hash(inode);
  1544. d_instantiate(dentry, inode);
  1545. bail:
  1546. if (status < 0 && did_quota)
  1547. dquot_free_space_nodirty(inode,
  1548. ocfs2_clusters_to_bytes(osb->sb, 1));
  1549. if (status < 0 && did_quota_inode)
  1550. dquot_free_inode(inode);
  1551. if (handle)
  1552. ocfs2_commit_trans(osb, handle);
  1553. ocfs2_inode_unlock(dir, 1);
  1554. if (did_block_signals)
  1555. ocfs2_unblock_signals(&oldset);
  1556. brelse(new_fe_bh);
  1557. brelse(parent_fe_bh);
  1558. kfree(si.name);
  1559. kfree(si.value);
  1560. ocfs2_free_dir_lookup_result(&lookup);
  1561. if (inode_ac)
  1562. ocfs2_free_alloc_context(inode_ac);
  1563. if (data_ac)
  1564. ocfs2_free_alloc_context(data_ac);
  1565. if (xattr_ac)
  1566. ocfs2_free_alloc_context(xattr_ac);
  1567. if ((status < 0) && inode) {
  1568. OCFS2_I(inode)->ip_flags |= OCFS2_INODE_SKIP_ORPHAN_DIR;
  1569. clear_nlink(inode);
  1570. iput(inode);
  1571. }
  1572. mlog_exit(status);
  1573. return status;
  1574. }
  1575. static int ocfs2_blkno_stringify(u64 blkno, char *name)
  1576. {
  1577. int status, namelen;
  1578. mlog_entry_void();
  1579. namelen = snprintf(name, OCFS2_ORPHAN_NAMELEN + 1, "%016llx",
  1580. (long long)blkno);
  1581. if (namelen <= 0) {
  1582. if (namelen)
  1583. status = namelen;
  1584. else
  1585. status = -EINVAL;
  1586. mlog_errno(status);
  1587. goto bail;
  1588. }
  1589. if (namelen != OCFS2_ORPHAN_NAMELEN) {
  1590. status = -EINVAL;
  1591. mlog_errno(status);
  1592. goto bail;
  1593. }
  1594. mlog(0, "built filename '%s' for orphan dir (len=%d)\n", name,
  1595. namelen);
  1596. status = 0;
  1597. bail:
  1598. mlog_exit(status);
  1599. return status;
  1600. }
  1601. static int ocfs2_lookup_lock_orphan_dir(struct ocfs2_super *osb,
  1602. struct inode **ret_orphan_dir,
  1603. struct buffer_head **ret_orphan_dir_bh)
  1604. {
  1605. struct inode *orphan_dir_inode;
  1606. struct buffer_head *orphan_dir_bh = NULL;
  1607. int ret = 0;
  1608. orphan_dir_inode = ocfs2_get_system_file_inode(osb,
  1609. ORPHAN_DIR_SYSTEM_INODE,
  1610. osb->slot_num);
  1611. if (!orphan_dir_inode) {
  1612. ret = -ENOENT;
  1613. mlog_errno(ret);
  1614. return ret;
  1615. }
  1616. mutex_lock(&orphan_dir_inode->i_mutex);
  1617. ret = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1);
  1618. if (ret < 0) {
  1619. mutex_unlock(&orphan_dir_inode->i_mutex);
  1620. iput(orphan_dir_inode);
  1621. mlog_errno(ret);
  1622. return ret;
  1623. }
  1624. *ret_orphan_dir = orphan_dir_inode;
  1625. *ret_orphan_dir_bh = orphan_dir_bh;
  1626. return 0;
  1627. }
  1628. static int __ocfs2_prepare_orphan_dir(struct inode *orphan_dir_inode,
  1629. struct buffer_head *orphan_dir_bh,
  1630. u64 blkno,
  1631. char *name,
  1632. struct ocfs2_dir_lookup_result *lookup)
  1633. {
  1634. int ret;
  1635. struct ocfs2_super *osb = OCFS2_SB(orphan_dir_inode->i_sb);
  1636. ret = ocfs2_blkno_stringify(blkno, name);
  1637. if (ret < 0) {
  1638. mlog_errno(ret);
  1639. return ret;
  1640. }
  1641. ret = ocfs2_prepare_dir_for_insert(osb, orphan_dir_inode,
  1642. orphan_dir_bh, name,
  1643. OCFS2_ORPHAN_NAMELEN, lookup);
  1644. if (ret < 0) {
  1645. mlog_errno(ret);
  1646. return ret;
  1647. }
  1648. return 0;
  1649. }
  1650. /**
  1651. * ocfs2_prepare_orphan_dir() - Prepare an orphan directory for
  1652. * insertion of an orphan.
  1653. * @osb: ocfs2 file system
  1654. * @ret_orphan_dir: Orphan dir inode - returned locked!
  1655. * @blkno: Actual block number of the inode to be inserted into orphan dir.
  1656. * @lookup: dir lookup result, to be passed back into functions like
  1657. * ocfs2_orphan_add
  1658. *
  1659. * Returns zero on success and the ret_orphan_dir, name and lookup
  1660. * fields will be populated.
  1661. *
  1662. * Returns non-zero on failure.
  1663. */
  1664. static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
  1665. struct inode **ret_orphan_dir,
  1666. u64 blkno,
  1667. char *name,
  1668. struct ocfs2_dir_lookup_result *lookup)
  1669. {
  1670. struct inode *orphan_dir_inode = NULL;
  1671. struct buffer_head *orphan_dir_bh = NULL;
  1672. int ret = 0;
  1673. ret = ocfs2_lookup_lock_orphan_dir(osb, &orphan_dir_inode,
  1674. &orphan_dir_bh);
  1675. if (ret < 0) {
  1676. mlog_errno(ret);
  1677. return ret;
  1678. }
  1679. ret = __ocfs2_prepare_orphan_dir(orphan_dir_inode, orphan_dir_bh,
  1680. blkno, name, lookup);
  1681. if (ret < 0) {
  1682. mlog_errno(ret);
  1683. goto out;
  1684. }
  1685. *ret_orphan_dir = orphan_dir_inode;
  1686. out:
  1687. brelse(orphan_dir_bh);
  1688. if (ret) {
  1689. ocfs2_inode_unlock(orphan_dir_inode, 1);
  1690. mutex_unlock(&orphan_dir_inode->i_mutex);
  1691. iput(orphan_dir_inode);
  1692. }
  1693. mlog_exit(ret);
  1694. return ret;
  1695. }
  1696. static int ocfs2_orphan_add(struct ocfs2_super *osb,
  1697. handle_t *handle,
  1698. struct inode *inode,
  1699. struct buffer_head *fe_bh,
  1700. char *name,
  1701. struct ocfs2_dir_lookup_result *lookup,
  1702. struct inode *orphan_dir_inode)
  1703. {
  1704. struct buffer_head *orphan_dir_bh = NULL;
  1705. int status = 0;
  1706. struct ocfs2_dinode *orphan_fe;
  1707. struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data;
  1708. mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino);
  1709. status = ocfs2_read_inode_block(orphan_dir_inode, &orphan_dir_bh);
  1710. if (status < 0) {
  1711. mlog_errno(status);
  1712. goto leave;
  1713. }
  1714. status = ocfs2_journal_access_di(handle,
  1715. INODE_CACHE(orphan_dir_inode),
  1716. orphan_dir_bh,
  1717. OCFS2_JOURNAL_ACCESS_WRITE);
  1718. if (status < 0) {
  1719. mlog_errno(status);
  1720. goto leave;
  1721. }
  1722. /* we're a cluster, and nlink can change on disk from
  1723. * underneath us... */
  1724. orphan_fe = (struct ocfs2_dinode *) orphan_dir_bh->b_data;
  1725. if (S_ISDIR(inode->i_mode))
  1726. ocfs2_add_links_count(orphan_fe, 1);
  1727. orphan_dir_inode->i_nlink = ocfs2_read_links_count(orphan_fe);
  1728. ocfs2_journal_dirty(handle, orphan_dir_bh);
  1729. status = __ocfs2_add_entry(handle, orphan_dir_inode, name,
  1730. OCFS2_ORPHAN_NAMELEN, inode,
  1731. OCFS2_I(inode)->ip_blkno,
  1732. orphan_dir_bh, lookup);
  1733. if (status < 0) {
  1734. mlog_errno(status);
  1735. goto leave;
  1736. }
  1737. /*
  1738. * We're going to journal the change of i_flags and i_orphaned_slot.
  1739. * It's safe anyway, though some callers may duplicate the journaling.
  1740. * Journaling within the func just make the logic look more
  1741. * straightforward.
  1742. */
  1743. status = ocfs2_journal_access_di(handle,
  1744. INODE_CACHE(inode),
  1745. fe_bh,
  1746. OCFS2_JOURNAL_ACCESS_WRITE);
  1747. if (status < 0) {
  1748. mlog_errno(status);
  1749. goto leave;
  1750. }
  1751. le32_add_cpu(&fe->i_flags, OCFS2_ORPHANED_FL);
  1752. OCFS2_I(inode)->ip_flags &= ~OCFS2_INODE_SKIP_ORPHAN_DIR;
  1753. /* Record which orphan dir our inode now resides
  1754. * in. delete_inode will use this to determine which orphan
  1755. * dir to lock. */
  1756. fe->i_orphaned_slot = cpu_to_le16(osb->slot_num);
  1757. ocfs2_journal_dirty(handle, fe_bh);
  1758. mlog(0, "Inode %llu orphaned in slot %d\n",
  1759. (unsigned long long)OCFS2_I(inode)->ip_blkno, osb->slot_num);
  1760. leave:
  1761. brelse(orphan_dir_bh);
  1762. mlog_exit(status);
  1763. return status;
  1764. }
  1765. /* unlike orphan_add, we expect the orphan dir to already be locked here. */
  1766. int ocfs2_orphan_del(struct ocfs2_super *osb,
  1767. handle_t *handle,
  1768. struct inode *orphan_dir_inode,
  1769. struct inode *inode,
  1770. struct buffer_head *orphan_dir_bh)
  1771. {
  1772. char name[OCFS2_ORPHAN_NAMELEN + 1];
  1773. struct ocfs2_dinode *orphan_fe;
  1774. int status = 0;
  1775. struct ocfs2_dir_lookup_result lookup = { NULL, };
  1776. mlog_entry_void();
  1777. status = ocfs2_blkno_stringify(OCFS2_I(inode)->ip_blkno, name);
  1778. if (status < 0) {
  1779. mlog_errno(status);
  1780. goto leave;
  1781. }
  1782. mlog(0, "removing '%s' from orphan dir %llu (namelen=%d)\n",
  1783. name, (unsigned long long)OCFS2_I(orphan_dir_inode)->ip_blkno,
  1784. OCFS2_ORPHAN_NAMELEN);
  1785. /* find it's spot in the orphan directory */
  1786. status = ocfs2_find_entry(name, OCFS2_ORPHAN_NAMELEN, orphan_dir_inode,
  1787. &lookup);
  1788. if (status) {
  1789. mlog_errno(status);
  1790. goto leave;
  1791. }
  1792. /* remove it from the orphan directory */
  1793. status = ocfs2_delete_entry(handle, orphan_dir_inode, &lookup);
  1794. if (status < 0) {
  1795. mlog_errno(status);
  1796. goto leave;
  1797. }
  1798. status = ocfs2_journal_access_di(handle,
  1799. INODE_CACHE(orphan_dir_inode),
  1800. orphan_dir_bh,
  1801. OCFS2_JOURNAL_ACCESS_WRITE);
  1802. if (status < 0) {
  1803. mlog_errno(status);
  1804. goto leave;
  1805. }
  1806. /* do the i_nlink dance! :) */
  1807. orphan_fe = (struct ocfs2_dinode *) orphan_dir_bh->b_data;
  1808. if (S_ISDIR(inode->i_mode))
  1809. ocfs2_add_links_count(orphan_fe, -1);
  1810. orphan_dir_inode->i_nlink = ocfs2_read_links_count(orphan_fe);
  1811. ocfs2_journal_dirty(handle, orphan_dir_bh);
  1812. leave:
  1813. ocfs2_free_dir_lookup_result(&lookup);
  1814. mlog_exit(status);
  1815. return status;
  1816. }
  1817. /**
  1818. * ocfs2_prep_new_orphaned_file() - Prepare the orphan dir to recieve a newly
  1819. * allocated file. This is different from the typical 'add to orphan dir'
  1820. * operation in that the inode does not yet exist. This is a problem because
  1821. * the orphan dir stringifies the inode block number to come up with it's
  1822. * dirent. Obviously if the inode does not yet exist we have a chicken and egg
  1823. * problem. This function works around it by calling deeper into the orphan
  1824. * and suballoc code than other callers. Use this only by necessity.
  1825. * @dir: The directory which this inode will ultimately wind up under - not the
  1826. * orphan dir!
  1827. * @dir_bh: buffer_head the @dir inode block
  1828. * @orphan_name: string of length (CFS2_ORPHAN_NAMELEN + 1). Will be filled
  1829. * with the string to be used for orphan dirent. Pass back to the orphan dir
  1830. * code.
  1831. * @ret_orphan_dir: orphan dir inode returned to be passed back into orphan
  1832. * dir code.
  1833. * @ret_di_blkno: block number where the new inode will be allocated.
  1834. * @orphan_insert: Dir insert context to be passed back into orphan dir code.
  1835. * @ret_inode_ac: Inode alloc context to be passed back to the allocator.
  1836. *
  1837. * Returns zero on success and the ret_orphan_dir, name and lookup
  1838. * fields will be populated.
  1839. *
  1840. * Returns non-zero on failure.
  1841. */
  1842. static int ocfs2_prep_new_orphaned_file(struct inode *dir,
  1843. struct buffer_head *dir_bh,
  1844. char *orphan_name,
  1845. struct inode **ret_orphan_dir,
  1846. u64 *ret_di_blkno,
  1847. struct ocfs2_dir_lookup_result *orphan_insert,
  1848. struct ocfs2_alloc_context **ret_inode_ac)
  1849. {
  1850. int ret;
  1851. u64 di_blkno;
  1852. struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
  1853. struct inode *orphan_dir = NULL;
  1854. struct buffer_head *orphan_dir_bh = NULL;
  1855. struct ocfs2_alloc_context *inode_ac = NULL;
  1856. ret = ocfs2_lookup_lock_orphan_dir(osb, &orphan_dir, &orphan_dir_bh);
  1857. if (ret < 0) {
  1858. mlog_errno(ret);
  1859. return ret;
  1860. }
  1861. /* reserve an inode spot */
  1862. ret = ocfs2_reserve_new_inode(osb, &inode_ac);
  1863. if (ret < 0) {
  1864. if (ret != -ENOSPC)
  1865. mlog_errno(ret);
  1866. goto out;
  1867. }
  1868. ret = ocfs2_find_new_inode_loc(dir, dir_bh, inode_ac,
  1869. &di_blkno);
  1870. if (ret) {
  1871. mlog_errno(ret);
  1872. goto out;
  1873. }
  1874. ret = __ocfs2_prepare_orphan_dir(orphan_dir, orphan_dir_bh,
  1875. di_blkno, orphan_name, orphan_insert);
  1876. if (ret < 0) {
  1877. mlog_errno(ret);
  1878. goto out;
  1879. }
  1880. out:
  1881. if (ret == 0) {
  1882. *ret_orphan_dir = orphan_dir;
  1883. *ret_di_blkno = di_blkno;
  1884. *ret_inode_ac = inode_ac;
  1885. /*
  1886. * orphan_name and orphan_insert are already up to
  1887. * date via prepare_orphan_dir
  1888. */
  1889. } else {
  1890. /* Unroll reserve_new_inode* */
  1891. if (inode_ac)
  1892. ocfs2_free_alloc_context(inode_ac);
  1893. /* Unroll orphan dir locking */
  1894. mutex_unlock(&orphan_dir->i_mutex);
  1895. ocfs2_inode_unlock(orphan_dir, 1);
  1896. iput(orphan_dir);
  1897. }
  1898. brelse(orphan_dir_bh);
  1899. return 0;
  1900. }
  1901. int ocfs2_create_inode_in_orphan(struct inode *dir,
  1902. int mode,
  1903. struct inode **new_inode)
  1904. {
  1905. int status, did_quota_inode = 0;
  1906. struct inode *inode = NULL;
  1907. struct inode *orphan_dir = NULL;
  1908. struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
  1909. struct ocfs2_dinode *di = NULL;
  1910. handle_t *handle = NULL;
  1911. char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
  1912. struct buffer_head *parent_di_bh = NULL;
  1913. struct buffer_head *new_di_bh = NULL;
  1914. struct ocfs2_alloc_context *inode_ac = NULL;
  1915. struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
  1916. u64 uninitialized_var(di_blkno), suballoc_loc;
  1917. u16 suballoc_bit;
  1918. status = ocfs2_inode_lock(dir, &parent_di_bh, 1);
  1919. if (status < 0) {
  1920. if (status != -ENOENT)
  1921. mlog_errno(status);
  1922. return status;
  1923. }
  1924. status = ocfs2_prep_new_orphaned_file(dir, parent_di_bh,
  1925. orphan_name, &orphan_dir,
  1926. &di_blkno, &orphan_insert, &inode_ac);
  1927. if (status < 0) {
  1928. if (status != -ENOSPC)
  1929. mlog_errno(status);
  1930. goto leave;
  1931. }
  1932. inode = ocfs2_get_init_inode(dir, mode);
  1933. if (!inode) {
  1934. status = -ENOMEM;
  1935. mlog_errno(status);
  1936. goto leave;
  1937. }
  1938. handle = ocfs2_start_trans(osb, ocfs2_mknod_credits(osb->sb, 0, 0));
  1939. if (IS_ERR(handle)) {
  1940. status = PTR_ERR(handle);
  1941. handle = NULL;
  1942. mlog_errno(status);
  1943. goto leave;
  1944. }
  1945. status = dquot_alloc_inode(inode);
  1946. if (status)
  1947. goto leave;
  1948. did_quota_inode = 1;
  1949. status = ocfs2_claim_new_inode_at_loc(handle, dir, inode_ac,
  1950. &suballoc_loc,
  1951. &suballoc_bit, di_blkno);
  1952. if (status < 0) {
  1953. mlog_errno(status);
  1954. goto leave;
  1955. }
  1956. inode->i_nlink = 0;
  1957. /* do the real work now. */
  1958. status = __ocfs2_mknod_locked(dir, inode,
  1959. 0, &new_di_bh, parent_di_bh, handle,
  1960. inode_ac, di_blkno, suballoc_loc,
  1961. suballoc_bit);
  1962. if (status < 0) {
  1963. mlog_errno(status);
  1964. goto leave;
  1965. }
  1966. di = (struct ocfs2_dinode *)new_di_bh->b_data;
  1967. status = ocfs2_orphan_add(osb, handle, inode, new_di_bh, orphan_name,
  1968. &orphan_insert, orphan_dir);
  1969. if (status < 0) {
  1970. mlog_errno(status);
  1971. goto leave;
  1972. }
  1973. /* get open lock so that only nodes can't remove it from orphan dir. */
  1974. status = ocfs2_open_lock(inode);
  1975. if (status < 0)
  1976. mlog_errno(status);
  1977. insert_inode_hash(inode);
  1978. leave:
  1979. if (status < 0 && did_quota_inode)
  1980. dquot_free_inode(inode);
  1981. if (handle)
  1982. ocfs2_commit_trans(osb, handle);
  1983. if (orphan_dir) {
  1984. /* This was locked for us in ocfs2_prepare_orphan_dir() */
  1985. ocfs2_inode_unlock(orphan_dir, 1);
  1986. mutex_unlock(&orphan_dir->i_mutex);
  1987. iput(orphan_dir);
  1988. }
  1989. if (status == -ENOSPC)
  1990. mlog(0, "Disk is full\n");
  1991. if ((status < 0) && inode) {
  1992. clear_nlink(inode);
  1993. iput(inode);
  1994. }
  1995. if (inode_ac)
  1996. ocfs2_free_alloc_context(inode_ac);
  1997. brelse(new_di_bh);
  1998. if (!status)
  1999. *new_inode = inode;
  2000. ocfs2_free_dir_lookup_result(&orphan_insert);
  2001. ocfs2_inode_unlock(dir, 1);
  2002. brelse(parent_di_bh);
  2003. return status;
  2004. }
  2005. int ocfs2_mv_orphaned_inode_to_new(struct inode *dir,
  2006. struct inode *inode,
  2007. struct dentry *dentry)
  2008. {
  2009. int status = 0;
  2010. struct buffer_head *parent_di_bh = NULL;
  2011. handle_t *handle = NULL;
  2012. struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
  2013. struct ocfs2_dinode *dir_di, *di;
  2014. struct inode *orphan_dir_inode = NULL;
  2015. struct buffer_head *orphan_dir_bh = NULL;
  2016. struct buffer_head *di_bh = NULL;
  2017. struct ocfs2_dir_lookup_result lookup = { NULL, };
  2018. mlog_entry("(0x%p, 0x%p, %.*s')\n", dir, dentry,
  2019. dentry->d_name.len, dentry->d_name.name);
  2020. status = ocfs2_inode_lock(dir, &parent_di_bh, 1);
  2021. if (status < 0) {
  2022. if (status != -ENOENT)
  2023. mlog_errno(status);
  2024. return status;
  2025. }
  2026. dir_di = (struct ocfs2_dinode *) parent_di_bh->b_data;
  2027. if (!dir_di->i_links_count) {
  2028. /* can't make a file in a deleted directory. */
  2029. status = -ENOENT;
  2030. goto leave;
  2031. }
  2032. status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
  2033. dentry->d_name.len);
  2034. if (status)
  2035. goto leave;
  2036. /* get a spot inside the dir. */
  2037. status = ocfs2_prepare_dir_for_insert(osb, dir, parent_di_bh,
  2038. dentry->d_name.name,
  2039. dentry->d_name.len, &lookup);
  2040. if (status < 0) {
  2041. mlog_errno(status);
  2042. goto leave;
  2043. }
  2044. orphan_dir_inode = ocfs2_get_system_file_inode(osb,
  2045. ORPHAN_DIR_SYSTEM_INODE,
  2046. osb->slot_num);
  2047. if (!orphan_dir_inode) {
  2048. status = -EEXIST;
  2049. mlog_errno(status);
  2050. goto leave;
  2051. }
  2052. mutex_lock(&orphan_dir_inode->i_mutex);
  2053. status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1);
  2054. if (status < 0) {
  2055. mlog_errno(status);
  2056. mutex_unlock(&orphan_dir_inode->i_mutex);
  2057. iput(orphan_dir_inode);
  2058. goto leave;
  2059. }
  2060. status = ocfs2_read_inode_block(inode, &di_bh);
  2061. if (status < 0) {
  2062. mlog_errno(status);
  2063. goto orphan_unlock;
  2064. }
  2065. handle = ocfs2_start_trans(osb, ocfs2_rename_credits(osb->sb));
  2066. if (IS_ERR(handle)) {
  2067. status = PTR_ERR(handle);
  2068. handle = NULL;
  2069. mlog_errno(status);
  2070. goto orphan_unlock;
  2071. }
  2072. status = ocfs2_journal_access_di(handle, INODE_CACHE(inode),
  2073. di_bh, OCFS2_JOURNAL_ACCESS_WRITE);
  2074. if (status < 0) {
  2075. mlog_errno(status);
  2076. goto out_commit;
  2077. }
  2078. status = ocfs2_orphan_del(osb, handle, orphan_dir_inode, inode,
  2079. orphan_dir_bh);
  2080. if (status < 0) {
  2081. mlog_errno(status);
  2082. goto out_commit;
  2083. }
  2084. di = (struct ocfs2_dinode *)di_bh->b_data;
  2085. le32_add_cpu(&di->i_flags, -OCFS2_ORPHANED_FL);
  2086. di->i_orphaned_slot = 0;
  2087. inode->i_nlink = 1;
  2088. ocfs2_set_links_count(di, inode->i_nlink);
  2089. ocfs2_journal_dirty(handle, di_bh);
  2090. status = ocfs2_add_entry(handle, dentry, inode,
  2091. OCFS2_I(inode)->ip_blkno, parent_di_bh,
  2092. &lookup);
  2093. if (status < 0) {
  2094. mlog_errno(status);
  2095. goto out_commit;
  2096. }
  2097. status = ocfs2_dentry_attach_lock(dentry, inode,
  2098. OCFS2_I(dir)->ip_blkno);
  2099. if (status) {
  2100. mlog_errno(status);
  2101. goto out_commit;
  2102. }
  2103. dentry->d_op = &ocfs2_dentry_ops;
  2104. d_instantiate(dentry, inode);
  2105. status = 0;
  2106. out_commit:
  2107. ocfs2_commit_trans(osb, handle);
  2108. orphan_unlock:
  2109. ocfs2_inode_unlock(orphan_dir_inode, 1);
  2110. mutex_unlock(&orphan_dir_inode->i_mutex);
  2111. iput(orphan_dir_inode);
  2112. leave:
  2113. ocfs2_inode_unlock(dir, 1);
  2114. brelse(di_bh);
  2115. brelse(parent_di_bh);
  2116. brelse(orphan_dir_bh);
  2117. ocfs2_free_dir_lookup_result(&lookup);
  2118. mlog_exit(status);
  2119. return status;
  2120. }
  2121. const struct inode_operations ocfs2_dir_iops = {
  2122. .create = ocfs2_create,
  2123. .lookup = ocfs2_lookup,
  2124. .link = ocfs2_link,
  2125. .unlink = ocfs2_unlink,
  2126. .rmdir = ocfs2_unlink,
  2127. .symlink = ocfs2_symlink,
  2128. .mkdir = ocfs2_mkdir,
  2129. .mknod = ocfs2_mknod,
  2130. .rename = ocfs2_rename,
  2131. .setattr = ocfs2_setattr,
  2132. .getattr = ocfs2_getattr,
  2133. .permission = ocfs2_permission,
  2134. .setxattr = generic_setxattr,
  2135. .getxattr = generic_getxattr,
  2136. .listxattr = ocfs2_listxattr,
  2137. .removexattr = generic_removexattr,
  2138. .fiemap = ocfs2_fiemap,
  2139. };