diff mbox series

[ndctl,v3,1/2] daxctl: Fail create-device if extra parameters are present

Message ID 20240606035149.1030610-1-lizhijian@fujitsu.com (mailing list archive)
State New
Headers show
Series [ndctl,v3,1/2] daxctl: Fail create-device if extra parameters are present | expand

Commit Message

Zhijian Li (Fujitsu) June 6, 2024, 3:51 a.m. UTC
Previously, an incorrect index(1) for create-device is causing the 1st
extra parameter to be ignored, which is wrong. For example:
$ daxctl create-device region0
[
  {
    "chardev":"dax0.1",
    "size":268435456,
    "target_node":1,
    "align":2097152,
    "mode":"devdax"
  }
]
created 1 device

where above user would want to specify '-r region0'.

Check extra parameters starting from index 0 to ensure no extra parameters
are specified for create-device.

Cc: Fan Ni <fan.ni@samsung.com>
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
---
V3:
  - Fix commit message and move the 'i' setting near the usage # Alison
  - collect reviewed tags, no logical changes.

V2:
Remove the external link[0] in case it get disappeared in the future.
[0] https://github.com/moking/moking.github.io/wiki/cxl%E2%80%90test%E2%80%90tool:-A-tool-to-ease-CXL-test-with-QEMU-setup%E2%80%90%E2%80%90Using-DCD-test-as-an-example#convert-dcd-memory-to-system-ram
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
 daxctl/device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Zhijian Li (Fujitsu) Aug. 22, 2024, 8:28 a.m. UTC | #1
Ping, I think these 2 patches should be included into v80



On 06/06/2024 11:51, Li Zhijian wrote:
> Previously, an incorrect index(1) for create-device is causing the 1st
> extra parameter to be ignored, which is wrong. For example:
> $ daxctl create-device region0
> [
>    {
>      "chardev":"dax0.1",
>      "size":268435456,
>      "target_node":1,
>      "align":2097152,
>      "mode":"devdax"
>    }
> ]
> created 1 device
> 
> where above user would want to specify '-r region0'.
> 
> Check extra parameters starting from index 0 to ensure no extra parameters
> are specified for create-device.
> 
> Cc: Fan Ni <fan.ni@samsung.com>
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> V3:
>    - Fix commit message and move the 'i' setting near the usage # Alison
>    - collect reviewed tags, no logical changes.
> 
> V2:
> Remove the external link[0] in case it get disappeared in the future.
> [0] https://github.com/moking/moking.github.io/wiki/cxl%E2%80%90test%E2%80%90tool:-A-tool-to-ease-CXL-test-with-QEMU-setup%E2%80%90%E2%80%90Using-DCD-test-as-an-example#convert-dcd-memory-to-system-ram
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
>   daxctl/device.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/daxctl/device.c b/daxctl/device.c
> index 839134301409..6ea91eb45315 100644
> --- a/daxctl/device.c
> +++ b/daxctl/device.c
> @@ -402,7 +402,10 @@ static const char *parse_device_options(int argc, const char **argv,
>   			action_string);
>   		rc = -EINVAL;
>   	}
> -	for (i = 1; i < argc; i++) {
> +
> +	/* ACTION_CREATE expects 0 parameters */
> +	i = action == ACTION_CREATE ? 0 : 1;
> +	for (; i < argc; i++) {
>   		fprintf(stderr, "unknown extra parameter \"%s\"\n", argv[i]);
>   		rc = -EINVAL;
>   	}
Alison Schofield Aug. 26, 2024, 8:04 p.m. UTC | #2
On Thu, Aug 22, 2024 at 08:28:17AM +0000, Zhijian Li (Fujitsu) wrote:
> 
> Ping, I think these 2 patches should be included into v80

Thanks for the reminder. I've queued them for v80 here:
https://github.com/pmem/ndctl/tree/pending

--Alison

> 
> 
> 
> On 06/06/2024 11:51, Li Zhijian wrote:
> > Previously, an incorrect index(1) for create-device is causing the 1st
> > extra parameter to be ignored, which is wrong. For example:
> > $ daxctl create-device region0
> > [
> >    {
> >      "chardev":"dax0.1",
> >      "size":268435456,
> >      "target_node":1,
> >      "align":2097152,
> >      "mode":"devdax"
> >    }
> > ]
> > created 1 device
> > 
> > where above user would want to specify '-r region0'.
> > 
> > Check extra parameters starting from index 0 to ensure no extra parameters
> > are specified for create-device.
> > 
> > Cc: Fan Ni <fan.ni@samsung.com>
> > Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> > Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
> > Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> > ---
> > V3:
> >    - Fix commit message and move the 'i' setting near the usage # Alison
> >    - collect reviewed tags, no logical changes.
> > 
> > V2:
> > Remove the external link[0] in case it get disappeared in the future.
> > [0] https://github.com/moking/moking.github.io/wiki/cxl%E2%80%90test%E2%80%90tool:-A-tool-to-ease-CXL-test-with-QEMU-setup%E2%80%90%E2%80%90Using-DCD-test-as-an-example#convert-dcd-memory-to-system-ram
> > Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> > ---
> >   daxctl/device.c | 5 ++++-
> >   1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/daxctl/device.c b/daxctl/device.c
> > index 839134301409..6ea91eb45315 100644
> > --- a/daxctl/device.c
> > +++ b/daxctl/device.c
> > @@ -402,7 +402,10 @@ static const char *parse_device_options(int argc, const char **argv,
> >   			action_string);
> >   		rc = -EINVAL;
> >   	}
> > -	for (i = 1; i < argc; i++) {
> > +
> > +	/* ACTION_CREATE expects 0 parameters */
> > +	i = action == ACTION_CREATE ? 0 : 1;
> > +	for (; i < argc; i++) {
> >   		fprintf(stderr, "unknown extra parameter \"%s\"\n", argv[i]);
> >   		rc = -EINVAL;
> >   	}
diff mbox series

Patch

diff --git a/daxctl/device.c b/daxctl/device.c
index 839134301409..6ea91eb45315 100644
--- a/daxctl/device.c
+++ b/daxctl/device.c
@@ -402,7 +402,10 @@  static const char *parse_device_options(int argc, const char **argv,
 			action_string);
 		rc = -EINVAL;
 	}
-	for (i = 1; i < argc; i++) {
+
+	/* ACTION_CREATE expects 0 parameters */
+	i = action == ACTION_CREATE ? 0 : 1;
+	for (; i < argc; i++) {
 		fprintf(stderr, "unknown extra parameter \"%s\"\n", argv[i]);
 		rc = -EINVAL;
 	}