Skip to content

Commit d11bb44

Browse files
gaowanlongaxboe
authored andcommitted
blk-cgroup: be able to remove the record of unplugged device
The bug is we're not able to remove the device from blkio cgroup's per-device control files if it gets unplugged. To reproduce the bug: # mount -t cgroup -o blkio xxx /cgroup # cd /cgroup # echo "8:0 1000" > blkio.throttle.read_bps_device # unplug the device # cat blkio.throttle.read_bps_device 8:0 1000 # echo "8:0 0" > blkio.throttle.read_bps_device -bash: echo: write error: No such device After patching, the device removal will succeed. Thanks for the comments of Paul, Zefan, and Vivek. Signed-off-by: Wanlong Gao <[email protected]> Cc: Li Zefan <[email protected]> Cc: Paul Menage <[email protected]> Acked-by: Vivek Goyal <[email protected]> Cc: Jens Axboe <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 8ad6a56 commit d11bb44

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

block/blk-cgroup.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,10 @@ static int blkio_policy_parse_and_set(char *buf,
785785
{
786786
char *s[4], *p, *major_s = NULL, *minor_s = NULL;
787787
int ret;
788-
unsigned long major, minor, temp;
788+
unsigned long major, minor;
789789
int i = 0;
790790
dev_t dev;
791-
u64 bps, iops;
791+
u64 temp;
792792

793793
memset(s, 0, sizeof(s));
794794

@@ -826,20 +826,23 @@ static int blkio_policy_parse_and_set(char *buf,
826826

827827
dev = MKDEV(major, minor);
828828

829-
ret = blkio_check_dev_num(dev);
829+
ret = strict_strtoull(s[1], 10, &temp);
830830
if (ret)
831-
return ret;
831+
return -EINVAL;
832832

833-
newpn->dev = dev;
833+
/* For rule removal, do not check for device presence. */
834+
if (temp) {
835+
ret = blkio_check_dev_num(dev);
836+
if (ret)
837+
return ret;
838+
}
834839

835-
if (s[1] == NULL)
836-
return -EINVAL;
840+
newpn->dev = dev;
837841

838842
switch (plid) {
839843
case BLKIO_POLICY_PROP:
840-
ret = strict_strtoul(s[1], 10, &temp);
841-
if (ret || (temp < BLKIO_WEIGHT_MIN && temp > 0) ||
842-
temp > BLKIO_WEIGHT_MAX)
844+
if ((temp < BLKIO_WEIGHT_MIN && temp > 0) ||
845+
temp > BLKIO_WEIGHT_MAX)
843846
return -EINVAL;
844847

845848
newpn->plid = plid;
@@ -850,26 +853,18 @@ static int blkio_policy_parse_and_set(char *buf,
850853
switch(fileid) {
851854
case BLKIO_THROTL_read_bps_device:
852855
case BLKIO_THROTL_write_bps_device:
853-
ret = strict_strtoull(s[1], 10, &bps);
854-
if (ret)
855-
return -EINVAL;
856-
857856
newpn->plid = plid;
858857
newpn->fileid = fileid;
859-
newpn->val.bps = bps;
858+
newpn->val.bps = temp;
860859
break;
861860
case BLKIO_THROTL_read_iops_device:
862861
case BLKIO_THROTL_write_iops_device:
863-
ret = strict_strtoull(s[1], 10, &iops);
864-
if (ret)
865-
return -EINVAL;
866-
867-
if (iops > THROTL_IOPS_MAX)
862+
if (temp > THROTL_IOPS_MAX)
868863
return -EINVAL;
869864

870865
newpn->plid = plid;
871866
newpn->fileid = fileid;
872-
newpn->val.iops = (unsigned int)iops;
867+
newpn->val.iops = (unsigned int)temp;
873868
break;
874869
}
875870
break;

0 commit comments

Comments
 (0)