Re: [ndctl PATCH v3 1/4] libndctl: test enablement for non-nfit devices

2021-03-18 Thread Santosh Sivaraj
"Verma, Vishal L"  writes:

Hi Vishal,

> On Thu, 2021-03-11 at 13:16 +0530, Santosh Sivaraj wrote:
>> Unify adding dimms for papr and nfit families, this will help in adding
>
> Minor nit, but it seems like the subject line and the first sentence in
> the body should be swapped. The one-line description of what's happening
> in this patch is "Unify adding dimms for papr and nfit families", and
> the body can go into more detail about why - i.e. in preparation for
> enabling tests on non-nfit devices.
>

Agree.

>> all attributes needed for the unit tests too. We don't fail adding a dimm
>> if some of the dimm attributes are missing, so this will work fine on PAPR
>> platforms where most dimm attributes are provided.
>
> Does this mean 'most - but not all'? Might be a good clarification to
> make here.

Yes, that's right. I will fix that up in the next version.

Thanks,
Santosh
>
>> 
>> Signed-off-by: Santosh Sivaraj 
>> ---
>>  ndctl/lib/libndctl.c | 103 ---
>>  1 file changed, 38 insertions(+), 65 deletions(-)
>> 
>> v3:
>> * Drop patch which skips SMART tests, smart test enablement will be posted
>>   soon.
>> 
>> v2:
>> * Patch 2: Fix a bug, I skip erroring out if PAPR family, but condition had
>>   INTEL family instead. That change was there to test the same code on x86, 
>> but
>>   accidently committed. Now have a environment variable to force test PAPR
>>   family on x86.
>> 
>> * Patch 4: Remove stray code, artifact of refactoring in patch 1.
>> 
>> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
>> index 36fb6fe..26b9317 100644
>> --- a/ndctl/lib/libndctl.c
>> +++ b/ndctl/lib/libndctl.c
>> @@ -1646,41 +1646,9 @@ static int ndctl_bind(struct ndctl_ctx *ctx, struct 
>> kmod_module *module,
>>  static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath);
>>  static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char 
>> *alias);
>>  
>> -static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
>> -{
>> -int rc = -ENODEV;
>> -char buf[SYSFS_ATTR_SIZE];
>> -struct ndctl_ctx *ctx = dimm->bus->ctx;
>> -char *path = calloc(1, strlen(dimm_base) + 100);
>> -const char * const devname = ndctl_dimm_get_devname(dimm);
>> -
>> -dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
>> -
>> -if (!path)
>> -return -ENOMEM;
>> -
>> -/* construct path to the papr compatible dimm flags file */
>> -sprintf(path, "%s/papr/flags", dimm_base);
>> -
>> -if (ndctl_bus_is_papr_scm(dimm->bus) &&
>> -sysfs_read_attr(ctx, path, buf) == 0) {
>> -
>> -dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, 
>> buf);
>> -dimm->cmd_family = NVDIMM_FAMILY_PAPR;
>> -
>> -/* Parse dimm flags */
>> -parse_papr_flags(dimm, buf);
>> -
>> -/* Allocate monitor mode fd */
>> -dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
>> -rc = 0;
>> -}
>> -
>> -free(path);
>> -return rc;
>> -}
>> -
>> -static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
>> +static int populate_dimm_attributes(struct ndctl_dimm *dimm,
>> +const char *dimm_base,
>> +const char *bus_prefix)
>>  {
>>  int i, rc = -1;
>>  char buf[SYSFS_ATTR_SIZE];
>> @@ -1694,7 +1662,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, 
>> const char *dimm_base)
>>   * 'unique_id' may not be available on older kernels, so don't
>>   * fail if the read fails.
>>   */
>> -sprintf(path, "%s/nfit/id", dimm_base);
>> +sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
>>  if (sysfs_read_attr(ctx, path, buf) == 0) {
>>  unsigned int b[9];
>> 
>> @@ -1709,68 +1677,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, 
>> const char *dimm_base)
>>  }
>>  }
>> 
>> -sprintf(path, "%s/nfit/handle", dimm_base);
>> +sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
>>  if (sysfs_read_attr(ctx, path, buf) < 0)
>>  goto err_read;
>>  dimm->handle = strtoul(buf, NULL, 0);
>>  
>> -sprintf(path, "%s/nfit/phys_id", dimm_base);
>> +sprintf(path, "%s/%s/phys_id", dimm_base, bus_prefix);
>>  if (sysfs_read_attr(ctx, path, buf) < 0)
>>  goto err_read;
>>  dimm->phys_id = strtoul(buf, NULL, 0);
>>  
>> -sprintf(path, "%s/nfit/serial", dimm_base);
>> +sprintf(path, "%s/%s/serial", dimm_base, bus_prefix);
>>  if (sysfs_read_attr(ctx, path, buf) == 0)
>>  dimm->serial = strtoul(buf, NULL, 0);
>>  
>> -sprintf(path, "%s/nfit/vendor", dimm_base);
>> +sprintf(path, "%s/%s/vendor", dimm_base, bus_prefix);
>>  if (sysfs_read_attr(ctx, path, buf) == 0)
>>  dimm->vendor_id = strtoul(buf, NULL, 0);
>>  
>> -sprintf(path, "%s/nfit/device", dimm_base);
>> +sprintf(path, "%s/%s/device", dimm_base, 

Re: [ndctl PATCH v3 1/4] libndctl: test enablement for non-nfit devices

2021-03-17 Thread Verma, Vishal L
On Thu, 2021-03-11 at 13:16 +0530, Santosh Sivaraj wrote:
> Unify adding dimms for papr and nfit families, this will help in adding

Minor nit, but it seems like the subject line and the first sentence in
the body should be swapped. The one-line description of what's happening
in this patch is "Unify adding dimms for papr and nfit families", and
the body can go into more detail about why - i.e. in preparation for
enabling tests on non-nfit devices.

> all attributes needed for the unit tests too. We don't fail adding a dimm
> if some of the dimm attributes are missing, so this will work fine on PAPR
> platforms where most dimm attributes are provided.

Does this mean 'most - but not all'? Might be a good clarification to
make here.

> 
> Signed-off-by: Santosh Sivaraj 
> ---
>  ndctl/lib/libndctl.c | 103 ---
>  1 file changed, 38 insertions(+), 65 deletions(-)
> 
> v3:
> * Drop patch which skips SMART tests, smart test enablement will be posted
>   soon.
> 
> v2:
> * Patch 2: Fix a bug, I skip erroring out if PAPR family, but condition had
>   INTEL family instead. That change was there to test the same code on x86, 
> but
>   accidently committed. Now have a environment variable to force test PAPR
>   family on x86.
> 
> * Patch 4: Remove stray code, artifact of refactoring in patch 1.
> 
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index 36fb6fe..26b9317 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -1646,41 +1646,9 @@ static int ndctl_bind(struct ndctl_ctx *ctx, struct 
> kmod_module *module,
>  static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath);
>  static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char 
> *alias);
>  
> -static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
> -{
> - int rc = -ENODEV;
> - char buf[SYSFS_ATTR_SIZE];
> - struct ndctl_ctx *ctx = dimm->bus->ctx;
> - char *path = calloc(1, strlen(dimm_base) + 100);
> - const char * const devname = ndctl_dimm_get_devname(dimm);
> -
> - dbg(ctx, "%s: Probing of_pmem dimm at %s\n", devname, dimm_base);
> -
> - if (!path)
> - return -ENOMEM;
> -
> - /* construct path to the papr compatible dimm flags file */
> - sprintf(path, "%s/papr/flags", dimm_base);
> -
> - if (ndctl_bus_is_papr_scm(dimm->bus) &&
> - sysfs_read_attr(ctx, path, buf) == 0) {
> -
> - dbg(ctx, "%s: Adding papr-scm dimm flags:\"%s\"\n", devname, 
> buf);
> - dimm->cmd_family = NVDIMM_FAMILY_PAPR;
> -
> - /* Parse dimm flags */
> - parse_papr_flags(dimm, buf);
> -
> - /* Allocate monitor mode fd */
> - dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
> - rc = 0;
> - }
> -
> - free(path);
> - return rc;
> -}
> -
> -static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
> +static int populate_dimm_attributes(struct ndctl_dimm *dimm,
> + const char *dimm_base,
> + const char *bus_prefix)
>  {
>   int i, rc = -1;
>   char buf[SYSFS_ATTR_SIZE];
> @@ -1694,7 +1662,7 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const 
> char *dimm_base)
>    * 'unique_id' may not be available on older kernels, so don't
>    * fail if the read fails.
>    */
> - sprintf(path, "%s/nfit/id", dimm_base);
> + sprintf(path, "%s/%s/id", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) == 0) {
>   unsigned int b[9];
> 
> @@ -1709,68 +1677,74 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, 
> const char *dimm_base)
>   }
>   }
> 
> - sprintf(path, "%s/nfit/handle", dimm_base);
> + sprintf(path, "%s/%s/handle", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) < 0)
>   goto err_read;
>   dimm->handle = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/phys_id", dimm_base);
> + sprintf(path, "%s/%s/phys_id", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) < 0)
>   goto err_read;
>   dimm->phys_id = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/serial", dimm_base);
> + sprintf(path, "%s/%s/serial", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) == 0)
>   dimm->serial = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/vendor", dimm_base);
> + sprintf(path, "%s/%s/vendor", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) == 0)
>   dimm->vendor_id = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/device", dimm_base);
> + sprintf(path, "%s/%s/device", dimm_base, bus_prefix);
>   if (sysfs_read_attr(ctx, path, buf) == 0)
>   dimm->device_id = strtoul(buf, NULL, 0);
>  
> - sprintf(path, "%s/nfit/rev_id", dimm_base);
> + sprintf(path,