namei.c 60 KB

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