nfs-utils: config value setting
Subsystems (2)
cover nfs-utils: config value setting
As part of my ongoing efforts to improve storage management integration with NFS I offer this support for setting configuration file values.
This code only updates a single config entry at a time, it attempts to preserve the existing structure and style of the comments file, and takes every precaution that the replacement file is written before using rename(2) to replace the original.
The cli nfsconf tool is also updated to be the first consumer of this functionality.
PATCH 1/5 nfs-utils: Ignore empty lines in config
The test for empty lines didn't ignore whitespace properly
--- support/nfs/conffile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
support/nfs/conffile.c +4 -4
@@ -255,14 +255,14 @@ conf_parse_line(int trans, char *line, const char *filename, int lineno, char **char *inc_section =NULL , *inc_subsection =NULL ;char *relpath, *subconf; +/* Strip off any leading blanks */ +while (isspace (*line)) + line++; +/* Ignore blank lines */ if (*line =='\0' )return ; -/* Strip off any leading blanks */ -while (isblank (*line)) - line++; -/* Lines starting with '#' or ';' are comments. */ if (*line =='#' || *line ==';' )return ;
Signature · 1 line
1.8.3.1
PATCH 2/5 nfs-utils: Fix comparison check for subsection headers
In reply to Justin MitchellWhen comparing two config section headers it incorrectly handled matching section names where only one had a subsection value
--- support/nfs/conffile.c | 2 ++ 1 file changed, 2 insertions(+)
support/nfs/conffile.c +2 -0
@@ -727,6 +727,8 @@ retry:continue ;if (arg && (cb->arg ==NULL ||strcasecmp (arg, cb->arg) !=0 ))continue ; +if (!arg && cb->arg) +continue ;if (strcasecmp (tag, cb->tag) !=0 )continue ;if (cb->value[0 ] =='$' ) {
Signature · 1 line
1.8.3.1
PATCH 3/5 nfs-utils: swap xlog_err for less fatal version
In reply to Justin MitchellUse of xlog_err is immediately fatal, switch to using xlog(L_ERROR, ...) instead so that the error handling and cleanup mechanisms can operate properly
--- support/nfs/conffile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
support/nfs/conffile.c +1 -1
@@ -495,7 +495,7 @@ conf_readfile(const char *path) {struct stat sb;if (!path) { -xlog_err ("conf_readfile: no path given" ); +xlog (L_ERROR ,"conf_readfile: no path given" );return NULL ; }
Signature · 1 line
1.8.3.1
PATCH 4/5 nfs-utils: Add config file writing function
In reply to Justin MitchellAdds a function to nfsconf handling to write a single config entry, creating the file and section headers as required.
--- support/include/conffile.h | 1 + support/nfs/conffile.c | 621 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 622 insertions(+)
support/include/conffile.h +1 -0
@@ -67,6 +67,7 @@ extern int conf_match_num(const char *, const char *, int);extern int conf_remove (int ,const char *,const char *);extern int conf_remove_section (int ,const char *);extern void conf_report (FILE *); +extern int conf_write (const char *,const char *,const char *,const char *,const char *);/* * Convert letter from upper case to lower case
support/nfs/conffile.c +621 -0
624 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 5/5 nfs-utils: Add config setting to nfsconf cli tool
In reply to Justin MitchellUse the new conf_write() function to add setting and unsetting of config file values to the cli tool
--- tools/nfsconf/nfsconf.man | 26 ++++++++++++++++ tools/nfsconf/nfsconfcli.c | 75 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 90 insertions(+), 11 deletions(-)
tools/nfsconf/nfsconf.man +26 -0
@@ -28,6 +28,25 @@ nfsconf \- Query various NFS configuration settings .IR subsection ] .IR section .IR tag +.P +.B nfsconf \-\-set +.RB [ \-v | \-\-verbose ] +.RB [ \-f | \-\-file +.IR infile.conf ] +.RB [ \-a | \-\-arg +.IR subsection ] +.IR section +.IR tag +.IR value +.P +.B nfsconf \-\-unset +.RB [ \-v | \-\-verbose ] +.RB [ \-f | \-\-file +.IR infile.conf ] +.RB [ \-a | \-\-arg +.IR subsection ] +.IR section +.IR tag .SH DESCRIPTION The .B nfsconf
@@ -41,6 +60,10 @@ Output an alphabetically sorted dump of the current configuration in conf file f Test if a specific tag has a value set. .IP "\fB\-g, \-\-get\fP" Output the current value of the specified tag. +.IP "\fB\-s, \-\-set\fP" +Update or Add a tag and value to the config file, creating the file if necessary. +.IP "\fB\-u, \-\-unset\fP" +Remove the specified tag and its value from the config file. .SH OPTIONS .SS Options valid in all modes .TP
@@ -69,6 +92,9 @@ The tool allows for easy testing of configuration values from shell scripts, her .TP .B nfsconf --file /etc/nfsmount.conf --get --arg /home MountPoint background Show default value for \fIbackground\fR option for NFS mounts of the \fI/home\fR path. +.TP +.B nfsconf --file /etc/nfs.conf --set nfsd debug 1 +Enable debugging in nfsd .SH FILES .TP .B /etc/nfs.conf
tools/nfsconf/nfsconfcli.c +64 -11
127 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH 5/5] nfs-utils: Add config setting to nfsconf cli tool
hi Justin, it's not a part of your patch, but I noticed a tiny typo: see below.
Quoted 188 lines · Justin Mitchell
Use the new
conf_write()function to add setting and unsetting of config file values to the cli toolSigned-off-by Justin Mitchell <[email protected]>--- tools/nfsconf/nfsconf.man | 26 ++++++++++++++++ tools/nfsconf/nfsconfcli.c | 75 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 90 insertions(+), 11 deletions(-)tools/nfsconf/nfsconf.man +26
-0@@ -28,6 +28,25 @@ nfsconf \- Query various NFS configuration settings .IR subsection ] .IR section .IR tag +.P +.B nfsconf \-\-set +.RB [ \-v | \-\-verbose ] +.RB [ \-f | \-\-file +.IR infile.conf ] +.RB [ \-a | \-\-arg +.IR subsection ] +.IR section +.IR tag +.IR value +.P +.B nfsconf \-\-unset +.RB [ \-v | \-\-verbose ] +.RB [ \-f | \-\-file +.IR infile.conf ] +.RB [ \-a | \-\-arg +.IR subsection ] +.IR section +.IR tag .SH DESCRIPTION The .B nfsconf@@ -41,6 +60,10 @@ Output an alphabetically sorted dump of the current configuration in conf file f Test if a specific tag has a value set. .IP "\fB\-g, \-\-get\fP" Output the current value of the specified tag. +.IP "\fB\-s, \-\-set\fP" +Update or Add a tag and value to the config file, creating the file if necessary. +.IP "\fB\-u, \-\-unset\fP" +Remove the specified tag and its value from the config file. .SH OPTIONS .SS Options valid in all modes .TP@@ -69,6 +92,9 @@ The tool allows for easy testing of configuration values from shell scripts, her .TP .B nfsconf --file /etc/nfsmount.conf --get --arg /home MountPoint background Show default value for \fIbackground\fR option for NFS mounts of the \fI/home\fR path. +.TP +.B nfsconf --file /etc/nfs.conf --set nfsd debug 1 +Enable debugging in nfsd .SH FILES .TP .B /etc/nfs.conftools/nfsconf/nfsconfcli.c +56
-11@@ -12,7 +12,9 @@ typedef enum {MODE_NONE ,MODE_GET ,MODE_ISSET , - MODE_DUMP +MODE_DUMP , +MODE_SET , + MODE_UNSET } confmode_t;static void usage (const char *name)@@ -29,11 +31,14 @@ static void usage(const char *name)fprintf (stderr," Output one specific config value\n" );fprintf (stderr," --isset [--arg subsection] {section} {tag}\n" );fprintf (stderr," Return code indicates if config value is present\n" ); +fprintf (stderr," --set [--arg subsection] {section} {tag} {value}\n" ); +fprintf (stderr," Set and Write a config value\n" ); +fprintf (stderr," --unset [--arg subsection] {section} {tag}\n" ); +fprintf (stderr," Remove an existing config value\n" ); }int main (int argc,char **argv) { -const char * val;char * confpath =NFS_CONFFILE ;char * arg =NULL ;int verbose=0 ;@@ -47,6 +52,8 @@ int main(int argc, char **argv)int index =0 ;struct option long_options[] = { {"get" , no_argument,0 ,'g' }, + {"set" , no_argument,0 ,'s' }, + {"unset" , no_argument,0 ,'u' }, {"arg" , required_argument,0 ,'a' }, {"isset" , no_argument,0 ,'i' }, {"dump" , optional_argument,0 ,'d' },@@ -55,7 +62,7 @@ int main(int argc, char **argv) {NULL, 0, 0, 0 } }; - c =getopt_long (argc, argv,"ga:id::f:v" , long_options, &index); + c =getopt_long (argc, argv,"gsua:id::f:v" , long_options, &index);if (c ==-1 )break ;switch (c) {@@ -75,6 +82,12 @@ int main(int argc, char **argv)case 'g' : mode =MODE_GET ;break ; +case 's' : + mode =MODE_SET ; +break ; +case 'u' : + mode =MODE_UNSET ; +break ;case 'i' : mode =MODE_ISSET ;break ;@@ -105,14 +118,18 @@ int main(int argc, char **argv)return 1 ; } -if (conf_init_file (confpath)) { -/* config file was missing or had an error, warn about it */ -if (verbose || mode !=MODE_ISSET ) -fprintf (stderr,"Error loading config file %s\n" , - confpath); -/* this isnt fatal for --isset */ -if (mode !=MODE_ISSET ) -return 1 ; +if (mode !=MODE_SET && mode !=MODE_UNSET ) { +if (conf_init_file (confpath)) { +/* config file was missing or had an error, warn about it */ +if (verbose || mode !=MODE_ISSET ) { +fprintf (stderr,"Error loading config file %s\n" , + confpath); + } + +/* this isnt fatal for --isset */ +if (mode !=MODE_ISSET ) +return 1 ; + } }/* --dump mode, output the current configuration */ @@ -144,6 +161,7 @@ int main(int argc, char **argv)if (mode ==MODE_GET || mode ==MODE_ISSET ) {char * section =NULL ;char * tag =NULL ; +const char * val;/* test they supplied section and tag names */ if (optind+1 >= argc) {@@ -169,6 +187,41 @@ int main(int argc, char **argv)fprintf (stderr,"Tag '%s' not found\n" , tag); ret =1 ; } + }else +if (mode ==MODE_SET || mode ==MODE_UNSET ) { +char * section =NULL ; +char * tag =NULL ; +char * val =NULL ; +int need =2 ; + +if (mode ==MODE_UNSET ) + need =1 ; + +/* test they supplied section and tag names */ +if (optind+need >= argc) { +fprintf (stderr,"Error: insufficient arguments for mode\n" ); +usage (argv[0 ]); + ret =2 ; + goto cleanup; + } + +/* now we have a section and tag name */ + section = argv[optind++]; + tag = argv[optind++]; +if (mode ==MODE_SET ) + val = argv[optind++]; + +/* setting an empty string is same as unsetting */ +if (val!=NULL && *val =='\0' ) { + mode =MODE_UNSET ;
tools/nfsconf/nfsconfcli.c int main(int argc, char **argv) · line 226
Quoted 10 lines
tools/nfsconf/nfsconfcli.c +8
-0+ val =NULL ; + } + +if (conf_write (confpath, section, arg, tag, val)) { +if (verbose) +fprintf (stderr,"Error writing config\n" ); + ret =1 ; + } }else {fprintf (stderr,"Mode not yet implimented.\n" );
-> implemented
Quoted 2 lines
tools/nfsconf/nfsconfcli.c +0
-0ret =2 ;
Re: [PATCH 5/5] nfs-utils: Add config setting to nfsconf cli tool
Quoted 8 lines · Calum Mackay
hi Justin, it's not a part of your patch, but I noticed a tiny typo: see below.
Quoted 2 lines · Justin Mitchell
} else { fprintf(stderr, "Mode not yet implimented.\n");-> implemented
Well spotted, a quick check with the spell checker spots a few others, so patch submitted separately.
thanks for pointing it out
-J
Quoted 8 lines · Justin Mitchell
As part of my ongoing efforts to improve storage management integration with NFS I offer this support for setting configuration file values.
This code only updates a single config entry at a time, it attempts to preserve the existing structure and style of the comments file, and takes every precaution that the replacement file is written before using rename(2) to replace the original.
Quoted 4 lines
The cli nfsconf tool is also updated to be the first consumer of this functionality.
Signed-off-by Justin Mitchell <[email protected]>
All 5 committed...
steved.