Skip to content

Commit d3a3a08

Browse files
johnpgarryaxboe
authored andcommitted
blk-throttle: Only use seq_printf() in tg_prfill_limit()
Currently tg_prfill_limit() uses a combination of snprintf() and strcpy() to generate the values parts of the limits string, before passing them as arguments to seq_printf(). Convert to use only a sequence of seq_printf() calls per argument, which is simpler. Suggested-by: Christoph Hellwig <hch@lst.de> Signed-off-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20240327094020.3505514-1-john.g.garry@oracle.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a46c270 commit d3a3a08

1 file changed

Lines changed: 26 additions & 25 deletions

File tree

block/blk-throttle.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,11 +1494,8 @@ static u64 tg_prfill_limit(struct seq_file *sf, struct blkg_policy_data *pd,
14941494
{
14951495
struct throtl_grp *tg = pd_to_tg(pd);
14961496
const char *dname = blkg_dev_name(pd->blkg);
1497-
char bufs[4][21] = { "max", "max", "max", "max" };
14981497
u64 bps_dft;
14991498
unsigned int iops_dft;
1500-
char idle_time[26] = "";
1501-
char latency_time[26] = "";
15021499

15031500
if (!dname)
15041501
return 0;
@@ -1520,35 +1517,39 @@ static u64 tg_prfill_limit(struct seq_file *sf, struct blkg_policy_data *pd,
15201517
tg->latency_target_conf == DFL_LATENCY_TARGET)))
15211518
return 0;
15221519

1523-
if (tg->bps_conf[READ][off] != U64_MAX)
1524-
snprintf(bufs[0], sizeof(bufs[0]), "%llu",
1525-
tg->bps_conf[READ][off]);
1526-
if (tg->bps_conf[WRITE][off] != U64_MAX)
1527-
snprintf(bufs[1], sizeof(bufs[1]), "%llu",
1528-
tg->bps_conf[WRITE][off]);
1529-
if (tg->iops_conf[READ][off] != UINT_MAX)
1530-
snprintf(bufs[2], sizeof(bufs[2]), "%u",
1531-
tg->iops_conf[READ][off]);
1532-
if (tg->iops_conf[WRITE][off] != UINT_MAX)
1533-
snprintf(bufs[3], sizeof(bufs[3]), "%u",
1534-
tg->iops_conf[WRITE][off]);
1520+
seq_printf(sf, "%s", dname);
1521+
if (tg->bps_conf[READ][off] == U64_MAX)
1522+
seq_printf(sf, " rbps=max");
1523+
else
1524+
seq_printf(sf, " rbps=%llu", tg->bps_conf[READ][off]);
1525+
1526+
if (tg->bps_conf[WRITE][off] == U64_MAX)
1527+
seq_printf(sf, " wbps=max");
1528+
else
1529+
seq_printf(sf, " wbps=%llu", tg->bps_conf[WRITE][off]);
1530+
1531+
if (tg->iops_conf[READ][off] == UINT_MAX)
1532+
seq_printf(sf, " riops=max");
1533+
else
1534+
seq_printf(sf, " riops=%u", tg->iops_conf[READ][off]);
1535+
1536+
if (tg->iops_conf[WRITE][off] == UINT_MAX)
1537+
seq_printf(sf, " wiops=max");
1538+
else
1539+
seq_printf(sf, " wiops=%u", tg->iops_conf[WRITE][off]);
1540+
15351541
if (off == LIMIT_LOW) {
15361542
if (tg->idletime_threshold_conf == ULONG_MAX)
1537-
strcpy(idle_time, " idle=max");
1543+
seq_printf(sf, " idle=max");
15381544
else
1539-
snprintf(idle_time, sizeof(idle_time), " idle=%lu",
1540-
tg->idletime_threshold_conf);
1545+
seq_printf(sf, " idle=%lu", tg->idletime_threshold_conf);
15411546

15421547
if (tg->latency_target_conf == ULONG_MAX)
1543-
strcpy(latency_time, " latency=max");
1548+
seq_printf(sf, " latency=max");
15441549
else
1545-
snprintf(latency_time, sizeof(latency_time),
1546-
" latency=%lu", tg->latency_target_conf);
1550+
seq_printf(sf, " latency=%lu", tg->latency_target_conf);
15471551
}
1548-
1549-
seq_printf(sf, "%s rbps=%s wbps=%s riops=%s wiops=%s%s%s\n",
1550-
dname, bufs[0], bufs[1], bufs[2], bufs[3], idle_time,
1551-
latency_time);
1552+
seq_printf(sf, "\n");
15521553
return 0;
15531554
}
15541555

0 commit comments

Comments
 (0)