Commit a44a9620 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

util: allow commas in spdk_cpuset_parse()



Linux sysfs entries that contain cpumasks will use comma delimiters
every 8 hex characters for readability purposes. So allow commas
in the spdk_cpuset_parse() input strings so that it can be used
directly with such sysfs strings.

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: Ie8bffa8229a19567f72c77d5cb771763f026d149
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23405


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 23b5ae4c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -143,6 +143,8 @@ const char *spdk_cpuset_fmt(struct spdk_cpuset *set);
 * \param set CPU set.
 * \param mask String defining CPU set. By default hexadecimal value is used or
 * as CPU list enclosed in square brackets defined as: 'c1[-c2][,c3[-c4],...]'.
 * When hexadecimal value is passed, any commas will be ignored, to allow using
 * this function with masks generated by Linux kernel in sysfs.
 *
 * \return zero if success, non zero if fails.
 */
+4 −0
Original line number Diff line number Diff line
@@ -259,6 +259,10 @@ parse_mask(const char *mask, struct spdk_cpuset *set, size_t len)
	spdk_cpuset_zero(set);
	for (i = len - 1; i >= 0; i--) {
		c = mask[i];
		if (c == ',') {
			/* Linux puts comma delimiters in its cpumasks, just skip them. */
			continue;
		}
		val = hex_value(c);
		if (val < 0) {
			/* Invalid character */
+21 −0
Original line number Diff line number Diff line
@@ -161,6 +161,27 @@ test_cpuset_parse(void)
	CU_ASSERT(cpuset_check_range(core_mask, 168, 171, true) == 0);
	CU_ASSERT(cpuset_check_range(core_mask, 172, SPDK_CPUSET_SIZE - 1, false) == 0);

	/* Test masks with commas. The commas should be ignored by cpuset, to
	 * allow using spdk_cpuset_parse() with Linux kernel sysfs strings
	 * that insert commas for readability purposes.
	 */
	rc = spdk_cpuset_parse(core_mask, "FF,FF0000FF,00000000");
	CU_ASSERT(rc == 0);
	CU_ASSERT(cpuset_check_range(core_mask, 0, 31, false) == 0);
	CU_ASSERT(cpuset_check_range(core_mask, 32, 39, true) == 0);
	CU_ASSERT(cpuset_check_range(core_mask, 40, 55, false) == 0);
	CU_ASSERT(cpuset_check_range(core_mask, 56, 71, true) == 0);
	CU_ASSERT(cpuset_check_range(core_mask, 72, SPDK_CPUSET_SIZE - 1, false) == 0);

	/* Test masks with random commas. We just ignore the commas, cpuset
	 * should not try to validate that commas are only in certain positions.
	 */
	rc = spdk_cpuset_parse(core_mask, ",,,,,000,,1,0,0,,,,");
	CU_ASSERT(rc == 0);
	CU_ASSERT(cpuset_check_range(core_mask, 0, 7, false) == 0);
	CU_ASSERT(cpuset_check_range(core_mask, 8, 8, true) == 0);
	CU_ASSERT(cpuset_check_range(core_mask, 9, SPDK_CPUSET_SIZE - 1, false) == 0);

	spdk_cpuset_free(core_mask);
}