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