@@ -699,7 +699,14 @@ static const char * const cmd_inspect_list_chunks_usage[] = {
699
699
"Show chunks (block groups) layout for all devices" ,
700
700
"" ,
701
701
HELPINFO_UNITS_LONG ,
702
- OPTLINE ("--sort MODE" , "sort by a column ascending: pstart, lstart, usage (default: pstart)" ),
702
+ OPTLINE ("--sort MODE" , "sort by a column ascending (default: pstart), "
703
+ "MODE can be one of: "
704
+ "pstart - physical offset, grouped by device, "
705
+ "lstart - logical offset, "
706
+ "usage - by chunk usage (implies --usage), "
707
+ "length_p - by chunk length, secondary by physical offset, "
708
+ "length_l - by chunk length, secondary by logical offset"
709
+ ),
703
710
OPTLINE ("--usage" , "show usage per block group (note: this can be slow)" ),
704
711
OPTLINE ("--no-usage" , "don't show usage per block group" ),
705
712
OPTLINE ("--empty" , "show empty space between block groups" ),
@@ -711,6 +718,10 @@ enum {
711
718
CHUNK_SORT_PSTART ,
712
719
CHUNK_SORT_LSTART ,
713
720
CHUNK_SORT_USAGE ,
721
+ /* Length, secondary physical start */
722
+ CHUNK_SORT_LENGTH_P ,
723
+ /* Length, secondary logical start */
724
+ CHUNK_SORT_LENGTH_L ,
714
725
CHUNK_SORT_DEFAULT = CHUNK_SORT_PSTART
715
726
};
716
727
@@ -789,6 +800,40 @@ static int cmp_cse_devid_usage(const void *va, const void *vb)
789
800
return 0 ;
790
801
}
791
802
803
+ static int cmp_cse_length_physical (const void * va , const void * vb )
804
+ {
805
+ const struct list_chunks_entry * a = va ;
806
+ const struct list_chunks_entry * b = vb ;
807
+
808
+ if (a -> length < b -> length )
809
+ return -1 ;
810
+ if (a -> length > b -> length )
811
+ return 1 ;
812
+
813
+ if (a -> start < b -> start )
814
+ return -1 ;
815
+ if (a -> start > b -> start )
816
+ return 1 ;
817
+ return 0 ;
818
+ }
819
+
820
+ static int cmp_cse_length_logical (const void * va , const void * vb )
821
+ {
822
+ const struct list_chunks_entry * a = va ;
823
+ const struct list_chunks_entry * b = vb ;
824
+
825
+ if (a -> length < b -> length )
826
+ return -1 ;
827
+ if (a -> length > b -> length )
828
+ return 1 ;
829
+
830
+ if (a -> lstart < b -> lstart )
831
+ return -1 ;
832
+ if (a -> lstart > b -> lstart )
833
+ return 1 ;
834
+ return 0 ;
835
+ }
836
+
792
837
static int print_list_chunks (struct list_chunks_ctx * ctx , unsigned sort_mode ,
793
838
unsigned unit_mode , bool with_usage , bool with_empty )
794
839
{
@@ -830,6 +875,12 @@ static int print_list_chunks(struct list_chunks_ctx *ctx, unsigned sort_mode,
830
875
else if (sort_mode == CHUNK_SORT_USAGE )
831
876
qsort (ctx -> stats , ctx -> length , sizeof (ctx -> stats [0 ]),
832
877
cmp_cse_devid_usage );
878
+ else if (sort_mode == CHUNK_SORT_LENGTH_P )
879
+ qsort (ctx -> stats , ctx -> length , sizeof (ctx -> stats [0 ]),
880
+ cmp_cse_length_physical );
881
+ else if (sort_mode == CHUNK_SORT_LENGTH_L )
882
+ qsort (ctx -> stats , ctx -> length , sizeof (ctx -> stats [0 ]),
883
+ cmp_cse_length_logical );
833
884
834
885
/* Optional usage, two rows for header and separator, gaps */
835
886
table = table_create (7 + (int )with_usage , 2 + ctx -> length + gaps );
@@ -992,6 +1043,10 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,
992
1043
} else if (strcmp (optarg , "usage" ) == 0 ) {
993
1044
sort_mode = CHUNK_SORT_USAGE ;
994
1045
with_usage = true;
1046
+ } else if (strcmp (optarg , "length_p" ) == 0 ) {
1047
+ sort_mode = CHUNK_SORT_LENGTH_P ;
1048
+ } else if (strcmp (optarg , "length_l" ) == 0 ) {
1049
+ sort_mode = CHUNK_SORT_LENGTH_L ;
995
1050
} else {
996
1051
error ("unknown sort mode: %s" , optarg );
997
1052
exit (1 );
0 commit comments