1 #include "ceph_debug.h"
4 #include <linux/kernel.h>
5 #include <linux/sched.h>
6 #include <linux/vmalloc.h>
7 #include <linux/wait.h>
11 #include "messenger.h"
14 * Capability management
16 * The Ceph metadata servers control client access to inode metadata
17 * and file data by issuing capabilities, granting clients permission
18 * to read and/or write both inode field and file data to OSDs
19 * (storage nodes). Each capability consists of a set of bits
20 * indicating which operations are allowed.
22 * If the client holds a *_SHARED cap, the client has a coherent value
23 * that can be safely read from the cached inode.
25 * In the case of a *_EXCL (exclusive) or FILE_WR capabilities, the
26 * client is allowed to change inode attributes (e.g., file size,
27 * mtime), note its dirty state in the ceph_cap, and asynchronously
28 * flush that metadata change to the MDS.
30 * In the event of a conflicting operation (perhaps by another
31 * client), the MDS will revoke the conflicting client capabilities.
33 * In order for a client to cache an inode, it must hold a capability
34 * with at least one MDS server. When inodes are released, release
35 * notifications are batched and periodically sent en masse to the MDS
36 * cluster to release server state.
41 * Generate readable cap strings for debugging output.
43 #define MAX_CAP_STR 20
44 static char cap_str
[MAX_CAP_STR
][40];
45 static DEFINE_SPINLOCK(cap_str_lock
);
46 static int last_cap_str
;
48 static char *gcap_string(char *s
, int c
)
50 if (c
& CEPH_CAP_GSHARED
)
52 if (c
& CEPH_CAP_GEXCL
)
54 if (c
& CEPH_CAP_GCACHE
)
60 if (c
& CEPH_CAP_GBUFFER
)
62 if (c
& CEPH_CAP_GLAZYIO
)
67 const char *ceph_cap_string(int caps
)
73 spin_lock(&cap_str_lock
);
75 if (last_cap_str
== MAX_CAP_STR
)
77 spin_unlock(&cap_str_lock
);
81 if (caps
& CEPH_CAP_PIN
)
84 c
= (caps
>> CEPH_CAP_SAUTH
) & 3;
87 s
= gcap_string(s
, c
);
90 c
= (caps
>> CEPH_CAP_SLINK
) & 3;
93 s
= gcap_string(s
, c
);
96 c
= (caps
>> CEPH_CAP_SXATTR
) & 3;
99 s
= gcap_string(s
, c
);
102 c
= caps
>> CEPH_CAP_SFILE
;
105 s
= gcap_string(s
, c
);
117 * Maintain a global pool of preallocated struct ceph_caps, referenced
118 * by struct ceph_caps_reservations. This ensures that we preallocate
119 * memory needed to successfully process an MDS response. (If an MDS
120 * sends us cap information and we fail to process it, we will have
121 * problems due to the client and MDS being out of sync.)
123 * Reservations are 'owned' by a ceph_cap_reservation context.
125 static spinlock_t caps_list_lock
;
126 static struct list_head caps_list
; /* unused (reserved or unreserved) */
127 static int caps_total_count
; /* total caps allocated */
128 static int caps_use_count
; /* in use */
129 static int caps_reserve_count
; /* unused, reserved */
130 static int caps_avail_count
; /* unused, unreserved */
132 void __init
ceph_caps_init(void)
134 INIT_LIST_HEAD(&caps_list
);
135 spin_lock_init(&caps_list_lock
);
138 void ceph_caps_finalize(void)
140 struct ceph_cap
*cap
;
142 spin_lock(&caps_list_lock
);
143 while (!list_empty(&caps_list
)) {
144 cap
= list_first_entry(&caps_list
, struct ceph_cap
, caps_item
);
145 list_del(&cap
->caps_item
);
146 kmem_cache_free(ceph_cap_cachep
, cap
);
148 caps_total_count
= 0;
149 caps_avail_count
= 0;
151 caps_reserve_count
= 0;
152 spin_unlock(&caps_list_lock
);
155 int ceph_reserve_caps(struct ceph_cap_reservation
*ctx
, int need
)
158 struct ceph_cap
*cap
;
164 dout("reserve caps ctx=%p need=%d\n", ctx
, need
);
166 /* first reserve any caps that are already allocated */
167 spin_lock(&caps_list_lock
);
168 if (caps_avail_count
>= need
)
171 have
= caps_avail_count
;
172 caps_avail_count
-= have
;
173 caps_reserve_count
+= have
;
174 BUG_ON(caps_total_count
!= caps_use_count
+ caps_reserve_count
+
176 spin_unlock(&caps_list_lock
);
178 for (i
= have
; i
< need
; i
++) {
179 cap
= kmem_cache_alloc(ceph_cap_cachep
, GFP_NOFS
);
182 goto out_alloc_count
;
184 list_add(&cap
->caps_item
, &newcaps
);
187 BUG_ON(have
+ alloc
!= need
);
189 spin_lock(&caps_list_lock
);
190 caps_total_count
+= alloc
;
191 caps_reserve_count
+= alloc
;
192 list_splice(&newcaps
, &caps_list
);
194 BUG_ON(caps_total_count
!= caps_use_count
+ caps_reserve_count
+
196 spin_unlock(&caps_list_lock
);
199 dout("reserve caps ctx=%p %d = %d used + %d resv + %d avail\n",
200 ctx
, caps_total_count
, caps_use_count
, caps_reserve_count
,
205 /* we didn't manage to reserve as much as we needed */
206 pr_warning("reserve caps ctx=%p ENOMEM need=%d got=%d\n",
211 int ceph_unreserve_caps(struct ceph_cap_reservation
*ctx
)
213 dout("unreserve caps ctx=%p count=%d\n", ctx
, ctx
->count
);
215 spin_lock(&caps_list_lock
);
216 BUG_ON(caps_reserve_count
< ctx
->count
);
217 caps_reserve_count
-= ctx
->count
;
218 caps_avail_count
+= ctx
->count
;
220 dout("unreserve caps %d = %d used + %d resv + %d avail\n",
221 caps_total_count
, caps_use_count
, caps_reserve_count
,
223 BUG_ON(caps_total_count
!= caps_use_count
+ caps_reserve_count
+
225 spin_unlock(&caps_list_lock
);
230 static struct ceph_cap
*get_cap(struct ceph_cap_reservation
*ctx
)
232 struct ceph_cap
*cap
= NULL
;
234 /* temporary, until we do something about cap import/export */
236 return kmem_cache_alloc(ceph_cap_cachep
, GFP_NOFS
);
238 spin_lock(&caps_list_lock
);
239 dout("get_cap ctx=%p (%d) %d = %d used + %d resv + %d avail\n",
240 ctx
, ctx
->count
, caps_total_count
, caps_use_count
,
241 caps_reserve_count
, caps_avail_count
);
243 BUG_ON(ctx
->count
> caps_reserve_count
);
244 BUG_ON(list_empty(&caps_list
));
247 caps_reserve_count
--;
250 cap
= list_first_entry(&caps_list
, struct ceph_cap
, caps_item
);
251 list_del(&cap
->caps_item
);
253 BUG_ON(caps_total_count
!= caps_use_count
+ caps_reserve_count
+
255 spin_unlock(&caps_list_lock
);
259 static void put_cap(struct ceph_cap
*cap
,
260 struct ceph_cap_reservation
*ctx
)
262 spin_lock(&caps_list_lock
);
263 dout("put_cap ctx=%p (%d) %d = %d used + %d resv + %d avail\n",
264 ctx
, ctx
? ctx
->count
: 0, caps_total_count
, caps_use_count
,
265 caps_reserve_count
, caps_avail_count
);
268 * Keep some preallocated caps around, at least enough to do a
269 * readdir (which needs to preallocate lots of them), to avoid
270 * lots of free/alloc churn.
272 if (caps_avail_count
>= caps_reserve_count
+
273 ceph_client(cap
->ci
->vfs_inode
.i_sb
)->mount_args
.max_readdir
) {
275 kmem_cache_free(ceph_cap_cachep
, cap
);
279 caps_reserve_count
++;
283 list_add(&cap
->caps_item
, &caps_list
);
286 BUG_ON(caps_total_count
!= caps_use_count
+ caps_reserve_count
+
288 spin_unlock(&caps_list_lock
);
291 void ceph_reservation_status(struct ceph_client
*client
,
292 int *total
, int *avail
, int *used
, int *reserved
)
295 *total
= caps_total_count
;
297 *avail
= caps_avail_count
;
299 *used
= caps_use_count
;
301 *reserved
= caps_reserve_count
;
305 * Find ceph_cap for given mds, if any.
307 * Called with i_lock held.
309 static struct ceph_cap
*__get_cap_for_mds(struct ceph_inode_info
*ci
, int mds
)
311 struct ceph_cap
*cap
;
312 struct rb_node
*n
= ci
->i_caps
.rb_node
;
315 cap
= rb_entry(n
, struct ceph_cap
, ci_node
);
318 else if (mds
> cap
->mds
)
327 * Return id of any MDS with a cap, preferably FILE_WR|WRBUFFER|EXCL, else
330 static int __ceph_get_cap_mds(struct ceph_inode_info
*ci
, u32
*mseq
)
332 struct ceph_cap
*cap
;
336 /* prefer mds with WR|WRBUFFER|EXCL caps */
337 for (p
= rb_first(&ci
->i_caps
); p
; p
= rb_next(p
)) {
338 cap
= rb_entry(p
, struct ceph_cap
, ci_node
);
342 if (cap
->issued
& (CEPH_CAP_FILE_WR
|
343 CEPH_CAP_FILE_BUFFER
|
350 int ceph_get_cap_mds(struct inode
*inode
)
353 spin_lock(&inode
->i_lock
);
354 mds
= __ceph_get_cap_mds(ceph_inode(inode
), NULL
);
355 spin_unlock(&inode
->i_lock
);
360 * Called under i_lock.
362 static void __insert_cap_node(struct ceph_inode_info
*ci
,
363 struct ceph_cap
*new)
365 struct rb_node
**p
= &ci
->i_caps
.rb_node
;
366 struct rb_node
*parent
= NULL
;
367 struct ceph_cap
*cap
= NULL
;
371 cap
= rb_entry(parent
, struct ceph_cap
, ci_node
);
372 if (new->mds
< cap
->mds
)
374 else if (new->mds
> cap
->mds
)
380 rb_link_node(&new->ci_node
, parent
, p
);
381 rb_insert_color(&new->ci_node
, &ci
->i_caps
);
385 * (re)set cap hold timeouts, which control the delayed release
386 * of unused caps back to the MDS. Should be called on cap use.
388 static void __cap_set_timeouts(struct ceph_mds_client
*mdsc
,
389 struct ceph_inode_info
*ci
)
391 struct ceph_mount_args
*ma
= &mdsc
->client
->mount_args
;
393 ci
->i_hold_caps_min
= round_jiffies(jiffies
+
394 ma
->caps_wanted_delay_min
* HZ
);
395 ci
->i_hold_caps_max
= round_jiffies(jiffies
+
396 ma
->caps_wanted_delay_max
* HZ
);
397 dout("__cap_set_timeouts %p min %lu max %lu\n", &ci
->vfs_inode
,
398 ci
->i_hold_caps_min
- jiffies
, ci
->i_hold_caps_max
- jiffies
);
402 * (Re)queue cap at the end of the delayed cap release list.
404 * If I_FLUSH is set, leave the inode at the front of the list.
406 * Caller holds i_lock
407 * -> we take mdsc->cap_delay_lock
409 static void __cap_delay_requeue(struct ceph_mds_client
*mdsc
,
410 struct ceph_inode_info
*ci
)
412 __cap_set_timeouts(mdsc
, ci
);
413 dout("__cap_delay_requeue %p flags %d at %lu\n", &ci
->vfs_inode
,
414 ci
->i_ceph_flags
, ci
->i_hold_caps_max
);
415 if (!mdsc
->stopping
) {
416 spin_lock(&mdsc
->cap_delay_lock
);
417 if (!list_empty(&ci
->i_cap_delay_list
)) {
418 if (ci
->i_ceph_flags
& CEPH_I_FLUSH
)
420 list_del_init(&ci
->i_cap_delay_list
);
422 list_add_tail(&ci
->i_cap_delay_list
, &mdsc
->cap_delay_list
);
424 spin_unlock(&mdsc
->cap_delay_lock
);
429 * Queue an inode for immediate writeback. Mark inode with I_FLUSH,
430 * indicating we should send a cap message to flush dirty metadata
431 * asap, and move to the front of the delayed cap list.
433 static void __cap_delay_requeue_front(struct ceph_mds_client
*mdsc
,
434 struct ceph_inode_info
*ci
)
436 dout("__cap_delay_requeue_front %p\n", &ci
->vfs_inode
);
437 spin_lock(&mdsc
->cap_delay_lock
);
438 ci
->i_ceph_flags
|= CEPH_I_FLUSH
;
439 if (!list_empty(&ci
->i_cap_delay_list
))
440 list_del_init(&ci
->i_cap_delay_list
);
441 list_add(&ci
->i_cap_delay_list
, &mdsc
->cap_delay_list
);
442 spin_unlock(&mdsc
->cap_delay_lock
);
446 * Cancel delayed work on cap.
448 * Caller must hold i_lock.
450 static void __cap_delay_cancel(struct ceph_mds_client
*mdsc
,
451 struct ceph_inode_info
*ci
)
453 dout("__cap_delay_cancel %p\n", &ci
->vfs_inode
);
454 if (list_empty(&ci
->i_cap_delay_list
))
456 spin_lock(&mdsc
->cap_delay_lock
);
457 list_del_init(&ci
->i_cap_delay_list
);
458 spin_unlock(&mdsc
->cap_delay_lock
);
462 * Common issue checks for add_cap, handle_cap_grant.
464 static void __check_cap_issue(struct ceph_inode_info
*ci
, struct ceph_cap
*cap
,
467 unsigned had
= __ceph_caps_issued(ci
, NULL
);
470 * Each time we receive FILE_CACHE anew, we increment
473 if ((issued
& CEPH_CAP_FILE_CACHE
) &&
474 (had
& CEPH_CAP_FILE_CACHE
) == 0)
478 * if we are newly issued FILE_SHARED, clear I_COMPLETE; we
479 * don't know what happened to this directory while we didn't
482 if ((issued
& CEPH_CAP_FILE_SHARED
) &&
483 (had
& CEPH_CAP_FILE_SHARED
) == 0) {
485 if (S_ISDIR(ci
->vfs_inode
.i_mode
)) {
486 dout(" marking %p NOT complete\n", &ci
->vfs_inode
);
487 ci
->i_ceph_flags
&= ~CEPH_I_COMPLETE
;
493 * Add a capability under the given MDS session.
495 * Caller should hold session snap_rwsem (read) and s_mutex.
497 * @fmode is the open file mode, if we are opening a file, otherwise
498 * it is < 0. (This is so we can atomically add the cap and add an
499 * open file reference to it.)
501 int ceph_add_cap(struct inode
*inode
,
502 struct ceph_mds_session
*session
, u64 cap_id
,
503 int fmode
, unsigned issued
, unsigned wanted
,
504 unsigned seq
, unsigned mseq
, u64 realmino
, int flags
,
505 struct ceph_cap_reservation
*caps_reservation
)
507 struct ceph_mds_client
*mdsc
= &ceph_inode_to_client(inode
)->mdsc
;
508 struct ceph_inode_info
*ci
= ceph_inode(inode
);
509 struct ceph_cap
*new_cap
= NULL
;
510 struct ceph_cap
*cap
;
511 int mds
= session
->s_mds
;
514 dout("add_cap %p mds%d cap %llx %s seq %d\n", inode
,
515 session
->s_mds
, cap_id
, ceph_cap_string(issued
), seq
);
518 * If we are opening the file, include file mode wanted bits
522 wanted
|= ceph_caps_for_mode(fmode
);
525 spin_lock(&inode
->i_lock
);
526 cap
= __get_cap_for_mds(ci
, mds
);
532 spin_unlock(&inode
->i_lock
);
533 new_cap
= get_cap(caps_reservation
);
540 cap
->implemented
= 0;
545 __insert_cap_node(ci
, cap
);
547 /* clear out old exporting info? (i.e. on cap import) */
548 if (ci
->i_cap_exporting_mds
== mds
) {
549 ci
->i_cap_exporting_issued
= 0;
550 ci
->i_cap_exporting_mseq
= 0;
551 ci
->i_cap_exporting_mds
= -1;
554 /* add to session cap list */
555 cap
->session
= session
;
556 spin_lock(&session
->s_cap_lock
);
557 list_add_tail(&cap
->session_caps
, &session
->s_caps
);
558 session
->s_nr_caps
++;
559 spin_unlock(&session
->s_cap_lock
);
562 if (!ci
->i_snap_realm
) {
564 * add this inode to the appropriate snap realm
566 struct ceph_snap_realm
*realm
= ceph_lookup_snap_realm(mdsc
,
569 ceph_get_snap_realm(mdsc
, realm
);
570 spin_lock(&realm
->inodes_with_caps_lock
);
571 ci
->i_snap_realm
= realm
;
572 list_add(&ci
->i_snap_realm_item
,
573 &realm
->inodes_with_caps
);
574 spin_unlock(&realm
->inodes_with_caps_lock
);
576 pr_err("ceph_add_cap: couldn't find snap realm %llx\n",
581 __check_cap_issue(ci
, cap
, issued
);
584 * If we are issued caps we don't want, or the mds' wanted
585 * value appears to be off, queue a check so we'll release
586 * later and/or update the mds wanted value.
588 actual_wanted
= __ceph_caps_wanted(ci
);
589 if ((wanted
& ~actual_wanted
) ||
590 (issued
& ~actual_wanted
& CEPH_CAP_ANY_WR
)) {
591 dout(" issued %s, mds wanted %s, actual %s, queueing\n",
592 ceph_cap_string(issued
), ceph_cap_string(wanted
),
593 ceph_cap_string(actual_wanted
));
594 __cap_delay_requeue(mdsc
, ci
);
597 if (flags
& CEPH_CAP_FLAG_AUTH
)
598 ci
->i_auth_cap
= cap
;
599 else if (ci
->i_auth_cap
== cap
)
600 ci
->i_auth_cap
= NULL
;
602 dout("add_cap inode %p (%llx.%llx) cap %p %s now %s seq %d mds%d\n",
603 inode
, ceph_vinop(inode
), cap
, ceph_cap_string(issued
),
604 ceph_cap_string(issued
|cap
->issued
), seq
, mds
);
605 cap
->cap_id
= cap_id
;
606 cap
->issued
= issued
;
607 cap
->implemented
|= issued
;
608 cap
->mds_wanted
|= wanted
;
610 cap
->issue_seq
= seq
;
612 cap
->gen
= session
->s_cap_gen
;
615 __ceph_get_fmode(ci
, fmode
);
616 spin_unlock(&inode
->i_lock
);
617 wake_up(&ci
->i_cap_wq
);
622 * Return true if cap has not timed out and belongs to the current
623 * generation of the MDS session (i.e. has not gone 'stale' due to
624 * us losing touch with the mds).
626 static int __cap_is_valid(struct ceph_cap
*cap
)
631 spin_lock(&cap
->session
->s_cap_lock
);
632 gen
= cap
->session
->s_cap_gen
;
633 ttl
= cap
->session
->s_cap_ttl
;
634 spin_unlock(&cap
->session
->s_cap_lock
);
636 if (cap
->gen
< gen
|| time_after_eq(jiffies
, ttl
)) {
637 dout("__cap_is_valid %p cap %p issued %s "
638 "but STALE (gen %u vs %u)\n", &cap
->ci
->vfs_inode
,
639 cap
, ceph_cap_string(cap
->issued
), cap
->gen
, gen
);
647 * Return set of valid cap bits issued to us. Note that caps time
648 * out, and may be invalidated in bulk if the client session times out
649 * and session->s_cap_gen is bumped.
651 int __ceph_caps_issued(struct ceph_inode_info
*ci
, int *implemented
)
653 int have
= ci
->i_snap_caps
;
654 struct ceph_cap
*cap
;
659 for (p
= rb_first(&ci
->i_caps
); p
; p
= rb_next(p
)) {
660 cap
= rb_entry(p
, struct ceph_cap
, ci_node
);
661 if (!__cap_is_valid(cap
))
663 dout("__ceph_caps_issued %p cap %p issued %s\n",
664 &ci
->vfs_inode
, cap
, ceph_cap_string(cap
->issued
));
667 *implemented
|= cap
->implemented
;
673 * Get cap bits issued by caps other than @ocap
675 int __ceph_caps_issued_other(struct ceph_inode_info
*ci
, struct ceph_cap
*ocap
)
677 int have
= ci
->i_snap_caps
;
678 struct ceph_cap
*cap
;
681 for (p
= rb_first(&ci
->i_caps
); p
; p
= rb_next(p
)) {
682 cap
= rb_entry(p
, struct ceph_cap
, ci_node
);
685 if (!__cap_is_valid(cap
))
693 * Move a cap to the end of the LRU (oldest caps at list head, newest
696 static void __touch_cap(struct ceph_cap
*cap
)
698 struct ceph_mds_session
*s
= cap
->session
;
700 dout("__touch_cap %p cap %p mds%d\n", &cap
->ci
->vfs_inode
, cap
,
702 spin_lock(&s
->s_cap_lock
);
703 list_move_tail(&cap
->session_caps
, &s
->s_caps
);
704 spin_unlock(&s
->s_cap_lock
);
708 * Check if we hold the given mask. If so, move the cap(s) to the
709 * front of their respective LRUs. (This is the preferred way for
710 * callers to check for caps they want.)
712 int __ceph_caps_issued_mask(struct ceph_inode_info
*ci
, int mask
, int touch
)
714 struct ceph_cap
*cap
;
716 int have
= ci
->i_snap_caps
;
718 if ((have
& mask
) == mask
) {
719 dout("__ceph_caps_issued_mask %p snap issued %s"
720 " (mask %s)\n", &ci
->vfs_inode
,
721 ceph_cap_string(have
),
722 ceph_cap_string(mask
));
726 for (p
= rb_first(&ci
->i_caps
); p
; p
= rb_next(p
)) {
727 cap
= rb_entry(p
, struct ceph_cap
, ci_node
);
728 if (!__cap_is_valid(cap
))
730 if ((cap
->issued
& mask
) == mask
) {
731 dout("__ceph_caps_issued_mask %p cap %p issued %s"
732 " (mask %s)\n", &ci
->vfs_inode
, cap
,
733 ceph_cap_string(cap
->issued
),
734 ceph_cap_string(mask
));
740 /* does a combination of caps satisfy mask? */
742 if ((have
& mask
) == mask
) {
743 dout("__ceph_caps_issued_mask %p combo issued %s"
744 " (mask %s)\n", &ci
->vfs_inode
,
745 ceph_cap_string(cap
->issued
),
746 ceph_cap_string(mask
));
750 /* touch this + preceeding caps */
752 for (q
= rb_first(&ci
->i_caps
); q
!= p
;
754 cap
= rb_entry(q
, struct ceph_cap
,
756 if (!__cap_is_valid(cap
))
769 * Return true if mask caps are currently being revoked by an MDS.
771 int ceph_caps_revoking(struct ceph_inode_info
*ci
, int mask
)
773 struct inode
*inode
= &ci
->vfs_inode
;
774 struct ceph_cap
*cap
;
778 spin_lock(&inode
->i_lock
);
779 for (p
= rb_first(&ci
->i_caps
); p
; p
= rb_next(p
)) {
780 cap
= rb_entry(p
, struct ceph_cap
, ci_node
);
781 if (__cap_is_valid(cap
) &&
782 (cap
->implemented
& ~cap
->issued
& mask
)) {
787 spin_unlock(&inode
->i_lock
);
788 dout("ceph_caps_revoking %p %s = %d\n", inode
,
789 ceph_cap_string(mask
), ret
);
793 int __ceph_caps_used(struct ceph_inode_info
*ci
)
797 used
|= CEPH_CAP_PIN
;
799 used
|= CEPH_CAP_FILE_RD
;
800 if (ci
->i_rdcache_ref
|| ci
->i_rdcache_gen
)
801 used
|= CEPH_CAP_FILE_CACHE
;
803 used
|= CEPH_CAP_FILE_WR
;
804 if (ci
->i_wrbuffer_ref
)
805 used
|= CEPH_CAP_FILE_BUFFER
;
810 * wanted, by virtue of open file modes
812 int __ceph_caps_file_wanted(struct ceph_inode_info
*ci
)
816 for (mode
= 0; mode
< 4; mode
++)
817 if (ci
->i_nr_by_mode
[mode
])
818 want
|= ceph_caps_for_mode(mode
);
823 * Return caps we have registered with the MDS(s) as 'wanted'.
825 int __ceph_caps_mds_wanted(struct ceph_inode_info
*ci
)
827 struct ceph_cap
*cap
;
831 for (p
= rb_first(&ci
->i_caps
); p
; p
= rb_next(p
)) {
832 cap
= rb_entry(p
, struct ceph_cap
, ci_node
);
833 if (!__cap_is_valid(cap
))
835 mds_wanted
|= cap
->mds_wanted
;
841 * called under i_lock
843 static int __ceph_is_any_caps(struct ceph_inode_info
*ci
)
845 return !RB_EMPTY_ROOT(&ci
->i_caps
) || ci
->i_cap_exporting_mds
>= 0;
849 * caller should hold i_lock, and session s_mutex.
850 * returns true if this is the last cap. if so, caller should iput.
852 void __ceph_remove_cap(struct ceph_cap
*cap
,
853 struct ceph_cap_reservation
*ctx
)
855 struct ceph_mds_session
*session
= cap
->session
;
856 struct ceph_inode_info
*ci
= cap
->ci
;
857 struct ceph_mds_client
*mdsc
= &ceph_client(ci
->vfs_inode
.i_sb
)->mdsc
;
859 dout("__ceph_remove_cap %p from %p\n", cap
, &ci
->vfs_inode
);
861 /* remove from session list */
862 spin_lock(&session
->s_cap_lock
);
863 list_del_init(&cap
->session_caps
);
864 session
->s_nr_caps
--;
865 spin_unlock(&session
->s_cap_lock
);
867 /* remove from inode list */
868 rb_erase(&cap
->ci_node
, &ci
->i_caps
);
870 if (ci
->i_auth_cap
== cap
)
871 ci
->i_auth_cap
= NULL
;
875 if (!__ceph_is_any_caps(ci
) && ci
->i_snap_realm
) {
876 struct ceph_snap_realm
*realm
= ci
->i_snap_realm
;
877 spin_lock(&realm
->inodes_with_caps_lock
);
878 list_del_init(&ci
->i_snap_realm_item
);
879 ci
->i_snap_realm_counter
++;
880 ci
->i_snap_realm
= NULL
;
881 spin_unlock(&realm
->inodes_with_caps_lock
);
882 ceph_put_snap_realm(mdsc
, realm
);
884 if (!__ceph_is_any_real_caps(ci
))
885 __cap_delay_cancel(mdsc
, ci
);
889 * Build and send a cap message to the given MDS.
891 * Caller should be holding s_mutex.
893 static int send_cap_msg(struct ceph_mds_session
*session
,
894 u64 ino
, u64 cid
, int op
,
895 int caps
, int wanted
, int dirty
,
896 u32 seq
, u64 flush_tid
, u32 issue_seq
, u32 mseq
,
897 u64 size
, u64 max_size
,
898 struct timespec
*mtime
, struct timespec
*atime
,
900 uid_t uid
, gid_t gid
, mode_t mode
,
902 struct ceph_buffer
*xattrs_buf
,
905 struct ceph_mds_caps
*fc
;
906 struct ceph_msg
*msg
;
908 dout("send_cap_msg %s %llx %llx caps %s wanted %s dirty %s"
909 " seq %u/%u mseq %u follows %lld size %llu/%llu"
910 " xattr_ver %llu xattr_len %d\n", ceph_cap_op_name(op
),
911 cid
, ino
, ceph_cap_string(caps
), ceph_cap_string(wanted
),
912 ceph_cap_string(dirty
),
913 seq
, issue_seq
, mseq
, follows
, size
, max_size
,
914 xattr_version
, xattrs_buf
? (int)xattrs_buf
->vec
.iov_len
: 0);
916 msg
= ceph_msg_new(CEPH_MSG_CLIENT_CAPS
, sizeof(*fc
), 0, 0, NULL
);
920 fc
= msg
->front
.iov_base
;
922 memset(fc
, 0, sizeof(*fc
));
924 fc
->cap_id
= cpu_to_le64(cid
);
925 fc
->op
= cpu_to_le32(op
);
926 fc
->seq
= cpu_to_le32(seq
);
927 fc
->client_tid
= cpu_to_le64(flush_tid
);
928 fc
->issue_seq
= cpu_to_le32(issue_seq
);
929 fc
->migrate_seq
= cpu_to_le32(mseq
);
930 fc
->caps
= cpu_to_le32(caps
);
931 fc
->wanted
= cpu_to_le32(wanted
);
932 fc
->dirty
= cpu_to_le32(dirty
);
933 fc
->ino
= cpu_to_le64(ino
);
934 fc
->snap_follows
= cpu_to_le64(follows
);
936 fc
->size
= cpu_to_le64(size
);
937 fc
->max_size
= cpu_to_le64(max_size
);
939 ceph_encode_timespec(&fc
->mtime
, mtime
);
941 ceph_encode_timespec(&fc
->atime
, atime
);
942 fc
->time_warp_seq
= cpu_to_le32(time_warp_seq
);
944 fc
->uid
= cpu_to_le32(uid
);
945 fc
->gid
= cpu_to_le32(gid
);
946 fc
->mode
= cpu_to_le32(mode
);
948 fc
->xattr_version
= cpu_to_le64(xattr_version
);
950 msg
->middle
= ceph_buffer_get(xattrs_buf
);
951 fc
->xattr_len
= cpu_to_le32(xattrs_buf
->vec
.iov_len
);
952 msg
->hdr
.middle_len
= cpu_to_le32(xattrs_buf
->vec
.iov_len
);
955 ceph_con_send(&session
->s_con
, msg
);
960 * Queue cap releases when an inode is dropped from our
963 void ceph_queue_caps_release(struct inode
*inode
)
965 struct ceph_inode_info
*ci
= ceph_inode(inode
);
968 spin_lock(&inode
->i_lock
);
969 p
= rb_first(&ci
->i_caps
);
971 struct ceph_cap
*cap
= rb_entry(p
, struct ceph_cap
, ci_node
);
972 struct ceph_mds_session
*session
= cap
->session
;
973 struct ceph_msg
*msg
;
974 struct ceph_mds_cap_release
*head
;
975 struct ceph_mds_cap_item
*item
;
977 spin_lock(&session
->s_cap_lock
);
978 BUG_ON(!session
->s_num_cap_releases
);
979 msg
= list_first_entry(&session
->s_cap_releases
,
980 struct ceph_msg
, list_head
);
982 dout(" adding %p release to mds%d msg %p (%d left)\n",
983 inode
, session
->s_mds
, msg
, session
->s_num_cap_releases
);
985 BUG_ON(msg
->front
.iov_len
+ sizeof(*item
) > PAGE_CACHE_SIZE
);
986 head
= msg
->front
.iov_base
;
987 head
->num
= cpu_to_le32(le32_to_cpu(head
->num
) + 1);
988 item
= msg
->front
.iov_base
+ msg
->front
.iov_len
;
989 item
->ino
= cpu_to_le64(ceph_ino(inode
));
990 item
->cap_id
= cpu_to_le64(cap
->cap_id
);
991 item
->migrate_seq
= cpu_to_le32(cap
->mseq
);
992 item
->seq
= cpu_to_le32(cap
->issue_seq
);
994 session
->s_num_cap_releases
--;
996 msg
->front
.iov_len
+= sizeof(*item
);
997 if (le32_to_cpu(head
->num
) == CEPH_CAPS_PER_RELEASE
) {
998 dout(" release msg %p full\n", msg
);
999 list_move_tail(&msg
->list_head
,
1000 &session
->s_cap_releases_done
);
1002 dout(" release msg %p at %d/%d (%d)\n", msg
,
1003 (int)le32_to_cpu(head
->num
),
1004 (int)CEPH_CAPS_PER_RELEASE
,
1005 (int)msg
->front
.iov_len
);
1007 spin_unlock(&session
->s_cap_lock
);
1009 __ceph_remove_cap(cap
, NULL
);
1012 spin_unlock(&inode
->i_lock
);
1016 * Send a cap msg on the given inode. Update our caps state, then
1017 * drop i_lock and send the message.
1019 * Make note of max_size reported/requested from mds, revoked caps
1020 * that have now been implemented.
1022 * Make half-hearted attempt ot to invalidate page cache if we are
1023 * dropping RDCACHE. Note that this will leave behind locked pages
1024 * that we'll then need to deal with elsewhere.
1026 * Return non-zero if delayed release, or we experienced an error
1027 * such that the caller should requeue + retry later.
1029 * called with i_lock, then drops it.
1030 * caller should hold snap_rwsem (read), s_mutex.
1032 static int __send_cap(struct ceph_mds_client
*mdsc
, struct ceph_cap
*cap
,
1033 int op
, int used
, int want
, int retain
, int flushing
,
1034 unsigned *pflush_tid
)
1035 __releases(cap
->ci
->vfs_inode
->i_lock
)
1037 struct ceph_inode_info
*ci
= cap
->ci
;
1038 struct inode
*inode
= &ci
->vfs_inode
;
1039 u64 cap_id
= cap
->cap_id
;
1040 int held
= cap
->issued
| cap
->implemented
;
1041 int revoking
= cap
->implemented
& ~cap
->issued
;
1042 int dropping
= cap
->issued
& ~retain
;
1044 u64 seq
, issue_seq
, mseq
, time_warp_seq
, follows
;
1046 struct timespec mtime
, atime
;
1051 struct ceph_mds_session
*session
;
1052 u64 xattr_version
= 0;
1058 dout("__send_cap %p cap %p session %p %s -> %s (revoking %s)\n",
1059 inode
, cap
, cap
->session
,
1060 ceph_cap_string(held
), ceph_cap_string(held
& retain
),
1061 ceph_cap_string(revoking
));
1062 BUG_ON((retain
& CEPH_CAP_PIN
) == 0);
1064 session
= cap
->session
;
1066 /* don't release wanted unless we've waited a bit. */
1067 if ((ci
->i_ceph_flags
& CEPH_I_NODELAY
) == 0 &&
1068 time_before(jiffies
, ci
->i_hold_caps_min
)) {
1069 dout(" delaying issued %s -> %s, wanted %s -> %s on send\n",
1070 ceph_cap_string(cap
->issued
),
1071 ceph_cap_string(cap
->issued
& retain
),
1072 ceph_cap_string(cap
->mds_wanted
),
1073 ceph_cap_string(want
));
1074 want
|= cap
->mds_wanted
;
1075 retain
|= cap
->issued
;
1078 ci
->i_ceph_flags
&= ~(CEPH_I_NODELAY
| CEPH_I_FLUSH
);
1080 cap
->issued
&= retain
; /* drop bits we don't want */
1081 if (cap
->implemented
& ~cap
->issued
) {
1083 * Wake up any waiters on wanted -> needed transition.
1084 * This is due to the weird transition from buffered
1085 * to sync IO... we need to flush dirty pages _before_
1086 * allowing sync writes to avoid reordering.
1090 cap
->implemented
&= cap
->issued
| used
;
1091 cap
->mds_wanted
= want
;
1095 * assign a tid for flush operations so we can avoid
1096 * flush1 -> dirty1 -> flush2 -> flushack1 -> mark
1097 * clean type races. track latest tid for every bit
1098 * so we can handle flush AxFw, flush Fw, and have the
1099 * first ack clean Ax.
1101 flush_tid
= ++ci
->i_cap_flush_last_tid
;
1103 *pflush_tid
= flush_tid
;
1104 dout(" cap_flush_tid %d\n", (int)flush_tid
);
1105 for (i
= 0; i
< CEPH_CAP_BITS
; i
++)
1106 if (flushing
& (1 << i
))
1107 ci
->i_cap_flush_tid
[i
] = flush_tid
;
1110 keep
= cap
->implemented
;
1112 issue_seq
= cap
->issue_seq
;
1114 size
= inode
->i_size
;
1115 ci
->i_reported_size
= size
;
1116 max_size
= ci
->i_wanted_max_size
;
1117 ci
->i_requested_max_size
= max_size
;
1118 mtime
= inode
->i_mtime
;
1119 atime
= inode
->i_atime
;
1120 time_warp_seq
= ci
->i_time_warp_seq
;
1121 follows
= ci
->i_snap_realm
->cached_context
->seq
;
1124 mode
= inode
->i_mode
;
1126 if (dropping
& CEPH_CAP_XATTR_EXCL
) {
1127 __ceph_build_xattrs_blob(ci
);
1128 xattr_version
= ci
->i_xattrs
.version
+ 1;
1131 spin_unlock(&inode
->i_lock
);
1133 if (dropping
& CEPH_CAP_FILE_CACHE
) {
1134 /* invalidate what we can */
1135 dout("invalidating pages on %p\n", inode
);
1136 invalidate_mapping_pages(&inode
->i_data
, 0, -1);
1139 ret
= send_cap_msg(session
, ceph_vino(inode
).ino
, cap_id
,
1140 op
, keep
, want
, flushing
, seq
, flush_tid
, issue_seq
, mseq
,
1141 size
, max_size
, &mtime
, &atime
, time_warp_seq
,
1144 (flushing
& CEPH_CAP_XATTR_EXCL
) ? ci
->i_xattrs
.blob
: NULL
,
1147 dout("error sending cap msg, must requeue %p\n", inode
);
1152 wake_up(&ci
->i_cap_wq
);
1158 * When a snapshot is taken, clients accumulate dirty metadata on
1159 * inodes with capabilities in ceph_cap_snaps to describe the file
1160 * state at the time the snapshot was taken. This must be flushed
1161 * asynchronously back to the MDS once sync writes complete and dirty
1162 * data is written out.
1164 * Called under i_lock. Takes s_mutex as needed.
1166 void __ceph_flush_snaps(struct ceph_inode_info
*ci
,
1167 struct ceph_mds_session
**psession
)
1169 struct inode
*inode
= &ci
->vfs_inode
;
1171 struct ceph_cap_snap
*capsnap
;
1173 struct ceph_mds_client
*mdsc
= &ceph_inode_to_client(inode
)->mdsc
;
1174 struct ceph_mds_session
*session
= NULL
; /* if session != NULL, we hold
1176 u64 next_follows
= 0; /* keep track of how far we've gotten through the
1177 i_cap_snaps list, and skip these entries next time
1178 around to avoid an infinite loop */
1181 session
= *psession
;
1183 dout("__flush_snaps %p\n", inode
);
1185 list_for_each_entry(capsnap
, &ci
->i_cap_snaps
, ci_item
) {
1186 /* avoid an infiniute loop after retry */
1187 if (capsnap
->follows
< next_follows
)
1190 * we need to wait for sync writes to complete and for dirty
1191 * pages to be written out.
1193 if (capsnap
->dirty_pages
|| capsnap
->writing
)
1196 /* pick mds, take s_mutex */
1197 mds
= __ceph_get_cap_mds(ci
, &mseq
);
1198 if (session
&& session
->s_mds
!= mds
) {
1199 dout("oops, wrong session %p mutex\n", session
);
1200 mutex_unlock(&session
->s_mutex
);
1201 ceph_put_mds_session(session
);
1205 spin_unlock(&inode
->i_lock
);
1206 mutex_lock(&mdsc
->mutex
);
1207 session
= __ceph_lookup_mds_session(mdsc
, mds
);
1208 mutex_unlock(&mdsc
->mutex
);
1210 dout("inverting session/ino locks on %p\n",
1212 mutex_lock(&session
->s_mutex
);
1215 * if session == NULL, we raced against a cap
1216 * deletion. retry, and we'll get a better
1217 * @mds value next time.
1219 spin_lock(&inode
->i_lock
);
1223 capsnap
->flush_tid
= ++ci
->i_cap_flush_last_tid
;
1224 atomic_inc(&capsnap
->nref
);
1225 if (!list_empty(&capsnap
->flushing_item
))
1226 list_del_init(&capsnap
->flushing_item
);
1227 list_add_tail(&capsnap
->flushing_item
,
1228 &session
->s_cap_snaps_flushing
);
1229 spin_unlock(&inode
->i_lock
);
1231 dout("flush_snaps %p cap_snap %p follows %lld size %llu\n",
1232 inode
, capsnap
, next_follows
, capsnap
->size
);
1233 send_cap_msg(session
, ceph_vino(inode
).ino
, 0,
1234 CEPH_CAP_OP_FLUSHSNAP
, capsnap
->issued
, 0,
1235 capsnap
->dirty
, 0, capsnap
->flush_tid
, 0, mseq
,
1237 &capsnap
->mtime
, &capsnap
->atime
,
1238 capsnap
->time_warp_seq
,
1239 capsnap
->uid
, capsnap
->gid
, capsnap
->mode
,
1243 next_follows
= capsnap
->follows
+ 1;
1244 ceph_put_cap_snap(capsnap
);
1246 spin_lock(&inode
->i_lock
);
1250 /* we flushed them all; remove this inode from the queue */
1251 spin_lock(&mdsc
->snap_flush_lock
);
1252 list_del_init(&ci
->i_snap_flush_item
);
1253 spin_unlock(&mdsc
->snap_flush_lock
);
1256 *psession
= session
;
1258 mutex_unlock(&session
->s_mutex
);
1259 ceph_put_mds_session(session
);
1263 static void ceph_flush_snaps(struct ceph_inode_info
*ci
)
1265 struct inode
*inode
= &ci
->vfs_inode
;
1267 spin_lock(&inode
->i_lock
);
1268 __ceph_flush_snaps(ci
, NULL
);
1269 spin_unlock(&inode
->i_lock
);
1273 * Add dirty inode to the flushing list. Assigned a seq number so we
1274 * can wait for caps to flush without starving.
1276 * Called under i_lock.
1278 static int __mark_caps_flushing(struct inode
*inode
,
1279 struct ceph_mds_session
*session
)
1281 struct ceph_mds_client
*mdsc
= &ceph_client(inode
->i_sb
)->mdsc
;
1282 struct ceph_inode_info
*ci
= ceph_inode(inode
);
1285 BUG_ON(ci
->i_dirty_caps
== 0);
1286 BUG_ON(list_empty(&ci
->i_dirty_item
));
1288 flushing
= ci
->i_dirty_caps
;
1289 dout("__mark_caps_flushing flushing %s, flushing_caps %s -> %s\n",
1290 ceph_cap_string(flushing
),
1291 ceph_cap_string(ci
->i_flushing_caps
),
1292 ceph_cap_string(ci
->i_flushing_caps
| flushing
));
1293 ci
->i_flushing_caps
|= flushing
;
1294 ci
->i_dirty_caps
= 0;
1296 spin_lock(&mdsc
->cap_dirty_lock
);
1297 if (list_empty(&ci
->i_flushing_item
)) {
1298 list_del_init(&ci
->i_dirty_item
);
1299 list_add_tail(&ci
->i_flushing_item
, &session
->s_cap_flushing
);
1300 mdsc
->num_cap_flushing
++;
1301 ci
->i_cap_flush_seq
= ++mdsc
->cap_flush_seq
;
1302 dout(" inode %p now flushing seq %lld\n", &ci
->vfs_inode
,
1303 ci
->i_cap_flush_seq
);
1305 spin_unlock(&mdsc
->cap_dirty_lock
);
1311 * Swiss army knife function to examine currently used and wanted
1312 * versus held caps. Release, flush, ack revoked caps to mds as
1315 * CHECK_CAPS_NODELAY - caller is delayed work and we should not delay
1316 * cap release further.
1317 * CHECK_CAPS_AUTHONLY - we should only check the auth cap
1318 * CHECK_CAPS_FLUSH - we should flush any dirty caps immediately, without
1321 void ceph_check_caps(struct ceph_inode_info
*ci
, int flags
,
1322 struct ceph_mds_session
*session
)
1324 struct ceph_client
*client
= ceph_inode_to_client(&ci
->vfs_inode
);
1325 struct ceph_mds_client
*mdsc
= &client
->mdsc
;
1326 struct inode
*inode
= &ci
->vfs_inode
;
1327 struct ceph_cap
*cap
;
1328 int file_wanted
, used
;
1329 int took_snap_rwsem
= 0; /* true if mdsc->snap_rwsem held */
1330 int drop_session_lock
= session
? 0 : 1;
1331 int want
, retain
, revoking
, flushing
= 0;
1332 int mds
= -1; /* keep track of how far we've gone through i_caps list
1333 to avoid an infinite loop on retry */
1335 int tried_invalidate
= 0;
1336 int delayed
= 0, sent
= 0, force_requeue
= 0, num
;
1337 int is_delayed
= flags
& CHECK_CAPS_NODELAY
;
1339 /* if we are unmounting, flush any unused caps immediately. */
1343 spin_lock(&inode
->i_lock
);
1345 if (ci
->i_ceph_flags
& CEPH_I_FLUSH
)
1346 flags
|= CHECK_CAPS_FLUSH
;
1348 /* flush snaps first time around only */
1349 if (!list_empty(&ci
->i_cap_snaps
))
1350 __ceph_flush_snaps(ci
, &session
);
1353 spin_lock(&inode
->i_lock
);
1355 file_wanted
= __ceph_caps_file_wanted(ci
);
1356 used
= __ceph_caps_used(ci
);
1357 want
= file_wanted
| used
;
1359 retain
= want
| CEPH_CAP_PIN
;
1360 if (!mdsc
->stopping
&& inode
->i_nlink
> 0) {
1362 retain
|= CEPH_CAP_ANY
; /* be greedy */
1364 retain
|= CEPH_CAP_ANY_SHARED
;
1366 * keep RD only if we didn't have the file open RW,
1367 * because then the mds would revoke it anyway to
1368 * journal max_size=0.
1370 if (ci
->i_max_size
== 0)
1371 retain
|= CEPH_CAP_ANY_RD
;
1375 dout("check_caps %p file_want %s used %s dirty %s flushing %s"
1376 " issued %s retain %s %s%s%s\n", inode
,
1377 ceph_cap_string(file_wanted
),
1378 ceph_cap_string(used
), ceph_cap_string(ci
->i_dirty_caps
),
1379 ceph_cap_string(ci
->i_flushing_caps
),
1380 ceph_cap_string(__ceph_caps_issued(ci
, NULL
)),
1381 ceph_cap_string(retain
),
1382 (flags
& CHECK_CAPS_AUTHONLY
) ? " AUTHONLY" : "",
1383 (flags
& CHECK_CAPS_NODELAY
) ? " NODELAY" : "",
1384 (flags
& CHECK_CAPS_FLUSH
) ? " FLUSH" : "");
1387 * If we no longer need to hold onto old our caps, and we may
1388 * have cached pages, but don't want them, then try to invalidate.
1389 * If we fail, it's because pages are locked.... try again later.
1391 if ((!is_delayed
|| mdsc
->stopping
) &&
1392 ci
->i_wrbuffer_ref
== 0 && /* no dirty pages... */
1393 ci
->i_rdcache_gen
&& /* may have cached pages */
1394 file_wanted
== 0 && /* no open files */
1395 !ci
->i_truncate_pending
&&
1396 !tried_invalidate
) {
1397 u32 invalidating_gen
= ci
->i_rdcache_gen
;
1400 dout("check_caps trying to invalidate on %p\n", inode
);
1401 spin_unlock(&inode
->i_lock
);
1402 ret
= invalidate_inode_pages2(&inode
->i_data
);
1403 spin_lock(&inode
->i_lock
);
1404 if (ret
== 0 && invalidating_gen
== ci
->i_rdcache_gen
) {
1406 ci
->i_rdcache_gen
= 0;
1407 ci
->i_rdcache_revoking
= 0;
1409 dout("check_caps failed to invalidate pages\n");
1410 /* we failed to invalidate pages. check these
1411 caps again later. */
1413 __cap_set_timeouts(mdsc
, ci
);
1415 tried_invalidate
= 1;
1420 for (p
= rb_first(&ci
->i_caps
); p
; p
= rb_next(p
)) {
1421 cap
= rb_entry(p
, struct ceph_cap
, ci_node
);
1424 /* avoid looping forever */
1425 if (mds
>= cap
->mds
||
1426 ((flags
& CHECK_CAPS_AUTHONLY
) && cap
!= ci
->i_auth_cap
))
1429 /* NOTE: no side-effects allowed, until we take s_mutex */
1431 revoking
= cap
->implemented
& ~cap
->issued
;
1433 dout("mds%d revoking %s\n", cap
->mds
,
1434 ceph_cap_string(revoking
));
1436 if (cap
== ci
->i_auth_cap
&&
1437 (cap
->issued
& CEPH_CAP_FILE_WR
)) {
1438 /* request larger max_size from MDS? */
1439 if (ci
->i_wanted_max_size
> ci
->i_max_size
&&
1440 ci
->i_wanted_max_size
> ci
->i_requested_max_size
) {
1441 dout("requesting new max_size\n");
1445 /* approaching file_max? */
1446 if ((inode
->i_size
<< 1) >= ci
->i_max_size
&&
1447 (ci
->i_reported_size
<< 1) < ci
->i_max_size
) {
1448 dout("i_size approaching max_size\n");
1452 /* flush anything dirty? */
1453 if (cap
== ci
->i_auth_cap
&& (flags
& CHECK_CAPS_FLUSH
) &&
1455 dout("flushing dirty caps\n");
1459 /* completed revocation? going down and there are no caps? */
1460 if (revoking
&& (revoking
& used
) == 0) {
1461 dout("completed revocation of %s\n",
1462 ceph_cap_string(cap
->implemented
& ~cap
->issued
));
1466 /* want more caps from mds? */
1467 if (want
& ~(cap
->mds_wanted
| cap
->issued
))
1470 /* things we might delay */
1471 if ((cap
->issued
& ~retain
) == 0 &&
1472 cap
->mds_wanted
== want
)
1473 continue; /* nope, all good */
1479 if ((ci
->i_ceph_flags
& CEPH_I_NODELAY
) == 0 &&
1480 time_before(jiffies
, ci
->i_hold_caps_max
)) {
1481 dout(" delaying issued %s -> %s, wanted %s -> %s\n",
1482 ceph_cap_string(cap
->issued
),
1483 ceph_cap_string(cap
->issued
& retain
),
1484 ceph_cap_string(cap
->mds_wanted
),
1485 ceph_cap_string(want
));
1491 if (session
&& session
!= cap
->session
) {
1492 dout("oops, wrong session %p mutex\n", session
);
1493 mutex_unlock(&session
->s_mutex
);
1497 session
= cap
->session
;
1498 if (mutex_trylock(&session
->s_mutex
) == 0) {
1499 dout("inverting session/ino locks on %p\n",
1501 spin_unlock(&inode
->i_lock
);
1502 if (took_snap_rwsem
) {
1503 up_read(&mdsc
->snap_rwsem
);
1504 took_snap_rwsem
= 0;
1506 mutex_lock(&session
->s_mutex
);
1510 /* take snap_rwsem after session mutex */
1511 if (!took_snap_rwsem
) {
1512 if (down_read_trylock(&mdsc
->snap_rwsem
) == 0) {
1513 dout("inverting snap/in locks on %p\n",
1515 spin_unlock(&inode
->i_lock
);
1516 down_read(&mdsc
->snap_rwsem
);
1517 took_snap_rwsem
= 1;
1520 took_snap_rwsem
= 1;
1523 if (cap
== ci
->i_auth_cap
&& ci
->i_dirty_caps
)
1524 flushing
= __mark_caps_flushing(inode
, session
);
1526 mds
= cap
->mds
; /* remember mds, so we don't repeat */
1529 /* __send_cap drops i_lock */
1530 delayed
+= __send_cap(mdsc
, cap
, CEPH_CAP_OP_UPDATE
, used
, want
,
1531 retain
, flushing
, NULL
);
1532 goto retry
; /* retake i_lock and restart our cap scan. */
1536 * Reschedule delayed caps release if we delayed anything,
1539 if (delayed
&& is_delayed
)
1540 force_requeue
= 1; /* __send_cap delayed release; requeue */
1541 if (!delayed
&& !is_delayed
)
1542 __cap_delay_cancel(mdsc
, ci
);
1543 else if (!is_delayed
|| force_requeue
)
1544 __cap_delay_requeue(mdsc
, ci
);
1546 spin_unlock(&inode
->i_lock
);
1548 if (session
&& drop_session_lock
)
1549 mutex_unlock(&session
->s_mutex
);
1550 if (took_snap_rwsem
)
1551 up_read(&mdsc
->snap_rwsem
);
1555 * Mark caps dirty. If inode is newly dirty, add to the global dirty
1558 int __ceph_mark_dirty_caps(struct ceph_inode_info
*ci
, int mask
)
1560 struct ceph_mds_client
*mdsc
= &ceph_client(ci
->vfs_inode
.i_sb
)->mdsc
;
1561 struct inode
*inode
= &ci
->vfs_inode
;
1562 int was
= __ceph_caps_dirty(ci
);
1565 dout("__mark_dirty_caps %p %s dirty %s -> %s\n", &ci
->vfs_inode
,
1566 ceph_cap_string(mask
), ceph_cap_string(ci
->i_dirty_caps
),
1567 ceph_cap_string(ci
->i_dirty_caps
| mask
));
1568 ci
->i_dirty_caps
|= mask
;
1570 dout(" inode %p now dirty\n", &ci
->vfs_inode
);
1571 spin_lock(&mdsc
->cap_dirty_lock
);
1572 list_add(&ci
->i_dirty_item
, &mdsc
->cap_dirty
);
1573 spin_unlock(&mdsc
->cap_dirty_lock
);
1575 dirty
|= I_DIRTY_SYNC
;
1577 if ((was
& CEPH_CAP_FILE_BUFFER
) &&
1578 (mask
& CEPH_CAP_FILE_BUFFER
))
1579 dirty
|= I_DIRTY_DATASYNC
;
1581 __mark_inode_dirty(inode
, dirty
);
1582 __cap_delay_requeue(mdsc
, ci
);
1587 * Try to flush dirty caps back to the auth mds.
1589 static int try_flush_caps(struct inode
*inode
, struct ceph_mds_session
*session
,
1590 unsigned *flush_tid
)
1592 struct ceph_mds_client
*mdsc
= &ceph_client(inode
->i_sb
)->mdsc
;
1593 struct ceph_inode_info
*ci
= ceph_inode(inode
);
1594 int unlock_session
= session
? 0 : 1;
1598 spin_lock(&inode
->i_lock
);
1599 if (ci
->i_dirty_caps
&& ci
->i_auth_cap
) {
1600 struct ceph_cap
*cap
= ci
->i_auth_cap
;
1601 int used
= __ceph_caps_used(ci
);
1602 int want
= __ceph_caps_wanted(ci
);
1606 spin_unlock(&inode
->i_lock
);
1607 session
= cap
->session
;
1608 mutex_lock(&session
->s_mutex
);
1611 BUG_ON(session
!= cap
->session
);
1612 if (cap
->session
->s_state
< CEPH_MDS_SESSION_OPEN
)
1615 flushing
= __mark_caps_flushing(inode
, session
);
1617 /* __send_cap drops i_lock */
1618 delayed
= __send_cap(mdsc
, cap
, CEPH_CAP_OP_FLUSH
, used
, want
,
1619 cap
->issued
| cap
->implemented
, flushing
,
1624 spin_lock(&inode
->i_lock
);
1625 __cap_delay_requeue(mdsc
, ci
);
1628 spin_unlock(&inode
->i_lock
);
1630 if (session
&& unlock_session
)
1631 mutex_unlock(&session
->s_mutex
);
1636 * Return true if we've flushed caps through the given flush_tid.
1638 static int caps_are_flushed(struct inode
*inode
, unsigned tid
)
1640 struct ceph_inode_info
*ci
= ceph_inode(inode
);
1641 int dirty
, i
, ret
= 1;
1643 spin_lock(&inode
->i_lock
);
1644 dirty
= __ceph_caps_dirty(ci
);
1645 for (i
= 0; i
< CEPH_CAP_BITS
; i
++)
1646 if ((ci
->i_flushing_caps
& (1 << i
)) &&
1647 ci
->i_cap_flush_tid
[i
] <= tid
) {
1648 /* still flushing this bit */
1652 spin_unlock(&inode
->i_lock
);
1657 * Wait on any unsafe replies for the given inode. First wait on the
1658 * newest request, and make that the upper bound. Then, if there are
1659 * more requests, keep waiting on the oldest as long as it is still older
1660 * than the original request.
1662 static void sync_write_wait(struct inode
*inode
)
1664 struct ceph_inode_info
*ci
= ceph_inode(inode
);
1665 struct list_head
*head
= &ci
->i_unsafe_writes
;
1666 struct ceph_osd_request
*req
;
1669 spin_lock(&ci
->i_unsafe_lock
);
1670 if (list_empty(head
))
1673 /* set upper bound as _last_ entry in chain */
1674 req
= list_entry(head
->prev
, struct ceph_osd_request
,
1676 last_tid
= req
->r_tid
;
1679 ceph_osdc_get_request(req
);
1680 spin_unlock(&ci
->i_unsafe_lock
);
1681 dout("sync_write_wait on tid %llu (until %llu)\n",
1682 req
->r_tid
, last_tid
);
1683 wait_for_completion(&req
->r_safe_completion
);
1684 spin_lock(&ci
->i_unsafe_lock
);
1685 ceph_osdc_put_request(req
);
1688 * from here on look at first entry in chain, since we
1689 * only want to wait for anything older than last_tid
1691 if (list_empty(head
))
1693 req
= list_entry(head
->next
, struct ceph_osd_request
,
1695 } while (req
->r_tid
< last_tid
);
1697 spin_unlock(&ci
->i_unsafe_lock
);
1700 int ceph_fsync(struct file
*file
, struct dentry
*dentry
, int datasync
)
1702 struct inode
*inode
= dentry
->d_inode
;
1703 struct ceph_inode_info
*ci
= ceph_inode(inode
);
1708 dout("fsync %p%s\n", inode
, datasync
? " datasync" : "");
1709 sync_write_wait(inode
);
1711 ret
= filemap_write_and_wait(inode
->i_mapping
);
1715 dirty
= try_flush_caps(inode
, NULL
, &flush_tid
);
1716 dout("fsync dirty caps are %s\n", ceph_cap_string(dirty
));
1719 * only wait on non-file metadata writeback (the mds
1720 * can recover size and mtime, so we don't need to
1723 if (!datasync
&& (dirty
& ~CEPH_CAP_ANY_FILE_WR
)) {
1724 dout("fsync waiting for flush_tid %u\n", flush_tid
);
1725 ret
= wait_event_interruptible(ci
->i_cap_wq
,
1726 caps_are_flushed(inode
, flush_tid
));
1729 dout("fsync %p%s done\n", inode
, datasync
? " datasync" : "");
1734 * Flush any dirty caps back to the mds. If we aren't asked to wait,
1735 * queue inode for flush but don't do so immediately, because we can
1736 * get by with fewer MDS messages if we wait for data writeback to
1739 int ceph_write_inode(struct inode
*inode
, int wait
)
1741 struct ceph_inode_info
*ci
= ceph_inode(inode
);
1746 dout("write_inode %p wait=%d\n", inode
, wait
);
1748 dirty
= try_flush_caps(inode
, NULL
, &flush_tid
);
1750 err
= wait_event_interruptible(ci
->i_cap_wq
,
1751 caps_are_flushed(inode
, flush_tid
));
1753 struct ceph_mds_client
*mdsc
= &ceph_client(inode
->i_sb
)->mdsc
;
1755 spin_lock(&inode
->i_lock
);
1756 if (__ceph_caps_dirty(ci
))
1757 __cap_delay_requeue_front(mdsc
, ci
);
1758 spin_unlock(&inode
->i_lock
);
1764 * After a recovering MDS goes active, we need to resend any caps
1767 * Caller holds session->s_mutex.
1769 static void kick_flushing_capsnaps(struct ceph_mds_client
*mdsc
,
1770 struct ceph_mds_session
*session
)
1772 struct ceph_cap_snap
*capsnap
;
1774 dout("kick_flushing_capsnaps mds%d\n", session
->s_mds
);
1775 list_for_each_entry(capsnap
, &session
->s_cap_snaps_flushing
,
1777 struct ceph_inode_info
*ci
= capsnap
->ci
;
1778 struct inode
*inode
= &ci
->vfs_inode
;
1779 struct ceph_cap
*cap
;
1781 spin_lock(&inode
->i_lock
);
1782 cap
= ci
->i_auth_cap
;
1783 if (cap
&& cap
->session
== session
) {
1784 dout("kick_flushing_caps %p cap %p capsnap %p\n", inode
,
1786 __ceph_flush_snaps(ci
, &session
);
1788 pr_err("%p auth cap %p not mds%d ???\n", inode
,
1789 cap
, session
->s_mds
);
1790 spin_unlock(&inode
->i_lock
);
1795 void ceph_kick_flushing_caps(struct ceph_mds_client
*mdsc
,
1796 struct ceph_mds_session
*session
)
1798 struct ceph_inode_info
*ci
;
1800 kick_flushing_capsnaps(mdsc
, session
);
1802 dout("kick_flushing_caps mds%d\n", session
->s_mds
);
1803 list_for_each_entry(ci
, &session
->s_cap_flushing
, i_flushing_item
) {
1804 struct inode
*inode
= &ci
->vfs_inode
;
1805 struct ceph_cap
*cap
;
1808 spin_lock(&inode
->i_lock
);
1809 cap
= ci
->i_auth_cap
;
1810 if (cap
&& cap
->session
== session
) {
1811 dout("kick_flushing_caps %p cap %p %s\n", inode
,
1812 cap
, ceph_cap_string(ci
->i_flushing_caps
));
1813 delayed
= __send_cap(mdsc
, cap
, CEPH_CAP_OP_FLUSH
,
1814 __ceph_caps_used(ci
),
1815 __ceph_caps_wanted(ci
),
1816 cap
->issued
| cap
->implemented
,
1817 ci
->i_flushing_caps
, NULL
);
1819 spin_lock(&inode
->i_lock
);
1820 __cap_delay_requeue(mdsc
, ci
);
1821 spin_unlock(&inode
->i_lock
);
1824 pr_err("%p auth cap %p not mds%d ???\n", inode
,
1825 cap
, session
->s_mds
);
1826 spin_unlock(&inode
->i_lock
);
1833 * Take references to capabilities we hold, so that we don't release
1834 * them to the MDS prematurely.
1836 * Protected by i_lock.
1838 static void __take_cap_refs(struct ceph_inode_info
*ci
, int got
)
1840 if (got
& CEPH_CAP_PIN
)
1842 if (got
& CEPH_CAP_FILE_RD
)
1844 if (got
& CEPH_CAP_FILE_CACHE
)
1845 ci
->i_rdcache_ref
++;
1846 if (got
& CEPH_CAP_FILE_WR
)
1848 if (got
& CEPH_CAP_FILE_BUFFER
) {
1849 if (ci
->i_wrbuffer_ref
== 0)
1850 igrab(&ci
->vfs_inode
);
1851 ci
->i_wrbuffer_ref
++;
1852 dout("__take_cap_refs %p wrbuffer %d -> %d (?)\n",
1853 &ci
->vfs_inode
, ci
->i_wrbuffer_ref
-1, ci
->i_wrbuffer_ref
);
1858 * Try to grab cap references. Specify those refs we @want, and the
1859 * minimal set we @need. Also include the larger offset we are writing
1860 * to (when applicable), and check against max_size here as well.
1861 * Note that caller is responsible for ensuring max_size increases are
1862 * requested from the MDS.
1864 static int try_get_cap_refs(struct ceph_inode_info
*ci
, int need
, int want
,
1865 int *got
, loff_t endoff
, int *check_max
, int *err
)
1867 struct inode
*inode
= &ci
->vfs_inode
;
1869 int have
, implemented
;
1871 dout("get_cap_refs %p need %s want %s\n", inode
,
1872 ceph_cap_string(need
), ceph_cap_string(want
));
1873 spin_lock(&inode
->i_lock
);
1875 /* make sure we _have_ some caps! */
1876 if (!__ceph_is_any_caps(ci
)) {
1877 dout("get_cap_refs %p no real caps\n", inode
);
1883 if (need
& CEPH_CAP_FILE_WR
) {
1884 if (endoff
>= 0 && endoff
> (loff_t
)ci
->i_max_size
) {
1885 dout("get_cap_refs %p endoff %llu > maxsize %llu\n",
1886 inode
, endoff
, ci
->i_max_size
);
1887 if (endoff
> ci
->i_wanted_max_size
) {
1894 * If a sync write is in progress, we must wait, so that we
1895 * can get a final snapshot value for size+mtime.
1897 if (__ceph_have_pending_cap_snap(ci
)) {
1898 dout("get_cap_refs %p cap_snap_pending\n", inode
);
1902 have
= __ceph_caps_issued(ci
, &implemented
);
1905 * disallow writes while a truncate is pending
1907 if (ci
->i_truncate_pending
)
1908 have
&= ~CEPH_CAP_FILE_WR
;
1910 if ((have
& need
) == need
) {
1912 * Look at (implemented & ~have & not) so that we keep waiting
1913 * on transition from wanted -> needed caps. This is needed
1914 * for WRBUFFER|WR -> WR to avoid a new WR sync write from
1915 * going before a prior buffered writeback happens.
1917 int not = want
& ~(have
& need
);
1918 int revoking
= implemented
& ~have
;
1919 dout("get_cap_refs %p have %s but not %s (revoking %s)\n",
1920 inode
, ceph_cap_string(have
), ceph_cap_string(not),
1921 ceph_cap_string(revoking
));
1922 if ((revoking
& not) == 0) {
1923 *got
= need
| (have
& want
);
1924 __take_cap_refs(ci
, *got
);
1928 dout("get_cap_refs %p have %s needed %s\n", inode
,
1929 ceph_cap_string(have
), ceph_cap_string(need
));
1932 spin_unlock(&inode
->i_lock
);
1933 dout("get_cap_refs %p ret %d got %s\n", inode
,
1934 ret
, ceph_cap_string(*got
));
1939 * Check the offset we are writing up to against our current
1940 * max_size. If necessary, tell the MDS we want to write to
1943 static void check_max_size(struct inode
*inode
, loff_t endoff
)
1945 struct ceph_inode_info
*ci
= ceph_inode(inode
);
1948 /* do we need to explicitly request a larger max_size? */
1949 spin_lock(&inode
->i_lock
);
1950 if ((endoff
>= ci
->i_max_size
||
1951 endoff
> (inode
->i_size
<< 1)) &&
1952 endoff
> ci
->i_wanted_max_size
) {
1953 dout("write %p at large endoff %llu, req max_size\n",
1955 ci
->i_wanted_max_size
= endoff
;
1958 spin_unlock(&inode
->i_lock
);
1960 ceph_check_caps(ci
, CHECK_CAPS_AUTHONLY
, NULL
);
1964 * Wait for caps, and take cap references. If we can't get a WR cap
1965 * due to a small max_size, make sure we check_max_size (and possibly
1966 * ask the mds) so we don't get hung up indefinitely.
1968 int ceph_get_caps(struct ceph_inode_info
*ci
, int need
, int want
, int *got
,
1971 int check_max
, ret
, err
;
1975 check_max_size(&ci
->vfs_inode
, endoff
);
1978 ret
= wait_event_interruptible(ci
->i_cap_wq
,
1979 try_get_cap_refs(ci
, need
, want
,
1990 * Take cap refs. Caller must already know we hold at least one ref
1991 * on the caps in question or we don't know this is safe.
1993 void ceph_get_cap_refs(struct ceph_inode_info
*ci
, int caps
)
1995 spin_lock(&ci
->vfs_inode
.i_lock
);
1996 __take_cap_refs(ci
, caps
);
1997 spin_unlock(&ci
->vfs_inode
.i_lock
);
2003 * If we released the last ref on any given cap, call ceph_check_caps
2004 * to release (or schedule a release).
2006 * If we are releasing a WR cap (from a sync write), finalize any affected
2007 * cap_snap, and wake up any waiters.
2009 void ceph_put_cap_refs(struct ceph_inode_info
*ci
, int had
)
2011 struct inode
*inode
= &ci
->vfs_inode
;
2012 int last
= 0, put
= 0, flushsnaps
= 0, wake
= 0;
2013 struct ceph_cap_snap
*capsnap
;
2015 spin_lock(&inode
->i_lock
);
2016 if (had
& CEPH_CAP_PIN
)
2018 if (had
& CEPH_CAP_FILE_RD
)
2019 if (--ci
->i_rd_ref
== 0)
2021 if (had
& CEPH_CAP_FILE_CACHE
)
2022 if (--ci
->i_rdcache_ref
== 0)
2024 if (had
& CEPH_CAP_FILE_BUFFER
) {
2025 if (--ci
->i_wrbuffer_ref
== 0) {
2029 dout("put_cap_refs %p wrbuffer %d -> %d (?)\n",
2030 inode
, ci
->i_wrbuffer_ref
+1, ci
->i_wrbuffer_ref
);
2032 if (had
& CEPH_CAP_FILE_WR
)
2033 if (--ci
->i_wr_ref
== 0) {
2035 if (!list_empty(&ci
->i_cap_snaps
)) {
2036 capsnap
= list_first_entry(&ci
->i_cap_snaps
,
2037 struct ceph_cap_snap
,
2039 if (capsnap
->writing
) {
2040 capsnap
->writing
= 0;
2042 __ceph_finish_cap_snap(ci
,
2048 spin_unlock(&inode
->i_lock
);
2050 dout("put_cap_refs %p had %s %s\n", inode
, ceph_cap_string(had
),
2051 last
? "last" : "");
2053 if (last
&& !flushsnaps
)
2054 ceph_check_caps(ci
, 0, NULL
);
2055 else if (flushsnaps
)
2056 ceph_flush_snaps(ci
);
2058 wake_up(&ci
->i_cap_wq
);
2064 * Release @nr WRBUFFER refs on dirty pages for the given @snapc snap
2065 * context. Adjust per-snap dirty page accounting as appropriate.
2066 * Once all dirty data for a cap_snap is flushed, flush snapped file
2067 * metadata back to the MDS. If we dropped the last ref, call
2070 void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info
*ci
, int nr
,
2071 struct ceph_snap_context
*snapc
)
2073 struct inode
*inode
= &ci
->vfs_inode
;
2077 struct ceph_cap_snap
*capsnap
= NULL
;
2079 spin_lock(&inode
->i_lock
);
2080 ci
->i_wrbuffer_ref
-= nr
;
2081 last
= !ci
->i_wrbuffer_ref
;
2083 if (ci
->i_head_snapc
== snapc
) {
2084 ci
->i_wrbuffer_ref_head
-= nr
;
2085 if (!ci
->i_wrbuffer_ref_head
) {
2086 ceph_put_snap_context(ci
->i_head_snapc
);
2087 ci
->i_head_snapc
= NULL
;
2089 dout("put_wrbuffer_cap_refs on %p head %d/%d -> %d/%d %s\n",
2091 ci
->i_wrbuffer_ref
+nr
, ci
->i_wrbuffer_ref_head
+nr
,
2092 ci
->i_wrbuffer_ref
, ci
->i_wrbuffer_ref_head
,
2093 last
? " LAST" : "");
2095 list_for_each_entry(capsnap
, &ci
->i_cap_snaps
, ci_item
) {
2096 if (capsnap
->context
== snapc
) {
2098 capsnap
->dirty_pages
-= nr
;
2099 last_snap
= !capsnap
->dirty_pages
;
2104 dout("put_wrbuffer_cap_refs on %p cap_snap %p "
2105 " snap %lld %d/%d -> %d/%d %s%s\n",
2106 inode
, capsnap
, capsnap
->context
->seq
,
2107 ci
->i_wrbuffer_ref
+nr
, capsnap
->dirty_pages
+ nr
,
2108 ci
->i_wrbuffer_ref
, capsnap
->dirty_pages
,
2109 last
? " (wrbuffer last)" : "",
2110 last_snap
? " (capsnap last)" : "");
2113 spin_unlock(&inode
->i_lock
);
2116 ceph_check_caps(ci
, CHECK_CAPS_AUTHONLY
, NULL
);
2118 } else if (last_snap
) {
2119 ceph_flush_snaps(ci
);
2120 wake_up(&ci
->i_cap_wq
);
2125 * Handle a cap GRANT message from the MDS. (Note that a GRANT may
2126 * actually be a revocation if it specifies a smaller cap set.)
2128 * caller holds s_mutex.
2131 * 1 - check_caps on auth cap only (writeback)
2132 * 2 - check_caps (ack revoke)
2134 static int handle_cap_grant(struct inode
*inode
, struct ceph_mds_caps
*grant
,
2135 struct ceph_mds_session
*session
,
2136 struct ceph_cap
*cap
,
2137 struct ceph_buffer
*xattr_buf
)
2138 __releases(inode
->i_lock
)
2141 struct ceph_inode_info
*ci
= ceph_inode(inode
);
2142 int mds
= session
->s_mds
;
2143 int seq
= le32_to_cpu(grant
->seq
);
2144 int newcaps
= le32_to_cpu(grant
->caps
);
2145 int issued
, implemented
, used
, wanted
, dirty
;
2146 u64 size
= le64_to_cpu(grant
->size
);
2147 u64 max_size
= le64_to_cpu(grant
->max_size
);
2148 struct timespec mtime
, atime
, ctime
;
2152 int revoked_rdcache
= 0;
2153 int invalidate_async
= 0;
2154 int tried_invalidate
= 0;
2157 dout("handle_cap_grant inode %p cap %p mds%d seq %d %s\n",
2158 inode
, cap
, mds
, seq
, ceph_cap_string(newcaps
));
2159 dout(" size %llu max_size %llu, i_size %llu\n", size
, max_size
,
2163 * If CACHE is being revoked, and we have no dirty buffers,
2164 * try to invalidate (once). (If there are dirty buffers, we
2165 * will invalidate _after_ writeback.)
2168 if (((cap
->issued
& ~newcaps
) & CEPH_CAP_FILE_CACHE
) &&
2169 !ci
->i_wrbuffer_ref
&& !tried_invalidate
) {
2170 dout("CACHE invalidation\n");
2171 spin_unlock(&inode
->i_lock
);
2172 tried_invalidate
= 1;
2174 ret
= invalidate_inode_pages2(&inode
->i_data
);
2175 spin_lock(&inode
->i_lock
);
2177 /* there were locked pages.. invalidate later
2178 in a separate thread. */
2179 if (ci
->i_rdcache_revoking
!= ci
->i_rdcache_gen
) {
2180 invalidate_async
= 1;
2181 ci
->i_rdcache_revoking
= ci
->i_rdcache_gen
;
2184 /* we successfully invalidated those pages */
2185 revoked_rdcache
= 1;
2186 ci
->i_rdcache_gen
= 0;
2187 ci
->i_rdcache_revoking
= 0;
2192 /* side effects now are allowed */
2194 issued
= __ceph_caps_issued(ci
, &implemented
);
2195 issued
|= implemented
| __ceph_caps_dirty(ci
);
2197 cap
->gen
= session
->s_cap_gen
;
2199 __check_cap_issue(ci
, cap
, newcaps
);
2201 if ((issued
& CEPH_CAP_AUTH_EXCL
) == 0) {
2202 inode
->i_mode
= le32_to_cpu(grant
->mode
);
2203 inode
->i_uid
= le32_to_cpu(grant
->uid
);
2204 inode
->i_gid
= le32_to_cpu(grant
->gid
);
2205 dout("%p mode 0%o uid.gid %d.%d\n", inode
, inode
->i_mode
,
2206 inode
->i_uid
, inode
->i_gid
);
2209 if ((issued
& CEPH_CAP_LINK_EXCL
) == 0)
2210 inode
->i_nlink
= le32_to_cpu(grant
->nlink
);
2212 if ((issued
& CEPH_CAP_XATTR_EXCL
) == 0 && grant
->xattr_len
) {
2213 int len
= le32_to_cpu(grant
->xattr_len
);
2214 u64 version
= le64_to_cpu(grant
->xattr_version
);
2216 if (version
> ci
->i_xattrs
.version
) {
2217 dout(" got new xattrs v%llu on %p len %d\n",
2218 version
, inode
, len
);
2219 if (ci
->i_xattrs
.blob
)
2220 ceph_buffer_put(ci
->i_xattrs
.blob
);
2221 ci
->i_xattrs
.blob
= ceph_buffer_get(xattr_buf
);
2222 ci
->i_xattrs
.version
= version
;
2226 /* size/ctime/mtime/atime? */
2227 ceph_fill_file_size(inode
, issued
,
2228 le32_to_cpu(grant
->truncate_seq
),
2229 le64_to_cpu(grant
->truncate_size
), size
);
2230 ceph_decode_timespec(&mtime
, &grant
->mtime
);
2231 ceph_decode_timespec(&atime
, &grant
->atime
);
2232 ceph_decode_timespec(&ctime
, &grant
->ctime
);
2233 ceph_fill_file_time(inode
, issued
,
2234 le32_to_cpu(grant
->time_warp_seq
), &ctime
, &mtime
,
2237 /* max size increase? */
2238 if (max_size
!= ci
->i_max_size
) {
2239 dout("max_size %lld -> %llu\n", ci
->i_max_size
, max_size
);
2240 ci
->i_max_size
= max_size
;
2241 if (max_size
>= ci
->i_wanted_max_size
) {
2242 ci
->i_wanted_max_size
= 0; /* reset */
2243 ci
->i_requested_max_size
= 0;
2248 /* check cap bits */
2249 wanted
= __ceph_caps_wanted(ci
);
2250 used
= __ceph_caps_used(ci
);
2251 dirty
= __ceph_caps_dirty(ci
);
2252 dout(" my wanted = %s, used = %s, dirty %s\n",
2253 ceph_cap_string(wanted
),
2254 ceph_cap_string(used
),
2255 ceph_cap_string(dirty
));
2256 if (wanted
!= le32_to_cpu(grant
->wanted
)) {
2257 dout("mds wanted %s -> %s\n",
2258 ceph_cap_string(le32_to_cpu(grant
->wanted
)),
2259 ceph_cap_string(wanted
));
2260 grant
->wanted
= cpu_to_le32(wanted
);
2265 /* file layout may have changed */
2266 ci
->i_layout
= grant
->layout
;
2268 /* revocation, grant, or no-op? */
2269 if (cap
->issued
& ~newcaps
) {
2270 dout("revocation: %s -> %s\n", ceph_cap_string(cap
->issued
),
2271 ceph_cap_string(newcaps
));
2272 if ((used
& ~newcaps
) & CEPH_CAP_FILE_BUFFER
)
2273 writeback
= 1; /* will delay ack */
2274 else if (dirty
& ~newcaps
)
2275 reply
= 1; /* initiate writeback in check_caps */
2276 else if (((used
& ~newcaps
) & CEPH_CAP_FILE_CACHE
) == 0 ||
2278 reply
= 2; /* send revoke ack in check_caps */
2279 cap
->issued
= newcaps
;
2280 } else if (cap
->issued
== newcaps
) {
2281 dout("caps unchanged: %s -> %s\n",
2282 ceph_cap_string(cap
->issued
), ceph_cap_string(newcaps
));
2284 dout("grant: %s -> %s\n", ceph_cap_string(cap
->issued
),
2285 ceph_cap_string(newcaps
));
2286 cap
->issued
= newcaps
;
2287 cap
->implemented
|= newcaps
; /* add bits only, to
2288 * avoid stepping on a
2289 * pending revocation */
2293 spin_unlock(&inode
->i_lock
);
2296 * queue inode for writeback: we can't actually call
2297 * filemap_write_and_wait, etc. from message handler
2300 dout("queueing %p for writeback\n", inode
);
2301 if (ceph_queue_writeback(inode
))
2304 if (invalidate_async
) {
2305 dout("queueing %p for page invalidation\n", inode
);
2306 if (ceph_queue_page_invalidation(inode
))
2310 wake_up(&ci
->i_cap_wq
);
2315 * Handle FLUSH_ACK from MDS, indicating that metadata we sent to the
2316 * MDS has been safely committed.
2318 static void handle_cap_flush_ack(struct inode
*inode
,
2319 struct ceph_mds_caps
*m
,
2320 struct ceph_mds_session
*session
,
2321 struct ceph_cap
*cap
)
2322 __releases(inode
->i_lock
)
2324 struct ceph_inode_info
*ci
= ceph_inode(inode
);
2325 struct ceph_mds_client
*mdsc
= &ceph_client(inode
->i_sb
)->mdsc
;
2326 unsigned seq
= le32_to_cpu(m
->seq
);
2327 int dirty
= le32_to_cpu(m
->dirty
);
2329 u64 flush_tid
= le64_to_cpu(m
->client_tid
);
2330 int old_dirty
= 0, new_dirty
= 0;
2333 for (i
= 0; i
< CEPH_CAP_BITS
; i
++)
2334 if ((dirty
& (1 << i
)) &&
2335 flush_tid
== ci
->i_cap_flush_tid
[i
])
2338 dout("handle_cap_flush_ack inode %p mds%d seq %d on %s cleaned %s,"
2339 " flushing %s -> %s\n",
2340 inode
, session
->s_mds
, seq
, ceph_cap_string(dirty
),
2341 ceph_cap_string(cleaned
), ceph_cap_string(ci
->i_flushing_caps
),
2342 ceph_cap_string(ci
->i_flushing_caps
& ~cleaned
));
2344 if (ci
->i_flushing_caps
== (ci
->i_flushing_caps
& ~cleaned
))
2347 old_dirty
= ci
->i_dirty_caps
| ci
->i_flushing_caps
;
2348 ci
->i_flushing_caps
&= ~cleaned
;
2349 new_dirty
= ci
->i_dirty_caps
| ci
->i_flushing_caps
;
2351 spin_lock(&mdsc
->cap_dirty_lock
);
2352 if (ci
->i_flushing_caps
== 0) {
2353 list_del_init(&ci
->i_flushing_item
);
2354 if (!list_empty(&session
->s_cap_flushing
))
2355 dout(" mds%d still flushing cap on %p\n",
2357 &list_entry(session
->s_cap_flushing
.next
,
2358 struct ceph_inode_info
,
2359 i_flushing_item
)->vfs_inode
);
2360 mdsc
->num_cap_flushing
--;
2361 wake_up(&mdsc
->cap_flushing_wq
);
2362 dout(" inode %p now !flushing\n", inode
);
2364 if (old_dirty
&& !new_dirty
) {
2365 dout(" inode %p now clean\n", inode
);
2366 list_del_init(&ci
->i_dirty_item
);
2368 spin_unlock(&mdsc
->cap_dirty_lock
);
2369 wake_up(&ci
->i_cap_wq
);
2372 spin_unlock(&inode
->i_lock
);
2373 if (old_dirty
&& !new_dirty
)
2378 * Handle FLUSHSNAP_ACK. MDS has flushed snap data to disk and we can
2379 * throw away our cap_snap.
2381 * Caller hold s_mutex.
2383 static void handle_cap_flushsnap_ack(struct inode
*inode
,
2384 struct ceph_mds_caps
*m
,
2385 struct ceph_mds_session
*session
)
2387 struct ceph_inode_info
*ci
= ceph_inode(inode
);
2388 u64 follows
= le64_to_cpu(m
->snap_follows
);
2389 u64 flush_tid
= le64_to_cpu(m
->client_tid
);
2390 struct ceph_cap_snap
*capsnap
;
2393 dout("handle_cap_flushsnap_ack inode %p ci %p mds%d follows %lld\n",
2394 inode
, ci
, session
->s_mds
, follows
);
2396 spin_lock(&inode
->i_lock
);
2397 list_for_each_entry(capsnap
, &ci
->i_cap_snaps
, ci_item
) {
2398 if (capsnap
->follows
== follows
) {
2399 if (capsnap
->flush_tid
!= flush_tid
) {
2400 dout(" cap_snap %p follows %lld tid %lld !="
2401 " %lld\n", capsnap
, follows
,
2402 flush_tid
, capsnap
->flush_tid
);
2405 WARN_ON(capsnap
->dirty_pages
|| capsnap
->writing
);
2406 dout(" removing cap_snap %p follows %lld\n",
2408 ceph_put_snap_context(capsnap
->context
);
2409 list_del(&capsnap
->ci_item
);
2410 list_del(&capsnap
->flushing_item
);
2411 ceph_put_cap_snap(capsnap
);
2415 dout(" skipping cap_snap %p follows %lld\n",
2416 capsnap
, capsnap
->follows
);
2419 spin_unlock(&inode
->i_lock
);
2425 * Handle TRUNC from MDS, indicating file truncation.
2427 * caller hold s_mutex.
2429 static void handle_cap_trunc(struct inode
*inode
,
2430 struct ceph_mds_caps
*trunc
,
2431 struct ceph_mds_session
*session
)
2432 __releases(inode
->i_lock
)
2434 struct ceph_inode_info
*ci
= ceph_inode(inode
);
2435 int mds
= session
->s_mds
;
2436 int seq
= le32_to_cpu(trunc
->seq
);
2437 u32 truncate_seq
= le32_to_cpu(trunc
->truncate_seq
);
2438 u64 truncate_size
= le64_to_cpu(trunc
->truncate_size
);
2439 u64 size
= le64_to_cpu(trunc
->size
);
2440 int implemented
= 0;
2441 int dirty
= __ceph_caps_dirty(ci
);
2442 int issued
= __ceph_caps_issued(ceph_inode(inode
), &implemented
);
2443 int queue_trunc
= 0;
2445 issued
|= implemented
| dirty
;
2447 dout("handle_cap_trunc inode %p mds%d seq %d to %lld seq %d\n",
2448 inode
, mds
, seq
, truncate_size
, truncate_seq
);
2449 queue_trunc
= ceph_fill_file_size(inode
, issued
,
2450 truncate_seq
, truncate_size
, size
);
2451 spin_unlock(&inode
->i_lock
);
2454 if (queue_work(ceph_client(inode
->i_sb
)->trunc_wq
,
2455 &ci
->i_vmtruncate_work
))
2460 * Handle EXPORT from MDS. Cap is being migrated _from_ this mds to a
2461 * different one. If we are the most recent migration we've seen (as
2462 * indicated by mseq), make note of the migrating cap bits for the
2463 * duration (until we see the corresponding IMPORT).
2465 * caller holds s_mutex
2467 static void handle_cap_export(struct inode
*inode
, struct ceph_mds_caps
*ex
,
2468 struct ceph_mds_session
*session
)
2470 struct ceph_inode_info
*ci
= ceph_inode(inode
);
2471 int mds
= session
->s_mds
;
2472 unsigned mseq
= le32_to_cpu(ex
->migrate_seq
);
2473 struct ceph_cap
*cap
= NULL
, *t
;
2477 dout("handle_cap_export inode %p ci %p mds%d mseq %d\n",
2478 inode
, ci
, mds
, mseq
);
2480 spin_lock(&inode
->i_lock
);
2482 /* make sure we haven't seen a higher mseq */
2483 for (p
= rb_first(&ci
->i_caps
); p
; p
= rb_next(p
)) {
2484 t
= rb_entry(p
, struct ceph_cap
, ci_node
);
2485 if (ceph_seq_cmp(t
->mseq
, mseq
) > 0) {
2486 dout(" higher mseq on cap from mds%d\n",
2490 if (t
->session
->s_mds
== mds
)
2497 ci
->i_cap_exporting_mds
= mds
;
2498 ci
->i_cap_exporting_mseq
= mseq
;
2499 ci
->i_cap_exporting_issued
= cap
->issued
;
2501 __ceph_remove_cap(cap
, NULL
);
2506 spin_unlock(&inode
->i_lock
);
2510 * Handle cap IMPORT. If there are temp bits from an older EXPORT,
2513 * caller holds s_mutex.
2515 static void handle_cap_import(struct ceph_mds_client
*mdsc
,
2516 struct inode
*inode
, struct ceph_mds_caps
*im
,
2517 struct ceph_mds_session
*session
,
2518 void *snaptrace
, int snaptrace_len
)
2520 struct ceph_inode_info
*ci
= ceph_inode(inode
);
2521 int mds
= session
->s_mds
;
2522 unsigned issued
= le32_to_cpu(im
->caps
);
2523 unsigned wanted
= le32_to_cpu(im
->wanted
);
2524 unsigned seq
= le32_to_cpu(im
->seq
);
2525 unsigned mseq
= le32_to_cpu(im
->migrate_seq
);
2526 u64 realmino
= le64_to_cpu(im
->realm
);
2527 u64 cap_id
= le64_to_cpu(im
->cap_id
);
2529 if (ci
->i_cap_exporting_mds
>= 0 &&
2530 ceph_seq_cmp(ci
->i_cap_exporting_mseq
, mseq
) < 0) {
2531 dout("handle_cap_import inode %p ci %p mds%d mseq %d"
2532 " - cleared exporting from mds%d\n",
2533 inode
, ci
, mds
, mseq
,
2534 ci
->i_cap_exporting_mds
);
2535 ci
->i_cap_exporting_issued
= 0;
2536 ci
->i_cap_exporting_mseq
= 0;
2537 ci
->i_cap_exporting_mds
= -1;
2539 dout("handle_cap_import inode %p ci %p mds%d mseq %d\n",
2540 inode
, ci
, mds
, mseq
);
2543 down_write(&mdsc
->snap_rwsem
);
2544 ceph_update_snap_trace(mdsc
, snaptrace
, snaptrace
+snaptrace_len
,
2546 downgrade_write(&mdsc
->snap_rwsem
);
2547 ceph_add_cap(inode
, session
, cap_id
, -1,
2548 issued
, wanted
, seq
, mseq
, realmino
, CEPH_CAP_FLAG_AUTH
,
2549 NULL
/* no caps context */);
2550 try_flush_caps(inode
, session
, NULL
);
2551 up_read(&mdsc
->snap_rwsem
);
2555 * Handle a caps message from the MDS.
2557 * Identify the appropriate session, inode, and call the right handler
2558 * based on the cap op.
2560 void ceph_handle_caps(struct ceph_mds_session
*session
,
2561 struct ceph_msg
*msg
)
2563 struct ceph_mds_client
*mdsc
= session
->s_mdsc
;
2564 struct super_block
*sb
= mdsc
->client
->sb
;
2565 struct inode
*inode
;
2566 struct ceph_cap
*cap
;
2567 struct ceph_mds_caps
*h
;
2568 int mds
= le64_to_cpu(msg
->hdr
.src
.name
.num
);
2571 struct ceph_vino vino
;
2577 dout("handle_caps from mds%d\n", mds
);
2580 if (msg
->front
.iov_len
< sizeof(*h
))
2582 h
= msg
->front
.iov_base
;
2583 op
= le32_to_cpu(h
->op
);
2584 vino
.ino
= le64_to_cpu(h
->ino
);
2585 vino
.snap
= CEPH_NOSNAP
;
2586 cap_id
= le64_to_cpu(h
->cap_id
);
2587 seq
= le32_to_cpu(h
->seq
);
2588 size
= le64_to_cpu(h
->size
);
2589 max_size
= le64_to_cpu(h
->max_size
);
2591 mutex_lock(&session
->s_mutex
);
2593 dout(" mds%d seq %lld cap seq %u\n", session
->s_mds
, session
->s_seq
,
2597 inode
= ceph_find_inode(sb
, vino
);
2598 dout(" op %s ino %llx.%llx inode %p\n", ceph_cap_op_name(op
), vino
.ino
,
2601 dout(" i don't have ino %llx\n", vino
.ino
);
2605 /* these will work even if we don't have a cap yet */
2607 case CEPH_CAP_OP_FLUSHSNAP_ACK
:
2608 handle_cap_flushsnap_ack(inode
, h
, session
);
2611 case CEPH_CAP_OP_EXPORT
:
2612 handle_cap_export(inode
, h
, session
);
2615 case CEPH_CAP_OP_IMPORT
:
2616 handle_cap_import(mdsc
, inode
, h
, session
,
2618 le32_to_cpu(h
->snap_trace_len
));
2619 check_caps
= 1; /* we may have sent a RELEASE to the old auth */
2623 /* the rest require a cap */
2624 spin_lock(&inode
->i_lock
);
2625 cap
= __get_cap_for_mds(ceph_inode(inode
), mds
);
2627 dout("no cap on %p ino %llx.%llx from mds%d, releasing\n",
2628 inode
, ceph_ino(inode
), ceph_snap(inode
), mds
);
2629 spin_unlock(&inode
->i_lock
);
2633 /* note that each of these drops i_lock for us */
2635 case CEPH_CAP_OP_REVOKE
:
2636 case CEPH_CAP_OP_GRANT
:
2637 r
= handle_cap_grant(inode
, h
, session
, cap
, msg
->middle
);
2639 ceph_check_caps(ceph_inode(inode
),
2640 CHECK_CAPS_NODELAY
|CHECK_CAPS_AUTHONLY
,
2643 ceph_check_caps(ceph_inode(inode
),
2648 case CEPH_CAP_OP_FLUSH_ACK
:
2649 handle_cap_flush_ack(inode
, h
, session
, cap
);
2652 case CEPH_CAP_OP_TRUNC
:
2653 handle_cap_trunc(inode
, h
, session
);
2657 spin_unlock(&inode
->i_lock
);
2658 pr_err("ceph_handle_caps: unknown cap op %d %s\n", op
,
2659 ceph_cap_op_name(op
));
2663 mutex_unlock(&session
->s_mutex
);
2666 ceph_check_caps(ceph_inode(inode
), CHECK_CAPS_NODELAY
, NULL
);
2672 pr_err("ceph_handle_caps: corrupt message\n");
2677 * Delayed work handler to process end of delayed cap release LRU list.
2679 void ceph_check_delayed_caps(struct ceph_mds_client
*mdsc
, int flushdirty
)
2681 struct ceph_inode_info
*ci
;
2682 int flags
= CHECK_CAPS_NODELAY
;
2685 flags
|= CHECK_CAPS_FLUSH
;
2687 dout("check_delayed_caps\n");
2689 spin_lock(&mdsc
->cap_delay_lock
);
2690 if (list_empty(&mdsc
->cap_delay_list
))
2692 ci
= list_first_entry(&mdsc
->cap_delay_list
,
2693 struct ceph_inode_info
,
2695 if ((ci
->i_ceph_flags
& CEPH_I_FLUSH
) == 0 &&
2696 time_before(jiffies
, ci
->i_hold_caps_max
))
2698 list_del_init(&ci
->i_cap_delay_list
);
2699 spin_unlock(&mdsc
->cap_delay_lock
);
2700 dout("check_delayed_caps on %p\n", &ci
->vfs_inode
);
2701 ceph_check_caps(ci
, flags
, NULL
);
2703 spin_unlock(&mdsc
->cap_delay_lock
);
2707 * Drop open file reference. If we were the last open file,
2708 * we may need to release capabilities to the MDS (or schedule
2709 * their delayed release).
2711 void ceph_put_fmode(struct ceph_inode_info
*ci
, int fmode
)
2713 struct inode
*inode
= &ci
->vfs_inode
;
2716 spin_lock(&inode
->i_lock
);
2717 dout("put_fmode %p fmode %d %d -> %d\n", inode
, fmode
,
2718 ci
->i_nr_by_mode
[fmode
], ci
->i_nr_by_mode
[fmode
]-1);
2719 BUG_ON(ci
->i_nr_by_mode
[fmode
] == 0);
2720 if (--ci
->i_nr_by_mode
[fmode
] == 0)
2722 spin_unlock(&inode
->i_lock
);
2724 if (last
&& ci
->i_vino
.snap
== CEPH_NOSNAP
)
2725 ceph_check_caps(ci
, 0, NULL
);
2729 * Helpers for embedding cap and dentry lease releases into mds
2732 * @force is used by dentry_release (below) to force inclusion of a
2733 * record for the directory inode, even when there aren't any caps to
2736 int ceph_encode_inode_release(void **p
, struct inode
*inode
,
2737 int mds
, int drop
, int unless
, int force
)
2739 struct ceph_inode_info
*ci
= ceph_inode(inode
);
2740 struct ceph_cap
*cap
;
2741 struct ceph_mds_request_release
*rel
= *p
;
2744 dout("encode_inode_release %p mds%d drop %s unless %s\n", inode
,
2745 mds
, ceph_cap_string(drop
), ceph_cap_string(unless
));
2747 spin_lock(&inode
->i_lock
);
2748 cap
= __get_cap_for_mds(ci
, mds
);
2749 if (cap
&& __cap_is_valid(cap
)) {
2751 ((cap
->issued
& drop
) &&
2752 (cap
->issued
& unless
) == 0)) {
2753 if ((cap
->issued
& drop
) &&
2754 (cap
->issued
& unless
) == 0) {
2755 dout("encode_inode_release %p cap %p %s -> "
2757 ceph_cap_string(cap
->issued
),
2758 ceph_cap_string(cap
->issued
& ~drop
));
2759 cap
->issued
&= ~drop
;
2760 cap
->implemented
&= ~drop
;
2761 if (ci
->i_ceph_flags
& CEPH_I_NODELAY
) {
2762 int wanted
= __ceph_caps_wanted(ci
);
2763 dout(" wanted %s -> %s (act %s)\n",
2764 ceph_cap_string(cap
->mds_wanted
),
2765 ceph_cap_string(cap
->mds_wanted
&
2767 ceph_cap_string(wanted
));
2768 cap
->mds_wanted
&= wanted
;
2771 dout("encode_inode_release %p cap %p %s"
2772 " (force)\n", inode
, cap
,
2773 ceph_cap_string(cap
->issued
));
2776 rel
->ino
= cpu_to_le64(ceph_ino(inode
));
2777 rel
->cap_id
= cpu_to_le64(cap
->cap_id
);
2778 rel
->seq
= cpu_to_le32(cap
->seq
);
2779 rel
->issue_seq
= cpu_to_le32(cap
->issue_seq
),
2780 rel
->mseq
= cpu_to_le32(cap
->mseq
);
2781 rel
->caps
= cpu_to_le32(cap
->issued
);
2782 rel
->wanted
= cpu_to_le32(cap
->mds_wanted
);
2788 dout("encode_inode_release %p cap %p %s\n",
2789 inode
, cap
, ceph_cap_string(cap
->issued
));
2792 spin_unlock(&inode
->i_lock
);
2796 int ceph_encode_dentry_release(void **p
, struct dentry
*dentry
,
2797 int mds
, int drop
, int unless
)
2799 struct inode
*dir
= dentry
->d_parent
->d_inode
;
2800 struct ceph_mds_request_release
*rel
= *p
;
2801 struct ceph_dentry_info
*di
= ceph_dentry(dentry
);
2806 * force an record for the directory caps if we have a dentry lease.
2807 * this is racy (can't take i_lock and d_lock together), but it
2808 * doesn't have to be perfect; the mds will revoke anything we don't
2811 spin_lock(&dentry
->d_lock
);
2812 if (di
->lease_session
&& di
->lease_session
->s_mds
== mds
)
2814 spin_unlock(&dentry
->d_lock
);
2816 ret
= ceph_encode_inode_release(p
, dir
, mds
, drop
, unless
, force
);
2818 spin_lock(&dentry
->d_lock
);
2819 if (ret
&& di
->lease_session
&& di
->lease_session
->s_mds
== mds
) {
2820 dout("encode_dentry_release %p mds%d seq %d\n",
2821 dentry
, mds
, (int)di
->lease_seq
);
2822 rel
->dname_len
= cpu_to_le32(dentry
->d_name
.len
);
2823 memcpy(*p
, dentry
->d_name
.name
, dentry
->d_name
.len
);
2824 *p
+= dentry
->d_name
.len
;
2825 rel
->dname_seq
= cpu_to_le32(di
->lease_seq
);
2827 spin_unlock(&dentry
->d_lock
);