@@ -687,19 +687,46 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
687687 {},
688688};
689689
690+ static bool debugfs_create_files (struct dentry * parent , void * data ,
691+ const struct blk_mq_debugfs_attr * attr )
692+ {
693+ d_inode (parent )-> i_private = data ;
694+
695+ for (; attr -> name ; attr ++ ) {
696+ if (!debugfs_create_file (attr -> name , attr -> mode , parent ,
697+ (void * )attr , & blk_mq_debugfs_fops ))
698+ return false;
699+ }
700+ return true;
701+ }
702+
690703int blk_mq_debugfs_register (struct request_queue * q )
691704{
705+ struct blk_mq_hw_ctx * hctx ;
706+ int i ;
707+
692708 if (!blk_debugfs_root )
693709 return - ENOENT ;
694710
695711 q -> debugfs_dir = debugfs_create_dir (kobject_name (q -> kobj .parent ),
696712 blk_debugfs_root );
697713 if (!q -> debugfs_dir )
698- goto err ;
714+ return - ENOMEM ;
699715
700- if (blk_mq_debugfs_register_mq (q ))
716+ if (!debugfs_create_files (q -> debugfs_dir , q ,
717+ blk_mq_debugfs_queue_attrs ))
701718 goto err ;
702719
720+ /*
721+ * blk_mq_init_hctx() attempted to do this already, but q->debugfs_dir
722+ * didn't exist yet (because we don't know what to name the directory
723+ * until the queue is registered to a gendisk).
724+ */
725+ queue_for_each_hw_ctx (q , hctx , i ) {
726+ if (!hctx -> debugfs_dir && blk_mq_debugfs_register_hctx (q , hctx ))
727+ goto err ;
728+ }
729+
703730 return 0 ;
704731
705732err :
@@ -710,32 +737,17 @@ int blk_mq_debugfs_register(struct request_queue *q)
710737void blk_mq_debugfs_unregister (struct request_queue * q )
711738{
712739 debugfs_remove_recursive (q -> debugfs_dir );
713- q -> mq_debugfs_dir = NULL ;
714740 q -> debugfs_dir = NULL ;
715741}
716742
717- static bool debugfs_create_files (struct dentry * parent , void * data ,
718- const struct blk_mq_debugfs_attr * attr )
719- {
720- d_inode (parent )-> i_private = data ;
721-
722- for (; attr -> name ; attr ++ ) {
723- if (!debugfs_create_file (attr -> name , attr -> mode , parent ,
724- (void * )attr , & blk_mq_debugfs_fops ))
725- return false;
726- }
727- return true;
728- }
729-
730- static int blk_mq_debugfs_register_ctx (struct request_queue * q ,
731- struct blk_mq_ctx * ctx ,
732- struct dentry * hctx_dir )
743+ static int blk_mq_debugfs_register_ctx (struct blk_mq_hw_ctx * hctx ,
744+ struct blk_mq_ctx * ctx )
733745{
734746 struct dentry * ctx_dir ;
735747 char name [20 ];
736748
737749 snprintf (name , sizeof (name ), "cpu%u" , ctx -> cpu );
738- ctx_dir = debugfs_create_dir (name , hctx_dir );
750+ ctx_dir = debugfs_create_dir (name , hctx -> debugfs_dir );
739751 if (!ctx_dir )
740752 return - ENOMEM ;
741753
@@ -745,59 +757,61 @@ static int blk_mq_debugfs_register_ctx(struct request_queue *q,
745757 return 0 ;
746758}
747759
748- static int blk_mq_debugfs_register_hctx (struct request_queue * q ,
749- struct blk_mq_hw_ctx * hctx )
760+ int blk_mq_debugfs_register_hctx (struct request_queue * q ,
761+ struct blk_mq_hw_ctx * hctx )
750762{
751763 struct blk_mq_ctx * ctx ;
752- struct dentry * hctx_dir ;
753764 char name [20 ];
754765 int i ;
755766
767+ if (!q -> debugfs_dir )
768+ return - ENOENT ;
769+
756770 snprintf (name , sizeof (name ), "hctx%u" , hctx -> queue_num );
757- hctx_dir = debugfs_create_dir (name , q -> mq_debugfs_dir );
758- if (!hctx_dir )
771+ hctx -> debugfs_dir = debugfs_create_dir (name , q -> debugfs_dir );
772+ if (!hctx -> debugfs_dir )
759773 return - ENOMEM ;
760774
761- if (!debugfs_create_files (hctx_dir , hctx , blk_mq_debugfs_hctx_attrs ))
762- return - ENOMEM ;
775+ if (!debugfs_create_files (hctx -> debugfs_dir , hctx ,
776+ blk_mq_debugfs_hctx_attrs ))
777+ goto err ;
763778
764779 hctx_for_each_ctx (hctx , ctx , i ) {
765- if (blk_mq_debugfs_register_ctx (q , ctx , hctx_dir ))
766- return - ENOMEM ;
780+ if (blk_mq_debugfs_register_ctx (hctx , ctx ))
781+ goto err ;
767782 }
768783
769784 return 0 ;
785+
786+ err :
787+ blk_mq_debugfs_unregister_hctx (hctx );
788+ return - ENOMEM ;
789+ }
790+
791+ void blk_mq_debugfs_unregister_hctx (struct blk_mq_hw_ctx * hctx )
792+ {
793+ debugfs_remove_recursive (hctx -> debugfs_dir );
794+ hctx -> debugfs_dir = NULL ;
770795}
771796
772- int blk_mq_debugfs_register_mq (struct request_queue * q )
797+ int blk_mq_debugfs_register_hctxs (struct request_queue * q )
773798{
774799 struct blk_mq_hw_ctx * hctx ;
775800 int i ;
776801
777- if (!q -> debugfs_dir )
778- return - ENOENT ;
779-
780- q -> mq_debugfs_dir = debugfs_create_dir ("mq" , q -> debugfs_dir );
781- if (!q -> mq_debugfs_dir )
782- goto err ;
783-
784- if (!debugfs_create_files (q -> mq_debugfs_dir , q , blk_mq_debugfs_queue_attrs ))
785- goto err ;
786-
787802 queue_for_each_hw_ctx (q , hctx , i ) {
788803 if (blk_mq_debugfs_register_hctx (q , hctx ))
789- goto err ;
804+ return - ENOMEM ;
790805 }
791806
792807 return 0 ;
793-
794- err :
795- blk_mq_debugfs_unregister_mq (q );
796- return - ENOMEM ;
797808}
798809
799- void blk_mq_debugfs_unregister_mq (struct request_queue * q )
810+ void blk_mq_debugfs_unregister_hctxs (struct request_queue * q )
800811{
801- debugfs_remove_recursive (q -> mq_debugfs_dir );
802- q -> mq_debugfs_dir = NULL ;
812+ struct blk_mq_hw_ctx * hctx ;
813+ int i ;
814+
815+ queue_for_each_hw_ctx (q , hctx , i )
816+ blk_mq_debugfs_unregister_hctx (hctx );
803817}
0 commit comments