@@ -149,6 +149,27 @@ static inline void blkio_update_group_bps(struct blkio_group *blkg, u64 bps,
149149 }
150150}
151151
152+ static inline void blkio_update_group_iops (struct blkio_group * blkg ,
153+ unsigned int iops , int fileid )
154+ {
155+ struct blkio_policy_type * blkiop ;
156+
157+ list_for_each_entry (blkiop , & blkio_list , list ) {
158+
159+ /* If this policy does not own the blkg, do not send updates */
160+ if (blkiop -> plid != blkg -> plid )
161+ continue ;
162+
163+ if (fileid == BLKIO_THROTL_read_iops_device
164+ && blkiop -> ops .blkio_update_group_read_iops_fn )
165+ blkiop -> ops .blkio_update_group_read_iops_fn (blkg , iops );
166+
167+ if (fileid == BLKIO_THROTL_write_iops_device
168+ && blkiop -> ops .blkio_update_group_write_iops_fn )
169+ blkiop -> ops .blkio_update_group_write_iops_fn (blkg ,iops );
170+ }
171+ }
172+
152173/*
153174 * Add to the appropriate stat variable depending on the request type.
154175 * This should be called with the blkg->stats_lock held.
@@ -630,7 +651,7 @@ static int blkio_policy_parse_and_set(char *buf,
630651{
631652 char * s [4 ], * p , * major_s = NULL , * minor_s = NULL ;
632653 int ret ;
633- unsigned long major , minor , temp ;
654+ unsigned long major , minor , temp , iops ;
634655 int i = 0 ;
635656 dev_t dev ;
636657 u64 bps ;
@@ -692,13 +713,28 @@ static int blkio_policy_parse_and_set(char *buf,
692713 newpn -> val .weight = temp ;
693714 break ;
694715 case BLKIO_POLICY_THROTL :
695- ret = strict_strtoull (s [1 ], 10 , & bps );
696- if (ret )
697- return - EINVAL ;
716+ switch (fileid ) {
717+ case BLKIO_THROTL_read_bps_device :
718+ case BLKIO_THROTL_write_bps_device :
719+ ret = strict_strtoull (s [1 ], 10 , & bps );
720+ if (ret )
721+ return - EINVAL ;
698722
699- newpn -> plid = plid ;
700- newpn -> fileid = fileid ;
701- newpn -> val .bps = bps ;
723+ newpn -> plid = plid ;
724+ newpn -> fileid = fileid ;
725+ newpn -> val .bps = bps ;
726+ break ;
727+ case BLKIO_THROTL_read_iops_device :
728+ case BLKIO_THROTL_write_iops_device :
729+ ret = strict_strtoul (s [1 ], 10 , & iops );
730+ if (ret )
731+ return - EINVAL ;
732+
733+ newpn -> plid = plid ;
734+ newpn -> fileid = fileid ;
735+ newpn -> val .iops = iops ;
736+ break ;
737+ }
702738 break ;
703739 default :
704740 BUG ();
@@ -744,6 +780,29 @@ uint64_t blkcg_get_write_bps(struct blkio_cgroup *blkcg, dev_t dev)
744780 return -1 ;
745781}
746782
783+ unsigned int blkcg_get_read_iops (struct blkio_cgroup * blkcg , dev_t dev )
784+ {
785+ struct blkio_policy_node * pn ;
786+
787+ pn = blkio_policy_search_node (blkcg , dev , BLKIO_POLICY_THROTL ,
788+ BLKIO_THROTL_read_iops_device );
789+ if (pn )
790+ return pn -> val .iops ;
791+ else
792+ return -1 ;
793+ }
794+
795+ unsigned int blkcg_get_write_iops (struct blkio_cgroup * blkcg , dev_t dev )
796+ {
797+ struct blkio_policy_node * pn ;
798+ pn = blkio_policy_search_node (blkcg , dev , BLKIO_POLICY_THROTL ,
799+ BLKIO_THROTL_write_iops_device );
800+ if (pn )
801+ return pn -> val .iops ;
802+ else
803+ return -1 ;
804+ }
805+
747806/* Checks whether user asked for deleting a policy rule */
748807static bool blkio_delete_rule_command (struct blkio_policy_node * pn )
749808{
@@ -753,8 +812,17 @@ static bool blkio_delete_rule_command(struct blkio_policy_node *pn)
753812 return 1 ;
754813 break ;
755814 case BLKIO_POLICY_THROTL :
756- if (pn -> val .bps == 0 )
757- return 1 ;
815+ switch (pn -> fileid ) {
816+ case BLKIO_THROTL_read_bps_device :
817+ case BLKIO_THROTL_write_bps_device :
818+ if (pn -> val .bps == 0 )
819+ return 1 ;
820+ break ;
821+ case BLKIO_THROTL_read_iops_device :
822+ case BLKIO_THROTL_write_iops_device :
823+ if (pn -> val .iops == 0 )
824+ return 1 ;
825+ }
758826 break ;
759827 default :
760828 BUG ();
@@ -771,7 +839,15 @@ static void blkio_update_policy_rule(struct blkio_policy_node *oldpn,
771839 oldpn -> val .weight = newpn -> val .weight ;
772840 break ;
773841 case BLKIO_POLICY_THROTL :
774- oldpn -> val .bps = newpn -> val .bps ;
842+ switch (newpn -> fileid ) {
843+ case BLKIO_THROTL_read_bps_device :
844+ case BLKIO_THROTL_write_bps_device :
845+ oldpn -> val .bps = newpn -> val .bps ;
846+ break ;
847+ case BLKIO_THROTL_read_iops_device :
848+ case BLKIO_THROTL_write_iops_device :
849+ oldpn -> val .iops = newpn -> val .iops ;
850+ }
775851 break ;
776852 default :
777853 BUG ();
@@ -785,7 +861,7 @@ static void blkio_update_policy_rule(struct blkio_policy_node *oldpn,
785861static void blkio_update_blkg_policy (struct blkio_cgroup * blkcg ,
786862 struct blkio_group * blkg , struct blkio_policy_node * pn )
787863{
788- unsigned int weight ;
864+ unsigned int weight , iops ;
789865 u64 bps ;
790866
791867 switch (pn -> plid ) {
@@ -801,6 +877,11 @@ static void blkio_update_blkg_policy(struct blkio_cgroup *blkcg,
801877 bps = pn -> val .bps ? pn -> val .bps : (-1 );
802878 blkio_update_group_bps (blkg , bps , pn -> fileid );
803879 break ;
880+ case BLKIO_THROTL_read_iops_device :
881+ case BLKIO_THROTL_write_iops_device :
882+ iops = pn -> val .iops ? pn -> val .iops : (-1 );
883+ blkio_update_group_iops (blkg , iops , pn -> fileid );
884+ break ;
804885 }
805886 break ;
806887 default :
@@ -900,14 +981,18 @@ blkio_print_policy_node(struct seq_file *m, struct blkio_policy_node *pn)
900981 MINOR (pn -> dev ), pn -> val .weight );
901982 break ;
902983 case BLKIO_POLICY_THROTL :
903- if (pn -> fileid == BLKIO_THROTL_read_bps_device )
984+ switch (pn -> fileid ) {
985+ case BLKIO_THROTL_read_bps_device :
986+ case BLKIO_THROTL_write_bps_device :
904987 seq_printf (m , "%u:%u\t%llu\n" , MAJOR (pn -> dev ),
905988 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 ();
989+ break ;
990+ case BLKIO_THROTL_read_iops_device :
991+ case BLKIO_THROTL_write_iops_device :
992+ seq_printf (m , "%u:%u\t%u\n" , MAJOR (pn -> dev ),
993+ MINOR (pn -> dev ), pn -> val .iops );
994+ break ;
995+ }
911996 break ;
912997 default :
913998 BUG ();
@@ -954,6 +1039,8 @@ static int blkiocg_file_read(struct cgroup *cgrp, struct cftype *cft,
9541039 switch (name ){
9551040 case BLKIO_THROTL_read_bps_device :
9561041 case BLKIO_THROTL_write_bps_device :
1042+ case BLKIO_THROTL_read_iops_device :
1043+ case BLKIO_THROTL_write_iops_device :
9571044 blkio_read_policy_node_files (cft , blkcg , m );
9581045 return 0 ;
9591046 default :
@@ -1171,6 +1258,24 @@ struct cftype blkio_files[] = {
11711258 .write_string = blkiocg_file_write ,
11721259 .max_write_len = 256 ,
11731260 },
1261+
1262+ {
1263+ .name = "throttle.read_iops_device" ,
1264+ .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_THROTL ,
1265+ BLKIO_THROTL_read_iops_device ),
1266+ .read_seq_string = blkiocg_file_read ,
1267+ .write_string = blkiocg_file_write ,
1268+ .max_write_len = 256 ,
1269+ },
1270+
1271+ {
1272+ .name = "throttle.write_iops_device" ,
1273+ .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_THROTL ,
1274+ BLKIO_THROTL_write_iops_device ),
1275+ .read_seq_string = blkiocg_file_read ,
1276+ .write_string = blkiocg_file_write ,
1277+ .max_write_len = 256 ,
1278+ },
11741279 {
11751280 .name = "time" ,
11761281 .private = BLKIOFILE_PRIVATE (BLKIO_POLICY_PROP ,
0 commit comments