Skip to content

Commit 135746c

Browse files
Paolo Abenikuba-moo
authored andcommitted
net-sysctl: factor out cpumask parsing helper
Will be used by the following patch to avoid code duplication. No functional changes intended. The only difference is that now flow_limit_cpu_sysctl() will always compute the flow limit mask on each read operation, even when read() will not return any byte to user-space. Note that the new helper is placed under a new #ifdef at the file start to better fit the usage in the later patch Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8697a25 commit 135746c

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

net/core/sysctl_net_core.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);
4545
int sysctl_devconf_inherit_init_net __read_mostly;
4646
EXPORT_SYMBOL(sysctl_devconf_inherit_init_net);
4747

48+
#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT)
49+
static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
50+
struct cpumask *mask)
51+
{
52+
char kbuf[128];
53+
int len;
54+
55+
if (*ppos || !*lenp) {
56+
*lenp = 0;
57+
return;
58+
}
59+
60+
len = min(sizeof(kbuf) - 1, *lenp);
61+
len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
62+
if (!len) {
63+
*lenp = 0;
64+
return;
65+
}
66+
67+
if (len < *lenp)
68+
kbuf[len++] = '\n';
69+
memcpy(buffer, kbuf, len);
70+
*lenp = len;
71+
*ppos += len;
72+
}
73+
#endif
74+
4875
#ifdef CONFIG_RPS
4976
static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
5077
void *buffer, size_t *lenp, loff_t *ppos)
@@ -155,13 +182,6 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
155182
write_unlock:
156183
mutex_unlock(&flow_limit_update_mutex);
157184
} else {
158-
char kbuf[128];
159-
160-
if (*ppos || !*lenp) {
161-
*lenp = 0;
162-
goto done;
163-
}
164-
165185
cpumask_clear(mask);
166186
rcu_read_lock();
167187
for_each_possible_cpu(i) {
@@ -171,17 +191,7 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
171191
}
172192
rcu_read_unlock();
173193

174-
len = min(sizeof(kbuf) - 1, *lenp);
175-
len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
176-
if (!len) {
177-
*lenp = 0;
178-
goto done;
179-
}
180-
if (len < *lenp)
181-
kbuf[len++] = '\n';
182-
memcpy(buffer, kbuf, len);
183-
*lenp = len;
184-
*ppos += len;
194+
dump_cpumask(buffer, lenp, ppos, mask);
185195
}
186196

187197
done:

0 commit comments

Comments
 (0)