cpuset: add option to allow cpulist_parse() to fail
This is a preparation patch for chcpu. If a cpu should be added to a cpu_set where the cpu doesn't fit into the cpu_set this got silently ignored. Since the cpu-list is user space provided it should be checked if cpus are specified that are completely out of range of the system. In order to do that add a parameter which specifies if cpulist_parse() should fail if it parses a cpu-list with "impossible" cpus. The current callers have been converted so they behave like before. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
This commit is contained in:
parent
344f73442d
commit
b16f615afb
|
@ -67,7 +67,7 @@ extern cpu_set_t *cpuset_alloc(int ncpus, size_t *setsize, size_t *nbits);
|
|||
extern void cpuset_free(cpu_set_t *set);
|
||||
|
||||
extern char *cpulist_create(char *str, size_t len, cpu_set_t *set, size_t setsize);
|
||||
extern int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize);
|
||||
extern int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail);
|
||||
|
||||
extern char *cpumask_create(char *str, size_t len, cpu_set_t *set, size_t setsize);
|
||||
extern int cpumask_parse(const char *str, cpu_set_t *set, size_t setsize);
|
||||
|
|
|
@ -264,8 +264,9 @@ int cpumask_parse(const char *str, cpu_set_t *set, size_t setsize)
|
|||
/*
|
||||
* Parses string with CPUs mask.
|
||||
*/
|
||||
int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize)
|
||||
int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail)
|
||||
{
|
||||
size_t max = cpuset_nbits(setsize);
|
||||
const char *p, *q;
|
||||
q = str;
|
||||
|
||||
|
@ -297,6 +298,8 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize)
|
|||
if (!(a <= b))
|
||||
return 1;
|
||||
while (a <= b) {
|
||||
if (fail && (a >= max))
|
||||
return 1;
|
||||
CPU_SET_S(a, setsize, set);
|
||||
a += s;
|
||||
}
|
||||
|
@ -359,7 +362,7 @@ int main(int argc, char *argv[])
|
|||
if (mask)
|
||||
rc = cpumask_parse(mask, set, setsize);
|
||||
else
|
||||
rc = cpulist_parse(range, set, setsize);
|
||||
rc = cpulist_parse(range, set, setsize, 0);
|
||||
|
||||
if (rc)
|
||||
errx(EXIT_FAILURE, "failed to parse string: %s", mask ? : range);
|
||||
|
|
|
@ -208,7 +208,7 @@ int main(int argc, char **argv)
|
|||
ts.get_only = 1;
|
||||
|
||||
else if (ts.use_list) {
|
||||
if (cpulist_parse(argv[optind], new_set, new_setsize))
|
||||
if (cpulist_parse(argv[optind], new_set, new_setsize, 0))
|
||||
errx(EXIT_FAILURE, _("failed to parse CPU list: %s"),
|
||||
argv[optind]);
|
||||
} else if (cpumask_parse(argv[optind], new_set, new_setsize)) {
|
||||
|
|
|
@ -304,7 +304,7 @@ path_cpuparse(int islist, const char *path, va_list ap)
|
|||
err(EXIT_FAILURE, _("failed to callocate cpu set"));
|
||||
|
||||
if (islist) {
|
||||
if (cpulist_parse(buf, set, setsize))
|
||||
if (cpulist_parse(buf, set, setsize, 0))
|
||||
errx(EXIT_FAILURE, _("failed to parse CPU list %s"), buf);
|
||||
} else {
|
||||
if (cpumask_parse(buf, set, setsize))
|
||||
|
|
Loading…
Reference in New Issue