Lines Matching +full:realm +full:-
1 // SPDX-License-Identifier: GPL-2.0
125 *s++ = '-'; in ceph_cap_string()
132 INIT_LIST_HEAD(&mdsc->caps_list); in ceph_caps_init()
133 spin_lock_init(&mdsc->caps_list_lock); in ceph_caps_init()
140 spin_lock(&mdsc->caps_list_lock); in ceph_caps_finalize()
141 while (!list_empty(&mdsc->caps_list)) { in ceph_caps_finalize()
142 cap = list_first_entry(&mdsc->caps_list, in ceph_caps_finalize()
144 list_del(&cap->caps_item); in ceph_caps_finalize()
147 mdsc->caps_total_count = 0; in ceph_caps_finalize()
148 mdsc->caps_avail_count = 0; in ceph_caps_finalize()
149 mdsc->caps_use_count = 0; in ceph_caps_finalize()
150 mdsc->caps_reserve_count = 0; in ceph_caps_finalize()
151 mdsc->caps_min_count = 0; in ceph_caps_finalize()
152 spin_unlock(&mdsc->caps_list_lock); in ceph_caps_finalize()
158 spin_lock(&mdsc->caps_list_lock); in ceph_adjust_caps_max_min()
159 mdsc->caps_min_count = fsopt->max_readdir; in ceph_adjust_caps_max_min()
160 if (mdsc->caps_min_count < 1024) in ceph_adjust_caps_max_min()
161 mdsc->caps_min_count = 1024; in ceph_adjust_caps_max_min()
162 mdsc->caps_use_max = fsopt->caps_max; in ceph_adjust_caps_max_min()
163 if (mdsc->caps_use_max > 0 && in ceph_adjust_caps_max_min()
164 mdsc->caps_use_max < mdsc->caps_min_count) in ceph_adjust_caps_max_min()
165 mdsc->caps_use_max = mdsc->caps_min_count; in ceph_adjust_caps_max_min()
166 spin_unlock(&mdsc->caps_list_lock); in ceph_adjust_caps_max_min()
175 BUG_ON(mdsc->caps_reserve_count < nr_caps); in __ceph_unreserve_caps()
176 mdsc->caps_reserve_count -= nr_caps; in __ceph_unreserve_caps()
177 if (mdsc->caps_avail_count >= in __ceph_unreserve_caps()
178 mdsc->caps_reserve_count + mdsc->caps_min_count) { in __ceph_unreserve_caps()
179 mdsc->caps_total_count -= nr_caps; in __ceph_unreserve_caps()
181 cap = list_first_entry(&mdsc->caps_list, in __ceph_unreserve_caps()
183 list_del(&cap->caps_item); in __ceph_unreserve_caps()
187 mdsc->caps_avail_count += nr_caps; in __ceph_unreserve_caps()
190 doutc(mdsc->fsc->client, in __ceph_unreserve_caps()
192 mdsc->caps_total_count, mdsc->caps_use_count, in __ceph_unreserve_caps()
193 mdsc->caps_reserve_count, mdsc->caps_avail_count); in __ceph_unreserve_caps()
194 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in __ceph_unreserve_caps()
195 mdsc->caps_reserve_count + in __ceph_unreserve_caps()
196 mdsc->caps_avail_count); in __ceph_unreserve_caps()
201 * Called under mdsc->mutex.
206 struct ceph_client *cl = mdsc->fsc->client; in ceph_reserve_caps()
220 spin_lock(&mdsc->caps_list_lock); in ceph_reserve_caps()
221 if (mdsc->caps_avail_count >= need) in ceph_reserve_caps()
224 have = mdsc->caps_avail_count; in ceph_reserve_caps()
225 mdsc->caps_avail_count -= have; in ceph_reserve_caps()
226 mdsc->caps_reserve_count += have; in ceph_reserve_caps()
227 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_reserve_caps()
228 mdsc->caps_reserve_count + in ceph_reserve_caps()
229 mdsc->caps_avail_count); in ceph_reserve_caps()
230 spin_unlock(&mdsc->caps_list_lock); in ceph_reserve_caps()
235 list_add(&cap->caps_item, &newcaps); in ceph_reserve_caps()
242 for (j = 0; j < mdsc->max_sessions; j++) { in ceph_reserve_caps()
246 mutex_unlock(&mdsc->mutex); in ceph_reserve_caps()
248 mutex_lock(&s->s_mutex); in ceph_reserve_caps()
249 max_caps = s->s_nr_caps - (need - i); in ceph_reserve_caps()
251 mutex_unlock(&s->s_mutex); in ceph_reserve_caps()
254 mutex_lock(&mdsc->mutex); in ceph_reserve_caps()
258 spin_lock(&mdsc->caps_list_lock); in ceph_reserve_caps()
259 if (mdsc->caps_avail_count) { in ceph_reserve_caps()
261 if (mdsc->caps_avail_count >= need - i) in ceph_reserve_caps()
262 more_have = need - i; in ceph_reserve_caps()
264 more_have = mdsc->caps_avail_count; in ceph_reserve_caps()
268 mdsc->caps_avail_count -= more_have; in ceph_reserve_caps()
269 mdsc->caps_reserve_count += more_have; in ceph_reserve_caps()
272 spin_unlock(&mdsc->caps_list_lock); in ceph_reserve_caps()
279 err = -ENOMEM; in ceph_reserve_caps()
285 ctx->count = need; in ceph_reserve_caps()
286 ctx->used = 0; in ceph_reserve_caps()
289 spin_lock(&mdsc->caps_list_lock); in ceph_reserve_caps()
290 mdsc->caps_total_count += alloc; in ceph_reserve_caps()
291 mdsc->caps_reserve_count += alloc; in ceph_reserve_caps()
292 list_splice(&newcaps, &mdsc->caps_list); in ceph_reserve_caps()
294 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_reserve_caps()
295 mdsc->caps_reserve_count + in ceph_reserve_caps()
296 mdsc->caps_avail_count); in ceph_reserve_caps()
301 spin_unlock(&mdsc->caps_list_lock); in ceph_reserve_caps()
304 mdsc->caps_total_count, mdsc->caps_use_count, in ceph_reserve_caps()
305 mdsc->caps_reserve_count, mdsc->caps_avail_count); in ceph_reserve_caps()
312 struct ceph_client *cl = mdsc->fsc->client; in ceph_unreserve_caps()
314 if (!ctx->count) in ceph_unreserve_caps()
317 doutc(cl, "ctx=%p count=%d\n", ctx, ctx->count); in ceph_unreserve_caps()
318 spin_lock(&mdsc->caps_list_lock); in ceph_unreserve_caps()
319 __ceph_unreserve_caps(mdsc, ctx->count); in ceph_unreserve_caps()
320 ctx->count = 0; in ceph_unreserve_caps()
322 if (mdsc->caps_use_max > 0 && in ceph_unreserve_caps()
323 mdsc->caps_use_count > mdsc->caps_use_max) in ceph_unreserve_caps()
325 spin_unlock(&mdsc->caps_list_lock); in ceph_unreserve_caps()
328 ceph_reclaim_caps_nr(mdsc, ctx->used); in ceph_unreserve_caps()
334 struct ceph_client *cl = mdsc->fsc->client; in ceph_get_cap()
341 spin_lock(&mdsc->caps_list_lock); in ceph_get_cap()
342 mdsc->caps_use_count++; in ceph_get_cap()
343 mdsc->caps_total_count++; in ceph_get_cap()
344 spin_unlock(&mdsc->caps_list_lock); in ceph_get_cap()
346 spin_lock(&mdsc->caps_list_lock); in ceph_get_cap()
347 if (mdsc->caps_avail_count) { in ceph_get_cap()
348 BUG_ON(list_empty(&mdsc->caps_list)); in ceph_get_cap()
350 mdsc->caps_avail_count--; in ceph_get_cap()
351 mdsc->caps_use_count++; in ceph_get_cap()
352 cap = list_first_entry(&mdsc->caps_list, in ceph_get_cap()
354 list_del(&cap->caps_item); in ceph_get_cap()
356 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_get_cap()
357 mdsc->caps_reserve_count + mdsc->caps_avail_count); in ceph_get_cap()
359 spin_unlock(&mdsc->caps_list_lock); in ceph_get_cap()
365 spin_lock(&mdsc->caps_list_lock); in ceph_get_cap()
367 ctx->count, mdsc->caps_total_count, mdsc->caps_use_count, in ceph_get_cap()
368 mdsc->caps_reserve_count, mdsc->caps_avail_count); in ceph_get_cap()
369 BUG_ON(!ctx->count); in ceph_get_cap()
370 BUG_ON(ctx->count > mdsc->caps_reserve_count); in ceph_get_cap()
371 BUG_ON(list_empty(&mdsc->caps_list)); in ceph_get_cap()
373 ctx->count--; in ceph_get_cap()
374 ctx->used++; in ceph_get_cap()
375 mdsc->caps_reserve_count--; in ceph_get_cap()
376 mdsc->caps_use_count++; in ceph_get_cap()
378 cap = list_first_entry(&mdsc->caps_list, struct ceph_cap, caps_item); in ceph_get_cap()
379 list_del(&cap->caps_item); in ceph_get_cap()
381 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_get_cap()
382 mdsc->caps_reserve_count + mdsc->caps_avail_count); in ceph_get_cap()
383 spin_unlock(&mdsc->caps_list_lock); in ceph_get_cap()
389 struct ceph_client *cl = mdsc->fsc->client; in ceph_put_cap()
391 spin_lock(&mdsc->caps_list_lock); in ceph_put_cap()
393 mdsc->caps_total_count, mdsc->caps_use_count, in ceph_put_cap()
394 mdsc->caps_reserve_count, mdsc->caps_avail_count); in ceph_put_cap()
395 mdsc->caps_use_count--; in ceph_put_cap()
400 if (mdsc->caps_avail_count >= mdsc->caps_reserve_count + in ceph_put_cap()
401 mdsc->caps_min_count) { in ceph_put_cap()
402 mdsc->caps_total_count--; in ceph_put_cap()
405 mdsc->caps_avail_count++; in ceph_put_cap()
406 list_add(&cap->caps_item, &mdsc->caps_list); in ceph_put_cap()
409 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_put_cap()
410 mdsc->caps_reserve_count + mdsc->caps_avail_count); in ceph_put_cap()
411 spin_unlock(&mdsc->caps_list_lock); in ceph_put_cap()
418 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_reservation_status()
420 spin_lock(&mdsc->caps_list_lock); in ceph_reservation_status()
423 *total = mdsc->caps_total_count; in ceph_reservation_status()
425 *avail = mdsc->caps_avail_count; in ceph_reservation_status()
427 *used = mdsc->caps_use_count; in ceph_reservation_status()
429 *reserved = mdsc->caps_reserve_count; in ceph_reservation_status()
431 *min = mdsc->caps_min_count; in ceph_reservation_status()
433 spin_unlock(&mdsc->caps_list_lock); in ceph_reservation_status()
444 struct rb_node *n = ci->i_caps.rb_node; in __get_cap_for_mds()
448 if (mds < cap->mds) in __get_cap_for_mds()
449 n = n->rb_left; in __get_cap_for_mds()
450 else if (mds > cap->mds) in __get_cap_for_mds()
451 n = n->rb_right; in __get_cap_for_mds()
462 spin_lock(&ci->i_ceph_lock); in ceph_get_cap_for_mds()
464 spin_unlock(&ci->i_ceph_lock); in ceph_get_cap_for_mds()
474 struct rb_node **p = &ci->i_caps.rb_node; in __insert_cap_node()
481 if (new->mds < cap->mds) in __insert_cap_node()
482 p = &(*p)->rb_left; in __insert_cap_node()
483 else if (new->mds > cap->mds) in __insert_cap_node()
484 p = &(*p)->rb_right; in __insert_cap_node()
489 rb_link_node(&new->ci_node, parent, p); in __insert_cap_node()
490 rb_insert_color(&new->ci_node, &ci->i_caps); in __insert_cap_node()
500 struct inode *inode = &ci->netfs.inode; in __cap_set_timeouts()
501 struct ceph_mount_options *opt = mdsc->fsc->mount_options; in __cap_set_timeouts()
503 ci->i_hold_caps_max = round_jiffies(jiffies + in __cap_set_timeouts()
504 opt->caps_wanted_delay_max * HZ); in __cap_set_timeouts()
505 doutc(mdsc->fsc->client, "%p %llx.%llx %lu\n", inode, in __cap_set_timeouts()
506 ceph_vinop(inode), ci->i_hold_caps_max - jiffies); in __cap_set_timeouts()
515 * -> we take mdsc->cap_delay_lock
520 struct inode *inode = &ci->netfs.inode; in __cap_delay_requeue()
522 doutc(mdsc->fsc->client, "%p %llx.%llx flags 0x%lx at %lu\n", in __cap_delay_requeue()
523 inode, ceph_vinop(inode), ci->i_ceph_flags, in __cap_delay_requeue()
524 ci->i_hold_caps_max); in __cap_delay_requeue()
525 if (!mdsc->stopping) { in __cap_delay_requeue()
526 spin_lock(&mdsc->cap_delay_lock); in __cap_delay_requeue()
527 if (!list_empty(&ci->i_cap_delay_list)) { in __cap_delay_requeue()
528 if (ci->i_ceph_flags & CEPH_I_FLUSH) in __cap_delay_requeue()
530 list_del_init(&ci->i_cap_delay_list); in __cap_delay_requeue()
533 list_add_tail(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue()
535 spin_unlock(&mdsc->cap_delay_lock); in __cap_delay_requeue()
547 struct inode *inode = &ci->netfs.inode; in __cap_delay_requeue_front()
549 doutc(mdsc->fsc->client, "%p %llx.%llx\n", inode, ceph_vinop(inode)); in __cap_delay_requeue_front()
550 spin_lock(&mdsc->cap_delay_lock); in __cap_delay_requeue_front()
551 ci->i_ceph_flags |= CEPH_I_FLUSH; in __cap_delay_requeue_front()
552 if (!list_empty(&ci->i_cap_delay_list)) in __cap_delay_requeue_front()
553 list_del_init(&ci->i_cap_delay_list); in __cap_delay_requeue_front()
554 list_add(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue_front()
555 spin_unlock(&mdsc->cap_delay_lock); in __cap_delay_requeue_front()
566 struct inode *inode = &ci->netfs.inode; in __cap_delay_cancel()
568 doutc(mdsc->fsc->client, "%p %llx.%llx\n", inode, ceph_vinop(inode)); in __cap_delay_cancel()
569 if (list_empty(&ci->i_cap_delay_list)) in __cap_delay_cancel()
571 spin_lock(&mdsc->cap_delay_lock); in __cap_delay_cancel()
572 list_del_init(&ci->i_cap_delay_list); in __cap_delay_cancel()
573 spin_unlock(&mdsc->cap_delay_lock); in __cap_delay_cancel()
580 struct inode *inode = &ci->netfs.inode; in __check_cap_issue()
585 lockdep_assert_held(&ci->i_ceph_lock); in __check_cap_issue()
591 if (S_ISREG(ci->netfs.inode.i_mode) && in __check_cap_issue()
594 ci->i_rdcache_gen++; in __check_cap_issue()
601 * stops on-going cached readdir. in __check_cap_issue()
605 atomic_inc(&ci->i_shared_gen); in __check_cap_issue()
606 if (S_ISDIR(ci->netfs.inode.i_mode)) { in __check_cap_issue()
613 if (S_ISDIR(ci->netfs.inode.i_mode) && (had & CEPH_CAP_DIR_CREATE) && in __check_cap_issue()
615 ceph_put_string(rcu_dereference_raw(ci->i_cached_layout.pool_ns)); in __check_cap_issue()
616 memset(&ci->i_cached_layout, 0, sizeof(ci->i_cached_layout)); in __check_cap_issue()
621 * change_auth_cap_ses - move inode to appropriate lists when auth caps change
628 lockdep_assert_held(&ci->i_ceph_lock); in change_auth_cap_ses()
630 if (list_empty(&ci->i_dirty_item) && list_empty(&ci->i_flushing_item)) in change_auth_cap_ses()
633 spin_lock(&session->s_mdsc->cap_dirty_lock); in change_auth_cap_ses()
634 if (!list_empty(&ci->i_dirty_item)) in change_auth_cap_ses()
635 list_move(&ci->i_dirty_item, &session->s_cap_dirty); in change_auth_cap_ses()
636 if (!list_empty(&ci->i_flushing_item)) in change_auth_cap_ses()
637 list_move_tail(&ci->i_flushing_item, &session->s_cap_flushing); in change_auth_cap_ses()
638 spin_unlock(&session->s_mdsc->cap_dirty_lock); in change_auth_cap_ses()
644 * Caller should hold session snap_rwsem (read) and ci->i_ceph_lock
656 struct ceph_mds_client *mdsc = ceph_inode_to_fs_client(inode)->mdsc; in ceph_add_cap()
660 int mds = session->s_mds; in ceph_add_cap()
664 lockdep_assert_held(&ci->i_ceph_lock); in ceph_add_cap()
667 ceph_vinop(inode), session->s_mds, cap_id, in ceph_add_cap()
670 gen = atomic_read(&session->s_cap_gen); in ceph_add_cap()
677 cap->issued = 0; in ceph_add_cap()
678 cap->implemented = 0; in ceph_add_cap()
679 cap->mds = mds; in ceph_add_cap()
680 cap->mds_wanted = 0; in ceph_add_cap()
681 cap->mseq = 0; in ceph_add_cap()
683 cap->ci = ci; in ceph_add_cap()
687 cap->session = session; in ceph_add_cap()
688 spin_lock(&session->s_cap_lock); in ceph_add_cap()
689 list_add_tail(&cap->session_caps, &session->s_caps); in ceph_add_cap()
690 session->s_nr_caps++; in ceph_add_cap()
691 atomic64_inc(&mdsc->metric.total_caps); in ceph_add_cap()
692 spin_unlock(&session->s_cap_lock); in ceph_add_cap()
694 spin_lock(&session->s_cap_lock); in ceph_add_cap()
695 list_move_tail(&cap->session_caps, &session->s_caps); in ceph_add_cap()
696 spin_unlock(&session->s_cap_lock); in ceph_add_cap()
698 if (cap->cap_gen < gen) in ceph_add_cap()
699 cap->issued = cap->implemented = CEPH_CAP_PIN; in ceph_add_cap()
706 * "ceph_seq_cmp(seq, cap->seq) <= 0" means we are processing in ceph_add_cap()
710 if (ceph_seq_cmp(seq, cap->seq) <= 0) { in ceph_add_cap()
711 WARN_ON(cap != ci->i_auth_cap); in ceph_add_cap()
712 WARN_ON(cap->cap_id != cap_id); in ceph_add_cap()
713 seq = cap->seq; in ceph_add_cap()
714 mseq = cap->mseq; in ceph_add_cap()
715 issued |= cap->issued; in ceph_add_cap()
720 if (!ci->i_snap_realm || in ceph_add_cap()
722 realmino != (u64)-1 && ci->i_snap_realm->ino != realmino)) { in ceph_add_cap()
724 * add this inode to the appropriate snap realm in ceph_add_cap()
726 struct ceph_snap_realm *realm = ceph_lookup_snap_realm(mdsc, in ceph_add_cap() local
728 if (realm) in ceph_add_cap()
729 ceph_change_snap_realm(inode, realm); in ceph_add_cap()
731 WARN(1, "%s: couldn't find snap realm 0x%llx (ino 0x%llx oldrealm 0x%llx)\n", in ceph_add_cap()
732 __func__, realmino, ci->i_vino.ino, in ceph_add_cap()
733 ci->i_snap_realm ? ci->i_snap_realm->ino : 0); in ceph_add_cap()
753 if (!ci->i_auth_cap || in ceph_add_cap()
754 ceph_seq_cmp(ci->i_auth_cap->mseq, mseq) < 0) { in ceph_add_cap()
755 if (ci->i_auth_cap && in ceph_add_cap()
756 ci->i_auth_cap->session != cap->session) in ceph_add_cap()
757 change_auth_cap_ses(ci, cap->session); in ceph_add_cap()
758 ci->i_auth_cap = cap; in ceph_add_cap()
759 cap->mds_wanted = wanted; in ceph_add_cap()
762 WARN_ON(ci->i_auth_cap == cap); in ceph_add_cap()
767 ceph_cap_string(issued|cap->issued), seq, mds); in ceph_add_cap()
768 cap->cap_id = cap_id; in ceph_add_cap()
769 cap->issued = issued; in ceph_add_cap()
770 cap->implemented |= issued; in ceph_add_cap()
771 if (ceph_seq_cmp(mseq, cap->mseq) > 0) in ceph_add_cap()
772 cap->mds_wanted = wanted; in ceph_add_cap()
774 cap->mds_wanted |= wanted; in ceph_add_cap()
775 cap->seq = seq; in ceph_add_cap()
776 cap->issue_seq = seq; in ceph_add_cap()
777 cap->mseq = mseq; in ceph_add_cap()
778 cap->cap_gen = gen; in ceph_add_cap()
779 wake_up_all(&ci->i_cap_wq); in ceph_add_cap()
789 struct inode *inode = &cap->ci->netfs.inode; in __cap_is_valid()
790 struct ceph_client *cl = cap->session->s_mdsc->fsc->client; in __cap_is_valid()
794 gen = atomic_read(&cap->session->s_cap_gen); in __cap_is_valid()
795 ttl = cap->session->s_cap_ttl; in __cap_is_valid()
797 if (cap->cap_gen < gen || time_after_eq(jiffies, ttl)) { in __cap_is_valid()
800 ceph_cap_string(cap->issued), cap->cap_gen, gen); in __cap_is_valid()
810 * and session->s_cap_gen is bumped.
814 struct inode *inode = &ci->netfs.inode; in __ceph_caps_issued()
816 int have = ci->i_snap_caps; in __ceph_caps_issued()
822 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued()
827 ceph_vinop(inode), cap, ceph_cap_string(cap->issued)); in __ceph_caps_issued()
828 have |= cap->issued; in __ceph_caps_issued()
830 *implemented |= cap->implemented; in __ceph_caps_issued()
833 * exclude caps issued by non-auth MDS, but are been revoking in __ceph_caps_issued()
834 * by the auth MDS. The non-auth MDS should be revoking/exporting in __ceph_caps_issued()
837 if (ci->i_auth_cap) { in __ceph_caps_issued()
838 cap = ci->i_auth_cap; in __ceph_caps_issued()
839 have &= ~cap->implemented | cap->issued; in __ceph_caps_issued()
849 int have = ci->i_snap_caps; in __ceph_caps_issued_other()
853 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued_other()
859 have |= cap->issued; in __ceph_caps_issued_other()
870 struct inode *inode = &cap->ci->netfs.inode; in __touch_cap()
871 struct ceph_mds_session *s = cap->session; in __touch_cap()
872 struct ceph_client *cl = s->s_mdsc->fsc->client; in __touch_cap()
874 spin_lock(&s->s_cap_lock); in __touch_cap()
875 if (!s->s_cap_iterator) { in __touch_cap()
877 ceph_vinop(inode), cap, s->s_mds); in __touch_cap()
878 list_move_tail(&cap->session_caps, &s->s_caps); in __touch_cap()
881 inode, ceph_vinop(inode), cap, s->s_mds); in __touch_cap()
883 spin_unlock(&s->s_cap_lock); in __touch_cap()
893 struct inode *inode = &ci->netfs.inode; in __ceph_caps_issued_mask()
897 int have = ci->i_snap_caps; in __ceph_caps_issued_mask()
906 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued_mask()
910 if ((cap->issued & mask) == mask) { in __ceph_caps_issued_mask()
913 ceph_cap_string(cap->issued), in __ceph_caps_issued_mask()
921 have |= cap->issued; in __ceph_caps_issued_mask()
925 ceph_cap_string(cap->issued), in __ceph_caps_issued_mask()
932 for (q = rb_first(&ci->i_caps); q != p; in __ceph_caps_issued_mask()
938 if (cap->issued & mask) in __ceph_caps_issued_mask()
952 struct ceph_fs_client *fsc = ceph_sb_to_fs_client(ci->netfs.inode.i_sb); in __ceph_caps_issued_mask_metric()
957 ceph_update_cap_hit(&fsc->mdsc->metric); in __ceph_caps_issued_mask_metric()
959 ceph_update_cap_mis(&fsc->mdsc->metric); in __ceph_caps_issued_mask_metric()
972 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_revoking_other()
975 (cap->implemented & ~cap->issued & mask)) in __ceph_caps_revoking_other()
984 if (ci->i_pin_ref) in __ceph_caps_used()
986 if (ci->i_rd_ref) in __ceph_caps_used()
988 if (ci->i_rdcache_ref || in __ceph_caps_used()
989 (S_ISREG(ci->netfs.inode.i_mode) && in __ceph_caps_used()
990 ci->netfs.inode.i_data.nrpages)) in __ceph_caps_used()
992 if (ci->i_wr_ref) in __ceph_caps_used()
994 if (ci->i_wb_ref || ci->i_wrbuffer_ref) in __ceph_caps_used()
996 if (ci->i_fx_ref) in __ceph_caps_used()
1013 ceph_inode_to_fs_client(&ci->netfs.inode)->mount_options; in __ceph_caps_file_wanted()
1014 unsigned long used_cutoff = jiffies - opt->caps_wanted_delay_max * HZ; in __ceph_caps_file_wanted()
1015 unsigned long idle_cutoff = jiffies - opt->caps_wanted_delay_min * HZ; in __ceph_caps_file_wanted()
1017 if (S_ISDIR(ci->netfs.inode.i_mode)) { in __ceph_caps_file_wanted()
1021 if (ci->i_nr_by_mode[RD_SHIFT] > 0 || in __ceph_caps_file_wanted()
1022 time_after(ci->i_last_rd, used_cutoff)) in __ceph_caps_file_wanted()
1025 if (ci->i_nr_by_mode[WR_SHIFT] > 0 || in __ceph_caps_file_wanted()
1026 time_after(ci->i_last_wr, used_cutoff)) { in __ceph_caps_file_wanted()
1028 if (opt->flags & CEPH_MOUNT_OPT_ASYNC_DIROPS) in __ceph_caps_file_wanted()
1032 if (want || ci->i_nr_by_mode[PIN_SHIFT] > 0) in __ceph_caps_file_wanted()
1039 if (ci->i_nr_by_mode[RD_SHIFT] > 0) { in __ceph_caps_file_wanted()
1040 if (ci->i_nr_by_mode[RD_SHIFT] >= FMODE_WAIT_BIAS || in __ceph_caps_file_wanted()
1041 time_after(ci->i_last_rd, used_cutoff)) in __ceph_caps_file_wanted()
1043 } else if (time_after(ci->i_last_rd, idle_cutoff)) { in __ceph_caps_file_wanted()
1047 if (ci->i_nr_by_mode[WR_SHIFT] > 0) { in __ceph_caps_file_wanted()
1048 if (ci->i_nr_by_mode[WR_SHIFT] >= FMODE_WAIT_BIAS || in __ceph_caps_file_wanted()
1049 time_after(ci->i_last_wr, used_cutoff)) in __ceph_caps_file_wanted()
1051 } else if (time_after(ci->i_last_wr, idle_cutoff)) { in __ceph_caps_file_wanted()
1057 ci->i_nr_by_mode[LAZY_SHIFT] > 0) in __ceph_caps_file_wanted()
1070 if (S_ISDIR(ci->netfs.inode.i_mode)) { in __ceph_caps_wanted()
1091 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_mds_wanted()
1095 if (cap == ci->i_auth_cap) in __ceph_caps_mds_wanted()
1096 mds_wanted |= cap->mds_wanted; in __ceph_caps_mds_wanted()
1098 mds_wanted |= (cap->mds_wanted & ~CEPH_CAP_ANY_FILE_WR); in __ceph_caps_mds_wanted()
1108 spin_lock(&ci->i_ceph_lock); in ceph_is_any_caps()
1110 spin_unlock(&ci->i_ceph_lock); in ceph_is_any_caps()
1123 struct ceph_mds_session *session = cap->session; in __ceph_remove_cap()
1124 struct ceph_client *cl = session->s_mdsc->fsc->client; in __ceph_remove_cap()
1125 struct ceph_inode_info *ci = cap->ci; in __ceph_remove_cap()
1126 struct inode *inode = &ci->netfs.inode; in __ceph_remove_cap()
1136 lockdep_assert_held(&ci->i_ceph_lock); in __ceph_remove_cap()
1140 mdsc = ceph_inode_to_fs_client(&ci->netfs.inode)->mdsc; in __ceph_remove_cap()
1143 rb_erase(&cap->ci_node, &ci->i_caps); in __ceph_remove_cap()
1144 if (ci->i_auth_cap == cap) in __ceph_remove_cap()
1145 ci->i_auth_cap = NULL; in __ceph_remove_cap()
1148 spin_lock(&session->s_cap_lock); in __ceph_remove_cap()
1149 if (session->s_cap_iterator == cap) { in __ceph_remove_cap()
1152 cap->session); in __ceph_remove_cap()
1154 list_del_init(&cap->session_caps); in __ceph_remove_cap()
1155 session->s_nr_caps--; in __ceph_remove_cap()
1156 atomic64_dec(&mdsc->metric.total_caps); in __ceph_remove_cap()
1157 cap->session = NULL; in __ceph_remove_cap()
1161 cap->ci = NULL; in __ceph_remove_cap()
1168 (!session->s_cap_reconnect || in __ceph_remove_cap()
1169 cap->cap_gen == atomic_read(&session->s_cap_gen))) { in __ceph_remove_cap()
1170 cap->queue_release = 1; in __ceph_remove_cap()
1176 cap->queue_release = 0; in __ceph_remove_cap()
1178 cap->cap_ino = ci->i_vino.ino; in __ceph_remove_cap()
1180 spin_unlock(&session->s_cap_lock); in __ceph_remove_cap()
1187 * i_wr_ref can be non-zero. If there are ongoing write, in __ceph_remove_cap()
1190 if (ci->i_wr_ref == 0 && ci->i_snap_realm) in __ceph_remove_cap()
1191 ceph_change_snap_realm(&ci->netfs.inode, NULL); in __ceph_remove_cap()
1200 struct ceph_inode_info *ci = cap->ci; in ceph_remove_cap()
1205 doutc(mdsc->fsc->client, "inode is NULL\n"); in ceph_remove_cap()
1209 lockdep_assert_held(&ci->i_ceph_lock); in ceph_remove_cap()
1211 fsc = ceph_inode_to_fs_client(&ci->netfs.inode); in ceph_remove_cap()
1212 WARN_ON_ONCE(ci->i_auth_cap == cap && in ceph_remove_cap()
1213 !list_empty(&ci->i_dirty_item) && in ceph_remove_cap()
1214 !fsc->blocklisted && in ceph_remove_cap()
1215 !ceph_inode_is_shutdown(&ci->netfs.inode)); in ceph_remove_cap()
1247 struct ceph_mds_client *mdsc = arg->session->s_mdsc; in encode_cap_msg()
1248 struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc; in encode_cap_msg()
1250 doutc(mdsc->fsc->client, in encode_cap_msg()
1254 ceph_cap_op_name(arg->op), arg->cid, arg->ino, in encode_cap_msg()
1255 ceph_cap_string(arg->caps), ceph_cap_string(arg->wanted), in encode_cap_msg()
1256 ceph_cap_string(arg->dirty), arg->seq, arg->issue_seq, in encode_cap_msg()
1257 arg->flush_tid, arg->oldest_flush_tid, arg->mseq, arg->follows, in encode_cap_msg()
1258 arg->size, arg->max_size, arg->xattr_version, in encode_cap_msg()
1259 arg->xattr_buf ? (int)arg->xattr_buf->vec.iov_len : 0); in encode_cap_msg()
1261 msg->hdr.version = cpu_to_le16(12); in encode_cap_msg()
1262 msg->hdr.tid = cpu_to_le64(arg->flush_tid); in encode_cap_msg()
1264 fc = msg->front.iov_base; in encode_cap_msg()
1267 fc->cap_id = cpu_to_le64(arg->cid); in encode_cap_msg()
1268 fc->op = cpu_to_le32(arg->op); in encode_cap_msg()
1269 fc->seq = cpu_to_le32(arg->seq); in encode_cap_msg()
1270 fc->issue_seq = cpu_to_le32(arg->issue_seq); in encode_cap_msg()
1271 fc->migrate_seq = cpu_to_le32(arg->mseq); in encode_cap_msg()
1272 fc->caps = cpu_to_le32(arg->caps); in encode_cap_msg()
1273 fc->wanted = cpu_to_le32(arg->wanted); in encode_cap_msg()
1274 fc->dirty = cpu_to_le32(arg->dirty); in encode_cap_msg()
1275 fc->ino = cpu_to_le64(arg->ino); in encode_cap_msg()
1276 fc->snap_follows = cpu_to_le64(arg->follows); in encode_cap_msg()
1279 if (arg->encrypted) in encode_cap_msg()
1280 fc->size = cpu_to_le64(round_up(arg->size, in encode_cap_msg()
1284 fc->size = cpu_to_le64(arg->size); in encode_cap_msg()
1285 fc->max_size = cpu_to_le64(arg->max_size); in encode_cap_msg()
1286 ceph_encode_timespec64(&fc->mtime, &arg->mtime); in encode_cap_msg()
1287 ceph_encode_timespec64(&fc->atime, &arg->atime); in encode_cap_msg()
1288 ceph_encode_timespec64(&fc->ctime, &arg->ctime); in encode_cap_msg()
1289 fc->time_warp_seq = cpu_to_le32(arg->time_warp_seq); in encode_cap_msg()
1291 fc->uid = cpu_to_le32(from_kuid(&init_user_ns, arg->uid)); in encode_cap_msg()
1292 fc->gid = cpu_to_le32(from_kgid(&init_user_ns, arg->gid)); in encode_cap_msg()
1293 fc->mode = cpu_to_le32(arg->mode); in encode_cap_msg()
1295 fc->xattr_version = cpu_to_le64(arg->xattr_version); in encode_cap_msg()
1296 if (arg->xattr_buf) { in encode_cap_msg()
1297 msg->middle = ceph_buffer_get(arg->xattr_buf); in encode_cap_msg()
1298 fc->xattr_len = cpu_to_le32(arg->xattr_buf->vec.iov_len); in encode_cap_msg()
1299 msg->hdr.middle_len = cpu_to_le32(arg->xattr_buf->vec.iov_len); in encode_cap_msg()
1306 ceph_encode_64(&p, arg->inline_data ? 0 : CEPH_INLINE_NONE); in encode_cap_msg()
1311 * The epoch_barrier is protected osdc->lock, so READ_ONCE here in in encode_cap_msg()
1314 ceph_encode_32(&p, READ_ONCE(osdc->epoch_barrier)); in encode_cap_msg()
1316 ceph_encode_64(&p, arg->oldest_flush_tid); in encode_cap_msg()
1332 ceph_encode_timespec64(p, &arg->btime); in encode_cap_msg()
1334 ceph_encode_64(&p, arg->change_attr); in encode_cap_msg()
1337 ceph_encode_32(&p, arg->flags); in encode_cap_msg()
1339 /* dirstats (version 11) - these are r/o on the client */ in encode_cap_msg()
1348 * tracks the real i_size as an __le64 field (and we use a rounded-up in encode_cap_msg()
1351 ceph_encode_32(&p, arg->fscrypt_auth_len); in encode_cap_msg()
1352 ceph_encode_copy(&p, arg->fscrypt_auth, arg->fscrypt_auth_len); in encode_cap_msg()
1354 ceph_encode_64(&p, arg->size); in encode_cap_msg()
1366 struct inode *inode = &ci->netfs.inode; in __ceph_remove_caps()
1367 struct ceph_mds_client *mdsc = ceph_inode_to_fs_client(inode)->mdsc; in __ceph_remove_caps()
1372 spin_lock(&ci->i_ceph_lock); in __ceph_remove_caps()
1373 p = rb_first(&ci->i_caps); in __ceph_remove_caps()
1379 spin_unlock(&ci->i_ceph_lock); in __ceph_remove_caps()
1394 struct ceph_inode_info *ci = cap->ci; in __prep_cap()
1395 struct inode *inode = &ci->netfs.inode; in __prep_cap()
1399 lockdep_assert_held(&ci->i_ceph_lock); in __prep_cap()
1401 held = cap->issued | cap->implemented; in __prep_cap()
1402 revoking = cap->implemented & ~cap->issued; in __prep_cap()
1405 doutc(cl, "%p %llx.%llx cap %p session %p %s -> %s (revoking %s)\n", in __prep_cap()
1406 inode, ceph_vinop(inode), cap, cap->session, in __prep_cap()
1411 ci->i_ceph_flags &= ~CEPH_I_FLUSH; in __prep_cap()
1413 cap->issued &= retain; /* drop bits we don't want */ in __prep_cap()
1415 * Wake up any waiters on wanted -> needed transition. This is due to in __prep_cap()
1419 arg->wake = cap->implemented & ~cap->issued; in __prep_cap()
1420 cap->implemented &= cap->issued | used; in __prep_cap()
1421 cap->mds_wanted = want; in __prep_cap()
1423 arg->session = cap->session; in __prep_cap()
1424 arg->ino = ceph_vino(inode).ino; in __prep_cap()
1425 arg->cid = cap->cap_id; in __prep_cap()
1426 arg->follows = flushing ? ci->i_head_snapc->seq : 0; in __prep_cap()
1427 arg->flush_tid = flush_tid; in __prep_cap()
1428 arg->oldest_flush_tid = oldest_flush_tid; in __prep_cap()
1429 arg->size = i_size_read(inode); in __prep_cap()
1430 ci->i_reported_size = arg->size; in __prep_cap()
1431 arg->max_size = ci->i_wanted_max_size; in __prep_cap()
1432 if (cap == ci->i_auth_cap) { in __prep_cap()
1434 ci->i_requested_max_size = arg->max_size; in __prep_cap()
1436 ci->i_requested_max_size = 0; in __prep_cap()
1440 arg->old_xattr_buf = __ceph_build_xattrs_blob(ci); in __prep_cap()
1441 arg->xattr_version = ci->i_xattrs.version; in __prep_cap()
1442 arg->xattr_buf = ceph_buffer_get(ci->i_xattrs.blob); in __prep_cap()
1444 arg->xattr_buf = NULL; in __prep_cap()
1445 arg->old_xattr_buf = NULL; in __prep_cap()
1448 arg->mtime = inode_get_mtime(inode); in __prep_cap()
1449 arg->atime = inode_get_atime(inode); in __prep_cap()
1450 arg->ctime = inode_get_ctime(inode); in __prep_cap()
1451 arg->btime = ci->i_btime; in __prep_cap()
1452 arg->change_attr = inode_peek_iversion_raw(inode); in __prep_cap()
1454 arg->op = op; in __prep_cap()
1455 arg->caps = cap->implemented; in __prep_cap()
1456 arg->wanted = want; in __prep_cap()
1457 arg->dirty = flushing; in __prep_cap()
1459 arg->seq = cap->seq; in __prep_cap()
1460 arg->issue_seq = cap->issue_seq; in __prep_cap()
1461 arg->mseq = cap->mseq; in __prep_cap()
1462 arg->time_warp_seq = ci->i_time_warp_seq; in __prep_cap()
1464 arg->uid = inode->i_uid; in __prep_cap()
1465 arg->gid = inode->i_gid; in __prep_cap()
1466 arg->mode = inode->i_mode; in __prep_cap()
1468 arg->inline_data = ci->i_inline_version != CEPH_INLINE_NONE; in __prep_cap()
1470 !list_empty(&ci->i_cap_snaps)) { in __prep_cap()
1472 list_for_each_entry_reverse(capsnap, &ci->i_cap_snaps, ci_item) { in __prep_cap()
1473 if (capsnap->cap_flush.tid) in __prep_cap()
1475 if (capsnap->need_flush) { in __prep_cap()
1481 arg->flags = flags; in __prep_cap()
1482 arg->encrypted = IS_ENCRYPTED(inode); in __prep_cap()
1484 if (ci->fscrypt_auth_len && in __prep_cap()
1485 WARN_ON_ONCE(ci->fscrypt_auth_len > sizeof(struct ceph_fscrypt_auth))) { in __prep_cap()
1487 arg->fscrypt_auth_len = 0; in __prep_cap()
1489 arg->fscrypt_auth_len = ci->fscrypt_auth_len; in __prep_cap()
1490 memcpy(arg->fscrypt_auth, ci->fscrypt_auth, in __prep_cap()
1491 min_t(size_t, ci->fscrypt_auth_len, in __prep_cap()
1492 sizeof(arg->fscrypt_auth))); in __prep_cap()
1503 return CAP_MSG_FIXED_FIELDS + arg->fscrypt_auth_len; in cap_msg_size()
1523 struct inode *inode = &ci->netfs.inode; in __send_cap()
1532 ceph_vinop(inode), ceph_cap_string(arg->dirty), in __send_cap()
1533 arg->flush_tid); in __send_cap()
1534 spin_lock(&ci->i_ceph_lock); in __send_cap()
1535 __cap_delay_requeue(arg->session->s_mdsc, ci); in __send_cap()
1536 spin_unlock(&ci->i_ceph_lock); in __send_cap()
1541 ceph_con_send(&arg->session->s_con, msg); in __send_cap()
1542 ceph_buffer_put(arg->old_xattr_buf); in __send_cap()
1543 ceph_buffer_put(arg->xattr_buf); in __send_cap()
1544 if (arg->wake) in __send_cap()
1545 wake_up_all(&ci->i_cap_wq); in __send_cap()
1559 arg.follows = capsnap->follows; in __send_flush_snap()
1560 arg.flush_tid = capsnap->cap_flush.tid; in __send_flush_snap()
1563 arg.size = capsnap->size; in __send_flush_snap()
1565 arg.xattr_version = capsnap->xattr_version; in __send_flush_snap()
1566 arg.xattr_buf = capsnap->xattr_blob; in __send_flush_snap()
1569 arg.atime = capsnap->atime; in __send_flush_snap()
1570 arg.mtime = capsnap->mtime; in __send_flush_snap()
1571 arg.ctime = capsnap->ctime; in __send_flush_snap()
1572 arg.btime = capsnap->btime; in __send_flush_snap()
1573 arg.change_attr = capsnap->change_attr; in __send_flush_snap()
1576 arg.caps = capsnap->issued; in __send_flush_snap()
1578 arg.dirty = capsnap->dirty; in __send_flush_snap()
1583 arg.time_warp_seq = capsnap->time_warp_seq; in __send_flush_snap()
1585 arg.uid = capsnap->uid; in __send_flush_snap()
1586 arg.gid = capsnap->gid; in __send_flush_snap()
1587 arg.mode = capsnap->mode; in __send_flush_snap()
1589 arg.inline_data = capsnap->inline_data; in __send_flush_snap()
1600 return -ENOMEM; in __send_flush_snap()
1603 ceph_con_send(&arg.session->s_con, msg); in __send_flush_snap()
1618 __releases(ci->i_ceph_lock) in __ceph_flush_snaps()
1619 __acquires(ci->i_ceph_lock) in __ceph_flush_snaps()
1621 struct inode *inode = &ci->netfs.inode; in __ceph_flush_snaps()
1622 struct ceph_mds_client *mdsc = session->s_mdsc; in __ceph_flush_snaps()
1623 struct ceph_client *cl = mdsc->fsc->client; in __ceph_flush_snaps()
1631 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { in __ceph_flush_snaps()
1636 if (capsnap->dirty_pages || capsnap->writing) in __ceph_flush_snaps()
1640 BUG_ON(!capsnap->need_flush); in __ceph_flush_snaps()
1643 if (capsnap->cap_flush.tid > 0) { in __ceph_flush_snaps()
1648 spin_lock(&mdsc->cap_dirty_lock); in __ceph_flush_snaps()
1649 capsnap->cap_flush.tid = ++mdsc->last_cap_flush_tid; in __ceph_flush_snaps()
1650 list_add_tail(&capsnap->cap_flush.g_list, in __ceph_flush_snaps()
1651 &mdsc->cap_flush_list); in __ceph_flush_snaps()
1654 if (list_empty(&ci->i_flushing_item)) { in __ceph_flush_snaps()
1655 list_add_tail(&ci->i_flushing_item, in __ceph_flush_snaps()
1656 &session->s_cap_flushing); in __ceph_flush_snaps()
1658 spin_unlock(&mdsc->cap_dirty_lock); in __ceph_flush_snaps()
1660 list_add_tail(&capsnap->cap_flush.i_list, in __ceph_flush_snaps()
1661 &ci->i_cap_flush_list); in __ceph_flush_snaps()
1664 first_tid = capsnap->cap_flush.tid; in __ceph_flush_snaps()
1665 last_tid = capsnap->cap_flush.tid; in __ceph_flush_snaps()
1668 ci->i_ceph_flags &= ~CEPH_I_FLUSH_SNAPS; in __ceph_flush_snaps()
1671 struct ceph_cap *cap = ci->i_auth_cap; in __ceph_flush_snaps()
1675 if (!(cap && cap->session == session)) { in __ceph_flush_snaps()
1677 inode, ceph_vinop(inode), cap, session->s_mds); in __ceph_flush_snaps()
1681 ret = -ENOENT; in __ceph_flush_snaps()
1682 list_for_each_entry(iter, &ci->i_cap_flush_list, i_list) { in __ceph_flush_snaps()
1683 if (iter->tid >= first_tid) { in __ceph_flush_snaps()
1692 first_tid = cf->tid + 1; in __ceph_flush_snaps()
1695 refcount_inc(&capsnap->nref); in __ceph_flush_snaps()
1696 spin_unlock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1699 ceph_vinop(inode), capsnap, cf->tid, in __ceph_flush_snaps()
1700 ceph_cap_string(capsnap->dirty)); in __ceph_flush_snaps()
1702 ret = __send_flush_snap(inode, session, capsnap, cap->mseq, in __ceph_flush_snaps()
1707 ceph_vinop(inode), cf->tid, in __ceph_flush_snaps()
1708 capsnap->follows); in __ceph_flush_snaps()
1712 spin_lock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1719 struct inode *inode = &ci->netfs.inode; in ceph_flush_snaps()
1720 struct ceph_mds_client *mdsc = ceph_inode_to_fs_client(inode)->mdsc; in ceph_flush_snaps()
1730 spin_lock(&ci->i_ceph_lock); in ceph_flush_snaps()
1731 if (!(ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)) { in ceph_flush_snaps()
1735 if (!ci->i_auth_cap) { in ceph_flush_snaps()
1740 mds = ci->i_auth_cap->session->s_mds; in ceph_flush_snaps()
1741 if (session && session->s_mds != mds) { in ceph_flush_snaps()
1747 spin_unlock(&ci->i_ceph_lock); in ceph_flush_snaps()
1748 mutex_lock(&mdsc->mutex); in ceph_flush_snaps()
1750 mutex_unlock(&mdsc->mutex); in ceph_flush_snaps()
1755 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) in ceph_flush_snaps()
1760 spin_unlock(&ci->i_ceph_lock); in ceph_flush_snaps()
1767 spin_lock(&mdsc->snap_flush_lock); in ceph_flush_snaps()
1768 if (!list_empty(&ci->i_snap_flush_item)) in ceph_flush_snaps()
1770 list_del_init(&ci->i_snap_flush_item); in ceph_flush_snaps()
1771 spin_unlock(&mdsc->snap_flush_lock); in ceph_flush_snaps()
1786 ceph_sb_to_fs_client(ci->netfs.inode.i_sb)->mdsc; in __ceph_mark_dirty_caps()
1787 struct inode *inode = &ci->netfs.inode; in __ceph_mark_dirty_caps()
1789 int was = ci->i_dirty_caps; in __ceph_mark_dirty_caps()
1792 lockdep_assert_held(&ci->i_ceph_lock); in __ceph_mark_dirty_caps()
1794 if (!ci->i_auth_cap) { in __ceph_mark_dirty_caps()
1802 doutc(cl, "%p %llx.%llx %s dirty %s -> %s\n", inode, in __ceph_mark_dirty_caps()
1805 ci->i_dirty_caps |= mask; in __ceph_mark_dirty_caps()
1807 struct ceph_mds_session *session = ci->i_auth_cap->session; in __ceph_mark_dirty_caps()
1809 WARN_ON_ONCE(ci->i_prealloc_cap_flush); in __ceph_mark_dirty_caps()
1810 swap(ci->i_prealloc_cap_flush, *pcf); in __ceph_mark_dirty_caps()
1812 if (!ci->i_head_snapc) { in __ceph_mark_dirty_caps()
1813 WARN_ON_ONCE(!rwsem_is_locked(&mdsc->snap_rwsem)); in __ceph_mark_dirty_caps()
1814 ci->i_head_snapc = ceph_get_snap_context( in __ceph_mark_dirty_caps()
1815 ci->i_snap_realm->cached_context); in __ceph_mark_dirty_caps()
1818 inode, ceph_vinop(inode), ci->i_head_snapc, in __ceph_mark_dirty_caps()
1819 ci->i_auth_cap); in __ceph_mark_dirty_caps()
1820 BUG_ON(!list_empty(&ci->i_dirty_item)); in __ceph_mark_dirty_caps()
1821 spin_lock(&mdsc->cap_dirty_lock); in __ceph_mark_dirty_caps()
1822 list_add(&ci->i_dirty_item, &session->s_cap_dirty); in __ceph_mark_dirty_caps()
1823 spin_unlock(&mdsc->cap_dirty_lock); in __ceph_mark_dirty_caps()
1824 if (ci->i_flushing_caps == 0) { in __ceph_mark_dirty_caps()
1829 WARN_ON_ONCE(!ci->i_prealloc_cap_flush); in __ceph_mark_dirty_caps()
1831 BUG_ON(list_empty(&ci->i_dirty_item)); in __ceph_mark_dirty_caps()
1832 if (((was | ci->i_flushing_caps) & CEPH_CAP_FILE_BUFFER) && in __ceph_mark_dirty_caps()
1847 cf->is_capsnap = false; in ceph_alloc_cap_flush()
1859 if (!list_empty(&mdsc->cap_flush_list)) { in __get_oldest_flush_tid()
1861 list_first_entry(&mdsc->cap_flush_list, in __get_oldest_flush_tid()
1863 return cf->tid; in __get_oldest_flush_tid()
1876 bool wake = cf->wake; in __detach_cap_flush_from_mdsc()
1878 if (wake && cf->g_list.prev != &mdsc->cap_flush_list) { in __detach_cap_flush_from_mdsc()
1880 prev->wake = true; in __detach_cap_flush_from_mdsc()
1883 list_del_init(&cf->g_list); in __detach_cap_flush_from_mdsc()
1891 bool wake = cf->wake; in __detach_cap_flush_from_ci()
1893 if (wake && cf->i_list.prev != &ci->i_cap_flush_list) { in __detach_cap_flush_from_ci()
1895 prev->wake = true; in __detach_cap_flush_from_ci()
1898 list_del_init(&cf->i_list); in __detach_cap_flush_from_ci()
1912 struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc; in __mark_caps_flushing()
1918 lockdep_assert_held(&ci->i_ceph_lock); in __mark_caps_flushing()
1919 BUG_ON(ci->i_dirty_caps == 0); in __mark_caps_flushing()
1920 BUG_ON(list_empty(&ci->i_dirty_item)); in __mark_caps_flushing()
1921 BUG_ON(!ci->i_prealloc_cap_flush); in __mark_caps_flushing()
1923 flushing = ci->i_dirty_caps; in __mark_caps_flushing()
1924 doutc(cl, "flushing %s, flushing_caps %s -> %s\n", in __mark_caps_flushing()
1926 ceph_cap_string(ci->i_flushing_caps), in __mark_caps_flushing()
1927 ceph_cap_string(ci->i_flushing_caps | flushing)); in __mark_caps_flushing()
1928 ci->i_flushing_caps |= flushing; in __mark_caps_flushing()
1929 ci->i_dirty_caps = 0; in __mark_caps_flushing()
1932 swap(cf, ci->i_prealloc_cap_flush); in __mark_caps_flushing()
1933 cf->caps = flushing; in __mark_caps_flushing()
1934 cf->wake = wake; in __mark_caps_flushing()
1936 spin_lock(&mdsc->cap_dirty_lock); in __mark_caps_flushing()
1937 list_del_init(&ci->i_dirty_item); in __mark_caps_flushing()
1939 cf->tid = ++mdsc->last_cap_flush_tid; in __mark_caps_flushing()
1940 list_add_tail(&cf->g_list, &mdsc->cap_flush_list); in __mark_caps_flushing()
1943 if (list_empty(&ci->i_flushing_item)) { in __mark_caps_flushing()
1944 list_add_tail(&ci->i_flushing_item, &session->s_cap_flushing); in __mark_caps_flushing()
1945 mdsc->num_cap_flushing++; in __mark_caps_flushing()
1947 spin_unlock(&mdsc->cap_dirty_lock); in __mark_caps_flushing()
1949 list_add_tail(&cf->i_list, &ci->i_cap_flush_list); in __mark_caps_flushing()
1951 return cf->tid; in __mark_caps_flushing()
1958 __releases(ci->i_ceph_lock) in try_nonblocking_invalidate()
1959 __acquires(ci->i_ceph_lock) in try_nonblocking_invalidate()
1963 u32 invalidating_gen = ci->i_rdcache_gen; in try_nonblocking_invalidate()
1965 spin_unlock(&ci->i_ceph_lock); in try_nonblocking_invalidate()
1967 invalidate_mapping_pages(&inode->i_data, 0, -1); in try_nonblocking_invalidate()
1968 spin_lock(&ci->i_ceph_lock); in try_nonblocking_invalidate()
1970 if (inode->i_data.nrpages == 0 && in try_nonblocking_invalidate()
1971 invalidating_gen == ci->i_rdcache_gen) { in try_nonblocking_invalidate()
1976 ci->i_rdcache_revoking = ci->i_rdcache_gen - 1; in try_nonblocking_invalidate()
1980 return -1; in try_nonblocking_invalidate()
1985 loff_t size = i_size_read(&ci->netfs.inode); in __ceph_should_report_size()
1987 if (ci->i_flushing_caps & CEPH_CAP_FILE_WR) in __ceph_should_report_size()
1989 if (size >= ci->i_max_size) in __ceph_should_report_size()
1992 if (ci->i_max_size > ci->i_reported_size && in __ceph_should_report_size()
1993 (size << 1) >= ci->i_max_size + ci->i_reported_size) in __ceph_should_report_size()
2003 * CHECK_CAPS_AUTHONLY - we should only check the auth cap
2004 * CHECK_CAPS_FLUSH - we should flush any dirty caps immediately, without
2006 * CHECK_CAPS_FLUSH_FORCE - we should flush any caps immediately, without
2011 struct inode *inode = &ci->netfs.inode; in ceph_check_caps()
2012 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb); in ceph_check_caps()
2018 int mds = -1; /* keep track of how far we've gone through i_caps list in ceph_check_caps()
2026 spin_lock(&ci->i_ceph_lock); in ceph_check_caps()
2027 if (ci->i_ceph_flags & CEPH_I_ASYNC_CREATE) { in ceph_check_caps()
2028 ci->i_ceph_flags |= CEPH_I_ASYNC_CHECK_CAPS; in ceph_check_caps()
2031 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
2035 if (ci->i_ceph_flags & CEPH_I_FLUSH) in ceph_check_caps()
2057 if (!mdsc->stopping && inode->i_nlink > 0) { in ceph_check_caps()
2060 } else if (S_ISDIR(inode->i_mode) && in ceph_check_caps()
2083 if (ci->i_max_size == 0) in ceph_check_caps()
2091 ceph_cap_string(used), ceph_cap_string(ci->i_dirty_caps), in ceph_check_caps()
2092 ceph_cap_string(ci->i_flushing_caps), in ceph_check_caps()
2105 if ((!(flags & CHECK_CAPS_NOINVAL) || mdsc->stopping) && in ceph_check_caps()
2106 S_ISREG(inode->i_mode) && in ceph_check_caps()
2107 !(ci->i_wb_ref || ci->i_wrbuffer_ref) && /* no dirty pages... */ in ceph_check_caps()
2108 inode->i_data.nrpages && /* have cached pages */ in ceph_check_caps()
2117 ci->i_rdcache_revoking = ci->i_rdcache_gen; in ceph_check_caps()
2123 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in ceph_check_caps()
2130 if (mds >= cap->mds || in ceph_check_caps()
2131 ((flags & CHECK_CAPS_AUTHONLY) && cap != ci->i_auth_cap)) in ceph_check_caps()
2139 if (ci->i_auth_cap && cap != ci->i_auth_cap) in ceph_check_caps()
2140 cap_used &= ~ci->i_auth_cap->issued; in ceph_check_caps()
2142 revoking = cap->implemented & ~cap->issued; in ceph_check_caps()
2144 cap->mds, cap, ceph_cap_string(cap_used), in ceph_check_caps()
2145 ceph_cap_string(cap->issued), in ceph_check_caps()
2146 ceph_cap_string(cap->implemented), in ceph_check_caps()
2153 ceph_cap_string(cap->implemented & ~cap->issued)); in ceph_check_caps()
2168 if (S_ISREG(inode->i_mode) && ci->i_wrbuffer_ref && in ceph_check_caps()
2178 if (cap == ci->i_auth_cap && in ceph_check_caps()
2179 (cap->issued & CEPH_CAP_FILE_WR)) { in ceph_check_caps()
2181 if (ci->i_wanted_max_size > ci->i_max_size && in ceph_check_caps()
2182 ci->i_wanted_max_size > ci->i_requested_max_size) { in ceph_check_caps()
2194 if (cap == ci->i_auth_cap) { in ceph_check_caps()
2195 if ((flags & CHECK_CAPS_FLUSH) && ci->i_dirty_caps) { in ceph_check_caps()
2199 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) { in ceph_check_caps()
2206 if (want & ~cap->mds_wanted) { in ceph_check_caps()
2207 if (want & ~(cap->mds_wanted | cap->issued)) in ceph_check_caps()
2214 if ((cap->issued & ~retain) == 0) in ceph_check_caps()
2219 session = ceph_get_mds_session(cap->session); in ceph_check_caps()
2223 if (cap == ci->i_auth_cap && in ceph_check_caps()
2224 (ci->i_ceph_flags & in ceph_check_caps()
2226 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) in ceph_check_caps()
2228 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) in ceph_check_caps()
2234 if (cap == ci->i_auth_cap && ci->i_dirty_caps) { in ceph_check_caps()
2235 flushing = ci->i_dirty_caps; in ceph_check_caps()
2239 list_empty(&session->s_cap_dirty)) in ceph_check_caps()
2244 spin_lock(&mdsc->cap_dirty_lock); in ceph_check_caps()
2246 spin_unlock(&mdsc->cap_dirty_lock); in ceph_check_caps()
2249 mds = cap->mds; /* remember mds, so we don't repeat */ in ceph_check_caps()
2254 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
2256 spin_lock(&ci->i_ceph_lock); in ceph_check_caps()
2261 /* periodically re-calculate caps wanted by open files */ in ceph_check_caps()
2263 list_empty(&ci->i_cap_delay_list) && in ceph_check_caps()
2269 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
2283 struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc; in try_flush_caps()
2288 spin_lock(&ci->i_ceph_lock); in try_flush_caps()
2290 if (ci->i_dirty_caps && ci->i_auth_cap) { in try_flush_caps()
2291 struct ceph_cap *cap = ci->i_auth_cap; in try_flush_caps()
2293 struct ceph_mds_session *session = cap->session; in try_flush_caps()
2295 if (session->s_state < CEPH_MDS_SESSION_OPEN) { in try_flush_caps()
2296 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2300 if (ci->i_ceph_flags & in try_flush_caps()
2302 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) in try_flush_caps()
2304 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) in try_flush_caps()
2309 flushing = ci->i_dirty_caps; in try_flush_caps()
2315 (cap->issued | cap->implemented), in try_flush_caps()
2317 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2321 if (!list_empty(&ci->i_cap_flush_list)) { in try_flush_caps()
2323 list_last_entry(&ci->i_cap_flush_list, in try_flush_caps()
2325 cf->wake = true; in try_flush_caps()
2326 flush_tid = cf->tid; in try_flush_caps()
2328 flushing = ci->i_flushing_caps; in try_flush_caps()
2329 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2344 spin_lock(&ci->i_ceph_lock); in caps_are_flushed()
2345 if (!list_empty(&ci->i_cap_flush_list)) { in caps_are_flushed()
2347 list_first_entry(&ci->i_cap_flush_list, in caps_are_flushed()
2349 if (cf->tid <= flush_tid) in caps_are_flushed()
2352 spin_unlock(&ci->i_ceph_lock); in caps_are_flushed()
2361 struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc; in flush_mdlog_and_wait_inode_unsafe_requests()
2367 spin_lock(&ci->i_unsafe_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2368 if (S_ISDIR(inode->i_mode) && !list_empty(&ci->i_unsafe_dirops)) { in flush_mdlog_and_wait_inode_unsafe_requests()
2369 req1 = list_last_entry(&ci->i_unsafe_dirops, in flush_mdlog_and_wait_inode_unsafe_requests()
2374 if (!list_empty(&ci->i_unsafe_iops)) { in flush_mdlog_and_wait_inode_unsafe_requests()
2375 req2 = list_last_entry(&ci->i_unsafe_iops, in flush_mdlog_and_wait_inode_unsafe_requests()
2380 spin_unlock(&ci->i_unsafe_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2394 mutex_lock(&mdsc->mutex); in flush_mdlog_and_wait_inode_unsafe_requests()
2395 max_sessions = mdsc->max_sessions; in flush_mdlog_and_wait_inode_unsafe_requests()
2399 mutex_unlock(&mdsc->mutex); in flush_mdlog_and_wait_inode_unsafe_requests()
2400 err = -ENOMEM; in flush_mdlog_and_wait_inode_unsafe_requests()
2404 spin_lock(&ci->i_unsafe_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2406 list_for_each_entry(req, &ci->i_unsafe_dirops, in flush_mdlog_and_wait_inode_unsafe_requests()
2408 s = req->r_session; in flush_mdlog_and_wait_inode_unsafe_requests()
2411 if (!sessions[s->s_mds]) { in flush_mdlog_and_wait_inode_unsafe_requests()
2413 sessions[s->s_mds] = s; in flush_mdlog_and_wait_inode_unsafe_requests()
2418 list_for_each_entry(req, &ci->i_unsafe_iops, in flush_mdlog_and_wait_inode_unsafe_requests()
2420 s = req->r_session; in flush_mdlog_and_wait_inode_unsafe_requests()
2423 if (!sessions[s->s_mds]) { in flush_mdlog_and_wait_inode_unsafe_requests()
2425 sessions[s->s_mds] = s; in flush_mdlog_and_wait_inode_unsafe_requests()
2429 spin_unlock(&ci->i_unsafe_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2432 spin_lock(&ci->i_ceph_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2433 if (ci->i_auth_cap) { in flush_mdlog_and_wait_inode_unsafe_requests()
2434 s = ci->i_auth_cap->session; in flush_mdlog_and_wait_inode_unsafe_requests()
2435 if (!sessions[s->s_mds]) in flush_mdlog_and_wait_inode_unsafe_requests()
2436 sessions[s->s_mds] = ceph_get_mds_session(s); in flush_mdlog_and_wait_inode_unsafe_requests()
2438 spin_unlock(&ci->i_ceph_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2439 mutex_unlock(&mdsc->mutex); in flush_mdlog_and_wait_inode_unsafe_requests()
2453 ceph_vinop(inode), req1 ? req1->r_tid : 0ULL, in flush_mdlog_and_wait_inode_unsafe_requests()
2454 req2 ? req2->r_tid : 0ULL); in flush_mdlog_and_wait_inode_unsafe_requests()
2456 ret = !wait_for_completion_timeout(&req1->r_safe_completion, in flush_mdlog_and_wait_inode_unsafe_requests()
2457 ceph_timeout_jiffies(req1->r_timeout)); in flush_mdlog_and_wait_inode_unsafe_requests()
2459 err = -EIO; in flush_mdlog_and_wait_inode_unsafe_requests()
2462 ret = !wait_for_completion_timeout(&req2->r_safe_completion, in flush_mdlog_and_wait_inode_unsafe_requests()
2463 ceph_timeout_jiffies(req2->r_timeout)); in flush_mdlog_and_wait_inode_unsafe_requests()
2465 err = -EIO; in flush_mdlog_and_wait_inode_unsafe_requests()
2478 struct inode *inode = file->f_mapping->host; in ceph_fsync()
2502 * only wait on non-file metadata writeback (the mds in ceph_fsync()
2507 err = wait_event_interruptible(ci->i_cap_wq, in ceph_fsync()
2536 int wait = (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync); in ceph_write_inode()
2546 err = wait_event_interruptible(ci->i_cap_wq, in ceph_write_inode()
2550 ceph_sb_to_fs_client(inode->i_sb)->mdsc; in ceph_write_inode()
2552 spin_lock(&ci->i_ceph_lock); in ceph_write_inode()
2555 spin_unlock(&ci->i_ceph_lock); in ceph_write_inode()
2564 __releases(ci->i_ceph_lock) in __kick_flushing_caps()
2565 __acquires(ci->i_ceph_lock) in __kick_flushing_caps()
2567 struct inode *inode = &ci->netfs.inode; in __kick_flushing_caps()
2568 struct ceph_client *cl = mdsc->fsc->client; in __kick_flushing_caps()
2576 if (ci->i_ceph_flags & CEPH_I_ASYNC_CREATE) in __kick_flushing_caps()
2579 ci->i_ceph_flags &= ~CEPH_I_KICK_FLUSH; in __kick_flushing_caps()
2581 list_for_each_entry_reverse(cf, &ci->i_cap_flush_list, i_list) { in __kick_flushing_caps()
2582 if (cf->is_capsnap) { in __kick_flushing_caps()
2583 last_snap_flush = cf->tid; in __kick_flushing_caps()
2588 list_for_each_entry(cf, &ci->i_cap_flush_list, i_list) { in __kick_flushing_caps()
2589 if (cf->tid < first_tid) in __kick_flushing_caps()
2592 cap = ci->i_auth_cap; in __kick_flushing_caps()
2593 if (!(cap && cap->session == session)) { in __kick_flushing_caps()
2595 inode, cap, session->s_mds); in __kick_flushing_caps()
2599 first_tid = cf->tid + 1; in __kick_flushing_caps()
2601 if (!cf->is_capsnap) { in __kick_flushing_caps()
2605 inode, ceph_vinop(inode), cap, cf->tid, in __kick_flushing_caps()
2606 ceph_cap_string(cf->caps)); in __kick_flushing_caps()
2608 (cf->tid < last_snap_flush ? in __kick_flushing_caps()
2612 (cap->issued | cap->implemented), in __kick_flushing_caps()
2613 cf->caps, cf->tid, oldest_flush_tid); in __kick_flushing_caps()
2614 spin_unlock(&ci->i_ceph_lock); in __kick_flushing_caps()
2621 inode, ceph_vinop(inode), capsnap, cf->tid, in __kick_flushing_caps()
2622 ceph_cap_string(capsnap->dirty)); in __kick_flushing_caps()
2624 refcount_inc(&capsnap->nref); in __kick_flushing_caps()
2625 spin_unlock(&ci->i_ceph_lock); in __kick_flushing_caps()
2627 ret = __send_flush_snap(inode, session, capsnap, cap->mseq, in __kick_flushing_caps()
2632 inode, ceph_vinop(inode), cf->tid, in __kick_flushing_caps()
2633 capsnap->follows); in __kick_flushing_caps()
2639 spin_lock(&ci->i_ceph_lock); in __kick_flushing_caps()
2646 struct ceph_client *cl = mdsc->fsc->client; in ceph_early_kick_flushing_caps()
2651 doutc(cl, "mds%d\n", session->s_mds); in ceph_early_kick_flushing_caps()
2653 spin_lock(&mdsc->cap_dirty_lock); in ceph_early_kick_flushing_caps()
2655 spin_unlock(&mdsc->cap_dirty_lock); in ceph_early_kick_flushing_caps()
2657 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) { in ceph_early_kick_flushing_caps()
2658 struct inode *inode = &ci->netfs.inode; in ceph_early_kick_flushing_caps()
2660 spin_lock(&ci->i_ceph_lock); in ceph_early_kick_flushing_caps()
2661 cap = ci->i_auth_cap; in ceph_early_kick_flushing_caps()
2662 if (!(cap && cap->session == session)) { in ceph_early_kick_flushing_caps()
2665 session->s_mds); in ceph_early_kick_flushing_caps()
2666 spin_unlock(&ci->i_ceph_lock); in ceph_early_kick_flushing_caps()
2672 * if flushing caps were revoked, we re-send the cap flush in ceph_early_kick_flushing_caps()
2677 if ((cap->issued & ci->i_flushing_caps) != in ceph_early_kick_flushing_caps()
2678 ci->i_flushing_caps) { in ceph_early_kick_flushing_caps()
2682 cap->seq = 0; in ceph_early_kick_flushing_caps()
2683 cap->issue_seq = 0; in ceph_early_kick_flushing_caps()
2684 cap->mseq = 0; in ceph_early_kick_flushing_caps()
2688 ci->i_ceph_flags |= CEPH_I_KICK_FLUSH; in ceph_early_kick_flushing_caps()
2691 spin_unlock(&ci->i_ceph_lock); in ceph_early_kick_flushing_caps()
2698 struct ceph_client *cl = mdsc->fsc->client; in ceph_kick_flushing_caps()
2703 lockdep_assert_held(&session->s_mutex); in ceph_kick_flushing_caps()
2705 doutc(cl, "mds%d\n", session->s_mds); in ceph_kick_flushing_caps()
2707 spin_lock(&mdsc->cap_dirty_lock); in ceph_kick_flushing_caps()
2709 spin_unlock(&mdsc->cap_dirty_lock); in ceph_kick_flushing_caps()
2711 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) { in ceph_kick_flushing_caps()
2712 struct inode *inode = &ci->netfs.inode; in ceph_kick_flushing_caps()
2714 spin_lock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2715 cap = ci->i_auth_cap; in ceph_kick_flushing_caps()
2716 if (!(cap && cap->session == session)) { in ceph_kick_flushing_caps()
2719 session->s_mds); in ceph_kick_flushing_caps()
2720 spin_unlock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2723 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) { in ceph_kick_flushing_caps()
2727 spin_unlock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2734 struct ceph_mds_client *mdsc = session->s_mdsc; in ceph_kick_flushing_inode_caps()
2735 struct ceph_cap *cap = ci->i_auth_cap; in ceph_kick_flushing_inode_caps()
2736 struct inode *inode = &ci->netfs.inode; in ceph_kick_flushing_inode_caps()
2738 lockdep_assert_held(&ci->i_ceph_lock); in ceph_kick_flushing_inode_caps()
2740 doutc(mdsc->fsc->client, "%p %llx.%llx flushing %s\n", in ceph_kick_flushing_inode_caps()
2742 ceph_cap_string(ci->i_flushing_caps)); in ceph_kick_flushing_inode_caps()
2744 if (!list_empty(&ci->i_cap_flush_list)) { in ceph_kick_flushing_inode_caps()
2746 spin_lock(&mdsc->cap_dirty_lock); in ceph_kick_flushing_inode_caps()
2747 list_move_tail(&ci->i_flushing_item, in ceph_kick_flushing_inode_caps()
2748 &cap->session->s_cap_flushing); in ceph_kick_flushing_inode_caps()
2750 spin_unlock(&mdsc->cap_dirty_lock); in ceph_kick_flushing_inode_caps()
2764 struct inode *inode = &ci->netfs.inode; in ceph_take_cap_refs()
2767 lockdep_assert_held(&ci->i_ceph_lock); in ceph_take_cap_refs()
2770 ci->i_pin_ref++; in ceph_take_cap_refs()
2772 ci->i_rd_ref++; in ceph_take_cap_refs()
2774 ci->i_rdcache_ref++; in ceph_take_cap_refs()
2776 ci->i_fx_ref++; in ceph_take_cap_refs()
2778 if (ci->i_wr_ref == 0 && !ci->i_head_snapc) { in ceph_take_cap_refs()
2780 ci->i_head_snapc = ceph_get_snap_context( in ceph_take_cap_refs()
2781 ci->i_snap_realm->cached_context); in ceph_take_cap_refs()
2783 ci->i_wr_ref++; in ceph_take_cap_refs()
2786 if (ci->i_wb_ref == 0) in ceph_take_cap_refs()
2788 ci->i_wb_ref++; in ceph_take_cap_refs()
2789 doutc(cl, "%p %llx.%llx wb %d -> %d (?)\n", inode, in ceph_take_cap_refs()
2790 ceph_vinop(inode), ci->i_wb_ref-1, ci->i_wb_ref); in ceph_take_cap_refs()
2803 * -EAGAIN: need to sleep but non-blocking is specified
2804 * -EFBIG: ask caller to call check_max_size() and try again.
2805 * -EUCLEAN: ask caller to call ceph_renew_caps() and try again.
2817 struct ceph_mds_client *mdsc = ceph_inode_to_fs_client(inode)->mdsc; in try_get_cap_refs()
2828 spin_lock(&ci->i_ceph_lock); in try_get_cap_refs()
2831 (ci->i_ceph_flags & CEPH_I_ERROR_FILELOCK)) { in try_get_cap_refs()
2834 ret = -EIO; in try_get_cap_refs()
2839 while (ci->i_truncate_pending) { in try_get_cap_refs()
2840 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2842 up_read(&mdsc->snap_rwsem); in try_get_cap_refs()
2846 spin_lock(&ci->i_ceph_lock); in try_get_cap_refs()
2852 if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) { in try_get_cap_refs()
2854 inode, ceph_vinop(inode), endoff, ci->i_max_size); in try_get_cap_refs()
2855 if (endoff > ci->i_requested_max_size) in try_get_cap_refs()
2856 ret = ci->i_auth_cap ? -EFBIG : -EUCLEAN; in try_get_cap_refs()
2873 * on transition from wanted -> needed caps. This is needed in try_get_cap_refs()
2874 * for WRBUFFER|WR -> WR to avoid a new WR sync write from in try_get_cap_refs()
2877 * For RDCACHE|RD -> RD, there is not need to wait and we can in try_get_cap_refs()
2888 !ci->i_head_snapc && in try_get_cap_refs()
2890 if (!down_read_trylock(&mdsc->snap_rwsem)) { in try_get_cap_refs()
2896 ret = -EAGAIN; in try_get_cap_refs()
2900 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2901 down_read(&mdsc->snap_rwsem); in try_get_cap_refs()
2917 if (ci->i_auth_cap && in try_get_cap_refs()
2919 struct ceph_mds_session *s = ci->i_auth_cap->session; in try_get_cap_refs()
2920 spin_lock(&s->s_cap_lock); in try_get_cap_refs()
2921 session_readonly = s->s_readonly; in try_get_cap_refs()
2922 spin_unlock(&s->s_cap_lock); in try_get_cap_refs()
2927 ci->i_auth_cap->mds); in try_get_cap_refs()
2928 ret = -EROFS; in try_get_cap_refs()
2935 ret = -ESTALE; in try_get_cap_refs()
2943 ret = -EUCLEAN; in try_get_cap_refs()
2955 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2957 up_read(&mdsc->snap_rwsem); in try_get_cap_refs()
2960 ceph_update_cap_mis(&mdsc->metric); in try_get_cap_refs()
2962 ceph_update_cap_hit(&mdsc->metric); in try_get_cap_refs()
2981 spin_lock(&ci->i_ceph_lock); in check_max_size()
2982 if (endoff >= ci->i_max_size && endoff > ci->i_wanted_max_size) { in check_max_size()
2985 ci->i_wanted_max_size = endoff; in check_max_size()
2988 if (ci->i_auth_cap && in check_max_size()
2989 (ci->i_auth_cap->issued & CEPH_CAP_FILE_WR) && in check_max_size()
2990 ci->i_wanted_max_size > ci->i_max_size && in check_max_size()
2991 ci->i_wanted_max_size > ci->i_requested_max_size) in check_max_size()
2993 spin_unlock(&ci->i_ceph_lock); in check_max_size()
3029 if (ret == -EAGAIN || ret == -EFBIG || ret == -EUCLEAN) in ceph_try_get_caps()
3050 if (fi && (fi->fmode & CEPH_FILE_MODE_WR) && in __ceph_get_caps()
3051 fi->filp_gen != READ_ONCE(fsc->filp_gen)) in __ceph_get_caps()
3052 return -EBADF; in __ceph_get_caps()
3063 WARN_ON_ONCE(ret == -EAGAIN); in __ceph_get_caps()
3066 struct ceph_mds_client *mdsc = fsc->mdsc; in __ceph_get_caps()
3073 cw.tgid = current->tgid; in __ceph_get_caps()
3077 spin_lock(&mdsc->caps_list_lock); in __ceph_get_caps()
3078 list_add(&cw.list, &mdsc->cap_wait_list); in __ceph_get_caps()
3079 spin_unlock(&mdsc->caps_list_lock); in __ceph_get_caps()
3084 add_wait_queue(&ci->i_cap_wq, &wait); in __ceph_get_caps()
3090 ret = -ERESTARTSYS; in __ceph_get_caps()
3096 remove_wait_queue(&ci->i_cap_wq, &wait); in __ceph_get_caps()
3100 spin_lock(&mdsc->caps_list_lock); in __ceph_get_caps()
3102 spin_unlock(&mdsc->caps_list_lock); in __ceph_get_caps()
3105 if (ret == -EAGAIN) in __ceph_get_caps()
3109 if (fi && (fi->fmode & CEPH_FILE_MODE_WR) && in __ceph_get_caps()
3110 fi->filp_gen != READ_ONCE(fsc->filp_gen)) { in __ceph_get_caps()
3113 return -EBADF; in __ceph_get_caps()
3117 if (ret == -EFBIG || ret == -EUCLEAN) { in __ceph_get_caps()
3122 if (ret == -EFBIG) { in __ceph_get_caps()
3126 if (ret == -EUCLEAN) { in __ceph_get_caps()
3135 if (S_ISREG(ci->netfs.inode.i_mode) && in __ceph_get_caps()
3140 find_get_page(inode->i_mapping, 0); in __ceph_get_caps()
3175 struct ceph_file_info *fi = filp->private_data; in ceph_get_caps()
3187 spin_lock(&ci->i_ceph_lock); in ceph_get_cap_refs()
3189 spin_unlock(&ci->i_ceph_lock); in ceph_get_cap_refs()
3200 struct inode *inode = &ci->netfs.inode; in ceph_try_drop_cap_snap()
3203 if (!capsnap->need_flush && in ceph_try_drop_cap_snap()
3204 !capsnap->writing && !capsnap->dirty_pages) { in ceph_try_drop_cap_snap()
3205 doutc(cl, "%p follows %llu\n", capsnap, capsnap->follows); in ceph_try_drop_cap_snap()
3206 BUG_ON(capsnap->cap_flush.tid > 0); in ceph_try_drop_cap_snap()
3207 ceph_put_snap_context(capsnap->context); in ceph_try_drop_cap_snap()
3208 if (!list_is_last(&capsnap->ci_item, &ci->i_cap_snaps)) in ceph_try_drop_cap_snap()
3209 ci->i_ceph_flags |= CEPH_I_FLUSH_SNAPS; in ceph_try_drop_cap_snap()
3211 list_del(&capsnap->ci_item); in ceph_try_drop_cap_snap()
3235 struct inode *inode = &ci->netfs.inode; in __ceph_put_cap_refs()
3240 spin_lock(&ci->i_ceph_lock); in __ceph_put_cap_refs()
3242 --ci->i_pin_ref; in __ceph_put_cap_refs()
3244 if (--ci->i_rd_ref == 0) in __ceph_put_cap_refs()
3247 if (--ci->i_rdcache_ref == 0) in __ceph_put_cap_refs()
3250 if (--ci->i_fx_ref == 0) in __ceph_put_cap_refs()
3253 if (--ci->i_wb_ref == 0) { in __ceph_put_cap_refs()
3259 doutc(cl, "%p %llx.%llx wb %d -> %d (?)\n", inode, in __ceph_put_cap_refs()
3260 ceph_vinop(inode), ci->i_wb_ref+1, ci->i_wb_ref); in __ceph_put_cap_refs()
3263 if (--ci->i_wr_ref == 0) { in __ceph_put_cap_refs()
3268 WARN_ON_ONCE(ci->i_wb_ref); in __ceph_put_cap_refs()
3272 if (ci->i_wrbuffer_ref_head == 0 && in __ceph_put_cap_refs()
3273 ci->i_dirty_caps == 0 && in __ceph_put_cap_refs()
3274 ci->i_flushing_caps == 0) { in __ceph_put_cap_refs()
3275 BUG_ON(!ci->i_head_snapc); in __ceph_put_cap_refs()
3276 ceph_put_snap_context(ci->i_head_snapc); in __ceph_put_cap_refs()
3277 ci->i_head_snapc = NULL; in __ceph_put_cap_refs()
3280 if (!__ceph_is_any_real_caps(ci) && ci->i_snap_realm) in __ceph_put_cap_refs()
3286 list_last_entry(&ci->i_cap_snaps, in __ceph_put_cap_refs()
3290 capsnap->writing = 0; in __ceph_put_cap_refs()
3298 spin_unlock(&ci->i_ceph_lock); in __ceph_put_cap_refs()
3320 wake_up_all(&ci->i_cap_wq); in __ceph_put_cap_refs()
3321 while (put-- > 0) in __ceph_put_cap_refs()
3337 * context. Adjust per-snap dirty page accounting as appropriate.
3345 struct inode *inode = &ci->netfs.inode; in ceph_put_wrbuffer_cap_refs()
3353 spin_lock(&ci->i_ceph_lock); in ceph_put_wrbuffer_cap_refs()
3354 ci->i_wrbuffer_ref -= nr; in ceph_put_wrbuffer_cap_refs()
3355 if (ci->i_wrbuffer_ref == 0) { in ceph_put_wrbuffer_cap_refs()
3360 if (ci->i_head_snapc == snapc) { in ceph_put_wrbuffer_cap_refs()
3361 ci->i_wrbuffer_ref_head -= nr; in ceph_put_wrbuffer_cap_refs()
3362 if (ci->i_wrbuffer_ref_head == 0 && in ceph_put_wrbuffer_cap_refs()
3363 ci->i_wr_ref == 0 && in ceph_put_wrbuffer_cap_refs()
3364 ci->i_dirty_caps == 0 && in ceph_put_wrbuffer_cap_refs()
3365 ci->i_flushing_caps == 0) { in ceph_put_wrbuffer_cap_refs()
3366 BUG_ON(!ci->i_head_snapc); in ceph_put_wrbuffer_cap_refs()
3367 ceph_put_snap_context(ci->i_head_snapc); in ceph_put_wrbuffer_cap_refs()
3368 ci->i_head_snapc = NULL; in ceph_put_wrbuffer_cap_refs()
3370 doutc(cl, "on %p %llx.%llx head %d/%d -> %d/%d %s\n", in ceph_put_wrbuffer_cap_refs()
3371 inode, ceph_vinop(inode), ci->i_wrbuffer_ref+nr, in ceph_put_wrbuffer_cap_refs()
3372 ci->i_wrbuffer_ref_head+nr, ci->i_wrbuffer_ref, in ceph_put_wrbuffer_cap_refs()
3373 ci->i_wrbuffer_ref_head, last ? " LAST" : ""); in ceph_put_wrbuffer_cap_refs()
3375 list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) { in ceph_put_wrbuffer_cap_refs()
3376 if (iter->context == snapc) { in ceph_put_wrbuffer_cap_refs()
3387 WARN_ON_ONCE(ci->i_auth_cap); in ceph_put_wrbuffer_cap_refs()
3391 capsnap->dirty_pages -= nr; in ceph_put_wrbuffer_cap_refs()
3392 if (capsnap->dirty_pages == 0) { in ceph_put_wrbuffer_cap_refs()
3394 if (!capsnap->writing) { in ceph_put_wrbuffer_cap_refs()
3398 ci->i_ceph_flags |= CEPH_I_FLUSH_SNAPS; in ceph_put_wrbuffer_cap_refs()
3403 doutc(cl, "%p %llx.%llx cap_snap %p snap %lld %d/%d -> %d/%d %s%s\n", in ceph_put_wrbuffer_cap_refs()
3404 inode, ceph_vinop(inode), capsnap, capsnap->context->seq, in ceph_put_wrbuffer_cap_refs()
3405 ci->i_wrbuffer_ref+nr, capsnap->dirty_pages + nr, in ceph_put_wrbuffer_cap_refs()
3406 ci->i_wrbuffer_ref, capsnap->dirty_pages, in ceph_put_wrbuffer_cap_refs()
3412 spin_unlock(&ci->i_ceph_lock); in ceph_put_wrbuffer_cap_refs()
3420 wake_up_all(&ci->i_cap_wq); in ceph_put_wrbuffer_cap_refs()
3421 while (put-- > 0) { in ceph_put_wrbuffer_cap_refs()
3437 * For non-directory inode, d_find_alias() only returns in invalidate_aliases()
3490 __releases(ci->i_ceph_lock) in handle_cap_grant()
3491 __releases(session->s_mdsc->snap_rwsem) in handle_cap_grant()
3495 int seq = le32_to_cpu(grant->seq); in handle_cap_grant()
3496 int newcaps = le32_to_cpu(grant->caps); in handle_cap_grant()
3498 u64 size = le64_to_cpu(grant->size); in handle_cap_grant()
3499 u64 max_size = le64_to_cpu(grant->max_size); in handle_cap_grant()
3501 bool was_stale = cap->cap_gen < atomic_read(&session->s_cap_gen); in handle_cap_grant()
3517 size = extra_info->fscrypt_file_size; in handle_cap_grant()
3520 ceph_vinop(inode), cap, session->s_mds, seq, in handle_cap_grant()
3531 if (S_ISREG(inode->i_mode) && /* don't invalidate readdir cache */ in handle_cap_grant()
3532 ((cap->issued & ~newcaps) & CEPH_CAP_FILE_CACHE) && in handle_cap_grant()
3534 !(ci->i_wrbuffer_ref || ci->i_wb_ref)) { in handle_cap_grant()
3538 if (ci->i_rdcache_revoking != ci->i_rdcache_gen) { in handle_cap_grant()
3540 ci->i_rdcache_revoking = ci->i_rdcache_gen; in handle_cap_grant()
3546 cap->issued = cap->implemented = CEPH_CAP_PIN; in handle_cap_grant()
3553 * "ceph_seq_cmp(seq, cap->seq) <= 0" means we are processing a message in handle_cap_grant()
3556 if (ceph_seq_cmp(seq, cap->seq) <= 0) { in handle_cap_grant()
3557 WARN_ON(cap != ci->i_auth_cap); in handle_cap_grant()
3558 WARN_ON(cap->cap_id != le64_to_cpu(grant->cap_id)); in handle_cap_grant()
3559 seq = cap->seq; in handle_cap_grant()
3560 newcaps |= cap->issued; in handle_cap_grant()
3564 cap->cap_gen = atomic_read(&session->s_cap_gen); in handle_cap_grant()
3565 cap->seq = seq; in handle_cap_grant()
3569 inode_set_max_iversion_raw(inode, extra_info->change_attr); in handle_cap_grant()
3572 (extra_info->issued & CEPH_CAP_AUTH_EXCL) == 0) { in handle_cap_grant()
3573 umode_t mode = le32_to_cpu(grant->mode); in handle_cap_grant()
3577 ceph_vinop(inode), inode->i_mode, mode); in handle_cap_grant()
3579 inode->i_mode = mode; in handle_cap_grant()
3580 inode->i_uid = make_kuid(&init_user_ns, le32_to_cpu(grant->uid)); in handle_cap_grant()
3581 inode->i_gid = make_kgid(&init_user_ns, le32_to_cpu(grant->gid)); in handle_cap_grant()
3582 ci->i_btime = extra_info->btime; in handle_cap_grant()
3584 ceph_vinop(inode), inode->i_mode, in handle_cap_grant()
3585 from_kuid(&init_user_ns, inode->i_uid), in handle_cap_grant()
3586 from_kgid(&init_user_ns, inode->i_gid)); in handle_cap_grant()
3588 if (ci->fscrypt_auth_len != extra_info->fscrypt_auth_len || in handle_cap_grant()
3589 memcmp(ci->fscrypt_auth, extra_info->fscrypt_auth, in handle_cap_grant()
3590 ci->fscrypt_auth_len)) in handle_cap_grant()
3592 "cap grant attempt to change fscrypt_auth on non-I_NEW inode (old len %d new len %d)\n", in handle_cap_grant()
3593 ci->fscrypt_auth_len, in handle_cap_grant()
3594 extra_info->fscrypt_auth_len); in handle_cap_grant()
3599 (extra_info->issued & CEPH_CAP_LINK_EXCL) == 0) { in handle_cap_grant()
3600 set_nlink(inode, le32_to_cpu(grant->nlink)); in handle_cap_grant()
3601 if (inode->i_nlink == 0) in handle_cap_grant()
3605 if ((extra_info->issued & CEPH_CAP_XATTR_EXCL) == 0 && in handle_cap_grant()
3606 grant->xattr_len) { in handle_cap_grant()
3607 int len = le32_to_cpu(grant->xattr_len); in handle_cap_grant()
3608 u64 version = le64_to_cpu(grant->xattr_version); in handle_cap_grant()
3610 if (version > ci->i_xattrs.version) { in handle_cap_grant()
3613 if (ci->i_xattrs.blob) in handle_cap_grant()
3614 ceph_buffer_put(ci->i_xattrs.blob); in handle_cap_grant()
3615 ci->i_xattrs.blob = ceph_buffer_get(xattr_buf); in handle_cap_grant()
3616 ci->i_xattrs.version = version; in handle_cap_grant()
3625 ceph_decode_timespec64(&mtime, &grant->mtime); in handle_cap_grant()
3626 ceph_decode_timespec64(&atime, &grant->atime); in handle_cap_grant()
3627 ceph_decode_timespec64(&ctime, &grant->ctime); in handle_cap_grant()
3628 ceph_fill_file_time(inode, extra_info->issued, in handle_cap_grant()
3629 le32_to_cpu(grant->time_warp_seq), in handle_cap_grant()
3633 if ((newcaps & CEPH_CAP_FILE_SHARED) && extra_info->dirstat_valid) { in handle_cap_grant()
3634 ci->i_files = extra_info->nfiles; in handle_cap_grant()
3635 ci->i_subdirs = extra_info->nsubdirs; in handle_cap_grant()
3640 s64 old_pool = ci->i_layout.pool_id; in handle_cap_grant()
3643 ceph_file_layout_from_legacy(&ci->i_layout, &grant->layout); in handle_cap_grant()
3644 old_ns = rcu_dereference_protected(ci->i_layout.pool_ns, in handle_cap_grant()
3645 lockdep_is_held(&ci->i_ceph_lock)); in handle_cap_grant()
3646 rcu_assign_pointer(ci->i_layout.pool_ns, extra_info->pool_ns); in handle_cap_grant()
3648 if (ci->i_layout.pool_id != old_pool || in handle_cap_grant()
3649 extra_info->pool_ns != old_ns) in handle_cap_grant()
3650 ci->i_ceph_flags &= ~CEPH_I_POOL_PERM; in handle_cap_grant()
3652 extra_info->pool_ns = old_ns; in handle_cap_grant()
3655 queue_trunc = ceph_fill_file_size(inode, extra_info->issued, in handle_cap_grant()
3656 le32_to_cpu(grant->truncate_seq), in handle_cap_grant()
3657 le64_to_cpu(grant->truncate_size), in handle_cap_grant()
3661 if (ci->i_auth_cap == cap && (newcaps & CEPH_CAP_ANY_FILE_WR)) { in handle_cap_grant()
3662 if (max_size != ci->i_max_size) { in handle_cap_grant()
3663 doutc(cl, "max_size %lld -> %llu\n", ci->i_max_size, in handle_cap_grant()
3665 ci->i_max_size = max_size; in handle_cap_grant()
3666 if (max_size >= ci->i_wanted_max_size) { in handle_cap_grant()
3667 ci->i_wanted_max_size = 0; /* reset */ in handle_cap_grant()
3668 ci->i_requested_max_size = 0; in handle_cap_grant()
3682 if ((was_stale || le32_to_cpu(grant->op) == CEPH_CAP_OP_IMPORT) && in handle_cap_grant()
3683 (wanted & ~(cap->mds_wanted | newcaps))) { in handle_cap_grant()
3697 /* revocation, grant, or no-op? */ in handle_cap_grant()
3698 if (cap->issued & ~newcaps) { in handle_cap_grant()
3699 int revoking = cap->issued & ~newcaps; in handle_cap_grant()
3701 doutc(cl, "revocation: %s -> %s (revoking %s)\n", in handle_cap_grant()
3702 ceph_cap_string(cap->issued), ceph_cap_string(newcaps), in handle_cap_grant()
3704 if (S_ISREG(inode->i_mode) && in handle_cap_grant()
3712 } else if (cap == ci->i_auth_cap) { in handle_cap_grant()
3718 if (~cap->issued & newcaps) in handle_cap_grant()
3720 cap->issued = newcaps; in handle_cap_grant()
3721 cap->implemented |= newcaps; in handle_cap_grant()
3722 } else if (cap->issued == newcaps) { in handle_cap_grant()
3723 doutc(cl, "caps unchanged: %s -> %s\n", in handle_cap_grant()
3724 ceph_cap_string(cap->issued), in handle_cap_grant()
3727 doutc(cl, "grant: %s -> %s\n", ceph_cap_string(cap->issued), in handle_cap_grant()
3729 /* non-auth MDS is revoking the newly grant caps ? */ in handle_cap_grant()
3730 if (cap == ci->i_auth_cap && in handle_cap_grant()
3734 cap->issued = newcaps; in handle_cap_grant()
3735 cap->implemented |= newcaps; /* add bits only, to in handle_cap_grant()
3740 BUG_ON(cap->issued & ~cap->implemented); in handle_cap_grant()
3743 if (!revoke_wait && le32_to_cpu(grant->op) == CEPH_CAP_OP_REVOKE) { in handle_cap_grant()
3744 cap->mds_wanted = 0; in handle_cap_grant()
3746 if (cap == ci->i_auth_cap) in handle_cap_grant()
3752 if (extra_info->inline_version > 0 && in handle_cap_grant()
3753 extra_info->inline_version >= ci->i_inline_version) { in handle_cap_grant()
3754 ci->i_inline_version = extra_info->inline_version; in handle_cap_grant()
3755 if (ci->i_inline_version != CEPH_INLINE_NONE && in handle_cap_grant()
3760 if (le32_to_cpu(grant->op) == CEPH_CAP_OP_IMPORT) { in handle_cap_grant()
3761 if (ci->i_auth_cap == cap) { in handle_cap_grant()
3762 if (newcaps & ~extra_info->issued) in handle_cap_grant()
3765 if (ci->i_requested_max_size > max_size || in handle_cap_grant()
3766 !(le32_to_cpu(grant->wanted) & CEPH_CAP_ANY_FILE_WR)) { in handle_cap_grant()
3767 /* re-request max_size if necessary */ in handle_cap_grant()
3768 ci->i_requested_max_size = 0; in handle_cap_grant()
3774 up_read(&session->s_mdsc->snap_rwsem); in handle_cap_grant()
3776 spin_unlock(&ci->i_ceph_lock); in handle_cap_grant()
3779 ceph_fill_inline_data(inode, NULL, extra_info->inline_data, in handle_cap_grant()
3780 extra_info->inline_len); in handle_cap_grant()
3797 wake_up_all(&ci->i_cap_wq); in handle_cap_grant()
3799 mutex_unlock(&session->s_mutex); in handle_cap_grant()
3814 __releases(ci->i_ceph_lock) in handle_cap_flush_ack()
3817 struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc; in handle_cap_flush_ack()
3818 struct ceph_client *cl = mdsc->fsc->client; in handle_cap_flush_ack()
3821 unsigned seq = le32_to_cpu(m->seq); in handle_cap_flush_ack()
3822 int dirty = le32_to_cpu(m->dirty); in handle_cap_flush_ack()
3828 list_for_each_entry_safe(cf, tmp_cf, &ci->i_cap_flush_list, i_list) { in handle_cap_flush_ack()
3830 if (cf->tid == flush_tid) in handle_cap_flush_ack()
3831 cleaned = cf->caps; in handle_cap_flush_ack()
3834 if (cf->is_capsnap) in handle_cap_flush_ack()
3837 if (cf->tid <= flush_tid) { in handle_cap_flush_ack()
3843 list_add_tail(&cf->i_list, &to_remove); in handle_cap_flush_ack()
3849 cleaned &= ~cf->caps; in handle_cap_flush_ack()
3855 doutc(cl, "%p %llx.%llx mds%d seq %d on %s cleaned %s, flushing %s -> %s\n", in handle_cap_flush_ack()
3856 inode, ceph_vinop(inode), session->s_mds, seq, in handle_cap_flush_ack()
3858 ceph_cap_string(ci->i_flushing_caps), in handle_cap_flush_ack()
3859 ceph_cap_string(ci->i_flushing_caps & ~cleaned)); in handle_cap_flush_ack()
3864 ci->i_flushing_caps &= ~cleaned; in handle_cap_flush_ack()
3866 spin_lock(&mdsc->cap_dirty_lock); in handle_cap_flush_ack()
3871 if (ci->i_flushing_caps == 0) { in handle_cap_flush_ack()
3872 if (list_empty(&ci->i_cap_flush_list)) { in handle_cap_flush_ack()
3873 list_del_init(&ci->i_flushing_item); in handle_cap_flush_ack()
3874 if (!list_empty(&session->s_cap_flushing)) { in handle_cap_flush_ack()
3876 &list_first_entry(&session->s_cap_flushing, in handle_cap_flush_ack()
3878 i_flushing_item)->netfs.inode; in handle_cap_flush_ack()
3880 session->s_mds, inode, ceph_vinop(inode)); in handle_cap_flush_ack()
3883 mdsc->num_cap_flushing--; in handle_cap_flush_ack()
3887 if (ci->i_dirty_caps == 0) { in handle_cap_flush_ack()
3890 BUG_ON(!list_empty(&ci->i_dirty_item)); in handle_cap_flush_ack()
3892 if (ci->i_wr_ref == 0 && in handle_cap_flush_ack()
3893 ci->i_wrbuffer_ref_head == 0) { in handle_cap_flush_ack()
3894 BUG_ON(!ci->i_head_snapc); in handle_cap_flush_ack()
3895 ceph_put_snap_context(ci->i_head_snapc); in handle_cap_flush_ack()
3896 ci->i_head_snapc = NULL; in handle_cap_flush_ack()
3899 BUG_ON(list_empty(&ci->i_dirty_item)); in handle_cap_flush_ack()
3902 spin_unlock(&mdsc->cap_dirty_lock); in handle_cap_flush_ack()
3905 spin_unlock(&ci->i_ceph_lock); in handle_cap_flush_ack()
3910 list_del_init(&cf->i_list); in handle_cap_flush_ack()
3911 if (!cf->is_capsnap) in handle_cap_flush_ack()
3916 wake_up_all(&ci->i_cap_wq); in handle_cap_flush_ack()
3918 wake_up_all(&mdsc->cap_flushing_wq); in handle_cap_flush_ack()
3927 struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc; in __ceph_remove_capsnap()
3928 struct ceph_client *cl = mdsc->fsc->client; in __ceph_remove_capsnap()
3931 lockdep_assert_held(&ci->i_ceph_lock); in __ceph_remove_capsnap()
3936 list_del_init(&capsnap->ci_item); in __ceph_remove_capsnap()
3937 ret = __detach_cap_flush_from_ci(ci, &capsnap->cap_flush); in __ceph_remove_capsnap()
3941 spin_lock(&mdsc->cap_dirty_lock); in __ceph_remove_capsnap()
3942 if (list_empty(&ci->i_cap_flush_list)) in __ceph_remove_capsnap()
3943 list_del_init(&ci->i_flushing_item); in __ceph_remove_capsnap()
3945 ret = __detach_cap_flush_from_mdsc(mdsc, &capsnap->cap_flush); in __ceph_remove_capsnap()
3948 spin_unlock(&mdsc->cap_dirty_lock); in __ceph_remove_capsnap()
3956 lockdep_assert_held(&ci->i_ceph_lock); in ceph_remove_capsnap()
3958 WARN_ON_ONCE(capsnap->dirty_pages || capsnap->writing); in ceph_remove_capsnap()
3973 struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc; in handle_cap_flushsnap_ack()
3974 struct ceph_client *cl = mdsc->fsc->client; in handle_cap_flushsnap_ack()
3975 u64 follows = le64_to_cpu(m->snap_follows); in handle_cap_flushsnap_ack()
3981 ceph_vinop(inode), ci, session->s_mds, follows); in handle_cap_flushsnap_ack()
3983 spin_lock(&ci->i_ceph_lock); in handle_cap_flushsnap_ack()
3984 list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) { in handle_cap_flushsnap_ack()
3985 if (iter->follows == follows) { in handle_cap_flushsnap_ack()
3986 if (iter->cap_flush.tid != flush_tid) { in handle_cap_flushsnap_ack()
3990 iter->cap_flush.tid); in handle_cap_flushsnap_ack()
3997 iter, iter->follows); in handle_cap_flushsnap_ack()
4002 spin_unlock(&ci->i_ceph_lock); in handle_cap_flushsnap_ack()
4005 ceph_put_snap_context(capsnap->context); in handle_cap_flushsnap_ack()
4008 wake_up_all(&ci->i_cap_wq); in handle_cap_flushsnap_ack()
4010 wake_up_all(&mdsc->cap_flushing_wq); in handle_cap_flushsnap_ack()
4027 int mds = session->s_mds; in handle_cap_trunc()
4028 int seq = le32_to_cpu(trunc->seq); in handle_cap_trunc()
4029 u32 truncate_seq = le32_to_cpu(trunc->truncate_seq); in handle_cap_trunc()
4030 u64 truncate_size = le64_to_cpu(trunc->truncate_size); in handle_cap_trunc()
4031 u64 size = le64_to_cpu(trunc->size); in handle_cap_trunc()
4037 lockdep_assert_held(&ci->i_ceph_lock); in handle_cap_trunc()
4047 size = extra_info->fscrypt_file_size; in handle_cap_trunc()
4068 struct ceph_mds_client *mdsc = ceph_inode_to_fs_client(inode)->mdsc; in handle_cap_export()
4069 struct ceph_client *cl = mdsc->fsc->client; in handle_cap_export()
4076 int mds = session->s_mds; in handle_cap_export()
4079 t_cap_id = le64_to_cpu(ph->cap_id); in handle_cap_export()
4080 t_issue_seq = le32_to_cpu(ph->issue_seq); in handle_cap_export()
4081 t_mseq = le32_to_cpu(ph->mseq); in handle_cap_export()
4082 target = le32_to_cpu(ph->mds); in handle_cap_export()
4085 target = -1; in handle_cap_export()
4091 down_read(&mdsc->snap_rwsem); in handle_cap_export()
4092 spin_lock(&ci->i_ceph_lock); in handle_cap_export()
4094 if (!cap || cap->cap_id != le64_to_cpu(ex->cap_id)) in handle_cap_export()
4107 issued = cap->issued; in handle_cap_export()
4108 if (issued != cap->implemented) in handle_cap_export()
4113 cap->seq, cap->mseq, in handle_cap_export()
4115 ceph_cap_string(cap->implemented)); in handle_cap_export()
4121 if (tcap->cap_id == t_cap_id && in handle_cap_export()
4122 ceph_seq_cmp(tcap->seq, t_issue_seq) < 0) { in handle_cap_export()
4125 tcap->cap_id = t_cap_id; in handle_cap_export()
4126 tcap->seq = t_issue_seq - 1; in handle_cap_export()
4127 tcap->issue_seq = t_issue_seq - 1; in handle_cap_export()
4128 tcap->issued |= issued; in handle_cap_export()
4129 tcap->implemented |= issued; in handle_cap_export()
4130 if (cap == ci->i_auth_cap) { in handle_cap_export()
4131 ci->i_auth_cap = tcap; in handle_cap_export()
4132 change_auth_cap_ses(ci, tcap->session); in handle_cap_export()
4139 int flag = (cap == ci->i_auth_cap) ? CEPH_CAP_FLAG_AUTH : 0; in handle_cap_export()
4142 t_issue_seq - 1, t_mseq, (u64)-1, flag, &new_cap); in handle_cap_export()
4144 if (!list_empty(&ci->i_cap_flush_list) && in handle_cap_export()
4145 ci->i_auth_cap == tcap) { in handle_cap_export()
4146 spin_lock(&mdsc->cap_dirty_lock); in handle_cap_export()
4147 list_move_tail(&ci->i_flushing_item, in handle_cap_export()
4148 &tcap->session->s_cap_flushing); in handle_cap_export()
4149 spin_unlock(&mdsc->cap_dirty_lock); in handle_cap_export()
4156 spin_unlock(&ci->i_ceph_lock); in handle_cap_export()
4157 up_read(&mdsc->snap_rwsem); in handle_cap_export()
4158 mutex_unlock(&session->s_mutex); in handle_cap_export()
4164 mutex_lock(&session->s_mutex); in handle_cap_export()
4165 mutex_lock_nested(&tsession->s_mutex, in handle_cap_export()
4168 mutex_lock(&tsession->s_mutex); in handle_cap_export()
4169 mutex_lock_nested(&session->s_mutex, in handle_cap_export()
4176 target = -1; in handle_cap_export()
4177 mutex_lock(&session->s_mutex); in handle_cap_export()
4182 spin_unlock(&ci->i_ceph_lock); in handle_cap_export()
4183 up_read(&mdsc->snap_rwsem); in handle_cap_export()
4184 mutex_unlock(&session->s_mutex); in handle_cap_export()
4186 mutex_unlock(&tsession->s_mutex); in handle_cap_export()
4205 struct ceph_client *cl = mdsc->fsc->client; in handle_cap_import()
4207 int mds = session->s_mds; in handle_cap_import()
4209 unsigned caps = le32_to_cpu(im->caps); in handle_cap_import()
4210 unsigned wanted = le32_to_cpu(im->wanted); in handle_cap_import()
4211 unsigned seq = le32_to_cpu(im->seq); in handle_cap_import()
4212 unsigned mseq = le32_to_cpu(im->migrate_seq); in handle_cap_import()
4213 u64 realmino = le64_to_cpu(im->realm); in handle_cap_import()
4214 u64 cap_id = le64_to_cpu(im->cap_id); in handle_cap_import()
4221 p_cap_id = le64_to_cpu(ph->cap_id); in handle_cap_import()
4222 peer = le32_to_cpu(ph->mds); in handle_cap_import()
4223 piseq = le32_to_cpu(ph->issue_seq); in handle_cap_import()
4224 pmseq = le32_to_cpu(ph->mseq); in handle_cap_import()
4227 peer = -1; in handle_cap_import()
4236 spin_unlock(&ci->i_ceph_lock); in handle_cap_import()
4238 spin_lock(&ci->i_ceph_lock); in handle_cap_import()
4256 if (ocap && ocap->cap_id == p_cap_id) { in handle_cap_import()
4258 ocap, peer, ph->flags); in handle_cap_import()
4259 if ((ph->flags & CEPH_CAP_FLAG_AUTH) && in handle_cap_import()
4260 (ocap->seq != piseq || in handle_cap_import()
4261 ocap->mseq != pmseq)) { in handle_cap_import()
4266 ocap->seq, ocap->mseq, mds, piseq, pmseq); in handle_cap_import()
4268 ceph_remove_cap(mdsc, ocap, (ph->flags & CEPH_CAP_FLAG_RELEASE)); in handle_cap_import()
4281 ceph_decode_32_safe(p, end, extra->fscrypt_auth_len, bad); in parse_fscrypt_fields()
4282 if (extra->fscrypt_auth_len) { in parse_fscrypt_fields()
4283 ceph_decode_need(p, end, extra->fscrypt_auth_len, bad); in parse_fscrypt_fields()
4284 extra->fscrypt_auth = kmalloc(extra->fscrypt_auth_len, in parse_fscrypt_fields()
4286 if (!extra->fscrypt_auth) in parse_fscrypt_fields()
4287 return -ENOMEM; in parse_fscrypt_fields()
4288 ceph_decode_copy_safe(p, end, extra->fscrypt_auth, in parse_fscrypt_fields()
4289 extra->fscrypt_auth_len, bad); in parse_fscrypt_fields()
4294 ceph_decode_64_safe(p, end, extra->fscrypt_file_size, bad); in parse_fscrypt_fields()
4295 len -= sizeof(u64); in parse_fscrypt_fields()
4300 return -EIO; in parse_fscrypt_fields()
4308 /* Don't care about these fields unless we're encryption-capable */ in parse_fscrypt_fields()
4317 return -EIO; in parse_fscrypt_fields()
4330 struct ceph_mds_client *mdsc = session->s_mdsc; in ceph_handle_caps()
4331 struct ceph_client *cl = mdsc->fsc->client; in ceph_handle_caps()
4337 struct ceph_snap_realm *realm = NULL; in ceph_handle_caps() local
4339 int msg_version = le16_to_cpu(msg->hdr.version); in ceph_handle_caps()
4354 end = msg->front.iov_base + msg->front.iov_len; in ceph_handle_caps()
4355 if (msg->front.iov_len < sizeof(*h)) in ceph_handle_caps()
4357 h = msg->front.iov_base; in ceph_handle_caps()
4358 op = le32_to_cpu(h->op); in ceph_handle_caps()
4359 vino.ino = le64_to_cpu(h->ino); in ceph_handle_caps()
4361 seq = le32_to_cpu(h->seq); in ceph_handle_caps()
4362 mseq = le32_to_cpu(h->migrate_seq); in ceph_handle_caps()
4363 issue_seq = le32_to_cpu(h->issue_seq); in ceph_handle_caps()
4366 snaptrace_len = le32_to_cpu(h->snap_trace_len); in ceph_handle_caps()
4385 peer = (void *)&h->size; in ceph_handle_caps()
4399 struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc; in ceph_handle_caps()
4450 inode = ceph_find_inode(mdsc->fsc->sb, vino); in ceph_handle_caps()
4452 session->s_mds, ceph_cap_op_name(op), vino.ino, vino.snap, inode, in ceph_handle_caps()
4455 mutex_lock(&session->s_mutex); in ceph_handle_caps()
4476 handle_cap_flushsnap_ack(inode, le64_to_cpu(msg->hdr.tid), in ceph_handle_caps()
4485 realm = NULL; in ceph_handle_caps()
4487 down_write(&mdsc->snap_rwsem); in ceph_handle_caps()
4490 false, &realm)) { in ceph_handle_caps()
4491 up_write(&mdsc->snap_rwsem); in ceph_handle_caps()
4495 downgrade_write(&mdsc->snap_rwsem); in ceph_handle_caps()
4497 down_read(&mdsc->snap_rwsem); in ceph_handle_caps()
4499 spin_lock(&ci->i_ceph_lock); in ceph_handle_caps()
4503 h, msg->middle, &extra_info); in ceph_handle_caps()
4504 if (realm) in ceph_handle_caps()
4505 ceph_put_snap_realm(mdsc, realm); in ceph_handle_caps()
4510 spin_lock(&ci->i_ceph_lock); in ceph_handle_caps()
4511 cap = __get_cap_for_mds(ceph_inode(inode), session->s_mds); in ceph_handle_caps()
4515 session->s_mds); in ceph_handle_caps()
4516 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
4535 h, msg->middle, &extra_info); in ceph_handle_caps()
4539 handle_cap_flush_ack(inode, le64_to_cpu(msg->hdr.tid), in ceph_handle_caps()
4546 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
4552 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
4558 mutex_unlock(&session->s_mutex); in ceph_handle_caps()
4581 cap->cap_ino = vino.ino; in ceph_handle_caps()
4582 cap->queue_release = 1; in ceph_handle_caps()
4583 cap->cap_id = le64_to_cpu(h->cap_id); in ceph_handle_caps()
4584 cap->mseq = mseq; in ceph_handle_caps()
4585 cap->seq = seq; in ceph_handle_caps()
4586 cap->issue_seq = seq; in ceph_handle_caps()
4587 spin_lock(&session->s_cap_lock); in ceph_handle_caps()
4589 spin_unlock(&session->s_cap_lock); in ceph_handle_caps()
4604 * processed in this run. In this case, the ci->i_hold_caps_max will be
4609 struct ceph_client *cl = mdsc->fsc->client; in ceph_check_delayed_caps()
4612 struct ceph_mount_options *opt = mdsc->fsc->mount_options; in ceph_check_delayed_caps()
4613 unsigned long delay_max = opt->caps_wanted_delay_max * HZ; in ceph_check_delayed_caps()
4618 spin_lock(&mdsc->cap_delay_lock); in ceph_check_delayed_caps()
4619 while (!list_empty(&mdsc->cap_delay_list)) { in ceph_check_delayed_caps()
4620 ci = list_first_entry(&mdsc->cap_delay_list, in ceph_check_delayed_caps()
4623 if (time_before(loop_start, ci->i_hold_caps_max - delay_max)) { in ceph_check_delayed_caps()
4625 delay = ci->i_hold_caps_max; in ceph_check_delayed_caps()
4628 if ((ci->i_ceph_flags & CEPH_I_FLUSH) == 0 && in ceph_check_delayed_caps()
4629 time_before(jiffies, ci->i_hold_caps_max)) in ceph_check_delayed_caps()
4631 list_del_init(&ci->i_cap_delay_list); in ceph_check_delayed_caps()
4633 inode = igrab(&ci->netfs.inode); in ceph_check_delayed_caps()
4635 spin_unlock(&mdsc->cap_delay_lock); in ceph_check_delayed_caps()
4640 spin_lock(&mdsc->cap_delay_lock); in ceph_check_delayed_caps()
4651 spin_unlock(&mdsc->cap_delay_lock); in ceph_check_delayed_caps()
4662 struct ceph_mds_client *mdsc = s->s_mdsc; in flush_dirty_session_caps()
4663 struct ceph_client *cl = mdsc->fsc->client; in flush_dirty_session_caps()
4668 spin_lock(&mdsc->cap_dirty_lock); in flush_dirty_session_caps()
4669 while (!list_empty(&s->s_cap_dirty)) { in flush_dirty_session_caps()
4670 ci = list_first_entry(&s->s_cap_dirty, struct ceph_inode_info, in flush_dirty_session_caps()
4672 inode = &ci->netfs.inode; in flush_dirty_session_caps()
4675 spin_unlock(&mdsc->cap_dirty_lock); in flush_dirty_session_caps()
4679 spin_lock(&mdsc->cap_dirty_lock); in flush_dirty_session_caps()
4681 spin_unlock(&mdsc->cap_dirty_lock); in flush_dirty_session_caps()
4695 struct ceph_mds_client *mdsc = s->s_mdsc; in flush_cap_releases()
4696 struct ceph_client *cl = mdsc->fsc->client; in flush_cap_releases()
4699 spin_lock(&s->s_cap_lock); in flush_cap_releases()
4700 if (s->s_num_cap_releases) in flush_cap_releases()
4702 spin_unlock(&s->s_cap_lock); in flush_cap_releases()
4717 ci->i_last_rd = now; in __ceph_touch_fmode()
4719 ci->i_last_wr = now; in __ceph_touch_fmode()
4723 list_empty(&ci->i_cap_delay_list)) in __ceph_touch_fmode()
4729 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->netfs.inode.i_sb); in ceph_get_fmode()
4735 atomic64_inc(&mdsc->metric.opened_files); in ceph_get_fmode()
4737 spin_lock(&ci->i_ceph_lock); in ceph_get_fmode()
4744 if (i && ci->i_nr_by_mode[i]) in ceph_get_fmode()
4748 ci->i_nr_by_mode[i] += count; in ceph_get_fmode()
4752 percpu_counter_inc(&mdsc->metric.opened_inodes); in ceph_get_fmode()
4753 spin_unlock(&ci->i_ceph_lock); in ceph_get_fmode()
4763 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->netfs.inode.i_sb); in ceph_put_fmode()
4769 atomic64_dec(&mdsc->metric.opened_files); in ceph_put_fmode()
4771 spin_lock(&ci->i_ceph_lock); in ceph_put_fmode()
4774 BUG_ON(ci->i_nr_by_mode[i] < count); in ceph_put_fmode()
4775 ci->i_nr_by_mode[i] -= count; in ceph_put_fmode()
4783 if (i && ci->i_nr_by_mode[i]) in ceph_put_fmode()
4788 percpu_counter_dec(&mdsc->metric.opened_inodes); in ceph_put_fmode()
4789 spin_unlock(&ci->i_ceph_lock); in ceph_put_fmode()
4793 * For a soon-to-be unlinked file, drop the LINK caps. If it
4803 spin_lock(&ci->i_ceph_lock); in ceph_drop_caps_for_unlink()
4804 if (inode->i_nlink == 1) { in ceph_drop_caps_for_unlink()
4809 ceph_inode_to_fs_client(inode)->mdsc; in ceph_drop_caps_for_unlink()
4811 doutc(mdsc->fsc->client, "%p %llx.%llx\n", inode, in ceph_drop_caps_for_unlink()
4813 spin_lock(&mdsc->cap_delay_lock); in ceph_drop_caps_for_unlink()
4814 ci->i_ceph_flags |= CEPH_I_FLUSH; in ceph_drop_caps_for_unlink()
4815 if (!list_empty(&ci->i_cap_delay_list)) in ceph_drop_caps_for_unlink()
4816 list_del_init(&ci->i_cap_delay_list); in ceph_drop_caps_for_unlink()
4817 list_add_tail(&ci->i_cap_delay_list, in ceph_drop_caps_for_unlink()
4818 &mdsc->cap_unlink_delay_list); in ceph_drop_caps_for_unlink()
4819 spin_unlock(&mdsc->cap_delay_lock); in ceph_drop_caps_for_unlink()
4828 spin_unlock(&ci->i_ceph_lock); in ceph_drop_caps_for_unlink()
4850 spin_lock(&ci->i_ceph_lock); in ceph_encode_inode_release()
4863 unless &= cap->issued; in ceph_encode_inode_release()
4875 if (force || (cap->issued & drop)) { in ceph_encode_inode_release()
4876 if (cap->issued & drop) { in ceph_encode_inode_release()
4878 doutc(cl, "%p %llx.%llx cap %p %s -> %s, " in ceph_encode_inode_release()
4879 "wanted %s -> %s\n", inode, in ceph_encode_inode_release()
4881 ceph_cap_string(cap->issued), in ceph_encode_inode_release()
4882 ceph_cap_string(cap->issued & ~drop), in ceph_encode_inode_release()
4883 ceph_cap_string(cap->mds_wanted), in ceph_encode_inode_release()
4886 cap->issued &= ~drop; in ceph_encode_inode_release()
4887 cap->implemented &= ~drop; in ceph_encode_inode_release()
4888 cap->mds_wanted = wanted; in ceph_encode_inode_release()
4889 if (cap == ci->i_auth_cap && in ceph_encode_inode_release()
4891 ci->i_requested_max_size = 0; in ceph_encode_inode_release()
4895 ceph_cap_string(cap->issued)); in ceph_encode_inode_release()
4898 rel->ino = cpu_to_le64(ceph_ino(inode)); in ceph_encode_inode_release()
4899 rel->cap_id = cpu_to_le64(cap->cap_id); in ceph_encode_inode_release()
4900 rel->seq = cpu_to_le32(cap->seq); in ceph_encode_inode_release()
4901 rel->issue_seq = cpu_to_le32(cap->issue_seq); in ceph_encode_inode_release()
4902 rel->mseq = cpu_to_le32(cap->mseq); in ceph_encode_inode_release()
4903 rel->caps = cpu_to_le32(cap->implemented); in ceph_encode_inode_release()
4904 rel->wanted = cpu_to_le32(cap->mds_wanted); in ceph_encode_inode_release()
4905 rel->dname_len = 0; in ceph_encode_inode_release()
4906 rel->dname_seq = 0; in ceph_encode_inode_release()
4912 ceph_cap_string(cap->issued)); in ceph_encode_inode_release()
4915 spin_unlock(&ci->i_ceph_lock); in ceph_encode_inode_release()
4920 * ceph_encode_dentry_release - encode a dentry release into an outgoing request
4950 spin_lock(&dentry->d_lock); in ceph_encode_dentry_release()
4951 if (di->lease_session && di->lease_session->s_mds == mds) in ceph_encode_dentry_release()
4953 spin_unlock(&dentry->d_lock); in ceph_encode_dentry_release()
4958 spin_lock(&dentry->d_lock); in ceph_encode_dentry_release()
4959 if (ret && di->lease_session && di->lease_session->s_mds == mds) { in ceph_encode_dentry_release()
4960 int len = dentry->d_name.len; in ceph_encode_dentry_release()
4962 (int)di->lease_seq); in ceph_encode_dentry_release()
4963 rel->dname_seq = cpu_to_le32(di->lease_seq); in ceph_encode_dentry_release()
4965 memcpy(*p, dentry->d_name.name, len); in ceph_encode_dentry_release()
4966 spin_unlock(&dentry->d_lock); in ceph_encode_dentry_release()
4972 rel->dname_len = cpu_to_le32(len); in ceph_encode_dentry_release()
4975 spin_unlock(&dentry->d_lock); in ceph_encode_dentry_release()
4983 struct ceph_client *cl = mdsc->fsc->client; in remove_capsnaps()
4987 lockdep_assert_held(&ci->i_ceph_lock); in remove_capsnaps()
4992 while (!list_empty(&ci->i_cap_snaps)) { in remove_capsnaps()
4993 capsnap = list_first_entry(&ci->i_cap_snaps, in remove_capsnaps()
4996 ceph_put_snap_context(capsnap->context); in remove_capsnaps()
5000 wake_up_all(&ci->i_cap_wq); in remove_capsnaps()
5001 wake_up_all(&mdsc->cap_flushing_wq); in remove_capsnaps()
5008 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_purge_inode_cap()
5009 struct ceph_client *cl = fsc->client; in ceph_purge_inode_cap()
5015 lockdep_assert_held(&ci->i_ceph_lock); in ceph_purge_inode_cap()
5020 is_auth = (cap == ci->i_auth_cap); in ceph_purge_inode_cap()
5026 if (inode->i_data.nrpages > 0) in ceph_purge_inode_cap()
5028 if (ci->i_wrbuffer_ref > 0) in ceph_purge_inode_cap()
5029 mapping_set_error(&inode->i_data, -EIO); in ceph_purge_inode_cap()
5032 spin_lock(&mdsc->cap_dirty_lock); in ceph_purge_inode_cap()
5035 while (!list_empty(&ci->i_cap_flush_list)) { in ceph_purge_inode_cap()
5036 cf = list_first_entry(&ci->i_cap_flush_list, in ceph_purge_inode_cap()
5038 list_del_init(&cf->g_list); in ceph_purge_inode_cap()
5039 list_del_init(&cf->i_list); in ceph_purge_inode_cap()
5040 if (!cf->is_capsnap) in ceph_purge_inode_cap()
5044 if (!list_empty(&ci->i_dirty_item)) { in ceph_purge_inode_cap()
5047 ceph_cap_string(ci->i_dirty_caps), in ceph_purge_inode_cap()
5049 ci->i_dirty_caps = 0; in ceph_purge_inode_cap()
5050 list_del_init(&ci->i_dirty_item); in ceph_purge_inode_cap()
5053 if (!list_empty(&ci->i_flushing_item)) { in ceph_purge_inode_cap()
5056 ceph_cap_string(ci->i_flushing_caps), in ceph_purge_inode_cap()
5058 ci->i_flushing_caps = 0; in ceph_purge_inode_cap()
5059 list_del_init(&ci->i_flushing_item); in ceph_purge_inode_cap()
5060 mdsc->num_cap_flushing--; in ceph_purge_inode_cap()
5063 spin_unlock(&mdsc->cap_dirty_lock); in ceph_purge_inode_cap()
5066 mapping_set_error(inode->i_mapping, -EIO); in ceph_purge_inode_cap()
5068 if (ci->i_wrbuffer_ref_head == 0 && in ceph_purge_inode_cap()
5069 ci->i_wr_ref == 0 && in ceph_purge_inode_cap()
5070 ci->i_dirty_caps == 0 && in ceph_purge_inode_cap()
5071 ci->i_flushing_caps == 0) { in ceph_purge_inode_cap()
5072 ceph_put_snap_context(ci->i_head_snapc); in ceph_purge_inode_cap()
5073 ci->i_head_snapc = NULL; in ceph_purge_inode_cap()
5077 if (atomic_read(&ci->i_filelock_ref) > 0) { in ceph_purge_inode_cap()
5078 /* make further file lock syscall return -EIO */ in ceph_purge_inode_cap()
5079 ci->i_ceph_flags |= CEPH_I_ERROR_FILELOCK; in ceph_purge_inode_cap()
5085 if (!ci->i_dirty_caps && ci->i_prealloc_cap_flush) { in ceph_purge_inode_cap()
5086 cf = ci->i_prealloc_cap_flush; in ceph_purge_inode_cap()
5087 ci->i_prealloc_cap_flush = NULL; in ceph_purge_inode_cap()
5088 if (!cf->is_capsnap) in ceph_purge_inode_cap()
5092 if (!list_empty(&ci->i_cap_snaps)) in ceph_purge_inode_cap()