Lines Matching refs:ci

310 static struct ceph_cap *__get_cap_for_mds(struct ceph_inode_info *ci, int mds)  in __get_cap_for_mds()  argument
313 struct rb_node *n = ci->i_caps.rb_node; in __get_cap_for_mds()
327 struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci, int mds) in ceph_get_cap_for_mds() argument
331 spin_lock(&ci->i_ceph_lock); in ceph_get_cap_for_mds()
332 cap = __get_cap_for_mds(ci, mds); in ceph_get_cap_for_mds()
333 spin_unlock(&ci->i_ceph_lock); in ceph_get_cap_for_mds()
340 static int __ceph_get_cap_mds(struct ceph_inode_info *ci) in __ceph_get_cap_mds() argument
347 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_get_cap_mds()
360 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_get_cap_mds() local
362 spin_lock(&ci->i_ceph_lock); in ceph_get_cap_mds()
364 spin_unlock(&ci->i_ceph_lock); in ceph_get_cap_mds()
371 static void __insert_cap_node(struct ceph_inode_info *ci, in __insert_cap_node() argument
374 struct rb_node **p = &ci->i_caps.rb_node; in __insert_cap_node()
390 rb_insert_color(&new->ci_node, &ci->i_caps); in __insert_cap_node()
398 struct ceph_inode_info *ci) in __cap_set_timeouts() argument
402 ci->i_hold_caps_min = round_jiffies(jiffies + in __cap_set_timeouts()
404 ci->i_hold_caps_max = round_jiffies(jiffies + in __cap_set_timeouts()
406 dout("__cap_set_timeouts %p min %lu max %lu\n", &ci->vfs_inode, in __cap_set_timeouts()
407 ci->i_hold_caps_min - jiffies, ci->i_hold_caps_max - jiffies); in __cap_set_timeouts()
419 struct ceph_inode_info *ci) in __cap_delay_requeue() argument
421 __cap_set_timeouts(mdsc, ci); in __cap_delay_requeue()
422 dout("__cap_delay_requeue %p flags %d at %lu\n", &ci->vfs_inode, in __cap_delay_requeue()
423 ci->i_ceph_flags, ci->i_hold_caps_max); in __cap_delay_requeue()
426 if (!list_empty(&ci->i_cap_delay_list)) { in __cap_delay_requeue()
427 if (ci->i_ceph_flags & CEPH_I_FLUSH) in __cap_delay_requeue()
429 list_del_init(&ci->i_cap_delay_list); in __cap_delay_requeue()
431 list_add_tail(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue()
443 struct ceph_inode_info *ci) in __cap_delay_requeue_front() argument
445 dout("__cap_delay_requeue_front %p\n", &ci->vfs_inode); in __cap_delay_requeue_front()
447 ci->i_ceph_flags |= CEPH_I_FLUSH; in __cap_delay_requeue_front()
448 if (!list_empty(&ci->i_cap_delay_list)) in __cap_delay_requeue_front()
449 list_del_init(&ci->i_cap_delay_list); in __cap_delay_requeue_front()
450 list_add(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue_front()
460 struct ceph_inode_info *ci) in __cap_delay_cancel() argument
462 dout("__cap_delay_cancel %p\n", &ci->vfs_inode); in __cap_delay_cancel()
463 if (list_empty(&ci->i_cap_delay_list)) in __cap_delay_cancel()
466 list_del_init(&ci->i_cap_delay_list); in __cap_delay_cancel()
473 static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap, in __check_cap_issue() argument
476 unsigned had = __ceph_caps_issued(ci, NULL); in __check_cap_issue()
484 ci->i_rdcache_gen++; in __check_cap_issue()
494 ci->i_shared_gen++; in __check_cap_issue()
495 if (S_ISDIR(ci->vfs_inode.i_mode)) { in __check_cap_issue()
496 dout(" marking %p NOT complete\n", &ci->vfs_inode); in __check_cap_issue()
497 __ceph_dir_clear_complete(ci); in __check_cap_issue()
518 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_add_cap() local
533 cap = __get_cap_for_mds(ci, mds); in ceph_add_cap()
544 cap->ci = ci; in ceph_add_cap()
545 __insert_cap_node(ci, cap); in ceph_add_cap()
564 WARN_ON(cap != ci->i_auth_cap); in ceph_add_cap()
573 if (!ci->i_snap_realm) { in ceph_add_cap()
581 ci->i_snap_realm = realm; in ceph_add_cap()
582 list_add(&ci->i_snap_realm_item, in ceph_add_cap()
592 __check_cap_issue(ci, cap, issued); in ceph_add_cap()
599 actual_wanted = __ceph_caps_wanted(ci); in ceph_add_cap()
605 __cap_delay_requeue(mdsc, ci); in ceph_add_cap()
609 if (ci->i_auth_cap == NULL || in ceph_add_cap()
610 ceph_seq_cmp(ci->i_auth_cap->mseq, mseq) < 0) { in ceph_add_cap()
611 ci->i_auth_cap = cap; in ceph_add_cap()
615 WARN_ON(ci->i_auth_cap == cap); in ceph_add_cap()
634 __ceph_get_fmode(ci, fmode); in ceph_add_cap()
654 "but STALE (gen %u vs %u)\n", &cap->ci->vfs_inode, in __cap_is_valid()
667 int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented) in __ceph_caps_issued() argument
669 int have = ci->i_snap_caps; in __ceph_caps_issued()
675 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued()
680 &ci->vfs_inode, cap, ceph_cap_string(cap->issued)); in __ceph_caps_issued()
690 if (ci->i_auth_cap) { in __ceph_caps_issued()
691 cap = ci->i_auth_cap; in __ceph_caps_issued()
700 int __ceph_caps_issued_other(struct ceph_inode_info *ci, struct ceph_cap *ocap) in __ceph_caps_issued_other() argument
702 int have = ci->i_snap_caps; in __ceph_caps_issued_other()
706 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued_other()
727 dout("__touch_cap %p cap %p mds%d\n", &cap->ci->vfs_inode, cap, in __touch_cap()
732 &cap->ci->vfs_inode, cap, s->s_mds); in __touch_cap()
742 int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int touch) in __ceph_caps_issued_mask() argument
746 int have = ci->i_snap_caps; in __ceph_caps_issued_mask()
750 " (mask %s)\n", &ci->vfs_inode, in __ceph_caps_issued_mask()
756 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_issued_mask()
762 " (mask %s)\n", &ci->vfs_inode, cap, in __ceph_caps_issued_mask()
774 " (mask %s)\n", &ci->vfs_inode, in __ceph_caps_issued_mask()
782 for (q = rb_first(&ci->i_caps); q != p; in __ceph_caps_issued_mask()
801 int __ceph_caps_revoking_other(struct ceph_inode_info *ci, in __ceph_caps_revoking_other() argument
807 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_revoking_other()
816 int ceph_caps_revoking(struct ceph_inode_info *ci, int mask) in ceph_caps_revoking() argument
818 struct inode *inode = &ci->vfs_inode; in ceph_caps_revoking()
821 spin_lock(&ci->i_ceph_lock); in ceph_caps_revoking()
822 ret = __ceph_caps_revoking_other(ci, NULL, mask); in ceph_caps_revoking()
823 spin_unlock(&ci->i_ceph_lock); in ceph_caps_revoking()
829 int __ceph_caps_used(struct ceph_inode_info *ci) in __ceph_caps_used() argument
832 if (ci->i_pin_ref) in __ceph_caps_used()
834 if (ci->i_rd_ref) in __ceph_caps_used()
836 if (ci->i_rdcache_ref || ci->vfs_inode.i_data.nrpages) in __ceph_caps_used()
838 if (ci->i_wr_ref) in __ceph_caps_used()
840 if (ci->i_wb_ref || ci->i_wrbuffer_ref) in __ceph_caps_used()
848 int __ceph_caps_file_wanted(struct ceph_inode_info *ci) in __ceph_caps_file_wanted() argument
853 if (ci->i_nr_by_mode[mode]) in __ceph_caps_file_wanted()
861 int __ceph_caps_mds_wanted(struct ceph_inode_info *ci) in __ceph_caps_mds_wanted() argument
867 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in __ceph_caps_mds_wanted()
871 if (cap == ci->i_auth_cap) in __ceph_caps_mds_wanted()
882 static int __ceph_is_any_caps(struct ceph_inode_info *ci) in __ceph_is_any_caps() argument
884 return !RB_EMPTY_ROOT(&ci->i_caps); in __ceph_is_any_caps()
889 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_is_any_caps() local
892 spin_lock(&ci->i_ceph_lock); in ceph_is_any_caps()
893 ret = __ceph_is_any_caps(ci); in ceph_is_any_caps()
894 spin_unlock(&ci->i_ceph_lock); in ceph_is_any_caps()
899 static void drop_inode_snap_realm(struct ceph_inode_info *ci) in drop_inode_snap_realm() argument
901 struct ceph_snap_realm *realm = ci->i_snap_realm; in drop_inode_snap_realm()
903 list_del_init(&ci->i_snap_realm_item); in drop_inode_snap_realm()
904 ci->i_snap_realm_counter++; in drop_inode_snap_realm()
905 ci->i_snap_realm = NULL; in drop_inode_snap_realm()
907 ceph_put_snap_realm(ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc, in drop_inode_snap_realm()
920 struct ceph_inode_info *ci = cap->ci; in __ceph_remove_cap() local
922 ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc; in __ceph_remove_cap()
925 dout("__ceph_remove_cap %p from %p\n", cap, &ci->vfs_inode); in __ceph_remove_cap()
936 __queue_cap_release(session, ci->i_vino.ino, cap->cap_id, in __ceph_remove_cap()
950 cap->ci = NULL; in __ceph_remove_cap()
954 rb_erase(&cap->ci_node, &ci->i_caps); in __ceph_remove_cap()
955 if (ci->i_auth_cap == cap) in __ceph_remove_cap()
956 ci->i_auth_cap = NULL; in __ceph_remove_cap()
965 if (!__ceph_is_any_caps(ci) && ci->i_wr_ref == 0 && ci->i_snap_realm) in __ceph_remove_cap()
966 drop_inode_snap_realm(ci); in __ceph_remove_cap()
968 if (!__ceph_is_any_real_caps(ci)) in __ceph_remove_cap()
969 __cap_delay_cancel(mdsc, ci); in __ceph_remove_cap()
1100 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_queue_caps_release() local
1103 p = rb_first(&ci->i_caps); in ceph_queue_caps_release()
1131 __releases(cap->ci->i_ceph_lock) in __send_cap()
1133 struct ceph_inode_info *ci = cap->ci; in __send_cap() local
1134 struct inode *inode = &ci->vfs_inode; in __send_cap()
1167 if ((ci->i_ceph_flags & CEPH_I_NODELAY) == 0 && in __send_cap()
1168 time_before(jiffies, ci->i_hold_caps_min)) { in __send_cap()
1178 ci->i_ceph_flags &= ~(CEPH_I_NODELAY | CEPH_I_FLUSH); in __send_cap()
1201 flush_tid = ++ci->i_cap_flush_last_tid; in __send_cap()
1207 ci->i_cap_flush_tid[i] = flush_tid; in __send_cap()
1209 follows = ci->i_head_snapc->seq; in __send_cap()
1219 ci->i_reported_size = size; in __send_cap()
1220 max_size = ci->i_wanted_max_size; in __send_cap()
1221 ci->i_requested_max_size = max_size; in __send_cap()
1224 time_warp_seq = ci->i_time_warp_seq; in __send_cap()
1230 __ceph_build_xattrs_blob(ci); in __send_cap()
1231 xattr_blob = ci->i_xattrs.blob; in __send_cap()
1232 xattr_version = ci->i_xattrs.version; in __send_cap()
1235 inline_data = ci->i_inline_version != CEPH_INLINE_NONE; in __send_cap()
1237 spin_unlock(&ci->i_ceph_lock); in __send_cap()
1250 wake_up_all(&ci->i_cap_wq); in __send_cap()
1267 void __ceph_flush_snaps(struct ceph_inode_info *ci, in __ceph_flush_snaps() argument
1270 __releases(ci->i_ceph_lock) in __ceph_flush_snaps()
1271 __acquires(ci->i_ceph_lock) in __ceph_flush_snaps()
1273 struct inode *inode = &ci->vfs_inode; in __ceph_flush_snaps()
1289 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { in __ceph_flush_snaps()
1307 if (ci->i_auth_cap == NULL) { in __ceph_flush_snaps()
1318 mds = ci->i_auth_cap->session->s_mds; in __ceph_flush_snaps()
1319 mseq = ci->i_auth_cap->mseq; in __ceph_flush_snaps()
1328 spin_unlock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1342 spin_lock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1346 capsnap->flush_tid = ++ci->i_cap_flush_last_tid; in __ceph_flush_snaps()
1352 spin_unlock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1369 spin_lock(&ci->i_ceph_lock); in __ceph_flush_snaps()
1375 list_del_init(&ci->i_snap_flush_item); in __ceph_flush_snaps()
1387 static void ceph_flush_snaps(struct ceph_inode_info *ci) in ceph_flush_snaps() argument
1389 spin_lock(&ci->i_ceph_lock); in ceph_flush_snaps()
1390 __ceph_flush_snaps(ci, NULL, 0); in ceph_flush_snaps()
1391 spin_unlock(&ci->i_ceph_lock); in ceph_flush_snaps()
1399 int __ceph_mark_dirty_caps(struct ceph_inode_info *ci, int mask) in __ceph_mark_dirty_caps() argument
1402 ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc; in __ceph_mark_dirty_caps()
1403 struct inode *inode = &ci->vfs_inode; in __ceph_mark_dirty_caps()
1404 int was = ci->i_dirty_caps; in __ceph_mark_dirty_caps()
1407 if (!ci->i_auth_cap) { in __ceph_mark_dirty_caps()
1414 dout("__mark_dirty_caps %p %s dirty %s -> %s\n", &ci->vfs_inode, in __ceph_mark_dirty_caps()
1417 ci->i_dirty_caps |= mask; in __ceph_mark_dirty_caps()
1419 if (!ci->i_head_snapc) in __ceph_mark_dirty_caps()
1420 ci->i_head_snapc = ceph_get_snap_context( in __ceph_mark_dirty_caps()
1421 ci->i_snap_realm->cached_context); in __ceph_mark_dirty_caps()
1423 &ci->vfs_inode, ci->i_head_snapc, ci->i_auth_cap); in __ceph_mark_dirty_caps()
1424 BUG_ON(!list_empty(&ci->i_dirty_item)); in __ceph_mark_dirty_caps()
1426 list_add(&ci->i_dirty_item, &mdsc->cap_dirty); in __ceph_mark_dirty_caps()
1428 if (ci->i_flushing_caps == 0) { in __ceph_mark_dirty_caps()
1433 BUG_ON(list_empty(&ci->i_dirty_item)); in __ceph_mark_dirty_caps()
1434 if (((was | ci->i_flushing_caps) & CEPH_CAP_FILE_BUFFER) && in __ceph_mark_dirty_caps()
1437 __cap_delay_requeue(mdsc, ci); in __ceph_mark_dirty_caps()
1451 struct ceph_inode_info *ci = ceph_inode(inode); in __mark_caps_flushing() local
1454 BUG_ON(ci->i_dirty_caps == 0); in __mark_caps_flushing()
1455 BUG_ON(list_empty(&ci->i_dirty_item)); in __mark_caps_flushing()
1457 flushing = ci->i_dirty_caps; in __mark_caps_flushing()
1460 ceph_cap_string(ci->i_flushing_caps), in __mark_caps_flushing()
1461 ceph_cap_string(ci->i_flushing_caps | flushing)); in __mark_caps_flushing()
1462 ci->i_flushing_caps |= flushing; in __mark_caps_flushing()
1463 ci->i_dirty_caps = 0; in __mark_caps_flushing()
1467 list_del_init(&ci->i_dirty_item); in __mark_caps_flushing()
1469 if (list_empty(&ci->i_flushing_item)) { in __mark_caps_flushing()
1470 ci->i_cap_flush_seq = ++mdsc->cap_flush_seq; in __mark_caps_flushing()
1471 list_add_tail(&ci->i_flushing_item, &session->s_cap_flushing); in __mark_caps_flushing()
1474 ci->i_cap_flush_seq); in __mark_caps_flushing()
1476 list_move_tail(&ci->i_flushing_item, &session->s_cap_flushing); in __mark_caps_flushing()
1478 ci->i_cap_flush_seq); in __mark_caps_flushing()
1490 struct ceph_inode_info *ci = ceph_inode(inode); in try_nonblocking_invalidate() local
1491 u32 invalidating_gen = ci->i_rdcache_gen; in try_nonblocking_invalidate()
1493 spin_unlock(&ci->i_ceph_lock); in try_nonblocking_invalidate()
1495 spin_lock(&ci->i_ceph_lock); in try_nonblocking_invalidate()
1498 invalidating_gen == ci->i_rdcache_gen) { in try_nonblocking_invalidate()
1502 ci->i_rdcache_revoking = ci->i_rdcache_gen - 1; in try_nonblocking_invalidate()
1520 void ceph_check_caps(struct ceph_inode_info *ci, int flags, in ceph_check_caps() argument
1523 struct ceph_fs_client *fsc = ceph_inode_to_client(&ci->vfs_inode); in ceph_check_caps()
1525 struct inode *inode = &ci->vfs_inode; in ceph_check_caps()
1542 spin_lock(&ci->i_ceph_lock); in ceph_check_caps()
1544 if (ci->i_ceph_flags & CEPH_I_FLUSH) in ceph_check_caps()
1548 if (!list_empty(&ci->i_cap_snaps)) in ceph_check_caps()
1549 __ceph_flush_snaps(ci, &session, 0); in ceph_check_caps()
1552 spin_lock(&ci->i_ceph_lock); in ceph_check_caps()
1554 file_wanted = __ceph_caps_file_wanted(ci); in ceph_check_caps()
1555 used = __ceph_caps_used(ci); in ceph_check_caps()
1557 issued = __ceph_caps_issued(ci, &implemented); in ceph_check_caps()
1566 __ceph_dir_is_complete(ci)) { in ceph_check_caps()
1583 if (ci->i_max_size == 0) in ceph_check_caps()
1591 ceph_cap_string(used), ceph_cap_string(ci->i_dirty_caps), in ceph_check_caps()
1592 ceph_cap_string(ci->i_flushing_caps), in ceph_check_caps()
1605 ci->i_wrbuffer_ref == 0 && /* no dirty pages... */ in ceph_check_caps()
1617 ci->i_rdcache_revoking = ci->i_rdcache_gen; in ceph_check_caps()
1623 __cap_set_timeouts(mdsc, ci); in ceph_check_caps()
1631 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { in ceph_check_caps()
1637 ((flags & CHECK_CAPS_AUTHONLY) && cap != ci->i_auth_cap)) in ceph_check_caps()
1643 if (ci->i_auth_cap && cap != ci->i_auth_cap) in ceph_check_caps()
1644 cap_used &= ~ci->i_auth_cap->issued; in ceph_check_caps()
1653 if (cap == ci->i_auth_cap && in ceph_check_caps()
1656 if (ci->i_wanted_max_size > ci->i_max_size && in ceph_check_caps()
1657 ci->i_wanted_max_size > ci->i_requested_max_size) { in ceph_check_caps()
1663 if ((inode->i_size << 1) >= ci->i_max_size && in ceph_check_caps()
1664 (ci->i_reported_size << 1) < ci->i_max_size) { in ceph_check_caps()
1670 if (cap == ci->i_auth_cap && (flags & CHECK_CAPS_FLUSH) && in ceph_check_caps()
1671 ci->i_dirty_caps) { in ceph_check_caps()
1696 if ((ci->i_ceph_flags & CEPH_I_NODELAY) == 0 && in ceph_check_caps()
1697 time_before(jiffies, ci->i_hold_caps_max)) { in ceph_check_caps()
1708 if (ci->i_ceph_flags & CEPH_I_NOFLUSH) { in ceph_check_caps()
1723 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
1737 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
1745 if (cap == ci->i_auth_cap && ci->i_dirty_caps) in ceph_check_caps()
1766 __cap_delay_cancel(mdsc, ci); in ceph_check_caps()
1768 __cap_delay_requeue(mdsc, ci); in ceph_check_caps()
1770 spin_unlock(&ci->i_ceph_lock); in ceph_check_caps()
1787 struct ceph_inode_info *ci = ceph_inode(inode); in try_flush_caps() local
1792 spin_lock(&ci->i_ceph_lock); in try_flush_caps()
1793 if (ci->i_ceph_flags & CEPH_I_NOFLUSH) { in try_flush_caps()
1797 if (ci->i_dirty_caps && ci->i_auth_cap) { in try_flush_caps()
1798 struct ceph_cap *cap = ci->i_auth_cap; in try_flush_caps()
1799 int used = __ceph_caps_used(ci); in try_flush_caps()
1800 int want = __ceph_caps_wanted(ci); in try_flush_caps()
1804 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
1823 spin_lock(&ci->i_ceph_lock); in try_flush_caps()
1824 __cap_delay_requeue(mdsc, ci); in try_flush_caps()
1827 spin_unlock(&ci->i_ceph_lock); in try_flush_caps()
1839 struct ceph_inode_info *ci = ceph_inode(inode); in caps_are_flushed() local
1842 spin_lock(&ci->i_ceph_lock); in caps_are_flushed()
1844 if ((ci->i_flushing_caps & (1 << i)) && in caps_are_flushed()
1845 ci->i_cap_flush_tid[i] <= tid) { in caps_are_flushed()
1850 spin_unlock(&ci->i_ceph_lock); in caps_are_flushed()
1862 struct ceph_inode_info *ci = ceph_inode(inode); in sync_write_wait() local
1863 struct list_head *head = &ci->i_unsafe_writes; in sync_write_wait()
1867 spin_lock(&ci->i_unsafe_lock); in sync_write_wait()
1878 spin_unlock(&ci->i_unsafe_lock); in sync_write_wait()
1882 spin_lock(&ci->i_unsafe_lock); in sync_write_wait()
1895 spin_unlock(&ci->i_unsafe_lock); in sync_write_wait()
1901 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_fsync() local
1924 ret = wait_event_interruptible(ci->i_cap_wq, in ceph_fsync()
1941 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_write_inode() local
1951 err = wait_event_interruptible(ci->i_cap_wq, in ceph_write_inode()
1957 spin_lock(&ci->i_ceph_lock); in ceph_write_inode()
1958 if (__ceph_caps_dirty(ci)) in ceph_write_inode()
1959 __cap_delay_requeue_front(mdsc, ci); in ceph_write_inode()
1960 spin_unlock(&ci->i_ceph_lock); in ceph_write_inode()
1979 struct ceph_inode_info *ci = capsnap->ci; in kick_flushing_capsnaps() local
1980 struct inode *inode = &ci->vfs_inode; in kick_flushing_capsnaps()
1983 spin_lock(&ci->i_ceph_lock); in kick_flushing_capsnaps()
1984 cap = ci->i_auth_cap; in kick_flushing_capsnaps()
1988 __ceph_flush_snaps(ci, &session, 1); in kick_flushing_capsnaps()
1993 spin_unlock(&ci->i_ceph_lock); in kick_flushing_capsnaps()
2000 struct ceph_inode_info *ci; in ceph_kick_flushing_caps() local
2005 list_for_each_entry(ci, &session->s_cap_flushing, i_flushing_item) { in ceph_kick_flushing_caps()
2006 struct inode *inode = &ci->vfs_inode; in ceph_kick_flushing_caps()
2010 spin_lock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2011 cap = ci->i_auth_cap; in ceph_kick_flushing_caps()
2014 cap, ceph_cap_string(ci->i_flushing_caps)); in ceph_kick_flushing_caps()
2016 __ceph_caps_used(ci), in ceph_kick_flushing_caps()
2017 __ceph_caps_wanted(ci), in ceph_kick_flushing_caps()
2019 ci->i_flushing_caps, NULL); in ceph_kick_flushing_caps()
2021 spin_lock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2022 __cap_delay_requeue(mdsc, ci); in ceph_kick_flushing_caps()
2023 spin_unlock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2028 spin_unlock(&ci->i_ceph_lock); in ceph_kick_flushing_caps()
2037 struct ceph_inode_info *ci = ceph_inode(inode); in kick_flushing_inode_caps() local
2041 spin_lock(&ci->i_ceph_lock); in kick_flushing_inode_caps()
2042 cap = ci->i_auth_cap; in kick_flushing_inode_caps()
2044 ceph_cap_string(ci->i_flushing_caps), ci->i_cap_flush_seq); in kick_flushing_inode_caps()
2046 __ceph_flush_snaps(ci, &session, 1); in kick_flushing_inode_caps()
2048 if (ci->i_flushing_caps) { in kick_flushing_inode_caps()
2050 list_move_tail(&ci->i_flushing_item, in kick_flushing_inode_caps()
2055 __ceph_caps_used(ci), in kick_flushing_inode_caps()
2056 __ceph_caps_wanted(ci), in kick_flushing_inode_caps()
2058 ci->i_flushing_caps, NULL); in kick_flushing_inode_caps()
2060 spin_lock(&ci->i_ceph_lock); in kick_flushing_inode_caps()
2061 __cap_delay_requeue(mdsc, ci); in kick_flushing_inode_caps()
2062 spin_unlock(&ci->i_ceph_lock); in kick_flushing_inode_caps()
2065 spin_unlock(&ci->i_ceph_lock); in kick_flushing_inode_caps()
2076 static void __take_cap_refs(struct ceph_inode_info *ci, int got) in __take_cap_refs() argument
2079 ci->i_pin_ref++; in __take_cap_refs()
2081 ci->i_rd_ref++; in __take_cap_refs()
2083 ci->i_rdcache_ref++; in __take_cap_refs()
2085 ci->i_wr_ref++; in __take_cap_refs()
2087 if (ci->i_wb_ref == 0) in __take_cap_refs()
2088 ihold(&ci->vfs_inode); in __take_cap_refs()
2089 ci->i_wb_ref++; in __take_cap_refs()
2091 &ci->vfs_inode, ci->i_wb_ref-1, ci->i_wb_ref); in __take_cap_refs()
2102 static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, in try_get_cap_refs() argument
2105 struct inode *inode = &ci->vfs_inode; in try_get_cap_refs()
2113 spin_lock(&ci->i_ceph_lock); in try_get_cap_refs()
2116 file_wanted = __ceph_caps_file_wanted(ci); in try_get_cap_refs()
2126 while (ci->i_truncate_pending) { in try_get_cap_refs()
2127 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2129 spin_lock(&ci->i_ceph_lock); in try_get_cap_refs()
2132 have = __ceph_caps_issued(ci, &implemented); in try_get_cap_refs()
2135 if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) { in try_get_cap_refs()
2137 inode, endoff, ci->i_max_size); in try_get_cap_refs()
2138 if (endoff > ci->i_requested_max_size) { in try_get_cap_refs()
2148 if (__ceph_have_pending_cap_snap(ci)) { in try_get_cap_refs()
2168 __take_cap_refs(ci, *got); in try_get_cap_refs()
2173 if ((need & CEPH_CAP_FILE_WR) && ci->i_auth_cap) { in try_get_cap_refs()
2174 struct ceph_mds_session *s = ci->i_auth_cap->session; in try_get_cap_refs()
2181 inode, ceph_cap_string(need), ci->i_auth_cap->mds); in try_get_cap_refs()
2191 spin_unlock(&ci->i_ceph_lock); in try_get_cap_refs()
2205 struct ceph_inode_info *ci = ceph_inode(inode); in check_max_size() local
2209 spin_lock(&ci->i_ceph_lock); in check_max_size()
2210 if (endoff >= ci->i_max_size && endoff > ci->i_wanted_max_size) { in check_max_size()
2213 ci->i_wanted_max_size = endoff; in check_max_size()
2216 if (ci->i_auth_cap && in check_max_size()
2217 (ci->i_auth_cap->issued & CEPH_CAP_FILE_WR) && in check_max_size()
2218 ci->i_wanted_max_size > ci->i_max_size && in check_max_size()
2219 ci->i_wanted_max_size > ci->i_requested_max_size) in check_max_size()
2221 spin_unlock(&ci->i_ceph_lock); in check_max_size()
2223 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL); in check_max_size()
2231 int ceph_get_caps(struct ceph_inode_info *ci, int need, int want, in ceph_get_caps() argument
2238 check_max_size(&ci->vfs_inode, endoff); in ceph_get_caps()
2241 ret = wait_event_interruptible(ci->i_cap_wq, in ceph_get_caps()
2242 try_get_cap_refs(ci, need, want, endoff, in ceph_get_caps()
2252 if (ci->i_inline_version != CEPH_INLINE_NONE && in ceph_get_caps()
2254 i_size_read(&ci->vfs_inode) > 0) { in ceph_get_caps()
2255 struct page *page = find_get_page(ci->vfs_inode.i_mapping, 0); in ceph_get_caps()
2267 ceph_put_cap_refs(ci, _got); in ceph_get_caps()
2271 ret = __ceph_do_getattr(&ci->vfs_inode, NULL, in ceph_get_caps()
2286 void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps) in ceph_get_cap_refs() argument
2288 spin_lock(&ci->i_ceph_lock); in ceph_get_cap_refs()
2289 __take_cap_refs(ci, caps); in ceph_get_cap_refs()
2290 spin_unlock(&ci->i_ceph_lock); in ceph_get_cap_refs()
2302 void ceph_put_cap_refs(struct ceph_inode_info *ci, int had) in ceph_put_cap_refs() argument
2304 struct inode *inode = &ci->vfs_inode; in ceph_put_cap_refs()
2308 spin_lock(&ci->i_ceph_lock); in ceph_put_cap_refs()
2310 --ci->i_pin_ref; in ceph_put_cap_refs()
2312 if (--ci->i_rd_ref == 0) in ceph_put_cap_refs()
2315 if (--ci->i_rdcache_ref == 0) in ceph_put_cap_refs()
2318 if (--ci->i_wb_ref == 0) { in ceph_put_cap_refs()
2323 inode, ci->i_wb_ref+1, ci->i_wb_ref); in ceph_put_cap_refs()
2326 if (--ci->i_wr_ref == 0) { in ceph_put_cap_refs()
2328 if (!list_empty(&ci->i_cap_snaps)) { in ceph_put_cap_refs()
2329 capsnap = list_first_entry(&ci->i_cap_snaps, in ceph_put_cap_refs()
2335 __ceph_finish_cap_snap(ci, in ceph_put_cap_refs()
2341 if (!__ceph_is_any_caps(ci) && ci->i_snap_realm) in ceph_put_cap_refs()
2342 drop_inode_snap_realm(ci); in ceph_put_cap_refs()
2344 spin_unlock(&ci->i_ceph_lock); in ceph_put_cap_refs()
2350 ceph_check_caps(ci, 0, NULL); in ceph_put_cap_refs()
2352 ceph_flush_snaps(ci); in ceph_put_cap_refs()
2354 wake_up_all(&ci->i_cap_wq); in ceph_put_cap_refs()
2366 void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr, in ceph_put_wrbuffer_cap_refs() argument
2369 struct inode *inode = &ci->vfs_inode; in ceph_put_wrbuffer_cap_refs()
2376 spin_lock(&ci->i_ceph_lock); in ceph_put_wrbuffer_cap_refs()
2377 ci->i_wrbuffer_ref -= nr; in ceph_put_wrbuffer_cap_refs()
2378 last = !ci->i_wrbuffer_ref; in ceph_put_wrbuffer_cap_refs()
2380 if (ci->i_head_snapc == snapc) { in ceph_put_wrbuffer_cap_refs()
2381 ci->i_wrbuffer_ref_head -= nr; in ceph_put_wrbuffer_cap_refs()
2382 if (ci->i_wrbuffer_ref_head == 0 && in ceph_put_wrbuffer_cap_refs()
2383 ci->i_dirty_caps == 0 && ci->i_flushing_caps == 0) { in ceph_put_wrbuffer_cap_refs()
2384 BUG_ON(!ci->i_head_snapc); in ceph_put_wrbuffer_cap_refs()
2385 ceph_put_snap_context(ci->i_head_snapc); in ceph_put_wrbuffer_cap_refs()
2386 ci->i_head_snapc = NULL; in ceph_put_wrbuffer_cap_refs()
2390 ci->i_wrbuffer_ref+nr, ci->i_wrbuffer_ref_head+nr, in ceph_put_wrbuffer_cap_refs()
2391 ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head, in ceph_put_wrbuffer_cap_refs()
2394 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { in ceph_put_wrbuffer_cap_refs()
2412 ci->i_wrbuffer_ref+nr, capsnap->dirty_pages + nr, in ceph_put_wrbuffer_cap_refs()
2413 ci->i_wrbuffer_ref, capsnap->dirty_pages, in ceph_put_wrbuffer_cap_refs()
2425 spin_unlock(&ci->i_ceph_lock); in ceph_put_wrbuffer_cap_refs()
2428 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL); in ceph_put_wrbuffer_cap_refs()
2431 ceph_flush_snaps(ci); in ceph_put_wrbuffer_cap_refs()
2432 wake_up_all(&ci->i_cap_wq); in ceph_put_wrbuffer_cap_refs()
2483 __releases(ci->i_ceph_lock) in handle_cap_grant()
2486 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_grant() local
2518 WARN_ON(cap != ci->i_auth_cap); in handle_cap_grant()
2531 !ci->i_wrbuffer_ref) { in handle_cap_grant()
2535 if (ci->i_rdcache_revoking != ci->i_rdcache_gen) { in handle_cap_grant()
2537 ci->i_rdcache_revoking = ci->i_rdcache_gen; in handle_cap_grant()
2548 __check_cap_issue(ci, cap, newcaps); in handle_cap_grant()
2572 if (version > ci->i_xattrs.version) { in handle_cap_grant()
2575 if (ci->i_xattrs.blob) in handle_cap_grant()
2576 ceph_buffer_put(ci->i_xattrs.blob); in handle_cap_grant()
2577 ci->i_xattrs.blob = ceph_buffer_get(xattr_buf); in handle_cap_grant()
2578 ci->i_xattrs.version = version; in handle_cap_grant()
2585 if ((issued & CEPH_CAP_FILE_CACHE) && ci->i_rdcache_gen > 1) in handle_cap_grant()
2600 ci->i_layout = grant->layout; in handle_cap_grant()
2607 if (ci->i_auth_cap == cap && max_size != ci->i_max_size) { in handle_cap_grant()
2609 ci->i_max_size, max_size); in handle_cap_grant()
2610 ci->i_max_size = max_size; in handle_cap_grant()
2611 if (max_size >= ci->i_wanted_max_size) { in handle_cap_grant()
2612 ci->i_wanted_max_size = 0; /* reset */ in handle_cap_grant()
2613 ci->i_requested_max_size = 0; in handle_cap_grant()
2620 wanted = __ceph_caps_wanted(ci); in handle_cap_grant()
2621 used = __ceph_caps_used(ci); in handle_cap_grant()
2622 dirty = __ceph_caps_dirty(ci); in handle_cap_grant()
2650 else if (cap == ci->i_auth_cap) in handle_cap_grant()
2663 if (cap == ci->i_auth_cap && in handle_cap_grant()
2664 __ceph_caps_revoking_other(ci, cap, newcaps)) in handle_cap_grant()
2675 if (inline_version > 0 && inline_version >= ci->i_inline_version) { in handle_cap_grant()
2676 ci->i_inline_version = inline_version; in handle_cap_grant()
2677 if (ci->i_inline_version != CEPH_INLINE_NONE && in handle_cap_grant()
2682 spin_unlock(&ci->i_ceph_lock); in handle_cap_grant()
2712 wake_up_all(&ci->i_cap_wq); in handle_cap_grant()
2715 ceph_check_caps(ci, CHECK_CAPS_NODELAY|CHECK_CAPS_AUTHONLY, in handle_cap_grant()
2718 ceph_check_caps(ci, CHECK_CAPS_NODELAY, session); in handle_cap_grant()
2731 __releases(ci->i_ceph_lock) in handle_cap_flush_ack()
2733 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_flush_ack() local
2743 (u16)flush_tid == ci->i_cap_flush_tid[i]) in handle_cap_flush_ack()
2749 ceph_cap_string(cleaned), ceph_cap_string(ci->i_flushing_caps), in handle_cap_flush_ack()
2750 ceph_cap_string(ci->i_flushing_caps & ~cleaned)); in handle_cap_flush_ack()
2752 if (ci->i_flushing_caps == (ci->i_flushing_caps & ~cleaned)) in handle_cap_flush_ack()
2755 ci->i_flushing_caps &= ~cleaned; in handle_cap_flush_ack()
2758 if (ci->i_flushing_caps == 0) { in handle_cap_flush_ack()
2759 list_del_init(&ci->i_flushing_item); in handle_cap_flush_ack()
2770 if (ci->i_dirty_caps == 0) { in handle_cap_flush_ack()
2772 BUG_ON(!list_empty(&ci->i_dirty_item)); in handle_cap_flush_ack()
2774 if (ci->i_wrbuffer_ref_head == 0) { in handle_cap_flush_ack()
2775 BUG_ON(!ci->i_head_snapc); in handle_cap_flush_ack()
2776 ceph_put_snap_context(ci->i_head_snapc); in handle_cap_flush_ack()
2777 ci->i_head_snapc = NULL; in handle_cap_flush_ack()
2780 BUG_ON(list_empty(&ci->i_dirty_item)); in handle_cap_flush_ack()
2784 wake_up_all(&ci->i_cap_wq); in handle_cap_flush_ack()
2787 spin_unlock(&ci->i_ceph_lock); in handle_cap_flush_ack()
2802 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_flushsnap_ack() local
2808 inode, ci, session->s_mds, follows); in handle_cap_flushsnap_ack()
2810 spin_lock(&ci->i_ceph_lock); in handle_cap_flushsnap_ack()
2811 list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { in handle_cap_flushsnap_ack()
2833 spin_unlock(&ci->i_ceph_lock); in handle_cap_flushsnap_ack()
2846 __releases(ci->i_ceph_lock) in handle_cap_trunc()
2848 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_trunc() local
2855 int dirty = __ceph_caps_dirty(ci); in handle_cap_trunc()
2865 spin_unlock(&ci->i_ceph_lock); in handle_cap_trunc()
2888 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_export() local
2906 inode, ci, mds, mseq, target); in handle_cap_export()
2908 spin_lock(&ci->i_ceph_lock); in handle_cap_export()
2909 cap = __get_cap_for_mds(ci, mds); in handle_cap_export()
2926 tcap = __get_cap_for_mds(ci, target); in handle_cap_export()
2938 if (cap == ci->i_auth_cap) in handle_cap_export()
2939 ci->i_auth_cap = tcap; in handle_cap_export()
2940 if (ci->i_flushing_caps && ci->i_auth_cap == tcap) { in handle_cap_export()
2942 list_move_tail(&ci->i_flushing_item, in handle_cap_export()
2951 int flag = (cap == ci->i_auth_cap) ? CEPH_CAP_FLAG_AUTH : 0; in handle_cap_export()
2959 spin_unlock(&ci->i_ceph_lock); in handle_cap_export()
2984 spin_unlock(&ci->i_ceph_lock); in handle_cap_export()
3004 __acquires(ci->i_ceph_lock) in handle_cap_import()
3006 struct ceph_inode_info *ci = ceph_inode(inode); in handle_cap_import() local
3028 inode, ci, mds, mseq, peer); in handle_cap_import()
3031 spin_lock(&ci->i_ceph_lock); in handle_cap_import()
3032 cap = __get_cap_for_mds(ci, mds); in handle_cap_import()
3035 spin_unlock(&ci->i_ceph_lock); in handle_cap_import()
3047 __ceph_caps_issued(ci, &issued); in handle_cap_import()
3048 issued |= __ceph_caps_dirty(ci); in handle_cap_import()
3053 ocap = peer >= 0 ? __get_cap_for_mds(ci, peer) : NULL; in handle_cap_import()
3071 ci->i_wanted_max_size = 0; in handle_cap_import()
3072 ci->i_requested_max_size = 0; in handle_cap_import()
3090 struct ceph_inode_info *ci; in ceph_handle_caps() local
3161 ci = ceph_inode(inode); in ceph_handle_caps()
3217 spin_lock(&ci->i_ceph_lock); in ceph_handle_caps()
3222 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
3230 __ceph_caps_issued(ci, &issued); in ceph_handle_caps()
3231 issued |= __ceph_caps_dirty(ci); in ceph_handle_caps()
3246 spin_unlock(&ci->i_ceph_lock); in ceph_handle_caps()
3279 struct ceph_inode_info *ci; in ceph_check_delayed_caps() local
3287 ci = list_first_entry(&mdsc->cap_delay_list, in ceph_check_delayed_caps()
3290 if ((ci->i_ceph_flags & CEPH_I_FLUSH) == 0 && in ceph_check_delayed_caps()
3291 time_before(jiffies, ci->i_hold_caps_max)) in ceph_check_delayed_caps()
3293 list_del_init(&ci->i_cap_delay_list); in ceph_check_delayed_caps()
3295 dout("check_delayed_caps on %p\n", &ci->vfs_inode); in ceph_check_delayed_caps()
3296 ceph_check_caps(ci, flags, NULL); in ceph_check_delayed_caps()
3306 struct ceph_inode_info *ci; in ceph_flush_dirty_caps() local
3312 ci = list_first_entry(&mdsc->cap_dirty, struct ceph_inode_info, in ceph_flush_dirty_caps()
3314 inode = &ci->vfs_inode; in ceph_flush_dirty_caps()
3318 ceph_check_caps(ci, CHECK_CAPS_NODELAY|CHECK_CAPS_FLUSH, NULL); in ceph_flush_dirty_caps()
3331 void ceph_put_fmode(struct ceph_inode_info *ci, int fmode) in ceph_put_fmode() argument
3333 struct inode *inode = &ci->vfs_inode; in ceph_put_fmode()
3336 spin_lock(&ci->i_ceph_lock); in ceph_put_fmode()
3338 ci->i_nr_by_mode[fmode], ci->i_nr_by_mode[fmode]-1); in ceph_put_fmode()
3339 BUG_ON(ci->i_nr_by_mode[fmode] == 0); in ceph_put_fmode()
3340 if (--ci->i_nr_by_mode[fmode] == 0) in ceph_put_fmode()
3342 spin_unlock(&ci->i_ceph_lock); in ceph_put_fmode()
3344 if (last && ci->i_vino.snap == CEPH_NOSNAP) in ceph_put_fmode()
3345 ceph_check_caps(ci, 0, NULL); in ceph_put_fmode()
3359 struct ceph_inode_info *ci = ceph_inode(inode); in ceph_encode_inode_release() local
3365 spin_lock(&ci->i_ceph_lock); in ceph_encode_inode_release()
3366 used = __ceph_caps_used(ci); in ceph_encode_inode_release()
3367 dirty = __ceph_caps_dirty(ci); in ceph_encode_inode_release()
3376 cap = __get_cap_for_mds(ci, mds); in ceph_encode_inode_release()
3383 int wanted = __ceph_caps_wanted(ci); in ceph_encode_inode_release()
3384 if ((ci->i_ceph_flags & CEPH_I_NODELAY) == 0) in ceph_encode_inode_release()
3418 spin_unlock(&ci->i_ceph_lock); in ceph_encode_inode_release()