@@ -730,7 +730,7 @@ void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work)
730730 spin_unlock_irqrestore (& worker -> lock , flags );
731731}
732732
733- struct btrfs_workqueue_struct {
733+ struct __btrfs_workqueue_struct {
734734 struct workqueue_struct * normal_wq ;
735735 /* List head pointing to ordered work list */
736736 struct list_head ordered_list ;
@@ -739,6 +739,38 @@ struct btrfs_workqueue_struct {
739739 spinlock_t list_lock ;
740740};
741741
742+ struct btrfs_workqueue_struct {
743+ struct __btrfs_workqueue_struct * normal ;
744+ struct __btrfs_workqueue_struct * high ;
745+ };
746+
747+ static inline struct __btrfs_workqueue_struct
748+ * __btrfs_alloc_workqueue (char * name , int flags , int max_active )
749+ {
750+ struct __btrfs_workqueue_struct * ret = kzalloc (sizeof (* ret ), GFP_NOFS );
751+
752+ if (unlikely (!ret ))
753+ return NULL ;
754+
755+ if (flags & WQ_HIGHPRI )
756+ ret -> normal_wq = alloc_workqueue ("%s-%s-high" , flags ,
757+ max_active , "btrfs" , name );
758+ else
759+ ret -> normal_wq = alloc_workqueue ("%s-%s" , flags ,
760+ max_active , "btrfs" , name );
761+ if (unlikely (!ret -> normal_wq )) {
762+ kfree (ret );
763+ return NULL ;
764+ }
765+
766+ INIT_LIST_HEAD (& ret -> ordered_list );
767+ spin_lock_init (& ret -> list_lock );
768+ return ret ;
769+ }
770+
771+ static inline void
772+ __btrfs_destroy_workqueue (struct __btrfs_workqueue_struct * wq );
773+
742774struct btrfs_workqueue_struct * btrfs_alloc_workqueue (char * name ,
743775 int flags ,
744776 int max_active )
@@ -748,19 +780,25 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name,
748780 if (unlikely (!ret ))
749781 return NULL ;
750782
751- ret -> normal_wq = alloc_workqueue ( "%s-%s" , flags , max_active ,
752- "btrfs" , name );
753- if (unlikely (!ret -> normal_wq )) {
783+ ret -> normal = __btrfs_alloc_workqueue ( name , flags & ~ WQ_HIGHPRI ,
784+ max_active );
785+ if (unlikely (!ret -> normal )) {
754786 kfree (ret );
755787 return NULL ;
756788 }
757789
758- INIT_LIST_HEAD (& ret -> ordered_list );
759- spin_lock_init (& ret -> list_lock );
790+ if (flags & WQ_HIGHPRI ) {
791+ ret -> high = __btrfs_alloc_workqueue (name , flags , max_active );
792+ if (unlikely (!ret -> high )) {
793+ __btrfs_destroy_workqueue (ret -> normal );
794+ kfree (ret );
795+ return NULL ;
796+ }
797+ }
760798 return ret ;
761799}
762800
763- static void run_ordered_work (struct btrfs_workqueue_struct * wq )
801+ static void run_ordered_work (struct __btrfs_workqueue_struct * wq )
764802{
765803 struct list_head * list = & wq -> ordered_list ;
766804 struct btrfs_work_struct * work ;
@@ -804,7 +842,7 @@ static void run_ordered_work(struct btrfs_workqueue_struct *wq)
804842static void normal_work_helper (struct work_struct * arg )
805843{
806844 struct btrfs_work_struct * work ;
807- struct btrfs_workqueue_struct * wq ;
845+ struct __btrfs_workqueue_struct * wq ;
808846 int need_order = 0 ;
809847
810848 work = container_of (arg , struct btrfs_work_struct , normal_work );
@@ -840,8 +878,8 @@ void btrfs_init_work(struct btrfs_work_struct *work,
840878 work -> flags = 0 ;
841879}
842880
843- void btrfs_queue_work (struct btrfs_workqueue_struct * wq ,
844- struct btrfs_work_struct * work )
881+ static inline void __btrfs_queue_work (struct __btrfs_workqueue_struct * wq ,
882+ struct btrfs_work_struct * work )
845883{
846884 unsigned long flags ;
847885
@@ -854,13 +892,42 @@ void btrfs_queue_work(struct btrfs_workqueue_struct *wq,
854892 queue_work (wq -> normal_wq , & work -> normal_work );
855893}
856894
857- void btrfs_destroy_workqueue (struct btrfs_workqueue_struct * wq )
895+ void btrfs_queue_work (struct btrfs_workqueue_struct * wq ,
896+ struct btrfs_work_struct * work )
897+ {
898+ struct __btrfs_workqueue_struct * dest_wq ;
899+
900+ if (test_bit (WORK_HIGH_PRIO_BIT , & work -> flags ) && wq -> high )
901+ dest_wq = wq -> high ;
902+ else
903+ dest_wq = wq -> normal ;
904+ __btrfs_queue_work (dest_wq , work );
905+ }
906+
907+ static inline void
908+ __btrfs_destroy_workqueue (struct __btrfs_workqueue_struct * wq )
858909{
859910 destroy_workqueue (wq -> normal_wq );
860911 kfree (wq );
861912}
862913
914+ void btrfs_destroy_workqueue (struct btrfs_workqueue_struct * wq )
915+ {
916+ if (!wq )
917+ return ;
918+ if (wq -> high )
919+ __btrfs_destroy_workqueue (wq -> high );
920+ __btrfs_destroy_workqueue (wq -> normal );
921+ }
922+
863923void btrfs_workqueue_set_max (struct btrfs_workqueue_struct * wq , int max )
864924{
865- workqueue_set_max_active (wq -> normal_wq , max );
925+ workqueue_set_max_active (wq -> normal -> normal_wq , max );
926+ if (wq -> high )
927+ workqueue_set_max_active (wq -> high -> normal_wq , max );
928+ }
929+
930+ void btrfs_set_work_high_priority (struct btrfs_work_struct * work )
931+ {
932+ set_bit (WORK_HIGH_PRIO_BIT , & work -> flags );
866933}
0 commit comments