Lines Matching refs:ci

50 				 struct ceph_inode_info *ci,
435 struct ceph_cap *__get_cap_for_mds(struct ceph_inode_info *ci, int mds) in __get_cap_for_mds() argument
438 struct rb_node *n = ci->i_caps.rb_node; in __get_cap_for_mds()
452 struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci, int mds) in ceph_get_cap_for_mds() argument
456 spin_lock(&ci->i_ceph_lock); in ceph_get_cap_for_mds()
457 cap = __get_cap_for_mds(ci, mds); in ceph_get_cap_for_mds()
458 spin_unlock(&ci->i_ceph_lock); in ceph_get_cap_for_mds()
465 static void __insert_cap_node(struct ceph_inode_info *ci, in __insert_cap_node() argument
468 struct rb_node **p = &ci->i_caps.rb_node; in __insert_cap_node()
484 rb_insert_color(&new->ci_node, &ci->i_caps); in __insert_cap_node()
492 struct ceph_inode_info *ci) in __cap_set_timeouts() argument
495 ci->i_hold_caps_max = round_jiffies(jiffies + in __cap_set_timeouts()
497 dout("__cap_set_timeouts %p %lu\n", &ci->netfs.inode, in __cap_set_timeouts()
498 ci->i_hold_caps_max - jiffies); in __cap_set_timeouts()
510 struct ceph_inode_info *ci) in __cap_delay_requeue() argument
512 dout("__cap_delay_requeue %p flags 0x%lx at %lu\n", &ci->netfs.inode, in __cap_delay_requeue()
513 ci->i_ceph_flags, ci->i_hold_caps_max); in __cap_delay_requeue()
516 if (!list_empty(&ci->i_cap_delay_list)) { in __cap_delay_requeue()
517 if (ci->i_ceph_flags & CEPH_I_FLUSH) in __cap_delay_requeue()
519 list_del_init(&ci->i_cap_delay_list); in __cap_delay_requeue()
521 __cap_set_timeouts(mdsc, ci); in __cap_delay_requeue()
522 list_add_tail(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue()
534 struct ceph_inode_info *ci) in __cap_delay_requeue_front() argument
536 dout("__cap_delay_requeue_front %p\n", &ci->netfs.inode); in __cap_delay_requeue_front()
538 ci->i_ceph_flags |= CEPH_I_FLUSH; in __cap_delay_requeue_front()
539 if (!list_empty(&ci->i_cap_delay_list)) in __cap_delay_requeue_front()
540 list_del_init(&ci->i_cap_delay_list); in __cap_delay_requeue_front()
541 list_add(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue_front()
551 struct ceph_inode_info *ci) in __cap_delay_cancel() argument
553 dout("__cap_delay_cancel %p\n", &ci->netfs.inode); in __cap_delay_cancel()
554 if (list_empty(&ci->i_cap_delay_list)) in __cap_delay_cancel()
557 list_del_init(&ci->i_cap_delay_list); in __cap_delay_cancel()
562 static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap, in __check_cap_issue() argument
565 unsigned had = __ceph_caps_issued(ci, NULL); in __check_cap_issue()
567 lockdep_assert_held(&ci->i_ceph_lock); in __check_cap_issue()
573 if (S_ISREG(ci->netfs.inode.i_mode) && in __check_cap_issue()
576 ci->i_rdcache_gen++; in __check_cap_issue()
587 atomic_inc(&ci->i_shared_gen); in __check_cap_issue()
588 if (S_ISDIR(ci->netfs.inode.i_mode)) { in __check_cap_issue()
589 dout(" marking %p NOT complete\n", &ci->netfs.inode); in __check_cap_issue()
590 __ceph_dir_clear_complete(ci); in __check_cap_issue()
595 if (S_ISDIR(ci->netfs.inode.i_mode) && (had & CEPH_CAP_DIR_CREATE) && in __check_cap_issue()
597 ceph_put_string(rcu_dereference_raw(ci->i_cached_layout.pool_ns)); in __check_cap_issue()
598 memset(&ci->i_cached_layout, 0, sizeof(ci->i_cached_layout)); in __check_cap_issue()
607 void change_auth_cap_ses(struct ceph_inode_info *ci, in change_auth_cap_ses() argument
610 lockdep_assert_held(&ci->i_ceph_lock); in change_auth_cap_ses()
612 if (list_empty(&ci->i_dirty_item) && list_empty(&ci->i_flushing_item)) in change_auth_cap_ses()
616 if (!list_empty(&ci->i_dirty_item)) in change_auth_cap_ses()
617 list_move(&ci->i_dirty_item, &session->s_cap_dirty); in change_auth_cap_ses()
618 if (!list_empty(&ci->i_flushing_item)) in change_auth_cap_ses()
619 list_move_tail(&ci->i_flushing_item, &session->s_cap_flushing); in change_auth_cap_ses()
639 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_add_cap() local
645 lockdep_assert_held(&ci->i_ceph_lock); in ceph_add_cap()
652 cap = __get_cap_for_mds(ci, mds); in ceph_add_cap()
663 cap->ci = ci; in ceph_add_cap()
664 __insert_cap_node(ci, cap); in ceph_add_cap()
691 WARN_ON(cap != ci->i_auth_cap); in ceph_add_cap()
700 if (!ci->i_snap_realm || in ceph_add_cap()
702 realmino != (u64)-1 && ci->i_snap_realm->ino != realmino)) { in ceph_add_cap()
712 __func__, realmino, ci->i_vino.ino, in ceph_add_cap()
713 ci->i_snap_realm ? ci->i_snap_realm->ino : 0); in ceph_add_cap()
716 __check_cap_issue(ci, cap, issued); in ceph_add_cap()
723 actual_wanted = __ceph_caps_wanted(ci); in ceph_add_cap()
729 __cap_delay_requeue(mdsc, ci); in ceph_add_cap()
733 if (!ci->i_auth_cap || in ceph_add_cap()
734 ceph_seq_cmp(ci->i_auth_cap->mseq, mseq) < 0) { in ceph_add_cap()
735 if (ci->i_auth_cap && in ceph_add_cap()
736 ci->i_auth_cap->session != cap->session) in ceph_add_cap()
737 change_auth_cap_ses(ci, cap->session); in ceph_add_cap()
738 ci->i_auth_cap = cap; in ceph_add_cap()
742 WARN_ON(ci->i_auth_cap == cap); in ceph_add_cap()
759 wake_up_all(&ci->i_cap_wq); in ceph_add_cap()
777 "but STALE (gen %u vs %u)\n", &cap->ci->netfs.inode, in __cap_is_valid()
790 int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented) in __ceph_caps_issued() argument
792 int have = ci->i_snap_caps; in __ceph_caps_issued()
798 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued()
803 &ci->netfs.inode, cap, ceph_cap_string(cap->issued)); in __ceph_caps_issued()
813 if (ci->i_auth_cap) { in __ceph_caps_issued()
814 cap = ci->i_auth_cap; in __ceph_caps_issued()
823 int __ceph_caps_issued_other(struct ceph_inode_info *ci, struct ceph_cap *ocap) in __ceph_caps_issued_other() argument
825 int have = ci->i_snap_caps; in __ceph_caps_issued_other()
829 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued_other()
850 dout("__touch_cap %p cap %p mds%d\n", &cap->ci->netfs.inode, cap, in __touch_cap()
855 &cap->ci->netfs.inode, cap, s->s_mds); in __touch_cap()
865 int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int touch) in __ceph_caps_issued_mask() argument
869 int have = ci->i_snap_caps; in __ceph_caps_issued_mask()
873 " (mask %s)\n", ceph_ino(&ci->netfs.inode), in __ceph_caps_issued_mask()
879 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued_mask()
885 " (mask %s)\n", ceph_ino(&ci->netfs.inode), cap, in __ceph_caps_issued_mask()
897 " (mask %s)\n", ceph_ino(&ci->netfs.inode), in __ceph_caps_issued_mask()
905 for (q = rb_first(&ci->i_caps); q != p; in __ceph_caps_issued_mask()
922 int __ceph_caps_issued_mask_metric(struct ceph_inode_info *ci, int mask, in __ceph_caps_issued_mask_metric() argument
925 struct ceph_fs_client *fsc = ceph_sb_to_client(ci->netfs.inode.i_sb); in __ceph_caps_issued_mask_metric()
928 r = __ceph_caps_issued_mask(ci, mask, touch); in __ceph_caps_issued_mask_metric()
939 int __ceph_caps_revoking_other(struct ceph_inode_info *ci, in __ceph_caps_revoking_other() argument
945 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_revoking_other()
954 int ceph_caps_revoking(struct ceph_inode_info *ci, int mask) in ceph_caps_revoking() argument
956 struct inode *inode = &ci->netfs.inode; in ceph_caps_revoking()
959 spin_lock(&ci->i_ceph_lock); in ceph_caps_revoking()
960 ret = __ceph_caps_revoking_other(ci, NULL, mask); in ceph_caps_revoking()
961 spin_unlock(&ci->i_ceph_lock); in ceph_caps_revoking()
967 int __ceph_caps_used(struct ceph_inode_info *ci) in __ceph_caps_used() argument
970 if (ci->i_pin_ref) in __ceph_caps_used()
972 if (ci->i_rd_ref) in __ceph_caps_used()
974 if (ci->i_rdcache_ref || in __ceph_caps_used()
975 (S_ISREG(ci->netfs.inode.i_mode) && in __ceph_caps_used()
976 ci->netfs.inode.i_data.nrpages)) in __ceph_caps_used()
978 if (ci->i_wr_ref) in __ceph_caps_used()
980 if (ci->i_wb_ref || ci->i_wrbuffer_ref) in __ceph_caps_used()
982 if (ci->i_fx_ref) in __ceph_caps_used()
992 int __ceph_caps_file_wanted(struct ceph_inode_info *ci) in __ceph_caps_file_wanted() argument
999 ceph_inode_to_client(&ci->netfs.inode)->mount_options; in __ceph_caps_file_wanted()
1003 if (S_ISDIR(ci->netfs.inode.i_mode)) { in __ceph_caps_file_wanted()
1007 if (ci->i_nr_by_mode[RD_SHIFT] > 0 || in __ceph_caps_file_wanted()
1008 time_after(ci->i_last_rd, used_cutoff)) in __ceph_caps_file_wanted()
1011 if (ci->i_nr_by_mode[WR_SHIFT] > 0 || in __ceph_caps_file_wanted()
1012 time_after(ci->i_last_wr, used_cutoff)) { in __ceph_caps_file_wanted()
1018 if (want || ci->i_nr_by_mode[PIN_SHIFT] > 0) in __ceph_caps_file_wanted()
1025 if (ci->i_nr_by_mode[RD_SHIFT] > 0) { in __ceph_caps_file_wanted()
1026 if (ci->i_nr_by_mode[RD_SHIFT] >= FMODE_WAIT_BIAS || in __ceph_caps_file_wanted()
1027 time_after(ci->i_last_rd, used_cutoff)) in __ceph_caps_file_wanted()
1029 } else if (time_after(ci->i_last_rd, idle_cutoff)) { in __ceph_caps_file_wanted()
1033 if (ci->i_nr_by_mode[WR_SHIFT] > 0) { in __ceph_caps_file_wanted()
1034 if (ci->i_nr_by_mode[WR_SHIFT] >= FMODE_WAIT_BIAS || in __ceph_caps_file_wanted()
1035 time_after(ci->i_last_wr, used_cutoff)) in __ceph_caps_file_wanted()
1037 } else if (time_after(ci->i_last_wr, idle_cutoff)) { in __ceph_caps_file_wanted()
1043 ci->i_nr_by_mode[LAZY_SHIFT] > 0) in __ceph_caps_file_wanted()
1053 int __ceph_caps_wanted(struct ceph_inode_info *ci) in __ceph_caps_wanted() argument
1055 int w = __ceph_caps_file_wanted(ci) | __ceph_caps_used(ci); in __ceph_caps_wanted()
1056 if (S_ISDIR(ci->netfs.inode.i_mode)) { in __ceph_caps_wanted()
1071 int __ceph_caps_mds_wanted(struct ceph_inode_info *ci, bool check) in __ceph_caps_mds_wanted() argument
1077 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_mds_wanted()
1081 if (cap == ci->i_auth_cap) in __ceph_caps_mds_wanted()
1091 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_is_any_caps() local
1094 spin_lock(&ci->i_ceph_lock); in ceph_is_any_caps()
1095 ret = __ceph_is_any_real_caps(ci); in ceph_is_any_caps()
1096 spin_unlock(&ci->i_ceph_lock); in ceph_is_any_caps()
1110 struct ceph_inode_info *ci = cap->ci; in __ceph_remove_cap() local
1115 if (!ci) { in __ceph_remove_cap()
1120 lockdep_assert_held(&ci->i_ceph_lock); in __ceph_remove_cap()
1122 dout("__ceph_remove_cap %p from %p\n", cap, &ci->netfs.inode); in __ceph_remove_cap()
1124 mdsc = ceph_inode_to_client(&ci->netfs.inode)->mdsc; in __ceph_remove_cap()
1127 rb_erase(&cap->ci_node, &ci->i_caps); in __ceph_remove_cap()
1128 if (ci->i_auth_cap == cap) in __ceph_remove_cap()
1129 ci->i_auth_cap = NULL; in __ceph_remove_cap()
1145 cap->ci = NULL; in __ceph_remove_cap()
1162 cap->cap_ino = ci->i_vino.ino; in __ceph_remove_cap()
1169 if (!__ceph_is_any_real_caps(ci)) { in __ceph_remove_cap()
1174 if (ci->i_wr_ref == 0 && ci->i_snap_realm) in __ceph_remove_cap()
1175 ceph_change_snap_realm(&ci->netfs.inode, NULL); in __ceph_remove_cap()
1177 __cap_delay_cancel(mdsc, ci); in __ceph_remove_cap()
1183 struct ceph_inode_info *ci = cap->ci; in ceph_remove_cap() local
1187 if (!ci) { in ceph_remove_cap()
1192 lockdep_assert_held(&ci->i_ceph_lock); in ceph_remove_cap()
1194 fsc = ceph_inode_to_client(&ci->netfs.inode); in ceph_remove_cap()
1195 WARN_ON_ONCE(ci->i_auth_cap == cap && in ceph_remove_cap()
1196 !list_empty(&ci->i_dirty_item) && in ceph_remove_cap()
1198 !ceph_inode_is_shutdown(&ci->netfs.inode)); in ceph_remove_cap()
1343 void __ceph_remove_caps(struct ceph_inode_info *ci) in __ceph_remove_caps() argument
1349 spin_lock(&ci->i_ceph_lock); in __ceph_remove_caps()
1350 p = rb_first(&ci->i_caps); in __ceph_remove_caps()
1356 spin_unlock(&ci->i_ceph_lock); in __ceph_remove_caps()
1371 struct ceph_inode_info *ci = cap->ci; in __prep_cap() local
1372 struct inode *inode = &ci->netfs.inode; in __prep_cap()
1375 lockdep_assert_held(&ci->i_ceph_lock); in __prep_cap()
1387 ci->i_ceph_flags &= ~CEPH_I_FLUSH; in __prep_cap()
1402 arg->follows = flushing ? ci->i_head_snapc->seq : 0; in __prep_cap()
1406 ci->i_reported_size = arg->size; in __prep_cap()
1407 arg->max_size = ci->i_wanted_max_size; in __prep_cap()
1408 if (cap == ci->i_auth_cap) { in __prep_cap()
1410 ci->i_requested_max_size = arg->max_size; in __prep_cap()
1412 ci->i_requested_max_size = 0; in __prep_cap()
1416 arg->old_xattr_buf = __ceph_build_xattrs_blob(ci); in __prep_cap()
1417 arg->xattr_version = ci->i_xattrs.version; in __prep_cap()
1418 arg->xattr_buf = ci->i_xattrs.blob; in __prep_cap()
1427 arg->btime = ci->i_btime; in __prep_cap()
1438 arg->time_warp_seq = ci->i_time_warp_seq; in __prep_cap()
1444 arg->inline_data = ci->i_inline_version != CEPH_INLINE_NONE; in __prep_cap()
1446 !list_empty(&ci->i_cap_snaps)) { in __prep_cap()
1448 list_for_each_entry_reverse(capsnap, &ci->i_cap_snaps, ci_item) { in __prep_cap()
1460 if (ci->fscrypt_auth_len && in __prep_cap()
1461 WARN_ON_ONCE(ci->fscrypt_auth_len > sizeof(struct ceph_fscrypt_auth))) { in __prep_cap()
1465 arg->fscrypt_auth_len = ci->fscrypt_auth_len; in __prep_cap()
1466 memcpy(arg->fscrypt_auth, ci->fscrypt_auth, in __prep_cap()
1467 min_t(size_t, ci->fscrypt_auth_len, in __prep_cap()
1496 static void __send_cap(struct cap_msg_args *arg, struct ceph_inode_info *ci) in __send_cap() argument
1499 struct inode *inode = &ci->netfs.inode; in __send_cap()
1507 spin_lock(&ci->i_ceph_lock); in __send_cap()
1508 __cap_delay_requeue(arg->session->s_mdsc, ci); in __send_cap()
1509 spin_unlock(&ci->i_ceph_lock); in __send_cap()
1517 wake_up_all(&ci->i_cap_wq); in __send_cap()
1588 static void __ceph_flush_snaps(struct ceph_inode_info *ci, in __ceph_flush_snaps() argument
1590 __releases(ci->i_ceph_lock) in __ceph_flush_snaps()
1591 __acquires(ci->i_ceph_lock) in __ceph_flush_snaps()
1593 struct inode *inode = &ci->netfs.inode; in __ceph_flush_snaps()
1601 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { in __ceph_flush_snaps()
1624 if (list_empty(&ci->i_flushing_item)) { in __ceph_flush_snaps()
1625 list_add_tail(&ci->i_flushing_item, in __ceph_flush_snaps()
1631 &ci->i_cap_flush_list); in __ceph_flush_snaps()
1638 ci->i_ceph_flags &= ~CEPH_I_FLUSH_SNAPS; in __ceph_flush_snaps()
1641 struct ceph_cap *cap = ci->i_auth_cap; in __ceph_flush_snaps()
1652 list_for_each_entry(iter, &ci->i_cap_flush_list, i_list) { in __ceph_flush_snaps()
1666 spin_unlock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1680 spin_lock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1684 void ceph_flush_snaps(struct ceph_inode_info *ci, in ceph_flush_snaps() argument
1687 struct inode *inode = &ci->netfs.inode; in ceph_flush_snaps()
1697 spin_lock(&ci->i_ceph_lock); in ceph_flush_snaps()
1698 if (!(ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)) { in ceph_flush_snaps()
1702 if (!ci->i_auth_cap) { in ceph_flush_snaps()
1707 mds = ci->i_auth_cap->session->s_mds; in ceph_flush_snaps()
1714 spin_unlock(&ci->i_ceph_lock); in ceph_flush_snaps()
1722 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) in ceph_flush_snaps()
1723 __kick_flushing_caps(mdsc, session, ci, 0); in ceph_flush_snaps()
1725 __ceph_flush_snaps(ci, session); in ceph_flush_snaps()
1727 spin_unlock(&ci->i_ceph_lock); in ceph_flush_snaps()
1735 if (!list_empty(&ci->i_snap_flush_item)) in ceph_flush_snaps()
1737 list_del_init(&ci->i_snap_flush_item); in ceph_flush_snaps()
1749 int __ceph_mark_dirty_caps(struct ceph_inode_info *ci, int mask, in __ceph_mark_dirty_caps() argument
1753 ceph_sb_to_client(ci->netfs.inode.i_sb)->mdsc; in __ceph_mark_dirty_caps()
1754 struct inode *inode = &ci->netfs.inode; in __ceph_mark_dirty_caps()
1755 int was = ci->i_dirty_caps; in __ceph_mark_dirty_caps()
1758 lockdep_assert_held(&ci->i_ceph_lock); in __ceph_mark_dirty_caps()
1760 if (!ci->i_auth_cap) { in __ceph_mark_dirty_caps()
1767 dout("__mark_dirty_caps %p %s dirty %s -> %s\n", &ci->netfs.inode, in __ceph_mark_dirty_caps()
1770 ci->i_dirty_caps |= mask; in __ceph_mark_dirty_caps()
1772 struct ceph_mds_session *session = ci->i_auth_cap->session; in __ceph_mark_dirty_caps()
1774 WARN_ON_ONCE(ci->i_prealloc_cap_flush); in __ceph_mark_dirty_caps()
1775 swap(ci->i_prealloc_cap_flush, *pcf); in __ceph_mark_dirty_caps()
1777 if (!ci->i_head_snapc) { in __ceph_mark_dirty_caps()
1779 ci->i_head_snapc = ceph_get_snap_context( in __ceph_mark_dirty_caps()
1780 ci->i_snap_realm->cached_context); in __ceph_mark_dirty_caps()
1783 &ci->netfs.inode, ci->i_head_snapc, ci->i_auth_cap); in __ceph_mark_dirty_caps()
1784 BUG_ON(!list_empty(&ci->i_dirty_item)); in __ceph_mark_dirty_caps()
1786 list_add(&ci->i_dirty_item, &session->s_cap_dirty); in __ceph_mark_dirty_caps()
1788 if (ci->i_flushing_caps == 0) { in __ceph_mark_dirty_caps()
1793 WARN_ON_ONCE(!ci->i_prealloc_cap_flush); in __ceph_mark_dirty_caps()
1795 BUG_ON(list_empty(&ci->i_dirty_item)); in __ceph_mark_dirty_caps()
1796 if (((was | ci->i_flushing_caps) & CEPH_CAP_FILE_BUFFER) && in __ceph_mark_dirty_caps()
1799 __cap_delay_requeue(mdsc, ci); in __ceph_mark_dirty_caps()
1851 static bool __detach_cap_flush_from_ci(struct ceph_inode_info *ci, in __detach_cap_flush_from_ci() argument
1857 if (wake && cf->i_list.prev != &ci->i_cap_flush_list) { in __detach_cap_flush_from_ci()
1877 struct ceph_inode_info *ci = ceph_inode(inode); in __mark_caps_flushing() local
1881 lockdep_assert_held(&ci->i_ceph_lock); in __mark_caps_flushing()
1882 BUG_ON(ci->i_dirty_caps == 0); in __mark_caps_flushing()
1883 BUG_ON(list_empty(&ci->i_dirty_item)); in __mark_caps_flushing()
1884 BUG_ON(!ci->i_prealloc_cap_flush); in __mark_caps_flushing()
1886 flushing = ci->i_dirty_caps; in __mark_caps_flushing()
1889 ceph_cap_string(ci->i_flushing_caps), in __mark_caps_flushing()
1890 ceph_cap_string(ci->i_flushing_caps | flushing)); in __mark_caps_flushing()
1891 ci->i_flushing_caps |= flushing; in __mark_caps_flushing()
1892 ci->i_dirty_caps = 0; in __mark_caps_flushing()
1895 swap(cf, ci->i_prealloc_cap_flush); in __mark_caps_flushing()
1900 list_del_init(&ci->i_dirty_item); in __mark_caps_flushing()
1906 if (list_empty(&ci->i_flushing_item)) { in __mark_caps_flushing()
1907 list_add_tail(&ci->i_flushing_item, &session->s_cap_flushing); in __mark_caps_flushing()
1912 list_add_tail(&cf->i_list, &ci->i_cap_flush_list); in __mark_caps_flushing()
1921 __releases(ci->i_ceph_lock) in try_nonblocking_invalidate()
1922 __acquires(ci->i_ceph_lock) in try_nonblocking_invalidate()
1924 struct ceph_inode_info *ci = ceph_inode(inode); in try_nonblocking_invalidate() local
1925 u32 invalidating_gen = ci->i_rdcache_gen; in try_nonblocking_invalidate()
1927 spin_unlock(&ci->i_ceph_lock); in try_nonblocking_invalidate()
1930 spin_lock(&ci->i_ceph_lock); in try_nonblocking_invalidate()
1933 invalidating_gen == ci->i_rdcache_gen) { in try_nonblocking_invalidate()
1937 ci->i_rdcache_revoking = ci->i_rdcache_gen - 1; in try_nonblocking_invalidate()
1944 bool __ceph_should_report_size(struct ceph_inode_info *ci) in __ceph_should_report_size() argument
1946 loff_t size = i_size_read(&ci->netfs.inode); in __ceph_should_report_size()
1948 if (ci->i_flushing_caps & CEPH_CAP_FILE_WR) in __ceph_should_report_size()
1950 if (size >= ci->i_max_size) in __ceph_should_report_size()
1953 if (ci->i_max_size > ci->i_reported_size && in __ceph_should_report_size()
1954 (size << 1) >= ci->i_max_size + ci->i_reported_size) in __ceph_should_report_size()
1968 void ceph_check_caps(struct ceph_inode_info *ci, int flags) in ceph_check_caps() argument
1970 struct inode *inode = &ci->netfs.inode; in ceph_check_caps()
1984 spin_lock(&ci->i_ceph_lock); in ceph_check_caps()
1985 if (ci->i_ceph_flags & CEPH_I_ASYNC_CREATE) { in ceph_check_caps()
1986 ci->i_ceph_flags |= CEPH_I_ASYNC_CHECK_CAPS; in ceph_check_caps()
1989 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
1993 if (ci->i_ceph_flags & CEPH_I_FLUSH) in ceph_check_caps()
1997 file_wanted = __ceph_caps_file_wanted(ci); in ceph_check_caps()
2000 used = __ceph_caps_used(ci); in ceph_check_caps()
2008 issued = __ceph_caps_issued(ci, &implemented); in ceph_check_caps()
2020 __ceph_dir_is_complete(ci)) { in ceph_check_caps()
2041 if (ci->i_max_size == 0) in ceph_check_caps()
2049 ceph_cap_string(used), ceph_cap_string(ci->i_dirty_caps), in ceph_check_caps()
2050 ceph_cap_string(ci->i_flushing_caps), in ceph_check_caps()
2064 !(ci->i_wb_ref || ci->i_wrbuffer_ref) && /* no dirty pages... */ in ceph_check_caps()
2074 ci->i_rdcache_revoking = ci->i_rdcache_gen; in ceph_check_caps()
2080 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in ceph_check_caps()
2088 ((flags & CHECK_CAPS_AUTHONLY) && cap != ci->i_auth_cap)) in ceph_check_caps()
2096 if (ci->i_auth_cap && cap != ci->i_auth_cap) in ceph_check_caps()
2097 cap_used &= ~ci->i_auth_cap->issued; in ceph_check_caps()
2106 if (cap == ci->i_auth_cap && in ceph_check_caps()
2109 if (ci->i_wanted_max_size > ci->i_max_size && in ceph_check_caps()
2110 ci->i_wanted_max_size > ci->i_requested_max_size) { in ceph_check_caps()
2116 if (__ceph_should_report_size(ci)) { in ceph_check_caps()
2122 if (cap == ci->i_auth_cap) { in ceph_check_caps()
2123 if ((flags & CHECK_CAPS_FLUSH) && ci->i_dirty_caps) { in ceph_check_caps()
2127 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) { in ceph_check_caps()
2152 if (S_ISREG(inode->i_mode) && ci->i_wrbuffer_ref && in ceph_check_caps()
2175 if (cap == ci->i_auth_cap && in ceph_check_caps()
2176 (ci->i_ceph_flags & in ceph_check_caps()
2178 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) in ceph_check_caps()
2179 __kick_flushing_caps(mdsc, session, ci, 0); in ceph_check_caps()
2180 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) in ceph_check_caps()
2181 __ceph_flush_snaps(ci, session); in ceph_check_caps()
2186 if (cap == ci->i_auth_cap && ci->i_dirty_caps) { in ceph_check_caps()
2187 flushing = ci->i_dirty_caps; in ceph_check_caps()
2206 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
2207 __send_cap(&arg, ci); in ceph_check_caps()
2208 spin_lock(&ci->i_ceph_lock); in ceph_check_caps()
2214 if (__ceph_is_any_real_caps(ci) && in ceph_check_caps()
2215 list_empty(&ci->i_cap_delay_list) && in ceph_check_caps()
2218 __cap_delay_requeue(mdsc, ci); in ceph_check_caps()
2221 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
2236 struct ceph_inode_info *ci = ceph_inode(inode); in try_flush_caps() local
2240 spin_lock(&ci->i_ceph_lock); in try_flush_caps()
2242 if (ci->i_dirty_caps && ci->i_auth_cap) { in try_flush_caps()
2243 struct ceph_cap *cap = ci->i_auth_cap; in try_flush_caps()
2248 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2252 if (ci->i_ceph_flags & in try_flush_caps()
2254 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) in try_flush_caps()
2255 __kick_flushing_caps(mdsc, session, ci, 0); in try_flush_caps()
2256 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) in try_flush_caps()
2257 __ceph_flush_snaps(ci, session); in try_flush_caps()
2261 flushing = ci->i_dirty_caps; in try_flush_caps()
2266 __ceph_caps_used(ci), __ceph_caps_wanted(ci), in try_flush_caps()
2269 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2271 __send_cap(&arg, ci); in try_flush_caps()
2273 if (!list_empty(&ci->i_cap_flush_list)) { in try_flush_caps()
2275 list_last_entry(&ci->i_cap_flush_list, in try_flush_caps()
2280 flushing = ci->i_flushing_caps; in try_flush_caps()
2281 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2293 struct ceph_inode_info *ci = ceph_inode(inode); in caps_are_flushed() local
2296 spin_lock(&ci->i_ceph_lock); in caps_are_flushed()
2297 if (!list_empty(&ci->i_cap_flush_list)) { in caps_are_flushed()
2299 list_first_entry(&ci->i_cap_flush_list, in caps_are_flushed()
2304 spin_unlock(&ci->i_ceph_lock); in caps_are_flushed()
2314 struct ceph_inode_info *ci = ceph_inode(inode); in flush_mdlog_and_wait_inode_unsafe_requests() local
2318 spin_lock(&ci->i_unsafe_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2319 if (S_ISDIR(inode->i_mode) && !list_empty(&ci->i_unsafe_dirops)) { in flush_mdlog_and_wait_inode_unsafe_requests()
2320 req1 = list_last_entry(&ci->i_unsafe_dirops, in flush_mdlog_and_wait_inode_unsafe_requests()
2325 if (!list_empty(&ci->i_unsafe_iops)) { in flush_mdlog_and_wait_inode_unsafe_requests()
2326 req2 = list_last_entry(&ci->i_unsafe_iops, in flush_mdlog_and_wait_inode_unsafe_requests()
2331 spin_unlock(&ci->i_unsafe_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2355 spin_lock(&ci->i_unsafe_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2357 list_for_each_entry(req, &ci->i_unsafe_dirops, in flush_mdlog_and_wait_inode_unsafe_requests()
2369 list_for_each_entry(req, &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()
2383 spin_lock(&ci->i_ceph_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2384 if (ci->i_auth_cap) { in flush_mdlog_and_wait_inode_unsafe_requests()
2385 s = ci->i_auth_cap->session; in flush_mdlog_and_wait_inode_unsafe_requests()
2389 spin_unlock(&ci->i_ceph_lock); in flush_mdlog_and_wait_inode_unsafe_requests()
2429 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_fsync() local
2455 err = wait_event_interruptible(ci->i_cap_wq, in ceph_fsync()
2478 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_write_inode() local
2492 err = wait_event_interruptible(ci->i_cap_wq, in ceph_write_inode()
2498 spin_lock(&ci->i_ceph_lock); in ceph_write_inode()
2499 if (__ceph_caps_dirty(ci)) in ceph_write_inode()
2500 __cap_delay_requeue_front(mdsc, ci); in ceph_write_inode()
2501 spin_unlock(&ci->i_ceph_lock); in ceph_write_inode()
2508 struct ceph_inode_info *ci, in __kick_flushing_caps() argument
2510 __releases(ci->i_ceph_lock) in __kick_flushing_caps()
2511 __acquires(ci->i_ceph_lock) in __kick_flushing_caps()
2513 struct inode *inode = &ci->netfs.inode; in __kick_flushing_caps()
2521 if (ci->i_ceph_flags & CEPH_I_ASYNC_CREATE) in __kick_flushing_caps()
2524 ci->i_ceph_flags &= ~CEPH_I_KICK_FLUSH; in __kick_flushing_caps()
2526 list_for_each_entry_reverse(cf, &ci->i_cap_flush_list, i_list) { in __kick_flushing_caps()
2533 list_for_each_entry(cf, &ci->i_cap_flush_list, i_list) { in __kick_flushing_caps()
2537 cap = ci->i_auth_cap; in __kick_flushing_caps()
2554 __ceph_caps_used(ci), in __kick_flushing_caps()
2555 __ceph_caps_wanted(ci), in __kick_flushing_caps()
2558 spin_unlock(&ci->i_ceph_lock); in __kick_flushing_caps()
2559 __send_cap(&arg, ci); in __kick_flushing_caps()
2569 spin_unlock(&ci->i_ceph_lock); in __kick_flushing_caps()
2584 spin_lock(&ci->i_ceph_lock); in __kick_flushing_caps()
2591 struct ceph_inode_info *ci; in ceph_early_kick_flushing_caps() local
2601 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) { in ceph_early_kick_flushing_caps()
2602 spin_lock(&ci->i_ceph_lock); in ceph_early_kick_flushing_caps()
2603 cap = ci->i_auth_cap; in ceph_early_kick_flushing_caps()
2606 &ci->netfs.inode, cap, session->s_mds); in ceph_early_kick_flushing_caps()
2607 spin_unlock(&ci->i_ceph_lock); in ceph_early_kick_flushing_caps()
2618 if ((cap->issued & ci->i_flushing_caps) != in ceph_early_kick_flushing_caps()
2619 ci->i_flushing_caps) { in ceph_early_kick_flushing_caps()
2626 __kick_flushing_caps(mdsc, session, ci, in ceph_early_kick_flushing_caps()
2629 ci->i_ceph_flags |= CEPH_I_KICK_FLUSH; in ceph_early_kick_flushing_caps()
2632 spin_unlock(&ci->i_ceph_lock); in ceph_early_kick_flushing_caps()
2639 struct ceph_inode_info *ci; in ceph_kick_flushing_caps() local
2651 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) { in ceph_kick_flushing_caps()
2652 spin_lock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2653 cap = ci->i_auth_cap; in ceph_kick_flushing_caps()
2656 &ci->netfs.inode, cap, session->s_mds); in ceph_kick_flushing_caps()
2657 spin_unlock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2660 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) { in ceph_kick_flushing_caps()
2661 __kick_flushing_caps(mdsc, session, ci, in ceph_kick_flushing_caps()
2664 spin_unlock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2669 struct ceph_inode_info *ci) in ceph_kick_flushing_inode_caps() argument
2672 struct ceph_cap *cap = ci->i_auth_cap; in ceph_kick_flushing_inode_caps()
2674 lockdep_assert_held(&ci->i_ceph_lock); in ceph_kick_flushing_inode_caps()
2676 dout("%s %p flushing %s\n", __func__, &ci->netfs.inode, in ceph_kick_flushing_inode_caps()
2677 ceph_cap_string(ci->i_flushing_caps)); in ceph_kick_flushing_inode_caps()
2679 if (!list_empty(&ci->i_cap_flush_list)) { in ceph_kick_flushing_inode_caps()
2682 list_move_tail(&ci->i_flushing_item, in ceph_kick_flushing_inode_caps()
2687 __kick_flushing_caps(mdsc, session, ci, oldest_flush_tid); in ceph_kick_flushing_inode_caps()
2696 void ceph_take_cap_refs(struct ceph_inode_info *ci, int got, in ceph_take_cap_refs() argument
2699 lockdep_assert_held(&ci->i_ceph_lock); in ceph_take_cap_refs()
2702 ci->i_pin_ref++; in ceph_take_cap_refs()
2704 ci->i_rd_ref++; in ceph_take_cap_refs()
2706 ci->i_rdcache_ref++; in ceph_take_cap_refs()
2708 ci->i_fx_ref++; in ceph_take_cap_refs()
2710 if (ci->i_wr_ref == 0 && !ci->i_head_snapc) { in ceph_take_cap_refs()
2712 ci->i_head_snapc = ceph_get_snap_context( in ceph_take_cap_refs()
2713 ci->i_snap_realm->cached_context); in ceph_take_cap_refs()
2715 ci->i_wr_ref++; in ceph_take_cap_refs()
2718 if (ci->i_wb_ref == 0) in ceph_take_cap_refs()
2719 ihold(&ci->netfs.inode); in ceph_take_cap_refs()
2720 ci->i_wb_ref++; in ceph_take_cap_refs()
2722 &ci->netfs.inode, ci->i_wb_ref-1, ci->i_wb_ref); in ceph_take_cap_refs()
2748 struct ceph_inode_info *ci = ceph_inode(inode); in try_get_cap_refs() local
2758 spin_lock(&ci->i_ceph_lock); in try_get_cap_refs()
2761 (ci->i_ceph_flags & CEPH_I_ERROR_FILELOCK)) { in try_get_cap_refs()
2768 while (ci->i_truncate_pending) { in try_get_cap_refs()
2769 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2775 spin_lock(&ci->i_ceph_lock); in try_get_cap_refs()
2778 have = __ceph_caps_issued(ci, &implemented); in try_get_cap_refs()
2781 if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) { in try_get_cap_refs()
2783 inode, endoff, ci->i_max_size); in try_get_cap_refs()
2784 if (endoff > ci->i_requested_max_size) in try_get_cap_refs()
2785 ret = ci->i_auth_cap ? -EFBIG : -EUCLEAN; in try_get_cap_refs()
2792 if (__ceph_have_pending_cap_snap(ci)) { in try_get_cap_refs()
2816 !ci->i_head_snapc && in try_get_cap_refs()
2828 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2839 ceph_take_cap_refs(ci, *got, true); in try_get_cap_refs()
2845 if (ci->i_auth_cap && in try_get_cap_refs()
2847 struct ceph_mds_session *s = ci->i_auth_cap->session; in try_get_cap_refs()
2854 inode, ceph_cap_string(need), ci->i_auth_cap->mds); in try_get_cap_refs()
2864 mds_wanted = __ceph_caps_mds_wanted(ci, false); in try_get_cap_refs()
2878 __ceph_touch_fmode(ci, mdsc, flags); in try_get_cap_refs()
2880 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2901 struct ceph_inode_info *ci = ceph_inode(inode); in check_max_size() local
2905 spin_lock(&ci->i_ceph_lock); in check_max_size()
2906 if (endoff >= ci->i_max_size && endoff > ci->i_wanted_max_size) { in check_max_size()
2909 ci->i_wanted_max_size = endoff; in check_max_size()
2912 if (ci->i_auth_cap && in check_max_size()
2913 (ci->i_auth_cap->issued & CEPH_CAP_FILE_WR) && in check_max_size()
2914 ci->i_wanted_max_size > ci->i_max_size && in check_max_size()
2915 ci->i_wanted_max_size > ci->i_requested_max_size) in check_max_size()
2917 spin_unlock(&ci->i_ceph_lock); in check_max_size()
2919 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY); in check_max_size()
2966 struct ceph_inode_info *ci = ceph_inode(inode); in __ceph_get_caps() local
3003 ceph_get_fmode(ci, flags, FMODE_WAIT_BIAS); in __ceph_get_caps()
3004 add_wait_queue(&ci->i_cap_wq, &wait); in __ceph_get_caps()
3016 remove_wait_queue(&ci->i_cap_wq, &wait); in __ceph_get_caps()
3017 ceph_put_fmode(ci, flags, FMODE_WAIT_BIAS); in __ceph_get_caps()
3030 ceph_put_cap_refs(ci, _got); in __ceph_get_caps()
3053 if (S_ISREG(ci->netfs.inode.i_mode) && in __ceph_get_caps()
3054 ceph_has_inline_data(ci) && in __ceph_get_caps()
3070 ceph_put_cap_refs(ci, _got); in __ceph_get_caps()
3103 void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps) in ceph_get_cap_refs() argument
3105 spin_lock(&ci->i_ceph_lock); in ceph_get_cap_refs()
3106 ceph_take_cap_refs(ci, caps, false); in ceph_get_cap_refs()
3107 spin_unlock(&ci->i_ceph_lock); in ceph_get_cap_refs()
3115 static int ceph_try_drop_cap_snap(struct ceph_inode_info *ci, in ceph_try_drop_cap_snap() argument
3124 if (!list_is_last(&capsnap->ci_item, &ci->i_cap_snaps)) in ceph_try_drop_cap_snap()
3125 ci->i_ceph_flags |= CEPH_I_FLUSH_SNAPS; in ceph_try_drop_cap_snap()
3149 static void __ceph_put_cap_refs(struct ceph_inode_info *ci, int had, in __ceph_put_cap_refs() argument
3152 struct inode *inode = &ci->netfs.inode; in __ceph_put_cap_refs()
3156 spin_lock(&ci->i_ceph_lock); in __ceph_put_cap_refs()
3158 --ci->i_pin_ref; in __ceph_put_cap_refs()
3160 if (--ci->i_rd_ref == 0) in __ceph_put_cap_refs()
3163 if (--ci->i_rdcache_ref == 0) in __ceph_put_cap_refs()
3166 if (--ci->i_fx_ref == 0) in __ceph_put_cap_refs()
3169 if (--ci->i_wb_ref == 0) { in __ceph_put_cap_refs()
3176 inode, ci->i_wb_ref+1, ci->i_wb_ref); in __ceph_put_cap_refs()
3179 if (--ci->i_wr_ref == 0) { in __ceph_put_cap_refs()
3184 WARN_ON_ONCE(ci->i_wb_ref); in __ceph_put_cap_refs()
3188 if (ci->i_wrbuffer_ref_head == 0 && in __ceph_put_cap_refs()
3189 ci->i_dirty_caps == 0 && in __ceph_put_cap_refs()
3190 ci->i_flushing_caps == 0) { in __ceph_put_cap_refs()
3191 BUG_ON(!ci->i_head_snapc); in __ceph_put_cap_refs()
3192 ceph_put_snap_context(ci->i_head_snapc); in __ceph_put_cap_refs()
3193 ci->i_head_snapc = NULL; in __ceph_put_cap_refs()
3196 if (!__ceph_is_any_real_caps(ci) && ci->i_snap_realm) in __ceph_put_cap_refs()
3200 if (check_flushsnaps && __ceph_have_pending_cap_snap(ci)) { in __ceph_put_cap_refs()
3202 list_last_entry(&ci->i_cap_snaps, in __ceph_put_cap_refs()
3207 if (ceph_try_drop_cap_snap(ci, capsnap)) in __ceph_put_cap_refs()
3210 else if (__ceph_finish_cap_snap(ci, capsnap)) in __ceph_put_cap_refs()
3214 spin_unlock(&ci->i_ceph_lock); in __ceph_put_cap_refs()
3222 ceph_check_caps(ci, 0); in __ceph_put_cap_refs()
3224 ceph_flush_snaps(ci, NULL); in __ceph_put_cap_refs()
3236 wake_up_all(&ci->i_cap_wq); in __ceph_put_cap_refs()
3241 void ceph_put_cap_refs(struct ceph_inode_info *ci, int had) in ceph_put_cap_refs() argument
3243 __ceph_put_cap_refs(ci, had, PUT_CAP_REFS_SYNC); in ceph_put_cap_refs()
3246 void ceph_put_cap_refs_async(struct ceph_inode_info *ci, int had) in ceph_put_cap_refs_async() argument
3248 __ceph_put_cap_refs(ci, had, PUT_CAP_REFS_ASYNC); in ceph_put_cap_refs_async()
3251 void ceph_put_cap_refs_no_check_caps(struct ceph_inode_info *ci, int had) in ceph_put_cap_refs_no_check_caps() argument
3253 __ceph_put_cap_refs(ci, had, PUT_CAP_REFS_NO_CHECK); in ceph_put_cap_refs_no_check_caps()
3263 void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr, in ceph_put_wrbuffer_cap_refs() argument
3266 struct inode *inode = &ci->netfs.inode; in ceph_put_wrbuffer_cap_refs()
3273 spin_lock(&ci->i_ceph_lock); in ceph_put_wrbuffer_cap_refs()
3274 ci->i_wrbuffer_ref -= nr; in ceph_put_wrbuffer_cap_refs()
3275 if (ci->i_wrbuffer_ref == 0) { in ceph_put_wrbuffer_cap_refs()
3280 if (ci->i_head_snapc == snapc) { in ceph_put_wrbuffer_cap_refs()
3281 ci->i_wrbuffer_ref_head -= nr; in ceph_put_wrbuffer_cap_refs()
3282 if (ci->i_wrbuffer_ref_head == 0 && in ceph_put_wrbuffer_cap_refs()
3283 ci->i_wr_ref == 0 && in ceph_put_wrbuffer_cap_refs()
3284 ci->i_dirty_caps == 0 && in ceph_put_wrbuffer_cap_refs()
3285 ci->i_flushing_caps == 0) { in ceph_put_wrbuffer_cap_refs()
3286 BUG_ON(!ci->i_head_snapc); in ceph_put_wrbuffer_cap_refs()
3287 ceph_put_snap_context(ci->i_head_snapc); in ceph_put_wrbuffer_cap_refs()
3288 ci->i_head_snapc = NULL; in ceph_put_wrbuffer_cap_refs()
3292 ci->i_wrbuffer_ref+nr, ci->i_wrbuffer_ref_head+nr, in ceph_put_wrbuffer_cap_refs()
3293 ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head, in ceph_put_wrbuffer_cap_refs()
3296 list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) { in ceph_put_wrbuffer_cap_refs()
3308 WARN_ON_ONCE(ci->i_auth_cap); in ceph_put_wrbuffer_cap_refs()
3316 if (ceph_try_drop_cap_snap(ci, capsnap)) { in ceph_put_wrbuffer_cap_refs()
3319 ci->i_ceph_flags |= CEPH_I_FLUSH_SNAPS; in ceph_put_wrbuffer_cap_refs()
3327 ci->i_wrbuffer_ref+nr, capsnap->dirty_pages + nr, in ceph_put_wrbuffer_cap_refs()
3328 ci->i_wrbuffer_ref, capsnap->dirty_pages, in ceph_put_wrbuffer_cap_refs()
3334 spin_unlock(&ci->i_ceph_lock); in ceph_put_wrbuffer_cap_refs()
3337 ceph_check_caps(ci, 0); in ceph_put_wrbuffer_cap_refs()
3339 ceph_flush_snaps(ci, NULL); in ceph_put_wrbuffer_cap_refs()
3342 wake_up_all(&ci->i_cap_wq); in ceph_put_wrbuffer_cap_refs()
3411 __releases(ci->i_ceph_lock) in handle_cap_grant()
3414 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_grant() local
3451 !(ci->i_wrbuffer_ref || ci->i_wb_ref)) { in handle_cap_grant()
3455 if (ci->i_rdcache_revoking != ci->i_rdcache_gen) { in handle_cap_grant()
3457 ci->i_rdcache_revoking = ci->i_rdcache_gen; in handle_cap_grant()
3474 WARN_ON(cap != ci->i_auth_cap); in handle_cap_grant()
3484 __check_cap_issue(ci, cap, newcaps); in handle_cap_grant()
3499 ci->i_btime = extra_info->btime; in handle_cap_grant()
3504 if (ci->fscrypt_auth_len != extra_info->fscrypt_auth_len || in handle_cap_grant()
3505 memcmp(ci->fscrypt_auth, extra_info->fscrypt_auth, in handle_cap_grant()
3506 ci->fscrypt_auth_len)) in handle_cap_grant()
3508 __func__, ci->fscrypt_auth_len, in handle_cap_grant()
3525 if (version > ci->i_xattrs.version) { in handle_cap_grant()
3528 if (ci->i_xattrs.blob) in handle_cap_grant()
3529 ceph_buffer_put(ci->i_xattrs.blob); in handle_cap_grant()
3530 ci->i_xattrs.blob = ceph_buffer_get(xattr_buf); in handle_cap_grant()
3531 ci->i_xattrs.version = version; in handle_cap_grant()
3549 ci->i_files = extra_info->nfiles; in handle_cap_grant()
3550 ci->i_subdirs = extra_info->nsubdirs; in handle_cap_grant()
3555 s64 old_pool = ci->i_layout.pool_id; in handle_cap_grant()
3558 ceph_file_layout_from_legacy(&ci->i_layout, &grant->layout); in handle_cap_grant()
3559 old_ns = rcu_dereference_protected(ci->i_layout.pool_ns, in handle_cap_grant()
3560 lockdep_is_held(&ci->i_ceph_lock)); in handle_cap_grant()
3561 rcu_assign_pointer(ci->i_layout.pool_ns, extra_info->pool_ns); in handle_cap_grant()
3563 if (ci->i_layout.pool_id != old_pool || in handle_cap_grant()
3565 ci->i_ceph_flags &= ~CEPH_I_POOL_PERM; in handle_cap_grant()
3576 if (ci->i_auth_cap == cap && (newcaps & CEPH_CAP_ANY_FILE_WR)) { in handle_cap_grant()
3577 if (max_size != ci->i_max_size) { in handle_cap_grant()
3579 ci->i_max_size, max_size); in handle_cap_grant()
3580 ci->i_max_size = max_size; in handle_cap_grant()
3581 if (max_size >= ci->i_wanted_max_size) { in handle_cap_grant()
3582 ci->i_wanted_max_size = 0; /* reset */ in handle_cap_grant()
3583 ci->i_requested_max_size = 0; in handle_cap_grant()
3590 wanted = __ceph_caps_wanted(ci); in handle_cap_grant()
3591 used = __ceph_caps_used(ci); in handle_cap_grant()
3592 dirty = __ceph_caps_dirty(ci); in handle_cap_grant()
3628 else if (cap == ci->i_auth_cap) in handle_cap_grant()
3644 if (cap == ci->i_auth_cap && in handle_cap_grant()
3645 __ceph_caps_revoking_other(ci, cap, newcaps)) in handle_cap_grant()
3659 if (cap == ci->i_auth_cap) in handle_cap_grant()
3666 extra_info->inline_version >= ci->i_inline_version) { in handle_cap_grant()
3667 ci->i_inline_version = extra_info->inline_version; in handle_cap_grant()
3668 if (ci->i_inline_version != CEPH_INLINE_NONE && in handle_cap_grant()
3674 if (ci->i_auth_cap == cap) { in handle_cap_grant()
3678 if (ci->i_requested_max_size > max_size || in handle_cap_grant()
3681 ci->i_requested_max_size = 0; in handle_cap_grant()
3685 ceph_kick_flushing_inode_caps(session, ci); in handle_cap_grant()
3689 spin_unlock(&ci->i_ceph_lock); in handle_cap_grant()
3710 wake_up_all(&ci->i_cap_wq); in handle_cap_grant()
3714 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY | CHECK_CAPS_NOINVAL); in handle_cap_grant()
3716 ceph_check_caps(ci, CHECK_CAPS_NOINVAL); in handle_cap_grant()
3727 __releases(ci->i_ceph_lock) in handle_cap_flush_ack()
3729 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_flush_ack() local
3740 list_for_each_entry_safe(cf, tmp_cf, &ci->i_cap_flush_list, i_list) { in handle_cap_flush_ack()
3754 wake_ci |= __detach_cap_flush_from_ci(ci, cf); in handle_cap_flush_ack()
3770 ceph_cap_string(cleaned), ceph_cap_string(ci->i_flushing_caps), in handle_cap_flush_ack()
3771 ceph_cap_string(ci->i_flushing_caps & ~cleaned)); in handle_cap_flush_ack()
3776 ci->i_flushing_caps &= ~cleaned; in handle_cap_flush_ack()
3783 if (ci->i_flushing_caps == 0) { in handle_cap_flush_ack()
3784 if (list_empty(&ci->i_cap_flush_list)) { in handle_cap_flush_ack()
3785 list_del_init(&ci->i_flushing_item); in handle_cap_flush_ack()
3797 if (ci->i_dirty_caps == 0) { in handle_cap_flush_ack()
3799 BUG_ON(!list_empty(&ci->i_dirty_item)); in handle_cap_flush_ack()
3801 if (ci->i_wr_ref == 0 && in handle_cap_flush_ack()
3802 ci->i_wrbuffer_ref_head == 0) { in handle_cap_flush_ack()
3803 BUG_ON(!ci->i_head_snapc); in handle_cap_flush_ack()
3804 ceph_put_snap_context(ci->i_head_snapc); in handle_cap_flush_ack()
3805 ci->i_head_snapc = NULL; in handle_cap_flush_ack()
3808 BUG_ON(list_empty(&ci->i_dirty_item)); in handle_cap_flush_ack()
3814 spin_unlock(&ci->i_ceph_lock); in handle_cap_flush_ack()
3825 wake_up_all(&ci->i_cap_wq); in handle_cap_flush_ack()
3835 struct ceph_inode_info *ci = ceph_inode(inode); in __ceph_remove_capsnap() local
3839 lockdep_assert_held(&ci->i_ceph_lock); in __ceph_remove_capsnap()
3841 dout("removing capsnap %p, inode %p ci %p\n", capsnap, inode, ci); in __ceph_remove_capsnap()
3844 ret = __detach_cap_flush_from_ci(ci, &capsnap->cap_flush); in __ceph_remove_capsnap()
3849 if (list_empty(&ci->i_cap_flush_list)) in __ceph_remove_capsnap()
3850 list_del_init(&ci->i_flushing_item); in __ceph_remove_capsnap()
3861 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_remove_capsnap() local
3863 lockdep_assert_held(&ci->i_ceph_lock); in ceph_remove_capsnap()
3879 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_flushsnap_ack() local
3887 inode, ci, session->s_mds, follows); in handle_cap_flushsnap_ack()
3889 spin_lock(&ci->i_ceph_lock); in handle_cap_flushsnap_ack()
3890 list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) { in handle_cap_flushsnap_ack()
3907 spin_unlock(&ci->i_ceph_lock); in handle_cap_flushsnap_ack()
3913 wake_up_all(&ci->i_cap_wq); in handle_cap_flushsnap_ack()
3930 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_trunc() local
3937 int dirty = __ceph_caps_dirty(ci); in handle_cap_trunc()
3941 lockdep_assert_held(&ci->i_ceph_lock); in handle_cap_trunc()
3975 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_export() local
3993 inode, ci, mds, mseq, target); in handle_cap_export()
3996 spin_lock(&ci->i_ceph_lock); in handle_cap_export()
3997 cap = __get_cap_for_mds(ci, mds); in handle_cap_export()
4021 tcap = __get_cap_for_mds(ci, target); in handle_cap_export()
4032 if (cap == ci->i_auth_cap) { in handle_cap_export()
4033 ci->i_auth_cap = tcap; in handle_cap_export()
4034 change_auth_cap_ses(ci, tcap->session); in handle_cap_export()
4041 int flag = (cap == ci->i_auth_cap) ? CEPH_CAP_FLAG_AUTH : 0; in handle_cap_export()
4046 if (!list_empty(&ci->i_cap_flush_list) && in handle_cap_export()
4047 ci->i_auth_cap == tcap) { in handle_cap_export()
4049 list_move_tail(&ci->i_flushing_item, in handle_cap_export()
4058 spin_unlock(&ci->i_ceph_lock); in handle_cap_export()
4084 spin_unlock(&ci->i_ceph_lock); in handle_cap_export()
4106 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_import() local
4128 inode, ci, mds, mseq, peer); in handle_cap_import()
4130 cap = __get_cap_for_mds(ci, mds); in handle_cap_import()
4133 spin_unlock(&ci->i_ceph_lock); in handle_cap_import()
4135 spin_lock(&ci->i_ceph_lock); in handle_cap_import()
4146 __ceph_caps_issued(ci, &issued); in handle_cap_import()
4147 issued |= __ceph_caps_dirty(ci); in handle_cap_import()
4152 ocap = peer >= 0 ? __get_cap_for_mds(ci, peer) : NULL; in handle_cap_import()
4231 struct ceph_inode_info *ci; in ceph_handle_caps() local
4371 ci = ceph_inode(inode); in ceph_handle_caps()
4399 spin_lock(&ci->i_ceph_lock); in ceph_handle_caps()
4410 spin_lock(&ci->i_ceph_lock); in ceph_handle_caps()
4416 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
4432 __ceph_caps_issued(ci, &extra_info.issued); in ceph_handle_caps()
4433 extra_info.issued |= __ceph_caps_dirty(ci); in ceph_handle_caps()
4446 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
4452 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
4510 struct ceph_inode_info *ci; in ceph_check_delayed_caps() local
4519 ci = list_first_entry(&mdsc->cap_delay_list, in ceph_check_delayed_caps()
4522 if (time_before(loop_start, ci->i_hold_caps_max - delay_max)) { in ceph_check_delayed_caps()
4524 delay = ci->i_hold_caps_max; in ceph_check_delayed_caps()
4527 if ((ci->i_ceph_flags & CEPH_I_FLUSH) == 0 && in ceph_check_delayed_caps()
4528 time_before(jiffies, ci->i_hold_caps_max)) in ceph_check_delayed_caps()
4530 list_del_init(&ci->i_cap_delay_list); in ceph_check_delayed_caps()
4532 inode = igrab(&ci->netfs.inode); in ceph_check_delayed_caps()
4536 ceph_check_caps(ci, 0); in ceph_check_delayed_caps()
4552 struct ceph_inode_info *ci; in flush_dirty_session_caps() local
4558 ci = list_first_entry(&s->s_cap_dirty, struct ceph_inode_info, in flush_dirty_session_caps()
4560 inode = &ci->netfs.inode; in flush_dirty_session_caps()
4565 ceph_check_caps(ci, CHECK_CAPS_FLUSH); in flush_dirty_session_caps()
4578 void __ceph_touch_fmode(struct ceph_inode_info *ci, in __ceph_touch_fmode() argument
4583 ci->i_last_rd = now; in __ceph_touch_fmode()
4585 ci->i_last_wr = now; in __ceph_touch_fmode()
4588 __ceph_is_any_real_caps(ci) && in __ceph_touch_fmode()
4589 list_empty(&ci->i_cap_delay_list)) in __ceph_touch_fmode()
4590 __cap_delay_requeue(mdsc, ci); in __ceph_touch_fmode()
4593 void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count) in ceph_get_fmode() argument
4595 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->netfs.inode.i_sb); in ceph_get_fmode()
4603 spin_lock(&ci->i_ceph_lock); in ceph_get_fmode()
4610 if (i && ci->i_nr_by_mode[i]) in ceph_get_fmode()
4614 ci->i_nr_by_mode[i] += count; in ceph_get_fmode()
4619 spin_unlock(&ci->i_ceph_lock); in ceph_get_fmode()
4627 void ceph_put_fmode(struct ceph_inode_info *ci, int fmode, int count) in ceph_put_fmode() argument
4629 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->netfs.inode.i_sb); in ceph_put_fmode()
4637 spin_lock(&ci->i_ceph_lock); in ceph_put_fmode()
4640 BUG_ON(ci->i_nr_by_mode[i] < count); in ceph_put_fmode()
4641 ci->i_nr_by_mode[i] -= count; in ceph_put_fmode()
4649 if (i && ci->i_nr_by_mode[i]) in ceph_put_fmode()
4655 spin_unlock(&ci->i_ceph_lock); in ceph_put_fmode()
4666 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_drop_caps_for_unlink() local
4669 spin_lock(&ci->i_ceph_lock); in ceph_drop_caps_for_unlink()
4671 drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN); in ceph_drop_caps_for_unlink()
4673 if (__ceph_caps_dirty(ci)) { in ceph_drop_caps_for_unlink()
4676 __cap_delay_requeue_front(mdsc, ci); in ceph_drop_caps_for_unlink()
4679 spin_unlock(&ci->i_ceph_lock); in ceph_drop_caps_for_unlink()
4694 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_encode_inode_release() local
4700 spin_lock(&ci->i_ceph_lock); in ceph_encode_inode_release()
4701 used = __ceph_caps_used(ci); in ceph_encode_inode_release()
4702 dirty = __ceph_caps_dirty(ci); in ceph_encode_inode_release()
4711 cap = __get_cap_for_mds(ci, mds); in ceph_encode_inode_release()
4727 int wanted = __ceph_caps_wanted(ci); in ceph_encode_inode_release()
4738 if (cap == ci->i_auth_cap && in ceph_encode_inode_release()
4740 ci->i_requested_max_size = 0; in ceph_encode_inode_release()
4763 spin_unlock(&ci->i_ceph_lock); in ceph_encode_inode_release()
4835 struct ceph_inode_info *ci = ceph_inode(inode); in remove_capsnaps() local
4839 lockdep_assert_held(&ci->i_ceph_lock); in remove_capsnaps()
4841 dout("removing capsnaps, ci is %p, inode is %p\n", ci, inode); in remove_capsnaps()
4843 while (!list_empty(&ci->i_cap_snaps)) { in remove_capsnaps()
4844 capsnap = list_first_entry(&ci->i_cap_snaps, in remove_capsnaps()
4851 wake_up_all(&ci->i_cap_wq); in remove_capsnaps()
4860 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_purge_inode_cap() local
4865 lockdep_assert_held(&ci->i_ceph_lock); in ceph_purge_inode_cap()
4868 cap, ci, &ci->netfs.inode); in ceph_purge_inode_cap()
4870 is_auth = (cap == ci->i_auth_cap); in ceph_purge_inode_cap()
4878 if (ci->i_wrbuffer_ref > 0) in ceph_purge_inode_cap()
4885 while (!list_empty(&ci->i_cap_flush_list)) { in ceph_purge_inode_cap()
4886 cf = list_first_entry(&ci->i_cap_flush_list, in ceph_purge_inode_cap()
4894 if (!list_empty(&ci->i_dirty_item)) { in ceph_purge_inode_cap()
4897 ceph_cap_string(ci->i_dirty_caps), in ceph_purge_inode_cap()
4899 ci->i_dirty_caps = 0; in ceph_purge_inode_cap()
4900 list_del_init(&ci->i_dirty_item); in ceph_purge_inode_cap()
4903 if (!list_empty(&ci->i_flushing_item)) { in ceph_purge_inode_cap()
4906 ceph_cap_string(ci->i_flushing_caps), in ceph_purge_inode_cap()
4908 ci->i_flushing_caps = 0; in ceph_purge_inode_cap()
4909 list_del_init(&ci->i_flushing_item); in ceph_purge_inode_cap()
4918 if (ci->i_wrbuffer_ref_head == 0 && in ceph_purge_inode_cap()
4919 ci->i_wr_ref == 0 && in ceph_purge_inode_cap()
4920 ci->i_dirty_caps == 0 && in ceph_purge_inode_cap()
4921 ci->i_flushing_caps == 0) { in ceph_purge_inode_cap()
4922 ceph_put_snap_context(ci->i_head_snapc); in ceph_purge_inode_cap()
4923 ci->i_head_snapc = NULL; in ceph_purge_inode_cap()
4927 if (atomic_read(&ci->i_filelock_ref) > 0) { in ceph_purge_inode_cap()
4929 ci->i_ceph_flags |= CEPH_I_ERROR_FILELOCK; in ceph_purge_inode_cap()
4934 if (!ci->i_dirty_caps && ci->i_prealloc_cap_flush) { in ceph_purge_inode_cap()
4935 cf = ci->i_prealloc_cap_flush; in ceph_purge_inode_cap()
4936 ci->i_prealloc_cap_flush = NULL; in ceph_purge_inode_cap()
4941 if (!list_empty(&ci->i_cap_snaps)) in ceph_purge_inode_cap()