@@ -2627,6 +2627,32 @@ static int nilfs_segctor_flush_mode(struct nilfs_sc_info *sci)
2627
2627
return SC_LSEG_SR ;
2628
2628
}
2629
2629
2630
+ /**
2631
+ * nilfs_log_write_required - determine whether log writing is required
2632
+ * @sci: nilfs_sc_info struct
2633
+ * @modep: location for storing log writing mode
2634
+ *
2635
+ * Return: true if log writing is required, false otherwise. If log writing
2636
+ * is required, the mode is stored in the location pointed to by @modep.
2637
+ */
2638
+ static bool nilfs_log_write_required (struct nilfs_sc_info * sci , int * modep )
2639
+ {
2640
+ bool timedout , ret = true;
2641
+
2642
+ spin_lock (& sci -> sc_state_lock );
2643
+ timedout = ((sci -> sc_state & NILFS_SEGCTOR_COMMIT ) &&
2644
+ time_after_eq (jiffies , sci -> sc_timer .expires ));
2645
+ if (timedout || sci -> sc_seq_request != sci -> sc_seq_done )
2646
+ * modep = SC_LSEG_SR ;
2647
+ else if (sci -> sc_flush_request )
2648
+ * modep = nilfs_segctor_flush_mode (sci );
2649
+ else
2650
+ ret = false;
2651
+
2652
+ spin_unlock (& sci -> sc_state_lock );
2653
+ return ret ;
2654
+ }
2655
+
2630
2656
/**
2631
2657
* nilfs_segctor_thread - main loop of the log writer thread
2632
2658
* @arg: pointer to a struct nilfs_sc_info.
@@ -2642,70 +2668,39 @@ static int nilfs_segctor_thread(void *arg)
2642
2668
{
2643
2669
struct nilfs_sc_info * sci = (struct nilfs_sc_info * )arg ;
2644
2670
struct the_nilfs * nilfs = sci -> sc_super -> s_fs_info ;
2645
- int timeout = 0 ;
2646
2671
2647
2672
nilfs_info (sci -> sc_super ,
2648
2673
"segctord starting. Construction interval = %lu seconds, CP frequency < %lu seconds" ,
2649
2674
sci -> sc_interval / HZ , sci -> sc_mjcp_freq / HZ );
2650
2675
2651
2676
set_freezable ();
2652
- spin_lock (& sci -> sc_state_lock );
2653
- loop :
2654
- for (;;) {
2655
- int mode ;
2656
-
2657
- if (kthread_should_stop ())
2658
- goto end_thread ;
2659
-
2660
- if (timeout || sci -> sc_seq_request != sci -> sc_seq_done )
2661
- mode = SC_LSEG_SR ;
2662
- else if (sci -> sc_flush_request )
2663
- mode = nilfs_segctor_flush_mode (sci );
2664
- else
2665
- break ;
2666
-
2667
- spin_unlock (& sci -> sc_state_lock );
2668
- nilfs_segctor_thread_construct (sci , mode );
2669
- spin_lock (& sci -> sc_state_lock );
2670
- timeout = 0 ;
2671
- }
2672
2677
2673
-
2674
- if (freezing (current )) {
2675
- spin_unlock (& sci -> sc_state_lock );
2676
- try_to_freeze ();
2677
- spin_lock (& sci -> sc_state_lock );
2678
- } else {
2678
+ while (!kthread_should_stop ()) {
2679
2679
DEFINE_WAIT (wait );
2680
- int should_sleep = 1 ;
2680
+ bool should_write ;
2681
+ int mode ;
2682
+
2683
+ if (freezing (current )) {
2684
+ try_to_freeze ();
2685
+ continue ;
2686
+ }
2681
2687
2682
2688
prepare_to_wait (& sci -> sc_wait_daemon , & wait ,
2683
2689
TASK_INTERRUPTIBLE );
2684
-
2685
- if (sci -> sc_seq_request != sci -> sc_seq_done )
2686
- should_sleep = 0 ;
2687
- else if (sci -> sc_flush_request )
2688
- should_sleep = 0 ;
2689
- else if (sci -> sc_state & NILFS_SEGCTOR_COMMIT )
2690
- should_sleep = time_before (jiffies ,
2691
- sci -> sc_timer .expires );
2692
-
2693
- if (should_sleep ) {
2694
- spin_unlock (& sci -> sc_state_lock );
2690
+ should_write = nilfs_log_write_required (sci , & mode );
2691
+ if (!should_write )
2695
2692
schedule ();
2696
- spin_lock (& sci -> sc_state_lock );
2697
- }
2698
2693
finish_wait (& sci -> sc_wait_daemon , & wait );
2699
- timeout = ((sci -> sc_state & NILFS_SEGCTOR_COMMIT ) &&
2700
- time_after_eq (jiffies , sci -> sc_timer .expires ));
2701
2694
2702
2695
if (nilfs_sb_dirty (nilfs ) && nilfs_sb_need_update (nilfs ))
2703
2696
set_nilfs_discontinued (nilfs );
2697
+
2698
+ if (should_write )
2699
+ nilfs_segctor_thread_construct (sci , mode );
2704
2700
}
2705
- goto loop ;
2706
2701
2707
- end_thread :
2708
2702
/* end sync. */
2703
+ spin_lock (& sci -> sc_state_lock );
2709
2704
sci -> sc_task = NULL ;
2710
2705
timer_shutdown_sync (& sci -> sc_timer );
2711
2706
spin_unlock (& sci -> sc_state_lock );
0 commit comments