All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] idmapd: Use inotify instead of dnotify
@ 2017-06-21 19:31 Alan Swanson
  2017-06-21 21:23 ` [PATCH V2] " Alan Swanson
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Swanson @ 2017-06-21 19:31 UTC (permalink / raw)
  To: linux-nfs; +Cc: Alan Swanson

Remove last use of dnotify in nfs-utils by bringing idmapd upto
date with (required) inotify use by gssd and blkmapd.

Signed-off-by: Alan Swanson <reiver@improbability.net>
---
 utils/idmapd/idmapd.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

Got annoyed by the dnotify kernel requirement. Read the last
discussion "DNOTIFY to INOTIFY migration" posted in 2014 and while
still not officially depreciated, dnotify was officially "replaced"
by inotify in Linux 2.6.13 in 2005. Would be nice to sync this
requirement across the codebase.

diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
index c12e878..c965119 100644
--- a/utils/idmapd/idmapd.c
+++ b/utils/idmapd/idmapd.c
@@ -36,7 +36,7 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
-#include <sys/poll.h>
+#include <sys/inotify.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <time.h>
@@ -205,15 +205,16 @@ void usage(char *progname)
 int
 main(int argc, char **argv)
 {
-	int fd = 0, opt, fg = 0, nfsdret = -1;
+	int wd = 0, opt, fg = 0, nfsdret = -1;
 	struct idmap_clientq icq;
-	struct event rootdirev, clntdirev, svrdirev;
+	struct event rootdirev, clntdirev, svrdirev, inotifyev;
 	struct event initialize;
 	struct passwd *pw;
 	struct group *gr;
 	struct stat sb;
 	char *xpipefsdir = NULL;
 	int serverstart = 1, clientstart = 1;
+	int inotify_fd;
 	int ret;
 	char *progname;
 	char *conf_path = NULL;
@@ -373,18 +374,15 @@ main(int argc, char **argv)
 			}
 		}
 
-		if ((fd = open(pipefsdir, O_RDONLY)) == -1)
-			xlog_err("main: open(%s): %s", pipefsdir, strerror(errno));
-
-		if (fcntl(fd, F_SETSIG, SIGUSR1) == -1)
-			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
-
-		if (fcntl(fd, F_NOTIFY,
-			DN_CREATE | DN_DELETE | DN_MODIFY | DN_MULTISHOT) == -1) {
-			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
-			if (errno == EINVAL)
-				xlog_err("main: Possibly no Dnotify support in kernel.");
+		inotify_fd = inotify_init1(IN_NONBLOCK);
+		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);
+			if (wd < 0)
+				xlog_err("Unable to inotify_add_watch(%s): %s\n", pipefsdir, strerror(errno));
 		}
+
 		TAILQ_INIT(&icq);
 
 		/* These events are persistent */
@@ -394,6 +392,10 @@ main(int argc, char **argv)
 		signal_add(&clntdirev, NULL);
 		signal_set(&svrdirev, SIGHUP, svrreopen, NULL);
 		signal_add(&svrdirev, NULL);
+		if ( wd >= 0) {
+			event_set(&inotifyev, inotify_fd, EV_READ | EV_PERSIST, dirscancb, &icq);
+			event_add(&inotifyev, NULL);
+		}
 
 		/* Fetch current state */
 		/* (Delay till start of event_dispatch to avoid possibly losing
@@ -402,7 +404,7 @@ main(int argc, char **argv)
 		evtimer_add(&initialize, &now);
 	}
 
-	if (nfsdret != 0 && fd == 0)
+	if (nfsdret != 0 && wd < 0)
 		xlog_err("main: Neither NFS client nor NFSd found");
 
 	daemon_ready();
-- 
2.13.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH V2] idmapd: Use inotify instead of dnotify
  2017-06-21 19:31 [PATCH] idmapd: Use inotify instead of dnotify Alan Swanson
@ 2017-06-21 21:23 ` Alan Swanson
  2018-08-19 16:43   ` [PATCH V3] " Alan Swanson
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Swanson @ 2017-06-21 21:23 UTC (permalink / raw)
  To: linux-nfs; +Cc: Alan Swanson

Remove last use of dnotify in nfs-utils by bringing idmapd upto
date with (required) inotify use by gssd and blkmapd.
---
 utils/idmapd/idmapd.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

Got annoyed by the dnotify kernel requirement. Read the last
discussion "DNOTIFY to INOTIFY migration" posted in 2014 and while
still not officially depreciated, dnotify was officially "replaced"
by inotify in Linux 2.6.13 in 2005. Would be nice to sync this
requirement across the codebase.

V2: Init wd to -1 not 0

diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
index c12e878..c29dba6 100644
--- a/utils/idmapd/idmapd.c
+++ b/utils/idmapd/idmapd.c
@@ -36,7 +36,7 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
-#include <sys/poll.h>
+#include <sys/inotify.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <time.h>
@@ -205,15 +205,16 @@ void usage(char *progname)
 int
 main(int argc, char **argv)
 {
-	int fd = 0, opt, fg = 0, nfsdret = -1;
+	int wd = -1, opt, fg = 0, nfsdret = -1;
 	struct idmap_clientq icq;
-	struct event rootdirev, clntdirev, svrdirev;
+	struct event rootdirev, clntdirev, svrdirev, inotifyev;
 	struct event initialize;
 	struct passwd *pw;
 	struct group *gr;
 	struct stat sb;
 	char *xpipefsdir = NULL;
 	int serverstart = 1, clientstart = 1;
+	int inotify_fd;
 	int ret;
 	char *progname;
 	char *conf_path = NULL;
@@ -373,18 +374,15 @@ main(int argc, char **argv)
 			}
 		}
 
-		if ((fd = open(pipefsdir, O_RDONLY)) == -1)
-			xlog_err("main: open(%s): %s", pipefsdir, strerror(errno));
-
-		if (fcntl(fd, F_SETSIG, SIGUSR1) == -1)
-			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
-
-		if (fcntl(fd, F_NOTIFY,
-			DN_CREATE | DN_DELETE | DN_MODIFY | DN_MULTISHOT) == -1) {
-			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
-			if (errno == EINVAL)
-				xlog_err("main: Possibly no Dnotify support in kernel.");
+		inotify_fd = inotify_init1(IN_NONBLOCK);
+		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);
+			if (wd < 0)
+				xlog_err("Unable to inotify_add_watch(%s): %s\n", pipefsdir, strerror(errno));
 		}
+
 		TAILQ_INIT(&icq);
 
 		/* These events are persistent */
@@ -394,6 +392,10 @@ main(int argc, char **argv)
 		signal_add(&clntdirev, NULL);
 		signal_set(&svrdirev, SIGHUP, svrreopen, NULL);
 		signal_add(&svrdirev, NULL);
+		if ( wd >= 0) {
+			event_set(&inotifyev, inotify_fd, EV_READ | EV_PERSIST, dirscancb, &icq);
+			event_add(&inotifyev, NULL);
+		}
 
 		/* Fetch current state */
 		/* (Delay till start of event_dispatch to avoid possibly losing
@@ -402,7 +404,7 @@ main(int argc, char **argv)
 		evtimer_add(&initialize, &now);
 	}
 
-	if (nfsdret != 0 && fd == 0)
+	if (nfsdret != 0 && wd < 0)
 		xlog_err("main: Neither NFS client nor NFSd found");
 
 	daemon_ready();
-- 
2.13.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH V3] idmapd: Use inotify instead of dnotify
  2017-06-21 21:23 ` [PATCH V2] " Alan Swanson
@ 2018-08-19 16:43   ` Alan Swanson
  2018-08-20 19:00     ` J. Bruce Fields
  2018-10-05 11:07     ` Steve Dickson
  0 siblings, 2 replies; 5+ messages in thread
From: Alan Swanson @ 2018-08-19 16:43 UTC (permalink / raw)
  To: linux-nfs; +Cc: Alan Swanson

Remove last use of dnotify in nfs-utils by bringing idmapd upto
date with (required) inotify use by gssd and blkmapd.
---
 utils/idmapd/idmapd.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

Got annoyed by the dnotify kernel requirement. Read the last
discussion "DNOTIFY to INOTIFY migration" posted in 2014 and while
still not officially depreciated, dnotify was officially "replaced"
by inotify in Linux 2.6.13 in 2005. Would be nice to sync this
requirement across the codebase.

V2: Init wd to -1 not 0
V3: Remove EV_PERSIST

Have been using V3 patch in production for the last year since a
few days after last V2 email.

diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
index 4811e0f..2dd9c31 100644
--- a/utils/idmapd/idmapd.c
+++ b/utils/idmapd/idmapd.c
@@ -36,7 +36,7 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
-#include <sys/poll.h>
+#include <sys/inotify.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <time.h>
@@ -205,15 +205,16 @@ static void usage(char *progname)
 int
 main(int argc, char **argv)
 {
-	int fd = 0, opt, fg = 0, nfsdret = -1;
+	int wd = -1, opt, fg = 0, nfsdret = -1;
 	struct idmap_clientq icq;
-	struct event rootdirev, clntdirev, svrdirev;
+	struct event rootdirev, clntdirev, svrdirev, inotifyev;
 	struct event initialize;
 	struct passwd *pw;
 	struct group *gr;
 	struct stat sb;
 	char *xpipefsdir = NULL;
 	int serverstart = 1, clientstart = 1;
+	int inotify_fd;
 	int ret;
 	char *progname;
 	char *conf_path = NULL;
@@ -373,18 +374,15 @@ main(int argc, char **argv)
 			}
 		}
 
-		if ((fd = open(pipefsdir, O_RDONLY)) == -1)
-			xlog_err("main: open(%s): %s", pipefsdir, strerror(errno));
-
-		if (fcntl(fd, F_SETSIG, SIGUSR1) == -1)
-			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
-
-		if (fcntl(fd, F_NOTIFY,
-			DN_CREATE | DN_DELETE | DN_MODIFY | DN_MULTISHOT) == -1) {
-			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
-			if (errno == EINVAL)
-				xlog_err("main: Possibly no Dnotify support in kernel.");
+		inotify_fd = inotify_init1(IN_NONBLOCK);
+		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);
+			if (wd < 0)
+				xlog_err("Unable to inotify_add_watch(%s): %s\n", pipefsdir, strerror(errno));
 		}
+
 		TAILQ_INIT(&icq);
 
 		/* These events are persistent */
@@ -394,6 +392,10 @@ main(int argc, char **argv)
 		signal_add(&clntdirev, NULL);
 		signal_set(&svrdirev, SIGHUP, svrreopen, NULL);
 		signal_add(&svrdirev, NULL);
+		if ( wd >= 0) {
+			event_set(&inotifyev, inotify_fd, EV_READ, dirscancb, &icq);
+			event_add(&inotifyev, NULL);
+		}
 
 		/* Fetch current state */
 		/* (Delay till start of event_dispatch to avoid possibly losing
@@ -402,7 +404,7 @@ main(int argc, char **argv)
 		evtimer_add(&initialize, &now);
 	}
 
-	if (nfsdret != 0 && fd == 0)
+	if (nfsdret != 0 && wd < 0)
 		xlog_err("main: Neither NFS client nor NFSd found");
 
 	daemon_ready();
-- 
2.16.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH V3] idmapd: Use inotify instead of dnotify
  2018-08-19 16:43   ` [PATCH V3] " Alan Swanson
@ 2018-08-20 19:00     ` J. Bruce Fields
  2018-10-05 11:07     ` Steve Dickson
  1 sibling, 0 replies; 5+ messages in thread
From: J. Bruce Fields @ 2018-08-20 19:00 UTC (permalink / raw)
  To: Alan Swanson; +Cc: linux-nfs

On Sun, Aug 19, 2018 at 05:43:42PM +0100, Alan Swanson wrote:
> Remove last use of dnotify in nfs-utils by bringing idmapd upto
> date with (required) inotify use by gssd and blkmapd.

OK by me.--b.

> ---
>  utils/idmapd/idmapd.c | 32 +++++++++++++++++---------------
>  1 file changed, 17 insertions(+), 15 deletions(-)
> 
> Got annoyed by the dnotify kernel requirement. Read the last
> discussion "DNOTIFY to INOTIFY migration" posted in 2014 and while
> still not officially depreciated, dnotify was officially "replaced"
> by inotify in Linux 2.6.13 in 2005. Would be nice to sync this
> requirement across the codebase.
> 
> V2: Init wd to -1 not 0
> V3: Remove EV_PERSIST
> 
> Have been using V3 patch in production for the last year since a
> few days after last V2 email.
> 
> diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
> index 4811e0f..2dd9c31 100644
> --- a/utils/idmapd/idmapd.c
> +++ b/utils/idmapd/idmapd.c
> @@ -36,7 +36,7 @@
>  
>  #include <sys/types.h>
>  #include <sys/time.h>
> -#include <sys/poll.h>
> +#include <sys/inotify.h>
>  #include <sys/socket.h>
>  #include <sys/stat.h>
>  #include <time.h>
> @@ -205,15 +205,16 @@ static void usage(char *progname)
>  int
>  main(int argc, char **argv)
>  {
> -	int fd = 0, opt, fg = 0, nfsdret = -1;
> +	int wd = -1, opt, fg = 0, nfsdret = -1;
>  	struct idmap_clientq icq;
> -	struct event rootdirev, clntdirev, svrdirev;
> +	struct event rootdirev, clntdirev, svrdirev, inotifyev;
>  	struct event initialize;
>  	struct passwd *pw;
>  	struct group *gr;
>  	struct stat sb;
>  	char *xpipefsdir = NULL;
>  	int serverstart = 1, clientstart = 1;
> +	int inotify_fd;
>  	int ret;
>  	char *progname;
>  	char *conf_path = NULL;
> @@ -373,18 +374,15 @@ main(int argc, char **argv)
>  			}
>  		}
>  
> -		if ((fd = open(pipefsdir, O_RDONLY)) == -1)
> -			xlog_err("main: open(%s): %s", pipefsdir, strerror(errno));
> -
> -		if (fcntl(fd, F_SETSIG, SIGUSR1) == -1)
> -			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
> -
> -		if (fcntl(fd, F_NOTIFY,
> -			DN_CREATE | DN_DELETE | DN_MODIFY | DN_MULTISHOT) == -1) {
> -			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
> -			if (errno == EINVAL)
> -				xlog_err("main: Possibly no Dnotify support in kernel.");
> +		inotify_fd = inotify_init1(IN_NONBLOCK);
> +		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);
> +			if (wd < 0)
> +				xlog_err("Unable to inotify_add_watch(%s): %s\n", pipefsdir, strerror(errno));
>  		}
> +
>  		TAILQ_INIT(&icq);
>  
>  		/* These events are persistent */
> @@ -394,6 +392,10 @@ main(int argc, char **argv)
>  		signal_add(&clntdirev, NULL);
>  		signal_set(&svrdirev, SIGHUP, svrreopen, NULL);
>  		signal_add(&svrdirev, NULL);
> +		if ( wd >= 0) {
> +			event_set(&inotifyev, inotify_fd, EV_READ, dirscancb, &icq);
> +			event_add(&inotifyev, NULL);
> +		}
>  
>  		/* Fetch current state */
>  		/* (Delay till start of event_dispatch to avoid possibly losing
> @@ -402,7 +404,7 @@ main(int argc, char **argv)
>  		evtimer_add(&initialize, &now);
>  	}
>  
> -	if (nfsdret != 0 && fd == 0)
> +	if (nfsdret != 0 && wd < 0)
>  		xlog_err("main: Neither NFS client nor NFSd found");
>  
>  	daemon_ready();
> -- 
> 2.16.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V3] idmapd: Use inotify instead of dnotify
  2018-08-19 16:43   ` [PATCH V3] " Alan Swanson
  2018-08-20 19:00     ` J. Bruce Fields
@ 2018-10-05 11:07     ` Steve Dickson
  1 sibling, 0 replies; 5+ messages in thread
From: Steve Dickson @ 2018-10-05 11:07 UTC (permalink / raw)
  To: Alan Swanson, linux-nfs

Hello,

On 8/19/18 12:43 PM, Alan Swanson wrote:
> Remove last use of dnotify in nfs-utils by bringing idmapd upto
> date with (required) inotify use by gssd and blkmapd.
Let me apologies for taking so long to get to this... 
Unfortunately it fell off my radar... In the future
please feel free to ping me directly. 

Committed... 

steved.

> ---
>  utils/idmapd/idmapd.c | 32 +++++++++++++++++---------------
>  1 file changed, 17 insertions(+), 15 deletions(-)
> 
> Got annoyed by the dnotify kernel requirement. Read the last
> discussion "DNOTIFY to INOTIFY migration" posted in 2014 and while
> still not officially depreciated, dnotify was officially "replaced"
> by inotify in Linux 2.6.13 in 2005. Would be nice to sync this
> requirement across the codebase.
> 
> V2: Init wd to -1 not 0
> V3: Remove EV_PERSIST
> 
> Have been using V3 patch in production for the last year since a
> few days after last V2 email.
> 
> diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
> index 4811e0f..2dd9c31 100644
> --- a/utils/idmapd/idmapd.c
> +++ b/utils/idmapd/idmapd.c
> @@ -36,7 +36,7 @@
>  
>  #include <sys/types.h>
>  #include <sys/time.h>
> -#include <sys/poll.h>
> +#include <sys/inotify.h>
>  #include <sys/socket.h>
>  #include <sys/stat.h>
>  #include <time.h>
> @@ -205,15 +205,16 @@ static void usage(char *progname)
>  int
>  main(int argc, char **argv)
>  {
> -	int fd = 0, opt, fg = 0, nfsdret = -1;
> +	int wd = -1, opt, fg = 0, nfsdret = -1;
>  	struct idmap_clientq icq;
> -	struct event rootdirev, clntdirev, svrdirev;
> +	struct event rootdirev, clntdirev, svrdirev, inotifyev;
>  	struct event initialize;
>  	struct passwd *pw;
>  	struct group *gr;
>  	struct stat sb;
>  	char *xpipefsdir = NULL;
>  	int serverstart = 1, clientstart = 1;
> +	int inotify_fd;
>  	int ret;
>  	char *progname;
>  	char *conf_path = NULL;
> @@ -373,18 +374,15 @@ main(int argc, char **argv)
>  			}
>  		}
>  
> -		if ((fd = open(pipefsdir, O_RDONLY)) == -1)
> -			xlog_err("main: open(%s): %s", pipefsdir, strerror(errno));
> -
> -		if (fcntl(fd, F_SETSIG, SIGUSR1) == -1)
> -			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
> -
> -		if (fcntl(fd, F_NOTIFY,
> -			DN_CREATE | DN_DELETE | DN_MODIFY | DN_MULTISHOT) == -1) {
> -			xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));
> -			if (errno == EINVAL)
> -				xlog_err("main: Possibly no Dnotify support in kernel.");
> +		inotify_fd = inotify_init1(IN_NONBLOCK);
> +		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);
> +			if (wd < 0)
> +				xlog_err("Unable to inotify_add_watch(%s): %s\n", pipefsdir, strerror(errno));
>  		}
> +
>  		TAILQ_INIT(&icq);
>  
>  		/* These events are persistent */
> @@ -394,6 +392,10 @@ main(int argc, char **argv)
>  		signal_add(&clntdirev, NULL);
>  		signal_set(&svrdirev, SIGHUP, svrreopen, NULL);
>  		signal_add(&svrdirev, NULL);
> +		if ( wd >= 0) {
> +			event_set(&inotifyev, inotify_fd, EV_READ, dirscancb, &icq);
> +			event_add(&inotifyev, NULL);
> +		}
>  
>  		/* Fetch current state */
>  		/* (Delay till start of event_dispatch to avoid possibly losing
> @@ -402,7 +404,7 @@ main(int argc, char **argv)
>  		evtimer_add(&initialize, &now);
>  	}
>  
> -	if (nfsdret != 0 && fd == 0)
> +	if (nfsdret != 0 && wd < 0)
>  		xlog_err("main: Neither NFS client nor NFSd found");
>  
>  	daemon_ready();
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-10-05 18:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-21 19:31 [PATCH] idmapd: Use inotify instead of dnotify Alan Swanson
2017-06-21 21:23 ` [PATCH V2] " Alan Swanson
2018-08-19 16:43   ` [PATCH V3] " Alan Swanson
2018-08-20 19:00     ` J. Bruce Fields
2018-10-05 11:07     ` Steve Dickson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.