Lines Matching refs:ci

50 				 struct ceph_inode_info *ci,
440 struct ceph_cap *__get_cap_for_mds(struct ceph_inode_info *ci, int mds)
443 struct rb_node *n = ci->i_caps.rb_node;
457 struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci, int mds)
461 spin_lock(&ci->i_ceph_lock);
462 cap = __get_cap_for_mds(ci, mds);
463 spin_unlock(&ci->i_ceph_lock);
470 static void __insert_cap_node(struct ceph_inode_info *ci,
473 struct rb_node **p = &ci->i_caps.rb_node;
489 rb_insert_color(&new->ci_node, &ci->i_caps);
497 struct ceph_inode_info *ci)
499 struct inode *inode = &ci->netfs.inode;
502 ci->i_hold_caps_max = round_jiffies(jiffies +
505 ceph_vinop(inode), ci->i_hold_caps_max - jiffies);
517 struct ceph_inode_info *ci)
519 struct inode *inode = &ci->netfs.inode;
522 inode, ceph_vinop(inode), ci->i_ceph_flags,
523 ci->i_hold_caps_max);
526 if (!list_empty(&ci->i_cap_delay_list)) {
527 if (ci->i_ceph_flags & CEPH_I_FLUSH)
529 list_del_init(&ci->i_cap_delay_list);
531 __cap_set_timeouts(mdsc, ci);
532 list_add_tail(&ci->i_cap_delay_list, &mdsc->cap_delay_list);
544 struct ceph_inode_info *ci)
546 struct inode *inode = &ci->netfs.inode;
550 ci->i_ceph_flags |= CEPH_I_FLUSH;
551 if (!list_empty(&ci->i_cap_delay_list))
552 list_del_init(&ci->i_cap_delay_list);
553 list_add(&ci->i_cap_delay_list, &mdsc->cap_delay_list);
563 struct ceph_inode_info *ci)
565 struct inode *inode = &ci->netfs.inode;
568 if (list_empty(&ci->i_cap_delay_list))
571 list_del_init(&ci->i_cap_delay_list);
576 static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap,
579 struct inode *inode = &ci->netfs.inode;
582 unsigned had = __ceph_caps_issued(ci, NULL);
584 lockdep_assert_held(&ci->i_ceph_lock);
590 if (S_ISREG(ci->netfs.inode.i_mode) &&
593 ci->i_rdcache_gen++;
604 atomic_inc(&ci->i_shared_gen);
605 if (S_ISDIR(ci->netfs.inode.i_mode)) {
607 __ceph_dir_clear_complete(ci);
612 if (S_ISDIR(ci->netfs.inode.i_mode) && (had & CEPH_CAP_DIR_CREATE) &&
614 ceph_put_string(rcu_dereference_raw(ci->i_cached_layout.pool_ns));
615 memset(&ci->i_cached_layout, 0, sizeof(ci->i_cached_layout));
621 * @ci: inode to be moved
624 void change_auth_cap_ses(struct ceph_inode_info *ci,
627 lockdep_assert_held(&ci->i_ceph_lock);
629 if (list_empty(&ci->i_dirty_item) && list_empty(&ci->i_flushing_item))
633 if (!list_empty(&ci->i_dirty_item))
634 list_move(&ci->i_dirty_item, &session->s_cap_dirty);
635 if (!list_empty(&ci->i_flushing_item))
636 list_move_tail(&ci->i_flushing_item, &session->s_cap_flushing);
643 * Caller should hold session snap_rwsem (read) and ci->i_ceph_lock
657 struct ceph_inode_info *ci = ceph_inode(inode);
663 lockdep_assert_held(&ci->i_ceph_lock);
671 cap = __get_cap_for_mds(ci, mds);
682 cap->ci = ci;
683 __insert_cap_node(ci, cap);
710 WARN_ON(cap != ci->i_auth_cap);
719 if (!ci->i_snap_realm ||
721 realmino != (u64)-1 && ci->i_snap_realm->ino != realmino)) {
731 __func__, realmino, ci->i_vino.ino,
732 ci->i_snap_realm ? ci->i_snap_realm->ino : 0);
735 __check_cap_issue(ci, cap, issued);
742 actual_wanted = __ceph_caps_wanted(ci);
748 __cap_delay_requeue(mdsc, ci);
752 if (!ci->i_auth_cap ||
753 ceph_seq_cmp(ci->i_auth_cap->mseq, mseq) < 0) {
754 if (ci->i_auth_cap &&
755 ci->i_auth_cap->session != cap->session)
756 change_auth_cap_ses(ci, cap->session);
757 ci->i_auth_cap = cap;
761 WARN_ON(ci->i_auth_cap == cap);
778 wake_up_all(&ci->i_cap_wq);
788 struct inode *inode = &cap->ci->netfs.inode;
811 int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented)
813 struct inode *inode = &ci->netfs.inode;
815 int have = ci->i_snap_caps;
821 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
836 if (ci->i_auth_cap) {
837 cap = ci->i_auth_cap;
846 int __ceph_caps_issued_other(struct ceph_inode_info *ci, struct ceph_cap *ocap)
848 int have = ci->i_snap_caps;
852 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
869 struct inode *inode = &cap->ci->netfs.inode;
890 int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int touch)
892 struct inode *inode = &ci->netfs.inode;
896 int have = ci->i_snap_caps;
905 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
931 for (q = rb_first(&ci->i_caps); q != p;
948 int __ceph_caps_issued_mask_metric(struct ceph_inode_info *ci, int mask,
951 struct ceph_fs_client *fsc = ceph_sb_to_fs_client(ci->netfs.inode.i_sb);
954 r = __ceph_caps_issued_mask(ci, mask, touch);
965 int __ceph_caps_revoking_other(struct ceph_inode_info *ci,
971 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
980 int ceph_caps_revoking(struct ceph_inode_info *ci, int mask)
982 struct inode *inode = &ci->netfs.inode;
986 spin_lock(&ci->i_ceph_lock);
987 ret = __ceph_caps_revoking_other(ci, NULL, mask);
988 spin_unlock(&ci->i_ceph_lock);
994 int __ceph_caps_used(struct ceph_inode_info *ci)
997 if (ci->i_pin_ref)
999 if (ci->i_rd_ref)
1001 if (ci->i_rdcache_ref ||
1002 (S_ISREG(ci->netfs.inode.i_mode) &&
1003 ci->netfs.inode.i_data.nrpages))
1005 if (ci->i_wr_ref)
1007 if (ci->i_wb_ref || ci->i_wrbuffer_ref)
1009 if (ci->i_fx_ref)
1019 int __ceph_caps_file_wanted(struct ceph_inode_info *ci)
1026 ceph_inode_to_fs_client(&ci->netfs.inode)->mount_options;
1030 if (S_ISDIR(ci->netfs.inode.i_mode)) {
1034 if (ci->i_nr_by_mode[RD_SHIFT] > 0 ||
1035 time_after(ci->i_last_rd, used_cutoff))
1038 if (ci->i_nr_by_mode[WR_SHIFT] > 0 ||
1039 time_after(ci->i_last_wr, used_cutoff)) {
1045 if (want || ci->i_nr_by_mode[PIN_SHIFT] > 0)
1052 if (ci->i_nr_by_mode[RD_SHIFT] > 0) {
1053 if (ci->i_nr_by_mode[RD_SHIFT] >= FMODE_WAIT_BIAS ||
1054 time_after(ci->i_last_rd, used_cutoff))
1056 } else if (time_after(ci->i_last_rd, idle_cutoff)) {
1060 if (ci->i_nr_by_mode[WR_SHIFT] > 0) {
1061 if (ci->i_nr_by_mode[WR_SHIFT] >= FMODE_WAIT_BIAS ||
1062 time_after(ci->i_last_wr, used_cutoff))
1064 } else if (time_after(ci->i_last_wr, idle_cutoff)) {
1070 ci->i_nr_by_mode[LAZY_SHIFT] > 0)
1080 int __ceph_caps_wanted(struct ceph_inode_info *ci)
1082 int w = __ceph_caps_file_wanted(ci) | __ceph_caps_used(ci);
1083 if (S_ISDIR(ci->netfs.inode.i_mode)) {
1098 int __ceph_caps_mds_wanted(struct ceph_inode_info *ci, bool check)
1104 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
1108 if (cap == ci->i_auth_cap)
1118 struct ceph_inode_info *ci = ceph_inode(inode);
1121 spin_lock(&ci->i_ceph_lock);
1122 ret = __ceph_is_any_real_caps(ci);
1123 spin_unlock(&ci->i_ceph_lock);
1138 struct ceph_inode_info *ci = cap->ci;
1139 struct inode *inode = &ci->netfs.inode;
1143 /* 'ci' being NULL means the remove have already occurred */
1144 if (!ci) {
1149 lockdep_assert_held(&ci->i_ceph_lock);
1153 mdsc = ceph_inode_to_fs_client(&ci->netfs.inode)->mdsc;
1156 rb_erase(&cap->ci_node, &ci->i_caps);
1157 if (ci->i_auth_cap == cap)
1158 ci->i_auth_cap = NULL;
1174 cap->ci = NULL;
1191 cap->cap_ino = ci->i_vino.ino;
1198 if (!__ceph_is_any_real_caps(ci)) {
1203 if (ci->i_wr_ref == 0 && ci->i_snap_realm)
1204 ceph_change_snap_realm(&ci->netfs.inode, NULL);
1206 __cap_delay_cancel(mdsc, ci);
1213 struct ceph_inode_info *ci = cap->ci;
1216 /* 'ci' being NULL means the remove have already occurred */
1217 if (!ci) {
1222 lockdep_assert_held(&ci->i_ceph_lock);
1224 fsc = ceph_inode_to_fs_client(&ci->netfs.inode);
1225 WARN_ON_ONCE(ci->i_auth_cap == cap &&
1226 !list_empty(&ci->i_dirty_item) &&
1228 !ceph_inode_is_shutdown(&ci->netfs.inode));
1377 void __ceph_remove_caps(struct ceph_inode_info *ci)
1379 struct inode *inode = &ci->netfs.inode;
1385 spin_lock(&ci->i_ceph_lock);
1386 p = rb_first(&ci->i_caps);
1392 spin_unlock(&ci->i_ceph_lock);
1407 struct ceph_inode_info *ci = cap->ci;
1408 struct inode *inode = &ci->netfs.inode;
1412 lockdep_assert_held(&ci->i_ceph_lock);
1424 ci->i_ceph_flags &= ~CEPH_I_FLUSH;
1439 arg->follows = flushing ? ci->i_head_snapc->seq : 0;
1443 ci->i_reported_size = arg->size;
1444 arg->max_size = ci->i_wanted_max_size;
1445 if (cap == ci->i_auth_cap) {
1447 ci->i_requested_max_size = arg->max_size;
1449 ci->i_requested_max_size = 0;
1453 arg->old_xattr_buf = __ceph_build_xattrs_blob(ci);
1454 arg->xattr_version = ci->i_xattrs.version;
1455 arg->xattr_buf = ceph_buffer_get(ci->i_xattrs.blob);
1464 arg->btime = ci->i_btime;
1475 arg->time_warp_seq = ci->i_time_warp_seq;
1481 arg->inline_data = ci->i_inline_version != CEPH_INLINE_NONE;
1483 !list_empty(&ci->i_cap_snaps)) {
1485 list_for_each_entry_reverse(capsnap, &ci->i_cap_snaps, ci_item) {
1497 if (ci->fscrypt_auth_len &&
1498 WARN_ON_ONCE(ci->fscrypt_auth_len > sizeof(struct ceph_fscrypt_auth))) {
1502 arg->fscrypt_auth_len = ci->fscrypt_auth_len;
1503 memcpy(arg->fscrypt_auth, ci->fscrypt_auth,
1504 min_t(size_t, ci->fscrypt_auth_len,
1533 static void __send_cap(struct cap_msg_args *arg, struct ceph_inode_info *ci)
1536 struct inode *inode = &ci->netfs.inode;
1547 spin_lock(&ci->i_ceph_lock);
1548 __cap_delay_requeue(arg->session->s_mdsc, ci);
1549 spin_unlock(&ci->i_ceph_lock);
1558 wake_up_all(&ci->i_cap_wq);
1629 static void __ceph_flush_snaps(struct ceph_inode_info *ci,
1631 __releases(ci->i_ceph_lock)
1632 __acquires(ci->i_ceph_lock)
1634 struct inode *inode = &ci->netfs.inode;
1644 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) {
1667 if (list_empty(&ci->i_flushing_item)) {
1668 list_add_tail(&ci->i_flushing_item,
1674 &ci->i_cap_flush_list);
1681 ci->i_ceph_flags &= ~CEPH_I_FLUSH_SNAPS;
1684 struct ceph_cap *cap = ci->i_auth_cap;
1695 list_for_each_entry(iter, &ci->i_cap_flush_list, i_list) {
1709 spin_unlock(&ci->i_ceph_lock);
1725 spin_lock(&ci->i_ceph_lock);
1729 void ceph_flush_snaps(struct ceph_inode_info *ci,
1732 struct inode *inode = &ci->netfs.inode;
1743 spin_lock(&ci->i_ceph_lock);
1744 if (!(ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)) {
1748 if (!ci->i_auth_cap) {
1753 mds = ci->i_auth_cap->session->s_mds;
1760 spin_unlock(&ci->i_ceph_lock);
1768 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH)
1769 __kick_flushing_caps(mdsc, session, ci, 0);
1771 __ceph_flush_snaps(ci, session);
1773 spin_unlock(&ci->i_ceph_lock);
1781 if (!list_empty(&ci->i_snap_flush_item))
1783 list_del_init(&ci->i_snap_flush_item);
1795 int __ceph_mark_dirty_caps(struct ceph_inode_info *ci, int mask,
1799 ceph_sb_to_fs_client(ci->netfs.inode.i_sb)->mdsc;
1800 struct inode *inode = &ci->netfs.inode;
1802 int was = ci->i_dirty_caps;
1805 lockdep_assert_held(&ci->i_ceph_lock);
1807 if (!ci->i_auth_cap) {
1818 ci->i_dirty_caps |= mask;
1820 struct ceph_mds_session *session = ci->i_auth_cap->session;
1822 WARN_ON_ONCE(ci->i_prealloc_cap_flush);
1823 swap(ci->i_prealloc_cap_flush, *pcf);
1825 if (!ci->i_head_snapc) {
1827 ci->i_head_snapc = ceph_get_snap_context(
1828 ci->i_snap_realm->cached_context);
1831 inode, ceph_vinop(inode), ci->i_head_snapc,
1832 ci->i_auth_cap);
1833 BUG_ON(!list_empty(&ci->i_dirty_item));
1835 list_add(&ci->i_dirty_item, &session->s_cap_dirty);
1837 if (ci->i_flushing_caps == 0) {
1842 WARN_ON_ONCE(!ci->i_prealloc_cap_flush);
1844 BUG_ON(list_empty(&ci->i_dirty_item));
1845 if (((was | ci->i_flushing_caps) & CEPH_CAP_FILE_BUFFER) &&
1848 __cap_delay_requeue(mdsc, ci);
1900 static bool __detach_cap_flush_from_ci(struct ceph_inode_info *ci,
1906 if (wake && cf->i_list.prev != &ci->i_cap_flush_list) {
1927 struct ceph_inode_info *ci = ceph_inode(inode);
1931 lockdep_assert_held(&ci->i_ceph_lock);
1932 BUG_ON(ci->i_dirty_caps == 0);
1933 BUG_ON(list_empty(&ci->i_dirty_item));
1934 BUG_ON(!ci->i_prealloc_cap_flush);
1936 flushing = ci->i_dirty_caps;
1939 ceph_cap_string(ci->i_flushing_caps),
1940 ceph_cap_string(ci->i_flushing_caps | flushing));
1941 ci->i_flushing_caps |= flushing;
1942 ci->i_dirty_caps = 0;
1945 swap(cf, ci->i_prealloc_cap_flush);
1950 list_del_init(&ci->i_dirty_item);
1956 if (list_empty(&ci->i_flushing_item)) {
1957 list_add_tail(&ci->i_flushing_item, &session->s_cap_flushing);
1962 list_add_tail(&cf->i_list, &ci->i_cap_flush_list);
1971 __releases(ci->i_ceph_lock)
1972 __acquires(ci->i_ceph_lock)
1975 struct ceph_inode_info *ci = ceph_inode(inode);
1976 u32 invalidating_gen = ci->i_rdcache_gen;
1978 spin_unlock(&ci->i_ceph_lock);
1981 spin_lock(&ci->i_ceph_lock);
1984 invalidating_gen == ci->i_rdcache_gen) {
1989 ci->i_rdcache_revoking = ci->i_rdcache_gen - 1;
1996 bool __ceph_should_report_size(struct ceph_inode_info *ci)
1998 loff_t size = i_size_read(&ci->netfs.inode);
2000 if (ci->i_flushing_caps & CEPH_CAP_FILE_WR)
2002 if (size >= ci->i_max_size)
2005 if (ci->i_max_size > ci->i_reported_size &&
2006 (size << 1) >= ci->i_max_size + ci->i_reported_size)
2020 void ceph_check_caps(struct ceph_inode_info *ci, int flags)
2022 struct inode *inode = &ci->netfs.inode;
2037 spin_lock(&ci->i_ceph_lock);
2038 if (ci->i_ceph_flags & CEPH_I_ASYNC_CREATE) {
2039 ci->i_ceph_flags |= CEPH_I_ASYNC_CHECK_CAPS;
2042 spin_unlock(&ci->i_ceph_lock);
2046 if (ci->i_ceph_flags & CEPH_I_FLUSH)
2050 file_wanted = __ceph_caps_file_wanted(ci);
2053 used = __ceph_caps_used(ci);
2061 issued = __ceph_caps_issued(ci, &implemented);
2073 __ceph_dir_is_complete(ci)) {
2094 if (ci->i_max_size == 0)
2102 ceph_cap_string(used), ceph_cap_string(ci->i_dirty_caps),
2103 ceph_cap_string(ci->i_flushing_caps),
2117 !(ci->i_wb_ref || ci->i_wrbuffer_ref) && /* no dirty pages... */
2127 ci->i_rdcache_revoking = ci->i_rdcache_gen;
2133 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
2141 ((flags & CHECK_CAPS_AUTHONLY) && cap != ci->i_auth_cap))
2149 if (ci->i_auth_cap && cap != ci->i_auth_cap)
2150 cap_used &= ~ci->i_auth_cap->issued;
2178 if (S_ISREG(inode->i_mode) && ci->i_wrbuffer_ref &&
2183 if (cap == ci->i_auth_cap &&
2186 if (ci->i_wanted_max_size > ci->i_max_size &&
2187 ci->i_wanted_max_size > ci->i_requested_max_size) {
2193 if (__ceph_should_report_size(ci)) {
2199 if (cap == ci->i_auth_cap) {
2200 if ((flags & CHECK_CAPS_FLUSH) && ci->i_dirty_caps) {
2204 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) {
2228 if (cap == ci->i_auth_cap &&
2229 (ci->i_ceph_flags &
2231 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH)
2232 __kick_flushing_caps(mdsc, session, ci, 0);
2233 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)
2234 __ceph_flush_snaps(ci, session);
2239 if (cap == ci->i_auth_cap && ci->i_dirty_caps) {
2240 flushing = ci->i_dirty_caps;
2259 spin_unlock(&ci->i_ceph_lock);
2260 __send_cap(&arg, ci);
2261 spin_lock(&ci->i_ceph_lock);
2267 if (__ceph_is_any_real_caps(ci) &&
2268 list_empty(&ci->i_cap_delay_list) &&
2271 __cap_delay_requeue(mdsc, ci);
2274 spin_unlock(&ci->i_ceph_lock);
2289 struct ceph_inode_info *ci = ceph_inode(inode);
2293 spin_lock(&ci->i_ceph_lock);
2295 if (ci->i_dirty_caps && ci->i_auth_cap) {
2296 struct ceph_cap *cap = ci->i_auth_cap;
2301 spin_unlock(&ci->i_ceph_lock);
2305 if (ci->i_ceph_flags &
2307 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH)
2308 __kick_flushing_caps(mdsc, session, ci, 0);
2309 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)
2310 __ceph_flush_snaps(ci, session);
2314 flushing = ci->i_dirty_caps;
2319 __ceph_caps_used(ci), __ceph_caps_wanted(ci),
2322 spin_unlock(&ci->i_ceph_lock);
2324 __send_cap(&arg, ci);
2326 if (!list_empty(&ci->i_cap_flush_list)) {
2328 list_last_entry(&ci->i_cap_flush_list,
2333 flushing = ci->i_flushing_caps;
2334 spin_unlock(&ci->i_ceph_lock);
2346 struct ceph_inode_info *ci = ceph_inode(inode);
2349 spin_lock(&ci->i_ceph_lock);
2350 if (!list_empty(&ci->i_cap_flush_list)) {
2352 list_first_entry(&ci->i_cap_flush_list,
2357 spin_unlock(&ci->i_ceph_lock);
2368 struct ceph_inode_info *ci = ceph_inode(inode);
2372 spin_lock(&ci->i_unsafe_lock);
2373 if (S_ISDIR(inode->i_mode) && !list_empty(&ci->i_unsafe_dirops)) {
2374 req1 = list_last_entry(&ci->i_unsafe_dirops,
2379 if (!list_empty(&ci->i_unsafe_iops)) {
2380 req2 = list_last_entry(&ci->i_unsafe_iops,
2385 spin_unlock(&ci->i_unsafe_lock);
2409 spin_lock(&ci->i_unsafe_lock);
2411 list_for_each_entry(req, &ci->i_unsafe_dirops,
2423 list_for_each_entry(req, &ci->i_unsafe_iops,
2434 spin_unlock(&ci->i_unsafe_lock);
2437 spin_lock(&ci->i_ceph_lock);
2438 if (ci->i_auth_cap) {
2439 s = ci->i_auth_cap->session;
2443 spin_unlock(&ci->i_ceph_lock);
2484 struct ceph_inode_info *ci = ceph_inode(inode);
2512 err = wait_event_interruptible(ci->i_cap_wq,
2536 struct ceph_inode_info *ci = ceph_inode(inode);
2551 err = wait_event_interruptible(ci->i_cap_wq,
2557 spin_lock(&ci->i_ceph_lock);
2558 if (__ceph_caps_dirty(ci))
2559 __cap_delay_requeue_front(mdsc, ci);
2560 spin_unlock(&ci->i_ceph_lock);
2567 struct ceph_inode_info *ci,
2569 __releases(ci->i_ceph_lock)
2570 __acquires(ci->i_ceph_lock)
2572 struct inode *inode = &ci->netfs.inode;
2581 if (ci->i_ceph_flags & CEPH_I_ASYNC_CREATE)
2584 ci->i_ceph_flags &= ~CEPH_I_KICK_FLUSH;
2586 list_for_each_entry_reverse(cf, &ci->i_cap_flush_list, i_list) {
2593 list_for_each_entry(cf, &ci->i_cap_flush_list, i_list) {
2597 cap = ci->i_auth_cap;
2615 __ceph_caps_used(ci),
2616 __ceph_caps_wanted(ci),
2619 spin_unlock(&ci->i_ceph_lock);
2620 __send_cap(&arg, ci);
2630 spin_unlock(&ci->i_ceph_lock);
2644 spin_lock(&ci->i_ceph_lock);
2652 struct ceph_inode_info *ci;
2662 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) {
2663 struct inode *inode = &ci->netfs.inode;
2665 spin_lock(&ci->i_ceph_lock);
2666 cap = ci->i_auth_cap;
2671 spin_unlock(&ci->i_ceph_lock);
2682 if ((cap->issued & ci->i_flushing_caps) !=
2683 ci->i_flushing_caps) {
2690 __kick_flushing_caps(mdsc, session, ci,
2693 ci->i_ceph_flags |= CEPH_I_KICK_FLUSH;
2696 spin_unlock(&ci->i_ceph_lock);
2704 struct ceph_inode_info *ci;
2716 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) {
2717 struct inode *inode = &ci->netfs.inode;
2719 spin_lock(&ci->i_ceph_lock);
2720 cap = ci->i_auth_cap;
2725 spin_unlock(&ci->i_ceph_lock);
2728 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) {
2729 __kick_flushing_caps(mdsc, session, ci,
2732 spin_unlock(&ci->i_ceph_lock);
2737 struct ceph_inode_info *ci)
2740 struct ceph_cap *cap = ci->i_auth_cap;
2741 struct inode *inode = &ci->netfs.inode;
2743 lockdep_assert_held(&ci->i_ceph_lock);
2747 ceph_cap_string(ci->i_flushing_caps));
2749 if (!list_empty(&ci->i_cap_flush_list)) {
2752 list_move_tail(&ci->i_flushing_item,
2757 __kick_flushing_caps(mdsc, session, ci, oldest_flush_tid);
2766 void ceph_take_cap_refs(struct ceph_inode_info *ci, int got,
2769 struct inode *inode = &ci->netfs.inode;
2772 lockdep_assert_held(&ci->i_ceph_lock);
2775 ci->i_pin_ref++;
2777 ci->i_rd_ref++;
2779 ci->i_rdcache_ref++;
2781 ci->i_fx_ref++;
2783 if (ci->i_wr_ref == 0 && !ci->i_head_snapc) {
2785 ci->i_head_snapc = ceph_get_snap_context(
2786 ci->i_snap_realm->cached_context);
2788 ci->i_wr_ref++;
2791 if (ci->i_wb_ref == 0)
2793 ci->i_wb_ref++;
2795 ceph_vinop(inode), ci->i_wb_ref-1, ci->i_wb_ref);
2821 struct ceph_inode_info *ci = ceph_inode(inode);
2833 spin_lock(&ci->i_ceph_lock);
2836 (ci->i_ceph_flags & CEPH_I_ERROR_FILELOCK)) {
2844 while (ci->i_truncate_pending) {
2845 spin_unlock(&ci->i_ceph_lock);
2851 spin_lock(&ci->i_ceph_lock);
2854 have = __ceph_caps_issued(ci, &implemented);
2857 if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) {
2859 inode, ceph_vinop(inode), endoff, ci->i_max_size);
2860 if (endoff > ci->i_requested_max_size)
2861 ret = ci->i_auth_cap ? -EFBIG : -EUCLEAN;
2868 if (__ceph_have_pending_cap_snap(ci)) {
2893 !ci->i_head_snapc &&
2905 spin_unlock(&ci->i_ceph_lock);
2916 ceph_take_cap_refs(ci, *got, true);
2922 if (ci->i_auth_cap &&
2924 struct ceph_mds_session *s = ci->i_auth_cap->session;
2932 ci->i_auth_cap->mds);
2943 mds_wanted = __ceph_caps_mds_wanted(ci, false);
2958 __ceph_touch_fmode(ci, mdsc, flags);
2960 spin_unlock(&ci->i_ceph_lock);
2981 struct ceph_inode_info *ci = ceph_inode(inode);
2986 spin_lock(&ci->i_ceph_lock);
2987 if (endoff >= ci->i_max_size && endoff > ci->i_wanted_max_size) {
2990 ci->i_wanted_max_size = endoff;
2993 if (ci->i_auth_cap &&
2994 (ci->i_auth_cap->issued & CEPH_CAP_FILE_WR) &&
2995 ci->i_wanted_max_size > ci->i_max_size &&
2996 ci->i_wanted_max_size > ci->i_requested_max_size)
2998 spin_unlock(&ci->i_ceph_lock);
3000 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY);
3047 struct ceph_inode_info *ci = ceph_inode(inode);
3084 ceph_get_fmode(ci, flags, FMODE_WAIT_BIAS);
3085 add_wait_queue(&ci->i_cap_wq, &wait);
3097 remove_wait_queue(&ci->i_cap_wq, &wait);
3098 ceph_put_fmode(ci, flags, FMODE_WAIT_BIAS);
3111 ceph_put_cap_refs(ci, _got);
3134 if (S_ISREG(ci->netfs.inode.i_mode) &&
3135 ceph_has_inline_data(ci) &&
3151 ceph_put_cap_refs(ci, _got);
3184 void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps)
3186 spin_lock(&ci->i_ceph_lock);
3187 ceph_take_cap_refs(ci, caps, false);
3188 spin_unlock(&ci->i_ceph_lock);
3196 static int ceph_try_drop_cap_snap(struct ceph_inode_info *ci,
3199 struct inode *inode = &ci->netfs.inode;
3207 if (!list_is_last(&capsnap->ci_item, &ci->i_cap_snaps))
3208 ci->i_ceph_flags |= CEPH_I_FLUSH_SNAPS;
3231 static void __ceph_put_cap_refs(struct ceph_inode_info *ci, int had,
3234 struct inode *inode = &ci->netfs.inode;
3239 spin_lock(&ci->i_ceph_lock);
3241 --ci->i_pin_ref;
3243 if (--ci->i_rd_ref == 0)
3246 if (--ci->i_rdcache_ref == 0)
3249 if (--ci->i_fx_ref == 0)
3252 if (--ci->i_wb_ref == 0) {
3259 ceph_vinop(inode), ci->i_wb_ref+1, ci->i_wb_ref);
3262 if (--ci->i_wr_ref == 0) {
3267 WARN_ON_ONCE(ci->i_wb_ref);
3271 if (ci->i_wrbuffer_ref_head == 0 &&
3272 ci->i_dirty_caps == 0 &&
3273 ci->i_flushing_caps == 0) {
3274 BUG_ON(!ci->i_head_snapc);
3275 ceph_put_snap_context(ci->i_head_snapc);
3276 ci->i_head_snapc = NULL;
3279 if (!__ceph_is_any_real_caps(ci) && ci->i_snap_realm)
3283 if (check_flushsnaps && __ceph_have_pending_cap_snap(ci)) {
3285 list_last_entry(&ci->i_cap_snaps,
3290 if (ceph_try_drop_cap_snap(ci, capsnap))
3293 else if (__ceph_finish_cap_snap(ci, capsnap))
3297 spin_unlock(&ci->i_ceph_lock);
3305 ceph_check_caps(ci, 0);
3307 ceph_flush_snaps(ci, NULL);
3319 wake_up_all(&ci->i_cap_wq);
3324 void ceph_put_cap_refs(struct ceph_inode_info *ci, int had)
3326 __ceph_put_cap_refs(ci, had, PUT_CAP_REFS_SYNC);
3329 void ceph_put_cap_refs_async(struct ceph_inode_info *ci, int had)
3331 __ceph_put_cap_refs(ci, had, PUT_CAP_REFS_ASYNC);
3341 void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr,
3344 struct inode *inode = &ci->netfs.inode;
3352 spin_lock(&ci->i_ceph_lock);
3353 ci->i_wrbuffer_ref -= nr;
3354 if (ci->i_wrbuffer_ref == 0) {
3359 if (ci->i_head_snapc == snapc) {
3360 ci->i_wrbuffer_ref_head -= nr;
3361 if (ci->i_wrbuffer_ref_head == 0 &&
3362 ci->i_wr_ref == 0 &&
3363 ci->i_dirty_caps == 0 &&
3364 ci->i_flushing_caps == 0) {
3365 BUG_ON(!ci->i_head_snapc);
3366 ceph_put_snap_context(ci->i_head_snapc);
3367 ci->i_head_snapc = NULL;
3370 inode, ceph_vinop(inode), ci->i_wrbuffer_ref+nr,
3371 ci->i_wrbuffer_ref_head+nr, ci->i_wrbuffer_ref,
3372 ci->i_wrbuffer_ref_head, last ? " LAST" : "");
3374 list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) {
3386 WARN_ON_ONCE(ci->i_auth_cap);
3394 if (ceph_try_drop_cap_snap(ci, capsnap)) {
3397 ci->i_ceph_flags |= CEPH_I_FLUSH_SNAPS;
3404 ci->i_wrbuffer_ref+nr, capsnap->dirty_pages + nr,
3405 ci->i_wrbuffer_ref, capsnap->dirty_pages,
3411 spin_unlock(&ci->i_ceph_lock);
3414 ceph_check_caps(ci, 0);
3416 ceph_flush_snaps(ci, NULL);
3419 wake_up_all(&ci->i_cap_wq);
3489 __releases(ci->i_ceph_lock)
3493 struct ceph_inode_info *ci = ceph_inode(inode);
3531 !(ci->i_wrbuffer_ref || ci->i_wb_ref)) {
3535 if (ci->i_rdcache_revoking != ci->i_rdcache_gen) {
3537 ci->i_rdcache_revoking = ci->i_rdcache_gen;
3554 WARN_ON(cap != ci->i_auth_cap);
3564 __check_cap_issue(ci, cap, newcaps);
3579 ci->i_btime = extra_info->btime;
3585 if (ci->fscrypt_auth_len != extra_info->fscrypt_auth_len ||
3586 memcmp(ci->fscrypt_auth, extra_info->fscrypt_auth,
3587 ci->fscrypt_auth_len))
3590 ci->fscrypt_auth_len,
3607 if (version > ci->i_xattrs.version) {
3610 if (ci->i_xattrs.blob)
3611 ceph_buffer_put(ci->i_xattrs.blob);
3612 ci->i_xattrs.blob = ceph_buffer_get(xattr_buf);
3613 ci->i_xattrs.version = version;
3631 ci->i_files = extra_info->nfiles;
3632 ci->i_subdirs = extra_info->nsubdirs;
3637 s64 old_pool = ci->i_layout.pool_id;
3640 ceph_file_layout_from_legacy(&ci->i_layout, &grant->layout);
3641 old_ns = rcu_dereference_protected(ci->i_layout.pool_ns,
3642 lockdep_is_held(&ci->i_ceph_lock));
3643 rcu_assign_pointer(ci->i_layout.pool_ns, extra_info->pool_ns);
3645 if (ci->i_layout.pool_id != old_pool ||
3647 ci->i_ceph_flags &= ~CEPH_I_POOL_PERM;
3658 if (ci->i_auth_cap == cap && (newcaps & CEPH_CAP_ANY_FILE_WR)) {
3659 if (max_size != ci->i_max_size) {
3660 doutc(cl, "max_size %lld -> %llu\n", ci->i_max_size,
3662 ci->i_max_size = max_size;
3663 if (max_size >= ci->i_wanted_max_size) {
3664 ci->i_wanted_max_size = 0; /* reset */
3665 ci->i_requested_max_size = 0;
3672 wanted = __ceph_caps_wanted(ci);
3673 used = __ceph_caps_used(ci);
3674 dirty = __ceph_caps_dirty(ci);
3708 else if (cap == ci->i_auth_cap)
3725 if (cap == ci->i_auth_cap &&
3726 __ceph_caps_revoking_other(ci, cap, newcaps))
3740 if (cap == ci->i_auth_cap)
3747 extra_info->inline_version >= ci->i_inline_version) {
3748 ci->i_inline_version = extra_info->inline_version;
3749 if (ci->i_inline_version != CEPH_INLINE_NONE &&
3755 if (ci->i_auth_cap == cap) {
3759 if (ci->i_requested_max_size > max_size ||
3762 ci->i_requested_max_size = 0;
3766 ceph_kick_flushing_inode_caps(session, ci);
3770 spin_unlock(&ci->i_ceph_lock);
3791 wake_up_all(&ci->i_cap_wq);
3795 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY | CHECK_CAPS_NOINVAL);
3797 ceph_check_caps(ci, CHECK_CAPS_NOINVAL);
3808 __releases(ci->i_ceph_lock)
3810 struct ceph_inode_info *ci = ceph_inode(inode);
3822 list_for_each_entry_safe(cf, tmp_cf, &ci->i_cap_flush_list, i_list) {
3836 wake_ci |= __detach_cap_flush_from_ci(ci, cf);
3852 ceph_cap_string(ci->i_flushing_caps),
3853 ceph_cap_string(ci->i_flushing_caps & ~cleaned));
3858 ci->i_flushing_caps &= ~cleaned;
3865 if (ci->i_flushing_caps == 0) {
3866 if (list_empty(&ci->i_cap_flush_list)) {
3867 list_del_init(&ci->i_flushing_item);
3881 if (ci->i_dirty_caps == 0) {
3884 BUG_ON(!list_empty(&ci->i_dirty_item));
3886 if (ci->i_wr_ref == 0 &&
3887 ci->i_wrbuffer_ref_head == 0) {
3888 BUG_ON(!ci->i_head_snapc);
3889 ceph_put_snap_context(ci->i_head_snapc);
3890 ci->i_head_snapc = NULL;
3893 BUG_ON(list_empty(&ci->i_dirty_item));
3899 spin_unlock(&ci->i_ceph_lock);
3910 wake_up_all(&ci->i_cap_wq);
3920 struct ceph_inode_info *ci = ceph_inode(inode);
3925 lockdep_assert_held(&ci->i_ceph_lock);
3927 doutc(cl, "removing capsnap %p, %p %llx.%llx ci %p\n", capsnap,
3928 inode, ceph_vinop(inode), ci);
3931 ret = __detach_cap_flush_from_ci(ci, &capsnap->cap_flush);
3936 if (list_empty(&ci->i_cap_flush_list))
3937 list_del_init(&ci->i_flushing_item);
3948 struct ceph_inode_info *ci = ceph_inode(inode);
3950 lockdep_assert_held(&ci->i_ceph_lock);
3966 struct ceph_inode_info *ci = ceph_inode(inode);
3974 doutc(cl, "%p %llx.%llx ci %p mds%d follows %lld\n", inode,
3975 ceph_vinop(inode), ci, session->s_mds, follows);
3977 spin_lock(&ci->i_ceph_lock);
3978 list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) {
3996 spin_unlock(&ci->i_ceph_lock);
4002 wake_up_all(&ci->i_cap_wq);
4019 struct ceph_inode_info *ci = ceph_inode(inode);
4027 int dirty = __ceph_caps_dirty(ci);
4031 lockdep_assert_held(&ci->i_ceph_lock);
4066 struct ceph_inode_info *ci = ceph_inode(inode);
4083 doutc(cl, "%p %llx.%llx ci %p mds%d mseq %d target %d\n",
4084 inode, ceph_vinop(inode), ci, mds, mseq, target);
4087 spin_lock(&ci->i_ceph_lock);
4088 cap = __get_cap_for_mds(ci, mds);
4113 tcap = __get_cap_for_mds(ci, target);
4125 if (cap == ci->i_auth_cap) {
4126 ci->i_auth_cap = tcap;
4127 change_auth_cap_ses(ci, tcap->session);
4134 int flag = (cap == ci->i_auth_cap) ? CEPH_CAP_FLAG_AUTH : 0;
4139 if (!list_empty(&ci->i_cap_flush_list) &&
4140 ci->i_auth_cap == tcap) {
4142 list_move_tail(&ci->i_flushing_item,
4151 spin_unlock(&ci->i_ceph_lock);
4177 spin_unlock(&ci->i_ceph_lock);
4199 struct ceph_inode_info *ci = ceph_inode(inode);
4221 doutc(cl, "%p %llx.%llx ci %p mds%d mseq %d peer %d\n",
4222 inode, ceph_vinop(inode), ci, mds, mseq, peer);
4224 cap = __get_cap_for_mds(ci, mds);
4227 spin_unlock(&ci->i_ceph_lock);
4229 spin_lock(&ci->i_ceph_lock);
4240 __ceph_caps_issued(ci, &issued);
4241 issued |= __ceph_caps_dirty(ci);
4246 ocap = peer >= 0 ? __get_cap_for_mds(ci, peer) : NULL;
4326 struct ceph_inode_info *ci;
4466 ci = ceph_inode(inode);
4494 spin_lock(&ci->i_ceph_lock);
4505 spin_lock(&ci->i_ceph_lock);
4511 spin_unlock(&ci->i_ceph_lock);
4527 __ceph_caps_issued(ci, &extra_info.issued);
4528 extra_info.issued |= __ceph_caps_dirty(ci);
4541 spin_unlock(&ci->i_ceph_lock);
4547 spin_unlock(&ci->i_ceph_lock);
4599 * processed in this run. In this case, the ci->i_hold_caps_max will be
4606 struct ceph_inode_info *ci;
4615 ci = list_first_entry(&mdsc->cap_delay_list,
4618 if (time_before(loop_start, ci->i_hold_caps_max - delay_max)) {
4620 delay = ci->i_hold_caps_max;
4623 if ((ci->i_ceph_flags & CEPH_I_FLUSH) == 0 &&
4624 time_before(jiffies, ci->i_hold_caps_max))
4626 list_del_init(&ci->i_cap_delay_list);
4628 inode = igrab(&ci->netfs.inode);
4633 ceph_check_caps(ci, 0);
4659 struct ceph_inode_info *ci;
4665 ci = list_first_entry(&s->s_cap_dirty, struct ceph_inode_info,
4667 inode = &ci->netfs.inode;
4672 ceph_check_caps(ci, CHECK_CAPS_FLUSH);
4685 void __ceph_touch_fmode(struct ceph_inode_info *ci,
4690 ci->i_last_rd = now;
4692 ci->i_last_wr = now;
4695 __ceph_is_any_real_caps(ci) &&
4696 list_empty(&ci->i_cap_delay_list))
4697 __cap_delay_requeue(mdsc, ci);
4700 void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count)
4702 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->netfs.inode.i_sb);
4710 spin_lock(&ci->i_ceph_lock);
4717 if (i && ci->i_nr_by_mode[i])
4721 ci->i_nr_by_mode[i] += count;
4726 spin_unlock(&ci->i_ceph_lock);
4734 void ceph_put_fmode(struct ceph_inode_info *ci, int fmode, int count)
4736 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->netfs.inode.i_sb);
4744 spin_lock(&ci->i_ceph_lock);
4747 BUG_ON(ci->i_nr_by_mode[i] < count);
4748 ci->i_nr_by_mode[i] -= count;
4756 if (i && ci->i_nr_by_mode[i])
4762 spin_unlock(&ci->i_ceph_lock);
4773 struct ceph_inode_info *ci = ceph_inode(inode);
4776 spin_lock(&ci->i_ceph_lock);
4778 drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN);
4780 if (__ceph_caps_dirty(ci)) {
4787 ci->i_ceph_flags |= CEPH_I_FLUSH;
4788 if (!list_empty(&ci->i_cap_delay_list))
4789 list_del_init(&ci->i_cap_delay_list);
4790 list_add_tail(&ci->i_cap_delay_list,
4801 spin_unlock(&ci->i_ceph_lock);
4816 struct ceph_inode_info *ci = ceph_inode(inode);
4823 spin_lock(&ci->i_ceph_lock);
4824 used = __ceph_caps_used(ci);
4825 dirty = __ceph_caps_dirty(ci);
4834 cap = __get_cap_for_mds(ci, mds);
4850 int wanted = __ceph_caps_wanted(ci);
4862 if (cap == ci->i_auth_cap &&
4864 ci->i_requested_max_size = 0;
4888 spin_unlock(&ci->i_ceph_lock);
4959 struct ceph_inode_info *ci = ceph_inode(inode);
4964 lockdep_assert_held(&ci->i_ceph_lock);
4966 doutc(cl, "removing capsnaps, ci is %p, %p %llx.%llx\n",
4967 ci, inode, ceph_vinop(inode));
4969 while (!list_empty(&ci->i_cap_snaps)) {
4970 capsnap = list_first_entry(&ci->i_cap_snaps,
4977 wake_up_all(&ci->i_cap_wq);
4987 struct ceph_inode_info *ci = ceph_inode(inode);
4992 lockdep_assert_held(&ci->i_ceph_lock);
4994 doutc(cl, "removing cap %p, ci is %p, %p %llx.%llx\n",
4995 cap, ci, inode, ceph_vinop(inode));
4997 is_auth = (cap == ci->i_auth_cap);
5005 if (ci->i_wrbuffer_ref > 0)
5012 while (!list_empty(&ci->i_cap_flush_list)) {
5013 cf = list_first_entry(&ci->i_cap_flush_list,
5021 if (!list_empty(&ci->i_dirty_item)) {
5024 ceph_cap_string(ci->i_dirty_caps),
5026 ci->i_dirty_caps = 0;
5027 list_del_init(&ci->i_dirty_item);
5030 if (!list_empty(&ci->i_flushing_item)) {
5033 ceph_cap_string(ci->i_flushing_caps),
5035 ci->i_flushing_caps = 0;
5036 list_del_init(&ci->i_flushing_item);
5045 if (ci->i_wrbuffer_ref_head == 0 &&
5046 ci->i_wr_ref == 0 &&
5047 ci->i_dirty_caps == 0 &&
5048 ci->i_flushing_caps == 0) {
5049 ceph_put_snap_context(ci->i_head_snapc);
5050 ci->i_head_snapc = NULL;
5054 if (atomic_read(&ci->i_filelock_ref) > 0) {
5056 ci->i_ceph_flags |= CEPH_I_ERROR_FILELOCK;
5062 if (!ci->i_dirty_caps && ci->i_prealloc_cap_flush) {
5063 cf = ci->i_prealloc_cap_flush;
5064 ci->i_prealloc_cap_flush = NULL;
5069 if (!list_empty(&ci->i_cap_snaps))