1 #include "ceph_debug.h"
4 #include <linux/kernel.h>
5 #include <linux/sched.h>
6 #include <linux/slab.h>
7 #include <linux/vmalloc.h>
8 #include <linux/wait.h>
9 #include <linux/writeback.h>
13 #include "messenger.h"
16 * Capability management
18 * The Ceph metadata servers control client access to inode metadata
19 * and file data by issuing capabilities, granting clients permission
20 * to read and/or write both inode field and file data to OSDs
21 * (storage nodes). Each capability consists of a set of bits
22 * indicating which operations are allowed.
24 * If the client holds a *_SHARED cap, the client has a coherent value
25 * that can be safely read from the cached inode.
27 * In the case of a *_EXCL (exclusive) or FILE_WR capabilities, the
28 * client is allowed to change inode attributes (e.g., file size,
29 * mtime), note its dirty state in the ceph_cap, and asynchronously
30 * flush that metadata change to the MDS.
32 * In the event of a conflicting operation (perhaps by another
33 * client), the MDS will revoke the conflicting client capabilities.
35 * In order for a client to cache an inode, it must hold a capability
36 * with at least one MDS server. When inodes are released, release
37 * notifications are batched and periodically sent en masse to the MDS
38 * cluster to release server state.
43 * Generate readable cap strings for debugging output.
45 #define MAX_CAP_STR 20
46 static char cap_str[MAX_CAP_STR][40];
47 static DEFINE_SPINLOCK(cap_str_lock);
48 static int last_cap_str;
50 static char *gcap_string(char *s, int c)
52 if (c & CEPH_CAP_GSHARED)
54 if (c & CEPH_CAP_GEXCL)
56 if (c & CEPH_CAP_GCACHE)
62 if (c & CEPH_CAP_GBUFFER)
64 if (c & CEPH_CAP_GLAZYIO)
69 const char *ceph_cap_string(int caps)
75 spin_lock(&cap_str_lock);
77 if (last_cap_str == MAX_CAP_STR)
79 spin_unlock(&cap_str_lock);
83 if (caps & CEPH_CAP_PIN)
86 c = (caps >> CEPH_CAP_SAUTH) & 3;
89 s = gcap_string(s, c);
92 c = (caps >> CEPH_CAP_SLINK) & 3;
95 s = gcap_string(s, c);
98 c = (caps >> CEPH_CAP_SXATTR) & 3;
101 s = gcap_string(s, c);
104 c = caps >> CEPH_CAP_SFILE;
107 s = gcap_string(s, c);
116 void ceph_caps_init(struct ceph_mds_client *mdsc)
118 INIT_LIST_HEAD(&mdsc->caps_list);
119 spin_lock_init(&mdsc->caps_list_lock);
122 void ceph_caps_finalize(struct ceph_mds_client *mdsc)
124 struct ceph_cap *cap;
126 spin_lock(&mdsc->caps_list_lock);
127 while (!list_empty(&mdsc->caps_list)) {
128 cap = list_first_entry(&mdsc->caps_list,
129 struct ceph_cap, caps_item);
130 list_del(&cap->caps_item);
131 kmem_cache_free(ceph_cap_cachep, cap);
133 mdsc->caps_total_count = 0;
134 mdsc->caps_avail_count = 0;
135 mdsc->caps_use_count = 0;
136 mdsc->caps_reserve_count = 0;
137 mdsc->caps_min_count = 0;
138 spin_unlock(&mdsc->caps_list_lock);
141 void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta)
143 spin_lock(&mdsc->caps_list_lock);
144 mdsc->caps_min_count += delta;
145 BUG_ON(mdsc->caps_min_count < 0);
146 spin_unlock(&mdsc->caps_list_lock);
149 int ceph_reserve_caps(struct ceph_mds_client *mdsc,
150 struct ceph_cap_reservation *ctx, int need)
153 struct ceph_cap *cap;
159 dout("reserve caps ctx=%p need=%d\n", ctx, need);
161 /* first reserve any caps that are already allocated */
162 spin_lock(&mdsc->caps_list_lock);
163 if (mdsc->caps_avail_count >= need)
166 have = mdsc->caps_avail_count;
167 mdsc->caps_avail_count -= have;
168 mdsc->caps_reserve_count += have;
169 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
170 mdsc->caps_reserve_count +
171 mdsc->caps_avail_count);
172 spin_unlock(&mdsc->caps_list_lock);
174 for (i = have; i < need; i++) {
175 cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS);
178 goto out_alloc_count;
180 list_add(&cap->caps_item, &newcaps);
183 BUG_ON(have + alloc != need);
185 spin_lock(&mdsc->caps_list_lock);
186 mdsc->caps_total_count += alloc;
187 mdsc->caps_reserve_count += alloc;
188 list_splice(&newcaps, &mdsc->caps_list);
190 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
191 mdsc->caps_reserve_count +
192 mdsc->caps_avail_count);
193 spin_unlock(&mdsc->caps_list_lock);
196 dout("reserve caps ctx=%p %d = %d used + %d resv + %d avail\n",
197 ctx, mdsc->caps_total_count, mdsc->caps_use_count,
198 mdsc->caps_reserve_count, mdsc->caps_avail_count);
202 /* we didn't manage to reserve as much as we needed */
203 pr_warning("reserve caps ctx=%p ENOMEM need=%d got=%d\n",
208 int ceph_unreserve_caps(struct ceph_mds_client *mdsc,
209 struct ceph_cap_reservation *ctx)
211 dout("unreserve caps ctx=%p count=%d\n", ctx, ctx->count);
213 spin_lock(&mdsc->caps_list_lock);
214 BUG_ON(mdsc->caps_reserve_count < ctx->count);
215 mdsc->caps_reserve_count -= ctx->count;
216 mdsc->caps_avail_count += ctx->count;
218 dout("unreserve caps %d = %d used + %d resv + %d avail\n",
219 mdsc->caps_total_count, mdsc->caps_use_count,
220 mdsc->caps_reserve_count, mdsc->caps_avail_count);
221 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
222 mdsc->caps_reserve_count +
223 mdsc->caps_avail_count);
224 spin_unlock(&mdsc->caps_list_lock);
229 static struct ceph_cap *get_cap(struct ceph_mds_client *mdsc,
230 struct ceph_cap_reservation *ctx)
232 struct ceph_cap *cap = NULL;
234 /* temporary, until we do something about cap import/export */
236 cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS);
238 mdsc->caps_use_count++;
239 mdsc->caps_total_count++;
244 spin_lock(&mdsc->caps_list_lock);
245 dout("get_cap ctx=%p (%d) %d = %d used + %d resv + %d avail\n",
246 ctx, ctx->count, mdsc->caps_total_count, mdsc->caps_use_count,
247 mdsc->caps_reserve_count, mdsc->caps_avail_count);
249 BUG_ON(ctx->count > mdsc->caps_reserve_count);
250 BUG_ON(list_empty(&mdsc->caps_list));
253 mdsc->caps_reserve_count--;
254 mdsc->caps_use_count++;
256 cap = list_first_entry(&mdsc->caps_list, struct ceph_cap, caps_item);
257 list_del(&cap->caps_item);
259 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
260 mdsc->caps_reserve_count + mdsc->caps_avail_count);
261 spin_unlock(&mdsc->caps_list_lock);
265 void ceph_put_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap)
267 spin_lock(&mdsc->caps_list_lock);
268 dout("put_cap %p %d = %d used + %d resv + %d avail\n",
269 cap, mdsc->caps_total_count, mdsc->caps_use_count,
270 mdsc->caps_reserve_count, mdsc->caps_avail_count);
271 mdsc->caps_use_count--;
273 * Keep some preallocated caps around (ceph_min_count), to
274 * avoid lots of free/alloc churn.
276 if (mdsc->caps_avail_count >= mdsc->caps_reserve_count +
277 mdsc->caps_min_count) {
278 mdsc->caps_total_count--;
279 kmem_cache_free(ceph_cap_cachep, cap);
281 mdsc->caps_avail_count++;
282 list_add(&cap->caps_item, &mdsc->caps_list);
285 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
286 mdsc->caps_reserve_count + mdsc->caps_avail_count);
287 spin_unlock(&mdsc->caps_list_lock);
290 void ceph_reservation_status(struct ceph_client *client,
291 int *total, int *avail, int *used, int *reserved,
294 struct ceph_mds_client *mdsc = &client->mdsc;
297 *total = mdsc->caps_total_count;
299 *avail = mdsc->caps_avail_count;
301 *used = mdsc->caps_use_count;
303 *reserved = mdsc->caps_reserve_count;
305 *min = mdsc->caps_min_count;
309 * Find ceph_cap for given mds, if any.
311 * Called with i_lock held.
313 static struct ceph_cap *__get_cap_for_mds(struct ceph_inode_info *ci, int mds)
315 struct ceph_cap *cap;
316 struct rb_node *n = ci->i_caps.rb_node;
319 cap = rb_entry(n, struct ceph_cap, ci_node);
322 else if (mds > cap->mds)
330 struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci, int mds)
332 struct ceph_cap *cap;
334 spin_lock(&ci->vfs_inode.i_lock);
335 cap = __get_cap_for_mds(ci, mds);
336 spin_unlock(&ci->vfs_inode.i_lock);
341 * Return id of any MDS with a cap, preferably FILE_WR|BUFFER|EXCL, else -1.
343 static int __ceph_get_cap_mds(struct ceph_inode_info *ci)
345 struct ceph_cap *cap;
349 /* prefer mds with WR|BUFFER|EXCL caps */
350 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
351 cap = rb_entry(p, struct ceph_cap, ci_node);
353 if (cap->issued & (CEPH_CAP_FILE_WR |
354 CEPH_CAP_FILE_BUFFER |
361 int ceph_get_cap_mds(struct inode *inode)
364 spin_lock(&inode->i_lock);
365 mds = __ceph_get_cap_mds(ceph_inode(inode));
366 spin_unlock(&inode->i_lock);
371 * Called under i_lock.
373 static void __insert_cap_node(struct ceph_inode_info *ci,
374 struct ceph_cap *new)
376 struct rb_node **p = &ci->i_caps.rb_node;
377 struct rb_node *parent = NULL;
378 struct ceph_cap *cap = NULL;
382 cap = rb_entry(parent, struct ceph_cap, ci_node);
383 if (new->mds < cap->mds)
385 else if (new->mds > cap->mds)
391 rb_link_node(&new->ci_node, parent, p);
392 rb_insert_color(&new->ci_node, &ci->i_caps);
396 * (re)set cap hold timeouts, which control the delayed release
397 * of unused caps back to the MDS. Should be called on cap use.
399 static void __cap_set_timeouts(struct ceph_mds_client *mdsc,
400 struct ceph_inode_info *ci)
402 struct ceph_mount_args *ma = mdsc->client->mount_args;
404 ci->i_hold_caps_min = round_jiffies(jiffies +
405 ma->caps_wanted_delay_min * HZ);
406 ci->i_hold_caps_max = round_jiffies(jiffies +
407 ma->caps_wanted_delay_max * HZ);
408 dout("__cap_set_timeouts %p min %lu max %lu\n", &ci->vfs_inode,
409 ci->i_hold_caps_min - jiffies, ci->i_hold_caps_max - jiffies);
413 * (Re)queue cap at the end of the delayed cap release list.
415 * If I_FLUSH is set, leave the inode at the front of the list.
417 * Caller holds i_lock
418 * -> we take mdsc->cap_delay_lock
420 static void __cap_delay_requeue(struct ceph_mds_client *mdsc,
421 struct ceph_inode_info *ci)
423 __cap_set_timeouts(mdsc, ci);
424 dout("__cap_delay_requeue %p flags %d at %lu\n", &ci->vfs_inode,
425 ci->i_ceph_flags, ci->i_hold_caps_max);
426 if (!mdsc->stopping) {
427 spin_lock(&mdsc->cap_delay_lock);
428 if (!list_empty(&ci->i_cap_delay_list)) {
429 if (ci->i_ceph_flags & CEPH_I_FLUSH)
431 list_del_init(&ci->i_cap_delay_list);
433 list_add_tail(&ci->i_cap_delay_list, &mdsc->cap_delay_list);
435 spin_unlock(&mdsc->cap_delay_lock);
440 * Queue an inode for immediate writeback. Mark inode with I_FLUSH,
441 * indicating we should send a cap message to flush dirty metadata
442 * asap, and move to the front of the delayed cap list.
444 static void __cap_delay_requeue_front(struct ceph_mds_client *mdsc,
445 struct ceph_inode_info *ci)
447 dout("__cap_delay_requeue_front %p\n", &ci->vfs_inode);
448 spin_lock(&mdsc->cap_delay_lock);
449 ci->i_ceph_flags |= CEPH_I_FLUSH;
450 if (!list_empty(&ci->i_cap_delay_list))
451 list_del_init(&ci->i_cap_delay_list);
452 list_add(&ci->i_cap_delay_list, &mdsc->cap_delay_list);
453 spin_unlock(&mdsc->cap_delay_lock);
457 * Cancel delayed work on cap.
459 * Caller must hold i_lock.
461 static void __cap_delay_cancel(struct ceph_mds_client *mdsc,
462 struct ceph_inode_info *ci)
464 dout("__cap_delay_cancel %p\n", &ci->vfs_inode);
465 if (list_empty(&ci->i_cap_delay_list))
467 spin_lock(&mdsc->cap_delay_lock);
468 list_del_init(&ci->i_cap_delay_list);
469 spin_unlock(&mdsc->cap_delay_lock);
473 * Common issue checks for add_cap, handle_cap_grant.
475 static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap,
478 unsigned had = __ceph_caps_issued(ci, NULL);
481 * Each time we receive FILE_CACHE anew, we increment
484 if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) &&
485 (had & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0)
489 * if we are newly issued FILE_SHARED, clear I_COMPLETE; we
490 * don't know what happened to this directory while we didn't
493 if ((issued & CEPH_CAP_FILE_SHARED) &&
494 (had & CEPH_CAP_FILE_SHARED) == 0) {
496 if (S_ISDIR(ci->vfs_inode.i_mode)) {
497 dout(" marking %p NOT complete\n", &ci->vfs_inode);
498 ci->i_ceph_flags &= ~CEPH_I_COMPLETE;
504 * Add a capability under the given MDS session.
506 * Caller should hold session snap_rwsem (read) and s_mutex.
508 * @fmode is the open file mode, if we are opening a file, otherwise
509 * it is < 0. (This is so we can atomically add the cap and add an
510 * open file reference to it.)
512 int ceph_add_cap(struct inode *inode,
513 struct ceph_mds_session *session, u64 cap_id,
514 int fmode, unsigned issued, unsigned wanted,
515 unsigned seq, unsigned mseq, u64 realmino, int flags,
516 struct ceph_cap_reservation *caps_reservation)
518 struct ceph_mds_client *mdsc = &ceph_inode_to_client(inode)->mdsc;
519 struct ceph_inode_info *ci = ceph_inode(inode);
520 struct ceph_cap *new_cap = NULL;
521 struct ceph_cap *cap;
522 int mds = session->s_mds;
525 dout("add_cap %p mds%d cap %llx %s seq %d\n", inode,
526 session->s_mds, cap_id, ceph_cap_string(issued), seq);
529 * If we are opening the file, include file mode wanted bits
533 wanted |= ceph_caps_for_mode(fmode);
536 spin_lock(&inode->i_lock);
537 cap = __get_cap_for_mds(ci, mds);
543 spin_unlock(&inode->i_lock);
544 new_cap = get_cap(mdsc, caps_reservation);
551 cap->implemented = 0;
556 __insert_cap_node(ci, cap);
558 /* clear out old exporting info? (i.e. on cap import) */
559 if (ci->i_cap_exporting_mds == mds) {
560 ci->i_cap_exporting_issued = 0;
561 ci->i_cap_exporting_mseq = 0;
562 ci->i_cap_exporting_mds = -1;
565 /* add to session cap list */
566 cap->session = session;
567 spin_lock(&session->s_cap_lock);
568 list_add_tail(&cap->session_caps, &session->s_caps);
569 session->s_nr_caps++;
570 spin_unlock(&session->s_cap_lock);
573 if (!ci->i_snap_realm) {
575 * add this inode to the appropriate snap realm
577 struct ceph_snap_realm *realm = ceph_lookup_snap_realm(mdsc,
580 ceph_get_snap_realm(mdsc, realm);
581 spin_lock(&realm->inodes_with_caps_lock);
582 ci->i_snap_realm = realm;
583 list_add(&ci->i_snap_realm_item,
584 &realm->inodes_with_caps);
585 spin_unlock(&realm->inodes_with_caps_lock);
587 pr_err("ceph_add_cap: couldn't find snap realm %llx\n",
592 __check_cap_issue(ci, cap, issued);
595 * If we are issued caps we don't want, or the mds' wanted
596 * value appears to be off, queue a check so we'll release
597 * later and/or update the mds wanted value.
599 actual_wanted = __ceph_caps_wanted(ci);
600 if ((wanted & ~actual_wanted) ||
601 (issued & ~actual_wanted & CEPH_CAP_ANY_WR)) {
602 dout(" issued %s, mds wanted %s, actual %s, queueing\n",
603 ceph_cap_string(issued), ceph_cap_string(wanted),
604 ceph_cap_string(actual_wanted));
605 __cap_delay_requeue(mdsc, ci);
608 if (flags & CEPH_CAP_FLAG_AUTH)
609 ci->i_auth_cap = cap;
610 else if (ci->i_auth_cap == cap)
611 ci->i_auth_cap = NULL;
613 dout("add_cap inode %p (%llx.%llx) cap %p %s now %s seq %d mds%d\n",
614 inode, ceph_vinop(inode), cap, ceph_cap_string(issued),
615 ceph_cap_string(issued|cap->issued), seq, mds);
616 cap->cap_id = cap_id;
617 cap->issued = issued;
618 cap->implemented |= issued;
619 cap->mds_wanted |= wanted;
621 cap->issue_seq = seq;
623 cap->cap_gen = session->s_cap_gen;
626 __ceph_get_fmode(ci, fmode);
627 spin_unlock(&inode->i_lock);
628 wake_up_all(&ci->i_cap_wq);
633 * Return true if cap has not timed out and belongs to the current
634 * generation of the MDS session (i.e. has not gone 'stale' due to
635 * us losing touch with the mds).
637 static int __cap_is_valid(struct ceph_cap *cap)
642 spin_lock(&cap->session->s_cap_lock);
643 gen = cap->session->s_cap_gen;
644 ttl = cap->session->s_cap_ttl;
645 spin_unlock(&cap->session->s_cap_lock);
647 if (cap->cap_gen < gen || time_after_eq(jiffies, ttl)) {
648 dout("__cap_is_valid %p cap %p issued %s "
649 "but STALE (gen %u vs %u)\n", &cap->ci->vfs_inode,
650 cap, ceph_cap_string(cap->issued), cap->cap_gen, gen);
658 * Return set of valid cap bits issued to us. Note that caps time
659 * out, and may be invalidated in bulk if the client session times out
660 * and session->s_cap_gen is bumped.
662 int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented)
664 int have = ci->i_snap_caps | ci->i_cap_exporting_issued;
665 struct ceph_cap *cap;
670 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
671 cap = rb_entry(p, struct ceph_cap, ci_node);
672 if (!__cap_is_valid(cap))
674 dout("__ceph_caps_issued %p cap %p issued %s\n",
675 &ci->vfs_inode, cap, ceph_cap_string(cap->issued));
678 *implemented |= cap->implemented;
684 * Get cap bits issued by caps other than @ocap
686 int __ceph_caps_issued_other(struct ceph_inode_info *ci, struct ceph_cap *ocap)
688 int have = ci->i_snap_caps;
689 struct ceph_cap *cap;
692 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
693 cap = rb_entry(p, struct ceph_cap, ci_node);
696 if (!__cap_is_valid(cap))
704 * Move a cap to the end of the LRU (oldest caps at list head, newest
707 static void __touch_cap(struct ceph_cap *cap)
709 struct ceph_mds_session *s = cap->session;
711 spin_lock(&s->s_cap_lock);
712 if (s->s_cap_iterator == NULL) {
713 dout("__touch_cap %p cap %p mds%d\n", &cap->ci->vfs_inode, cap,
715 list_move_tail(&cap->session_caps, &s->s_caps);
717 dout("__touch_cap %p cap %p mds%d NOP, iterating over caps\n",
718 &cap->ci->vfs_inode, cap, s->s_mds);
720 spin_unlock(&s->s_cap_lock);
724 * Check if we hold the given mask. If so, move the cap(s) to the
725 * front of their respective LRUs. (This is the preferred way for
726 * callers to check for caps they want.)
728 int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int touch)
730 struct ceph_cap *cap;
732 int have = ci->i_snap_caps;
734 if ((have & mask) == mask) {
735 dout("__ceph_caps_issued_mask %p snap issued %s"
736 " (mask %s)\n", &ci->vfs_inode,
737 ceph_cap_string(have),
738 ceph_cap_string(mask));
742 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
743 cap = rb_entry(p, struct ceph_cap, ci_node);
744 if (!__cap_is_valid(cap))
746 if ((cap->issued & mask) == mask) {
747 dout("__ceph_caps_issued_mask %p cap %p issued %s"
748 " (mask %s)\n", &ci->vfs_inode, cap,
749 ceph_cap_string(cap->issued),
750 ceph_cap_string(mask));
756 /* does a combination of caps satisfy mask? */
758 if ((have & mask) == mask) {
759 dout("__ceph_caps_issued_mask %p combo issued %s"
760 " (mask %s)\n", &ci->vfs_inode,
761 ceph_cap_string(cap->issued),
762 ceph_cap_string(mask));
766 /* touch this + preceeding caps */
768 for (q = rb_first(&ci->i_caps); q != p;
770 cap = rb_entry(q, struct ceph_cap,
772 if (!__cap_is_valid(cap))
785 * Return true if mask caps are currently being revoked by an MDS.
787 int ceph_caps_revoking(struct ceph_inode_info *ci, int mask)
789 struct inode *inode = &ci->vfs_inode;
790 struct ceph_cap *cap;
794 spin_lock(&inode->i_lock);
795 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
796 cap = rb_entry(p, struct ceph_cap, ci_node);
797 if (__cap_is_valid(cap) &&
798 (cap->implemented & ~cap->issued & mask)) {
803 spin_unlock(&inode->i_lock);
804 dout("ceph_caps_revoking %p %s = %d\n", inode,
805 ceph_cap_string(mask), ret);
809 int __ceph_caps_used(struct ceph_inode_info *ci)
813 used |= CEPH_CAP_PIN;
815 used |= CEPH_CAP_FILE_RD;
816 if (ci->i_rdcache_ref || ci->i_rdcache_gen)
817 used |= CEPH_CAP_FILE_CACHE;
819 used |= CEPH_CAP_FILE_WR;
820 if (ci->i_wrbuffer_ref)
821 used |= CEPH_CAP_FILE_BUFFER;
826 * wanted, by virtue of open file modes
828 int __ceph_caps_file_wanted(struct ceph_inode_info *ci)
832 for (mode = 0; mode < CEPH_FILE_MODE_NUM; mode++)
833 if (ci->i_nr_by_mode[mode])
834 want |= ceph_caps_for_mode(mode);
839 * Return caps we have registered with the MDS(s) as 'wanted'.
841 int __ceph_caps_mds_wanted(struct ceph_inode_info *ci)
843 struct ceph_cap *cap;
847 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
848 cap = rb_entry(p, struct ceph_cap, ci_node);
849 if (!__cap_is_valid(cap))
851 mds_wanted |= cap->mds_wanted;
857 * called under i_lock
859 static int __ceph_is_any_caps(struct ceph_inode_info *ci)
861 return !RB_EMPTY_ROOT(&ci->i_caps) || ci->i_cap_exporting_mds >= 0;
865 * Remove a cap. Take steps to deal with a racing iterate_session_caps.
867 * caller should hold i_lock.
868 * caller will not hold session s_mutex if called from destroy_inode.
870 void __ceph_remove_cap(struct ceph_cap *cap)
872 struct ceph_mds_session *session = cap->session;
873 struct ceph_inode_info *ci = cap->ci;
874 struct ceph_mds_client *mdsc =
875 &ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc;
878 dout("__ceph_remove_cap %p from %p\n", cap, &ci->vfs_inode);
880 /* remove from session list */
881 spin_lock(&session->s_cap_lock);
882 if (session->s_cap_iterator == cap) {
883 /* not yet, we are iterating over this very cap */
884 dout("__ceph_remove_cap delaying %p removal from session %p\n",
887 list_del_init(&cap->session_caps);
888 session->s_nr_caps--;
892 /* protect backpointer with s_cap_lock: see iterate_session_caps */
894 spin_unlock(&session->s_cap_lock);
896 /* remove from inode list */
897 rb_erase(&cap->ci_node, &ci->i_caps);
898 if (ci->i_auth_cap == cap)
899 ci->i_auth_cap = NULL;
902 ceph_put_cap(mdsc, cap);
904 if (!__ceph_is_any_caps(ci) && ci->i_snap_realm) {
905 struct ceph_snap_realm *realm = ci->i_snap_realm;
906 spin_lock(&realm->inodes_with_caps_lock);
907 list_del_init(&ci->i_snap_realm_item);
908 ci->i_snap_realm_counter++;
909 ci->i_snap_realm = NULL;
910 spin_unlock(&realm->inodes_with_caps_lock);
911 ceph_put_snap_realm(mdsc, realm);
913 if (!__ceph_is_any_real_caps(ci))
914 __cap_delay_cancel(mdsc, ci);
918 * Build and send a cap message to the given MDS.
920 * Caller should be holding s_mutex.
922 static int send_cap_msg(struct ceph_mds_session *session,
923 u64 ino, u64 cid, int op,
924 int caps, int wanted, int dirty,
925 u32 seq, u64 flush_tid, u32 issue_seq, u32 mseq,
926 u64 size, u64 max_size,
927 struct timespec *mtime, struct timespec *atime,
929 uid_t uid, gid_t gid, mode_t mode,
931 struct ceph_buffer *xattrs_buf,
934 struct ceph_mds_caps *fc;
935 struct ceph_msg *msg;
937 dout("send_cap_msg %s %llx %llx caps %s wanted %s dirty %s"
938 " seq %u/%u mseq %u follows %lld size %llu/%llu"
939 " xattr_ver %llu xattr_len %d\n", ceph_cap_op_name(op),
940 cid, ino, ceph_cap_string(caps), ceph_cap_string(wanted),
941 ceph_cap_string(dirty),
942 seq, issue_seq, mseq, follows, size, max_size,
943 xattr_version, xattrs_buf ? (int)xattrs_buf->vec.iov_len : 0);
945 msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, sizeof(*fc), GFP_NOFS);
949 msg->hdr.tid = cpu_to_le64(flush_tid);
951 fc = msg->front.iov_base;
952 memset(fc, 0, sizeof(*fc));
954 fc->cap_id = cpu_to_le64(cid);
955 fc->op = cpu_to_le32(op);
956 fc->seq = cpu_to_le32(seq);
957 fc->issue_seq = cpu_to_le32(issue_seq);
958 fc->migrate_seq = cpu_to_le32(mseq);
959 fc->caps = cpu_to_le32(caps);
960 fc->wanted = cpu_to_le32(wanted);
961 fc->dirty = cpu_to_le32(dirty);
962 fc->ino = cpu_to_le64(ino);
963 fc->snap_follows = cpu_to_le64(follows);
965 fc->size = cpu_to_le64(size);
966 fc->max_size = cpu_to_le64(max_size);
968 ceph_encode_timespec(&fc->mtime, mtime);
970 ceph_encode_timespec(&fc->atime, atime);
971 fc->time_warp_seq = cpu_to_le32(time_warp_seq);
973 fc->uid = cpu_to_le32(uid);
974 fc->gid = cpu_to_le32(gid);
975 fc->mode = cpu_to_le32(mode);
977 fc->xattr_version = cpu_to_le64(xattr_version);
979 msg->middle = ceph_buffer_get(xattrs_buf);
980 fc->xattr_len = cpu_to_le32(xattrs_buf->vec.iov_len);
981 msg->hdr.middle_len = cpu_to_le32(xattrs_buf->vec.iov_len);
984 ceph_con_send(&session->s_con, msg);
988 static void __queue_cap_release(struct ceph_mds_session *session,
989 u64 ino, u64 cap_id, u32 migrate_seq,
992 struct ceph_msg *msg;
993 struct ceph_mds_cap_release *head;
994 struct ceph_mds_cap_item *item;
996 spin_lock(&session->s_cap_lock);
997 BUG_ON(!session->s_num_cap_releases);
998 msg = list_first_entry(&session->s_cap_releases,
999 struct ceph_msg, list_head);
1001 dout(" adding %llx release to mds%d msg %p (%d left)\n",
1002 ino, session->s_mds, msg, session->s_num_cap_releases);
1004 BUG_ON(msg->front.iov_len + sizeof(*item) > PAGE_CACHE_SIZE);
1005 head = msg->front.iov_base;
1006 head->num = cpu_to_le32(le32_to_cpu(head->num) + 1);
1007 item = msg->front.iov_base + msg->front.iov_len;
1008 item->ino = cpu_to_le64(ino);
1009 item->cap_id = cpu_to_le64(cap_id);
1010 item->migrate_seq = cpu_to_le32(migrate_seq);
1011 item->seq = cpu_to_le32(issue_seq);
1013 session->s_num_cap_releases--;
1015 msg->front.iov_len += sizeof(*item);
1016 if (le32_to_cpu(head->num) == CEPH_CAPS_PER_RELEASE) {
1017 dout(" release msg %p full\n", msg);
1018 list_move_tail(&msg->list_head, &session->s_cap_releases_done);
1020 dout(" release msg %p at %d/%d (%d)\n", msg,
1021 (int)le32_to_cpu(head->num),
1022 (int)CEPH_CAPS_PER_RELEASE,
1023 (int)msg->front.iov_len);
1025 spin_unlock(&session->s_cap_lock);
1029 * Queue cap releases when an inode is dropped from our cache. Since
1030 * inode is about to be destroyed, there is no need for i_lock.
1032 void ceph_queue_caps_release(struct inode *inode)
1034 struct ceph_inode_info *ci = ceph_inode(inode);
1037 p = rb_first(&ci->i_caps);
1039 struct ceph_cap *cap = rb_entry(p, struct ceph_cap, ci_node);
1040 struct ceph_mds_session *session = cap->session;
1042 __queue_cap_release(session, ceph_ino(inode), cap->cap_id,
1043 cap->mseq, cap->issue_seq);
1045 __ceph_remove_cap(cap);
1050 * Send a cap msg on the given inode. Update our caps state, then
1051 * drop i_lock and send the message.
1053 * Make note of max_size reported/requested from mds, revoked caps
1054 * that have now been implemented.
1056 * Make half-hearted attempt ot to invalidate page cache if we are
1057 * dropping RDCACHE. Note that this will leave behind locked pages
1058 * that we'll then need to deal with elsewhere.
1060 * Return non-zero if delayed release, or we experienced an error
1061 * such that the caller should requeue + retry later.
1063 * called with i_lock, then drops it.
1064 * caller should hold snap_rwsem (read), s_mutex.
1066 static int __send_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap,
1067 int op, int used, int want, int retain, int flushing,
1068 unsigned *pflush_tid)
1069 __releases(cap->ci->vfs_inode->i_lock)
1071 struct ceph_inode_info *ci = cap->ci;
1072 struct inode *inode = &ci->vfs_inode;
1073 u64 cap_id = cap->cap_id;
1074 int held, revoking, dropping, keep;
1075 u64 seq, issue_seq, mseq, time_warp_seq, follows;
1077 struct timespec mtime, atime;
1082 struct ceph_mds_session *session;
1083 u64 xattr_version = 0;
1089 held = cap->issued | cap->implemented;
1090 revoking = cap->implemented & ~cap->issued;
1091 retain &= ~revoking;
1092 dropping = cap->issued & ~retain;
1094 dout("__send_cap %p cap %p session %p %s -> %s (revoking %s)\n",
1095 inode, cap, cap->session,
1096 ceph_cap_string(held), ceph_cap_string(held & retain),
1097 ceph_cap_string(revoking));
1098 BUG_ON((retain & CEPH_CAP_PIN) == 0);
1100 session = cap->session;
1102 /* don't release wanted unless we've waited a bit. */
1103 if ((ci->i_ceph_flags & CEPH_I_NODELAY) == 0 &&
1104 time_before(jiffies, ci->i_hold_caps_min)) {
1105 dout(" delaying issued %s -> %s, wanted %s -> %s on send\n",
1106 ceph_cap_string(cap->issued),
1107 ceph_cap_string(cap->issued & retain),
1108 ceph_cap_string(cap->mds_wanted),
1109 ceph_cap_string(want));
1110 want |= cap->mds_wanted;
1111 retain |= cap->issued;
1114 ci->i_ceph_flags &= ~(CEPH_I_NODELAY | CEPH_I_FLUSH);
1116 cap->issued &= retain; /* drop bits we don't want */
1117 if (cap->implemented & ~cap->issued) {
1119 * Wake up any waiters on wanted -> needed transition.
1120 * This is due to the weird transition from buffered
1121 * to sync IO... we need to flush dirty pages _before_
1122 * allowing sync writes to avoid reordering.
1126 cap->implemented &= cap->issued | used;
1127 cap->mds_wanted = want;
1131 * assign a tid for flush operations so we can avoid
1132 * flush1 -> dirty1 -> flush2 -> flushack1 -> mark
1133 * clean type races. track latest tid for every bit
1134 * so we can handle flush AxFw, flush Fw, and have the
1135 * first ack clean Ax.
1137 flush_tid = ++ci->i_cap_flush_last_tid;
1139 *pflush_tid = flush_tid;
1140 dout(" cap_flush_tid %d\n", (int)flush_tid);
1141 for (i = 0; i < CEPH_CAP_BITS; i++)
1142 if (flushing & (1 << i))
1143 ci->i_cap_flush_tid[i] = flush_tid;
1146 keep = cap->implemented;
1148 issue_seq = cap->issue_seq;
1150 size = inode->i_size;
1151 ci->i_reported_size = size;
1152 max_size = ci->i_wanted_max_size;
1153 ci->i_requested_max_size = max_size;
1154 mtime = inode->i_mtime;
1155 atime = inode->i_atime;
1156 time_warp_seq = ci->i_time_warp_seq;
1157 follows = ci->i_snap_realm->cached_context->seq;
1160 mode = inode->i_mode;
1162 if (dropping & CEPH_CAP_XATTR_EXCL) {
1163 __ceph_build_xattrs_blob(ci);
1164 xattr_version = ci->i_xattrs.version + 1;
1167 spin_unlock(&inode->i_lock);
1169 ret = send_cap_msg(session, ceph_vino(inode).ino, cap_id,
1170 op, keep, want, flushing, seq, flush_tid, issue_seq, mseq,
1171 size, max_size, &mtime, &atime, time_warp_seq,
1174 (flushing & CEPH_CAP_XATTR_EXCL) ? ci->i_xattrs.blob : NULL,
1177 dout("error sending cap msg, must requeue %p\n", inode);
1182 wake_up_all(&ci->i_cap_wq);
1188 * When a snapshot is taken, clients accumulate dirty metadata on
1189 * inodes with capabilities in ceph_cap_snaps to describe the file
1190 * state at the time the snapshot was taken. This must be flushed
1191 * asynchronously back to the MDS once sync writes complete and dirty
1192 * data is written out.
1194 * Called under i_lock. Takes s_mutex as needed.
1196 void __ceph_flush_snaps(struct ceph_inode_info *ci,
1197 struct ceph_mds_session **psession)
1198 __releases(ci->vfs_inode->i_lock)
1199 __acquires(ci->vfs_inode->i_lock)
1201 struct inode *inode = &ci->vfs_inode;
1203 struct ceph_cap_snap *capsnap;
1205 struct ceph_mds_client *mdsc = &ceph_inode_to_client(inode)->mdsc;
1206 struct ceph_mds_session *session = NULL; /* if session != NULL, we hold
1208 u64 next_follows = 0; /* keep track of how far we've gotten through the
1209 i_cap_snaps list, and skip these entries next time
1210 around to avoid an infinite loop */
1213 session = *psession;
1215 dout("__flush_snaps %p\n", inode);
1217 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) {
1218 /* avoid an infiniute loop after retry */
1219 if (capsnap->follows < next_follows)
1222 * we need to wait for sync writes to complete and for dirty
1223 * pages to be written out.
1225 if (capsnap->dirty_pages || capsnap->writing)
1229 * if cap writeback already occurred, we should have dropped
1230 * the capsnap in ceph_put_wrbuffer_cap_refs.
1232 BUG_ON(capsnap->dirty == 0);
1234 /* pick mds, take s_mutex */
1235 if (ci->i_auth_cap == NULL) {
1236 dout("no auth cap (migrating?), doing nothing\n");
1239 mds = ci->i_auth_cap->session->s_mds;
1240 mseq = ci->i_auth_cap->mseq;
1242 if (session && session->s_mds != mds) {
1243 dout("oops, wrong session %p mutex\n", session);
1244 mutex_unlock(&session->s_mutex);
1245 ceph_put_mds_session(session);
1249 spin_unlock(&inode->i_lock);
1250 mutex_lock(&mdsc->mutex);
1251 session = __ceph_lookup_mds_session(mdsc, mds);
1252 mutex_unlock(&mdsc->mutex);
1254 dout("inverting session/ino locks on %p\n",
1256 mutex_lock(&session->s_mutex);
1259 * if session == NULL, we raced against a cap
1260 * deletion or migration. retry, and we'll
1261 * get a better @mds value next time.
1263 spin_lock(&inode->i_lock);
1267 capsnap->flush_tid = ++ci->i_cap_flush_last_tid;
1268 atomic_inc(&capsnap->nref);
1269 if (!list_empty(&capsnap->flushing_item))
1270 list_del_init(&capsnap->flushing_item);
1271 list_add_tail(&capsnap->flushing_item,
1272 &session->s_cap_snaps_flushing);
1273 spin_unlock(&inode->i_lock);
1275 dout("flush_snaps %p cap_snap %p follows %lld size %llu\n",
1276 inode, capsnap, next_follows, capsnap->size);
1277 send_cap_msg(session, ceph_vino(inode).ino, 0,
1278 CEPH_CAP_OP_FLUSHSNAP, capsnap->issued, 0,
1279 capsnap->dirty, 0, capsnap->flush_tid, 0, mseq,
1281 &capsnap->mtime, &capsnap->atime,
1282 capsnap->time_warp_seq,
1283 capsnap->uid, capsnap->gid, capsnap->mode,
1287 next_follows = capsnap->follows + 1;
1288 ceph_put_cap_snap(capsnap);
1290 spin_lock(&inode->i_lock);
1294 /* we flushed them all; remove this inode from the queue */
1295 spin_lock(&mdsc->snap_flush_lock);
1296 list_del_init(&ci->i_snap_flush_item);
1297 spin_unlock(&mdsc->snap_flush_lock);
1301 *psession = session;
1303 mutex_unlock(&session->s_mutex);
1304 ceph_put_mds_session(session);
1308 static void ceph_flush_snaps(struct ceph_inode_info *ci)
1310 struct inode *inode = &ci->vfs_inode;
1312 spin_lock(&inode->i_lock);
1313 __ceph_flush_snaps(ci, NULL);
1314 spin_unlock(&inode->i_lock);
1318 * Mark caps dirty. If inode is newly dirty, add to the global dirty
1321 void __ceph_mark_dirty_caps(struct ceph_inode_info *ci, int mask)
1323 struct ceph_mds_client *mdsc =
1324 &ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc;
1325 struct inode *inode = &ci->vfs_inode;
1326 int was = ci->i_dirty_caps;
1329 dout("__mark_dirty_caps %p %s dirty %s -> %s\n", &ci->vfs_inode,
1330 ceph_cap_string(mask), ceph_cap_string(was),
1331 ceph_cap_string(was | mask));
1332 ci->i_dirty_caps |= mask;
1334 dout(" inode %p now dirty\n", &ci->vfs_inode);
1335 BUG_ON(!list_empty(&ci->i_dirty_item));
1336 spin_lock(&mdsc->cap_dirty_lock);
1337 list_add(&ci->i_dirty_item, &mdsc->cap_dirty);
1338 spin_unlock(&mdsc->cap_dirty_lock);
1339 if (ci->i_flushing_caps == 0) {
1341 dirty |= I_DIRTY_SYNC;
1344 BUG_ON(list_empty(&ci->i_dirty_item));
1345 if (((was | ci->i_flushing_caps) & CEPH_CAP_FILE_BUFFER) &&
1346 (mask & CEPH_CAP_FILE_BUFFER))
1347 dirty |= I_DIRTY_DATASYNC;
1349 __mark_inode_dirty(inode, dirty);
1350 __cap_delay_requeue(mdsc, ci);
1354 * Add dirty inode to the flushing list. Assigned a seq number so we
1355 * can wait for caps to flush without starving.
1357 * Called under i_lock.
1359 static int __mark_caps_flushing(struct inode *inode,
1360 struct ceph_mds_session *session)
1362 struct ceph_mds_client *mdsc = &ceph_sb_to_client(inode->i_sb)->mdsc;
1363 struct ceph_inode_info *ci = ceph_inode(inode);
1366 BUG_ON(ci->i_dirty_caps == 0);
1367 BUG_ON(list_empty(&ci->i_dirty_item));
1369 flushing = ci->i_dirty_caps;
1370 dout("__mark_caps_flushing flushing %s, flushing_caps %s -> %s\n",
1371 ceph_cap_string(flushing),
1372 ceph_cap_string(ci->i_flushing_caps),
1373 ceph_cap_string(ci->i_flushing_caps | flushing));
1374 ci->i_flushing_caps |= flushing;
1375 ci->i_dirty_caps = 0;
1376 dout(" inode %p now !dirty\n", inode);
1378 spin_lock(&mdsc->cap_dirty_lock);
1379 list_del_init(&ci->i_dirty_item);
1381 ci->i_cap_flush_seq = ++mdsc->cap_flush_seq;
1382 if (list_empty(&ci->i_flushing_item)) {
1383 list_add_tail(&ci->i_flushing_item, &session->s_cap_flushing);
1384 mdsc->num_cap_flushing++;
1385 dout(" inode %p now flushing seq %lld\n", inode,
1386 ci->i_cap_flush_seq);
1388 list_move_tail(&ci->i_flushing_item, &session->s_cap_flushing);
1389 dout(" inode %p now flushing (more) seq %lld\n", inode,
1390 ci->i_cap_flush_seq);
1392 spin_unlock(&mdsc->cap_dirty_lock);
1398 * try to invalidate mapping pages without blocking.
1400 static int mapping_is_empty(struct address_space *mapping)
1402 struct page *page = find_get_page(mapping, 0);
1411 static int try_nonblocking_invalidate(struct inode *inode)
1413 struct ceph_inode_info *ci = ceph_inode(inode);
1414 u32 invalidating_gen = ci->i_rdcache_gen;
1416 spin_unlock(&inode->i_lock);
1417 invalidate_mapping_pages(&inode->i_data, 0, -1);
1418 spin_lock(&inode->i_lock);
1420 if (mapping_is_empty(&inode->i_data) &&
1421 invalidating_gen == ci->i_rdcache_gen) {
1423 dout("try_nonblocking_invalidate %p success\n", inode);
1424 ci->i_rdcache_gen = 0;
1425 ci->i_rdcache_revoking = 0;
1428 dout("try_nonblocking_invalidate %p failed\n", inode);
1433 * Swiss army knife function to examine currently used and wanted
1434 * versus held caps. Release, flush, ack revoked caps to mds as
1437 * CHECK_CAPS_NODELAY - caller is delayed work and we should not delay
1438 * cap release further.
1439 * CHECK_CAPS_AUTHONLY - we should only check the auth cap
1440 * CHECK_CAPS_FLUSH - we should flush any dirty caps immediately, without
1443 void ceph_check_caps(struct ceph_inode_info *ci, int flags,
1444 struct ceph_mds_session *session)
1446 struct ceph_client *client = ceph_inode_to_client(&ci->vfs_inode);
1447 struct ceph_mds_client *mdsc = &client->mdsc;
1448 struct inode *inode = &ci->vfs_inode;
1449 struct ceph_cap *cap;
1450 int file_wanted, used;
1451 int took_snap_rwsem = 0; /* true if mdsc->snap_rwsem held */
1452 int issued, implemented, want, retain, revoking, flushing = 0;
1453 int mds = -1; /* keep track of how far we've gone through i_caps list
1454 to avoid an infinite loop on retry */
1456 int tried_invalidate = 0;
1457 int delayed = 0, sent = 0, force_requeue = 0, num;
1458 int queue_invalidate = 0;
1459 int is_delayed = flags & CHECK_CAPS_NODELAY;
1461 /* if we are unmounting, flush any unused caps immediately. */
1465 spin_lock(&inode->i_lock);
1467 if (ci->i_ceph_flags & CEPH_I_FLUSH)
1468 flags |= CHECK_CAPS_FLUSH;
1470 /* flush snaps first time around only */
1471 if (!list_empty(&ci->i_cap_snaps))
1472 __ceph_flush_snaps(ci, &session);
1475 spin_lock(&inode->i_lock);
1477 file_wanted = __ceph_caps_file_wanted(ci);
1478 used = __ceph_caps_used(ci);
1479 want = file_wanted | used;
1480 issued = __ceph_caps_issued(ci, &implemented);
1481 revoking = implemented & ~issued;
1483 retain = want | CEPH_CAP_PIN;
1484 if (!mdsc->stopping && inode->i_nlink > 0) {
1486 retain |= CEPH_CAP_ANY; /* be greedy */
1488 retain |= CEPH_CAP_ANY_SHARED;
1490 * keep RD only if we didn't have the file open RW,
1491 * because then the mds would revoke it anyway to
1492 * journal max_size=0.
1494 if (ci->i_max_size == 0)
1495 retain |= CEPH_CAP_ANY_RD;
1499 dout("check_caps %p file_want %s used %s dirty %s flushing %s"
1500 " issued %s revoking %s retain %s %s%s%s\n", inode,
1501 ceph_cap_string(file_wanted),
1502 ceph_cap_string(used), ceph_cap_string(ci->i_dirty_caps),
1503 ceph_cap_string(ci->i_flushing_caps),
1504 ceph_cap_string(issued), ceph_cap_string(revoking),
1505 ceph_cap_string(retain),
1506 (flags & CHECK_CAPS_AUTHONLY) ? " AUTHONLY" : "",
1507 (flags & CHECK_CAPS_NODELAY) ? " NODELAY" : "",
1508 (flags & CHECK_CAPS_FLUSH) ? " FLUSH" : "");
1511 * If we no longer need to hold onto old our caps, and we may
1512 * have cached pages, but don't want them, then try to invalidate.
1513 * If we fail, it's because pages are locked.... try again later.
1515 if ((!is_delayed || mdsc->stopping) &&
1516 ci->i_wrbuffer_ref == 0 && /* no dirty pages... */
1517 ci->i_rdcache_gen && /* may have cached pages */
1518 (file_wanted == 0 || /* no open files */
1519 (revoking & (CEPH_CAP_FILE_CACHE|
1520 CEPH_CAP_FILE_LAZYIO))) && /* or revoking cache */
1521 !tried_invalidate) {
1522 dout("check_caps trying to invalidate on %p\n", inode);
1523 if (try_nonblocking_invalidate(inode) < 0) {
1524 if (revoking & (CEPH_CAP_FILE_CACHE|
1525 CEPH_CAP_FILE_LAZYIO)) {
1526 dout("check_caps queuing invalidate\n");
1527 queue_invalidate = 1;
1528 ci->i_rdcache_revoking = ci->i_rdcache_gen;
1530 dout("check_caps failed to invalidate pages\n");
1531 /* we failed to invalidate pages. check these
1532 caps again later. */
1534 __cap_set_timeouts(mdsc, ci);
1537 tried_invalidate = 1;
1542 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
1543 cap = rb_entry(p, struct ceph_cap, ci_node);
1546 /* avoid looping forever */
1547 if (mds >= cap->mds ||
1548 ((flags & CHECK_CAPS_AUTHONLY) && cap != ci->i_auth_cap))
1551 /* NOTE: no side-effects allowed, until we take s_mutex */
1553 revoking = cap->implemented & ~cap->issued;
1555 dout(" mds%d revoking %s\n", cap->mds,
1556 ceph_cap_string(revoking));
1558 if (cap == ci->i_auth_cap &&
1559 (cap->issued & CEPH_CAP_FILE_WR)) {
1560 /* request larger max_size from MDS? */
1561 if (ci->i_wanted_max_size > ci->i_max_size &&
1562 ci->i_wanted_max_size > ci->i_requested_max_size) {
1563 dout("requesting new max_size\n");
1567 /* approaching file_max? */
1568 if ((inode->i_size << 1) >= ci->i_max_size &&
1569 (ci->i_reported_size << 1) < ci->i_max_size) {
1570 dout("i_size approaching max_size\n");
1574 /* flush anything dirty? */
1575 if (cap == ci->i_auth_cap && (flags & CHECK_CAPS_FLUSH) &&
1577 dout("flushing dirty caps\n");
1581 /* completed revocation? going down and there are no caps? */
1582 if (revoking && (revoking & used) == 0) {
1583 dout("completed revocation of %s\n",
1584 ceph_cap_string(cap->implemented & ~cap->issued));
1588 /* want more caps from mds? */
1589 if (want & ~(cap->mds_wanted | cap->issued))
1592 /* things we might delay */
1593 if ((cap->issued & ~retain) == 0 &&
1594 cap->mds_wanted == want)
1595 continue; /* nope, all good */
1601 if ((ci->i_ceph_flags & CEPH_I_NODELAY) == 0 &&
1602 time_before(jiffies, ci->i_hold_caps_max)) {
1603 dout(" delaying issued %s -> %s, wanted %s -> %s\n",
1604 ceph_cap_string(cap->issued),
1605 ceph_cap_string(cap->issued & retain),
1606 ceph_cap_string(cap->mds_wanted),
1607 ceph_cap_string(want));
1613 if (ci->i_ceph_flags & CEPH_I_NOFLUSH) {
1614 dout(" skipping %p I_NOFLUSH set\n", inode);
1618 if (session && session != cap->session) {
1619 dout("oops, wrong session %p mutex\n", session);
1620 mutex_unlock(&session->s_mutex);
1624 session = cap->session;
1625 if (mutex_trylock(&session->s_mutex) == 0) {
1626 dout("inverting session/ino locks on %p\n",
1628 spin_unlock(&inode->i_lock);
1629 if (took_snap_rwsem) {
1630 up_read(&mdsc->snap_rwsem);
1631 took_snap_rwsem = 0;
1633 mutex_lock(&session->s_mutex);
1637 /* take snap_rwsem after session mutex */
1638 if (!took_snap_rwsem) {
1639 if (down_read_trylock(&mdsc->snap_rwsem) == 0) {
1640 dout("inverting snap/in locks on %p\n",
1642 spin_unlock(&inode->i_lock);
1643 down_read(&mdsc->snap_rwsem);
1644 took_snap_rwsem = 1;
1647 took_snap_rwsem = 1;
1650 if (cap == ci->i_auth_cap && ci->i_dirty_caps)
1651 flushing = __mark_caps_flushing(inode, session);
1653 mds = cap->mds; /* remember mds, so we don't repeat */
1656 /* __send_cap drops i_lock */
1657 delayed += __send_cap(mdsc, cap, CEPH_CAP_OP_UPDATE, used, want,
1658 retain, flushing, NULL);
1659 goto retry; /* retake i_lock and restart our cap scan. */
1663 * Reschedule delayed caps release if we delayed anything,
1666 if (delayed && is_delayed)
1667 force_requeue = 1; /* __send_cap delayed release; requeue */
1668 if (!delayed && !is_delayed)
1669 __cap_delay_cancel(mdsc, ci);
1670 else if (!is_delayed || force_requeue)
1671 __cap_delay_requeue(mdsc, ci);
1673 spin_unlock(&inode->i_lock);
1675 if (queue_invalidate)
1676 ceph_queue_invalidate(inode);
1679 mutex_unlock(&session->s_mutex);
1680 if (took_snap_rwsem)
1681 up_read(&mdsc->snap_rwsem);
1685 * Try to flush dirty caps back to the auth mds.
1687 static int try_flush_caps(struct inode *inode, struct ceph_mds_session *session,
1688 unsigned *flush_tid)
1690 struct ceph_mds_client *mdsc = &ceph_sb_to_client(inode->i_sb)->mdsc;
1691 struct ceph_inode_info *ci = ceph_inode(inode);
1692 int unlock_session = session ? 0 : 1;
1696 spin_lock(&inode->i_lock);
1697 if (ci->i_ceph_flags & CEPH_I_NOFLUSH) {
1698 dout("try_flush_caps skipping %p I_NOFLUSH set\n", inode);
1701 if (ci->i_dirty_caps && ci->i_auth_cap) {
1702 struct ceph_cap *cap = ci->i_auth_cap;
1703 int used = __ceph_caps_used(ci);
1704 int want = __ceph_caps_wanted(ci);
1708 spin_unlock(&inode->i_lock);
1709 session = cap->session;
1710 mutex_lock(&session->s_mutex);
1713 BUG_ON(session != cap->session);
1714 if (cap->session->s_state < CEPH_MDS_SESSION_OPEN)
1717 flushing = __mark_caps_flushing(inode, session);
1719 /* __send_cap drops i_lock */
1720 delayed = __send_cap(mdsc, cap, CEPH_CAP_OP_FLUSH, used, want,
1721 cap->issued | cap->implemented, flushing,
1726 spin_lock(&inode->i_lock);
1727 __cap_delay_requeue(mdsc, ci);
1730 spin_unlock(&inode->i_lock);
1732 if (session && unlock_session)
1733 mutex_unlock(&session->s_mutex);
1738 * Return true if we've flushed caps through the given flush_tid.
1740 static int caps_are_flushed(struct inode *inode, unsigned tid)
1742 struct ceph_inode_info *ci = ceph_inode(inode);
1745 spin_lock(&inode->i_lock);
1746 for (i = 0; i < CEPH_CAP_BITS; i++)
1747 if ((ci->i_flushing_caps & (1 << i)) &&
1748 ci->i_cap_flush_tid[i] <= tid) {
1749 /* still flushing this bit */
1753 spin_unlock(&inode->i_lock);
1758 * Wait on any unsafe replies for the given inode. First wait on the
1759 * newest request, and make that the upper bound. Then, if there are
1760 * more requests, keep waiting on the oldest as long as it is still older
1761 * than the original request.
1763 static void sync_write_wait(struct inode *inode)
1765 struct ceph_inode_info *ci = ceph_inode(inode);
1766 struct list_head *head = &ci->i_unsafe_writes;
1767 struct ceph_osd_request *req;
1770 spin_lock(&ci->i_unsafe_lock);
1771 if (list_empty(head))
1774 /* set upper bound as _last_ entry in chain */
1775 req = list_entry(head->prev, struct ceph_osd_request,
1777 last_tid = req->r_tid;
1780 ceph_osdc_get_request(req);
1781 spin_unlock(&ci->i_unsafe_lock);
1782 dout("sync_write_wait on tid %llu (until %llu)\n",
1783 req->r_tid, last_tid);
1784 wait_for_completion(&req->r_safe_completion);
1785 spin_lock(&ci->i_unsafe_lock);
1786 ceph_osdc_put_request(req);
1789 * from here on look at first entry in chain, since we
1790 * only want to wait for anything older than last_tid
1792 if (list_empty(head))
1794 req = list_entry(head->next, struct ceph_osd_request,
1796 } while (req->r_tid < last_tid);
1798 spin_unlock(&ci->i_unsafe_lock);
1801 int ceph_fsync(struct file *file, int datasync)
1803 struct inode *inode = file->f_mapping->host;
1804 struct ceph_inode_info *ci = ceph_inode(inode);
1809 dout("fsync %p%s\n", inode, datasync ? " datasync" : "");
1810 sync_write_wait(inode);
1812 ret = filemap_write_and_wait(inode->i_mapping);
1816 dirty = try_flush_caps(inode, NULL, &flush_tid);
1817 dout("fsync dirty caps are %s\n", ceph_cap_string(dirty));
1820 * only wait on non-file metadata writeback (the mds
1821 * can recover size and mtime, so we don't need to
1824 if (!datasync && (dirty & ~CEPH_CAP_ANY_FILE_WR)) {
1825 dout("fsync waiting for flush_tid %u\n", flush_tid);
1826 ret = wait_event_interruptible(ci->i_cap_wq,
1827 caps_are_flushed(inode, flush_tid));
1830 dout("fsync %p%s done\n", inode, datasync ? " datasync" : "");
1835 * Flush any dirty caps back to the mds. If we aren't asked to wait,
1836 * queue inode for flush but don't do so immediately, because we can
1837 * get by with fewer MDS messages if we wait for data writeback to
1840 int ceph_write_inode(struct inode *inode, struct writeback_control *wbc)
1842 struct ceph_inode_info *ci = ceph_inode(inode);
1846 int wait = wbc->sync_mode == WB_SYNC_ALL;
1848 dout("write_inode %p wait=%d\n", inode, wait);
1850 dirty = try_flush_caps(inode, NULL, &flush_tid);
1852 err = wait_event_interruptible(ci->i_cap_wq,
1853 caps_are_flushed(inode, flush_tid));
1855 struct ceph_mds_client *mdsc =
1856 &ceph_sb_to_client(inode->i_sb)->mdsc;
1858 spin_lock(&inode->i_lock);
1859 if (__ceph_caps_dirty(ci))
1860 __cap_delay_requeue_front(mdsc, ci);
1861 spin_unlock(&inode->i_lock);
1867 * After a recovering MDS goes active, we need to resend any caps
1870 * Caller holds session->s_mutex.
1872 static void kick_flushing_capsnaps(struct ceph_mds_client *mdsc,
1873 struct ceph_mds_session *session)
1875 struct ceph_cap_snap *capsnap;
1877 dout("kick_flushing_capsnaps mds%d\n", session->s_mds);
1878 list_for_each_entry(capsnap, &session->s_cap_snaps_flushing,
1880 struct ceph_inode_info *ci = capsnap->ci;
1881 struct inode *inode = &ci->vfs_inode;
1882 struct ceph_cap *cap;
1884 spin_lock(&inode->i_lock);
1885 cap = ci->i_auth_cap;
1886 if (cap && cap->session == session) {
1887 dout("kick_flushing_caps %p cap %p capsnap %p\n", inode,
1889 __ceph_flush_snaps(ci, &session);
1891 pr_err("%p auth cap %p not mds%d ???\n", inode,
1892 cap, session->s_mds);
1894 spin_unlock(&inode->i_lock);
1898 void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc,
1899 struct ceph_mds_session *session)
1901 struct ceph_inode_info *ci;
1903 kick_flushing_capsnaps(mdsc, session);
1905 dout("kick_flushing_caps mds%d\n", session->s_mds);
1906 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) {
1907 struct inode *inode = &ci->vfs_inode;
1908 struct ceph_cap *cap;
1911 spin_lock(&inode->i_lock);
1912 cap = ci->i_auth_cap;
1913 if (cap && cap->session == session) {
1914 dout("kick_flushing_caps %p cap %p %s\n", inode,
1915 cap, ceph_cap_string(ci->i_flushing_caps));
1916 delayed = __send_cap(mdsc, cap, CEPH_CAP_OP_FLUSH,
1917 __ceph_caps_used(ci),
1918 __ceph_caps_wanted(ci),
1919 cap->issued | cap->implemented,
1920 ci->i_flushing_caps, NULL);
1922 spin_lock(&inode->i_lock);
1923 __cap_delay_requeue(mdsc, ci);
1924 spin_unlock(&inode->i_lock);
1927 pr_err("%p auth cap %p not mds%d ???\n", inode,
1928 cap, session->s_mds);
1929 spin_unlock(&inode->i_lock);
1936 * Take references to capabilities we hold, so that we don't release
1937 * them to the MDS prematurely.
1939 * Protected by i_lock.
1941 static void __take_cap_refs(struct ceph_inode_info *ci, int got)
1943 if (got & CEPH_CAP_PIN)
1945 if (got & CEPH_CAP_FILE_RD)
1947 if (got & CEPH_CAP_FILE_CACHE)
1948 ci->i_rdcache_ref++;
1949 if (got & CEPH_CAP_FILE_WR)
1951 if (got & CEPH_CAP_FILE_BUFFER) {
1952 if (ci->i_wrbuffer_ref == 0)
1953 igrab(&ci->vfs_inode);
1954 ci->i_wrbuffer_ref++;
1955 dout("__take_cap_refs %p wrbuffer %d -> %d (?)\n",
1956 &ci->vfs_inode, ci->i_wrbuffer_ref-1, ci->i_wrbuffer_ref);
1961 * Try to grab cap references. Specify those refs we @want, and the
1962 * minimal set we @need. Also include the larger offset we are writing
1963 * to (when applicable), and check against max_size here as well.
1964 * Note that caller is responsible for ensuring max_size increases are
1965 * requested from the MDS.
1967 static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
1968 int *got, loff_t endoff, int *check_max, int *err)
1970 struct inode *inode = &ci->vfs_inode;
1972 int have, implemented;
1975 dout("get_cap_refs %p need %s want %s\n", inode,
1976 ceph_cap_string(need), ceph_cap_string(want));
1977 spin_lock(&inode->i_lock);
1979 /* make sure file is actually open */
1980 file_wanted = __ceph_caps_file_wanted(ci);
1981 if ((file_wanted & need) == 0) {
1982 dout("try_get_cap_refs need %s file_wanted %s, EBADF\n",
1983 ceph_cap_string(need), ceph_cap_string(file_wanted));
1989 if (need & CEPH_CAP_FILE_WR) {
1990 if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) {
1991 dout("get_cap_refs %p endoff %llu > maxsize %llu\n",
1992 inode, endoff, ci->i_max_size);
1993 if (endoff > ci->i_wanted_max_size) {
2000 * If a sync write is in progress, we must wait, so that we
2001 * can get a final snapshot value for size+mtime.
2003 if (__ceph_have_pending_cap_snap(ci)) {
2004 dout("get_cap_refs %p cap_snap_pending\n", inode);
2008 have = __ceph_caps_issued(ci, &implemented);
2011 * disallow writes while a truncate is pending
2013 if (ci->i_truncate_pending)
2014 have &= ~CEPH_CAP_FILE_WR;
2016 if ((have & need) == need) {
2018 * Look at (implemented & ~have & not) so that we keep waiting
2019 * on transition from wanted -> needed caps. This is needed
2020 * for WRBUFFER|WR -> WR to avoid a new WR sync write from
2021 * going before a prior buffered writeback happens.
2023 int not = want & ~(have & need);
2024 int revoking = implemented & ~have;
2025 dout("get_cap_refs %p have %s but not %s (revoking %s)\n",
2026 inode, ceph_cap_string(have), ceph_cap_string(not),
2027 ceph_cap_string(revoking));
2028 if ((revoking & not) == 0) {
2029 *got = need | (have & want);
2030 __take_cap_refs(ci, *got);
2034 dout("get_cap_refs %p have %s needed %s\n", inode,
2035 ceph_cap_string(have), ceph_cap_string(need));
2038 spin_unlock(&inode->i_lock);
2039 dout("get_cap_refs %p ret %d got %s\n", inode,
2040 ret, ceph_cap_string(*got));
2045 * Check the offset we are writing up to against our current
2046 * max_size. If necessary, tell the MDS we want to write to
2049 static void check_max_size(struct inode *inode, loff_t endoff)
2051 struct ceph_inode_info *ci = ceph_inode(inode);
2054 /* do we need to explicitly request a larger max_size? */
2055 spin_lock(&inode->i_lock);
2056 if ((endoff >= ci->i_max_size ||
2057 endoff > (inode->i_size << 1)) &&
2058 endoff > ci->i_wanted_max_size) {
2059 dout("write %p at large endoff %llu, req max_size\n",
2061 ci->i_wanted_max_size = endoff;
2064 spin_unlock(&inode->i_lock);
2066 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL);
2070 * Wait for caps, and take cap references. If we can't get a WR cap
2071 * due to a small max_size, make sure we check_max_size (and possibly
2072 * ask the mds) so we don't get hung up indefinitely.
2074 int ceph_get_caps(struct ceph_inode_info *ci, int need, int want, int *got,
2077 int check_max, ret, err;
2081 check_max_size(&ci->vfs_inode, endoff);
2084 ret = wait_event_interruptible(ci->i_cap_wq,
2085 try_get_cap_refs(ci, need, want,
2096 * Take cap refs. Caller must already know we hold at least one ref
2097 * on the caps in question or we don't know this is safe.
2099 void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps)
2101 spin_lock(&ci->vfs_inode.i_lock);
2102 __take_cap_refs(ci, caps);
2103 spin_unlock(&ci->vfs_inode.i_lock);
2109 * If we released the last ref on any given cap, call ceph_check_caps
2110 * to release (or schedule a release).
2112 * If we are releasing a WR cap (from a sync write), finalize any affected
2113 * cap_snap, and wake up any waiters.
2115 void ceph_put_cap_refs(struct ceph_inode_info *ci, int had)
2117 struct inode *inode = &ci->vfs_inode;
2118 int last = 0, put = 0, flushsnaps = 0, wake = 0;
2119 struct ceph_cap_snap *capsnap;
2121 spin_lock(&inode->i_lock);
2122 if (had & CEPH_CAP_PIN)
2124 if (had & CEPH_CAP_FILE_RD)
2125 if (--ci->i_rd_ref == 0)
2127 if (had & CEPH_CAP_FILE_CACHE)
2128 if (--ci->i_rdcache_ref == 0)
2130 if (had & CEPH_CAP_FILE_BUFFER) {
2131 if (--ci->i_wrbuffer_ref == 0) {
2135 dout("put_cap_refs %p wrbuffer %d -> %d (?)\n",
2136 inode, ci->i_wrbuffer_ref+1, ci->i_wrbuffer_ref);
2138 if (had & CEPH_CAP_FILE_WR)
2139 if (--ci->i_wr_ref == 0) {
2141 if (!list_empty(&ci->i_cap_snaps)) {
2142 capsnap = list_first_entry(&ci->i_cap_snaps,
2143 struct ceph_cap_snap,
2145 if (capsnap->writing) {
2146 capsnap->writing = 0;
2148 __ceph_finish_cap_snap(ci,
2154 spin_unlock(&inode->i_lock);
2156 dout("put_cap_refs %p had %s%s%s\n", inode, ceph_cap_string(had),
2157 last ? " last" : "", put ? " put" : "");
2159 if (last && !flushsnaps)
2160 ceph_check_caps(ci, 0, NULL);
2161 else if (flushsnaps)
2162 ceph_flush_snaps(ci);
2164 wake_up_all(&ci->i_cap_wq);
2170 * Release @nr WRBUFFER refs on dirty pages for the given @snapc snap
2171 * context. Adjust per-snap dirty page accounting as appropriate.
2172 * Once all dirty data for a cap_snap is flushed, flush snapped file
2173 * metadata back to the MDS. If we dropped the last ref, call
2176 void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr,
2177 struct ceph_snap_context *snapc)
2179 struct inode *inode = &ci->vfs_inode;
2181 int complete_capsnap = 0;
2182 int drop_capsnap = 0;
2184 struct ceph_cap_snap *capsnap = NULL;
2186 spin_lock(&inode->i_lock);
2187 ci->i_wrbuffer_ref -= nr;
2188 last = !ci->i_wrbuffer_ref;
2190 if (ci->i_head_snapc == snapc) {
2191 ci->i_wrbuffer_ref_head -= nr;
2192 if (!ci->i_wrbuffer_ref_head) {
2193 ceph_put_snap_context(ci->i_head_snapc);
2194 ci->i_head_snapc = NULL;
2196 dout("put_wrbuffer_cap_refs on %p head %d/%d -> %d/%d %s\n",
2198 ci->i_wrbuffer_ref+nr, ci->i_wrbuffer_ref_head+nr,
2199 ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head,
2200 last ? " LAST" : "");
2202 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) {
2203 if (capsnap->context == snapc) {
2209 capsnap->dirty_pages -= nr;
2210 if (capsnap->dirty_pages == 0) {
2211 complete_capsnap = 1;
2212 if (capsnap->dirty == 0)
2213 /* cap writeback completed before we created
2214 * the cap_snap; no FLUSHSNAP is needed */
2217 dout("put_wrbuffer_cap_refs on %p cap_snap %p "
2218 " snap %lld %d/%d -> %d/%d %s%s%s\n",
2219 inode, capsnap, capsnap->context->seq,
2220 ci->i_wrbuffer_ref+nr, capsnap->dirty_pages + nr,
2221 ci->i_wrbuffer_ref, capsnap->dirty_pages,
2222 last ? " (wrbuffer last)" : "",
2223 complete_capsnap ? " (complete capsnap)" : "",
2224 drop_capsnap ? " (drop capsnap)" : "");
2226 ceph_put_snap_context(capsnap->context);
2227 list_del(&capsnap->ci_item);
2228 list_del(&capsnap->flushing_item);
2229 ceph_put_cap_snap(capsnap);
2233 spin_unlock(&inode->i_lock);
2236 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL);
2238 } else if (complete_capsnap) {
2239 ceph_flush_snaps(ci);
2240 wake_up_all(&ci->i_cap_wq);
2247 * Handle a cap GRANT message from the MDS. (Note that a GRANT may
2248 * actually be a revocation if it specifies a smaller cap set.)
2250 * caller holds s_mutex and i_lock, we drop both.
2254 * 1 - check_caps on auth cap only (writeback)
2255 * 2 - check_caps (ack revoke)
2257 static void handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
2258 struct ceph_mds_session *session,
2259 struct ceph_cap *cap,
2260 struct ceph_buffer *xattr_buf)
2261 __releases(inode->i_lock)
2263 struct ceph_inode_info *ci = ceph_inode(inode);
2264 int mds = session->s_mds;
2265 int seq = le32_to_cpu(grant->seq);
2266 int newcaps = le32_to_cpu(grant->caps);
2267 int issued, implemented, used, wanted, dirty;
2268 u64 size = le64_to_cpu(grant->size);
2269 u64 max_size = le64_to_cpu(grant->max_size);
2270 struct timespec mtime, atime, ctime;
2274 int revoked_rdcache = 0;
2275 int queue_invalidate = 0;
2277 dout("handle_cap_grant inode %p cap %p mds%d seq %d %s\n",
2278 inode, cap, mds, seq, ceph_cap_string(newcaps));
2279 dout(" size %llu max_size %llu, i_size %llu\n", size, max_size,
2283 * If CACHE is being revoked, and we have no dirty buffers,
2284 * try to invalidate (once). (If there are dirty buffers, we
2285 * will invalidate _after_ writeback.)
2287 if (((cap->issued & ~newcaps) & CEPH_CAP_FILE_CACHE) &&
2288 (newcaps & CEPH_CAP_FILE_LAZYIO) == 0 &&
2289 !ci->i_wrbuffer_ref) {
2290 if (try_nonblocking_invalidate(inode) == 0) {
2291 revoked_rdcache = 1;
2293 /* there were locked pages.. invalidate later
2294 in a separate thread. */
2295 if (ci->i_rdcache_revoking != ci->i_rdcache_gen) {
2296 queue_invalidate = 1;
2297 ci->i_rdcache_revoking = ci->i_rdcache_gen;
2302 /* side effects now are allowed */
2304 issued = __ceph_caps_issued(ci, &implemented);
2305 issued |= implemented | __ceph_caps_dirty(ci);
2307 cap->cap_gen = session->s_cap_gen;
2309 __check_cap_issue(ci, cap, newcaps);
2311 if ((issued & CEPH_CAP_AUTH_EXCL) == 0) {
2312 inode->i_mode = le32_to_cpu(grant->mode);
2313 inode->i_uid = le32_to_cpu(grant->uid);
2314 inode->i_gid = le32_to_cpu(grant->gid);
2315 dout("%p mode 0%o uid.gid %d.%d\n", inode, inode->i_mode,
2316 inode->i_uid, inode->i_gid);
2319 if ((issued & CEPH_CAP_LINK_EXCL) == 0)
2320 inode->i_nlink = le32_to_cpu(grant->nlink);
2322 if ((issued & CEPH_CAP_XATTR_EXCL) == 0 && grant->xattr_len) {
2323 int len = le32_to_cpu(grant->xattr_len);
2324 u64 version = le64_to_cpu(grant->xattr_version);
2326 if (version > ci->i_xattrs.version) {
2327 dout(" got new xattrs v%llu on %p len %d\n",
2328 version, inode, len);
2329 if (ci->i_xattrs.blob)
2330 ceph_buffer_put(ci->i_xattrs.blob);
2331 ci->i_xattrs.blob = ceph_buffer_get(xattr_buf);
2332 ci->i_xattrs.version = version;
2336 /* size/ctime/mtime/atime? */
2337 ceph_fill_file_size(inode, issued,
2338 le32_to_cpu(grant->truncate_seq),
2339 le64_to_cpu(grant->truncate_size), size);
2340 ceph_decode_timespec(&mtime, &grant->mtime);
2341 ceph_decode_timespec(&atime, &grant->atime);
2342 ceph_decode_timespec(&ctime, &grant->ctime);
2343 ceph_fill_file_time(inode, issued,
2344 le32_to_cpu(grant->time_warp_seq), &ctime, &mtime,
2347 /* max size increase? */
2348 if (max_size != ci->i_max_size) {
2349 dout("max_size %lld -> %llu\n", ci->i_max_size, max_size);
2350 ci->i_max_size = max_size;
2351 if (max_size >= ci->i_wanted_max_size) {
2352 ci->i_wanted_max_size = 0; /* reset */
2353 ci->i_requested_max_size = 0;
2358 /* check cap bits */
2359 wanted = __ceph_caps_wanted(ci);
2360 used = __ceph_caps_used(ci);
2361 dirty = __ceph_caps_dirty(ci);
2362 dout(" my wanted = %s, used = %s, dirty %s\n",
2363 ceph_cap_string(wanted),
2364 ceph_cap_string(used),
2365 ceph_cap_string(dirty));
2366 if (wanted != le32_to_cpu(grant->wanted)) {
2367 dout("mds wanted %s -> %s\n",
2368 ceph_cap_string(le32_to_cpu(grant->wanted)),
2369 ceph_cap_string(wanted));
2370 grant->wanted = cpu_to_le32(wanted);
2375 /* file layout may have changed */
2376 ci->i_layout = grant->layout;
2378 /* revocation, grant, or no-op? */
2379 if (cap->issued & ~newcaps) {
2380 int revoking = cap->issued & ~newcaps;
2382 dout("revocation: %s -> %s (revoking %s)\n",
2383 ceph_cap_string(cap->issued),
2384 ceph_cap_string(newcaps),
2385 ceph_cap_string(revoking));
2386 if (revoking & CEPH_CAP_FILE_BUFFER)
2387 writeback = 1; /* initiate writeback; will delay ack */
2388 else if (revoking == CEPH_CAP_FILE_CACHE &&
2389 (newcaps & CEPH_CAP_FILE_LAZYIO) == 0 &&
2391 ; /* do nothing yet, invalidation will be queued */
2392 else if (cap == ci->i_auth_cap)
2393 check_caps = 1; /* check auth cap only */
2395 check_caps = 2; /* check all caps */
2396 cap->issued = newcaps;
2397 cap->implemented |= newcaps;
2398 } else if (cap->issued == newcaps) {
2399 dout("caps unchanged: %s -> %s\n",
2400 ceph_cap_string(cap->issued), ceph_cap_string(newcaps));
2402 dout("grant: %s -> %s\n", ceph_cap_string(cap->issued),
2403 ceph_cap_string(newcaps));
2404 cap->issued = newcaps;
2405 cap->implemented |= newcaps; /* add bits only, to
2406 * avoid stepping on a
2407 * pending revocation */
2410 BUG_ON(cap->issued & ~cap->implemented);
2412 spin_unlock(&inode->i_lock);
2415 * queue inode for writeback: we can't actually call
2416 * filemap_write_and_wait, etc. from message handler
2419 ceph_queue_writeback(inode);
2420 if (queue_invalidate)
2421 ceph_queue_invalidate(inode);
2423 wake_up_all(&ci->i_cap_wq);
2425 if (check_caps == 1)
2426 ceph_check_caps(ci, CHECK_CAPS_NODELAY|CHECK_CAPS_AUTHONLY,
2428 else if (check_caps == 2)
2429 ceph_check_caps(ci, CHECK_CAPS_NODELAY, session);
2431 mutex_unlock(&session->s_mutex);
2435 * Handle FLUSH_ACK from MDS, indicating that metadata we sent to the
2436 * MDS has been safely committed.
2438 static void handle_cap_flush_ack(struct inode *inode, u64 flush_tid,
2439 struct ceph_mds_caps *m,
2440 struct ceph_mds_session *session,
2441 struct ceph_cap *cap)
2442 __releases(inode->i_lock)
2444 struct ceph_inode_info *ci = ceph_inode(inode);
2445 struct ceph_mds_client *mdsc = &ceph_sb_to_client(inode->i_sb)->mdsc;
2446 unsigned seq = le32_to_cpu(m->seq);
2447 int dirty = le32_to_cpu(m->dirty);
2452 for (i = 0; i < CEPH_CAP_BITS; i++)
2453 if ((dirty & (1 << i)) &&
2454 flush_tid == ci->i_cap_flush_tid[i])
2457 dout("handle_cap_flush_ack inode %p mds%d seq %d on %s cleaned %s,"
2458 " flushing %s -> %s\n",
2459 inode, session->s_mds, seq, ceph_cap_string(dirty),
2460 ceph_cap_string(cleaned), ceph_cap_string(ci->i_flushing_caps),
2461 ceph_cap_string(ci->i_flushing_caps & ~cleaned));
2463 if (ci->i_flushing_caps == (ci->i_flushing_caps & ~cleaned))
2466 ci->i_flushing_caps &= ~cleaned;
2468 spin_lock(&mdsc->cap_dirty_lock);
2469 if (ci->i_flushing_caps == 0) {
2470 list_del_init(&ci->i_flushing_item);
2471 if (!list_empty(&session->s_cap_flushing))
2472 dout(" mds%d still flushing cap on %p\n",
2474 &list_entry(session->s_cap_flushing.next,
2475 struct ceph_inode_info,
2476 i_flushing_item)->vfs_inode);
2477 mdsc->num_cap_flushing--;
2478 wake_up_all(&mdsc->cap_flushing_wq);
2479 dout(" inode %p now !flushing\n", inode);
2481 if (ci->i_dirty_caps == 0) {
2482 dout(" inode %p now clean\n", inode);
2483 BUG_ON(!list_empty(&ci->i_dirty_item));
2486 BUG_ON(list_empty(&ci->i_dirty_item));
2489 spin_unlock(&mdsc->cap_dirty_lock);
2490 wake_up_all(&ci->i_cap_wq);
2493 spin_unlock(&inode->i_lock);
2499 * Handle FLUSHSNAP_ACK. MDS has flushed snap data to disk and we can
2500 * throw away our cap_snap.
2502 * Caller hold s_mutex.
2504 static void handle_cap_flushsnap_ack(struct inode *inode, u64 flush_tid,
2505 struct ceph_mds_caps *m,
2506 struct ceph_mds_session *session)
2508 struct ceph_inode_info *ci = ceph_inode(inode);
2509 u64 follows = le64_to_cpu(m->snap_follows);
2510 struct ceph_cap_snap *capsnap;
2513 dout("handle_cap_flushsnap_ack inode %p ci %p mds%d follows %lld\n",
2514 inode, ci, session->s_mds, follows);
2516 spin_lock(&inode->i_lock);
2517 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) {
2518 if (capsnap->follows == follows) {
2519 if (capsnap->flush_tid != flush_tid) {
2520 dout(" cap_snap %p follows %lld tid %lld !="
2521 " %lld\n", capsnap, follows,
2522 flush_tid, capsnap->flush_tid);
2525 WARN_ON(capsnap->dirty_pages || capsnap->writing);
2526 dout(" removing %p cap_snap %p follows %lld\n",
2527 inode, capsnap, follows);
2528 ceph_put_snap_context(capsnap->context);
2529 list_del(&capsnap->ci_item);
2530 list_del(&capsnap->flushing_item);
2531 ceph_put_cap_snap(capsnap);
2535 dout(" skipping cap_snap %p follows %lld\n",
2536 capsnap, capsnap->follows);
2539 spin_unlock(&inode->i_lock);
2545 * Handle TRUNC from MDS, indicating file truncation.
2547 * caller hold s_mutex.
2549 static void handle_cap_trunc(struct inode *inode,
2550 struct ceph_mds_caps *trunc,
2551 struct ceph_mds_session *session)
2552 __releases(inode->i_lock)
2554 struct ceph_inode_info *ci = ceph_inode(inode);
2555 int mds = session->s_mds;
2556 int seq = le32_to_cpu(trunc->seq);
2557 u32 truncate_seq = le32_to_cpu(trunc->truncate_seq);
2558 u64 truncate_size = le64_to_cpu(trunc->truncate_size);
2559 u64 size = le64_to_cpu(trunc->size);
2560 int implemented = 0;
2561 int dirty = __ceph_caps_dirty(ci);
2562 int issued = __ceph_caps_issued(ceph_inode(inode), &implemented);
2563 int queue_trunc = 0;
2565 issued |= implemented | dirty;
2567 dout("handle_cap_trunc inode %p mds%d seq %d to %lld seq %d\n",
2568 inode, mds, seq, truncate_size, truncate_seq);
2569 queue_trunc = ceph_fill_file_size(inode, issued,
2570 truncate_seq, truncate_size, size);
2571 spin_unlock(&inode->i_lock);
2574 ceph_queue_vmtruncate(inode);
2578 * Handle EXPORT from MDS. Cap is being migrated _from_ this mds to a
2579 * different one. If we are the most recent migration we've seen (as
2580 * indicated by mseq), make note of the migrating cap bits for the
2581 * duration (until we see the corresponding IMPORT).
2583 * caller holds s_mutex
2585 static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
2586 struct ceph_mds_session *session,
2587 int *open_target_sessions)
2589 struct ceph_inode_info *ci = ceph_inode(inode);
2590 int mds = session->s_mds;
2591 unsigned mseq = le32_to_cpu(ex->migrate_seq);
2592 struct ceph_cap *cap = NULL, *t;
2596 dout("handle_cap_export inode %p ci %p mds%d mseq %d\n",
2597 inode, ci, mds, mseq);
2599 spin_lock(&inode->i_lock);
2601 /* make sure we haven't seen a higher mseq */
2602 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
2603 t = rb_entry(p, struct ceph_cap, ci_node);
2604 if (ceph_seq_cmp(t->mseq, mseq) > 0) {
2605 dout(" higher mseq on cap from mds%d\n",
2609 if (t->session->s_mds == mds)
2616 ci->i_cap_exporting_mds = mds;
2617 ci->i_cap_exporting_mseq = mseq;
2618 ci->i_cap_exporting_issued = cap->issued;
2621 * make sure we have open sessions with all possible
2622 * export targets, so that we get the matching IMPORT
2624 *open_target_sessions = 1;
2626 __ceph_remove_cap(cap);
2628 /* else, we already released it */
2630 spin_unlock(&inode->i_lock);
2634 * Handle cap IMPORT. If there are temp bits from an older EXPORT,
2637 * caller holds s_mutex.
2639 static void handle_cap_import(struct ceph_mds_client *mdsc,
2640 struct inode *inode, struct ceph_mds_caps *im,
2641 struct ceph_mds_session *session,
2642 void *snaptrace, int snaptrace_len)
2644 struct ceph_inode_info *ci = ceph_inode(inode);
2645 int mds = session->s_mds;
2646 unsigned issued = le32_to_cpu(im->caps);
2647 unsigned wanted = le32_to_cpu(im->wanted);
2648 unsigned seq = le32_to_cpu(im->seq);
2649 unsigned mseq = le32_to_cpu(im->migrate_seq);
2650 u64 realmino = le64_to_cpu(im->realm);
2651 u64 cap_id = le64_to_cpu(im->cap_id);
2653 if (ci->i_cap_exporting_mds >= 0 &&
2654 ceph_seq_cmp(ci->i_cap_exporting_mseq, mseq) < 0) {
2655 dout("handle_cap_import inode %p ci %p mds%d mseq %d"
2656 " - cleared exporting from mds%d\n",
2657 inode, ci, mds, mseq,
2658 ci->i_cap_exporting_mds);
2659 ci->i_cap_exporting_issued = 0;
2660 ci->i_cap_exporting_mseq = 0;
2661 ci->i_cap_exporting_mds = -1;
2663 dout("handle_cap_import inode %p ci %p mds%d mseq %d\n",
2664 inode, ci, mds, mseq);
2667 down_write(&mdsc->snap_rwsem);
2668 ceph_update_snap_trace(mdsc, snaptrace, snaptrace+snaptrace_len,
2670 downgrade_write(&mdsc->snap_rwsem);
2671 ceph_add_cap(inode, session, cap_id, -1,
2672 issued, wanted, seq, mseq, realmino, CEPH_CAP_FLAG_AUTH,
2673 NULL /* no caps context */);
2674 try_flush_caps(inode, session, NULL);
2675 up_read(&mdsc->snap_rwsem);
2679 * Handle a caps message from the MDS.
2681 * Identify the appropriate session, inode, and call the right handler
2682 * based on the cap op.
2684 void ceph_handle_caps(struct ceph_mds_session *session,
2685 struct ceph_msg *msg)
2687 struct ceph_mds_client *mdsc = session->s_mdsc;
2688 struct super_block *sb = mdsc->client->sb;
2689 struct inode *inode;
2690 struct ceph_cap *cap;
2691 struct ceph_mds_caps *h;
2692 int mds = session->s_mds;
2695 struct ceph_vino vino;
2700 int open_target_sessions = 0;
2702 dout("handle_caps from mds%d\n", mds);
2705 tid = le64_to_cpu(msg->hdr.tid);
2706 if (msg->front.iov_len < sizeof(*h))
2708 h = msg->front.iov_base;
2710 op = le32_to_cpu(h->op);
2711 vino.ino = le64_to_cpu(h->ino);
2712 vino.snap = CEPH_NOSNAP;
2713 cap_id = le64_to_cpu(h->cap_id);
2714 seq = le32_to_cpu(h->seq);
2715 mseq = le32_to_cpu(h->migrate_seq);
2716 size = le64_to_cpu(h->size);
2717 max_size = le64_to_cpu(h->max_size);
2719 mutex_lock(&session->s_mutex);
2721 dout(" mds%d seq %lld cap seq %u\n", session->s_mds, session->s_seq,
2725 inode = ceph_find_inode(sb, vino);
2726 dout(" op %s ino %llx.%llx inode %p\n", ceph_cap_op_name(op), vino.ino,
2729 dout(" i don't have ino %llx\n", vino.ino);
2731 if (op == CEPH_CAP_OP_IMPORT)
2732 __queue_cap_release(session, vino.ino, cap_id,
2736 * send any full release message to try to move things
2737 * along for the mds (who clearly thinks we still have this
2740 ceph_add_cap_releases(mdsc, session);
2741 ceph_send_cap_releases(mdsc, session);
2745 /* these will work even if we don't have a cap yet */
2747 case CEPH_CAP_OP_FLUSHSNAP_ACK:
2748 handle_cap_flushsnap_ack(inode, tid, h, session);
2751 case CEPH_CAP_OP_EXPORT:
2752 handle_cap_export(inode, h, session, &open_target_sessions);
2755 case CEPH_CAP_OP_IMPORT:
2756 handle_cap_import(mdsc, inode, h, session,
2757 snaptrace, le32_to_cpu(h->snap_trace_len));
2758 ceph_check_caps(ceph_inode(inode), CHECK_CAPS_NODELAY,
2763 /* the rest require a cap */
2764 spin_lock(&inode->i_lock);
2765 cap = __get_cap_for_mds(ceph_inode(inode), mds);
2767 dout(" no cap on %p ino %llx.%llx from mds%d\n",
2768 inode, ceph_ino(inode), ceph_snap(inode), mds);
2769 spin_unlock(&inode->i_lock);
2773 /* note that each of these drops i_lock for us */
2775 case CEPH_CAP_OP_REVOKE:
2776 case CEPH_CAP_OP_GRANT:
2777 handle_cap_grant(inode, h, session, cap, msg->middle);
2780 case CEPH_CAP_OP_FLUSH_ACK:
2781 handle_cap_flush_ack(inode, tid, h, session, cap);
2784 case CEPH_CAP_OP_TRUNC:
2785 handle_cap_trunc(inode, h, session);
2789 spin_unlock(&inode->i_lock);
2790 pr_err("ceph_handle_caps: unknown cap op %d %s\n", op,
2791 ceph_cap_op_name(op));
2795 mutex_unlock(&session->s_mutex);
2799 if (open_target_sessions)
2800 ceph_mdsc_open_export_target_sessions(mdsc, session);
2804 pr_err("ceph_handle_caps: corrupt message\n");
2810 * Delayed work handler to process end of delayed cap release LRU list.
2812 void ceph_check_delayed_caps(struct ceph_mds_client *mdsc)
2814 struct ceph_inode_info *ci;
2815 int flags = CHECK_CAPS_NODELAY;
2817 dout("check_delayed_caps\n");
2819 spin_lock(&mdsc->cap_delay_lock);
2820 if (list_empty(&mdsc->cap_delay_list))
2822 ci = list_first_entry(&mdsc->cap_delay_list,
2823 struct ceph_inode_info,
2825 if ((ci->i_ceph_flags & CEPH_I_FLUSH) == 0 &&
2826 time_before(jiffies, ci->i_hold_caps_max))
2828 list_del_init(&ci->i_cap_delay_list);
2829 spin_unlock(&mdsc->cap_delay_lock);
2830 dout("check_delayed_caps on %p\n", &ci->vfs_inode);
2831 ceph_check_caps(ci, flags, NULL);
2833 spin_unlock(&mdsc->cap_delay_lock);
2837 * Flush all dirty caps to the mds
2839 void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc)
2841 struct ceph_inode_info *ci, *nci = NULL;
2842 struct inode *inode, *ninode = NULL;
2843 struct list_head *p, *n;
2845 dout("flush_dirty_caps\n");
2846 spin_lock(&mdsc->cap_dirty_lock);
2847 list_for_each_safe(p, n, &mdsc->cap_dirty) {
2851 ci->i_ceph_flags &= ~CEPH_I_NOFLUSH;
2852 dout("flush_dirty_caps inode %p (was next inode)\n",
2855 ci = list_entry(p, struct ceph_inode_info,
2857 inode = igrab(&ci->vfs_inode);
2859 dout("flush_dirty_caps inode %p\n", inode);
2861 if (n != &mdsc->cap_dirty) {
2862 nci = list_entry(n, struct ceph_inode_info,
2864 ninode = igrab(&nci->vfs_inode);
2866 nci->i_ceph_flags |= CEPH_I_NOFLUSH;
2867 dout("flush_dirty_caps next inode %p, noflush\n",
2873 spin_unlock(&mdsc->cap_dirty_lock);
2875 ceph_check_caps(ci, CHECK_CAPS_NODELAY|CHECK_CAPS_FLUSH,
2879 spin_lock(&mdsc->cap_dirty_lock);
2881 spin_unlock(&mdsc->cap_dirty_lock);
2885 * Drop open file reference. If we were the last open file,
2886 * we may need to release capabilities to the MDS (or schedule
2887 * their delayed release).
2889 void ceph_put_fmode(struct ceph_inode_info *ci, int fmode)
2891 struct inode *inode = &ci->vfs_inode;
2894 spin_lock(&inode->i_lock);
2895 dout("put_fmode %p fmode %d %d -> %d\n", inode, fmode,
2896 ci->i_nr_by_mode[fmode], ci->i_nr_by_mode[fmode]-1);
2897 BUG_ON(ci->i_nr_by_mode[fmode] == 0);
2898 if (--ci->i_nr_by_mode[fmode] == 0)
2900 spin_unlock(&inode->i_lock);
2902 if (last && ci->i_vino.snap == CEPH_NOSNAP)
2903 ceph_check_caps(ci, 0, NULL);
2907 * Helpers for embedding cap and dentry lease releases into mds
2910 * @force is used by dentry_release (below) to force inclusion of a
2911 * record for the directory inode, even when there aren't any caps to
2914 int ceph_encode_inode_release(void **p, struct inode *inode,
2915 int mds, int drop, int unless, int force)
2917 struct ceph_inode_info *ci = ceph_inode(inode);
2918 struct ceph_cap *cap;
2919 struct ceph_mds_request_release *rel = *p;
2923 spin_lock(&inode->i_lock);
2924 used = __ceph_caps_used(ci);
2925 dirty = __ceph_caps_dirty(ci);
2927 dout("encode_inode_release %p mds%d used|dirty %s drop %s unless %s\n",
2928 inode, mds, ceph_cap_string(used|dirty), ceph_cap_string(drop),
2929 ceph_cap_string(unless));
2931 /* only drop unused, clean caps */
2932 drop &= ~(used | dirty);
2934 cap = __get_cap_for_mds(ci, mds);
2935 if (cap && __cap_is_valid(cap)) {
2937 ((cap->issued & drop) &&
2938 (cap->issued & unless) == 0)) {
2939 if ((cap->issued & drop) &&
2940 (cap->issued & unless) == 0) {
2941 dout("encode_inode_release %p cap %p %s -> "
2943 ceph_cap_string(cap->issued),
2944 ceph_cap_string(cap->issued & ~drop));
2945 cap->issued &= ~drop;
2946 cap->implemented &= ~drop;
2947 if (ci->i_ceph_flags & CEPH_I_NODELAY) {
2948 int wanted = __ceph_caps_wanted(ci);
2949 dout(" wanted %s -> %s (act %s)\n",
2950 ceph_cap_string(cap->mds_wanted),
2951 ceph_cap_string(cap->mds_wanted &
2953 ceph_cap_string(wanted));
2954 cap->mds_wanted &= wanted;
2957 dout("encode_inode_release %p cap %p %s"
2958 " (force)\n", inode, cap,
2959 ceph_cap_string(cap->issued));
2962 rel->ino = cpu_to_le64(ceph_ino(inode));
2963 rel->cap_id = cpu_to_le64(cap->cap_id);
2964 rel->seq = cpu_to_le32(cap->seq);
2965 rel->issue_seq = cpu_to_le32(cap->issue_seq),
2966 rel->mseq = cpu_to_le32(cap->mseq);
2967 rel->caps = cpu_to_le32(cap->issued);
2968 rel->wanted = cpu_to_le32(cap->mds_wanted);
2974 dout("encode_inode_release %p cap %p %s\n",
2975 inode, cap, ceph_cap_string(cap->issued));
2978 spin_unlock(&inode->i_lock);
2982 int ceph_encode_dentry_release(void **p, struct dentry *dentry,
2983 int mds, int drop, int unless)
2985 struct inode *dir = dentry->d_parent->d_inode;
2986 struct ceph_mds_request_release *rel = *p;
2987 struct ceph_dentry_info *di = ceph_dentry(dentry);
2992 * force an record for the directory caps if we have a dentry lease.
2993 * this is racy (can't take i_lock and d_lock together), but it
2994 * doesn't have to be perfect; the mds will revoke anything we don't
2997 spin_lock(&dentry->d_lock);
2998 if (di->lease_session && di->lease_session->s_mds == mds)
3000 spin_unlock(&dentry->d_lock);
3002 ret = ceph_encode_inode_release(p, dir, mds, drop, unless, force);
3004 spin_lock(&dentry->d_lock);
3005 if (ret && di->lease_session && di->lease_session->s_mds == mds) {
3006 dout("encode_dentry_release %p mds%d seq %d\n",
3007 dentry, mds, (int)di->lease_seq);
3008 rel->dname_len = cpu_to_le32(dentry->d_name.len);
3009 memcpy(*p, dentry->d_name.name, dentry->d_name.len);
3010 *p += dentry->d_name.len;
3011 rel->dname_seq = cpu_to_le32(di->lease_seq);
3012 __ceph_mdsc_drop_dentry_lease(dentry);
3014 spin_unlock(&dentry->d_lock);