dir.c 33 KB

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