dir.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. #include "ceph_debug.h"
  2. #include <linux/spinlock.h>
  3. #include <linux/fs_struct.h>
  4. #include <linux/namei.h>
  5. #include <linux/sched.h>
  6. #include "super.h"
  7. /*
  8. * Directory operations: readdir, lookup, create, link, unlink,
  9. * rename, etc.
  10. */
  11. /*
  12. * Ceph MDS operations are specified in terms of a base ino and
  13. * relative path. Thus, the client can specify an operation on a
  14. * specific inode (e.g., a getattr due to fstat(2)), or as a path
  15. * relative to, say, the root directory.
  16. *
  17. * Normally, we limit ourselves to strict inode ops (no path component)
  18. * or dentry operations (a single path component relative to an ino). The
  19. * exception to this is open_root_dentry(), which will open the mount
  20. * point by name.
  21. */
  22. const struct inode_operations ceph_dir_iops;
  23. const struct file_operations ceph_dir_fops;
  24. struct dentry_operations ceph_dentry_ops;
  25. /*
  26. * Initialize ceph dentry state.
  27. */
  28. int ceph_init_dentry(struct dentry *dentry)
  29. {
  30. struct ceph_dentry_info *di;
  31. if (dentry->d_fsdata)
  32. return 0;
  33. if (ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP)
  34. dentry->d_op = &ceph_dentry_ops;
  35. else if (ceph_snap(dentry->d_parent->d_inode) == CEPH_SNAPDIR)
  36. dentry->d_op = &ceph_snapdir_dentry_ops;
  37. else
  38. dentry->d_op = &ceph_snap_dentry_ops;
  39. di = kmem_cache_alloc(ceph_dentry_cachep, GFP_NOFS);
  40. if (!di)
  41. return -ENOMEM; /* oh well */
  42. spin_lock(&dentry->d_lock);
  43. if (dentry->d_fsdata) /* lost a race */
  44. goto out_unlock;
  45. di->dentry = dentry;
  46. di->lease_session = NULL;
  47. dentry->d_fsdata = di;
  48. dentry->d_time = jiffies;
  49. ceph_dentry_lru_add(dentry);
  50. out_unlock:
  51. spin_unlock(&dentry->d_lock);
  52. return 0;
  53. }
  54. /*
  55. * for readdir, we encode the directory frag and offset within that
  56. * frag into f_pos.
  57. */
  58. static unsigned fpos_frag(loff_t p)
  59. {
  60. return p >> 32;
  61. }
  62. static unsigned fpos_off(loff_t p)
  63. {
  64. return p & 0xffffffff;
  65. }
  66. /*
  67. * When possible, we try to satisfy a readdir by peeking at the
  68. * dcache. We make this work by carefully ordering dentries on
  69. * d_u.d_child when we initially get results back from the MDS, and
  70. * falling back to a "normal" sync readdir if any dentries in the dir
  71. * are dropped.
  72. *
  73. * I_COMPLETE tells indicates we have all dentries in the dir. It is
  74. * defined IFF we hold CEPH_CAP_FILE_SHARED (which will be revoked by
  75. * the MDS if/when the directory is modified).
  76. */
  77. static int __dcache_readdir(struct file *filp,
  78. void *dirent, filldir_t filldir)
  79. {
  80. struct inode *inode = filp->f_dentry->d_inode;
  81. struct ceph_file_info *fi = filp->private_data;
  82. struct dentry *parent = filp->f_dentry;
  83. struct inode *dir = parent->d_inode;
  84. struct list_head *p;
  85. struct dentry *dentry, *last;
  86. struct ceph_dentry_info *di;
  87. int err = 0;
  88. /* claim ref on last dentry we returned */
  89. last = fi->dentry;
  90. fi->dentry = NULL;
  91. dout("__dcache_readdir %p at %llu (last %p)\n", dir, filp->f_pos,
  92. last);
  93. spin_lock(&dcache_lock);
  94. /* start at beginning? */
  95. if (filp->f_pos == 2 || (last &&
  96. filp->f_pos < ceph_dentry(last)->offset)) {
  97. if (list_empty(&parent->d_subdirs))
  98. goto out_unlock;
  99. p = parent->d_subdirs.prev;
  100. dout(" initial p %p/%p\n", p->prev, p->next);
  101. } else {
  102. p = last->d_u.d_child.prev;
  103. }
  104. more:
  105. dentry = list_entry(p, struct dentry, d_u.d_child);
  106. di = ceph_dentry(dentry);
  107. while (1) {
  108. dout(" p %p/%p d_subdirs %p/%p\n", p->prev, p->next,
  109. parent->d_subdirs.prev, parent->d_subdirs.next);
  110. if (p == &parent->d_subdirs) {
  111. fi->at_end = 1;
  112. goto out_unlock;
  113. }
  114. if (!d_unhashed(dentry) && dentry->d_inode &&
  115. ceph_snap(dentry->d_inode) != CEPH_SNAPDIR &&
  116. ceph_ino(dentry->d_inode) != CEPH_INO_CEPH &&
  117. filp->f_pos <= di->offset)
  118. break;
  119. dout(" skipping %p %.*s at %llu (%llu)%s%s\n", dentry,
  120. dentry->d_name.len, dentry->d_name.name, di->offset,
  121. filp->f_pos, d_unhashed(dentry) ? " unhashed" : "",
  122. !dentry->d_inode ? " null" : "");
  123. p = p->prev;
  124. dentry = list_entry(p, struct dentry, d_u.d_child);
  125. di = ceph_dentry(dentry);
  126. }
  127. atomic_inc(&dentry->d_count);
  128. spin_unlock(&dcache_lock);
  129. spin_unlock(&inode->i_lock);
  130. dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, filp->f_pos,
  131. dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
  132. filp->f_pos = di->offset;
  133. err = filldir(dirent, dentry->d_name.name,
  134. dentry->d_name.len, di->offset,
  135. dentry->d_inode->i_ino,
  136. dentry->d_inode->i_mode >> 12);
  137. if (last) {
  138. if (err < 0) {
  139. /* remember our position */
  140. fi->dentry = last;
  141. fi->next_offset = di->offset;
  142. } else {
  143. dput(last);
  144. }
  145. last = NULL;
  146. }
  147. spin_lock(&inode->i_lock);
  148. spin_lock(&dcache_lock);
  149. if (err < 0)
  150. goto out_unlock;
  151. last = dentry;
  152. p = p->prev;
  153. filp->f_pos++;
  154. /* make sure a dentry wasn't dropped while we didn't have dcache_lock */
  155. if ((ceph_inode(dir)->i_ceph_flags & CEPH_I_COMPLETE))
  156. goto more;
  157. dout(" lost I_COMPLETE on %p; falling back to mds\n", dir);
  158. err = -EAGAIN;
  159. out_unlock:
  160. spin_unlock(&dcache_lock);
  161. if (last) {
  162. spin_unlock(&inode->i_lock);
  163. dput(last);
  164. spin_lock(&inode->i_lock);
  165. }
  166. return err;
  167. }
  168. /*
  169. * make note of the last dentry we read, so we can
  170. * continue at the same lexicographical point,
  171. * regardless of what dir changes take place on the
  172. * server.
  173. */
  174. static int note_last_dentry(struct ceph_file_info *fi, const char *name,
  175. int len)
  176. {
  177. kfree(fi->last_name);
  178. fi->last_name = kmalloc(len+1, GFP_NOFS);
  179. if (!fi->last_name)
  180. return -ENOMEM;
  181. memcpy(fi->last_name, name, len);
  182. fi->last_name[len] = 0;
  183. dout("note_last_dentry '%s'\n", fi->last_name);
  184. return 0;
  185. }
  186. static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
  187. {
  188. struct ceph_file_info *fi = filp->private_data;
  189. struct inode *inode = filp->f_dentry->d_inode;
  190. struct ceph_inode_info *ci = ceph_inode(inode);
  191. struct ceph_client *client = ceph_inode_to_client(inode);
  192. struct ceph_mds_client *mdsc = &client->mdsc;
  193. unsigned frag = fpos_frag(filp->f_pos);
  194. int off = fpos_off(filp->f_pos);
  195. int err;
  196. u32 ftype;
  197. struct ceph_mds_reply_info_parsed *rinfo;
  198. const int max_entries = client->mount_args->max_readdir;
  199. dout("readdir %p filp %p frag %u off %u\n", inode, filp, frag, off);
  200. if (fi->at_end)
  201. return 0;
  202. /* always start with . and .. */
  203. if (filp->f_pos == 0) {
  204. /* note dir version at start of readdir so we can tell
  205. * if any dentries get dropped */
  206. fi->dir_release_count = ci->i_release_count;
  207. dout("readdir off 0 -> '.'\n");
  208. if (filldir(dirent, ".", 1, ceph_make_fpos(0, 0),
  209. inode->i_ino, inode->i_mode >> 12) < 0)
  210. return 0;
  211. filp->f_pos = 1;
  212. off = 1;
  213. }
  214. if (filp->f_pos == 1) {
  215. dout("readdir off 1 -> '..'\n");
  216. if (filldir(dirent, "..", 2, ceph_make_fpos(0, 1),
  217. filp->f_dentry->d_parent->d_inode->i_ino,
  218. inode->i_mode >> 12) < 0)
  219. return 0;
  220. filp->f_pos = 2;
  221. off = 2;
  222. }
  223. /* can we use the dcache? */
  224. spin_lock(&inode->i_lock);
  225. if ((filp->f_pos == 2 || fi->dentry) &&
  226. !ceph_test_opt(client, NOASYNCREADDIR) &&
  227. (ci->i_ceph_flags & CEPH_I_COMPLETE) &&
  228. __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1)) {
  229. err = __dcache_readdir(filp, dirent, filldir);
  230. if (err != -EAGAIN) {
  231. spin_unlock(&inode->i_lock);
  232. return err;
  233. }
  234. }
  235. spin_unlock(&inode->i_lock);
  236. if (fi->dentry) {
  237. err = note_last_dentry(fi, fi->dentry->d_name.name,
  238. fi->dentry->d_name.len);
  239. if (err)
  240. return err;
  241. dput(fi->dentry);
  242. fi->dentry = NULL;
  243. }
  244. /* proceed with a normal readdir */
  245. more:
  246. /* do we have the correct frag content buffered? */
  247. if (fi->frag != frag || fi->last_readdir == NULL) {
  248. struct ceph_mds_request *req;
  249. int op = ceph_snap(inode) == CEPH_SNAPDIR ?
  250. CEPH_MDS_OP_LSSNAP : CEPH_MDS_OP_READDIR;
  251. /* discard old result, if any */
  252. if (fi->last_readdir)
  253. ceph_mdsc_put_request(fi->last_readdir);
  254. /* requery frag tree, as the frag topology may have changed */
  255. frag = ceph_choose_frag(ceph_inode(inode), frag, NULL, NULL);
  256. dout("readdir fetching %llx.%llx frag %x offset '%s'\n",
  257. ceph_vinop(inode), frag, fi->last_name);
  258. req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
  259. if (IS_ERR(req))
  260. return PTR_ERR(req);
  261. req->r_inode = igrab(inode);
  262. req->r_dentry = dget(filp->f_dentry);
  263. /* hints to request -> mds selection code */
  264. req->r_direct_mode = USE_AUTH_MDS;
  265. req->r_direct_hash = ceph_frag_value(frag);
  266. req->r_direct_is_hash = true;
  267. req->r_path2 = kstrdup(fi->last_name, GFP_NOFS);
  268. req->r_readdir_offset = fi->next_offset;
  269. req->r_args.readdir.frag = cpu_to_le32(frag);
  270. req->r_args.readdir.max_entries = cpu_to_le32(max_entries);
  271. req->r_num_caps = max_entries;
  272. err = ceph_mdsc_do_request(mdsc, NULL, req);
  273. if (err < 0) {
  274. ceph_mdsc_put_request(req);
  275. return err;
  276. }
  277. dout("readdir got and parsed readdir result=%d"
  278. " on frag %x, end=%d, complete=%d\n", err, frag,
  279. (int)req->r_reply_info.dir_end,
  280. (int)req->r_reply_info.dir_complete);
  281. if (!req->r_did_prepopulate) {
  282. dout("readdir !did_prepopulate");
  283. fi->dir_release_count--; /* preclude I_COMPLETE */
  284. }
  285. /* note next offset and last dentry name */
  286. fi->offset = fi->next_offset;
  287. fi->last_readdir = req;
  288. if (req->r_reply_info.dir_end) {
  289. kfree(fi->last_name);
  290. fi->last_name = NULL;
  291. fi->next_offset = 0;
  292. } else {
  293. rinfo = &req->r_reply_info;
  294. err = note_last_dentry(fi,
  295. rinfo->dir_dname[rinfo->dir_nr-1],
  296. rinfo->dir_dname_len[rinfo->dir_nr-1]);
  297. if (err)
  298. return err;
  299. fi->next_offset += rinfo->dir_nr;
  300. }
  301. }
  302. rinfo = &fi->last_readdir->r_reply_info;
  303. dout("readdir frag %x num %d off %d chunkoff %d\n", frag,
  304. rinfo->dir_nr, off, fi->offset);
  305. while (off - fi->offset >= 0 && off - fi->offset < rinfo->dir_nr) {
  306. u64 pos = ceph_make_fpos(frag, off);
  307. struct ceph_mds_reply_inode *in =
  308. rinfo->dir_in[off - fi->offset].in;
  309. dout("readdir off %d (%d/%d) -> %lld '%.*s' %p\n",
  310. off, off - fi->offset, rinfo->dir_nr, pos,
  311. rinfo->dir_dname_len[off - fi->offset],
  312. rinfo->dir_dname[off - fi->offset], in);
  313. BUG_ON(!in);
  314. ftype = le32_to_cpu(in->mode) >> 12;
  315. if (filldir(dirent,
  316. rinfo->dir_dname[off - fi->offset],
  317. rinfo->dir_dname_len[off - fi->offset],
  318. pos,
  319. le64_to_cpu(in->ino),
  320. ftype) < 0) {
  321. dout("filldir stopping us...\n");
  322. return 0;
  323. }
  324. off++;
  325. filp->f_pos = pos + 1;
  326. }
  327. if (fi->last_name) {
  328. ceph_mdsc_put_request(fi->last_readdir);
  329. fi->last_readdir = NULL;
  330. goto more;
  331. }
  332. /* more frags? */
  333. if (!ceph_frag_is_rightmost(frag)) {
  334. frag = ceph_frag_next(frag);
  335. off = 0;
  336. filp->f_pos = ceph_make_fpos(frag, off);
  337. dout("readdir next frag is %x\n", frag);
  338. goto more;
  339. }
  340. fi->at_end = 1;
  341. /*
  342. * if dir_release_count still matches the dir, no dentries
  343. * were released during the whole readdir, and we should have
  344. * the complete dir contents in our cache.
  345. */
  346. spin_lock(&inode->i_lock);
  347. if (ci->i_release_count == fi->dir_release_count) {
  348. dout(" marking %p complete\n", inode);
  349. ci->i_ceph_flags |= CEPH_I_COMPLETE;
  350. ci->i_max_offset = filp->f_pos;
  351. }
  352. spin_unlock(&inode->i_lock);
  353. dout("readdir %p filp %p done.\n", inode, filp);
  354. return 0;
  355. }
  356. static void reset_readdir(struct ceph_file_info *fi)
  357. {
  358. if (fi->last_readdir) {
  359. ceph_mdsc_put_request(fi->last_readdir);
  360. fi->last_readdir = NULL;
  361. }
  362. kfree(fi->last_name);
  363. fi->next_offset = 2; /* compensate for . and .. */
  364. if (fi->dentry) {
  365. dput(fi->dentry);
  366. fi->dentry = NULL;
  367. }
  368. fi->at_end = 0;
  369. }
  370. static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin)
  371. {
  372. struct ceph_file_info *fi = file->private_data;
  373. struct inode *inode = file->f_mapping->host;
  374. loff_t old_offset = offset;
  375. loff_t retval;
  376. mutex_lock(&inode->i_mutex);
  377. switch (origin) {
  378. case SEEK_END:
  379. offset += inode->i_size + 2; /* FIXME */
  380. break;
  381. case SEEK_CUR:
  382. offset += file->f_pos;
  383. }
  384. retval = -EINVAL;
  385. if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) {
  386. if (offset != file->f_pos) {
  387. file->f_pos = offset;
  388. file->f_version = 0;
  389. fi->at_end = 0;
  390. }
  391. retval = offset;
  392. /*
  393. * discard buffered readdir content on seekdir(0), or
  394. * seek to new frag, or seek prior to current chunk.
  395. */
  396. if (offset == 0 ||
  397. fpos_frag(offset) != fpos_frag(old_offset) ||
  398. fpos_off(offset) < fi->offset) {
  399. dout("dir_llseek dropping %p content\n", file);
  400. reset_readdir(fi);
  401. }
  402. /* bump dir_release_count if we did a forward seek */
  403. if (offset > old_offset)
  404. fi->dir_release_count--;
  405. }
  406. mutex_unlock(&inode->i_mutex);
  407. return retval;
  408. }
  409. /*
  410. * Process result of a lookup/open request.
  411. *
  412. * Mainly, make sure we return the final req->r_dentry (if it already
  413. * existed) in place of the original VFS-provided dentry when they
  414. * differ.
  415. *
  416. * Gracefully handle the case where the MDS replies with -ENOENT and
  417. * no trace (which it may do, at its discretion, e.g., if it doesn't
  418. * care to issue a lease on the negative dentry).
  419. */
  420. struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
  421. struct dentry *dentry, int err)
  422. {
  423. struct ceph_client *client = ceph_client(dentry->d_sb);
  424. struct inode *parent = dentry->d_parent->d_inode;
  425. /* .snap dir? */
  426. if (err == -ENOENT &&
  427. ceph_vino(parent).ino != CEPH_INO_ROOT && /* no .snap in root dir */
  428. strcmp(dentry->d_name.name,
  429. client->mount_args->snapdir_name) == 0) {
  430. struct inode *inode = ceph_get_snapdir(parent);
  431. dout("ENOENT on snapdir %p '%.*s', linking to snapdir %p\n",
  432. dentry, dentry->d_name.len, dentry->d_name.name, inode);
  433. d_add(dentry, inode);
  434. err = 0;
  435. }
  436. if (err == -ENOENT) {
  437. /* no trace? */
  438. err = 0;
  439. if (!req->r_reply_info.head->is_dentry) {
  440. dout("ENOENT and no trace, dentry %p inode %p\n",
  441. dentry, dentry->d_inode);
  442. if (dentry->d_inode) {
  443. d_drop(dentry);
  444. err = -ENOENT;
  445. } else {
  446. d_add(dentry, NULL);
  447. }
  448. }
  449. }
  450. if (err)
  451. dentry = ERR_PTR(err);
  452. else if (dentry != req->r_dentry)
  453. dentry = dget(req->r_dentry); /* we got spliced */
  454. else
  455. dentry = NULL;
  456. return dentry;
  457. }
  458. static int is_root_ceph_dentry(struct inode *inode, struct dentry *dentry)
  459. {
  460. return ceph_ino(inode) == CEPH_INO_ROOT &&
  461. strncmp(dentry->d_name.name, ".ceph", 5) == 0;
  462. }
  463. /*
  464. * Look up a single dir entry. If there is a lookup intent, inform
  465. * the MDS so that it gets our 'caps wanted' value in a single op.
  466. */
  467. static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
  468. struct nameidata *nd)
  469. {
  470. struct ceph_client *client = ceph_sb_to_client(dir->i_sb);
  471. struct ceph_mds_client *mdsc = &client->mdsc;
  472. struct ceph_mds_request *req;
  473. int op;
  474. int err;
  475. dout("lookup %p dentry %p '%.*s'\n",
  476. dir, dentry, dentry->d_name.len, dentry->d_name.name);
  477. if (dentry->d_name.len > NAME_MAX)
  478. return ERR_PTR(-ENAMETOOLONG);
  479. err = ceph_init_dentry(dentry);
  480. if (err < 0)
  481. return ERR_PTR(err);
  482. /* open (but not create!) intent? */
  483. if (nd &&
  484. (nd->flags & LOOKUP_OPEN) &&
  485. (nd->flags & LOOKUP_CONTINUE) == 0 && /* only open last component */
  486. !(nd->intent.open.flags & O_CREAT)) {
  487. int mode = nd->intent.open.create_mode & ~current->fs->umask;
  488. return ceph_lookup_open(dir, dentry, nd, mode, 1);
  489. }
  490. /* can we conclude ENOENT locally? */
  491. if (dentry->d_inode == NULL) {
  492. struct ceph_inode_info *ci = ceph_inode(dir);
  493. struct ceph_dentry_info *di = ceph_dentry(dentry);
  494. spin_lock(&dir->i_lock);
  495. dout(" dir %p flags are %d\n", dir, ci->i_ceph_flags);
  496. if (strncmp(dentry->d_name.name,
  497. client->mount_args->snapdir_name,
  498. dentry->d_name.len) &&
  499. !is_root_ceph_dentry(dir, dentry) &&
  500. (ci->i_ceph_flags & CEPH_I_COMPLETE) &&
  501. (__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1))) {
  502. di->offset = ci->i_max_offset++;
  503. spin_unlock(&dir->i_lock);
  504. dout(" dir %p complete, -ENOENT\n", dir);
  505. d_add(dentry, NULL);
  506. di->lease_shared_gen = ci->i_shared_gen;
  507. return NULL;
  508. }
  509. spin_unlock(&dir->i_lock);
  510. }
  511. op = ceph_snap(dir) == CEPH_SNAPDIR ?
  512. CEPH_MDS_OP_LOOKUPSNAP : CEPH_MDS_OP_LOOKUP;
  513. req = ceph_mdsc_create_request(mdsc, op, USE_ANY_MDS);
  514. if (IS_ERR(req))
  515. return ERR_PTR(PTR_ERR(req));
  516. req->r_dentry = dget(dentry);
  517. req->r_num_caps = 2;
  518. /* we only need inode linkage */
  519. req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
  520. req->r_locked_dir = dir;
  521. err = ceph_mdsc_do_request(mdsc, NULL, req);
  522. dentry = ceph_finish_lookup(req, dentry, err);
  523. ceph_mdsc_put_request(req); /* will dput(dentry) */
  524. dout("lookup result=%p\n", dentry);
  525. return dentry;
  526. }
  527. /*
  528. * If we do a create but get no trace back from the MDS, follow up with
  529. * a lookup (the VFS expects us to link up the provided dentry).
  530. */
  531. int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry)
  532. {
  533. struct dentry *result = ceph_lookup(dir, dentry, NULL);
  534. if (result && !IS_ERR(result)) {
  535. /*
  536. * We created the item, then did a lookup, and found
  537. * it was already linked to another inode we already
  538. * had in our cache (and thus got spliced). Link our
  539. * dentry to that inode, but don't hash it, just in
  540. * case the VFS wants to dereference it.
  541. */
  542. BUG_ON(!result->d_inode);
  543. d_instantiate(dentry, result->d_inode);
  544. return 0;
  545. }
  546. return PTR_ERR(result);
  547. }
  548. static int ceph_mknod(struct inode *dir, struct dentry *dentry,
  549. int mode, dev_t rdev)
  550. {
  551. struct ceph_client *client = ceph_sb_to_client(dir->i_sb);
  552. struct ceph_mds_client *mdsc = &client->mdsc;
  553. struct ceph_mds_request *req;
  554. int err;
  555. if (ceph_snap(dir) != CEPH_NOSNAP)
  556. return -EROFS;
  557. dout("mknod in dir %p dentry %p mode 0%o rdev %d\n",
  558. dir, dentry, mode, rdev);
  559. req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKNOD, USE_AUTH_MDS);
  560. if (IS_ERR(req)) {
  561. d_drop(dentry);
  562. return PTR_ERR(req);
  563. }
  564. req->r_dentry = dget(dentry);
  565. req->r_num_caps = 2;
  566. req->r_locked_dir = dir;
  567. req->r_args.mknod.mode = cpu_to_le32(mode);
  568. req->r_args.mknod.rdev = cpu_to_le32(rdev);
  569. req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
  570. req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
  571. err = ceph_mdsc_do_request(mdsc, dir, req);
  572. if (!err && !req->r_reply_info.head->is_dentry)
  573. err = ceph_handle_notrace_create(dir, dentry);
  574. ceph_mdsc_put_request(req);
  575. if (err)
  576. d_drop(dentry);
  577. return err;
  578. }
  579. static int ceph_create(struct inode *dir, struct dentry *dentry, int mode,
  580. struct nameidata *nd)
  581. {
  582. dout("create in dir %p dentry %p name '%.*s'\n",
  583. dir, dentry, dentry->d_name.len, dentry->d_name.name);
  584. if (ceph_snap(dir) != CEPH_NOSNAP)
  585. return -EROFS;
  586. if (nd) {
  587. BUG_ON((nd->flags & LOOKUP_OPEN) == 0);
  588. dentry = ceph_lookup_open(dir, dentry, nd, mode, 0);
  589. /* hrm, what should i do here if we get aliased? */
  590. if (IS_ERR(dentry))
  591. return PTR_ERR(dentry);
  592. return 0;
  593. }
  594. /* fall back to mknod */
  595. return ceph_mknod(dir, dentry, (mode & ~S_IFMT) | S_IFREG, 0);
  596. }
  597. static int ceph_symlink(struct inode *dir, struct dentry *dentry,
  598. const char *dest)
  599. {
  600. struct ceph_client *client = ceph_sb_to_client(dir->i_sb);
  601. struct ceph_mds_client *mdsc = &client->mdsc;
  602. struct ceph_mds_request *req;
  603. int err;
  604. if (ceph_snap(dir) != CEPH_NOSNAP)
  605. return -EROFS;
  606. dout("symlink in dir %p dentry %p to '%s'\n", dir, dentry, dest);
  607. req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SYMLINK, USE_AUTH_MDS);
  608. if (IS_ERR(req)) {
  609. d_drop(dentry);
  610. return PTR_ERR(req);
  611. }
  612. req->r_dentry = dget(dentry);
  613. req->r_num_caps = 2;
  614. req->r_path2 = kstrdup(dest, GFP_NOFS);
  615. req->r_locked_dir = dir;
  616. req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
  617. req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
  618. err = ceph_mdsc_do_request(mdsc, dir, req);
  619. if (!err && !req->r_reply_info.head->is_dentry)
  620. err = ceph_handle_notrace_create(dir, dentry);
  621. ceph_mdsc_put_request(req);
  622. if (err)
  623. d_drop(dentry);
  624. return err;
  625. }
  626. static int ceph_mkdir(struct inode *dir, struct dentry *dentry, int mode)
  627. {
  628. struct ceph_client *client = ceph_sb_to_client(dir->i_sb);
  629. struct ceph_mds_client *mdsc = &client->mdsc;
  630. struct ceph_mds_request *req;
  631. int err = -EROFS;
  632. int op;
  633. if (ceph_snap(dir) == CEPH_SNAPDIR) {
  634. /* mkdir .snap/foo is a MKSNAP */
  635. op = CEPH_MDS_OP_MKSNAP;
  636. dout("mksnap dir %p snap '%.*s' dn %p\n", dir,
  637. dentry->d_name.len, dentry->d_name.name, dentry);
  638. } else if (ceph_snap(dir) == CEPH_NOSNAP) {
  639. dout("mkdir dir %p dn %p mode 0%o\n", dir, dentry, mode);
  640. op = CEPH_MDS_OP_MKDIR;
  641. } else {
  642. goto out;
  643. }
  644. req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
  645. if (IS_ERR(req)) {
  646. err = PTR_ERR(req);
  647. goto out;
  648. }
  649. req->r_dentry = dget(dentry);
  650. req->r_num_caps = 2;
  651. req->r_locked_dir = dir;
  652. req->r_args.mkdir.mode = cpu_to_le32(mode);
  653. req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
  654. req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
  655. err = ceph_mdsc_do_request(mdsc, dir, req);
  656. if (!err && !req->r_reply_info.head->is_dentry)
  657. err = ceph_handle_notrace_create(dir, dentry);
  658. ceph_mdsc_put_request(req);
  659. out:
  660. if (err < 0)
  661. d_drop(dentry);
  662. return err;
  663. }
  664. static int ceph_link(struct dentry *old_dentry, struct inode *dir,
  665. struct dentry *dentry)
  666. {
  667. struct ceph_client *client = ceph_sb_to_client(dir->i_sb);
  668. struct ceph_mds_client *mdsc = &client->mdsc;
  669. struct ceph_mds_request *req;
  670. int err;
  671. if (ceph_snap(dir) != CEPH_NOSNAP)
  672. return -EROFS;
  673. dout("link in dir %p old_dentry %p dentry %p\n", dir,
  674. old_dentry, dentry);
  675. req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LINK, USE_AUTH_MDS);
  676. if (IS_ERR(req)) {
  677. d_drop(dentry);
  678. return PTR_ERR(req);
  679. }
  680. req->r_dentry = dget(dentry);
  681. req->r_num_caps = 2;
  682. req->r_old_dentry = dget(old_dentry); /* or inode? hrm. */
  683. req->r_locked_dir = dir;
  684. req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
  685. req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
  686. err = ceph_mdsc_do_request(mdsc, dir, req);
  687. if (err)
  688. d_drop(dentry);
  689. else if (!req->r_reply_info.head->is_dentry)
  690. d_instantiate(dentry, igrab(old_dentry->d_inode));
  691. ceph_mdsc_put_request(req);
  692. return err;
  693. }
  694. /*
  695. * For a soon-to-be unlinked file, drop the AUTH_RDCACHE caps. If it
  696. * looks like the link count will hit 0, drop any other caps (other
  697. * than PIN) we don't specifically want (due to the file still being
  698. * open).
  699. */
  700. static int drop_caps_for_unlink(struct inode *inode)
  701. {
  702. struct ceph_inode_info *ci = ceph_inode(inode);
  703. int drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
  704. spin_lock(&inode->i_lock);
  705. if (inode->i_nlink == 1) {
  706. drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN);
  707. ci->i_ceph_flags |= CEPH_I_NODELAY;
  708. }
  709. spin_unlock(&inode->i_lock);
  710. return drop;
  711. }
  712. /*
  713. * rmdir and unlink are differ only by the metadata op code
  714. */
  715. static int ceph_unlink(struct inode *dir, struct dentry *dentry)
  716. {
  717. struct ceph_client *client = ceph_sb_to_client(dir->i_sb);
  718. struct ceph_mds_client *mdsc = &client->mdsc;
  719. struct inode *inode = dentry->d_inode;
  720. struct ceph_mds_request *req;
  721. int err = -EROFS;
  722. int op;
  723. if (ceph_snap(dir) == CEPH_SNAPDIR) {
  724. /* rmdir .snap/foo is RMSNAP */
  725. dout("rmsnap dir %p '%.*s' dn %p\n", dir, dentry->d_name.len,
  726. dentry->d_name.name, dentry);
  727. op = CEPH_MDS_OP_RMSNAP;
  728. } else if (ceph_snap(dir) == CEPH_NOSNAP) {
  729. dout("unlink/rmdir dir %p dn %p inode %p\n",
  730. dir, dentry, inode);
  731. op = ((dentry->d_inode->i_mode & S_IFMT) == S_IFDIR) ?
  732. CEPH_MDS_OP_RMDIR : CEPH_MDS_OP_UNLINK;
  733. } else
  734. goto out;
  735. req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
  736. if (IS_ERR(req)) {
  737. err = PTR_ERR(req);
  738. goto out;
  739. }
  740. req->r_dentry = dget(dentry);
  741. req->r_num_caps = 2;
  742. req->r_locked_dir = dir;
  743. req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
  744. req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
  745. req->r_inode_drop = drop_caps_for_unlink(inode);
  746. err = ceph_mdsc_do_request(mdsc, dir, req);
  747. if (!err && !req->r_reply_info.head->is_dentry)
  748. d_delete(dentry);
  749. ceph_mdsc_put_request(req);
  750. out:
  751. return err;
  752. }
  753. static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,
  754. struct inode *new_dir, struct dentry *new_dentry)
  755. {
  756. struct ceph_client *client = ceph_sb_to_client(old_dir->i_sb);
  757. struct ceph_mds_client *mdsc = &client->mdsc;
  758. struct ceph_mds_request *req;
  759. int err;
  760. if (ceph_snap(old_dir) != ceph_snap(new_dir))
  761. return -EXDEV;
  762. if (ceph_snap(old_dir) != CEPH_NOSNAP ||
  763. ceph_snap(new_dir) != CEPH_NOSNAP)
  764. return -EROFS;
  765. dout("rename dir %p dentry %p to dir %p dentry %p\n",
  766. old_dir, old_dentry, new_dir, new_dentry);
  767. req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_RENAME, USE_AUTH_MDS);
  768. if (IS_ERR(req))
  769. return PTR_ERR(req);
  770. req->r_dentry = dget(new_dentry);
  771. req->r_num_caps = 2;
  772. req->r_old_dentry = dget(old_dentry);
  773. req->r_locked_dir = new_dir;
  774. req->r_old_dentry_drop = CEPH_CAP_FILE_SHARED;
  775. req->r_old_dentry_unless = CEPH_CAP_FILE_EXCL;
  776. req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
  777. req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
  778. /* release LINK_RDCACHE on source inode (mds will lock it) */
  779. req->r_old_inode_drop = CEPH_CAP_LINK_SHARED;
  780. if (new_dentry->d_inode)
  781. req->r_inode_drop = drop_caps_for_unlink(new_dentry->d_inode);
  782. err = ceph_mdsc_do_request(mdsc, old_dir, req);
  783. if (!err && !req->r_reply_info.head->is_dentry) {
  784. /*
  785. * Normally d_move() is done by fill_trace (called by
  786. * do_request, above). If there is no trace, we need
  787. * to do it here.
  788. */
  789. d_move(old_dentry, new_dentry);
  790. }
  791. ceph_mdsc_put_request(req);
  792. return err;
  793. }
  794. /*
  795. * Check if dentry lease is valid. If not, delete the lease. Try to
  796. * renew if the least is more than half up.
  797. */
  798. static int dentry_lease_is_valid(struct dentry *dentry)
  799. {
  800. struct ceph_dentry_info *di;
  801. struct ceph_mds_session *s;
  802. int valid = 0;
  803. u32 gen;
  804. unsigned long ttl;
  805. struct ceph_mds_session *session = NULL;
  806. struct inode *dir = NULL;
  807. u32 seq = 0;
  808. spin_lock(&dentry->d_lock);
  809. di = ceph_dentry(dentry);
  810. if (di && di->lease_session) {
  811. s = di->lease_session;
  812. spin_lock(&s->s_cap_lock);
  813. gen = s->s_cap_gen;
  814. ttl = s->s_cap_ttl;
  815. spin_unlock(&s->s_cap_lock);
  816. if (di->lease_gen == gen &&
  817. time_before(jiffies, dentry->d_time) &&
  818. time_before(jiffies, ttl)) {
  819. valid = 1;
  820. if (di->lease_renew_after &&
  821. time_after(jiffies, di->lease_renew_after)) {
  822. /* we should renew */
  823. dir = dentry->d_parent->d_inode;
  824. session = ceph_get_mds_session(s);
  825. seq = di->lease_seq;
  826. di->lease_renew_after = 0;
  827. di->lease_renew_from = jiffies;
  828. }
  829. }
  830. }
  831. spin_unlock(&dentry->d_lock);
  832. if (session) {
  833. ceph_mdsc_lease_send_msg(session, dir, dentry,
  834. CEPH_MDS_LEASE_RENEW, seq);
  835. ceph_put_mds_session(session);
  836. }
  837. dout("dentry_lease_is_valid - dentry %p = %d\n", dentry, valid);
  838. return valid;
  839. }
  840. /*
  841. * Check if directory-wide content lease/cap is valid.
  842. */
  843. static int dir_lease_is_valid(struct inode *dir, struct dentry *dentry)
  844. {
  845. struct ceph_inode_info *ci = ceph_inode(dir);
  846. struct ceph_dentry_info *di = ceph_dentry(dentry);
  847. int valid = 0;
  848. spin_lock(&dir->i_lock);
  849. if (ci->i_shared_gen == di->lease_shared_gen)
  850. valid = __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1);
  851. spin_unlock(&dir->i_lock);
  852. dout("dir_lease_is_valid dir %p v%u dentry %p v%u = %d\n",
  853. dir, (unsigned)ci->i_shared_gen, dentry,
  854. (unsigned)di->lease_shared_gen, valid);
  855. return valid;
  856. }
  857. /*
  858. * Check if cached dentry can be trusted.
  859. */
  860. static int ceph_d_revalidate(struct dentry *dentry, struct nameidata *nd)
  861. {
  862. struct inode *dir = dentry->d_parent->d_inode;
  863. dout("d_revalidate %p '%.*s' inode %p\n", dentry,
  864. dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
  865. /* always trust cached snapped dentries, snapdir dentry */
  866. if (ceph_snap(dir) != CEPH_NOSNAP) {
  867. dout("d_revalidate %p '%.*s' inode %p is SNAPPED\n", dentry,
  868. dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
  869. goto out_touch;
  870. }
  871. if (dentry->d_inode && ceph_snap(dentry->d_inode) == CEPH_SNAPDIR)
  872. goto out_touch;
  873. if (dentry_lease_is_valid(dentry) ||
  874. dir_lease_is_valid(dir, dentry))
  875. goto out_touch;
  876. dout("d_revalidate %p invalid\n", dentry);
  877. d_drop(dentry);
  878. return 0;
  879. out_touch:
  880. ceph_dentry_lru_touch(dentry);
  881. return 1;
  882. }
  883. /*
  884. * When a dentry is released, clear the dir I_COMPLETE if it was part
  885. * of the current dir gen.
  886. */
  887. static void ceph_dentry_release(struct dentry *dentry)
  888. {
  889. struct ceph_dentry_info *di = ceph_dentry(dentry);
  890. struct inode *parent_inode = dentry->d_parent->d_inode;
  891. if (parent_inode) {
  892. struct ceph_inode_info *ci = ceph_inode(parent_inode);
  893. spin_lock(&parent_inode->i_lock);
  894. if (ci->i_shared_gen == di->lease_shared_gen) {
  895. dout(" clearing %p complete (d_release)\n",
  896. parent_inode);
  897. ci->i_ceph_flags &= ~CEPH_I_COMPLETE;
  898. ci->i_release_count++;
  899. }
  900. spin_unlock(&parent_inode->i_lock);
  901. }
  902. if (di) {
  903. ceph_dentry_lru_del(dentry);
  904. if (di->lease_session)
  905. ceph_put_mds_session(di->lease_session);
  906. kmem_cache_free(ceph_dentry_cachep, di);
  907. dentry->d_fsdata = NULL;
  908. }
  909. }
  910. static int ceph_snapdir_d_revalidate(struct dentry *dentry,
  911. struct nameidata *nd)
  912. {
  913. /*
  914. * Eventually, we'll want to revalidate snapped metadata
  915. * too... probably...
  916. */
  917. return 1;
  918. }
  919. /*
  920. * read() on a dir. This weird interface hack only works if mounted
  921. * with '-o dirstat'.
  922. */
  923. static ssize_t ceph_read_dir(struct file *file, char __user *buf, size_t size,
  924. loff_t *ppos)
  925. {
  926. struct ceph_file_info *cf = file->private_data;
  927. struct inode *inode = file->f_dentry->d_inode;
  928. struct ceph_inode_info *ci = ceph_inode(inode);
  929. int left;
  930. if (!ceph_test_opt(ceph_client(inode->i_sb), DIRSTAT))
  931. return -EISDIR;
  932. if (!cf->dir_info) {
  933. cf->dir_info = kmalloc(1024, GFP_NOFS);
  934. if (!cf->dir_info)
  935. return -ENOMEM;
  936. cf->dir_info_len =
  937. sprintf(cf->dir_info,
  938. "entries: %20lld\n"
  939. " files: %20lld\n"
  940. " subdirs: %20lld\n"
  941. "rentries: %20lld\n"
  942. " rfiles: %20lld\n"
  943. " rsubdirs: %20lld\n"
  944. "rbytes: %20lld\n"
  945. "rctime: %10ld.%09ld\n",
  946. ci->i_files + ci->i_subdirs,
  947. ci->i_files,
  948. ci->i_subdirs,
  949. ci->i_rfiles + ci->i_rsubdirs,
  950. ci->i_rfiles,
  951. ci->i_rsubdirs,
  952. ci->i_rbytes,
  953. (long)ci->i_rctime.tv_sec,
  954. (long)ci->i_rctime.tv_nsec);
  955. }
  956. if (*ppos >= cf->dir_info_len)
  957. return 0;
  958. size = min_t(unsigned, size, cf->dir_info_len-*ppos);
  959. left = copy_to_user(buf, cf->dir_info + *ppos, size);
  960. if (left == size)
  961. return -EFAULT;
  962. *ppos += (size - left);
  963. return size - left;
  964. }
  965. /*
  966. * an fsync() on a dir will wait for any uncommitted directory
  967. * operations to commit.
  968. */
  969. static int ceph_dir_fsync(struct file *file, struct dentry *dentry,
  970. int datasync)
  971. {
  972. struct inode *inode = dentry->d_inode;
  973. struct ceph_inode_info *ci = ceph_inode(inode);
  974. struct list_head *head = &ci->i_unsafe_dirops;
  975. struct ceph_mds_request *req;
  976. u64 last_tid;
  977. int ret = 0;
  978. dout("dir_fsync %p\n", inode);
  979. spin_lock(&ci->i_unsafe_lock);
  980. if (list_empty(head))
  981. goto out;
  982. req = list_entry(head->prev,
  983. struct ceph_mds_request, r_unsafe_dir_item);
  984. last_tid = req->r_tid;
  985. do {
  986. ceph_mdsc_get_request(req);
  987. spin_unlock(&ci->i_unsafe_lock);
  988. dout("dir_fsync %p wait on tid %llu (until %llu)\n",
  989. inode, req->r_tid, last_tid);
  990. if (req->r_timeout) {
  991. ret = wait_for_completion_timeout(
  992. &req->r_safe_completion, req->r_timeout);
  993. if (ret > 0)
  994. ret = 0;
  995. else if (ret == 0)
  996. ret = -EIO; /* timed out */
  997. } else {
  998. wait_for_completion(&req->r_safe_completion);
  999. }
  1000. spin_lock(&ci->i_unsafe_lock);
  1001. ceph_mdsc_put_request(req);
  1002. if (ret || list_empty(head))
  1003. break;
  1004. req = list_entry(head->next,
  1005. struct ceph_mds_request, r_unsafe_dir_item);
  1006. } while (req->r_tid < last_tid);
  1007. out:
  1008. spin_unlock(&ci->i_unsafe_lock);
  1009. return ret;
  1010. }
  1011. /*
  1012. * We maintain a private dentry LRU.
  1013. *
  1014. * FIXME: this needs to be changed to a per-mds lru to be useful.
  1015. */
  1016. void ceph_dentry_lru_add(struct dentry *dn)
  1017. {
  1018. struct ceph_dentry_info *di = ceph_dentry(dn);
  1019. struct ceph_mds_client *mdsc;
  1020. dout("dentry_lru_add %p %p '%.*s'\n", di, dn,
  1021. dn->d_name.len, dn->d_name.name);
  1022. if (di) {
  1023. mdsc = &ceph_client(dn->d_sb)->mdsc;
  1024. spin_lock(&mdsc->dentry_lru_lock);
  1025. list_add_tail(&di->lru, &mdsc->dentry_lru);
  1026. mdsc->num_dentry++;
  1027. spin_unlock(&mdsc->dentry_lru_lock);
  1028. }
  1029. }
  1030. void ceph_dentry_lru_touch(struct dentry *dn)
  1031. {
  1032. struct ceph_dentry_info *di = ceph_dentry(dn);
  1033. struct ceph_mds_client *mdsc;
  1034. dout("dentry_lru_touch %p %p '%.*s'\n", di, dn,
  1035. dn->d_name.len, dn->d_name.name);
  1036. if (di) {
  1037. mdsc = &ceph_client(dn->d_sb)->mdsc;
  1038. spin_lock(&mdsc->dentry_lru_lock);
  1039. list_move_tail(&di->lru, &mdsc->dentry_lru);
  1040. spin_unlock(&mdsc->dentry_lru_lock);
  1041. }
  1042. }
  1043. void ceph_dentry_lru_del(struct dentry *dn)
  1044. {
  1045. struct ceph_dentry_info *di = ceph_dentry(dn);
  1046. struct ceph_mds_client *mdsc;
  1047. dout("dentry_lru_del %p %p '%.*s'\n", di, dn,
  1048. dn->d_name.len, dn->d_name.name);
  1049. if (di) {
  1050. mdsc = &ceph_client(dn->d_sb)->mdsc;
  1051. spin_lock(&mdsc->dentry_lru_lock);
  1052. list_del_init(&di->lru);
  1053. mdsc->num_dentry--;
  1054. spin_unlock(&mdsc->dentry_lru_lock);
  1055. }
  1056. }
  1057. const struct file_operations ceph_dir_fops = {
  1058. .read = ceph_read_dir,
  1059. .readdir = ceph_readdir,
  1060. .llseek = ceph_dir_llseek,
  1061. .open = ceph_open,
  1062. .release = ceph_release,
  1063. .unlocked_ioctl = ceph_ioctl,
  1064. .fsync = ceph_dir_fsync,
  1065. };
  1066. const struct inode_operations ceph_dir_iops = {
  1067. .lookup = ceph_lookup,
  1068. .permission = ceph_permission,
  1069. .getattr = ceph_getattr,
  1070. .setattr = ceph_setattr,
  1071. .setxattr = ceph_setxattr,
  1072. .getxattr = ceph_getxattr,
  1073. .listxattr = ceph_listxattr,
  1074. .removexattr = ceph_removexattr,
  1075. .mknod = ceph_mknod,
  1076. .symlink = ceph_symlink,
  1077. .mkdir = ceph_mkdir,
  1078. .link = ceph_link,
  1079. .unlink = ceph_unlink,
  1080. .rmdir = ceph_unlink,
  1081. .rename = ceph_rename,
  1082. .create = ceph_create,
  1083. };
  1084. struct dentry_operations ceph_dentry_ops = {
  1085. .d_revalidate = ceph_d_revalidate,
  1086. .d_release = ceph_dentry_release,
  1087. };
  1088. struct dentry_operations ceph_snapdir_dentry_ops = {
  1089. .d_revalidate = ceph_snapdir_d_revalidate,
  1090. };
  1091. struct dentry_operations ceph_snap_dentry_ops = {
  1092. };