namei.c 60 KB

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