inode.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226
  1. #include <linux/ceph/ceph_debug.h>
  2. #include <linux/module.h>
  3. #include <linux/fs.h>
  4. #include <linux/slab.h>
  5. #include <linux/string.h>
  6. #include <linux/uaccess.h>
  7. #include <linux/kernel.h>
  8. #include <linux/writeback.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/xattr.h>
  11. #include <linux/posix_acl.h>
  12. #include <linux/random.h>
  13. #include <linux/sort.h>
  14. #include "super.h"
  15. #include "mds_client.h"
  16. #include "cache.h"
  17. #include <linux/ceph/decode.h>
  18. /*
  19. * Ceph inode operations
  20. *
  21. * Implement basic inode helpers (get, alloc) and inode ops (getattr,
  22. * setattr, etc.), xattr helpers, and helpers for assimilating
  23. * metadata returned by the MDS into our cache.
  24. *
  25. * Also define helpers for doing asynchronous writeback, invalidation,
  26. * and truncation for the benefit of those who can't afford to block
  27. * (typically because they are in the message handler path).
  28. */
  29. static const struct inode_operations ceph_symlink_iops;
  30. static void ceph_invalidate_work(struct work_struct *work);
  31. static void ceph_writeback_work(struct work_struct *work);
  32. static void ceph_vmtruncate_work(struct work_struct *work);
  33. /*
  34. * find or create an inode, given the ceph ino number
  35. */
  36. static int ceph_set_ino_cb(struct inode *inode, void *data)
  37. {
  38. ceph_inode(inode)->i_vino = *(struct ceph_vino *)data;
  39. inode->i_ino = ceph_vino_to_ino(*(struct ceph_vino *)data);
  40. return 0;
  41. }
  42. struct inode *ceph_get_inode(struct super_block *sb, struct ceph_vino vino)
  43. {
  44. struct inode *inode;
  45. ino_t t = ceph_vino_to_ino(vino);
  46. inode = iget5_locked(sb, t, ceph_ino_compare, ceph_set_ino_cb, &vino);
  47. if (inode == NULL)
  48. return ERR_PTR(-ENOMEM);
  49. if (inode->i_state & I_NEW) {
  50. dout("get_inode created new inode %p %llx.%llx ino %llx\n",
  51. inode, ceph_vinop(inode), (u64)inode->i_ino);
  52. unlock_new_inode(inode);
  53. }
  54. dout("get_inode on %lu=%llx.%llx got %p\n", inode->i_ino, vino.ino,
  55. vino.snap, inode);
  56. return inode;
  57. }
  58. /*
  59. * get/constuct snapdir inode for a given directory
  60. */
  61. struct inode *ceph_get_snapdir(struct inode *parent)
  62. {
  63. struct ceph_vino vino = {
  64. .ino = ceph_ino(parent),
  65. .snap = CEPH_SNAPDIR,
  66. };
  67. struct inode *inode = ceph_get_inode(parent->i_sb, vino);
  68. struct ceph_inode_info *ci = ceph_inode(inode);
  69. BUG_ON(!S_ISDIR(parent->i_mode));
  70. if (IS_ERR(inode))
  71. return inode;
  72. inode->i_mode = parent->i_mode;
  73. inode->i_uid = parent->i_uid;
  74. inode->i_gid = parent->i_gid;
  75. inode->i_op = &ceph_snapdir_iops;
  76. inode->i_fop = &ceph_snapdir_fops;
  77. ci->i_snap_caps = CEPH_CAP_PIN; /* so we can open */
  78. ci->i_rbytes = 0;
  79. return inode;
  80. }
  81. const struct inode_operations ceph_file_iops = {
  82. .permission = ceph_permission,
  83. .setattr = ceph_setattr,
  84. .getattr = ceph_getattr,
  85. .setxattr = generic_setxattr,
  86. .getxattr = generic_getxattr,
  87. .listxattr = ceph_listxattr,
  88. .removexattr = generic_removexattr,
  89. .get_acl = ceph_get_acl,
  90. .set_acl = ceph_set_acl,
  91. };
  92. /*
  93. * We use a 'frag tree' to keep track of the MDS's directory fragments
  94. * for a given inode (usually there is just a single fragment). We
  95. * need to know when a child frag is delegated to a new MDS, or when
  96. * it is flagged as replicated, so we can direct our requests
  97. * accordingly.
  98. */
  99. /*
  100. * find/create a frag in the tree
  101. */
  102. static struct ceph_inode_frag *__get_or_create_frag(struct ceph_inode_info *ci,
  103. u32 f)
  104. {
  105. struct rb_node **p;
  106. struct rb_node *parent = NULL;
  107. struct ceph_inode_frag *frag;
  108. int c;
  109. p = &ci->i_fragtree.rb_node;
  110. while (*p) {
  111. parent = *p;
  112. frag = rb_entry(parent, struct ceph_inode_frag, node);
  113. c = ceph_frag_compare(f, frag->frag);
  114. if (c < 0)
  115. p = &(*p)->rb_left;
  116. else if (c > 0)
  117. p = &(*p)->rb_right;
  118. else
  119. return frag;
  120. }
  121. frag = kmalloc(sizeof(*frag), GFP_NOFS);
  122. if (!frag) {
  123. pr_err("__get_or_create_frag ENOMEM on %p %llx.%llx "
  124. "frag %x\n", &ci->vfs_inode,
  125. ceph_vinop(&ci->vfs_inode), f);
  126. return ERR_PTR(-ENOMEM);
  127. }
  128. frag->frag = f;
  129. frag->split_by = 0;
  130. frag->mds = -1;
  131. frag->ndist = 0;
  132. rb_link_node(&frag->node, parent, p);
  133. rb_insert_color(&frag->node, &ci->i_fragtree);
  134. dout("get_or_create_frag added %llx.%llx frag %x\n",
  135. ceph_vinop(&ci->vfs_inode), f);
  136. return frag;
  137. }
  138. /*
  139. * find a specific frag @f
  140. */
  141. struct ceph_inode_frag *__ceph_find_frag(struct ceph_inode_info *ci, u32 f)
  142. {
  143. struct rb_node *n = ci->i_fragtree.rb_node;
  144. while (n) {
  145. struct ceph_inode_frag *frag =
  146. rb_entry(n, struct ceph_inode_frag, node);
  147. int c = ceph_frag_compare(f, frag->frag);
  148. if (c < 0)
  149. n = n->rb_left;
  150. else if (c > 0)
  151. n = n->rb_right;
  152. else
  153. return frag;
  154. }
  155. return NULL;
  156. }
  157. /*
  158. * Choose frag containing the given value @v. If @pfrag is
  159. * specified, copy the frag delegation info to the caller if
  160. * it is present.
  161. */
  162. static u32 __ceph_choose_frag(struct ceph_inode_info *ci, u32 v,
  163. struct ceph_inode_frag *pfrag, int *found)
  164. {
  165. u32 t = ceph_frag_make(0, 0);
  166. struct ceph_inode_frag *frag;
  167. unsigned nway, i;
  168. u32 n;
  169. if (found)
  170. *found = 0;
  171. while (1) {
  172. WARN_ON(!ceph_frag_contains_value(t, v));
  173. frag = __ceph_find_frag(ci, t);
  174. if (!frag)
  175. break; /* t is a leaf */
  176. if (frag->split_by == 0) {
  177. if (pfrag)
  178. memcpy(pfrag, frag, sizeof(*pfrag));
  179. if (found)
  180. *found = 1;
  181. break;
  182. }
  183. /* choose child */
  184. nway = 1 << frag->split_by;
  185. dout("choose_frag(%x) %x splits by %d (%d ways)\n", v, t,
  186. frag->split_by, nway);
  187. for (i = 0; i < nway; i++) {
  188. n = ceph_frag_make_child(t, frag->split_by, i);
  189. if (ceph_frag_contains_value(n, v)) {
  190. t = n;
  191. break;
  192. }
  193. }
  194. BUG_ON(i == nway);
  195. }
  196. dout("choose_frag(%x) = %x\n", v, t);
  197. return t;
  198. }
  199. u32 ceph_choose_frag(struct ceph_inode_info *ci, u32 v,
  200. struct ceph_inode_frag *pfrag, int *found)
  201. {
  202. u32 ret;
  203. mutex_lock(&ci->i_fragtree_mutex);
  204. ret = __ceph_choose_frag(ci, v, pfrag, found);
  205. mutex_unlock(&ci->i_fragtree_mutex);
  206. return ret;
  207. }
  208. /*
  209. * Process dirfrag (delegation) info from the mds. Include leaf
  210. * fragment in tree ONLY if ndist > 0. Otherwise, only
  211. * branches/splits are included in i_fragtree)
  212. */
  213. static int ceph_fill_dirfrag(struct inode *inode,
  214. struct ceph_mds_reply_dirfrag *dirinfo)
  215. {
  216. struct ceph_inode_info *ci = ceph_inode(inode);
  217. struct ceph_inode_frag *frag;
  218. u32 id = le32_to_cpu(dirinfo->frag);
  219. int mds = le32_to_cpu(dirinfo->auth);
  220. int ndist = le32_to_cpu(dirinfo->ndist);
  221. int diri_auth = -1;
  222. int i;
  223. int err = 0;
  224. spin_lock(&ci->i_ceph_lock);
  225. if (ci->i_auth_cap)
  226. diri_auth = ci->i_auth_cap->mds;
  227. spin_unlock(&ci->i_ceph_lock);
  228. if (mds == -1) /* CDIR_AUTH_PARENT */
  229. mds = diri_auth;
  230. mutex_lock(&ci->i_fragtree_mutex);
  231. if (ndist == 0 && mds == diri_auth) {
  232. /* no delegation info needed. */
  233. frag = __ceph_find_frag(ci, id);
  234. if (!frag)
  235. goto out;
  236. if (frag->split_by == 0) {
  237. /* tree leaf, remove */
  238. dout("fill_dirfrag removed %llx.%llx frag %x"
  239. " (no ref)\n", ceph_vinop(inode), id);
  240. rb_erase(&frag->node, &ci->i_fragtree);
  241. kfree(frag);
  242. } else {
  243. /* tree branch, keep and clear */
  244. dout("fill_dirfrag cleared %llx.%llx frag %x"
  245. " referral\n", ceph_vinop(inode), id);
  246. frag->mds = -1;
  247. frag->ndist = 0;
  248. }
  249. goto out;
  250. }
  251. /* find/add this frag to store mds delegation info */
  252. frag = __get_or_create_frag(ci, id);
  253. if (IS_ERR(frag)) {
  254. /* this is not the end of the world; we can continue
  255. with bad/inaccurate delegation info */
  256. pr_err("fill_dirfrag ENOMEM on mds ref %llx.%llx fg %x\n",
  257. ceph_vinop(inode), le32_to_cpu(dirinfo->frag));
  258. err = -ENOMEM;
  259. goto out;
  260. }
  261. frag->mds = mds;
  262. frag->ndist = min_t(u32, ndist, CEPH_MAX_DIRFRAG_REP);
  263. for (i = 0; i < frag->ndist; i++)
  264. frag->dist[i] = le32_to_cpu(dirinfo->dist[i]);
  265. dout("fill_dirfrag %llx.%llx frag %x ndist=%d\n",
  266. ceph_vinop(inode), frag->frag, frag->ndist);
  267. out:
  268. mutex_unlock(&ci->i_fragtree_mutex);
  269. return err;
  270. }
  271. static int frag_tree_split_cmp(const void *l, const void *r)
  272. {
  273. struct ceph_frag_tree_split *ls = (struct ceph_frag_tree_split*)l;
  274. struct ceph_frag_tree_split *rs = (struct ceph_frag_tree_split*)r;
  275. return ceph_frag_compare(ls->frag, rs->frag);
  276. }
  277. static bool is_frag_child(u32 f, struct ceph_inode_frag *frag)
  278. {
  279. if (!frag)
  280. return f == ceph_frag_make(0, 0);
  281. if (ceph_frag_bits(f) != ceph_frag_bits(frag->frag) + frag->split_by)
  282. return false;
  283. return ceph_frag_contains_value(frag->frag, ceph_frag_value(f));
  284. }
  285. static int ceph_fill_fragtree(struct inode *inode,
  286. struct ceph_frag_tree_head *fragtree,
  287. struct ceph_mds_reply_dirfrag *dirinfo)
  288. {
  289. struct ceph_inode_info *ci = ceph_inode(inode);
  290. struct ceph_inode_frag *frag, *prev_frag = NULL;
  291. struct rb_node *rb_node;
  292. unsigned i, split_by, nsplits;
  293. u32 id;
  294. bool update = false;
  295. mutex_lock(&ci->i_fragtree_mutex);
  296. nsplits = le32_to_cpu(fragtree->nsplits);
  297. if (nsplits != ci->i_fragtree_nsplits) {
  298. update = true;
  299. } else if (nsplits) {
  300. i = prandom_u32() % nsplits;
  301. id = le32_to_cpu(fragtree->splits[i].frag);
  302. if (!__ceph_find_frag(ci, id))
  303. update = true;
  304. } else if (!RB_EMPTY_ROOT(&ci->i_fragtree)) {
  305. rb_node = rb_first(&ci->i_fragtree);
  306. frag = rb_entry(rb_node, struct ceph_inode_frag, node);
  307. if (frag->frag != ceph_frag_make(0, 0) || rb_next(rb_node))
  308. update = true;
  309. }
  310. if (!update && dirinfo) {
  311. id = le32_to_cpu(dirinfo->frag);
  312. if (id != __ceph_choose_frag(ci, id, NULL, NULL))
  313. update = true;
  314. }
  315. if (!update)
  316. goto out_unlock;
  317. if (nsplits > 1) {
  318. sort(fragtree->splits, nsplits, sizeof(fragtree->splits[0]),
  319. frag_tree_split_cmp, NULL);
  320. }
  321. dout("fill_fragtree %llx.%llx\n", ceph_vinop(inode));
  322. rb_node = rb_first(&ci->i_fragtree);
  323. for (i = 0; i < nsplits; i++) {
  324. id = le32_to_cpu(fragtree->splits[i].frag);
  325. split_by = le32_to_cpu(fragtree->splits[i].by);
  326. if (split_by == 0 || ceph_frag_bits(id) + split_by > 24) {
  327. pr_err("fill_fragtree %llx.%llx invalid split %d/%u, "
  328. "frag %x split by %d\n", ceph_vinop(inode),
  329. i, nsplits, id, split_by);
  330. continue;
  331. }
  332. frag = NULL;
  333. while (rb_node) {
  334. frag = rb_entry(rb_node, struct ceph_inode_frag, node);
  335. if (ceph_frag_compare(frag->frag, id) >= 0) {
  336. if (frag->frag != id)
  337. frag = NULL;
  338. else
  339. rb_node = rb_next(rb_node);
  340. break;
  341. }
  342. rb_node = rb_next(rb_node);
  343. /* delete stale split/leaf node */
  344. if (frag->split_by > 0 ||
  345. !is_frag_child(frag->frag, prev_frag)) {
  346. rb_erase(&frag->node, &ci->i_fragtree);
  347. if (frag->split_by > 0)
  348. ci->i_fragtree_nsplits--;
  349. kfree(frag);
  350. }
  351. frag = NULL;
  352. }
  353. if (!frag) {
  354. frag = __get_or_create_frag(ci, id);
  355. if (IS_ERR(frag))
  356. continue;
  357. }
  358. if (frag->split_by == 0)
  359. ci->i_fragtree_nsplits++;
  360. frag->split_by = split_by;
  361. dout(" frag %x split by %d\n", frag->frag, frag->split_by);
  362. prev_frag = frag;
  363. }
  364. while (rb_node) {
  365. frag = rb_entry(rb_node, struct ceph_inode_frag, node);
  366. rb_node = rb_next(rb_node);
  367. /* delete stale split/leaf node */
  368. if (frag->split_by > 0 ||
  369. !is_frag_child(frag->frag, prev_frag)) {
  370. rb_erase(&frag->node, &ci->i_fragtree);
  371. if (frag->split_by > 0)
  372. ci->i_fragtree_nsplits--;
  373. kfree(frag);
  374. }
  375. }
  376. out_unlock:
  377. mutex_unlock(&ci->i_fragtree_mutex);
  378. return 0;
  379. }
  380. /*
  381. * initialize a newly allocated inode.
  382. */
  383. struct inode *ceph_alloc_inode(struct super_block *sb)
  384. {
  385. struct ceph_inode_info *ci;
  386. int i;
  387. ci = kmem_cache_alloc(ceph_inode_cachep, GFP_NOFS);
  388. if (!ci)
  389. return NULL;
  390. dout("alloc_inode %p\n", &ci->vfs_inode);
  391. spin_lock_init(&ci->i_ceph_lock);
  392. ci->i_version = 0;
  393. ci->i_inline_version = 0;
  394. ci->i_time_warp_seq = 0;
  395. ci->i_ceph_flags = 0;
  396. atomic64_set(&ci->i_ordered_count, 1);
  397. atomic64_set(&ci->i_release_count, 1);
  398. atomic64_set(&ci->i_complete_seq[0], 0);
  399. atomic64_set(&ci->i_complete_seq[1], 0);
  400. ci->i_symlink = NULL;
  401. memset(&ci->i_dir_layout, 0, sizeof(ci->i_dir_layout));
  402. RCU_INIT_POINTER(ci->i_layout.pool_ns, NULL);
  403. ci->i_fragtree = RB_ROOT;
  404. mutex_init(&ci->i_fragtree_mutex);
  405. ci->i_xattrs.blob = NULL;
  406. ci->i_xattrs.prealloc_blob = NULL;
  407. ci->i_xattrs.dirty = false;
  408. ci->i_xattrs.index = RB_ROOT;
  409. ci->i_xattrs.count = 0;
  410. ci->i_xattrs.names_size = 0;
  411. ci->i_xattrs.vals_size = 0;
  412. ci->i_xattrs.version = 0;
  413. ci->i_xattrs.index_version = 0;
  414. ci->i_caps = RB_ROOT;
  415. ci->i_auth_cap = NULL;
  416. ci->i_dirty_caps = 0;
  417. ci->i_flushing_caps = 0;
  418. INIT_LIST_HEAD(&ci->i_dirty_item);
  419. INIT_LIST_HEAD(&ci->i_flushing_item);
  420. ci->i_prealloc_cap_flush = NULL;
  421. INIT_LIST_HEAD(&ci->i_cap_flush_list);
  422. init_waitqueue_head(&ci->i_cap_wq);
  423. ci->i_hold_caps_min = 0;
  424. ci->i_hold_caps_max = 0;
  425. INIT_LIST_HEAD(&ci->i_cap_delay_list);
  426. INIT_LIST_HEAD(&ci->i_cap_snaps);
  427. ci->i_head_snapc = NULL;
  428. ci->i_snap_caps = 0;
  429. for (i = 0; i < CEPH_FILE_MODE_BITS; i++)
  430. ci->i_nr_by_mode[i] = 0;
  431. mutex_init(&ci->i_truncate_mutex);
  432. ci->i_truncate_seq = 0;
  433. ci->i_truncate_size = 0;
  434. ci->i_truncate_pending = 0;
  435. ci->i_max_size = 0;
  436. ci->i_reported_size = 0;
  437. ci->i_wanted_max_size = 0;
  438. ci->i_requested_max_size = 0;
  439. ci->i_pin_ref = 0;
  440. ci->i_rd_ref = 0;
  441. ci->i_rdcache_ref = 0;
  442. ci->i_wr_ref = 0;
  443. ci->i_wb_ref = 0;
  444. ci->i_wrbuffer_ref = 0;
  445. ci->i_wrbuffer_ref_head = 0;
  446. ci->i_shared_gen = 0;
  447. ci->i_rdcache_gen = 0;
  448. ci->i_rdcache_revoking = 0;
  449. INIT_LIST_HEAD(&ci->i_unsafe_writes);
  450. INIT_LIST_HEAD(&ci->i_unsafe_dirops);
  451. INIT_LIST_HEAD(&ci->i_unsafe_iops);
  452. spin_lock_init(&ci->i_unsafe_lock);
  453. ci->i_snap_realm = NULL;
  454. INIT_LIST_HEAD(&ci->i_snap_realm_item);
  455. INIT_LIST_HEAD(&ci->i_snap_flush_item);
  456. INIT_WORK(&ci->i_wb_work, ceph_writeback_work);
  457. INIT_WORK(&ci->i_pg_inv_work, ceph_invalidate_work);
  458. INIT_WORK(&ci->i_vmtruncate_work, ceph_vmtruncate_work);
  459. ceph_fscache_inode_init(ci);
  460. return &ci->vfs_inode;
  461. }
  462. static void ceph_i_callback(struct rcu_head *head)
  463. {
  464. struct inode *inode = container_of(head, struct inode, i_rcu);
  465. struct ceph_inode_info *ci = ceph_inode(inode);
  466. kmem_cache_free(ceph_inode_cachep, ci);
  467. }
  468. void ceph_destroy_inode(struct inode *inode)
  469. {
  470. struct ceph_inode_info *ci = ceph_inode(inode);
  471. struct ceph_inode_frag *frag;
  472. struct rb_node *n;
  473. dout("destroy_inode %p ino %llx.%llx\n", inode, ceph_vinop(inode));
  474. ceph_fscache_unregister_inode_cookie(ci);
  475. ceph_queue_caps_release(inode);
  476. /*
  477. * we may still have a snap_realm reference if there are stray
  478. * caps in i_snap_caps.
  479. */
  480. if (ci->i_snap_realm) {
  481. struct ceph_mds_client *mdsc =
  482. ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc;
  483. struct ceph_snap_realm *realm = ci->i_snap_realm;
  484. dout(" dropping residual ref to snap realm %p\n", realm);
  485. spin_lock(&realm->inodes_with_caps_lock);
  486. list_del_init(&ci->i_snap_realm_item);
  487. spin_unlock(&realm->inodes_with_caps_lock);
  488. ceph_put_snap_realm(mdsc, realm);
  489. }
  490. kfree(ci->i_symlink);
  491. while ((n = rb_first(&ci->i_fragtree)) != NULL) {
  492. frag = rb_entry(n, struct ceph_inode_frag, node);
  493. rb_erase(n, &ci->i_fragtree);
  494. kfree(frag);
  495. }
  496. ci->i_fragtree_nsplits = 0;
  497. __ceph_destroy_xattrs(ci);
  498. if (ci->i_xattrs.blob)
  499. ceph_buffer_put(ci->i_xattrs.blob);
  500. if (ci->i_xattrs.prealloc_blob)
  501. ceph_buffer_put(ci->i_xattrs.prealloc_blob);
  502. ceph_put_string(rcu_dereference_raw(ci->i_layout.pool_ns));
  503. call_rcu(&inode->i_rcu, ceph_i_callback);
  504. }
  505. int ceph_drop_inode(struct inode *inode)
  506. {
  507. /*
  508. * Positve dentry and corresponding inode are always accompanied
  509. * in MDS reply. So no need to keep inode in the cache after
  510. * dropping all its aliases.
  511. */
  512. return 1;
  513. }
  514. void ceph_evict_inode(struct inode *inode)
  515. {
  516. /* wait unsafe sync writes */
  517. ceph_sync_write_wait(inode);
  518. truncate_inode_pages_final(&inode->i_data);
  519. clear_inode(inode);
  520. }
  521. static inline blkcnt_t calc_inode_blocks(u64 size)
  522. {
  523. return (size + (1<<9) - 1) >> 9;
  524. }
  525. /*
  526. * Helpers to fill in size, ctime, mtime, and atime. We have to be
  527. * careful because either the client or MDS may have more up to date
  528. * info, depending on which capabilities are held, and whether
  529. * time_warp_seq or truncate_seq have increased. (Ordinarily, mtime
  530. * and size are monotonically increasing, except when utimes() or
  531. * truncate() increments the corresponding _seq values.)
  532. */
  533. int ceph_fill_file_size(struct inode *inode, int issued,
  534. u32 truncate_seq, u64 truncate_size, u64 size)
  535. {
  536. struct ceph_inode_info *ci = ceph_inode(inode);
  537. int queue_trunc = 0;
  538. if (ceph_seq_cmp(truncate_seq, ci->i_truncate_seq) > 0 ||
  539. (truncate_seq == ci->i_truncate_seq && size > inode->i_size)) {
  540. dout("size %lld -> %llu\n", inode->i_size, size);
  541. if (size > 0 && S_ISDIR(inode->i_mode)) {
  542. pr_err("fill_file_size non-zero size for directory\n");
  543. size = 0;
  544. }
  545. i_size_write(inode, size);
  546. inode->i_blocks = calc_inode_blocks(size);
  547. ci->i_reported_size = size;
  548. if (truncate_seq != ci->i_truncate_seq) {
  549. dout("truncate_seq %u -> %u\n",
  550. ci->i_truncate_seq, truncate_seq);
  551. ci->i_truncate_seq = truncate_seq;
  552. /* the MDS should have revoked these caps */
  553. WARN_ON_ONCE(issued & (CEPH_CAP_FILE_EXCL |
  554. CEPH_CAP_FILE_RD |
  555. CEPH_CAP_FILE_WR |
  556. CEPH_CAP_FILE_LAZYIO));
  557. /*
  558. * If we hold relevant caps, or in the case where we're
  559. * not the only client referencing this file and we
  560. * don't hold those caps, then we need to check whether
  561. * the file is either opened or mmaped
  562. */
  563. if ((issued & (CEPH_CAP_FILE_CACHE|
  564. CEPH_CAP_FILE_BUFFER)) ||
  565. mapping_mapped(inode->i_mapping) ||
  566. __ceph_caps_file_wanted(ci)) {
  567. ci->i_truncate_pending++;
  568. queue_trunc = 1;
  569. }
  570. }
  571. }
  572. if (ceph_seq_cmp(truncate_seq, ci->i_truncate_seq) >= 0 &&
  573. ci->i_truncate_size != truncate_size) {
  574. dout("truncate_size %lld -> %llu\n", ci->i_truncate_size,
  575. truncate_size);
  576. ci->i_truncate_size = truncate_size;
  577. }
  578. if (queue_trunc)
  579. ceph_fscache_invalidate(inode);
  580. return queue_trunc;
  581. }
  582. void ceph_fill_file_time(struct inode *inode, int issued,
  583. u64 time_warp_seq, struct timespec *ctime,
  584. struct timespec *mtime, struct timespec *atime)
  585. {
  586. struct ceph_inode_info *ci = ceph_inode(inode);
  587. int warn = 0;
  588. if (issued & (CEPH_CAP_FILE_EXCL|
  589. CEPH_CAP_FILE_WR|
  590. CEPH_CAP_FILE_BUFFER|
  591. CEPH_CAP_AUTH_EXCL|
  592. CEPH_CAP_XATTR_EXCL)) {
  593. if (timespec_compare(ctime, &inode->i_ctime) > 0) {
  594. dout("ctime %ld.%09ld -> %ld.%09ld inc w/ cap\n",
  595. inode->i_ctime.tv_sec, inode->i_ctime.tv_nsec,
  596. ctime->tv_sec, ctime->tv_nsec);
  597. inode->i_ctime = *ctime;
  598. }
  599. if (ceph_seq_cmp(time_warp_seq, ci->i_time_warp_seq) > 0) {
  600. /* the MDS did a utimes() */
  601. dout("mtime %ld.%09ld -> %ld.%09ld "
  602. "tw %d -> %d\n",
  603. inode->i_mtime.tv_sec, inode->i_mtime.tv_nsec,
  604. mtime->tv_sec, mtime->tv_nsec,
  605. ci->i_time_warp_seq, (int)time_warp_seq);
  606. inode->i_mtime = *mtime;
  607. inode->i_atime = *atime;
  608. ci->i_time_warp_seq = time_warp_seq;
  609. } else if (time_warp_seq == ci->i_time_warp_seq) {
  610. /* nobody did utimes(); take the max */
  611. if (timespec_compare(mtime, &inode->i_mtime) > 0) {
  612. dout("mtime %ld.%09ld -> %ld.%09ld inc\n",
  613. inode->i_mtime.tv_sec,
  614. inode->i_mtime.tv_nsec,
  615. mtime->tv_sec, mtime->tv_nsec);
  616. inode->i_mtime = *mtime;
  617. }
  618. if (timespec_compare(atime, &inode->i_atime) > 0) {
  619. dout("atime %ld.%09ld -> %ld.%09ld inc\n",
  620. inode->i_atime.tv_sec,
  621. inode->i_atime.tv_nsec,
  622. atime->tv_sec, atime->tv_nsec);
  623. inode->i_atime = *atime;
  624. }
  625. } else if (issued & CEPH_CAP_FILE_EXCL) {
  626. /* we did a utimes(); ignore mds values */
  627. } else {
  628. warn = 1;
  629. }
  630. } else {
  631. /* we have no write|excl caps; whatever the MDS says is true */
  632. if (ceph_seq_cmp(time_warp_seq, ci->i_time_warp_seq) >= 0) {
  633. inode->i_ctime = *ctime;
  634. inode->i_mtime = *mtime;
  635. inode->i_atime = *atime;
  636. ci->i_time_warp_seq = time_warp_seq;
  637. } else {
  638. warn = 1;
  639. }
  640. }
  641. if (warn) /* time_warp_seq shouldn't go backwards */
  642. dout("%p mds time_warp_seq %llu < %u\n",
  643. inode, time_warp_seq, ci->i_time_warp_seq);
  644. }
  645. /*
  646. * Populate an inode based on info from mds. May be called on new or
  647. * existing inodes.
  648. */
  649. static int fill_inode(struct inode *inode, struct page *locked_page,
  650. struct ceph_mds_reply_info_in *iinfo,
  651. struct ceph_mds_reply_dirfrag *dirinfo,
  652. struct ceph_mds_session *session,
  653. unsigned long ttl_from, int cap_fmode,
  654. struct ceph_cap_reservation *caps_reservation)
  655. {
  656. struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
  657. struct ceph_mds_reply_inode *info = iinfo->in;
  658. struct ceph_inode_info *ci = ceph_inode(inode);
  659. int issued = 0, implemented, new_issued;
  660. struct timespec mtime, atime, ctime;
  661. struct ceph_buffer *xattr_blob = NULL;
  662. struct ceph_string *pool_ns = NULL;
  663. struct ceph_cap *new_cap = NULL;
  664. int err = 0;
  665. bool wake = false;
  666. bool queue_trunc = false;
  667. bool new_version = false;
  668. bool fill_inline = false;
  669. dout("fill_inode %p ino %llx.%llx v %llu had %llu\n",
  670. inode, ceph_vinop(inode), le64_to_cpu(info->version),
  671. ci->i_version);
  672. /* prealloc new cap struct */
  673. if (info->cap.caps && ceph_snap(inode) == CEPH_NOSNAP)
  674. new_cap = ceph_get_cap(mdsc, caps_reservation);
  675. /*
  676. * prealloc xattr data, if it looks like we'll need it. only
  677. * if len > 4 (meaning there are actually xattrs; the first 4
  678. * bytes are the xattr count).
  679. */
  680. if (iinfo->xattr_len > 4) {
  681. xattr_blob = ceph_buffer_new(iinfo->xattr_len, GFP_NOFS);
  682. if (!xattr_blob)
  683. pr_err("fill_inode ENOMEM xattr blob %d bytes\n",
  684. iinfo->xattr_len);
  685. }
  686. if (iinfo->pool_ns_len > 0)
  687. pool_ns = ceph_find_or_create_string(iinfo->pool_ns_data,
  688. iinfo->pool_ns_len);
  689. spin_lock(&ci->i_ceph_lock);
  690. /*
  691. * provided version will be odd if inode value is projected,
  692. * even if stable. skip the update if we have newer stable
  693. * info (ours>=theirs, e.g. due to racing mds replies), unless
  694. * we are getting projected (unstable) info (in which case the
  695. * version is odd, and we want ours>theirs).
  696. * us them
  697. * 2 2 skip
  698. * 3 2 skip
  699. * 3 3 update
  700. */
  701. if (ci->i_version == 0 ||
  702. ((info->cap.flags & CEPH_CAP_FLAG_AUTH) &&
  703. le64_to_cpu(info->version) > (ci->i_version & ~1)))
  704. new_version = true;
  705. issued = __ceph_caps_issued(ci, &implemented);
  706. issued |= implemented | __ceph_caps_dirty(ci);
  707. new_issued = ~issued & le32_to_cpu(info->cap.caps);
  708. /* update inode */
  709. ci->i_version = le64_to_cpu(info->version);
  710. inode->i_version++;
  711. inode->i_rdev = le32_to_cpu(info->rdev);
  712. inode->i_blkbits = fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
  713. if ((new_version || (new_issued & CEPH_CAP_AUTH_SHARED)) &&
  714. (issued & CEPH_CAP_AUTH_EXCL) == 0) {
  715. inode->i_mode = le32_to_cpu(info->mode);
  716. inode->i_uid = make_kuid(&init_user_ns, le32_to_cpu(info->uid));
  717. inode->i_gid = make_kgid(&init_user_ns, le32_to_cpu(info->gid));
  718. dout("%p mode 0%o uid.gid %d.%d\n", inode, inode->i_mode,
  719. from_kuid(&init_user_ns, inode->i_uid),
  720. from_kgid(&init_user_ns, inode->i_gid));
  721. }
  722. if ((new_version || (new_issued & CEPH_CAP_LINK_SHARED)) &&
  723. (issued & CEPH_CAP_LINK_EXCL) == 0)
  724. set_nlink(inode, le32_to_cpu(info->nlink));
  725. if (new_version || (new_issued & CEPH_CAP_ANY_RD)) {
  726. /* be careful with mtime, atime, size */
  727. ceph_decode_timespec(&atime, &info->atime);
  728. ceph_decode_timespec(&mtime, &info->mtime);
  729. ceph_decode_timespec(&ctime, &info->ctime);
  730. ceph_fill_file_time(inode, issued,
  731. le32_to_cpu(info->time_warp_seq),
  732. &ctime, &mtime, &atime);
  733. }
  734. if (new_version ||
  735. (new_issued & (CEPH_CAP_ANY_FILE_RD | CEPH_CAP_ANY_FILE_WR))) {
  736. s64 old_pool = ci->i_layout.pool_id;
  737. struct ceph_string *old_ns;
  738. ceph_file_layout_from_legacy(&ci->i_layout, &info->layout);
  739. old_ns = rcu_dereference_protected(ci->i_layout.pool_ns,
  740. lockdep_is_held(&ci->i_ceph_lock));
  741. rcu_assign_pointer(ci->i_layout.pool_ns, pool_ns);
  742. if (ci->i_layout.pool_id != old_pool || pool_ns != old_ns)
  743. ci->i_ceph_flags &= ~CEPH_I_POOL_PERM;
  744. pool_ns = old_ns;
  745. queue_trunc = ceph_fill_file_size(inode, issued,
  746. le32_to_cpu(info->truncate_seq),
  747. le64_to_cpu(info->truncate_size),
  748. le64_to_cpu(info->size));
  749. /* only update max_size on auth cap */
  750. if ((info->cap.flags & CEPH_CAP_FLAG_AUTH) &&
  751. ci->i_max_size != le64_to_cpu(info->max_size)) {
  752. dout("max_size %lld -> %llu\n", ci->i_max_size,
  753. le64_to_cpu(info->max_size));
  754. ci->i_max_size = le64_to_cpu(info->max_size);
  755. }
  756. }
  757. /* xattrs */
  758. /* note that if i_xattrs.len <= 4, i_xattrs.data will still be NULL. */
  759. if ((ci->i_xattrs.version == 0 || !(issued & CEPH_CAP_XATTR_EXCL)) &&
  760. le64_to_cpu(info->xattr_version) > ci->i_xattrs.version) {
  761. if (ci->i_xattrs.blob)
  762. ceph_buffer_put(ci->i_xattrs.blob);
  763. ci->i_xattrs.blob = xattr_blob;
  764. if (xattr_blob)
  765. memcpy(ci->i_xattrs.blob->vec.iov_base,
  766. iinfo->xattr_data, iinfo->xattr_len);
  767. ci->i_xattrs.version = le64_to_cpu(info->xattr_version);
  768. ceph_forget_all_cached_acls(inode);
  769. xattr_blob = NULL;
  770. }
  771. inode->i_mapping->a_ops = &ceph_aops;
  772. switch (inode->i_mode & S_IFMT) {
  773. case S_IFIFO:
  774. case S_IFBLK:
  775. case S_IFCHR:
  776. case S_IFSOCK:
  777. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  778. inode->i_op = &ceph_file_iops;
  779. break;
  780. case S_IFREG:
  781. inode->i_op = &ceph_file_iops;
  782. inode->i_fop = &ceph_file_fops;
  783. break;
  784. case S_IFLNK:
  785. inode->i_op = &ceph_symlink_iops;
  786. if (!ci->i_symlink) {
  787. u32 symlen = iinfo->symlink_len;
  788. char *sym;
  789. spin_unlock(&ci->i_ceph_lock);
  790. if (symlen != i_size_read(inode)) {
  791. pr_err("fill_inode %llx.%llx BAD symlink "
  792. "size %lld\n", ceph_vinop(inode),
  793. i_size_read(inode));
  794. i_size_write(inode, symlen);
  795. inode->i_blocks = calc_inode_blocks(symlen);
  796. }
  797. err = -ENOMEM;
  798. sym = kstrndup(iinfo->symlink, symlen, GFP_NOFS);
  799. if (!sym)
  800. goto out;
  801. spin_lock(&ci->i_ceph_lock);
  802. if (!ci->i_symlink)
  803. ci->i_symlink = sym;
  804. else
  805. kfree(sym); /* lost a race */
  806. }
  807. inode->i_link = ci->i_symlink;
  808. break;
  809. case S_IFDIR:
  810. inode->i_op = &ceph_dir_iops;
  811. inode->i_fop = &ceph_dir_fops;
  812. ci->i_dir_layout = iinfo->dir_layout;
  813. ci->i_files = le64_to_cpu(info->files);
  814. ci->i_subdirs = le64_to_cpu(info->subdirs);
  815. ci->i_rbytes = le64_to_cpu(info->rbytes);
  816. ci->i_rfiles = le64_to_cpu(info->rfiles);
  817. ci->i_rsubdirs = le64_to_cpu(info->rsubdirs);
  818. ceph_decode_timespec(&ci->i_rctime, &info->rctime);
  819. break;
  820. default:
  821. pr_err("fill_inode %llx.%llx BAD mode 0%o\n",
  822. ceph_vinop(inode), inode->i_mode);
  823. }
  824. /* were we issued a capability? */
  825. if (info->cap.caps) {
  826. if (ceph_snap(inode) == CEPH_NOSNAP) {
  827. unsigned caps = le32_to_cpu(info->cap.caps);
  828. ceph_add_cap(inode, session,
  829. le64_to_cpu(info->cap.cap_id),
  830. cap_fmode, caps,
  831. le32_to_cpu(info->cap.wanted),
  832. le32_to_cpu(info->cap.seq),
  833. le32_to_cpu(info->cap.mseq),
  834. le64_to_cpu(info->cap.realm),
  835. info->cap.flags, &new_cap);
  836. /* set dir completion flag? */
  837. if (S_ISDIR(inode->i_mode) &&
  838. ci->i_files == 0 && ci->i_subdirs == 0 &&
  839. (caps & CEPH_CAP_FILE_SHARED) &&
  840. (issued & CEPH_CAP_FILE_EXCL) == 0 &&
  841. !__ceph_dir_is_complete(ci)) {
  842. dout(" marking %p complete (empty)\n", inode);
  843. i_size_write(inode, 0);
  844. __ceph_dir_set_complete(ci,
  845. atomic64_read(&ci->i_release_count),
  846. atomic64_read(&ci->i_ordered_count));
  847. }
  848. wake = true;
  849. } else {
  850. dout(" %p got snap_caps %s\n", inode,
  851. ceph_cap_string(le32_to_cpu(info->cap.caps)));
  852. ci->i_snap_caps |= le32_to_cpu(info->cap.caps);
  853. if (cap_fmode >= 0)
  854. __ceph_get_fmode(ci, cap_fmode);
  855. }
  856. } else if (cap_fmode >= 0) {
  857. pr_warn("mds issued no caps on %llx.%llx\n",
  858. ceph_vinop(inode));
  859. __ceph_get_fmode(ci, cap_fmode);
  860. }
  861. if (iinfo->inline_version > 0 &&
  862. iinfo->inline_version >= ci->i_inline_version) {
  863. int cache_caps = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO;
  864. ci->i_inline_version = iinfo->inline_version;
  865. if (ci->i_inline_version != CEPH_INLINE_NONE &&
  866. (locked_page ||
  867. (le32_to_cpu(info->cap.caps) & cache_caps)))
  868. fill_inline = true;
  869. }
  870. spin_unlock(&ci->i_ceph_lock);
  871. if (fill_inline)
  872. ceph_fill_inline_data(inode, locked_page,
  873. iinfo->inline_data, iinfo->inline_len);
  874. if (wake)
  875. wake_up_all(&ci->i_cap_wq);
  876. /* queue truncate if we saw i_size decrease */
  877. if (queue_trunc)
  878. ceph_queue_vmtruncate(inode);
  879. /* populate frag tree */
  880. if (S_ISDIR(inode->i_mode))
  881. ceph_fill_fragtree(inode, &info->fragtree, dirinfo);
  882. /* update delegation info? */
  883. if (dirinfo)
  884. ceph_fill_dirfrag(inode, dirinfo);
  885. err = 0;
  886. out:
  887. if (new_cap)
  888. ceph_put_cap(mdsc, new_cap);
  889. if (xattr_blob)
  890. ceph_buffer_put(xattr_blob);
  891. ceph_put_string(pool_ns);
  892. return err;
  893. }
  894. /*
  895. * caller should hold session s_mutex.
  896. */
  897. static void update_dentry_lease(struct dentry *dentry,
  898. struct ceph_mds_reply_lease *lease,
  899. struct ceph_mds_session *session,
  900. unsigned long from_time)
  901. {
  902. struct ceph_dentry_info *di = ceph_dentry(dentry);
  903. long unsigned duration = le32_to_cpu(lease->duration_ms);
  904. long unsigned ttl = from_time + (duration * HZ) / 1000;
  905. long unsigned half_ttl = from_time + (duration * HZ / 2) / 1000;
  906. struct inode *dir;
  907. /* only track leases on regular dentries */
  908. if (dentry->d_op != &ceph_dentry_ops)
  909. return;
  910. spin_lock(&dentry->d_lock);
  911. dout("update_dentry_lease %p duration %lu ms ttl %lu\n",
  912. dentry, duration, ttl);
  913. /* make lease_rdcache_gen match directory */
  914. dir = d_inode(dentry->d_parent);
  915. di->lease_shared_gen = ceph_inode(dir)->i_shared_gen;
  916. if (duration == 0)
  917. goto out_unlock;
  918. if (di->lease_gen == session->s_cap_gen &&
  919. time_before(ttl, di->time))
  920. goto out_unlock; /* we already have a newer lease. */
  921. if (di->lease_session && di->lease_session != session)
  922. goto out_unlock;
  923. ceph_dentry_lru_touch(dentry);
  924. if (!di->lease_session)
  925. di->lease_session = ceph_get_mds_session(session);
  926. di->lease_gen = session->s_cap_gen;
  927. di->lease_seq = le32_to_cpu(lease->seq);
  928. di->lease_renew_after = half_ttl;
  929. di->lease_renew_from = 0;
  930. di->time = ttl;
  931. out_unlock:
  932. spin_unlock(&dentry->d_lock);
  933. return;
  934. }
  935. /*
  936. * splice a dentry to an inode.
  937. * caller must hold directory i_mutex for this to be safe.
  938. */
  939. static struct dentry *splice_dentry(struct dentry *dn, struct inode *in)
  940. {
  941. struct dentry *realdn;
  942. BUG_ON(d_inode(dn));
  943. /* dn must be unhashed */
  944. if (!d_unhashed(dn))
  945. d_drop(dn);
  946. realdn = d_splice_alias(in, dn);
  947. if (IS_ERR(realdn)) {
  948. pr_err("splice_dentry error %ld %p inode %p ino %llx.%llx\n",
  949. PTR_ERR(realdn), dn, in, ceph_vinop(in));
  950. dn = realdn; /* note realdn contains the error */
  951. goto out;
  952. } else if (realdn) {
  953. dout("dn %p (%d) spliced with %p (%d) "
  954. "inode %p ino %llx.%llx\n",
  955. dn, d_count(dn),
  956. realdn, d_count(realdn),
  957. d_inode(realdn), ceph_vinop(d_inode(realdn)));
  958. dput(dn);
  959. dn = realdn;
  960. } else {
  961. BUG_ON(!ceph_dentry(dn));
  962. dout("dn %p attached to %p ino %llx.%llx\n",
  963. dn, d_inode(dn), ceph_vinop(d_inode(dn)));
  964. }
  965. out:
  966. return dn;
  967. }
  968. /*
  969. * Incorporate results into the local cache. This is either just
  970. * one inode, or a directory, dentry, and possibly linked-to inode (e.g.,
  971. * after a lookup).
  972. *
  973. * A reply may contain
  974. * a directory inode along with a dentry.
  975. * and/or a target inode
  976. *
  977. * Called with snap_rwsem (read).
  978. */
  979. int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req,
  980. struct ceph_mds_session *session)
  981. {
  982. struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info;
  983. struct inode *in = NULL;
  984. struct ceph_vino vino;
  985. struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
  986. int err = 0;
  987. dout("fill_trace %p is_dentry %d is_target %d\n", req,
  988. rinfo->head->is_dentry, rinfo->head->is_target);
  989. #if 0
  990. /*
  991. * Debugging hook:
  992. *
  993. * If we resend completed ops to a recovering mds, we get no
  994. * trace. Since that is very rare, pretend this is the case
  995. * to ensure the 'no trace' handlers in the callers behave.
  996. *
  997. * Fill in inodes unconditionally to avoid breaking cap
  998. * invariants.
  999. */
  1000. if (rinfo->head->op & CEPH_MDS_OP_WRITE) {
  1001. pr_info("fill_trace faking empty trace on %lld %s\n",
  1002. req->r_tid, ceph_mds_op_name(rinfo->head->op));
  1003. if (rinfo->head->is_dentry) {
  1004. rinfo->head->is_dentry = 0;
  1005. err = fill_inode(req->r_locked_dir,
  1006. &rinfo->diri, rinfo->dirfrag,
  1007. session, req->r_request_started, -1);
  1008. }
  1009. if (rinfo->head->is_target) {
  1010. rinfo->head->is_target = 0;
  1011. ininfo = rinfo->targeti.in;
  1012. vino.ino = le64_to_cpu(ininfo->ino);
  1013. vino.snap = le64_to_cpu(ininfo->snapid);
  1014. in = ceph_get_inode(sb, vino);
  1015. err = fill_inode(in, &rinfo->targeti, NULL,
  1016. session, req->r_request_started,
  1017. req->r_fmode);
  1018. iput(in);
  1019. }
  1020. }
  1021. #endif
  1022. if (!rinfo->head->is_target && !rinfo->head->is_dentry) {
  1023. dout("fill_trace reply is empty!\n");
  1024. if (rinfo->head->result == 0 && req->r_locked_dir)
  1025. ceph_invalidate_dir_request(req);
  1026. return 0;
  1027. }
  1028. if (rinfo->head->is_dentry) {
  1029. struct inode *dir = req->r_locked_dir;
  1030. if (dir) {
  1031. err = fill_inode(dir, NULL,
  1032. &rinfo->diri, rinfo->dirfrag,
  1033. session, req->r_request_started, -1,
  1034. &req->r_caps_reservation);
  1035. if (err < 0)
  1036. goto done;
  1037. } else {
  1038. WARN_ON_ONCE(1);
  1039. }
  1040. if (dir && req->r_op == CEPH_MDS_OP_LOOKUPNAME) {
  1041. struct qstr dname;
  1042. struct dentry *dn, *parent;
  1043. BUG_ON(!rinfo->head->is_target);
  1044. BUG_ON(req->r_dentry);
  1045. parent = d_find_any_alias(dir);
  1046. BUG_ON(!parent);
  1047. dname.name = rinfo->dname;
  1048. dname.len = rinfo->dname_len;
  1049. dname.hash = full_name_hash(parent, dname.name, dname.len);
  1050. vino.ino = le64_to_cpu(rinfo->targeti.in->ino);
  1051. vino.snap = le64_to_cpu(rinfo->targeti.in->snapid);
  1052. retry_lookup:
  1053. dn = d_lookup(parent, &dname);
  1054. dout("d_lookup on parent=%p name=%.*s got %p\n",
  1055. parent, dname.len, dname.name, dn);
  1056. if (!dn) {
  1057. dn = d_alloc(parent, &dname);
  1058. dout("d_alloc %p '%.*s' = %p\n", parent,
  1059. dname.len, dname.name, dn);
  1060. if (dn == NULL) {
  1061. dput(parent);
  1062. err = -ENOMEM;
  1063. goto done;
  1064. }
  1065. err = ceph_init_dentry(dn);
  1066. if (err < 0) {
  1067. dput(dn);
  1068. dput(parent);
  1069. goto done;
  1070. }
  1071. } else if (d_really_is_positive(dn) &&
  1072. (ceph_ino(d_inode(dn)) != vino.ino ||
  1073. ceph_snap(d_inode(dn)) != vino.snap)) {
  1074. dout(" dn %p points to wrong inode %p\n",
  1075. dn, d_inode(dn));
  1076. d_delete(dn);
  1077. dput(dn);
  1078. goto retry_lookup;
  1079. }
  1080. req->r_dentry = dn;
  1081. dput(parent);
  1082. }
  1083. }
  1084. if (rinfo->head->is_target) {
  1085. vino.ino = le64_to_cpu(rinfo->targeti.in->ino);
  1086. vino.snap = le64_to_cpu(rinfo->targeti.in->snapid);
  1087. in = ceph_get_inode(sb, vino);
  1088. if (IS_ERR(in)) {
  1089. err = PTR_ERR(in);
  1090. goto done;
  1091. }
  1092. req->r_target_inode = in;
  1093. err = fill_inode(in, req->r_locked_page, &rinfo->targeti, NULL,
  1094. session, req->r_request_started,
  1095. (!req->r_aborted && rinfo->head->result == 0) ?
  1096. req->r_fmode : -1,
  1097. &req->r_caps_reservation);
  1098. if (err < 0) {
  1099. pr_err("fill_inode badness %p %llx.%llx\n",
  1100. in, ceph_vinop(in));
  1101. goto done;
  1102. }
  1103. }
  1104. /*
  1105. * ignore null lease/binding on snapdir ENOENT, or else we
  1106. * will have trouble splicing in the virtual snapdir later
  1107. */
  1108. if (rinfo->head->is_dentry && !req->r_aborted &&
  1109. req->r_locked_dir &&
  1110. (rinfo->head->is_target || strncmp(req->r_dentry->d_name.name,
  1111. fsc->mount_options->snapdir_name,
  1112. req->r_dentry->d_name.len))) {
  1113. /*
  1114. * lookup link rename : null -> possibly existing inode
  1115. * mknod symlink mkdir : null -> new inode
  1116. * unlink : linked -> null
  1117. */
  1118. struct inode *dir = req->r_locked_dir;
  1119. struct dentry *dn = req->r_dentry;
  1120. bool have_dir_cap, have_lease;
  1121. BUG_ON(!dn);
  1122. BUG_ON(!dir);
  1123. BUG_ON(d_inode(dn->d_parent) != dir);
  1124. BUG_ON(ceph_ino(dir) !=
  1125. le64_to_cpu(rinfo->diri.in->ino));
  1126. BUG_ON(ceph_snap(dir) !=
  1127. le64_to_cpu(rinfo->diri.in->snapid));
  1128. /* do we have a lease on the whole dir? */
  1129. have_dir_cap =
  1130. (le32_to_cpu(rinfo->diri.in->cap.caps) &
  1131. CEPH_CAP_FILE_SHARED);
  1132. /* do we have a dn lease? */
  1133. have_lease = have_dir_cap ||
  1134. le32_to_cpu(rinfo->dlease->duration_ms);
  1135. if (!have_lease)
  1136. dout("fill_trace no dentry lease or dir cap\n");
  1137. /* rename? */
  1138. if (req->r_old_dentry && req->r_op == CEPH_MDS_OP_RENAME) {
  1139. struct inode *olddir = req->r_old_dentry_dir;
  1140. BUG_ON(!olddir);
  1141. dout(" src %p '%pd' dst %p '%pd'\n",
  1142. req->r_old_dentry,
  1143. req->r_old_dentry,
  1144. dn, dn);
  1145. dout("fill_trace doing d_move %p -> %p\n",
  1146. req->r_old_dentry, dn);
  1147. /* d_move screws up sibling dentries' offsets */
  1148. ceph_dir_clear_ordered(dir);
  1149. ceph_dir_clear_ordered(olddir);
  1150. d_move(req->r_old_dentry, dn);
  1151. dout(" src %p '%pd' dst %p '%pd'\n",
  1152. req->r_old_dentry,
  1153. req->r_old_dentry,
  1154. dn, dn);
  1155. /* ensure target dentry is invalidated, despite
  1156. rehashing bug in vfs_rename_dir */
  1157. ceph_invalidate_dentry_lease(dn);
  1158. dout("dn %p gets new offset %lld\n", req->r_old_dentry,
  1159. ceph_dentry(req->r_old_dentry)->offset);
  1160. dn = req->r_old_dentry; /* use old_dentry */
  1161. }
  1162. /* null dentry? */
  1163. if (!rinfo->head->is_target) {
  1164. dout("fill_trace null dentry\n");
  1165. if (d_really_is_positive(dn)) {
  1166. ceph_dir_clear_ordered(dir);
  1167. dout("d_delete %p\n", dn);
  1168. d_delete(dn);
  1169. } else {
  1170. if (have_lease && d_unhashed(dn))
  1171. d_add(dn, NULL);
  1172. update_dentry_lease(dn, rinfo->dlease,
  1173. session,
  1174. req->r_request_started);
  1175. }
  1176. goto done;
  1177. }
  1178. /* attach proper inode */
  1179. if (d_really_is_negative(dn)) {
  1180. ceph_dir_clear_ordered(dir);
  1181. ihold(in);
  1182. dn = splice_dentry(dn, in);
  1183. if (IS_ERR(dn)) {
  1184. err = PTR_ERR(dn);
  1185. goto done;
  1186. }
  1187. req->r_dentry = dn; /* may have spliced */
  1188. } else if (d_really_is_positive(dn) && d_inode(dn) != in) {
  1189. dout(" %p links to %p %llx.%llx, not %llx.%llx\n",
  1190. dn, d_inode(dn), ceph_vinop(d_inode(dn)),
  1191. ceph_vinop(in));
  1192. d_invalidate(dn);
  1193. have_lease = false;
  1194. }
  1195. if (have_lease)
  1196. update_dentry_lease(dn, rinfo->dlease, session,
  1197. req->r_request_started);
  1198. dout(" final dn %p\n", dn);
  1199. } else if (!req->r_aborted &&
  1200. (req->r_op == CEPH_MDS_OP_LOOKUPSNAP ||
  1201. req->r_op == CEPH_MDS_OP_MKSNAP)) {
  1202. struct dentry *dn = req->r_dentry;
  1203. struct inode *dir = req->r_locked_dir;
  1204. /* fill out a snapdir LOOKUPSNAP dentry */
  1205. BUG_ON(!dn);
  1206. BUG_ON(!dir);
  1207. BUG_ON(ceph_snap(dir) != CEPH_SNAPDIR);
  1208. dout(" linking snapped dir %p to dn %p\n", in, dn);
  1209. ceph_dir_clear_ordered(dir);
  1210. ihold(in);
  1211. dn = splice_dentry(dn, in);
  1212. if (IS_ERR(dn)) {
  1213. err = PTR_ERR(dn);
  1214. goto done;
  1215. }
  1216. req->r_dentry = dn; /* may have spliced */
  1217. }
  1218. done:
  1219. dout("fill_trace done err=%d\n", err);
  1220. return err;
  1221. }
  1222. /*
  1223. * Prepopulate our cache with readdir results, leases, etc.
  1224. */
  1225. static int readdir_prepopulate_inodes_only(struct ceph_mds_request *req,
  1226. struct ceph_mds_session *session)
  1227. {
  1228. struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info;
  1229. int i, err = 0;
  1230. for (i = 0; i < rinfo->dir_nr; i++) {
  1231. struct ceph_mds_reply_dir_entry *rde = rinfo->dir_entries + i;
  1232. struct ceph_vino vino;
  1233. struct inode *in;
  1234. int rc;
  1235. vino.ino = le64_to_cpu(rde->inode.in->ino);
  1236. vino.snap = le64_to_cpu(rde->inode.in->snapid);
  1237. in = ceph_get_inode(req->r_dentry->d_sb, vino);
  1238. if (IS_ERR(in)) {
  1239. err = PTR_ERR(in);
  1240. dout("new_inode badness got %d\n", err);
  1241. continue;
  1242. }
  1243. rc = fill_inode(in, NULL, &rde->inode, NULL, session,
  1244. req->r_request_started, -1,
  1245. &req->r_caps_reservation);
  1246. if (rc < 0) {
  1247. pr_err("fill_inode badness on %p got %d\n", in, rc);
  1248. err = rc;
  1249. }
  1250. iput(in);
  1251. }
  1252. return err;
  1253. }
  1254. void ceph_readdir_cache_release(struct ceph_readdir_cache_control *ctl)
  1255. {
  1256. if (ctl->page) {
  1257. kunmap(ctl->page);
  1258. put_page(ctl->page);
  1259. ctl->page = NULL;
  1260. }
  1261. }
  1262. static int fill_readdir_cache(struct inode *dir, struct dentry *dn,
  1263. struct ceph_readdir_cache_control *ctl,
  1264. struct ceph_mds_request *req)
  1265. {
  1266. struct ceph_inode_info *ci = ceph_inode(dir);
  1267. unsigned nsize = PAGE_SIZE / sizeof(struct dentry*);
  1268. unsigned idx = ctl->index % nsize;
  1269. pgoff_t pgoff = ctl->index / nsize;
  1270. if (!ctl->page || pgoff != page_index(ctl->page)) {
  1271. ceph_readdir_cache_release(ctl);
  1272. if (idx == 0)
  1273. ctl->page = grab_cache_page(&dir->i_data, pgoff);
  1274. else
  1275. ctl->page = find_lock_page(&dir->i_data, pgoff);
  1276. if (!ctl->page) {
  1277. ctl->index = -1;
  1278. return idx == 0 ? -ENOMEM : 0;
  1279. }
  1280. /* reading/filling the cache are serialized by
  1281. * i_mutex, no need to use page lock */
  1282. unlock_page(ctl->page);
  1283. ctl->dentries = kmap(ctl->page);
  1284. if (idx == 0)
  1285. memset(ctl->dentries, 0, PAGE_SIZE);
  1286. }
  1287. if (req->r_dir_release_cnt == atomic64_read(&ci->i_release_count) &&
  1288. req->r_dir_ordered_cnt == atomic64_read(&ci->i_ordered_count)) {
  1289. dout("readdir cache dn %p idx %d\n", dn, ctl->index);
  1290. ctl->dentries[idx] = dn;
  1291. ctl->index++;
  1292. } else {
  1293. dout("disable readdir cache\n");
  1294. ctl->index = -1;
  1295. }
  1296. return 0;
  1297. }
  1298. int ceph_readdir_prepopulate(struct ceph_mds_request *req,
  1299. struct ceph_mds_session *session)
  1300. {
  1301. struct dentry *parent = req->r_dentry;
  1302. struct ceph_inode_info *ci = ceph_inode(d_inode(parent));
  1303. struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info;
  1304. struct qstr dname;
  1305. struct dentry *dn;
  1306. struct inode *in;
  1307. int err = 0, skipped = 0, ret, i;
  1308. struct inode *snapdir = NULL;
  1309. struct ceph_mds_request_head *rhead = req->r_request->front.iov_base;
  1310. u32 frag = le32_to_cpu(rhead->args.readdir.frag);
  1311. u32 last_hash = 0;
  1312. u32 fpos_offset;
  1313. struct ceph_readdir_cache_control cache_ctl = {};
  1314. if (req->r_aborted)
  1315. return readdir_prepopulate_inodes_only(req, session);
  1316. if (rinfo->hash_order && req->r_path2) {
  1317. last_hash = ceph_str_hash(ci->i_dir_layout.dl_dir_hash,
  1318. req->r_path2, strlen(req->r_path2));
  1319. last_hash = ceph_frag_value(last_hash);
  1320. }
  1321. if (rinfo->dir_dir &&
  1322. le32_to_cpu(rinfo->dir_dir->frag) != frag) {
  1323. dout("readdir_prepopulate got new frag %x -> %x\n",
  1324. frag, le32_to_cpu(rinfo->dir_dir->frag));
  1325. frag = le32_to_cpu(rinfo->dir_dir->frag);
  1326. if (!rinfo->hash_order)
  1327. req->r_readdir_offset = 2;
  1328. }
  1329. if (le32_to_cpu(rinfo->head->op) == CEPH_MDS_OP_LSSNAP) {
  1330. snapdir = ceph_get_snapdir(d_inode(parent));
  1331. parent = d_find_alias(snapdir);
  1332. dout("readdir_prepopulate %d items under SNAPDIR dn %p\n",
  1333. rinfo->dir_nr, parent);
  1334. } else {
  1335. dout("readdir_prepopulate %d items under dn %p\n",
  1336. rinfo->dir_nr, parent);
  1337. if (rinfo->dir_dir)
  1338. ceph_fill_dirfrag(d_inode(parent), rinfo->dir_dir);
  1339. }
  1340. if (ceph_frag_is_leftmost(frag) && req->r_readdir_offset == 2) {
  1341. /* note dir version at start of readdir so we can tell
  1342. * if any dentries get dropped */
  1343. req->r_dir_release_cnt = atomic64_read(&ci->i_release_count);
  1344. req->r_dir_ordered_cnt = atomic64_read(&ci->i_ordered_count);
  1345. req->r_readdir_cache_idx = 0;
  1346. }
  1347. cache_ctl.index = req->r_readdir_cache_idx;
  1348. fpos_offset = req->r_readdir_offset;
  1349. /* FIXME: release caps/leases if error occurs */
  1350. for (i = 0; i < rinfo->dir_nr; i++) {
  1351. struct ceph_mds_reply_dir_entry *rde = rinfo->dir_entries + i;
  1352. struct ceph_vino vino;
  1353. dname.name = rde->name;
  1354. dname.len = rde->name_len;
  1355. dname.hash = full_name_hash(parent, dname.name, dname.len);
  1356. vino.ino = le64_to_cpu(rde->inode.in->ino);
  1357. vino.snap = le64_to_cpu(rde->inode.in->snapid);
  1358. if (rinfo->hash_order) {
  1359. u32 hash = ceph_str_hash(ci->i_dir_layout.dl_dir_hash,
  1360. rde->name, rde->name_len);
  1361. hash = ceph_frag_value(hash);
  1362. if (hash != last_hash)
  1363. fpos_offset = 2;
  1364. last_hash = hash;
  1365. rde->offset = ceph_make_fpos(hash, fpos_offset++, true);
  1366. } else {
  1367. rde->offset = ceph_make_fpos(frag, fpos_offset++, false);
  1368. }
  1369. retry_lookup:
  1370. dn = d_lookup(parent, &dname);
  1371. dout("d_lookup on parent=%p name=%.*s got %p\n",
  1372. parent, dname.len, dname.name, dn);
  1373. if (!dn) {
  1374. dn = d_alloc(parent, &dname);
  1375. dout("d_alloc %p '%.*s' = %p\n", parent,
  1376. dname.len, dname.name, dn);
  1377. if (dn == NULL) {
  1378. dout("d_alloc badness\n");
  1379. err = -ENOMEM;
  1380. goto out;
  1381. }
  1382. ret = ceph_init_dentry(dn);
  1383. if (ret < 0) {
  1384. dput(dn);
  1385. err = ret;
  1386. goto out;
  1387. }
  1388. } else if (d_really_is_positive(dn) &&
  1389. (ceph_ino(d_inode(dn)) != vino.ino ||
  1390. ceph_snap(d_inode(dn)) != vino.snap)) {
  1391. dout(" dn %p points to wrong inode %p\n",
  1392. dn, d_inode(dn));
  1393. d_delete(dn);
  1394. dput(dn);
  1395. goto retry_lookup;
  1396. }
  1397. /* inode */
  1398. if (d_really_is_positive(dn)) {
  1399. in = d_inode(dn);
  1400. } else {
  1401. in = ceph_get_inode(parent->d_sb, vino);
  1402. if (IS_ERR(in)) {
  1403. dout("new_inode badness\n");
  1404. d_drop(dn);
  1405. dput(dn);
  1406. err = PTR_ERR(in);
  1407. goto out;
  1408. }
  1409. }
  1410. ret = fill_inode(in, NULL, &rde->inode, NULL, session,
  1411. req->r_request_started, -1,
  1412. &req->r_caps_reservation);
  1413. if (ret < 0) {
  1414. pr_err("fill_inode badness on %p\n", in);
  1415. if (d_really_is_negative(dn))
  1416. iput(in);
  1417. d_drop(dn);
  1418. err = ret;
  1419. goto next_item;
  1420. }
  1421. if (d_really_is_negative(dn)) {
  1422. struct dentry *realdn;
  1423. if (ceph_security_xattr_deadlock(in)) {
  1424. dout(" skip splicing dn %p to inode %p"
  1425. " (security xattr deadlock)\n", dn, in);
  1426. iput(in);
  1427. skipped++;
  1428. goto next_item;
  1429. }
  1430. realdn = splice_dentry(dn, in);
  1431. if (IS_ERR(realdn)) {
  1432. err = PTR_ERR(realdn);
  1433. d_drop(dn);
  1434. dn = NULL;
  1435. goto next_item;
  1436. }
  1437. dn = realdn;
  1438. }
  1439. ceph_dentry(dn)->offset = rde->offset;
  1440. update_dentry_lease(dn, rde->lease, req->r_session,
  1441. req->r_request_started);
  1442. if (err == 0 && skipped == 0 && cache_ctl.index >= 0) {
  1443. ret = fill_readdir_cache(d_inode(parent), dn,
  1444. &cache_ctl, req);
  1445. if (ret < 0)
  1446. err = ret;
  1447. }
  1448. next_item:
  1449. if (dn)
  1450. dput(dn);
  1451. }
  1452. out:
  1453. if (err == 0 && skipped == 0) {
  1454. req->r_did_prepopulate = true;
  1455. req->r_readdir_cache_idx = cache_ctl.index;
  1456. }
  1457. ceph_readdir_cache_release(&cache_ctl);
  1458. if (snapdir) {
  1459. iput(snapdir);
  1460. dput(parent);
  1461. }
  1462. dout("readdir_prepopulate done\n");
  1463. return err;
  1464. }
  1465. int ceph_inode_set_size(struct inode *inode, loff_t size)
  1466. {
  1467. struct ceph_inode_info *ci = ceph_inode(inode);
  1468. int ret = 0;
  1469. spin_lock(&ci->i_ceph_lock);
  1470. dout("set_size %p %llu -> %llu\n", inode, inode->i_size, size);
  1471. i_size_write(inode, size);
  1472. inode->i_blocks = calc_inode_blocks(size);
  1473. /* tell the MDS if we are approaching max_size */
  1474. if ((size << 1) >= ci->i_max_size &&
  1475. (ci->i_reported_size << 1) < ci->i_max_size)
  1476. ret = 1;
  1477. spin_unlock(&ci->i_ceph_lock);
  1478. return ret;
  1479. }
  1480. /*
  1481. * Write back inode data in a worker thread. (This can't be done
  1482. * in the message handler context.)
  1483. */
  1484. void ceph_queue_writeback(struct inode *inode)
  1485. {
  1486. ihold(inode);
  1487. if (queue_work(ceph_inode_to_client(inode)->wb_wq,
  1488. &ceph_inode(inode)->i_wb_work)) {
  1489. dout("ceph_queue_writeback %p\n", inode);
  1490. } else {
  1491. dout("ceph_queue_writeback %p failed\n", inode);
  1492. iput(inode);
  1493. }
  1494. }
  1495. static void ceph_writeback_work(struct work_struct *work)
  1496. {
  1497. struct ceph_inode_info *ci = container_of(work, struct ceph_inode_info,
  1498. i_wb_work);
  1499. struct inode *inode = &ci->vfs_inode;
  1500. dout("writeback %p\n", inode);
  1501. filemap_fdatawrite(&inode->i_data);
  1502. iput(inode);
  1503. }
  1504. /*
  1505. * queue an async invalidation
  1506. */
  1507. void ceph_queue_invalidate(struct inode *inode)
  1508. {
  1509. ihold(inode);
  1510. if (queue_work(ceph_inode_to_client(inode)->pg_inv_wq,
  1511. &ceph_inode(inode)->i_pg_inv_work)) {
  1512. dout("ceph_queue_invalidate %p\n", inode);
  1513. } else {
  1514. dout("ceph_queue_invalidate %p failed\n", inode);
  1515. iput(inode);
  1516. }
  1517. }
  1518. /*
  1519. * Invalidate inode pages in a worker thread. (This can't be done
  1520. * in the message handler context.)
  1521. */
  1522. static void ceph_invalidate_work(struct work_struct *work)
  1523. {
  1524. struct ceph_inode_info *ci = container_of(work, struct ceph_inode_info,
  1525. i_pg_inv_work);
  1526. struct inode *inode = &ci->vfs_inode;
  1527. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  1528. u32 orig_gen;
  1529. int check = 0;
  1530. mutex_lock(&ci->i_truncate_mutex);
  1531. if (ACCESS_ONCE(fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) {
  1532. pr_warn_ratelimited("invalidate_pages %p %lld forced umount\n",
  1533. inode, ceph_ino(inode));
  1534. mapping_set_error(inode->i_mapping, -EIO);
  1535. truncate_pagecache(inode, 0);
  1536. mutex_unlock(&ci->i_truncate_mutex);
  1537. goto out;
  1538. }
  1539. spin_lock(&ci->i_ceph_lock);
  1540. dout("invalidate_pages %p gen %d revoking %d\n", inode,
  1541. ci->i_rdcache_gen, ci->i_rdcache_revoking);
  1542. if (ci->i_rdcache_revoking != ci->i_rdcache_gen) {
  1543. if (__ceph_caps_revoking_other(ci, NULL, CEPH_CAP_FILE_CACHE))
  1544. check = 1;
  1545. spin_unlock(&ci->i_ceph_lock);
  1546. mutex_unlock(&ci->i_truncate_mutex);
  1547. goto out;
  1548. }
  1549. orig_gen = ci->i_rdcache_gen;
  1550. spin_unlock(&ci->i_ceph_lock);
  1551. if (invalidate_inode_pages2(inode->i_mapping) < 0) {
  1552. pr_err("invalidate_pages %p fails\n", inode);
  1553. }
  1554. spin_lock(&ci->i_ceph_lock);
  1555. if (orig_gen == ci->i_rdcache_gen &&
  1556. orig_gen == ci->i_rdcache_revoking) {
  1557. dout("invalidate_pages %p gen %d successful\n", inode,
  1558. ci->i_rdcache_gen);
  1559. ci->i_rdcache_revoking--;
  1560. check = 1;
  1561. } else {
  1562. dout("invalidate_pages %p gen %d raced, now %d revoking %d\n",
  1563. inode, orig_gen, ci->i_rdcache_gen,
  1564. ci->i_rdcache_revoking);
  1565. if (__ceph_caps_revoking_other(ci, NULL, CEPH_CAP_FILE_CACHE))
  1566. check = 1;
  1567. }
  1568. spin_unlock(&ci->i_ceph_lock);
  1569. mutex_unlock(&ci->i_truncate_mutex);
  1570. out:
  1571. if (check)
  1572. ceph_check_caps(ci, 0, NULL);
  1573. iput(inode);
  1574. }
  1575. /*
  1576. * called by trunc_wq;
  1577. *
  1578. * We also truncate in a separate thread as well.
  1579. */
  1580. static void ceph_vmtruncate_work(struct work_struct *work)
  1581. {
  1582. struct ceph_inode_info *ci = container_of(work, struct ceph_inode_info,
  1583. i_vmtruncate_work);
  1584. struct inode *inode = &ci->vfs_inode;
  1585. dout("vmtruncate_work %p\n", inode);
  1586. __ceph_do_pending_vmtruncate(inode);
  1587. iput(inode);
  1588. }
  1589. /*
  1590. * Queue an async vmtruncate. If we fail to queue work, we will handle
  1591. * the truncation the next time we call __ceph_do_pending_vmtruncate.
  1592. */
  1593. void ceph_queue_vmtruncate(struct inode *inode)
  1594. {
  1595. struct ceph_inode_info *ci = ceph_inode(inode);
  1596. ihold(inode);
  1597. if (queue_work(ceph_sb_to_client(inode->i_sb)->trunc_wq,
  1598. &ci->i_vmtruncate_work)) {
  1599. dout("ceph_queue_vmtruncate %p\n", inode);
  1600. } else {
  1601. dout("ceph_queue_vmtruncate %p failed, pending=%d\n",
  1602. inode, ci->i_truncate_pending);
  1603. iput(inode);
  1604. }
  1605. }
  1606. /*
  1607. * Make sure any pending truncation is applied before doing anything
  1608. * that may depend on it.
  1609. */
  1610. void __ceph_do_pending_vmtruncate(struct inode *inode)
  1611. {
  1612. struct ceph_inode_info *ci = ceph_inode(inode);
  1613. u64 to;
  1614. int wrbuffer_refs, finish = 0;
  1615. mutex_lock(&ci->i_truncate_mutex);
  1616. retry:
  1617. spin_lock(&ci->i_ceph_lock);
  1618. if (ci->i_truncate_pending == 0) {
  1619. dout("__do_pending_vmtruncate %p none pending\n", inode);
  1620. spin_unlock(&ci->i_ceph_lock);
  1621. mutex_unlock(&ci->i_truncate_mutex);
  1622. return;
  1623. }
  1624. /*
  1625. * make sure any dirty snapped pages are flushed before we
  1626. * possibly truncate them.. so write AND block!
  1627. */
  1628. if (ci->i_wrbuffer_ref_head < ci->i_wrbuffer_ref) {
  1629. dout("__do_pending_vmtruncate %p flushing snaps first\n",
  1630. inode);
  1631. spin_unlock(&ci->i_ceph_lock);
  1632. filemap_write_and_wait_range(&inode->i_data, 0,
  1633. inode->i_sb->s_maxbytes);
  1634. goto retry;
  1635. }
  1636. /* there should be no reader or writer */
  1637. WARN_ON_ONCE(ci->i_rd_ref || ci->i_wr_ref);
  1638. to = ci->i_truncate_size;
  1639. wrbuffer_refs = ci->i_wrbuffer_ref;
  1640. dout("__do_pending_vmtruncate %p (%d) to %lld\n", inode,
  1641. ci->i_truncate_pending, to);
  1642. spin_unlock(&ci->i_ceph_lock);
  1643. truncate_pagecache(inode, to);
  1644. spin_lock(&ci->i_ceph_lock);
  1645. if (to == ci->i_truncate_size) {
  1646. ci->i_truncate_pending = 0;
  1647. finish = 1;
  1648. }
  1649. spin_unlock(&ci->i_ceph_lock);
  1650. if (!finish)
  1651. goto retry;
  1652. mutex_unlock(&ci->i_truncate_mutex);
  1653. if (wrbuffer_refs == 0)
  1654. ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL);
  1655. wake_up_all(&ci->i_cap_wq);
  1656. }
  1657. /*
  1658. * symlinks
  1659. */
  1660. static const struct inode_operations ceph_symlink_iops = {
  1661. .readlink = generic_readlink,
  1662. .get_link = simple_get_link,
  1663. .setattr = ceph_setattr,
  1664. .getattr = ceph_getattr,
  1665. .setxattr = generic_setxattr,
  1666. .getxattr = generic_getxattr,
  1667. .listxattr = ceph_listxattr,
  1668. .removexattr = generic_removexattr,
  1669. };
  1670. int __ceph_setattr(struct inode *inode, struct iattr *attr)
  1671. {
  1672. struct ceph_inode_info *ci = ceph_inode(inode);
  1673. const unsigned int ia_valid = attr->ia_valid;
  1674. struct ceph_mds_request *req;
  1675. struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
  1676. struct ceph_cap_flush *prealloc_cf;
  1677. int issued;
  1678. int release = 0, dirtied = 0;
  1679. int mask = 0;
  1680. int err = 0;
  1681. int inode_dirty_flags = 0;
  1682. bool lock_snap_rwsem = false;
  1683. if (ceph_snap(inode) != CEPH_NOSNAP)
  1684. return -EROFS;
  1685. err = inode_change_ok(inode, attr);
  1686. if (err != 0)
  1687. return err;
  1688. prealloc_cf = ceph_alloc_cap_flush();
  1689. if (!prealloc_cf)
  1690. return -ENOMEM;
  1691. req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETATTR,
  1692. USE_AUTH_MDS);
  1693. if (IS_ERR(req)) {
  1694. ceph_free_cap_flush(prealloc_cf);
  1695. return PTR_ERR(req);
  1696. }
  1697. spin_lock(&ci->i_ceph_lock);
  1698. issued = __ceph_caps_issued(ci, NULL);
  1699. if (!ci->i_head_snapc &&
  1700. (issued & (CEPH_CAP_ANY_EXCL | CEPH_CAP_FILE_WR))) {
  1701. lock_snap_rwsem = true;
  1702. if (!down_read_trylock(&mdsc->snap_rwsem)) {
  1703. spin_unlock(&ci->i_ceph_lock);
  1704. down_read(&mdsc->snap_rwsem);
  1705. spin_lock(&ci->i_ceph_lock);
  1706. issued = __ceph_caps_issued(ci, NULL);
  1707. }
  1708. }
  1709. dout("setattr %p issued %s\n", inode, ceph_cap_string(issued));
  1710. if (ia_valid & ATTR_UID) {
  1711. dout("setattr %p uid %d -> %d\n", inode,
  1712. from_kuid(&init_user_ns, inode->i_uid),
  1713. from_kuid(&init_user_ns, attr->ia_uid));
  1714. if (issued & CEPH_CAP_AUTH_EXCL) {
  1715. inode->i_uid = attr->ia_uid;
  1716. dirtied |= CEPH_CAP_AUTH_EXCL;
  1717. } else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 ||
  1718. !uid_eq(attr->ia_uid, inode->i_uid)) {
  1719. req->r_args.setattr.uid = cpu_to_le32(
  1720. from_kuid(&init_user_ns, attr->ia_uid));
  1721. mask |= CEPH_SETATTR_UID;
  1722. release |= CEPH_CAP_AUTH_SHARED;
  1723. }
  1724. }
  1725. if (ia_valid & ATTR_GID) {
  1726. dout("setattr %p gid %d -> %d\n", inode,
  1727. from_kgid(&init_user_ns, inode->i_gid),
  1728. from_kgid(&init_user_ns, attr->ia_gid));
  1729. if (issued & CEPH_CAP_AUTH_EXCL) {
  1730. inode->i_gid = attr->ia_gid;
  1731. dirtied |= CEPH_CAP_AUTH_EXCL;
  1732. } else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 ||
  1733. !gid_eq(attr->ia_gid, inode->i_gid)) {
  1734. req->r_args.setattr.gid = cpu_to_le32(
  1735. from_kgid(&init_user_ns, attr->ia_gid));
  1736. mask |= CEPH_SETATTR_GID;
  1737. release |= CEPH_CAP_AUTH_SHARED;
  1738. }
  1739. }
  1740. if (ia_valid & ATTR_MODE) {
  1741. dout("setattr %p mode 0%o -> 0%o\n", inode, inode->i_mode,
  1742. attr->ia_mode);
  1743. if (issued & CEPH_CAP_AUTH_EXCL) {
  1744. inode->i_mode = attr->ia_mode;
  1745. dirtied |= CEPH_CAP_AUTH_EXCL;
  1746. } else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 ||
  1747. attr->ia_mode != inode->i_mode) {
  1748. inode->i_mode = attr->ia_mode;
  1749. req->r_args.setattr.mode = cpu_to_le32(attr->ia_mode);
  1750. mask |= CEPH_SETATTR_MODE;
  1751. release |= CEPH_CAP_AUTH_SHARED;
  1752. }
  1753. }
  1754. if (ia_valid & ATTR_ATIME) {
  1755. dout("setattr %p atime %ld.%ld -> %ld.%ld\n", inode,
  1756. inode->i_atime.tv_sec, inode->i_atime.tv_nsec,
  1757. attr->ia_atime.tv_sec, attr->ia_atime.tv_nsec);
  1758. if (issued & CEPH_CAP_FILE_EXCL) {
  1759. ci->i_time_warp_seq++;
  1760. inode->i_atime = attr->ia_atime;
  1761. dirtied |= CEPH_CAP_FILE_EXCL;
  1762. } else if ((issued & CEPH_CAP_FILE_WR) &&
  1763. timespec_compare(&inode->i_atime,
  1764. &attr->ia_atime) < 0) {
  1765. inode->i_atime = attr->ia_atime;
  1766. dirtied |= CEPH_CAP_FILE_WR;
  1767. } else if ((issued & CEPH_CAP_FILE_SHARED) == 0 ||
  1768. !timespec_equal(&inode->i_atime, &attr->ia_atime)) {
  1769. ceph_encode_timespec(&req->r_args.setattr.atime,
  1770. &attr->ia_atime);
  1771. mask |= CEPH_SETATTR_ATIME;
  1772. release |= CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_RD |
  1773. CEPH_CAP_FILE_WR;
  1774. }
  1775. }
  1776. if (ia_valid & ATTR_MTIME) {
  1777. dout("setattr %p mtime %ld.%ld -> %ld.%ld\n", inode,
  1778. inode->i_mtime.tv_sec, inode->i_mtime.tv_nsec,
  1779. attr->ia_mtime.tv_sec, attr->ia_mtime.tv_nsec);
  1780. if (issued & CEPH_CAP_FILE_EXCL) {
  1781. ci->i_time_warp_seq++;
  1782. inode->i_mtime = attr->ia_mtime;
  1783. dirtied |= CEPH_CAP_FILE_EXCL;
  1784. } else if ((issued & CEPH_CAP_FILE_WR) &&
  1785. timespec_compare(&inode->i_mtime,
  1786. &attr->ia_mtime) < 0) {
  1787. inode->i_mtime = attr->ia_mtime;
  1788. dirtied |= CEPH_CAP_FILE_WR;
  1789. } else if ((issued & CEPH_CAP_FILE_SHARED) == 0 ||
  1790. !timespec_equal(&inode->i_mtime, &attr->ia_mtime)) {
  1791. ceph_encode_timespec(&req->r_args.setattr.mtime,
  1792. &attr->ia_mtime);
  1793. mask |= CEPH_SETATTR_MTIME;
  1794. release |= CEPH_CAP_FILE_SHARED | CEPH_CAP_FILE_RD |
  1795. CEPH_CAP_FILE_WR;
  1796. }
  1797. }
  1798. if (ia_valid & ATTR_SIZE) {
  1799. dout("setattr %p size %lld -> %lld\n", inode,
  1800. inode->i_size, attr->ia_size);
  1801. if ((issued & CEPH_CAP_FILE_EXCL) &&
  1802. attr->ia_size > inode->i_size) {
  1803. i_size_write(inode, attr->ia_size);
  1804. inode->i_blocks = calc_inode_blocks(attr->ia_size);
  1805. inode->i_ctime = attr->ia_ctime;
  1806. ci->i_reported_size = attr->ia_size;
  1807. dirtied |= CEPH_CAP_FILE_EXCL;
  1808. } else if ((issued & CEPH_CAP_FILE_SHARED) == 0 ||
  1809. attr->ia_size != inode->i_size) {
  1810. req->r_args.setattr.size = cpu_to_le64(attr->ia_size);
  1811. req->r_args.setattr.old_size =
  1812. cpu_to_le64(inode->i_size);
  1813. mask |= CEPH_SETATTR_SIZE;
  1814. release |= CEPH_CAP_FILE_SHARED | CEPH_CAP_FILE_RD |
  1815. CEPH_CAP_FILE_WR;
  1816. }
  1817. }
  1818. /* these do nothing */
  1819. if (ia_valid & ATTR_CTIME) {
  1820. bool only = (ia_valid & (ATTR_SIZE|ATTR_MTIME|ATTR_ATIME|
  1821. ATTR_MODE|ATTR_UID|ATTR_GID)) == 0;
  1822. dout("setattr %p ctime %ld.%ld -> %ld.%ld (%s)\n", inode,
  1823. inode->i_ctime.tv_sec, inode->i_ctime.tv_nsec,
  1824. attr->ia_ctime.tv_sec, attr->ia_ctime.tv_nsec,
  1825. only ? "ctime only" : "ignored");
  1826. inode->i_ctime = attr->ia_ctime;
  1827. if (only) {
  1828. /*
  1829. * if kernel wants to dirty ctime but nothing else,
  1830. * we need to choose a cap to dirty under, or do
  1831. * a almost-no-op setattr
  1832. */
  1833. if (issued & CEPH_CAP_AUTH_EXCL)
  1834. dirtied |= CEPH_CAP_AUTH_EXCL;
  1835. else if (issued & CEPH_CAP_FILE_EXCL)
  1836. dirtied |= CEPH_CAP_FILE_EXCL;
  1837. else if (issued & CEPH_CAP_XATTR_EXCL)
  1838. dirtied |= CEPH_CAP_XATTR_EXCL;
  1839. else
  1840. mask |= CEPH_SETATTR_CTIME;
  1841. }
  1842. }
  1843. if (ia_valid & ATTR_FILE)
  1844. dout("setattr %p ATTR_FILE ... hrm!\n", inode);
  1845. if (dirtied) {
  1846. inode_dirty_flags = __ceph_mark_dirty_caps(ci, dirtied,
  1847. &prealloc_cf);
  1848. inode->i_ctime = current_time(inode);
  1849. }
  1850. release &= issued;
  1851. spin_unlock(&ci->i_ceph_lock);
  1852. if (lock_snap_rwsem)
  1853. up_read(&mdsc->snap_rwsem);
  1854. if (inode_dirty_flags)
  1855. __mark_inode_dirty(inode, inode_dirty_flags);
  1856. if (ia_valid & ATTR_MODE) {
  1857. err = posix_acl_chmod(inode, attr->ia_mode);
  1858. if (err)
  1859. goto out_put;
  1860. }
  1861. if (mask) {
  1862. req->r_inode = inode;
  1863. ihold(inode);
  1864. req->r_inode_drop = release;
  1865. req->r_args.setattr.mask = cpu_to_le32(mask);
  1866. req->r_num_caps = 1;
  1867. err = ceph_mdsc_do_request(mdsc, NULL, req);
  1868. }
  1869. dout("setattr %p result=%d (%s locally, %d remote)\n", inode, err,
  1870. ceph_cap_string(dirtied), mask);
  1871. ceph_mdsc_put_request(req);
  1872. if (mask & CEPH_SETATTR_SIZE)
  1873. __ceph_do_pending_vmtruncate(inode);
  1874. ceph_free_cap_flush(prealloc_cf);
  1875. return err;
  1876. out_put:
  1877. ceph_mdsc_put_request(req);
  1878. ceph_free_cap_flush(prealloc_cf);
  1879. return err;
  1880. }
  1881. /*
  1882. * setattr
  1883. */
  1884. int ceph_setattr(struct dentry *dentry, struct iattr *attr)
  1885. {
  1886. return __ceph_setattr(d_inode(dentry), attr);
  1887. }
  1888. /*
  1889. * Verify that we have a lease on the given mask. If not,
  1890. * do a getattr against an mds.
  1891. */
  1892. int __ceph_do_getattr(struct inode *inode, struct page *locked_page,
  1893. int mask, bool force)
  1894. {
  1895. struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
  1896. struct ceph_mds_client *mdsc = fsc->mdsc;
  1897. struct ceph_mds_request *req;
  1898. int err;
  1899. if (ceph_snap(inode) == CEPH_SNAPDIR) {
  1900. dout("do_getattr inode %p SNAPDIR\n", inode);
  1901. return 0;
  1902. }
  1903. dout("do_getattr inode %p mask %s mode 0%o\n",
  1904. inode, ceph_cap_string(mask), inode->i_mode);
  1905. if (!force && ceph_caps_issued_mask(ceph_inode(inode), mask, 1))
  1906. return 0;
  1907. req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
  1908. if (IS_ERR(req))
  1909. return PTR_ERR(req);
  1910. req->r_inode = inode;
  1911. ihold(inode);
  1912. req->r_num_caps = 1;
  1913. req->r_args.getattr.mask = cpu_to_le32(mask);
  1914. req->r_locked_page = locked_page;
  1915. err = ceph_mdsc_do_request(mdsc, NULL, req);
  1916. if (locked_page && err == 0) {
  1917. u64 inline_version = req->r_reply_info.targeti.inline_version;
  1918. if (inline_version == 0) {
  1919. /* the reply is supposed to contain inline data */
  1920. err = -EINVAL;
  1921. } else if (inline_version == CEPH_INLINE_NONE) {
  1922. err = -ENODATA;
  1923. } else {
  1924. err = req->r_reply_info.targeti.inline_len;
  1925. }
  1926. }
  1927. ceph_mdsc_put_request(req);
  1928. dout("do_getattr result=%d\n", err);
  1929. return err;
  1930. }
  1931. /*
  1932. * Check inode permissions. We verify we have a valid value for
  1933. * the AUTH cap, then call the generic handler.
  1934. */
  1935. int ceph_permission(struct inode *inode, int mask)
  1936. {
  1937. int err;
  1938. if (mask & MAY_NOT_BLOCK)
  1939. return -ECHILD;
  1940. err = ceph_do_getattr(inode, CEPH_CAP_AUTH_SHARED, false);
  1941. if (!err)
  1942. err = generic_permission(inode, mask);
  1943. return err;
  1944. }
  1945. /*
  1946. * Get all attributes. Hopefully somedata we'll have a statlite()
  1947. * and can limit the fields we require to be accurate.
  1948. */
  1949. int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry,
  1950. struct kstat *stat)
  1951. {
  1952. struct inode *inode = d_inode(dentry);
  1953. struct ceph_inode_info *ci = ceph_inode(inode);
  1954. int err;
  1955. err = ceph_do_getattr(inode, CEPH_STAT_CAP_INODE_ALL, false);
  1956. if (!err) {
  1957. generic_fillattr(inode, stat);
  1958. stat->ino = ceph_translate_ino(inode->i_sb, inode->i_ino);
  1959. if (ceph_snap(inode) != CEPH_NOSNAP)
  1960. stat->dev = ceph_snap(inode);
  1961. else
  1962. stat->dev = 0;
  1963. if (S_ISDIR(inode->i_mode)) {
  1964. if (ceph_test_mount_opt(ceph_sb_to_client(inode->i_sb),
  1965. RBYTES))
  1966. stat->size = ci->i_rbytes;
  1967. else
  1968. stat->size = ci->i_files + ci->i_subdirs;
  1969. stat->blocks = 0;
  1970. stat->blksize = 65536;
  1971. }
  1972. }
  1973. return err;
  1974. }