@@ -343,6 +343,46 @@ static void ceph_monc_handle_map(struct ceph_mon_client *monc,
343343/*
344344 * statfs
345345 */
346+ static struct ceph_mon_statfs_request * __lookup_statfs (
347+ struct ceph_mon_client * monc , u64 tid )
348+ {
349+ struct ceph_mon_statfs_request * req ;
350+ struct rb_node * n = monc -> statfs_request_tree .rb_node ;
351+
352+ while (n ) {
353+ req = rb_entry (n , struct ceph_mon_statfs_request , node );
354+ if (tid < req -> tid )
355+ n = n -> rb_left ;
356+ else if (tid > req -> tid )
357+ n = n -> rb_right ;
358+ else
359+ return req ;
360+ }
361+ return NULL ;
362+ }
363+
364+ static void __insert_statfs (struct ceph_mon_client * monc ,
365+ struct ceph_mon_statfs_request * new )
366+ {
367+ struct rb_node * * p = & monc -> statfs_request_tree .rb_node ;
368+ struct rb_node * parent = NULL ;
369+ struct ceph_mon_statfs_request * req = NULL ;
370+
371+ while (* p ) {
372+ parent = * p ;
373+ req = rb_entry (parent , struct ceph_mon_statfs_request , node );
374+ if (new -> tid < req -> tid )
375+ p = & (* p )-> rb_left ;
376+ else if (new -> tid > req -> tid )
377+ p = & (* p )-> rb_right ;
378+ else
379+ BUG ();
380+ }
381+
382+ rb_link_node (& new -> node , parent , p );
383+ rb_insert_color (& new -> node , & monc -> statfs_request_tree );
384+ }
385+
346386static void handle_statfs_reply (struct ceph_mon_client * monc ,
347387 struct ceph_msg * msg )
348388{
@@ -356,7 +396,7 @@ static void handle_statfs_reply(struct ceph_mon_client *monc,
356396 dout ("handle_statfs_reply %p tid %llu\n" , msg , tid );
357397
358398 mutex_lock (& monc -> mutex );
359- req = radix_tree_lookup ( & monc -> statfs_request_tree , tid );
399+ req = __lookup_statfs ( monc , tid );
360400 if (req ) {
361401 * req -> buf = reply -> st ;
362402 req -> result = 0 ;
@@ -416,11 +456,7 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
416456 req .tid = ++ monc -> last_tid ;
417457 req .last_attempt = jiffies ;
418458 req .delay = BASE_DELAY_INTERVAL ;
419- if (radix_tree_insert (& monc -> statfs_request_tree , req .tid , & req ) < 0 ) {
420- mutex_unlock (& monc -> mutex );
421- pr_err ("ENOMEM in do_statfs\n" );
422- return - ENOMEM ;
423- }
459+ __insert_statfs (monc , & req );
424460 monc -> num_statfs_requests ++ ;
425461 mutex_unlock (& monc -> mutex );
426462
@@ -430,7 +466,7 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
430466 err = wait_for_completion_interruptible (& req .completion );
431467
432468 mutex_lock (& monc -> mutex );
433- radix_tree_delete ( & monc -> statfs_request_tree , req . tid );
469+ rb_erase ( & req . node , & monc -> statfs_request_tree );
434470 monc -> num_statfs_requests -- ;
435471 ceph_msgpool_resv (& monc -> msgpool_statfs_reply , -1 );
436472 mutex_unlock (& monc -> mutex );
@@ -445,20 +481,11 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
445481 */
446482static void __resend_statfs (struct ceph_mon_client * monc )
447483{
448- u64 next_tid = 0 ;
449- int got ;
450- int did = 0 ;
451484 struct ceph_mon_statfs_request * req ;
485+ struct rb_node * p ;
452486
453- while (1 ) {
454- got = radix_tree_gang_lookup (& monc -> statfs_request_tree ,
455- (void * * )& req ,
456- next_tid , 1 );
457- if (got == 0 )
458- break ;
459- did ++ ;
460- next_tid = req -> tid + 1 ;
461-
487+ for (p = rb_first (& monc -> statfs_request_tree ); p ; p = rb_next (p )) {
488+ req = rb_entry (p , struct ceph_mon_statfs_request , node );
462489 send_statfs (monc , req );
463490 }
464491}
@@ -578,7 +605,7 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
578605 monc -> sub_sent = 0 ;
579606
580607 INIT_DELAYED_WORK (& monc -> delayed_work , delayed_work );
581- INIT_RADIX_TREE ( & monc -> statfs_request_tree , GFP_NOFS ) ;
608+ monc -> statfs_request_tree = RB_ROOT ;
582609 monc -> num_statfs_requests = 0 ;
583610 monc -> last_tid = 0 ;
584611
0 commit comments