Lines Matching full:ci

48 				 struct ceph_inode_info *ci,
433 static struct ceph_cap *__get_cap_for_mds(struct ceph_inode_info *ci, int mds) in __get_cap_for_mds() argument
436 struct rb_node *n = ci->i_caps.rb_node; in __get_cap_for_mds()
450 struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci, int mds) in ceph_get_cap_for_mds() argument
454 spin_lock(&ci->i_ceph_lock); in ceph_get_cap_for_mds()
455 cap = __get_cap_for_mds(ci, mds); in ceph_get_cap_for_mds()
456 spin_unlock(&ci->i_ceph_lock); in ceph_get_cap_for_mds()
463 static void __insert_cap_node(struct ceph_inode_info *ci, in __insert_cap_node() argument
466 struct rb_node **p = &ci->i_caps.rb_node; in __insert_cap_node()
482 rb_insert_color(&new->ci_node, &ci->i_caps); in __insert_cap_node()
490 struct ceph_inode_info *ci) in __cap_set_timeouts() argument
493 ci->i_hold_caps_max = round_jiffies(jiffies + in __cap_set_timeouts()
495 dout("__cap_set_timeouts %p %lu\n", &ci->vfs_inode, in __cap_set_timeouts()
496 ci->i_hold_caps_max - jiffies); in __cap_set_timeouts()
508 struct ceph_inode_info *ci) in __cap_delay_requeue() argument
510 dout("__cap_delay_requeue %p flags 0x%lx at %lu\n", &ci->vfs_inode, in __cap_delay_requeue()
511 ci->i_ceph_flags, ci->i_hold_caps_max); in __cap_delay_requeue()
514 if (!list_empty(&ci->i_cap_delay_list)) { in __cap_delay_requeue()
515 if (ci->i_ceph_flags & CEPH_I_FLUSH) in __cap_delay_requeue()
517 list_del_init(&ci->i_cap_delay_list); in __cap_delay_requeue()
519 __cap_set_timeouts(mdsc, ci); in __cap_delay_requeue()
520 list_add_tail(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue()
532 struct ceph_inode_info *ci) in __cap_delay_requeue_front() argument
534 dout("__cap_delay_requeue_front %p\n", &ci->vfs_inode); in __cap_delay_requeue_front()
536 ci->i_ceph_flags |= CEPH_I_FLUSH; in __cap_delay_requeue_front()
537 if (!list_empty(&ci->i_cap_delay_list)) in __cap_delay_requeue_front()
538 list_del_init(&ci->i_cap_delay_list); in __cap_delay_requeue_front()
539 list_add(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue_front()
549 struct ceph_inode_info *ci) in __cap_delay_cancel() argument
551 dout("__cap_delay_cancel %p\n", &ci->vfs_inode); in __cap_delay_cancel()
552 if (list_empty(&ci->i_cap_delay_list)) in __cap_delay_cancel()
555 list_del_init(&ci->i_cap_delay_list); in __cap_delay_cancel()
560 static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap, in __check_cap_issue() argument
563 unsigned had = __ceph_caps_issued(ci, NULL); in __check_cap_issue()
565 lockdep_assert_held(&ci->i_ceph_lock); in __check_cap_issue()
571 if (S_ISREG(ci->vfs_inode.i_mode) && in __check_cap_issue()
574 ci->i_rdcache_gen++; in __check_cap_issue()
585 atomic_inc(&ci->i_shared_gen); in __check_cap_issue()
586 if (S_ISDIR(ci->vfs_inode.i_mode)) { in __check_cap_issue()
587 dout(" marking %p NOT complete\n", &ci->vfs_inode); in __check_cap_issue()
588 __ceph_dir_clear_complete(ci); in __check_cap_issue()
593 if (S_ISDIR(ci->vfs_inode.i_mode) && (had & CEPH_CAP_DIR_CREATE) && in __check_cap_issue()
595 ceph_put_string(rcu_dereference_raw(ci->i_cached_layout.pool_ns)); in __check_cap_issue()
596 memset(&ci->i_cached_layout, 0, sizeof(ci->i_cached_layout)); in __check_cap_issue()
602 * @ci: inode to be moved
605 static void change_auth_cap_ses(struct ceph_inode_info *ci, in change_auth_cap_ses() argument
608 lockdep_assert_held(&ci->i_ceph_lock); in change_auth_cap_ses()
610 if (list_empty(&ci->i_dirty_item) && list_empty(&ci->i_flushing_item)) in change_auth_cap_ses()
614 if (!list_empty(&ci->i_dirty_item)) in change_auth_cap_ses()
615 list_move(&ci->i_dirty_item, &session->s_cap_dirty); in change_auth_cap_ses()
616 if (!list_empty(&ci->i_flushing_item)) in change_auth_cap_ses()
617 list_move_tail(&ci->i_flushing_item, &session->s_cap_flushing); in change_auth_cap_ses()
624 * Caller should hold session snap_rwsem (read) and ci->i_ceph_lock
637 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_add_cap() local
643 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()
709 struct ceph_snap_realm *oldrealm = ci->i_snap_realm; in ceph_add_cap()
712 list_del_init(&ci->i_snap_realm_item); in ceph_add_cap()
717 list_add(&ci->i_snap_realm_item, in ceph_add_cap()
719 ci->i_snap_realm = realm; in ceph_add_cap()
720 if (realm->ino == ci->i_vino.ino) in ceph_add_cap()
733 __check_cap_issue(ci, cap, issued); in ceph_add_cap()
740 actual_wanted = __ceph_caps_wanted(ci); in ceph_add_cap()
746 __cap_delay_requeue(mdsc, ci); in ceph_add_cap()
750 if (!ci->i_auth_cap || in ceph_add_cap()
751 ceph_seq_cmp(ci->i_auth_cap->mseq, mseq) < 0) { in ceph_add_cap()
752 if (ci->i_auth_cap && in ceph_add_cap()
753 ci->i_auth_cap->session != cap->session) in ceph_add_cap()
754 change_auth_cap_ses(ci, cap->session); in ceph_add_cap()
755 ci->i_auth_cap = cap; in ceph_add_cap()
759 WARN_ON(ci->i_auth_cap == cap); in ceph_add_cap()
795 "but STALE (gen %u vs %u)\n", &cap->ci->vfs_inode, in __cap_is_valid()
808 int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented) in __ceph_caps_issued() argument
810 int have = ci->i_snap_caps; in __ceph_caps_issued()
816 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued()
821 &ci->vfs_inode, cap, ceph_cap_string(cap->issued)); in __ceph_caps_issued()
831 if (ci->i_auth_cap) { in __ceph_caps_issued()
832 cap = ci->i_auth_cap; in __ceph_caps_issued()
841 int __ceph_caps_issued_other(struct ceph_inode_info *ci, struct ceph_cap *ocap) in __ceph_caps_issued_other() argument
843 int have = ci->i_snap_caps; in __ceph_caps_issued_other()
847 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued_other()
868 dout("__touch_cap %p cap %p mds%d\n", &cap->ci->vfs_inode, cap, in __touch_cap()
873 &cap->ci->vfs_inode, cap, s->s_mds); in __touch_cap()
883 int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int touch) in __ceph_caps_issued_mask() argument
887 int have = ci->i_snap_caps; in __ceph_caps_issued_mask()
891 " (mask %s)\n", ceph_ino(&ci->vfs_inode), in __ceph_caps_issued_mask()
897 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued_mask()
903 " (mask %s)\n", ceph_ino(&ci->vfs_inode), cap, in __ceph_caps_issued_mask()
915 " (mask %s)\n", ceph_ino(&ci->vfs_inode), in __ceph_caps_issued_mask()
923 for (q = rb_first(&ci->i_caps); q != p; in __ceph_caps_issued_mask()
940 int __ceph_caps_issued_mask_metric(struct ceph_inode_info *ci, int mask, in __ceph_caps_issued_mask_metric() argument
943 struct ceph_fs_client *fsc = ceph_sb_to_client(ci->vfs_inode.i_sb); in __ceph_caps_issued_mask_metric()
946 r = __ceph_caps_issued_mask(ci, mask, touch); in __ceph_caps_issued_mask_metric()
957 int __ceph_caps_revoking_other(struct ceph_inode_info *ci, in __ceph_caps_revoking_other() argument
963 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_revoking_other()
972 int ceph_caps_revoking(struct ceph_inode_info *ci, int mask) in ceph_caps_revoking() argument
974 struct inode *inode = &ci->vfs_inode; in ceph_caps_revoking()
977 spin_lock(&ci->i_ceph_lock); in ceph_caps_revoking()
978 ret = __ceph_caps_revoking_other(ci, NULL, mask); in ceph_caps_revoking()
979 spin_unlock(&ci->i_ceph_lock); in ceph_caps_revoking()
985 int __ceph_caps_used(struct ceph_inode_info *ci) in __ceph_caps_used() argument
988 if (ci->i_pin_ref) in __ceph_caps_used()
990 if (ci->i_rd_ref) in __ceph_caps_used()
992 if (ci->i_rdcache_ref || in __ceph_caps_used()
993 (S_ISREG(ci->vfs_inode.i_mode) && in __ceph_caps_used()
994 ci->vfs_inode.i_data.nrpages)) in __ceph_caps_used()
996 if (ci->i_wr_ref) in __ceph_caps_used()
998 if (ci->i_wb_ref || ci->i_wrbuffer_ref) in __ceph_caps_used()
1000 if (ci->i_fx_ref) in __ceph_caps_used()
1010 int __ceph_caps_file_wanted(struct ceph_inode_info *ci) in __ceph_caps_file_wanted() argument
1017 ceph_inode_to_client(&ci->vfs_inode)->mount_options; in __ceph_caps_file_wanted()
1021 if (S_ISDIR(ci->vfs_inode.i_mode)) { in __ceph_caps_file_wanted()
1025 if (ci->i_nr_by_mode[RD_SHIFT] > 0 || in __ceph_caps_file_wanted()
1026 time_after(ci->i_last_rd, used_cutoff)) in __ceph_caps_file_wanted()
1029 if (ci->i_nr_by_mode[WR_SHIFT] > 0 || in __ceph_caps_file_wanted()
1030 time_after(ci->i_last_wr, used_cutoff)) { in __ceph_caps_file_wanted()
1036 if (want || ci->i_nr_by_mode[PIN_SHIFT] > 0) in __ceph_caps_file_wanted()
1043 if (ci->i_nr_by_mode[RD_SHIFT] > 0) { in __ceph_caps_file_wanted()
1044 if (ci->i_nr_by_mode[RD_SHIFT] >= FMODE_WAIT_BIAS || in __ceph_caps_file_wanted()
1045 time_after(ci->i_last_rd, used_cutoff)) in __ceph_caps_file_wanted()
1047 } else if (time_after(ci->i_last_rd, idle_cutoff)) { in __ceph_caps_file_wanted()
1051 if (ci->i_nr_by_mode[WR_SHIFT] > 0) { in __ceph_caps_file_wanted()
1052 if (ci->i_nr_by_mode[WR_SHIFT] >= FMODE_WAIT_BIAS || in __ceph_caps_file_wanted()
1053 time_after(ci->i_last_wr, used_cutoff)) in __ceph_caps_file_wanted()
1055 } else if (time_after(ci->i_last_wr, idle_cutoff)) { in __ceph_caps_file_wanted()
1061 ci->i_nr_by_mode[LAZY_SHIFT] > 0) in __ceph_caps_file_wanted()
1071 int __ceph_caps_wanted(struct ceph_inode_info *ci) in __ceph_caps_wanted() argument
1073 int w = __ceph_caps_file_wanted(ci) | __ceph_caps_used(ci); in __ceph_caps_wanted()
1074 if (S_ISDIR(ci->vfs_inode.i_mode)) { in __ceph_caps_wanted()
1089 int __ceph_caps_mds_wanted(struct ceph_inode_info *ci, bool check) in __ceph_caps_mds_wanted() argument
1095 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_mds_wanted()
1099 if (cap == ci->i_auth_cap) in __ceph_caps_mds_wanted()
1109 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_is_any_caps() local
1112 spin_lock(&ci->i_ceph_lock); in ceph_is_any_caps()
1113 ret = __ceph_is_any_real_caps(ci); in ceph_is_any_caps()
1114 spin_unlock(&ci->i_ceph_lock); in ceph_is_any_caps()
1119 static void drop_inode_snap_realm(struct ceph_inode_info *ci) in drop_inode_snap_realm() argument
1121 struct ceph_snap_realm *realm = ci->i_snap_realm; in drop_inode_snap_realm()
1123 list_del_init(&ci->i_snap_realm_item); in drop_inode_snap_realm()
1124 ci->i_snap_realm_counter++; in drop_inode_snap_realm()
1125 ci->i_snap_realm = NULL; in drop_inode_snap_realm()
1126 if (realm->ino == ci->i_vino.ino) in drop_inode_snap_realm()
1129 ceph_put_snap_realm(ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc, in drop_inode_snap_realm()
1142 struct ceph_inode_info *ci = cap->ci; in __ceph_remove_cap() local
1146 /* 'ci' being NULL means the remove have already occurred */ in __ceph_remove_cap()
1147 if (!ci) { in __ceph_remove_cap()
1152 dout("__ceph_remove_cap %p from %p\n", cap, &ci->vfs_inode); in __ceph_remove_cap()
1154 mdsc = ceph_inode_to_client(&ci->vfs_inode)->mdsc; in __ceph_remove_cap()
1157 rb_erase(&cap->ci_node, &ci->i_caps); in __ceph_remove_cap()
1158 if (ci->i_auth_cap == cap) { in __ceph_remove_cap()
1159 WARN_ON_ONCE(!list_empty(&ci->i_dirty_item)); in __ceph_remove_cap()
1160 ci->i_auth_cap = NULL; in __ceph_remove_cap()
1177 cap->ci = NULL; in __ceph_remove_cap()
1193 cap->cap_ino = ci->i_vino.ino; in __ceph_remove_cap()
1200 if (!__ceph_is_any_real_caps(ci)) { in __ceph_remove_cap()
1205 if (ci->i_wr_ref == 0 && ci->i_snap_realm) in __ceph_remove_cap()
1206 drop_inode_snap_realm(ci); in __ceph_remove_cap()
1208 __cap_delay_cancel(mdsc, ci); in __ceph_remove_cap()
1329 void __ceph_remove_caps(struct ceph_inode_info *ci) in __ceph_remove_caps() argument
1335 spin_lock(&ci->i_ceph_lock); in __ceph_remove_caps()
1336 p = rb_first(&ci->i_caps); in __ceph_remove_caps()
1342 spin_unlock(&ci->i_ceph_lock); in __ceph_remove_caps()
1357 struct ceph_inode_info *ci = cap->ci; in __prep_cap() local
1358 struct inode *inode = &ci->vfs_inode; in __prep_cap()
1361 lockdep_assert_held(&ci->i_ceph_lock); in __prep_cap()
1373 ci->i_ceph_flags &= ~CEPH_I_FLUSH; in __prep_cap()
1388 arg->follows = flushing ? ci->i_head_snapc->seq : 0; in __prep_cap()
1393 ci->i_reported_size = arg->size; in __prep_cap()
1394 arg->max_size = ci->i_wanted_max_size; in __prep_cap()
1395 if (cap == ci->i_auth_cap) { in __prep_cap()
1397 ci->i_requested_max_size = arg->max_size; in __prep_cap()
1399 ci->i_requested_max_size = 0; in __prep_cap()
1403 arg->old_xattr_buf = __ceph_build_xattrs_blob(ci); in __prep_cap()
1404 arg->xattr_version = ci->i_xattrs.version; in __prep_cap()
1405 arg->xattr_buf = ci->i_xattrs.blob; in __prep_cap()
1414 arg->btime = ci->i_btime; in __prep_cap()
1425 arg->time_warp_seq = ci->i_time_warp_seq; in __prep_cap()
1431 arg->inline_data = ci->i_inline_version != CEPH_INLINE_NONE; in __prep_cap()
1433 !list_empty(&ci->i_cap_snaps)) { in __prep_cap()
1435 list_for_each_entry_reverse(capsnap, &ci->i_cap_snaps, ci_item) { in __prep_cap()
1452 static void __send_cap(struct cap_msg_args *arg, struct ceph_inode_info *ci) in __send_cap() argument
1455 struct inode *inode = &ci->vfs_inode; in __send_cap()
1462 spin_lock(&ci->i_ceph_lock); in __send_cap()
1463 __cap_delay_requeue(arg->session->s_mdsc, ci); in __send_cap()
1464 spin_unlock(&ci->i_ceph_lock); in __send_cap()
1472 wake_up_all(&ci->i_cap_wq); in __send_cap()
1538 static void __ceph_flush_snaps(struct ceph_inode_info *ci, in __ceph_flush_snaps() argument
1540 __releases(ci->i_ceph_lock) in __ceph_flush_snaps()
1541 __acquires(ci->i_ceph_lock) in __ceph_flush_snaps()
1543 struct inode *inode = &ci->vfs_inode; in __ceph_flush_snaps()
1551 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { in __ceph_flush_snaps()
1574 if (list_empty(&ci->i_flushing_item)) { in __ceph_flush_snaps()
1575 list_add_tail(&ci->i_flushing_item, in __ceph_flush_snaps()
1581 &ci->i_cap_flush_list); in __ceph_flush_snaps()
1588 ci->i_ceph_flags &= ~CEPH_I_FLUSH_SNAPS; in __ceph_flush_snaps()
1591 struct ceph_cap *cap = ci->i_auth_cap; in __ceph_flush_snaps()
1602 list_for_each_entry(cf, &ci->i_cap_flush_list, i_list) { in __ceph_flush_snaps()
1615 spin_unlock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1629 spin_lock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1633 void ceph_flush_snaps(struct ceph_inode_info *ci, in ceph_flush_snaps() argument
1636 struct inode *inode = &ci->vfs_inode; in ceph_flush_snaps()
1645 spin_lock(&ci->i_ceph_lock); in ceph_flush_snaps()
1646 if (!(ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS)) { in ceph_flush_snaps()
1650 if (!ci->i_auth_cap) { in ceph_flush_snaps()
1655 mds = ci->i_auth_cap->session->s_mds; in ceph_flush_snaps()
1663 spin_unlock(&ci->i_ceph_lock); in ceph_flush_snaps()
1675 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) in ceph_flush_snaps()
1676 __kick_flushing_caps(mdsc, session, ci, 0); in ceph_flush_snaps()
1678 __ceph_flush_snaps(ci, session); in ceph_flush_snaps()
1680 spin_unlock(&ci->i_ceph_lock); in ceph_flush_snaps()
1690 list_del_init(&ci->i_snap_flush_item); in ceph_flush_snaps()
1699 int __ceph_mark_dirty_caps(struct ceph_inode_info *ci, int mask, in __ceph_mark_dirty_caps() argument
1703 ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc; in __ceph_mark_dirty_caps()
1704 struct inode *inode = &ci->vfs_inode; in __ceph_mark_dirty_caps()
1705 int was = ci->i_dirty_caps; in __ceph_mark_dirty_caps()
1708 lockdep_assert_held(&ci->i_ceph_lock); in __ceph_mark_dirty_caps()
1710 if (!ci->i_auth_cap) { in __ceph_mark_dirty_caps()
1717 dout("__mark_dirty_caps %p %s dirty %s -> %s\n", &ci->vfs_inode, in __ceph_mark_dirty_caps()
1720 ci->i_dirty_caps |= mask; in __ceph_mark_dirty_caps()
1722 struct ceph_mds_session *session = ci->i_auth_cap->session; in __ceph_mark_dirty_caps()
1724 WARN_ON_ONCE(ci->i_prealloc_cap_flush); in __ceph_mark_dirty_caps()
1725 swap(ci->i_prealloc_cap_flush, *pcf); in __ceph_mark_dirty_caps()
1727 if (!ci->i_head_snapc) { in __ceph_mark_dirty_caps()
1729 ci->i_head_snapc = ceph_get_snap_context( in __ceph_mark_dirty_caps()
1730 ci->i_snap_realm->cached_context); in __ceph_mark_dirty_caps()
1733 &ci->vfs_inode, ci->i_head_snapc, ci->i_auth_cap); in __ceph_mark_dirty_caps()
1734 BUG_ON(!list_empty(&ci->i_dirty_item)); in __ceph_mark_dirty_caps()
1736 list_add(&ci->i_dirty_item, &session->s_cap_dirty); in __ceph_mark_dirty_caps()
1738 if (ci->i_flushing_caps == 0) { in __ceph_mark_dirty_caps()
1743 WARN_ON_ONCE(!ci->i_prealloc_cap_flush); in __ceph_mark_dirty_caps()
1745 BUG_ON(list_empty(&ci->i_dirty_item)); in __ceph_mark_dirty_caps()
1746 if (((was | ci->i_flushing_caps) & CEPH_CAP_FILE_BUFFER) && in __ceph_mark_dirty_caps()
1749 __cap_delay_requeue(mdsc, ci); in __ceph_mark_dirty_caps()
1801 static bool __detach_cap_flush_from_ci(struct ceph_inode_info *ci, in __detach_cap_flush_from_ci() argument
1807 if (wake && cf->i_list.prev != &ci->i_cap_flush_list) { in __detach_cap_flush_from_ci()
1827 struct ceph_inode_info *ci = ceph_inode(inode); in __mark_caps_flushing() local
1831 lockdep_assert_held(&ci->i_ceph_lock); in __mark_caps_flushing()
1832 BUG_ON(ci->i_dirty_caps == 0); in __mark_caps_flushing()
1833 BUG_ON(list_empty(&ci->i_dirty_item)); in __mark_caps_flushing()
1834 BUG_ON(!ci->i_prealloc_cap_flush); in __mark_caps_flushing()
1836 flushing = ci->i_dirty_caps; in __mark_caps_flushing()
1839 ceph_cap_string(ci->i_flushing_caps), in __mark_caps_flushing()
1840 ceph_cap_string(ci->i_flushing_caps | flushing)); in __mark_caps_flushing()
1841 ci->i_flushing_caps |= flushing; in __mark_caps_flushing()
1842 ci->i_dirty_caps = 0; in __mark_caps_flushing()
1845 swap(cf, ci->i_prealloc_cap_flush); in __mark_caps_flushing()
1850 list_del_init(&ci->i_dirty_item); in __mark_caps_flushing()
1856 if (list_empty(&ci->i_flushing_item)) { in __mark_caps_flushing()
1857 list_add_tail(&ci->i_flushing_item, &session->s_cap_flushing); in __mark_caps_flushing()
1862 list_add_tail(&cf->i_list, &ci->i_cap_flush_list); in __mark_caps_flushing()
1871 __releases(ci->i_ceph_lock) in try_nonblocking_invalidate()
1872 __acquires(ci->i_ceph_lock) in try_nonblocking_invalidate()
1874 struct ceph_inode_info *ci = ceph_inode(inode); in try_nonblocking_invalidate() local
1875 u32 invalidating_gen = ci->i_rdcache_gen; in try_nonblocking_invalidate()
1877 spin_unlock(&ci->i_ceph_lock); in try_nonblocking_invalidate()
1880 spin_lock(&ci->i_ceph_lock); in try_nonblocking_invalidate()
1883 invalidating_gen == ci->i_rdcache_gen) { in try_nonblocking_invalidate()
1887 ci->i_rdcache_revoking = ci->i_rdcache_gen - 1; in try_nonblocking_invalidate()
1894 bool __ceph_should_report_size(struct ceph_inode_info *ci) in __ceph_should_report_size() argument
1896 loff_t size = ci->vfs_inode.i_size; in __ceph_should_report_size()
1898 if (ci->i_flushing_caps & CEPH_CAP_FILE_WR) in __ceph_should_report_size()
1900 if (size >= ci->i_max_size) in __ceph_should_report_size()
1903 if (ci->i_max_size > ci->i_reported_size && in __ceph_should_report_size()
1904 (size << 1) >= ci->i_max_size + ci->i_reported_size) in __ceph_should_report_size()
1918 void ceph_check_caps(struct ceph_inode_info *ci, int flags, in ceph_check_caps() argument
1921 struct inode *inode = &ci->vfs_inode; in ceph_check_caps()
1934 spin_lock(&ci->i_ceph_lock); in ceph_check_caps()
1935 if (ci->i_ceph_flags & CEPH_I_FLUSH) in ceph_check_caps()
1940 spin_lock(&ci->i_ceph_lock); in ceph_check_caps()
1943 file_wanted = __ceph_caps_file_wanted(ci); in ceph_check_caps()
1946 used = __ceph_caps_used(ci); in ceph_check_caps()
1954 issued = __ceph_caps_issued(ci, &implemented); in ceph_check_caps()
1966 __ceph_dir_is_complete(ci)) { in ceph_check_caps()
1987 if (ci->i_max_size == 0) in ceph_check_caps()
1995 ceph_cap_string(used), ceph_cap_string(ci->i_dirty_caps), in ceph_check_caps()
1996 ceph_cap_string(ci->i_flushing_caps), in ceph_check_caps()
2009 !(ci->i_wb_ref || ci->i_wrbuffer_ref) && /* no dirty pages... */ in ceph_check_caps()
2018 ci->i_rdcache_revoking = ci->i_rdcache_gen; in ceph_check_caps()
2024 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in ceph_check_caps()
2032 ((flags & CHECK_CAPS_AUTHONLY) && cap != ci->i_auth_cap)) in ceph_check_caps()
2042 if (ci->i_auth_cap && cap != ci->i_auth_cap) in ceph_check_caps()
2043 cap_used &= ~ci->i_auth_cap->issued; in ceph_check_caps()
2052 if (cap == ci->i_auth_cap && in ceph_check_caps()
2055 if (ci->i_wanted_max_size > ci->i_max_size && in ceph_check_caps()
2056 ci->i_wanted_max_size > ci->i_requested_max_size) { in ceph_check_caps()
2062 if (__ceph_should_report_size(ci)) { in ceph_check_caps()
2068 if (cap == ci->i_auth_cap) { in ceph_check_caps()
2069 if ((flags & CHECK_CAPS_FLUSH) && ci->i_dirty_caps) { in ceph_check_caps()
2073 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) { in ceph_check_caps()
2110 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
2133 if (cap == ci->i_auth_cap && in ceph_check_caps()
2134 (ci->i_ceph_flags & in ceph_check_caps()
2136 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) in ceph_check_caps()
2137 __kick_flushing_caps(mdsc, session, ci, 0); in ceph_check_caps()
2138 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) in ceph_check_caps()
2139 __ceph_flush_snaps(ci, session); in ceph_check_caps()
2149 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
2157 if (cap == ci->i_auth_cap && ci->i_dirty_caps) { in ceph_check_caps()
2158 flushing = ci->i_dirty_caps; in ceph_check_caps()
2176 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
2178 __send_cap(&arg, ci); in ceph_check_caps()
2184 if (__ceph_is_any_real_caps(ci) && in ceph_check_caps()
2185 list_empty(&ci->i_cap_delay_list) && in ceph_check_caps()
2188 __cap_delay_requeue(mdsc, ci); in ceph_check_caps()
2191 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
2208 struct ceph_inode_info *ci = ceph_inode(inode); in try_flush_caps() local
2214 spin_lock(&ci->i_ceph_lock); in try_flush_caps()
2216 if (ci->i_dirty_caps && ci->i_auth_cap) { in try_flush_caps()
2217 struct ceph_cap *cap = ci->i_auth_cap; in try_flush_caps()
2221 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2229 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2233 if (ci->i_ceph_flags & in try_flush_caps()
2235 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) in try_flush_caps()
2236 __kick_flushing_caps(mdsc, session, ci, 0); in try_flush_caps()
2237 if (ci->i_ceph_flags & CEPH_I_FLUSH_SNAPS) in try_flush_caps()
2238 __ceph_flush_snaps(ci, session); in try_flush_caps()
2242 flushing = ci->i_dirty_caps; in try_flush_caps()
2247 __ceph_caps_used(ci), __ceph_caps_wanted(ci), in try_flush_caps()
2250 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2252 __send_cap(&arg, ci); in try_flush_caps()
2254 if (!list_empty(&ci->i_cap_flush_list)) { in try_flush_caps()
2256 list_last_entry(&ci->i_cap_flush_list, in try_flush_caps()
2261 flushing = ci->i_flushing_caps; in try_flush_caps()
2262 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
2277 struct ceph_inode_info *ci = ceph_inode(inode); in caps_are_flushed() local
2280 spin_lock(&ci->i_ceph_lock); in caps_are_flushed()
2281 if (!list_empty(&ci->i_cap_flush_list)) { in caps_are_flushed()
2283 list_first_entry(&ci->i_cap_flush_list, in caps_are_flushed()
2288 spin_unlock(&ci->i_ceph_lock); in caps_are_flushed()
2298 struct ceph_inode_info *ci = ceph_inode(inode); in unsafe_request_wait() local
2302 spin_lock(&ci->i_unsafe_lock); in unsafe_request_wait()
2303 if (S_ISDIR(inode->i_mode) && !list_empty(&ci->i_unsafe_dirops)) { in unsafe_request_wait()
2304 req1 = list_last_entry(&ci->i_unsafe_dirops, in unsafe_request_wait()
2309 if (!list_empty(&ci->i_unsafe_iops)) { in unsafe_request_wait()
2310 req2 = list_last_entry(&ci->i_unsafe_iops, in unsafe_request_wait()
2315 spin_unlock(&ci->i_unsafe_lock); in unsafe_request_wait()
2339 spin_lock(&ci->i_unsafe_lock); in unsafe_request_wait()
2341 list_for_each_entry(req, &ci->i_unsafe_dirops, in unsafe_request_wait()
2353 list_for_each_entry(req, &ci->i_unsafe_iops, in unsafe_request_wait()
2364 spin_unlock(&ci->i_unsafe_lock); in unsafe_request_wait()
2367 spin_lock(&ci->i_ceph_lock); in unsafe_request_wait()
2368 if (ci->i_auth_cap) { in unsafe_request_wait()
2369 s = ci->i_auth_cap->session; in unsafe_request_wait()
2373 spin_unlock(&ci->i_ceph_lock); in unsafe_request_wait()
2413 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_fsync() local
2439 err = wait_event_interruptible(ci->i_cap_wq, in ceph_fsync()
2462 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_write_inode() local
2472 err = wait_event_interruptible(ci->i_cap_wq, in ceph_write_inode()
2478 spin_lock(&ci->i_ceph_lock); in ceph_write_inode()
2479 if (__ceph_caps_dirty(ci)) in ceph_write_inode()
2480 __cap_delay_requeue_front(mdsc, ci); in ceph_write_inode()
2481 spin_unlock(&ci->i_ceph_lock); in ceph_write_inode()
2488 struct ceph_inode_info *ci, in __kick_flushing_caps() argument
2490 __releases(ci->i_ceph_lock) in __kick_flushing_caps()
2491 __acquires(ci->i_ceph_lock) in __kick_flushing_caps()
2493 struct inode *inode = &ci->vfs_inode; in __kick_flushing_caps()
2500 ci->i_ceph_flags &= ~CEPH_I_KICK_FLUSH; in __kick_flushing_caps()
2502 list_for_each_entry_reverse(cf, &ci->i_cap_flush_list, i_list) { in __kick_flushing_caps()
2509 list_for_each_entry(cf, &ci->i_cap_flush_list, i_list) { in __kick_flushing_caps()
2513 cap = ci->i_auth_cap; in __kick_flushing_caps()
2530 __ceph_caps_used(ci), in __kick_flushing_caps()
2531 __ceph_caps_wanted(ci), in __kick_flushing_caps()
2534 spin_unlock(&ci->i_ceph_lock); in __kick_flushing_caps()
2535 __send_cap(&arg, ci); in __kick_flushing_caps()
2545 spin_unlock(&ci->i_ceph_lock); in __kick_flushing_caps()
2560 spin_lock(&ci->i_ceph_lock); in __kick_flushing_caps()
2567 struct ceph_inode_info *ci; in ceph_early_kick_flushing_caps() local
2577 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) { in ceph_early_kick_flushing_caps()
2578 spin_lock(&ci->i_ceph_lock); in ceph_early_kick_flushing_caps()
2579 cap = ci->i_auth_cap; in ceph_early_kick_flushing_caps()
2582 &ci->vfs_inode, cap, session->s_mds); in ceph_early_kick_flushing_caps()
2583 spin_unlock(&ci->i_ceph_lock); in ceph_early_kick_flushing_caps()
2594 if ((cap->issued & ci->i_flushing_caps) != in ceph_early_kick_flushing_caps()
2595 ci->i_flushing_caps) { in ceph_early_kick_flushing_caps()
2602 __kick_flushing_caps(mdsc, session, ci, in ceph_early_kick_flushing_caps()
2605 ci->i_ceph_flags |= CEPH_I_KICK_FLUSH; in ceph_early_kick_flushing_caps()
2608 spin_unlock(&ci->i_ceph_lock); in ceph_early_kick_flushing_caps()
2615 struct ceph_inode_info *ci; in ceph_kick_flushing_caps() local
2627 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) { in ceph_kick_flushing_caps()
2628 spin_lock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2629 cap = ci->i_auth_cap; in ceph_kick_flushing_caps()
2632 &ci->vfs_inode, cap, session->s_mds); in ceph_kick_flushing_caps()
2633 spin_unlock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2636 if (ci->i_ceph_flags & CEPH_I_KICK_FLUSH) { in ceph_kick_flushing_caps()
2637 __kick_flushing_caps(mdsc, session, ci, in ceph_kick_flushing_caps()
2640 spin_unlock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2645 struct ceph_inode_info *ci) in ceph_kick_flushing_inode_caps() argument
2648 struct ceph_cap *cap = ci->i_auth_cap; in ceph_kick_flushing_inode_caps()
2650 lockdep_assert_held(&ci->i_ceph_lock); in ceph_kick_flushing_inode_caps()
2652 dout("%s %p flushing %s\n", __func__, &ci->vfs_inode, in ceph_kick_flushing_inode_caps()
2653 ceph_cap_string(ci->i_flushing_caps)); in ceph_kick_flushing_inode_caps()
2655 if (!list_empty(&ci->i_cap_flush_list)) { in ceph_kick_flushing_inode_caps()
2658 list_move_tail(&ci->i_flushing_item, in ceph_kick_flushing_inode_caps()
2663 __kick_flushing_caps(mdsc, session, ci, oldest_flush_tid); in ceph_kick_flushing_inode_caps()
2672 void ceph_take_cap_refs(struct ceph_inode_info *ci, int got, in ceph_take_cap_refs() argument
2675 lockdep_assert_held(&ci->i_ceph_lock); in ceph_take_cap_refs()
2678 ci->i_pin_ref++; in ceph_take_cap_refs()
2680 ci->i_rd_ref++; in ceph_take_cap_refs()
2682 ci->i_rdcache_ref++; in ceph_take_cap_refs()
2684 ci->i_fx_ref++; in ceph_take_cap_refs()
2686 if (ci->i_wr_ref == 0 && !ci->i_head_snapc) { in ceph_take_cap_refs()
2688 ci->i_head_snapc = ceph_get_snap_context( in ceph_take_cap_refs()
2689 ci->i_snap_realm->cached_context); in ceph_take_cap_refs()
2691 ci->i_wr_ref++; in ceph_take_cap_refs()
2694 if (ci->i_wb_ref == 0) in ceph_take_cap_refs()
2695 ihold(&ci->vfs_inode); in ceph_take_cap_refs()
2696 ci->i_wb_ref++; in ceph_take_cap_refs()
2698 &ci->vfs_inode, ci->i_wb_ref-1, ci->i_wb_ref); in ceph_take_cap_refs()
2724 struct ceph_inode_info *ci = ceph_inode(inode); in try_get_cap_refs() local
2734 spin_lock(&ci->i_ceph_lock); in try_get_cap_refs()
2737 (ci->i_ceph_flags & CEPH_I_ERROR_FILELOCK)) { in try_get_cap_refs()
2744 while (ci->i_truncate_pending) { in try_get_cap_refs()
2745 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2751 spin_lock(&ci->i_ceph_lock); in try_get_cap_refs()
2754 have = __ceph_caps_issued(ci, &implemented); in try_get_cap_refs()
2757 if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) { in try_get_cap_refs()
2759 inode, endoff, ci->i_max_size); in try_get_cap_refs()
2760 if (endoff > ci->i_requested_max_size) in try_get_cap_refs()
2761 ret = ci->i_auth_cap ? -EFBIG : -ESTALE; in try_get_cap_refs()
2768 if (__ceph_have_pending_cap_snap(ci)) { in try_get_cap_refs()
2788 !ci->i_head_snapc && in try_get_cap_refs()
2800 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2814 ceph_disable_fscache_readpage(ci); in try_get_cap_refs()
2815 ceph_take_cap_refs(ci, *got, true); in try_get_cap_refs()
2821 if (ci->i_auth_cap && in try_get_cap_refs()
2823 struct ceph_mds_session *s = ci->i_auth_cap->session; in try_get_cap_refs()
2830 inode, ceph_cap_string(need), ci->i_auth_cap->mds); in try_get_cap_refs()
2840 mds_wanted = __ceph_caps_mds_wanted(ci, false); in try_get_cap_refs()
2854 __ceph_touch_fmode(ci, mdsc, flags); in try_get_cap_refs()
2856 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2877 struct ceph_inode_info *ci = ceph_inode(inode); in check_max_size() local
2881 spin_lock(&ci->i_ceph_lock); in check_max_size()
2882 if (endoff >= ci->i_max_size && endoff > ci->i_wanted_max_size) { in check_max_size()
2885 ci->i_wanted_max_size = endoff; in check_max_size()
2888 if (ci->i_auth_cap && in check_max_size()
2889 (ci->i_auth_cap->issued & CEPH_CAP_FILE_WR) && in check_max_size()
2890 ci->i_wanted_max_size > ci->i_max_size && in check_max_size()
2891 ci->i_wanted_max_size > ci->i_requested_max_size) in check_max_size()
2893 spin_unlock(&ci->i_ceph_lock); in check_max_size()
2895 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL); in check_max_size()
2944 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_get_caps() local
2981 ceph_get_fmode(ci, flags, FMODE_WAIT_BIAS); in ceph_get_caps()
2982 add_wait_queue(&ci->i_cap_wq, &wait); in ceph_get_caps()
2994 remove_wait_queue(&ci->i_cap_wq, &wait); in ceph_get_caps()
2995 ceph_put_fmode(ci, flags, FMODE_WAIT_BIAS); in ceph_get_caps()
3008 ceph_put_cap_refs(ci, _got); in ceph_get_caps()
3031 if (S_ISREG(ci->vfs_inode.i_mode) && in ceph_get_caps()
3032 ci->i_inline_version != CEPH_INLINE_NONE && in ceph_get_caps()
3048 ceph_put_cap_refs(ci, _got); in ceph_get_caps()
3065 if (S_ISREG(ci->vfs_inode.i_mode) && in ceph_get_caps()
3067 ceph_fscache_revalidate_cookie(ci); in ceph_get_caps()
3077 void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps) in ceph_get_cap_refs() argument
3079 spin_lock(&ci->i_ceph_lock); in ceph_get_cap_refs()
3080 ceph_take_cap_refs(ci, caps, false); in ceph_get_cap_refs()
3081 spin_unlock(&ci->i_ceph_lock); in ceph_get_cap_refs()
3089 static int ceph_try_drop_cap_snap(struct ceph_inode_info *ci, in ceph_try_drop_cap_snap() argument
3098 if (!list_is_last(&capsnap->ci_item, &ci->i_cap_snaps)) in ceph_try_drop_cap_snap()
3099 ci->i_ceph_flags |= CEPH_I_FLUSH_SNAPS; in ceph_try_drop_cap_snap()
3117 static void __ceph_put_cap_refs(struct ceph_inode_info *ci, int had, in __ceph_put_cap_refs() argument
3120 struct inode *inode = &ci->vfs_inode; in __ceph_put_cap_refs()
3123 spin_lock(&ci->i_ceph_lock); in __ceph_put_cap_refs()
3125 --ci->i_pin_ref; in __ceph_put_cap_refs()
3127 if (--ci->i_rd_ref == 0) in __ceph_put_cap_refs()
3130 if (--ci->i_rdcache_ref == 0) in __ceph_put_cap_refs()
3133 if (--ci->i_fx_ref == 0) in __ceph_put_cap_refs()
3136 if (--ci->i_wb_ref == 0) { in __ceph_put_cap_refs()
3141 inode, ci->i_wb_ref+1, ci->i_wb_ref); in __ceph_put_cap_refs()
3144 if (--ci->i_wr_ref == 0) { in __ceph_put_cap_refs()
3146 if (__ceph_have_pending_cap_snap(ci)) { in __ceph_put_cap_refs()
3148 list_last_entry(&ci->i_cap_snaps, in __ceph_put_cap_refs()
3152 if (ceph_try_drop_cap_snap(ci, capsnap)) in __ceph_put_cap_refs()
3154 else if (__ceph_finish_cap_snap(ci, capsnap)) in __ceph_put_cap_refs()
3158 if (ci->i_wrbuffer_ref_head == 0 && in __ceph_put_cap_refs()
3159 ci->i_dirty_caps == 0 && in __ceph_put_cap_refs()
3160 ci->i_flushing_caps == 0) { in __ceph_put_cap_refs()
3161 BUG_ON(!ci->i_head_snapc); in __ceph_put_cap_refs()
3162 ceph_put_snap_context(ci->i_head_snapc); in __ceph_put_cap_refs()
3163 ci->i_head_snapc = NULL; in __ceph_put_cap_refs()
3166 if (!__ceph_is_any_real_caps(ci) && ci->i_snap_realm) in __ceph_put_cap_refs()
3167 drop_inode_snap_realm(ci); in __ceph_put_cap_refs()
3169 spin_unlock(&ci->i_ceph_lock); in __ceph_put_cap_refs()
3176 ceph_check_caps(ci, 0, NULL); in __ceph_put_cap_refs()
3178 ceph_flush_snaps(ci, NULL); in __ceph_put_cap_refs()
3181 wake_up_all(&ci->i_cap_wq); in __ceph_put_cap_refs()
3186 void ceph_put_cap_refs(struct ceph_inode_info *ci, int had) in ceph_put_cap_refs() argument
3188 __ceph_put_cap_refs(ci, had, false); in ceph_put_cap_refs()
3191 void ceph_put_cap_refs_no_check_caps(struct ceph_inode_info *ci, int had) in ceph_put_cap_refs_no_check_caps() argument
3193 __ceph_put_cap_refs(ci, had, true); in ceph_put_cap_refs_no_check_caps()
3203 void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr, in ceph_put_wrbuffer_cap_refs() argument
3206 struct inode *inode = &ci->vfs_inode; in ceph_put_wrbuffer_cap_refs()
3214 spin_lock(&ci->i_ceph_lock); in ceph_put_wrbuffer_cap_refs()
3215 ci->i_wrbuffer_ref -= nr; in ceph_put_wrbuffer_cap_refs()
3216 if (ci->i_wrbuffer_ref == 0) { in ceph_put_wrbuffer_cap_refs()
3221 if (ci->i_head_snapc == snapc) { in ceph_put_wrbuffer_cap_refs()
3222 ci->i_wrbuffer_ref_head -= nr; in ceph_put_wrbuffer_cap_refs()
3223 if (ci->i_wrbuffer_ref_head == 0 && in ceph_put_wrbuffer_cap_refs()
3224 ci->i_wr_ref == 0 && in ceph_put_wrbuffer_cap_refs()
3225 ci->i_dirty_caps == 0 && in ceph_put_wrbuffer_cap_refs()
3226 ci->i_flushing_caps == 0) { in ceph_put_wrbuffer_cap_refs()
3227 BUG_ON(!ci->i_head_snapc); in ceph_put_wrbuffer_cap_refs()
3228 ceph_put_snap_context(ci->i_head_snapc); in ceph_put_wrbuffer_cap_refs()
3229 ci->i_head_snapc = NULL; in ceph_put_wrbuffer_cap_refs()
3233 ci->i_wrbuffer_ref+nr, ci->i_wrbuffer_ref_head+nr, in ceph_put_wrbuffer_cap_refs()
3234 ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head, in ceph_put_wrbuffer_cap_refs()
3237 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { in ceph_put_wrbuffer_cap_refs()
3249 WARN_ON_ONCE(ci->i_auth_cap); in ceph_put_wrbuffer_cap_refs()
3257 if (ceph_try_drop_cap_snap(ci, capsnap)) { in ceph_put_wrbuffer_cap_refs()
3260 ci->i_ceph_flags |= CEPH_I_FLUSH_SNAPS; in ceph_put_wrbuffer_cap_refs()
3268 ci->i_wrbuffer_ref+nr, capsnap->dirty_pages + nr, in ceph_put_wrbuffer_cap_refs()
3269 ci->i_wrbuffer_ref, capsnap->dirty_pages, in ceph_put_wrbuffer_cap_refs()
3275 spin_unlock(&ci->i_ceph_lock); in ceph_put_wrbuffer_cap_refs()
3278 ceph_check_caps(ci, 0, NULL); in ceph_put_wrbuffer_cap_refs()
3280 ceph_flush_snaps(ci, NULL); in ceph_put_wrbuffer_cap_refs()
3283 wake_up_all(&ci->i_cap_wq); in ceph_put_wrbuffer_cap_refs()
3350 __releases(ci->i_ceph_lock) in handle_cap_grant()
3353 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_grant() local
3382 !(ci->i_wrbuffer_ref || ci->i_wb_ref)) { in handle_cap_grant()
3386 if (ci->i_rdcache_revoking != ci->i_rdcache_gen) { in handle_cap_grant()
3388 ci->i_rdcache_revoking = ci->i_rdcache_gen; in handle_cap_grant()
3405 WARN_ON(cap != ci->i_auth_cap); in handle_cap_grant()
3415 __check_cap_issue(ci, cap, newcaps); in handle_cap_grant()
3424 ci->i_btime = extra_info->btime; in handle_cap_grant()
3443 if (version > ci->i_xattrs.version) { in handle_cap_grant()
3446 if (ci->i_xattrs.blob) in handle_cap_grant()
3447 ceph_buffer_put(ci->i_xattrs.blob); in handle_cap_grant()
3448 ci->i_xattrs.blob = ceph_buffer_get(xattr_buf); in handle_cap_grant()
3449 ci->i_xattrs.version = version; in handle_cap_grant()
3467 ci->i_files = extra_info->nfiles; in handle_cap_grant()
3468 ci->i_subdirs = extra_info->nsubdirs; in handle_cap_grant()
3473 s64 old_pool = ci->i_layout.pool_id; in handle_cap_grant()
3476 ceph_file_layout_from_legacy(&ci->i_layout, &grant->layout); in handle_cap_grant()
3477 old_ns = rcu_dereference_protected(ci->i_layout.pool_ns, in handle_cap_grant()
3478 lockdep_is_held(&ci->i_ceph_lock)); in handle_cap_grant()
3479 rcu_assign_pointer(ci->i_layout.pool_ns, extra_info->pool_ns); in handle_cap_grant()
3481 if (ci->i_layout.pool_id != old_pool || in handle_cap_grant()
3483 ci->i_ceph_flags &= ~CEPH_I_POOL_PERM; in handle_cap_grant()
3494 if (ci->i_auth_cap == cap && (newcaps & CEPH_CAP_ANY_FILE_WR)) { in handle_cap_grant()
3495 if (max_size != ci->i_max_size) { in handle_cap_grant()
3497 ci->i_max_size, max_size); in handle_cap_grant()
3498 ci->i_max_size = max_size; in handle_cap_grant()
3499 if (max_size >= ci->i_wanted_max_size) { in handle_cap_grant()
3500 ci->i_wanted_max_size = 0; /* reset */ in handle_cap_grant()
3501 ci->i_requested_max_size = 0; in handle_cap_grant()
3508 wanted = __ceph_caps_wanted(ci); in handle_cap_grant()
3509 used = __ceph_caps_used(ci); in handle_cap_grant()
3510 dirty = __ceph_caps_dirty(ci); in handle_cap_grant()
3546 else if (cap == ci->i_auth_cap) in handle_cap_grant()
3559 if (cap == ci->i_auth_cap && in handle_cap_grant()
3560 __ceph_caps_revoking_other(ci, cap, newcaps)) in handle_cap_grant()
3572 extra_info->inline_version >= ci->i_inline_version) { in handle_cap_grant()
3573 ci->i_inline_version = extra_info->inline_version; in handle_cap_grant()
3574 if (ci->i_inline_version != CEPH_INLINE_NONE && in handle_cap_grant()
3580 if (ci->i_auth_cap == cap) { in handle_cap_grant()
3584 if (ci->i_requested_max_size > max_size || in handle_cap_grant()
3587 ci->i_requested_max_size = 0; in handle_cap_grant()
3591 ceph_kick_flushing_inode_caps(session, ci); in handle_cap_grant()
3595 spin_unlock(&ci->i_ceph_lock); in handle_cap_grant()
3616 wake_up_all(&ci->i_cap_wq); in handle_cap_grant()
3619 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY | CHECK_CAPS_NOINVAL, in handle_cap_grant()
3622 ceph_check_caps(ci, CHECK_CAPS_NOINVAL, session); in handle_cap_grant()
3635 __releases(ci->i_ceph_lock) in handle_cap_flush_ack()
3637 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_flush_ack() local
3648 list_for_each_entry_safe(cf, tmp_cf, &ci->i_cap_flush_list, i_list) { in handle_cap_flush_ack()
3662 wake_ci |= __detach_cap_flush_from_ci(ci, cf); in handle_cap_flush_ack()
3678 ceph_cap_string(cleaned), ceph_cap_string(ci->i_flushing_caps), in handle_cap_flush_ack()
3679 ceph_cap_string(ci->i_flushing_caps & ~cleaned)); in handle_cap_flush_ack()
3684 ci->i_flushing_caps &= ~cleaned; in handle_cap_flush_ack()
3691 if (ci->i_flushing_caps == 0) { in handle_cap_flush_ack()
3692 if (list_empty(&ci->i_cap_flush_list)) { in handle_cap_flush_ack()
3693 list_del_init(&ci->i_flushing_item); in handle_cap_flush_ack()
3705 if (ci->i_dirty_caps == 0) { in handle_cap_flush_ack()
3707 BUG_ON(!list_empty(&ci->i_dirty_item)); in handle_cap_flush_ack()
3709 if (ci->i_wr_ref == 0 && in handle_cap_flush_ack()
3710 ci->i_wrbuffer_ref_head == 0) { in handle_cap_flush_ack()
3711 BUG_ON(!ci->i_head_snapc); in handle_cap_flush_ack()
3712 ceph_put_snap_context(ci->i_head_snapc); in handle_cap_flush_ack()
3713 ci->i_head_snapc = NULL; in handle_cap_flush_ack()
3716 BUG_ON(list_empty(&ci->i_dirty_item)); in handle_cap_flush_ack()
3722 spin_unlock(&ci->i_ceph_lock); in handle_cap_flush_ack()
3733 wake_up_all(&ci->i_cap_wq); in handle_cap_flush_ack()
3743 struct ceph_inode_info *ci = ceph_inode(inode); in __ceph_remove_capsnap() local
3747 lockdep_assert_held(&ci->i_ceph_lock); in __ceph_remove_capsnap()
3749 dout("removing capsnap %p, inode %p ci %p\n", capsnap, inode, ci); in __ceph_remove_capsnap()
3752 ret = __detach_cap_flush_from_ci(ci, &capsnap->cap_flush); in __ceph_remove_capsnap()
3757 if (list_empty(&ci->i_cap_flush_list)) in __ceph_remove_capsnap()
3758 list_del_init(&ci->i_flushing_item); in __ceph_remove_capsnap()
3769 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_remove_capsnap() local
3771 lockdep_assert_held(&ci->i_ceph_lock); in ceph_remove_capsnap()
3787 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_flushsnap_ack() local
3795 dout("handle_cap_flushsnap_ack inode %p ci %p mds%d follows %lld\n", in handle_cap_flushsnap_ack()
3796 inode, ci, session->s_mds, follows); in handle_cap_flushsnap_ack()
3798 spin_lock(&ci->i_ceph_lock); in handle_cap_flushsnap_ack()
3799 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { in handle_cap_flushsnap_ack()
3816 spin_unlock(&ci->i_ceph_lock); in handle_cap_flushsnap_ack()
3822 wake_up_all(&ci->i_cap_wq); in handle_cap_flushsnap_ack()
3838 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_trunc() local
3845 int dirty = __ceph_caps_dirty(ci); in handle_cap_trunc()
3849 lockdep_assert_held(&ci->i_ceph_lock); in handle_cap_trunc()
3875 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_export() local
3892 dout("handle_cap_export inode %p ci %p mds%d mseq %d target %d\n", in handle_cap_export()
3893 inode, ci, mds, mseq, target); in handle_cap_export()
3895 spin_lock(&ci->i_ceph_lock); in handle_cap_export()
3896 cap = __get_cap_for_mds(ci, mds); in handle_cap_export()
3920 tcap = __get_cap_for_mds(ci, target); in handle_cap_export()
3931 if (cap == ci->i_auth_cap) { in handle_cap_export()
3932 ci->i_auth_cap = tcap; in handle_cap_export()
3933 change_auth_cap_ses(ci, tcap->session); in handle_cap_export()
3940 int flag = (cap == ci->i_auth_cap) ? CEPH_CAP_FLAG_AUTH : 0; in handle_cap_export()
3945 if (!list_empty(&ci->i_cap_flush_list) && in handle_cap_export()
3946 ci->i_auth_cap == tcap) { in handle_cap_export()
3948 list_move_tail(&ci->i_flushing_item, in handle_cap_export()
3957 spin_unlock(&ci->i_ceph_lock); in handle_cap_export()
3982 spin_unlock(&ci->i_ceph_lock); in handle_cap_export()
4003 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_import() local
4024 dout("handle_cap_import inode %p ci %p mds%d mseq %d peer %d\n", in handle_cap_import()
4025 inode, ci, mds, mseq, peer); in handle_cap_import()
4027 cap = __get_cap_for_mds(ci, mds); in handle_cap_import()
4030 spin_unlock(&ci->i_ceph_lock); in handle_cap_import()
4032 spin_lock(&ci->i_ceph_lock); in handle_cap_import()
4043 __ceph_caps_issued(ci, &issued); in handle_cap_import()
4044 issued |= __ceph_caps_dirty(ci); in handle_cap_import()
4049 ocap = peer >= 0 ? __get_cap_for_mds(ci, peer) : NULL; in handle_cap_import()
4082 struct ceph_inode_info *ci; in ceph_handle_caps() local
4194 ci = ceph_inode(inode); in ceph_handle_caps()
4243 spin_lock(&ci->i_ceph_lock); in ceph_handle_caps()
4254 spin_lock(&ci->i_ceph_lock); in ceph_handle_caps()
4260 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
4268 __ceph_caps_issued(ci, &extra_info.issued); in ceph_handle_caps()
4269 extra_info.issued |= __ceph_caps_dirty(ci); in ceph_handle_caps()
4281 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
4287 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
4319 * processed in this run. In this case, the ci->i_hold_caps_max will be
4325 struct ceph_inode_info *ci; in ceph_check_delayed_caps() local
4334 ci = list_first_entry(&mdsc->cap_delay_list, in ceph_check_delayed_caps()
4337 if (time_before(loop_start, ci->i_hold_caps_max - delay_max)) { in ceph_check_delayed_caps()
4339 delay = ci->i_hold_caps_max; in ceph_check_delayed_caps()
4342 if ((ci->i_ceph_flags & CEPH_I_FLUSH) == 0 && in ceph_check_delayed_caps()
4343 time_before(jiffies, ci->i_hold_caps_max)) in ceph_check_delayed_caps()
4345 list_del_init(&ci->i_cap_delay_list); in ceph_check_delayed_caps()
4347 inode = igrab(&ci->vfs_inode); in ceph_check_delayed_caps()
4351 ceph_check_caps(ci, 0, NULL); in ceph_check_delayed_caps()
4368 struct ceph_inode_info *ci; in flush_dirty_session_caps() local
4374 ci = list_first_entry(&s->s_cap_dirty, struct ceph_inode_info, in flush_dirty_session_caps()
4376 inode = &ci->vfs_inode; in flush_dirty_session_caps()
4380 ceph_check_caps(ci, CHECK_CAPS_FLUSH, NULL); in flush_dirty_session_caps()
4393 void __ceph_touch_fmode(struct ceph_inode_info *ci, in __ceph_touch_fmode() argument
4398 ci->i_last_rd = now; in __ceph_touch_fmode()
4400 ci->i_last_wr = now; in __ceph_touch_fmode()
4403 __ceph_is_any_real_caps(ci) && in __ceph_touch_fmode()
4404 list_empty(&ci->i_cap_delay_list)) in __ceph_touch_fmode()
4405 __cap_delay_requeue(mdsc, ci); in __ceph_touch_fmode()
4408 void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count) in ceph_get_fmode() argument
4410 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->vfs_inode.i_sb); in ceph_get_fmode()
4418 spin_lock(&ci->i_ceph_lock); in ceph_get_fmode()
4425 if (i && ci->i_nr_by_mode[i]) in ceph_get_fmode()
4429 ci->i_nr_by_mode[i] += count; in ceph_get_fmode()
4434 spin_unlock(&ci->i_ceph_lock); in ceph_get_fmode()
4442 void ceph_put_fmode(struct ceph_inode_info *ci, int fmode, int count) in ceph_put_fmode() argument
4444 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->vfs_inode.i_sb); in ceph_put_fmode()
4452 spin_lock(&ci->i_ceph_lock); in ceph_put_fmode()
4455 BUG_ON(ci->i_nr_by_mode[i] < count); in ceph_put_fmode()
4456 ci->i_nr_by_mode[i] -= count; in ceph_put_fmode()
4464 if (i && ci->i_nr_by_mode[i]) in ceph_put_fmode()
4470 spin_unlock(&ci->i_ceph_lock); in ceph_put_fmode()
4481 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_drop_caps_for_unlink() local
4484 spin_lock(&ci->i_ceph_lock); in ceph_drop_caps_for_unlink()
4486 drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN); in ceph_drop_caps_for_unlink()
4488 if (__ceph_caps_dirty(ci)) { in ceph_drop_caps_for_unlink()
4491 __cap_delay_requeue_front(mdsc, ci); in ceph_drop_caps_for_unlink()
4494 spin_unlock(&ci->i_ceph_lock); in ceph_drop_caps_for_unlink()
4509 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_encode_inode_release() local
4515 spin_lock(&ci->i_ceph_lock); in ceph_encode_inode_release()
4516 used = __ceph_caps_used(ci); in ceph_encode_inode_release()
4517 dirty = __ceph_caps_dirty(ci); in ceph_encode_inode_release()
4526 cap = __get_cap_for_mds(ci, mds); in ceph_encode_inode_release()
4542 int wanted = __ceph_caps_wanted(ci); in ceph_encode_inode_release()
4553 if (cap == ci->i_auth_cap && in ceph_encode_inode_release()
4555 ci->i_requested_max_size = 0; in ceph_encode_inode_release()
4578 spin_unlock(&ci->i_ceph_lock); in ceph_encode_inode_release()