dir.c 33 KB

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