From: Jeff Layton <jlayton@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: chuck.lever@oracle.com, steved@redhat.com
Subject: [PATCH 2/6] nfs-utils: break up nfssvc.c into more individually callable functions
Date: Tue, 26 May 2009 11:15:47 -0400 [thread overview]
Message-ID: <1243350951-13462-3-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1243350951-13462-1-git-send-email-jlayton@redhat.com>
nfssvc.c contains functions for starting up knfsd. Currently, the only
non-static function in that file is nfssvc(). In order to add IPv6
support, we'll need to be able to call some of these functions in a
more granular fashion.
Reorganize these functions and add prototypes to the header so that
they can be called individually, and change the nfsd program to call
those routines individually.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
support/include/nfslib.h | 6 +++-
support/nfs/nfssvc.c | 75 +++++++++++++++++++++++++---------------------
utils/nfsd/nfsd.c | 17 ++++++++++-
3 files changed, 62 insertions(+), 36 deletions(-)
diff --git a/support/include/nfslib.h b/support/include/nfslib.h
index ae98650..0bfb2ee 100644
--- a/support/include/nfslib.h
+++ b/support/include/nfslib.h
@@ -130,7 +130,11 @@ int wildmat(char *text, char *pattern);
* nfsd library functions.
*/
int nfsctl(int, struct nfsctl_arg *, union nfsctl_res *);
-int nfssvc(int port, int nrservs, unsigned int versbits, int minorvers4, unsigned int portbits, char *haddr);
+int nfssvc_inuse(void);
+void nfssvc_setfds(unsigned int ctlbits, struct sockaddr *sa,
+ socklen_t addrlen);
+void nfssvc_setvers(unsigned int ctlbits, int minorvers4);
+int nfssvc_threads(unsigned short port, int nrservs);
int nfsaddclient(struct nfsctl_client *clp);
int nfsdelclient(struct nfsctl_client *clp);
int nfsexport(struct nfsctl_export *exp);
diff --git a/support/nfs/nfssvc.c b/support/nfs/nfssvc.c
index 33c15a7..c2c5480 100644
--- a/support/nfs/nfssvc.c
+++ b/support/nfs/nfssvc.c
@@ -25,44 +25,55 @@
#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;
- /* 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.
- */
+ return 1;
+
+ return 0;
+}
+
+void
+nfssvc_setfds(unsigned int ctlbits, struct sockaddr *sa, socklen_t addrlen)
+{
+ int fd, on = 1;
+ char buf[BUFSIZ];
+ int udpfd = -1, tcpfd = -1;
+
fd = open(NFSD_PORTS_FILE, O_WRONLY);
if (fd < 0)
return;
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
- sin.sin_addr.s_addr = inet_addr(haddr);
if (NFSCTL_UDPISSET(ctlbits)) {
udpfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (udpfd < 0) {
- syslog(LOG_ERR, "nfssvc: unable to create UPD socket: "
+ syslog(LOG_ERR, "nfssvc: unable to create UDP socket: "
"errno %d (%s)\n", errno, strerror(errno));
exit(1);
}
- if (bind(udpfd, (struct sockaddr *)&sin, sizeof(sin)) < 0){
- syslog(LOG_ERR, "nfssvc: unable to bind UPD socket: "
+ if (bind(udpfd, sa, addrlen) < 0) {
+ syslog(LOG_ERR, "nfssvc: unable to bind UDP socket: "
"errno %d (%s)\n", errno, strerror(errno));
exit(1);
}
@@ -71,7 +82,7 @@ nfssvc_setfds(int port, unsigned int ctlbits, char *haddr)
if (NFSCTL_TCPISSET(ctlbits)) {
tcpfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (tcpfd < 0) {
- syslog(LOG_ERR, "nfssvc: unable to createt tcp socket: "
+ syslog(LOG_ERR, "nfssvc: unable to create TCP socket: "
"errno %d (%s)\n", errno, strerror(errno));
exit(1);
}
@@ -80,7 +91,7 @@ nfssvc_setfds(int port, unsigned int ctlbits, char *haddr)
"errno %d (%s)\n", errno, strerror(errno));
exit(1);
}
- if (bind(tcpfd, (struct sockaddr *)&sin, sizeof(sin)) < 0){
+ if (bind(tcpfd, sa, addrlen) < 0) {
syslog(LOG_ERR, "nfssvc: unable to bind TCP socket: "
"errno %d (%s)\n", errno, strerror(errno));
exit(1);
@@ -111,12 +122,15 @@ nfssvc_setfds(int port, unsigned int ctlbits, char *haddr)
errno, strerror(errno));
}
}
- close(fd);
+
+ if (fd >= 0)
+ close(fd);
return;
}
-static void
-nfssvc_versbits(unsigned int ctlbits, int minorvers4)
+
+void
+nfssvc_setvers(unsigned int ctlbits, int minorvers4)
{
int fd, n, off;
char buf[BUFSIZ], *ptr;
@@ -147,20 +161,13 @@ nfssvc_versbits(unsigned int ctlbits, int minorvers4)
return;
}
+
int
-nfssvc(int port, int nrservs, unsigned int versbits, int minorvers4,
- unsigned protobits, char *haddr)
+nfssvc_threads(unsigned short port, int nrservs)
{
struct nfsctl_arg arg;
int fd;
- /* Note: must set versions before fds so that
- * the ports get registered with portmap against correct
- * versions
- */
- nfssvc_versbits(versbits, minorvers4);
- nfssvc_setfds(port, protobits, haddr);
-
fd = open(NFSD_THREAD_FILE, O_WRONLY);
if (fd < 0)
fd = open("/proc/fs/nfs/threads", O_WRONLY);
diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c
index e3c0094..ec6c49a 100644
--- a/utils/nfsd/nfsd.c
+++ b/utils/nfsd/nfsd.c
@@ -51,6 +51,7 @@ main(int argc, char **argv)
struct servent *ent;
struct hostent *hp;
char *p;
+ struct sockaddr_in sin;
ent = getservbyname ("nfs", "udp");
if (ent != NULL)
@@ -163,8 +164,22 @@ main(int argc, char **argv)
}
closeall(3);
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(port);
+ sin.sin_addr.s_addr = inet_addr(haddr);
+
+ /*
+ * must set versions before the fd's so that the right versions get
+ * registered with rpcbind. Note that on older kernels w/o the right
+ * interfaces, these are a no-op.
+ */
+ if (!nfssvc_inuse()) {
+ nfssvc_setvers(versbits, minorvers4);
+ nfssvc_setfds(protobits, (struct sockaddr *) &sin, sizeof(sin));
+ }
+
openlog("nfsd", LOG_PID, LOG_DAEMON);
- if ((error = nfssvc(port, count, versbits, minorvers4, protobits, haddr)) < 0) {
+ if ((error = nfssvc_threads(port, count)) < 0) {
int e = errno;
syslog(LOG_ERR, "nfssvc: %s", strerror(e));
closelog();
--
1.6.0.6
next prev parent reply other threads:[~2009-05-26 15:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-26 15:15 [PATCH 0/6] nfs-utils: add IPv6 support for rpc.nfsd (try #2) Jeff Layton
2009-05-26 15:15 ` [PATCH 1/6] nfs-utils: don't link libexport.a and libmisc.a to nfsd Jeff Layton
2009-05-26 15:15 ` Jeff Layton [this message]
2009-05-26 15:15 ` [PATCH 3/6] nfs-utils: set IPV6_V6ONLY on nfssvc IPv6 sockets Jeff Layton
2009-05-26 15:15 ` [PATCH 4/6] nfs-utils: add IPv6 support to nfsd Jeff Layton
2009-05-26 15:24 ` Chuck Lever
2009-05-26 16:49 ` Jeff Layton
[not found] ` <20090526124907.4b711eaa-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2009-05-26 17:31 ` Chuck Lever
2009-05-26 17:56 ` Jeff Layton
2009-05-26 15:15 ` [PATCH 5/6] nfs-utils: limit protocols and families used by nfsd to those listed in /etc/netconfig Jeff Layton
2009-05-26 15:15 ` [PATCH 6/6] nfs-utils: add -4 and -6 options to nfsd manpage Jeff Layton
2009-05-26 15:24 ` [PATCH 0/6] nfs-utils: add IPv6 support for rpc.nfsd (try #2) Chuck Lever
2009-05-26 17:08 ` 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=1243350951-13462-3-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