nfs-utils patches
Subsystems (2)
cover nfs-utils patches
A few more as I progress through all the utils. There isn't any dependency on the previous patches.
Although idmapd client support is depreciated, the kernel still falls back to using it if the upcall fails.
Wasn't originally going to send the last patch upstream, but figured might as well, and let you decide if it's wanted. Basically allows you to load the plugins from a development source tree for testing instead of requiring them to be installed in their final location.
Thanks,
Doug
Doug Nazar (4):
exportfs: Fix a few valgrind warnings
idmapd: Add graceful exit and resource cleanup
idmapd: Fix client mode support
nfsidmap: Allow overriding location of method libraries
support/nfs/exports.c | 1 + support/nfsidmap/libnfsidmap.c | 40 +++++-- utils/exportfs/exportfs.c | 7 +- utils/idmapd/idmapd.c | 211 +++++++++++++++++++++++---------- 4 files changed, 183 insertions(+), 76 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/4 exportfs: Fix a few valgrind warnings
--- support/nfs/exports.c | 1 + utils/exportfs/exportfs.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
support/nfs/exports.c +1 -0
@@ -838,6 +838,7 @@ struct export_features *get_export_features(void)close (fd);if (c ==-1 ) goto err; + buf[c] =0 ; c =sscanf (buf,"%x %x" , &ef.flags, &ef.secinfo_flags);if (c !=2 ) goto err;
utils/exportfs/exportfs.c +6 -1
@@ -85,8 +85,11 @@ grab_lockfile()static void release_lockfile () { -if (_lockfd !=-1 ) +if (_lockfd !=-1 ) {lockf (_lockfd,F_ULOCK ,0 ); +close (_lockfd); + _lockfd =-1 ; + } }int
@@ -184,6 +187,7 @@ main(int argc, char **argv)xtab_export_read ();dump (f_verbose, f_export_format);free_state_path_names (&etab); +export_freeall ();return 0 ; } }
@@ -225,6 +229,7 @@ main(int argc, char **argv)xtab_export_write ();cache_flush (force_flush);free_state_path_names (&etab); +export_freeall ();return export_errno; }
Signature · 1 line
2.26.2
PATCH 2/4 idmapd: Add graceful exit and resource cleanup
In reply to Doug Nazar--- utils/idmapd/idmapd.c | 75 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 10 deletions(-)
utils/idmapd/idmapd.c +65 -10
@@ -155,6 +155,7 @@ static void idtonameres(struct idmap_msg *);static void nametoidres (struct idmap_msg *);static int nfsdopen (void ); +static void nfsdclose (void );static int nfsdopenone (struct idmap_client *);static void nfsdreopen_one (struct idmap_client *);static void nfsdreopen (void );
@@ -167,6 +168,20 @@ static char *nobodyuser, *nobodygroup;static uid_t nobodyuid;static gid_t nobodygid;static struct event_base *evbase =NULL ; +static bool signal_received = false; + +static void +sig_die (int signal) +{ +if (signal_received) { +xlog_warn ("forced exiting on signal %d\n" , signal); +exit (0 ); + } + + signal_received = true; +xlog_warn ("exiting on signal %d\n" , signal); +event_base_loopexit (evbase,NULL ); +}static int flush_nfsd_cache (char *path,time_t now)
@@ -210,14 +225,15 @@ main(int argc, char **argv) {int wd =-1 , opt, fg =0 , nfsdret =-1 ;struct idmap_clientq icq; -struct event *rootdirev, *clntdirev, *svrdirev, *inotifyev; -struct event *initialize; +struct event *rootdirev =NULL , *clntdirev =NULL , + *svrdirev =NULL , *inotifyev =NULL ; +struct event *initialize =NULL ;struct passwd *pw;struct group *gr;struct stat sb;char *xpipefsdir =NULL ;int serverstart =1 , clientstart =1 ; -int inotify_fd; +int inotify_fd =-1 ;int ret;char *progname;char *conf_path =NULL ;
@@ -290,6 +306,9 @@ main(int argc, char **argv) serverstart =0 ; } +/* Not needed anymore */ +conf_cleanup (); +while ((opt =getopt (argc, argv,GETOPTSTR )) !=-1 )switch (opt) {case 'v' :
@@ -398,6 +417,9 @@ main(int argc, char **argv)TAILQ_INIT (&icq); +signal (SIGINT , sig_die); +signal (SIGTERM , sig_die); +/* These events are persistent */ rootdirev =evsignal_new (evbase,SIGUSR1 , dirscancb, &icq);if (rootdirev ==NULL )
@@ -435,7 +457,25 @@ main(int argc, char **argv)if (event_base_dispatch (evbase) <0 )xlog_err ("main: event_dispatch returns errno %d (%s)" , errno,strerror (errno)); -/* NOTREACHED */ + +nfs4_term_name_mapping (); +nfsdclose (); + +if (inotifyev) +event_free (inotifyev); +if (inotify_fd !=-1 ) +close (inotify_fd); + +if (initialize) +event_free (initialize); +if (rootdirev) +event_free (rootdirev); +if (clntdirev) +event_free (clntdirev); +if (svrdirev) +event_free (svrdirev); +event_base_free (evbase); +return 1 ; }
@@ -760,6 +800,19 @@ out:event_add (ic->ic_event,NULL ); } +static void +nfsdclose_one (struct idmap_client *ic) +{ +if (ic->ic_event) { +event_free (ic->ic_event); + ic->ic_event =NULL ; + } +if (ic->ic_fd !=-1 ) { +close (ic->ic_fd); + ic->ic_fd =-1 ; + } +} +static void nfsdreopen_one (struct idmap_client *ic) {
@@ -769,12 +822,7 @@ nfsdreopen_one(struct idmap_client *ic)xlog_warn ("ReOpening %s" , ic->ic_path);if ((fd =open (ic->ic_path,O_RDWR ,0 )) !=-1 ) { -if (ic->ic_event &&event_initialized (ic->ic_event)) { -event_del (ic->ic_event); -event_free (ic->ic_event); - } -if (ic->ic_fd !=-1 ) -close (ic->ic_fd); +nfsdclose_one (ic); ic->ic_fd = fd; ic->ic_event =event_new (evbase, ic->ic_fd,EV_READ , nfsdcb, ic);
@@ -807,6 +855,13 @@ nfsdopen(void) nfsdopenone(&nfsd_ic[IC_IDNAME]) == 0) ? 0 : -1); } +static void +nfsdclose (void ) +{ +nfsdclose_one (&nfsd_ic[IC_NAMEID ]); +nfsdclose_one (&nfsd_ic[IC_IDNAME ]); +} +static int nfsdopenone (struct idmap_client *ic) {
Signature · 1 line
2.26.2
Re: [PATCH 2/4] idmapd: Add graceful exit and resource cleanup
Hello,
Quoted 58 lines · Doug Nazar
Signed-off-by Doug Nazar <[email protected]>--- utils/idmapd/idmapd.c | 75 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 10 deletions(-)utils/idmapd/idmapd.c +19
-3@@ -155,6 +155,7 @@ static void idtonameres(struct idmap_msg *);static void nametoidres (struct idmap_msg *);static int nfsdopen (void ); +static void nfsdclose (void );static int nfsdopenone (struct idmap_client *);static void nfsdreopen_one (struct idmap_client *);static void nfsdreopen (void );@@ -167,6 +168,20 @@ static char *nobodyuser, *nobodygroup;static uid_t nobodyuid;static gid_t nobodygid;static struct event_base *evbase =NULL ; +static bool signal_received = false; + +static void +sig_die (int signal) +{ +if (signal_received) { +xlog_warn ("forced exiting on signal %d\n" , signal); +exit (0 ); + } + + signal_received = true; +xlog_warn ("exiting on signal %d\n" , signal); +event_base_loopexit (evbase,NULL ); +}static int flush_nfsd_cache (char *path,time_t now)@@ -210,14 +225,15 @@ main(int argc, char **argv) {int wd =-1 , opt, fg =0 , nfsdret =-1 ;struct idmap_clientq icq; -struct event *rootdirev, *clntdirev, *svrdirev, *inotifyev; -struct event *initialize; +struct event *rootdirev =NULL , *clntdirev =NULL , + *svrdirev =NULL , *inotifyev =NULL ; +struct event *initialize =NULL ;struct passwd *pw;struct group *gr;struct stat sb;char *xpipefsdir =NULL ;int serverstart =1 , clientstart =1 ; -int inotify_fd; +int inotify_fd =-1 ;int ret;char *progname;char *conf_path =NULL ;
utils/idmapd/idmapd.c main(int argc, char **argv) · line 311
Quoted 6 lines
utils/idmapd/idmapd.c +3
-0@@ -290,6 +306,9 @@ main(int argc, char **argv) serverstart =0 ; } +/* Not needed anymore */ +conf_cleanup (); +
I'm a bit confused by this comment... If it is not needed why as the call added?
steved.
Quoted 89 lines
utils/idmapd/idmapd.c +43
-7while ((opt =getopt (argc, argv,GETOPTSTR )) !=-1 )switch (opt) {case 'v' :@@ -398,6 +417,9 @@ main(int argc, char **argv)TAILQ_INIT (&icq); +signal (SIGINT , sig_die); +signal (SIGTERM , sig_die); +/* These events are persistent */ rootdirev =evsignal_new (evbase,SIGUSR1 , dirscancb, &icq);if (rootdirev ==NULL )@@ -435,7 +457,25 @@ main(int argc, char **argv)if (event_base_dispatch (evbase) <0 )xlog_err ("main: event_dispatch returns errno %d (%s)" , errno,strerror (errno)); -/* NOTREACHED */ + +nfs4_term_name_mapping (); +nfsdclose (); + +if (inotifyev) +event_free (inotifyev); +if (inotify_fd !=-1 ) +close (inotify_fd); + +if (initialize) +event_free (initialize); +if (rootdirev) +event_free (rootdirev); +if (clntdirev) +event_free (clntdirev); +if (svrdirev) +event_free (svrdirev); +event_base_free (evbase); +return 1 ; }@@ -760,6 +800,19 @@ out:event_add (ic->ic_event,NULL ); } +static void +nfsdclose_one (struct idmap_client *ic) +{ +if (ic->ic_event) { +event_free (ic->ic_event); + ic->ic_event =NULL ; + } +if (ic->ic_fd !=-1 ) { +close (ic->ic_fd); + ic->ic_fd =-1 ; + } +} +static void nfsdreopen_one (struct idmap_client *ic) {@@ -769,12 +822,7 @@ nfsdreopen_one(struct idmap_client *ic)xlog_warn ("ReOpening %s" , ic->ic_path);if ((fd =open (ic->ic_path,O_RDWR ,0 )) !=-1 ) { -if (ic->ic_event &&event_initialized (ic->ic_event)) { -event_del (ic->ic_event); -event_free (ic->ic_event); - } -if (ic->ic_fd !=-1 ) -close (ic->ic_fd); +nfsdclose_one (ic); ic->ic_fd = fd; ic->ic_event =event_new (evbase, ic->ic_fd,EV_READ , nfsdcb, ic);@@ -807,6 +855,13 @@ nfsdopen(void) nfsdopenone(&nfsd_ic[IC_IDNAME]) == 0) ? 0 : -1); } +static void +nfsdclose (void ) +{ +nfsdclose_one (&nfsd_ic[IC_NAMEID ]); +nfsdclose_one (&nfsd_ic[IC_IDNAME ]); +} +static int nfsdopenone (struct idmap_client *ic) {
Re: [PATCH 2/4] idmapd: Add graceful exit and resource cleanup
Quoted 8 lines · Steve Dickson
(quoted diff) +0
-0@@ -290,6 +306,9 @@ main(int argc, char **argv) > serverstart = 0; > }utils/idmapd/idmapd.c main(int argc, char **argv) · line 311
Quoted 4 lines
utils/idmapd/idmapd.c +3
-0+/* Not needed anymore */ +conf_cleanup (); +I'm a bit confused by this comment... If it is not needed why as the call added?
Sorry, I should have been a bit more verbose in the comment. I meant that we didn't need access to the config file anymore (we've already looked up everything) and can free those resources early.
Perhaps /* Config not needed anymore */ or something.
Doug
Re: [PATCH 2/4] idmapd: Add graceful exit and resource cleanup
Quoted 7 lines · Doug Nazar
Quoted 6 lines · Steve Dickson
(quoted diff) +0
-0@@ -290,6 +306,9 @@ main(int argc, char **argv) > serverstart = 0; > }Quoted 3 lines
+ /* Not needed anymore */
+conf_cleanup();
+
Quoted 5 lines
Quoted 1 line
I'm a bit confused by this comment... If it is not needed why as the call added?
Sorry, I should have been a bit more verbose in the comment. I meant that we didn't need access to the config file anymore (we've already looked up everything) and can free those resources early.
Perhaps /* Config not needed anymore */ or something.
Ok.. got it... I'll make it work...
steved.
Quoted 3 lines
Doug
PATCH 3/4 idmapd: Fix client mode support
In reply to Doug NazarThe inotify event was never rearmed, so we wouldn't get any notice after the first event. Even if it had been re-added, we never read the pending events so it would continously fire. Fix this by moving to persistent events and reading any pending inotify events. Effect was we'd leak any clients that existed after the first event.
Switch from dnotify to inotify on the client dir if the idmap file isn't available yet.
--- utils/idmapd/idmapd.c | 138 +++++++++++++++++++++++++----------------- 1 file changed, 84 insertions(+), 54 deletions(-)
utils/idmapd/idmapd.c +84 -54
@@ -169,6 +169,7 @@ static uid_t nobodyuid;static gid_t nobodygid;static struct event_base *evbase =NULL ;static bool signal_received = false; +static int inotify_fd =-1 ;static void sig_die (int signal)
@@ -233,7 +234,6 @@ main(int argc, char **argv)struct stat sb;char *xpipefsdir =NULL ;int serverstart =1 , clientstart =1 ; -int inotify_fd =-1 ;int ret;char *progname;char *conf_path =NULL ;
@@ -410,7 +410,7 @@ main(int argc, char **argv)if (inotify_fd ==-1 ) {xlog_err ("Unable to initialise inotify_init1: %s\n" ,strerror (errno)); }else { - wd =inotify_add_watch (inotify_fd, pipefsdir,IN_CREATE |IN_DELETE |IN_MODIFY ); + wd =inotify_add_watch (inotify_fd, pipefsdir,IN_CREATE |IN_DELETE );if (wd <0 )xlog_err ("Unable to inotify_add_watch(%s): %s\n" , pipefsdir,strerror (errno)); }
@@ -434,7 +434,8 @@ main(int argc, char **argv)errx (1 ,"Failed to create SIGHUP event." );evsignal_add (svrdirev,NULL );if ( wd >=0 ) { - inotifyev =event_new (evbase, inotify_fd,EV_READ , dirscancb, &icq); + inotifyev =event_new (evbase, inotify_fd, +EV_READ |EV_PERSIST , dirscancb, &icq);if (inotifyev ==NULL )errx (1 ,"Failed to create inotify read event." );event_add (inotifyev,NULL );
@@ -480,7 +481,33 @@ main(int argc, char **argv) }static void -dirscancb (int UNUSED (fd ),short UNUSED (which ),void *data) +flush_inotify (int fd) +{ +while (true) { + char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event)))); +const struct inotify_event *ev; +ssize_t len; +char *ptr; + + len =read (fd, buf,sizeof (buf)); +if (len ==-1 && errno ==EINTR ) +continue ; + +if (len <=0 ) +break ; + +for (ptr = buf; ptr < buf + len; + ptr +=sizeof (struct inotify_event ) + ev->len) { + + ev = (const struct inotify_event *)ptr; +xlog_warn ("pipefs inotify: wd=%i, mask=0x%08x, len=%i, name=%s" , + ev->wd, ev->mask, ev->len, ev->len ? ev->name :"" ); + } + } +} + +static void +dirscancb (int fd,short UNUSED (which ),void *data) {int nent, i;struct dirent **ents;
@@ -488,6 +515,13 @@ dirscancb(int UNUSED(fd), short UNUSED(which), void *data)char path[PATH_MAX +256 ];/* + sizeof(d_name) */ struct idmap_clientq *icq = data; +if (fd !=-1 ) +flush_inotify (fd); + + TAILQ_FOREACH(ic, icq, ic_next) { + ic->ic_scanned =0 ; + } + nent =scandir (pipefsdir, &ents,NULL , alphasort);if (nent ==-1 ) {xlog_warn ("dirscancb: scandir(%s): %s" , pipefsdir,strerror (errno));
@@ -521,15 +555,15 @@ dirscancb(int UNUSED(fd), short UNUSED(which), void *data)strlcat (path,"/idmap" ,sizeof (path));strlcpy (ic->ic_path, path,sizeof (ic->ic_path)); -if (verbose >0 ) -xlog_warn ("New client: %s" , ic->ic_clid); -if (nfsopen (ic) ==-1 ) {close (ic->ic_dirfd);free (ic); goto out; } +if (verbose >0 ) +xlog_warn ("New client: %s" , ic->ic_clid); + ic->ic_id ="Client" ;TAILQ_INSERT_TAIL (icq, ic, ic_next);
@@ -543,18 +577,19 @@ dirscancb(int UNUSED(fd), short UNUSED(which), void *data)while (ic !=NULL ) { nextic=TAILQ_NEXT (ic, ic_next);if (!ic->ic_scanned) { -event_del (ic->ic_event); -event_free (ic->ic_event); -close (ic->ic_fd); -close (ic->ic_dirfd); +if (ic->ic_event) +event_free (ic->ic_event); +if (ic->ic_fd !=-1 ) +close (ic->ic_fd); +if (ic->ic_dirfd !=-1 ) +close (ic->ic_dirfd);TAILQ_REMOVE (icq, ic, ic_next);if (verbose >0 ) {xlog_warn ("Stale client: %s" , ic->ic_clid);xlog_warn ("\t-> closed %s" , ic->ic_path); }free (ic); - }else - ic->ic_scanned =0 ; + } ic = nextic; }
@@ -600,7 +635,7 @@ nfsdcb(int UNUSED(fd), short which, void *data)unsigned long tmp;if (which !=EV_READ ) - goto out; +return ; len =read (ic->ic_fd, buf,sizeof (buf));if (len ==0 )
@@ -623,11 +658,11 @@ nfsdcb(int UNUSED(fd), short which, void *data)/* Authentication name -- ignored for now*/ if (getfield (&bp, authbuf,sizeof (authbuf)) ==-1 ) {xlog_warn ("nfsdcb: bad authentication name in upcall\n" ); - goto out; +return ; }if (getfield (&bp, typebuf,sizeof (typebuf)) ==-1 ) {xlog_warn ("nfsdcb: bad type in upcall\n" ); - goto out; +return ; }if (verbose >0 ) xlog_warn("nfsdcb: authbuf=%s authtype=%s",
@@ -641,26 +676,26 @@ nfsdcb(int UNUSED(fd), short which, void *data) im.im_conv =IDMAP_CONV_NAMETOID ;if (getfield (&bp, im.im_name,sizeof (im.im_name)) ==-1 ) {xlog_warn ("nfsdcb: bad name in upcall\n" ); - goto out; +return ; }break ;case IC_IDNAME : im.im_conv =IDMAP_CONV_IDTONAME ;if (getfield (&bp, buf1,sizeof (buf1)) ==-1 ) {xlog_warn ("nfsdcb: bad id in upcall\n" ); - goto out; +return ; } tmp =strtoul (buf1, (char **)NULL ,10 ); im.im_id = (u_int32_t )tmp;if ((tmp ==ULONG_MAX && errno ==ERANGE ) || (unsigned long )im.im_id != tmp) {xlog_warn ("nfsdcb: id '%s' too big!\n" , buf1); - goto out; +return ; }break ;default :xlog_warn ("nfsdcb: Unknown which type %d" , ic->ic_which); - goto out; +return ; }imconv (ic, &im);
@@ -721,7 +756,7 @@ nfsdcb(int UNUSED(fd), short which, void *data)break ;default :xlog_warn ("nfsdcb: Unknown which type %d" , ic->ic_which); - goto out; +return ; } bsiz =sizeof (buf) - bsiz;
@@ -729,9 +764,6 @@ nfsdcb(int UNUSED(fd), short which, void *data)if (atomicio ((void *)write, ic->ic_fd, buf, bsiz) != bsiz)xlog_warn ("nfsdcb: write(%s) failed: errno %d (%s)" , ic->ic_path, errno,strerror (errno)); - -out: -event_add (ic->ic_event,NULL ); } static void
@@ -775,14 +807,12 @@ nfscb(int UNUSED(fd), short which, void *data)struct idmap_msg im;if (which !=EV_READ ) - goto out; +return ;if (atomicio (read, ic->ic_fd, &im,sizeof (im)) !=sizeof (im)) {if (verbose >0 )xlog_warn ("nfscb: read(%s): %s" , ic->ic_path,strerror (errno)); -if (errno ==EPIPE ) -return ; - goto out; +return ; }imconv (ic, &im);
@@ -796,8 +826,6 @@ nfscb(int UNUSED(fd), short which, void *data)if (atomicio ((void *)write, ic->ic_fd, &im,sizeof (im)) !=sizeof (im))xlog_warn ("nfscb: write(%s): %s" , ic->ic_path,strerror (errno)); -out: -event_add (ic->ic_event,NULL ); } static void
@@ -825,7 +853,7 @@ nfsdreopen_one(struct idmap_client *ic)nfsdclose_one (ic); ic->ic_fd = fd; - ic->ic_event =event_new (evbase, ic->ic_fd,EV_READ , nfsdcb, ic); + ic->ic_event =event_new (evbase, ic->ic_fd,EV_READ |EV_PERSIST , nfsdcb, ic);if (ic->ic_event ==NULL ) {xlog_warn ("nfsdreopen: Failed to create event for '%s'" , ic->ic_path);
@@ -873,7 +901,7 @@ nfsdopenone(struct idmap_client *ic)return (-1 ); } - ic->ic_event =event_new (evbase, ic->ic_fd,EV_READ , nfsdcb, ic); + ic->ic_event =event_new (evbase, ic->ic_fd,EV_READ |EV_PERSIST , nfsdcb, ic);if (ic->ic_event ==NULL ) {if (verbose >0 ) xlog_warn("nfsdopenone: Create event for %s failed",
@@ -894,32 +922,34 @@ static int nfsopen(struct idmap_client *ic) {if ((ic->ic_fd =open (ic->ic_path,O_RDWR ,0 )) ==-1 ) { -switch (errno) { -case ENOENT : -fcntl (ic->ic_dirfd,F_SETSIG ,SIGUSR2 ); -fcntl (ic->ic_dirfd,F_NOTIFY , -DN_CREATE |DN_DELETE |DN_MULTISHOT ); -break ; -default : -xlog_warn ("nfsopen: open(%s): %s" , ic->ic_path,strerror (errno)); -return (-1 ); - } - }else { - ic->ic_event =event_new (evbase, ic->ic_fd,EV_READ , nfscb, ic); -if (ic->ic_event ==NULL ) { -xlog_warn ("nfsdopenone: Create event for %s failed" , - ic->ic_path); -close (ic->ic_fd); - ic->ic_fd =-1 ; +if (errno ==ENOENT ) { +char *slash; + + slash =strrchr (ic->ic_path,'/' ); +if (!slash) +return -1 ; + *slash =0 ; +inotify_add_watch (inotify_fd, ic->ic_path,IN_CREATE |IN_ONLYDIR |IN_ONESHOT ); + *slash ='/' ; +xlog_warn ("Path %s not available. waiting..." , ic->ic_path);return -1 ; } -event_add (ic->ic_event,NULL ); -fcntl (ic->ic_dirfd,F_NOTIFY ,0 ); -fcntl (ic->ic_dirfd,F_SETSIG ,0 ); -if (verbose >0 ) -xlog_warn ("Opened %s" , ic->ic_path); + +xlog_warn ("nfsopen: open(%s): %s" , ic->ic_path,strerror (errno)); +return (-1 ); } + ic->ic_event =event_new (evbase, ic->ic_fd,EV_READ |EV_PERSIST , nfscb, ic); +if (ic->ic_event ==NULL ) { +xlog_warn ("nfsopen: Create event for %s failed" , ic->ic_path); +close (ic->ic_fd); + ic->ic_fd =-1 ; +return -1 ; + } +event_add (ic->ic_event,NULL ); +if (verbose >0 ) +xlog_warn ("Opened %s" , ic->ic_path); +return (0 ); }
Signature · 1 line
2.26.2
PATCH 4/4 nfsidmap: Allow overriding location of method libraries
In reply to Doug Nazar--- support/nfsidmap/libnfsidmap.c | 40 ++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-)
support/nfsidmap/libnfsidmap.c +28 -12
@@ -237,24 +237,40 @@ static int load_translation_plugin(char *method, struct mapping_plugin *plgn) {void *dl =NULL ;struct trans_func *trans =NULL ; -libnfsidmap_plugin_init_t init_func; +libnfsidmap_plugin_init_t init_func =NULL ;char plgname[128 ];int ret =0 ; -snprintf (plgname,sizeof (plgname),"%s/%s.so" ,PATH_PLUGINS , method); +/* Look for library using search path first to allow overriding */ +snprintf (plgname,sizeof (plgname),"%s.so" , method); dl =dlopen (plgname,RTLD_NOW |RTLD_LOCAL ); -if (dl ==NULL ) { -IDMAP_LOG (1 , ("libnfsidmap: Unable to load plugin: %s" , -dlerror ())); -return -1 ; +if (dl !=NULL ) { +/* Is it really one of our libraries */ + init_func = (libnfsidmap_plugin_init_t )dlsym (dl,PLUGIN_INIT_FUNC ); +if (init_func ==NULL ) { +dlclose (dl); + dl =NULL ; + } } - init_func = (libnfsidmap_plugin_init_t )dlsym (dl,PLUGIN_INIT_FUNC ); -if (init_func ==NULL ) { -IDMAP_LOG (1 , ("libnfsidmap: Unable to get init function: %s" , -dlerror ())); -dlclose (dl); -return -1 ; + +if (dl ==NULL ) { +/* Fallback to hard-coded path */ +snprintf (plgname,sizeof (plgname),"%s/%s.so" ,PATH_PLUGINS , method); + + dl =dlopen (plgname,RTLD_NOW |RTLD_LOCAL ); +if (dl ==NULL ) { +IDMAP_LOG (1 , ("libnfsidmap: Unable to load plugin: %s" , +dlerror ())); +return -1 ; + } + init_func = (libnfsidmap_plugin_init_t )dlsym (dl,PLUGIN_INIT_FUNC ); +if (init_func ==NULL ) { +IDMAP_LOG (1 , ("libnfsidmap: Unable to get init function: %s" , +dlerror ())); +dlclose (dl); +return -1 ; + } } trans =init_func ();if (trans ==NULL ) {
Signature · 1 line
2.26.2
Quoted 15 lines · Doug Nazar
A few more as I progress through all the utils. There isn't any dependency on the previous patches.
Although idmapd client support is depreciated, the kernel still falls back to using it if the upcall fails.
Wasn't originally going to send the last patch upstream, but figured might as well, and let you decide if it's wanted. Basically allows you to load the plugins from a development source tree for testing instead of requiring them to be installed in their final location.
Thanks,
Doug
Quoted 5 lines
Doug Nazar (4):
exportfs: Fix a few valgrind warnings
idmapd: Add graceful exit and resource cleanup
idmapd: Fix client mode support
nfsidmap: Allow overriding location of method libraries
Series committed... (tag: nfs-utils-2-5-2-rc3)
steved.
Quoted 7 lines
support/nfs/exports.c | 1 + support/nfsidmap/libnfsidmap.c | 40 +++++-- utils/exportfs/exportfs.c | 7 +- utils/idmapd/idmapd.c | 211 +++++++++++++++++++++++---------- 4 files changed, 183 insertions(+), 76 deletions(-)