Lines Matching refs:mdsc

118 void ceph_caps_init(struct ceph_mds_client *mdsc)  in ceph_caps_init()  argument
120 INIT_LIST_HEAD(&mdsc->caps_list); in ceph_caps_init()
121 spin_lock_init(&mdsc->caps_list_lock); in ceph_caps_init()
124 void ceph_caps_finalize(struct ceph_mds_client *mdsc) in ceph_caps_finalize() argument
128 spin_lock(&mdsc->caps_list_lock); in ceph_caps_finalize()
129 while (!list_empty(&mdsc->caps_list)) { in ceph_caps_finalize()
130 cap = list_first_entry(&mdsc->caps_list, in ceph_caps_finalize()
135 mdsc->caps_total_count = 0; in ceph_caps_finalize()
136 mdsc->caps_avail_count = 0; in ceph_caps_finalize()
137 mdsc->caps_use_count = 0; in ceph_caps_finalize()
138 mdsc->caps_reserve_count = 0; in ceph_caps_finalize()
139 mdsc->caps_min_count = 0; in ceph_caps_finalize()
140 spin_unlock(&mdsc->caps_list_lock); in ceph_caps_finalize()
143 void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta) in ceph_adjust_min_caps() argument
145 spin_lock(&mdsc->caps_list_lock); in ceph_adjust_min_caps()
146 mdsc->caps_min_count += delta; in ceph_adjust_min_caps()
147 BUG_ON(mdsc->caps_min_count < 0); in ceph_adjust_min_caps()
148 spin_unlock(&mdsc->caps_list_lock); in ceph_adjust_min_caps()
151 void ceph_reserve_caps(struct ceph_mds_client *mdsc, in ceph_reserve_caps() argument
163 spin_lock(&mdsc->caps_list_lock); in ceph_reserve_caps()
164 if (mdsc->caps_avail_count >= need) in ceph_reserve_caps()
167 have = mdsc->caps_avail_count; in ceph_reserve_caps()
168 mdsc->caps_avail_count -= have; in ceph_reserve_caps()
169 mdsc->caps_reserve_count += have; in ceph_reserve_caps()
170 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_reserve_caps()
171 mdsc->caps_reserve_count + in ceph_reserve_caps()
172 mdsc->caps_avail_count); in ceph_reserve_caps()
173 spin_unlock(&mdsc->caps_list_lock); in ceph_reserve_caps()
187 spin_lock(&mdsc->caps_list_lock); in ceph_reserve_caps()
188 mdsc->caps_total_count += alloc; in ceph_reserve_caps()
189 mdsc->caps_reserve_count += alloc; in ceph_reserve_caps()
190 list_splice(&newcaps, &mdsc->caps_list); in ceph_reserve_caps()
192 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_reserve_caps()
193 mdsc->caps_reserve_count + in ceph_reserve_caps()
194 mdsc->caps_avail_count); in ceph_reserve_caps()
195 spin_unlock(&mdsc->caps_list_lock); in ceph_reserve_caps()
199 ctx, mdsc->caps_total_count, mdsc->caps_use_count, in ceph_reserve_caps()
200 mdsc->caps_reserve_count, mdsc->caps_avail_count); in ceph_reserve_caps()
203 int ceph_unreserve_caps(struct ceph_mds_client *mdsc, in ceph_unreserve_caps() argument
208 spin_lock(&mdsc->caps_list_lock); in ceph_unreserve_caps()
209 BUG_ON(mdsc->caps_reserve_count < ctx->count); in ceph_unreserve_caps()
210 mdsc->caps_reserve_count -= ctx->count; in ceph_unreserve_caps()
211 mdsc->caps_avail_count += ctx->count; in ceph_unreserve_caps()
214 mdsc->caps_total_count, mdsc->caps_use_count, in ceph_unreserve_caps()
215 mdsc->caps_reserve_count, mdsc->caps_avail_count); in ceph_unreserve_caps()
216 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_unreserve_caps()
217 mdsc->caps_reserve_count + in ceph_unreserve_caps()
218 mdsc->caps_avail_count); in ceph_unreserve_caps()
219 spin_unlock(&mdsc->caps_list_lock); in ceph_unreserve_caps()
224 struct ceph_cap *ceph_get_cap(struct ceph_mds_client *mdsc, in ceph_get_cap() argument
233 spin_lock(&mdsc->caps_list_lock); in ceph_get_cap()
234 mdsc->caps_use_count++; in ceph_get_cap()
235 mdsc->caps_total_count++; in ceph_get_cap()
236 spin_unlock(&mdsc->caps_list_lock); in ceph_get_cap()
241 spin_lock(&mdsc->caps_list_lock); in ceph_get_cap()
243 ctx, ctx->count, mdsc->caps_total_count, mdsc->caps_use_count, in ceph_get_cap()
244 mdsc->caps_reserve_count, mdsc->caps_avail_count); in ceph_get_cap()
246 BUG_ON(ctx->count > mdsc->caps_reserve_count); in ceph_get_cap()
247 BUG_ON(list_empty(&mdsc->caps_list)); in ceph_get_cap()
250 mdsc->caps_reserve_count--; in ceph_get_cap()
251 mdsc->caps_use_count++; in ceph_get_cap()
253 cap = list_first_entry(&mdsc->caps_list, struct ceph_cap, caps_item); in ceph_get_cap()
256 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_get_cap()
257 mdsc->caps_reserve_count + mdsc->caps_avail_count); in ceph_get_cap()
258 spin_unlock(&mdsc->caps_list_lock); in ceph_get_cap()
262 void ceph_put_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap) in ceph_put_cap() argument
264 spin_lock(&mdsc->caps_list_lock); in ceph_put_cap()
266 cap, mdsc->caps_total_count, mdsc->caps_use_count, in ceph_put_cap()
267 mdsc->caps_reserve_count, mdsc->caps_avail_count); in ceph_put_cap()
268 mdsc->caps_use_count--; in ceph_put_cap()
273 if (mdsc->caps_avail_count >= mdsc->caps_reserve_count + in ceph_put_cap()
274 mdsc->caps_min_count) { in ceph_put_cap()
275 mdsc->caps_total_count--; in ceph_put_cap()
278 mdsc->caps_avail_count++; in ceph_put_cap()
279 list_add(&cap->caps_item, &mdsc->caps_list); in ceph_put_cap()
282 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + in ceph_put_cap()
283 mdsc->caps_reserve_count + mdsc->caps_avail_count); in ceph_put_cap()
284 spin_unlock(&mdsc->caps_list_lock); in ceph_put_cap()
291 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_reservation_status() local
294 *total = mdsc->caps_total_count; in ceph_reservation_status()
296 *avail = mdsc->caps_avail_count; in ceph_reservation_status()
298 *used = mdsc->caps_use_count; in ceph_reservation_status()
300 *reserved = mdsc->caps_reserve_count; in ceph_reservation_status()
302 *min = mdsc->caps_min_count; in ceph_reservation_status()
397 static void __cap_set_timeouts(struct ceph_mds_client *mdsc, in __cap_set_timeouts() argument
400 struct ceph_mount_options *ma = mdsc->fsc->mount_options; in __cap_set_timeouts()
418 static void __cap_delay_requeue(struct ceph_mds_client *mdsc, in __cap_delay_requeue() argument
421 __cap_set_timeouts(mdsc, ci); in __cap_delay_requeue()
424 if (!mdsc->stopping) { in __cap_delay_requeue()
425 spin_lock(&mdsc->cap_delay_lock); in __cap_delay_requeue()
431 list_add_tail(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue()
433 spin_unlock(&mdsc->cap_delay_lock); in __cap_delay_requeue()
442 static void __cap_delay_requeue_front(struct ceph_mds_client *mdsc, in __cap_delay_requeue_front() argument
446 spin_lock(&mdsc->cap_delay_lock); in __cap_delay_requeue_front()
450 list_add(&ci->i_cap_delay_list, &mdsc->cap_delay_list); in __cap_delay_requeue_front()
451 spin_unlock(&mdsc->cap_delay_lock); in __cap_delay_requeue_front()
459 static void __cap_delay_cancel(struct ceph_mds_client *mdsc, in __cap_delay_cancel() argument
465 spin_lock(&mdsc->cap_delay_lock); in __cap_delay_cancel()
467 spin_unlock(&mdsc->cap_delay_lock); in __cap_delay_cancel()
517 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; in ceph_add_cap() local
577 struct ceph_snap_realm *realm = ceph_lookup_snap_realm(mdsc, in ceph_add_cap()
605 __cap_delay_requeue(mdsc, ci); in ceph_add_cap()
909 ceph_put_snap_realm(ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc, in drop_inode_snap_realm()
923 struct ceph_mds_client *mdsc = in __ceph_remove_cap() local
924 ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc; in __ceph_remove_cap()
970 ceph_put_cap(mdsc, cap); in __ceph_remove_cap()
980 __cap_delay_cancel(mdsc, ci); in __ceph_remove_cap()
1108 static int __send_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap, in __send_cap() argument
1237 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; in __ceph_flush_snaps() local
1289 mutex_lock(&mdsc->mutex); in __ceph_flush_snaps()
1290 session = __ceph_lookup_mds_session(mdsc, mds); in __ceph_flush_snaps()
1291 mutex_unlock(&mdsc->mutex); in __ceph_flush_snaps()
1306 spin_lock(&mdsc->cap_dirty_lock); in __ceph_flush_snaps()
1307 capsnap->flush_tid = ++mdsc->last_cap_flush_tid; in __ceph_flush_snaps()
1308 spin_unlock(&mdsc->cap_dirty_lock); in __ceph_flush_snaps()
1336 spin_lock(&mdsc->snap_flush_lock); in __ceph_flush_snaps()
1338 spin_unlock(&mdsc->snap_flush_lock); in __ceph_flush_snaps()
1364 struct ceph_mds_client *mdsc = in __ceph_mark_dirty_caps() local
1365 ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc; in __ceph_mark_dirty_caps()
1386 WARN_ON_ONCE(!rwsem_is_locked(&mdsc->snap_rwsem)); in __ceph_mark_dirty_caps()
1393 spin_lock(&mdsc->cap_dirty_lock); in __ceph_mark_dirty_caps()
1394 list_add(&ci->i_dirty_item, &mdsc->cap_dirty); in __ceph_mark_dirty_caps()
1395 spin_unlock(&mdsc->cap_dirty_lock); in __ceph_mark_dirty_caps()
1407 __cap_delay_requeue(mdsc, ci); in __ceph_mark_dirty_caps()
1434 static void __add_cap_flushing_to_mdsc(struct ceph_mds_client *mdsc, in __add_cap_flushing_to_mdsc() argument
1437 struct rb_node **p = &mdsc->cap_flush_tree.rb_node; in __add_cap_flushing_to_mdsc()
1454 rb_insert_color(&cf->g_node, &mdsc->cap_flush_tree); in __add_cap_flushing_to_mdsc()
1468 static u64 __get_oldest_flush_tid(struct ceph_mds_client *mdsc) in __get_oldest_flush_tid() argument
1470 struct rb_node *n = rb_first(&mdsc->cap_flush_tree); in __get_oldest_flush_tid()
1489 struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; in __mark_caps_flushing() local
1510 spin_lock(&mdsc->cap_dirty_lock); in __mark_caps_flushing()
1513 cf->tid = ++mdsc->last_cap_flush_tid; in __mark_caps_flushing()
1514 __add_cap_flushing_to_mdsc(mdsc, cf); in __mark_caps_flushing()
1515 *oldest_flush_tid = __get_oldest_flush_tid(mdsc); in __mark_caps_flushing()
1519 mdsc->num_cap_flushing++; in __mark_caps_flushing()
1526 spin_unlock(&mdsc->cap_dirty_lock); in __mark_caps_flushing()
1573 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_check_caps() local
1589 if (mdsc->stopping) in ceph_check_caps()
1611 if (!mdsc->stopping && inode->i_nlink > 0) { in ceph_check_caps()
1654 if ((!is_delayed || mdsc->stopping) && in ceph_check_caps()
1673 __cap_set_timeouts(mdsc, ci); in ceph_check_caps()
1775 up_read(&mdsc->snap_rwsem); in ceph_check_caps()
1784 if (down_read_trylock(&mdsc->snap_rwsem) == 0) { in ceph_check_caps()
1788 down_read(&mdsc->snap_rwsem); in ceph_check_caps()
1802 spin_lock(&mdsc->cap_dirty_lock); in ceph_check_caps()
1803 oldest_flush_tid = __get_oldest_flush_tid(mdsc); in ceph_check_caps()
1804 spin_unlock(&mdsc->cap_dirty_lock); in ceph_check_caps()
1811 delayed += __send_cap(mdsc, cap, CEPH_CAP_OP_UPDATE, cap_used, in ceph_check_caps()
1824 __cap_delay_cancel(mdsc, ci); in ceph_check_caps()
1826 __cap_delay_requeue(mdsc, ci); in ceph_check_caps()
1836 up_read(&mdsc->snap_rwsem); in ceph_check_caps()
1844 struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; in try_flush_caps() local
1877 delayed = __send_cap(mdsc, cap, CEPH_CAP_OP_FLUSH, used, want, in try_flush_caps()
1883 __cap_delay_requeue(mdsc, ci); in try_flush_caps()
2076 struct ceph_mds_client *mdsc = in ceph_write_inode() local
2077 ceph_sb_to_client(inode->i_sb)->mdsc; in ceph_write_inode()
2081 __cap_delay_requeue_front(mdsc, ci); in ceph_write_inode()
2093 static void kick_flushing_capsnaps(struct ceph_mds_client *mdsc, in kick_flushing_capsnaps() argument
2119 static int __kick_flushing_caps(struct ceph_mds_client *mdsc, in __kick_flushing_caps() argument
2131 spin_lock(&mdsc->cap_dirty_lock); in __kick_flushing_caps()
2132 oldest_flush_tid = __get_oldest_flush_tid(mdsc); in __kick_flushing_caps()
2133 spin_unlock(&mdsc->cap_dirty_lock); in __kick_flushing_caps()
2161 delayed |= __send_cap(mdsc, cap, CEPH_CAP_OP_FLUSH, in __kick_flushing_caps()
2170 void ceph_early_kick_flushing_caps(struct ceph_mds_client *mdsc, in ceph_early_kick_flushing_caps() argument
2197 if (!__kick_flushing_caps(mdsc, session, ci)) in ceph_early_kick_flushing_caps()
2206 void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc, in ceph_kick_flushing_caps() argument
2211 kick_flushing_capsnaps(mdsc, session); in ceph_kick_flushing_caps()
2215 int delayed = __kick_flushing_caps(mdsc, session, ci); in ceph_kick_flushing_caps()
2218 __cap_delay_requeue(mdsc, ci); in ceph_kick_flushing_caps()
2224 static void kick_flushing_inode_caps(struct ceph_mds_client *mdsc, in kick_flushing_inode_caps() argument
2241 spin_lock(&mdsc->cap_dirty_lock); in kick_flushing_inode_caps()
2244 spin_unlock(&mdsc->cap_dirty_lock); in kick_flushing_inode_caps()
2248 delayed = __kick_flushing_caps(mdsc, session, ci); in kick_flushing_inode_caps()
2251 __cap_delay_requeue(mdsc, ci); in kick_flushing_inode_caps()
2303 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; in try_get_cap_refs() local
2329 up_read(&mdsc->snap_rwsem); in try_get_cap_refs()
2374 if (!down_read_trylock(&mdsc->snap_rwsem)) { in try_get_cap_refs()
2386 down_read(&mdsc->snap_rwsem); in try_get_cap_refs()
2413 ACCESS_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { in try_get_cap_refs()
2426 up_read(&mdsc->snap_rwsem); in try_get_cap_refs()
2750 static void handle_cap_grant(struct ceph_mds_client *mdsc, in handle_cap_grant() argument
2758 __releases(mdsc->snap_rwsem) in handle_cap_grant()
2960 kick_flushing_inode_caps(mdsc, session, inode); in handle_cap_grant()
2961 up_read(&mdsc->snap_rwsem); in handle_cap_grant()
3009 struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; in handle_cap_flush_ack() local
3045 spin_lock(&mdsc->cap_dirty_lock); in handle_cap_flush_ack()
3049 rb_erase(&cf->g_node, &mdsc->cap_flush_tree); in handle_cap_flush_ack()
3051 n = rb_first(&mdsc->cap_flush_tree); in handle_cap_flush_ack()
3054 wake_up_all(&mdsc->cap_flushing_wq); in handle_cap_flush_ack()
3065 mdsc->num_cap_flushing--; in handle_cap_flush_ack()
3082 spin_unlock(&mdsc->cap_dirty_lock); in handle_cap_flush_ack()
3109 struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; in handle_cap_flushsnap_ack() local
3133 wake_up_all(&mdsc->cap_flushing_wq); in handle_cap_flushsnap_ack()
3193 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; in handle_cap_export() local
3249 spin_lock(&mdsc->cap_dirty_lock); in handle_cap_export()
3252 spin_unlock(&mdsc->cap_dirty_lock); in handle_cap_export()
3271 tsession = ceph_mdsc_open_export_target_session(mdsc, target); in handle_cap_export()
3282 new_cap = ceph_get_cap(mdsc, NULL); in handle_cap_export()
3298 ceph_put_cap(mdsc, new_cap); in handle_cap_export()
3306 static void handle_cap_import(struct ceph_mds_client *mdsc, in handle_cap_import() argument
3343 new_cap = ceph_get_cap(mdsc, NULL); in handle_cap_import()
3349 ceph_put_cap(mdsc, new_cap); in handle_cap_import()
3394 struct ceph_mds_client *mdsc = session->s_mdsc; in ceph_handle_caps() local
3395 struct super_block *sb = mdsc->fsc->sb; in ceph_handle_caps()
3481 cap = ceph_get_cap(mdsc, NULL); in ceph_handle_caps()
3509 down_write(&mdsc->snap_rwsem); in ceph_handle_caps()
3510 ceph_update_snap_trace(mdsc, snaptrace, in ceph_handle_caps()
3513 downgrade_write(&mdsc->snap_rwsem); in ceph_handle_caps()
3515 down_read(&mdsc->snap_rwsem); in ceph_handle_caps()
3517 handle_cap_import(mdsc, inode, h, peer, session, in ceph_handle_caps()
3519 handle_cap_grant(mdsc, inode, h, in ceph_handle_caps()
3523 ceph_put_snap_realm(mdsc, realm); in ceph_handle_caps()
3543 handle_cap_grant(mdsc, inode, h, in ceph_handle_caps()
3570 ceph_send_cap_releases(mdsc, session); in ceph_handle_caps()
3587 void ceph_check_delayed_caps(struct ceph_mds_client *mdsc) in ceph_check_delayed_caps() argument
3594 spin_lock(&mdsc->cap_delay_lock); in ceph_check_delayed_caps()
3595 if (list_empty(&mdsc->cap_delay_list)) in ceph_check_delayed_caps()
3597 ci = list_first_entry(&mdsc->cap_delay_list, in ceph_check_delayed_caps()
3604 spin_unlock(&mdsc->cap_delay_lock); in ceph_check_delayed_caps()
3608 spin_unlock(&mdsc->cap_delay_lock); in ceph_check_delayed_caps()
3614 void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc) in ceph_flush_dirty_caps() argument
3620 spin_lock(&mdsc->cap_dirty_lock); in ceph_flush_dirty_caps()
3621 while (!list_empty(&mdsc->cap_dirty)) { in ceph_flush_dirty_caps()
3622 ci = list_first_entry(&mdsc->cap_dirty, struct ceph_inode_info, in ceph_flush_dirty_caps()
3627 spin_unlock(&mdsc->cap_dirty_lock); in ceph_flush_dirty_caps()
3630 spin_lock(&mdsc->cap_dirty_lock); in ceph_flush_dirty_caps()
3632 spin_unlock(&mdsc->cap_dirty_lock); in ceph_flush_dirty_caps()