15
15
static struct cached_fid * init_cached_dir (const char * path );
16
16
static void free_cached_dir (struct cached_fid * cfid );
17
17
static void smb2_close_cached_fid (struct kref * ref );
18
+ static void cfids_laundromat_worker (struct work_struct * work );
18
19
19
20
static struct cached_fid * find_or_create_cached_dir (struct cached_fids * cfids ,
20
21
const char * path ,
@@ -572,53 +573,46 @@ static void free_cached_dir(struct cached_fid *cfid)
572
573
kfree (cfid );
573
574
}
574
575
575
- static int
576
- cifs_cfids_laundromat_thread (void * p )
576
+ static void cfids_laundromat_worker (struct work_struct * work )
577
577
{
578
- struct cached_fids * cfids = p ;
578
+ struct cached_fids * cfids ;
579
579
struct cached_fid * cfid , * q ;
580
- struct list_head entry ;
580
+ LIST_HEAD ( entry ) ;
581
581
582
- while (!kthread_should_stop ()) {
583
- ssleep (1 );
584
- INIT_LIST_HEAD (& entry );
585
- if (kthread_should_stop ())
586
- return 0 ;
587
- spin_lock (& cfids -> cfid_list_lock );
588
- list_for_each_entry_safe (cfid , q , & cfids -> entries , entry ) {
589
- if (time_after (jiffies , cfid -> time + HZ * dir_cache_timeout )) {
590
- list_del (& cfid -> entry );
591
- list_add (& cfid -> entry , & entry );
592
- cfids -> num_entries -- ;
593
- }
582
+ cfids = container_of (work , struct cached_fids , laundromat_work .work );
583
+
584
+ spin_lock (& cfids -> cfid_list_lock );
585
+ list_for_each_entry_safe (cfid , q , & cfids -> entries , entry ) {
586
+ if (time_after (jiffies , cfid -> time + HZ * dir_cache_timeout )) {
587
+ list_move (& cfid -> entry , & entry );
588
+ cfids -> num_entries -- ;
594
589
}
595
- spin_unlock (& cfids -> cfid_list_lock );
590
+ }
591
+ spin_unlock (& cfids -> cfid_list_lock );
596
592
597
- list_for_each_entry_safe (cfid , q , & entry , entry ) {
598
- cfid -> on_list = false;
599
- list_del (& cfid -> entry );
593
+ list_for_each_entry_safe (cfid , q , & entry , entry ) {
594
+ cfid -> on_list = false;
595
+ list_del (& cfid -> entry );
596
+ /*
597
+ * Cancel and wait for the work to finish in case we are racing
598
+ * with it.
599
+ */
600
+ cancel_work_sync (& cfid -> lease_break );
601
+ if (cfid -> has_lease ) {
600
602
/*
601
- * Cancel, and wait for the work to finish in
602
- * case we are racing with it .
603
+ * Our lease has not yet been cancelled from the server
604
+ * so we need to drop the reference .
603
605
*/
604
- cancel_work_sync (& cfid -> lease_break );
605
- if (cfid -> has_lease ) {
606
- /*
607
- * We lease has not yet been cancelled from
608
- * the server so we need to drop the reference.
609
- */
610
- spin_lock (& cfids -> cfid_list_lock );
611
- cfid -> has_lease = false;
612
- spin_unlock (& cfids -> cfid_list_lock );
613
- kref_put (& cfid -> refcount , smb2_close_cached_fid );
614
- }
606
+ spin_lock (& cfids -> cfid_list_lock );
607
+ cfid -> has_lease = false;
608
+ spin_unlock (& cfids -> cfid_list_lock );
609
+ kref_put (& cfid -> refcount , smb2_close_cached_fid );
615
610
}
616
611
}
617
-
618
- return 0 ;
612
+ queue_delayed_work ( cifsiod_wq , & cfids -> laundromat_work ,
613
+ dir_cache_timeout * HZ ) ;
619
614
}
620
615
621
-
622
616
struct cached_fids * init_cached_dirs (void )
623
617
{
624
618
struct cached_fids * cfids ;
@@ -629,19 +623,10 @@ struct cached_fids *init_cached_dirs(void)
629
623
spin_lock_init (& cfids -> cfid_list_lock );
630
624
INIT_LIST_HEAD (& cfids -> entries );
631
625
632
- /*
633
- * since we're in a cifs function already, we know that
634
- * this will succeed. No need for try_module_get().
635
- */
636
- __module_get (THIS_MODULE );
637
- cfids -> laundromat = kthread_run (cifs_cfids_laundromat_thread ,
638
- cfids , "cifsd-cfid-laundromat" );
639
- if (IS_ERR (cfids -> laundromat )) {
640
- cifs_dbg (VFS , "Failed to start cfids laundromat thread.\n" );
641
- kfree (cfids );
642
- module_put (THIS_MODULE );
643
- return NULL ;
644
- }
626
+ INIT_DELAYED_WORK (& cfids -> laundromat_work , cfids_laundromat_worker );
627
+ queue_delayed_work (cifsiod_wq , & cfids -> laundromat_work ,
628
+ dir_cache_timeout * HZ );
629
+
645
630
return cfids ;
646
631
}
647
632
@@ -657,11 +642,7 @@ void free_cached_dirs(struct cached_fids *cfids)
657
642
if (cfids == NULL )
658
643
return ;
659
644
660
- if (cfids -> laundromat ) {
661
- kthread_stop (cfids -> laundromat );
662
- cfids -> laundromat = NULL ;
663
- module_put (THIS_MODULE );
664
- }
645
+ cancel_delayed_work_sync (& cfids -> laundromat_work );
665
646
666
647
spin_lock (& cfids -> cfid_list_lock );
667
648
list_for_each_entry_safe (cfid , q , & cfids -> entries , entry ) {
0 commit comments