public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: chuck.lever@oracle.com, steved@redhat.com
Subject: [PATCH 05/10] nfs-utils: move check for active knfsd to helper function
Date: Wed,  3 Jun 2009 15:52:38 -0400	[thread overview]
Message-ID: <1244058763-10352-6-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1244058763-10352-1-git-send-email-jlayton@redhat.com>

nfssvc_setfds checks to see if knfsd is already running. Move this
check to a helper function. Eventually the nfsd code will call this
directly.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 support/nfs/nfssvc.c |   44 +++++++++++++++++++++++++++++++-------------
 1 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/support/nfs/nfssvc.c b/support/nfs/nfssvc.c
index 3e6bd31..8b15c4d 100644
--- a/support/nfs/nfssvc.c
+++ b/support/nfs/nfssvc.c
@@ -24,28 +24,46 @@
 #define NFSD_VERS_FILE    "/proc/fs/nfsd/versions"
 #define NFSD_THREAD_FILE  "/proc/fs/nfsd/threads"
 
-static void
-nfssvc_setfds(int port, unsigned int ctlbits, char *haddr)
+/*
+ * Are there already sockets configured? If not, then it is safe to try to
+ * open some and pass them through.
+ *
+ * Note: If the user explicitly asked for 'udp', then we should probably check
+ * if that is open, and should open it if not. However we don't yet. All
+ * sockets have to be opened when the first daemon is started.
+ */
+int
+nfssvc_inuse(void)
 {
-	int fd, n, on=1;
+	int fd, n;
 	char buf[BUFSIZ];
-	int udpfd = -1, tcpfd = -1;
-	struct sockaddr_in sin;
 
 	fd = open(NFSD_PORTS_FILE, O_RDONLY);
+
+	/* problem opening file, assume that nothing is configured */
 	if (fd < 0)
-		return;
+		return 0;
+
 	n = read(fd, buf, BUFSIZ);
 	close(fd);
+
 	if (n != 0)
+		return 1;
+
+	return 0;
+}
+
+static void
+nfssvc_setfds(int port, unsigned int ctlbits, char *haddr)
+{
+	int fd, n, on=1;
+	char buf[BUFSIZ];
+	int udpfd = -1, tcpfd = -1;
+	struct sockaddr_in sin;
+
+	if (nfssvc_inuse())
 		return;
-	/* there are no ports currently open, so it is safe to
-	 * try to open some and pass them through.
-	 * Note: If the user explicitly asked for 'udp', then
-	 * we should probably check if that is open, and should
-	 * open it if not.  However we don't yet.  All sockets
-	 * have to be opened when the first daemon is started.
-	 */
+
 	fd = open(NFSD_PORTS_FILE, O_WRONLY);
 	if (fd < 0)
 		return;
-- 
1.6.2.2


  parent reply	other threads:[~2009-06-03 19:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-03 19:52 [PATCH 00/10] nfs-utils: add IPv6 support to rpc.nfsd (try #5) Jeff Layton
2009-06-03 19:52 ` [PATCH 01/10] nfs-utils: don't link libexport.a and libmisc.a to nfsd Jeff Layton
2009-06-03 19:52 ` [PATCH 02/10] nfs-utils: clean up option parsing in nfsd.c Jeff Layton
2009-06-03 19:52 ` [PATCH 03/10] nfs-utils: convert rpc.nfsd to use xlog() Jeff Layton
2009-06-03 20:01   ` Chuck Lever
2009-06-03 20:22     ` Jeff Layton
     [not found]       ` <20090603162214.2aeed744-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2009-06-03 20:25         ` Steve Dickson
2009-06-03 20:31         ` Jeff Layton
     [not found]   ` <7968D2B9-3E31-4E0D-9D0B-309D757A0014@oracle.com>
2009-06-04 20:25     ` Jeff Layton
     [not found]       ` <20090604162534.15db803a-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2009-06-04 20:38         ` Chuck Lever
2009-06-03 19:52 ` [PATCH 04/10] nfs-utils: clean up NFSCTL_* macros for handling protocol bits Jeff Layton
2009-06-03 19:52 ` Jeff Layton [this message]
2009-06-04 20:00   ` [PATCH 05/10] nfs-utils: move check for active knfsd to helper function Chuck Lever
2009-06-04 20:29     ` Jeff Layton
2009-06-03 19:52 ` [PATCH 06/10] nfs-utils: convert nfssvc_setfds to use getaddrinfo Jeff Layton
2009-06-04 20:17   ` Chuck Lever
2009-06-04 20:36     ` Jeff Layton
2009-06-03 19:52 ` [PATCH 07/10] nfs-utils: break up the nfssvc interface Jeff Layton
2009-06-03 19:52 ` [PATCH 08/10] nfs-utils: add IPv6 support to nfssvc_setfds Jeff Layton
2009-06-03 20:08   ` Chuck Lever
2009-06-03 20:16     ` Steve Dickson
     [not found]       ` <4A26DA3B.3090404-AfCzQyP5zfLQT0dZR+AlfA@public.gmane.org>
2009-06-03 20:20         ` Steve Dickson
2009-06-03 20:24         ` Chuck Lever
2009-06-04 21:00   ` Chuck Lever
2009-06-03 19:52 ` [PATCH 09/10] nfs-utils: add IPv6 support to nfsd Jeff Layton
2009-06-03 19:52 ` [PATCH 10/10] nfs-utils: update the nfsd manpage Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1244058763-10352-6-git-send-email-jlayton@redhat.com \
    --to=jlayton@redhat.com \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox