rdma: Add batch command support
Subsystems (2)
PATCH 1/1 rdma: Add batch command support
From: Leon Romanovsky <[email protected]>
Implement an option (-b) to execute RDMAtool commands from supplied file. This follows the same model as in use for ip and devlink tools, by expecting every new command to be on new line.
These commands are expected to be without any -* (e.g. -d, -j, e.t.c) global flags, which should be called externally.
--- man/man8/rdma.8 | 16 +++++++++++++ rdma/rdma.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 8 deletions(-)
man/man8/rdma.8 +16 -0
@@ -11,6 +11,12 @@ rdma \- RDMA tool .BR help " }" .sp +.ti -8 +.B rdma +.RB "[ " -force " ] " +.BI "-batch " filename +.sp + .ti -8 .IR OBJECT " := { " .BR dev " | " link " }"
@@ -31,6 +37,16 @@ Print the version of the .B rdma tool and exit. +.TP +.BR "\-b", " \-batch " <FILENAME> +Read commands from provided file or standard input and invoke them. +First failure will cause termination of rdma. + +.TP +.BR "\-force" +Don't terminate rdma on errors in batch mode. +If there were any errors during execution of the commands, the application return code will be non zero. + .TP .BR "\-d" , " --details" Otuput detailed information.
rdma/rdma.c +62 -8
132 lines not on this page · raw message
--
2.16.1
Quoted 21 lines · Leon Romanovsky
rdma/rdma.c +13
-1@@ -36,17 +37,54 @@ static int rd_cmd(struct rd *rd) { 0 } }; + rd->argc = argc; + rd->argv = argv; +return rd_exec_cmd (rd, cmds,"object" ); } -static int rd_init (struct rd *rd,int argc,char **argv,char *filename) +static int rd_batch (struct rd *rd,const char *name,bool force) +{ +char *line =NULL ; +size_t len =0 ; +int ret =0 ; + +if (name &&strcmp (name,"-" ) !=0 ) { +if (!freopen (name,"r" , stdin)) { +pr_err ("Cannot open file \"%s\" for reading: %s\n" , + name,strerror (errno));
rdma/rdma.c static int rd_cmd(struct rd *rd) · line 65
Quoted 10 lines
rdma/rdma.c +10
-0+return errno; + } + } + + cmdlineno =0 ; +while (getcmdline (&line, &len, stdin) !=-1 ) { +char *largv[512 ]; +int largc; + + largc =makeargs (line, largv,100 );
you have largv[512] declared but passing a max of 100. I realize other batch commands have it hardcoded, but ARRAY_SIZE is better.
Quoted 27 lines · David Ahern
Quoted 26 lines · Leon Romanovsky
(quoted diff) +18
-1@@ -36,17 +37,54 @@ static int rd_cmd(struct rd *rd) { 0 } }; + rd->argc = argc; + rd->argv = argv; + return rd_exec_cmd(rd, cmds, "object"); } -static int rd_init(struct rd *rd, int argc, char **argv, char *filename) +static int rd_batch(struct rd *rd, const char *name, bool force) +{ + char *line = NULL; + size_t len = 0; + int ret = 0; + + if (name && strcmp(name, "-") != 0) { + if (!freopen(name, "r", stdin)) { + pr_err("Cannot open file \"%s\" for reading: %s\n", + name, strerror(errno)); + return errno; + } + } + + cmdlineno = 0;
Quoted 8 lines
Review static int rd_cmd(struct rd *rd) · line 65
Quoted 5 lines
(quoted diff) +5
-0+ while (getcmdline(&line, &len, stdin) != -1) { + char *largv[512]; + int largc; + + largc = makeargs(line, largv, 100);you have largv[512] declared but passing a max of 100. I realize other batch commands have it hardcoded, but
ARRAY_SIZEis better.
Thanks for catching it, it was my copy/paste error.
I'll wait for a day for other comments and will resubmit if it is needed.
The fix is:
rdma/rdma.c +1 -1
@@ -62,7 +62,7 @@ static int rd_batch(struct rd *rd, const char *name, bool force)char *largv[512 ];int largc; - largc =makeargs (line, largv,100 ); + largc =makeargs (line, largv,ARRAY_SIZE (largv));if (!largc)continue ;/* blank line */