@@ -128,6 +128,27 @@ blkio_update_group_weight(struct blkio_group *blkg, unsigned int weight)
128128 }
129129}
130130
131+ static inline void blkio_update_group_bps (struct blkio_group * blkg , u64 bps ,
132+ int fileid )
133+ {
134+ struct blkio_policy_type * blkiop ;
135+
136+ list_for_each_entry (blkiop , & blkio_list , list ) {
137+
138+ /* If this policy does not own the blkg, do not send updates */
139+ if (blkiop -> plid != blkg -> plid )
140+ continue ;
141+
142+ if (fileid == BLKIO_THROTL_read_bps_device
143+ && blkiop -> ops .blkio_update_group_read_bps_fn )
144+ blkiop -> ops .blkio_update_group_read_bps_fn (blkg , bps );
145+
146+ if (fileid == BLKIO_THROTL_write_bps_device
147+ && blkiop -> ops .blkio_update_group_write_bps_fn )
148+ blkiop -> ops .blkio_update_group_write_bps_fn (blkg , bps );
149+ }
150+ }
151+
131152/*
132153 * Add to the appropriate stat variable depending on the request type.
133154 * This should be called with the blkg->stats_lock held.
@@ -612,6 +633,7 @@ static int blkio_policy_parse_and_set(char *buf,
612633 unsigned long major , minor , temp ;
613634 int i = 0 ;
614635 dev_t dev ;
636+ u64 bps ;
615637
616638 memset (s , 0 , sizeof (s ));
617639
@@ -667,7 +689,16 @@ static int blkio_policy_parse_and_set(char *buf,
667689
668690 newpn -> plid = plid ;
669691 newpn -> fileid = fileid ;
670- newpn -> weight = temp ;
692+ newpn -> val .weight = temp ;
693+ break ;
694+ case BLKIO_POLICY_THROTL :
695+ ret = strict_strtoull (s [1 ], 10 , & bps );
696+ if (ret )
697+ return - EINVAL ;
698+
699+ newpn -> plid = plid ;
700+ newpn -> fileid = fileid ;
701+ newpn -> val .bps = bps ;
671702 break ;
672703 default :
673704 BUG ();
@@ -684,18 +715,45 @@ unsigned int blkcg_get_weight(struct blkio_cgroup *blkcg,
684715 pn = blkio_policy_search_node (blkcg , dev , BLKIO_POLICY_PROP ,
685716 BLKIO_PROP_weight_device );
686717 if (pn )
687- return pn -> weight ;
718+ return pn -> val . weight ;
688719 else
689720 return blkcg -> weight ;
690721}
691722EXPORT_SYMBOL_GPL (blkcg_get_weight );
692723
724+ uint64_t blkcg_get_read_bps (struct blkio_cgroup * blkcg , dev_t dev )
725+ {
726+ struct blkio_policy_node * pn ;
727+
728+ pn = blkio_policy_search_node (blkcg , dev , BLKIO_POLICY_THROTL ,
729+ BLKIO_THROTL_read_bps_device );
730+ if (pn )
731+ return pn -> val .bps ;
732+ else
733+ return -1 ;
734+ }
735+
736+ uint64_t blkcg_get_write_bps (struct blkio_cgroup * blkcg , dev_t dev )
737+ {
738+ struct blkio_policy_node * pn ;
739+ pn = blkio_policy_search_node (blkcg , dev , BLKIO_POLICY_THROTL ,
740+ BLKIO_THROTL_write_bps_device );
741+ if (pn )
742+ return pn -> val .bps ;
743+ else
744+ return -1 ;
745+ }
746+
693747/* Checks whether user asked for deleting a policy rule */
694748static bool blkio_delete_rule_command (struct blkio_policy_node * pn )
695749{
696750 switch (pn -> plid ) {
697751 case BLKIO_POLICY_PROP :
698- if (pn -> weight == 0 )
752+ if (pn -> val .weight == 0 )
753+ return 1 ;
754+ break ;
755+ case BLKIO_POLICY_THROTL :
756+ if (pn -> val .bps == 0 )
699757 return 1 ;
700758 break ;
701759 default :
@@ -710,7 +768,10 @@ static void blkio_update_policy_rule(struct blkio_policy_node *oldpn,
710768{
711769 switch (oldpn -> plid ) {
712770 case BLKIO_POLICY_PROP :
713- oldpn -> weight = newpn -> weight ;
771+ oldpn -> val .weight = newpn -> val .weight ;
772+ break ;
773+ case BLKIO_POLICY_THROTL :
774+ oldpn -> val .bps = newpn -> val .bps ;
714775 break ;
715776 default :
716777 BUG ();
@@ -725,13 +786,23 @@ static void blkio_update_blkg_policy(struct blkio_cgroup *blkcg,
725786 struct blkio_group * blkg , struct blkio_policy_node * pn )
726787{
727788 unsigned int weight ;
789+ u64 bps ;
728790
729791 switch (pn -> plid ) {
730792 case BLKIO_POLICY_PROP :
731- weight = pn -> weight ? pn -> weight :
793+ weight = pn -> val . weight ? pn -> val . weight :
732794 blkcg -> weight ;
733795 blkio_update_group_weight (blkg , weight );
734796 break ;
797+ case BLKIO_POLICY_THROTL :
798+ switch (pn -> fileid ) {
799+ case BLKIO_THROTL_read_bps_device :
800+ case BLKIO_THROTL_write_bps_device :
801+ bps = pn -> val .bps ? pn -> val .bps : (-1 );
802+ blkio_update_group_bps (blkg , bps , pn -> fileid );
803+ break ;
804+ }
805+ break ;
735806 default :
736807 BUG ();
737808 }
@@ -826,7 +897,17 @@ blkio_print_policy_node(struct seq_file *m, struct blkio_policy_node *pn)
826897 case BLKIO_POLICY_PROP :
827898 if (pn -> fileid == BLKIO_PROP_weight_device )
828899 seq_printf (m , "%u:%u\t%u\n" , MAJOR (pn -> dev ),
829- MINOR (pn -> dev ), pn -> weight );
900+ MINOR (pn -> dev ), pn -> val .weight );
901+ break ;
902+ case BLKIO_POLICY_THROTL :
903+ if (pn -> fileid == BLKIO_THROTL_read_bps_device )
904+ seq_printf (m , "%u:%u\t%llu\n" , MAJOR (pn -> dev ),
905+ MINOR (pn -> dev ), pn -> val .bps );
906+ else if (pn -> fileid == BLKIO_THROTL_write_bps_device )
907+ seq_printf (m , "%u:%u\t%llu\n" , MAJOR (pn -> dev ),
908+ MINOR (pn -> dev ), pn -> val .bps );
909+ else
910+ BUG ();
830911 break ;
831912 default :
832913 BUG ();
@@ -869,6 +950,16 @@ static int blkiocg_file_read(struct cgroup *cgrp, struct cftype *cft,
869950 BUG ();
870951 }
871952 break ;
953+ case BLKIO_POLICY_THROTL :
954+ switch (name ){
955+ case BLKIO_THROTL_read_bps_device :
956+ case BLKIO_THROTL_write_bps_device :
957+ blkio_read_policy_node_files (cft , blkcg , m );
958+ return 0 ;
959+ default :
960+ BUG ();
961+ }
962+ break ;
872963 default :
873964 BUG ();
874965 }
@@ -959,7 +1050,18 @@ static int blkiocg_file_read_map(struct cgroup *cgrp, struct cftype *cft,
9591050 BUG ();
9601051 }
9611052 break ;
962-
1053+ case BLKIO_POLICY_THROTL :
1054+ switch (name ){
1055+ case BLKIO_THROTL_io_service_bytes :
1056+ return blkio_read_blkg_stats (blkcg , cft , cb ,
1057+ BLKIO_STAT_SERVICE_BYTES , 1 );
1058+ case BLKIO_THROTL_io_serviced :
1059+ return blkio_read_blkg_stats (blkcg , cft , cb ,
1060+ BLKIO_STAT_SERVICED , 1 );
1061+ default :
1062+ BUG ();
1063+ }
1064+ break ;
9631065 default :
9641066 BUG ();
9651067 }
@@ -1052,6 +1154,23 @@ struct cftype blkio_files[] = {
10521154 .read_u64 = blkiocg_file_read_u64 ,
10531155 .write_u64 = blkiocg_file_write_u64 ,
10541156 },
1157+ {
1158+ .name = "throttle.read_bps_device" ,
1159+ .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_THROTL ,
1160+ BLKIO_THROTL_read_bps_device ),
1161+ .read_seq_string = blkiocg_file_read ,
1162+ .write_string = blkiocg_file_write ,
1163+ .max_write_len = 256 ,
1164+ },
1165+
1166+ {
1167+ .name = "throttle.write_bps_device" ,
1168+ .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_THROTL ,
1169+ BLKIO_THROTL_write_bps_device ),
1170+ .read_seq_string = blkiocg_file_read ,
1171+ .write_string = blkiocg_file_write ,
1172+ .max_write_len = 256 ,
1173+ },
10551174 {
10561175 .name = "time" ,
10571176 .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_PROP ,
@@ -1070,12 +1189,24 @@ struct cftype blkio_files[] = {
10701189 BLKIO_PROP_io_service_bytes ),
10711190 .read_map = blkiocg_file_read_map ,
10721191 },
1192+ {
1193+ .name = "throttle.io_service_bytes" ,
1194+ .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_THROTL ,
1195+ BLKIO_THROTL_io_service_bytes ),
1196+ .read_map = blkiocg_file_read_map ,
1197+ },
10731198 {
10741199 .name = "io_serviced" ,
10751200 .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_PROP ,
10761201 BLKIO_PROP_io_serviced ),
10771202 .read_map = blkiocg_file_read_map ,
10781203 },
1204+ {
1205+ .name = "throttle.io_serviced" ,
1206+ .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_THROTL ,
1207+ BLKIO_THROTL_io_serviced ),
1208+ .read_map = blkiocg_file_read_map ,
1209+ },
10791210 {
10801211 .name = "io_service_time" ,
10811212 .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_PROP ,
0 commit comments