diff mbox

[ndctl] ndctl: fail NUMA filtering when unsupported

Message ID 20180309233416.13243-1-ross.zwisler@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ross Zwisler March 9, 2018, 11:34 p.m. UTC
For systems that don't support NUMA, numactl gives a loud and fatal error:

  # numactl -N 0 ls
  numactl: This system does not support NUMA policy

Follow this model in ndctl for NUMA based filtering:

  # ./ndctl/ndctl list --numa-node=0
    Error: This system does not support NUMA

This is done instead of just quietly filtering out all dimms, regions and
namespaces because the NUMA node they were trying to match didn't exist in
the system.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
---
 util/filter.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Verma, Vishal L March 9, 2018, 11:47 p.m. UTC | #1
On Fri, 2018-03-09 at 16:34 -0700, Ross Zwisler wrote:
> For systems that don't support NUMA, numactl gives a loud and fatal
> error:
> 
>   # numactl -N 0 ls
>   numactl: This system does not support NUMA policy
> 
> Follow this model in ndctl for NUMA based filtering:
> 
>   # ./ndctl/ndctl list --numa-node=0
>     Error: This system does not support NUMA
> 
> This is done instead of just quietly filtering out all dimms, regions
> and
> namespaces because the NUMA node they were trying to match didn't
> exist in
> the system.
> 
> Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  util/filter.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/util/filter.c b/util/filter.c
> index 291d7ed..fdc46a3 100644
> --- a/util/filter.c
> +++ b/util/filter.c
> @@ -14,7 +14,10 @@
>  #include <string.h>
>  #include <stdlib.h>
>  #include <limits.h>
> +#include <unistd.h>
> +#include <sys/stat.h>
>  #include <util/util.h>
> +#include <sys/types.h>
>  #include <ndctl/ndctl.h>
>  #include <util/filter.h>
>  #include <ndctl/libndctl.h>
> @@ -328,6 +331,13 @@ int util_filter_walk(struct ndctl_ctx *ctx,
> struct util_filter_ctx *fctx,
>  	}
>  
>  	if (param->numa_node && strcmp(param->numa_node, "all") !=
> 0) {
> +		struct stat st;
> +
> +		if (stat("/sys/devices/system/node", &st)) {
> +			error("This system does not support
> NUMA\n");
> +			return -EINVAL;
> +		}

Is it ok to just directly read sysfs here? Alternatively we could use
the get_mempolicy syscall (like libnuma does) but that requires linking
with -lnuma..

https://github.com/numactl/numactl/blob/master/libnuma.c#L800

> +
>  		numa_node = strtol(param->numa_node, &end, 0);
>  		if (end == param->numa_node || end[0]) {
>  			error("invalid numa_node: '%s'\n", param-
> >numa_node);
Dan Williams March 10, 2018, 12:20 a.m. UTC | #2
On Fri, Mar 9, 2018 at 3:47 PM, Verma, Vishal L
<vishal.l.verma@intel.com> wrote:
>
> On Fri, 2018-03-09 at 16:34 -0700, Ross Zwisler wrote:
>> For systems that don't support NUMA, numactl gives a loud and fatal
>> error:
>>
>>   # numactl -N 0 ls
>>   numactl: This system does not support NUMA policy
>>
>> Follow this model in ndctl for NUMA based filtering:
>>
>>   # ./ndctl/ndctl list --numa-node=0
>>     Error: This system does not support NUMA
>>
>> This is done instead of just quietly filtering out all dimms, regions
>> and
>> namespaces because the NUMA node they were trying to match didn't
>> exist in
>> the system.
>>
>> Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
>> Suggested-by: Dan Williams <dan.j.williams@intel.com>
>> ---
>>  util/filter.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/util/filter.c b/util/filter.c
>> index 291d7ed..fdc46a3 100644
>> --- a/util/filter.c
>> +++ b/util/filter.c
>> @@ -14,7 +14,10 @@
>>  #include <string.h>
>>  #include <stdlib.h>
>>  #include <limits.h>
>> +#include <unistd.h>
>> +#include <sys/stat.h>
>>  #include <util/util.h>
>> +#include <sys/types.h>
>>  #include <ndctl/ndctl.h>
>>  #include <util/filter.h>
>>  #include <ndctl/libndctl.h>
>> @@ -328,6 +331,13 @@ int util_filter_walk(struct ndctl_ctx *ctx,
>> struct util_filter_ctx *fctx,
>>       }
>>
>>       if (param->numa_node && strcmp(param->numa_node, "all") !=
>> 0) {
>> +             struct stat st;
>> +
>> +             if (stat("/sys/devices/system/node", &st)) {
>> +                     error("This system does not support
>> NUMA\n");
>> +                     return -EINVAL;
>> +             }
>
> Is it ok to just directly read sysfs here? Alternatively we could use
> the get_mempolicy syscall (like libnuma does) but that requires linking
> with -lnuma..
>
> https://github.com/numactl/numactl/blob/master/libnuma.c#L800

I don't mind linking against libnuma if the goal is to mimic the
behavior of numactl.
diff mbox

Patch

diff --git a/util/filter.c b/util/filter.c
index 291d7ed..fdc46a3 100644
--- a/util/filter.c
+++ b/util/filter.c
@@ -14,7 +14,10 @@ 
 #include <string.h>
 #include <stdlib.h>
 #include <limits.h>
+#include <unistd.h>
+#include <sys/stat.h>
 #include <util/util.h>
+#include <sys/types.h>
 #include <ndctl/ndctl.h>
 #include <util/filter.h>
 #include <ndctl/libndctl.h>
@@ -328,6 +331,13 @@  int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx,
 	}
 
 	if (param->numa_node && strcmp(param->numa_node, "all") != 0) {
+		struct stat st;
+
+		if (stat("/sys/devices/system/node", &st)) {
+			error("This system does not support NUMA\n");
+			return -EINVAL;
+		}
+
 		numa_node = strtol(param->numa_node, &end, 0);
 		if (end == param->numa_node || end[0]) {
 			error("invalid numa_node: '%s'\n", param->numa_node);