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