All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: NeilBrown <neilb@suse.com>, Matt Benjamin <mbenjami@redhat.com>,
	Jeff Layton <jlayton@redhat.com>,
	"J . Bruce Fields" <bfields@fieldses.org>,
	Chuck Lever <chuck.lever@oracle.com>,
	Steve Dickson <steved@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH nfs-utils v3 13/14] nfsd: add --vsock (-v) option to nfsd
Date: Wed, 13 Sep 2017 11:26:49 +0100	[thread overview]
Message-ID: <20170913102650.10377-14-stefanha@redhat.com> (raw)
In-Reply-To: <20170913102650.10377-1-stefanha@redhat.com>

The following command-line serves NFSv4.1 over AF_VSOCK:

  nfsd -TU -N3 -V4.1 -v 2049

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 utils/nfsd/nfssvc.h |  1 +
 utils/nfsd/nfsd.c   | 18 +++++++++++++---
 utils/nfsd/nfssvc.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 utils/nfsd/nfsd.man |  4 ++++
 4 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/utils/nfsd/nfssvc.h b/utils/nfsd/nfssvc.h
index 39ebf37..1d251ca 100644
--- a/utils/nfsd/nfssvc.h
+++ b/utils/nfsd/nfssvc.h
@@ -26,6 +26,7 @@ int	nfssvc_set_sockets(const unsigned int protobits,
 			   const char *host, const char *port);
 void	nfssvc_set_time(const char *type, const int seconds);
 int	nfssvc_set_rdmaport(const char *port);
+int	nfssvc_set_vsock(const char *port);
 void	nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers4, unsigned int minorvers4set);
 int	nfssvc_threads(int nrservs);
 void	nfssvc_get_minormask(unsigned int *mask);
diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c
index f973203..7f527db 100644
--- a/utils/nfsd/nfsd.c
+++ b/utils/nfsd/nfsd.c
@@ -53,6 +53,7 @@ static struct option longopts[] =
 	{ "rdma", 2, 0, 'R' },
 	{ "grace-time", 1, 0, 'G'},
 	{ "lease-time", 1, 0, 'L'},
+	{ "vsock", 1, 0, 'v' },
 	{ NULL, 0, 0, 0 }
 };
 
@@ -61,6 +62,7 @@ main(int argc, char **argv)
 {
 	int	count = NFSD_NPROC, c, i, error = 0, portnum, fd, found_one;
 	char *p, *progname, *port, *rdma_port = NULL;
+	char *vsock_port = NULL;
 	char **haddr = NULL;
 	int hcounter = 0;
 	struct conf_list *hosts;
@@ -145,7 +147,7 @@ main(int argc, char **argv)
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "dH:hN:V:p:P:stTituUrG:L:", longopts, NULL)) != EOF) {
+	while ((c = getopt_long(argc, argv, "dH:hN:V:p:P:stTituUrG:L:v:", longopts, NULL)) != EOF) {
 		switch(c) {
 		case 'd':
 			xlog_config(D_ALL, 1);
@@ -180,7 +182,9 @@ main(int argc, char **argv)
 			else
 				rdma_port = "nfsrdma";
 			break;
-
+		case 'v': /* --vsock */
+			vsock_port = optarg;
+			break;
 		case 'N':
 			switch((c = strtol(optarg, &p, 0))) {
 			case 4:
@@ -309,7 +313,8 @@ main(int argc, char **argv)
 	}
 
 	if (NFSCTL_VERISSET(versbits, 4) &&
-	    !NFSCTL_TCPISSET(protobits)) {
+	    !NFSCTL_TCPISSET(protobits) &&
+	    !vsock_port) {
 		xlog(L_ERROR, "version 4 requires the TCP protocol");
 		exit(1);
 	}
@@ -353,6 +358,13 @@ main(int argc, char **argv)
 		if (!error)
 			socket_up = 1;
 	}
+
+	if (vsock_port) {
+		error = nfssvc_set_vsock(vsock_port);
+		if (!error)
+			socket_up = 1;
+	}
+
 set_threads:
 	/* don't start any threads if unable to hand off any sockets */
 	if (!socket_up) {
diff --git a/utils/nfsd/nfssvc.c b/utils/nfsd/nfssvc.c
index e8609c1..2fbdb48 100644
--- a/utils/nfsd/nfssvc.c
+++ b/utils/nfsd/nfssvc.c
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "vsock.h"
 #include "nfslib.h"
 #include "xlog.h"
 #include "nfssvc.h"
@@ -304,6 +305,67 @@ nfssvc_set_rdmaport(const char *port)
 	return ret;
 }
 
+int
+nfssvc_set_vsock(const char *port)
+{
+	struct sockaddr_vm svm;
+	int nport;
+	char buf[20];
+	int rc = 1;
+	int sockfd = -1;
+	int fd = -1;
+	char *ep;
+
+	nport = strtol(port, &ep, 10);
+	if (!*port || *ep) {
+		xlog(L_ERROR, "unable to interpret port name %s",
+		     port);
+		goto out;
+	}
+
+	sockfd = socket(AF_VSOCK, SOCK_STREAM, 0);
+	if (sockfd < 0) {
+		xlog(L_ERROR, "unable to create AF_VSOCK socket: "
+			      "errno %d (%m)", errno);
+		goto out;
+	}
+
+	svm.svm_family = AF_VSOCK;
+	svm.svm_port = nport;
+	svm.svm_cid = VMADDR_CID_ANY;
+
+	if (bind(sockfd, (struct sockaddr*)&svm, sizeof(svm))) {
+		xlog(L_ERROR, "unable to bind AF_VSOCK socket: "
+			      "errno %d (%m)", errno);
+		goto out;
+	}
+
+	if (listen(sockfd, 64)) {
+		xlog(L_ERROR, "unable to create listening socket: "
+			      "errno %d (%m)", errno);
+		goto out;
+	}
+
+	fd = open(NFSD_PORTS_FILE, O_WRONLY);
+	if (fd < 0) {
+		xlog(L_ERROR, "couldn't open ports file: errno "
+		     "%d (%m)", errno);
+		goto out;
+	}
+	snprintf(buf, sizeof(buf), "%d\n", sockfd);
+	if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) {
+		xlog(L_ERROR, "unable to request vsock services: %m");
+		goto out;
+	}
+	rc = 0;
+out:
+	if (fd != -1)
+		close(fd);
+	if (sockfd != -1)
+		close(sockfd);
+	return rc;
+}
+
 void
 nfssvc_set_time(const char *type, const int seconds)
 {
diff --git a/utils/nfsd/nfsd.man b/utils/nfsd/nfsd.man
index d83ef86..058a252 100644
--- a/utils/nfsd/nfsd.man
+++ b/utils/nfsd/nfsd.man
@@ -52,6 +52,10 @@ Listen for RDMA requests on an alternate port - may be a number or a
 name listed in
 .BR /etc/services .
 .TP
+.BI \-\-vsock= port
+Listen for vsock requests on a given port number.
+Requires NFS version 4.0 or later.
+.TP
 .B \-N " or " \-\-no-nfs-version vers
 This option can be used to request that 
 .B rpc.nfsd
-- 
2.13.5


  parent reply	other threads:[~2017-09-13 10:27 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-13 10:26 [PATCH nfs-utils v3 00/14] add NFS over AF_VSOCK support Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 01/14] mount: don't use IPPROTO_UDP for address resolution Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 02/14] nfs-utils: add vsock.h Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 03/14] nfs-utils: add AF_VSOCK support to sockaddr.h Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 04/14] mount: present AF_VSOCK addresses Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 05/14] mount: accept AF_VSOCK in nfs_verify_family() Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 06/14] mount: generate AF_VSOCK clientaddr Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 07/14] getport: recognize "vsock" netid Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 08/14] mount: AF_VSOCK address parsing Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 09/14] exportfs: introduce host_freeaddrinfo() Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 10/14] exportfs: add AF_VSOCK address parsing and printing Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 11/14] exportfs: add AF_VSOCK support to set_addrlist() Stefan Hajnoczi
2017-09-13 10:26 ` [PATCH nfs-utils v3 12/14] exportfs: add support for "vsock:" exports(5) syntax Stefan Hajnoczi
2017-09-13 10:26 ` Stefan Hajnoczi [this message]
2017-09-13 10:26 ` [PATCH nfs-utils v3 14/14] tests: add "vsock:" exports(5) test case Stefan Hajnoczi
2017-09-13 16:21 ` [PATCH nfs-utils v3 00/14] add NFS over AF_VSOCK support Christoph Hellwig
2017-09-13 18:18   ` [nfsv4] " David Noveck
2017-09-13 18:21     ` Chuck Lever
2017-09-15 11:52       ` Stefan Hajnoczi
2017-09-13 22:39 ` NeilBrown
2017-09-14 15:39 ` Steve Dickson
2017-09-14 15:55   ` Steve Dickson
2017-09-14 17:37     ` J . Bruce Fields
2017-09-15 11:07       ` Jeff Layton
2017-09-15 15:17         ` J . Bruce Fields
2017-09-15 23:29           ` NeilBrown
2017-09-16 14:55             ` J . Bruce Fields
2017-09-15 13:12       ` Stefan Hajnoczi
2017-09-15 13:31         ` J . Bruce Fields
2017-09-15 13:59           ` Chuck Lever
2017-09-15 16:42             ` J. Bruce Fields
2017-09-16 15:55               ` Chuck Lever
2017-09-18 18:09                 ` Stefan Hajnoczi
2017-09-19  9:31                   ` Daniel P. Berrange
2017-09-19 14:35                     ` Chuck Lever
2017-09-19 15:10                       ` Daniel P. Berrange
2017-09-19 15:48                         ` Chuck Lever
2017-09-19 16:44                           ` Daniel P. Berrange
2017-09-19 17:24                             ` J. Bruce Fields
2017-09-21 17:00                               ` Stefan Hajnoczi
2017-09-22  9:55                                 ` Steven Whitehouse
2017-09-22 11:32                                   ` Jeff Layton
2017-09-22 12:08                                     ` Matt Benjamin
2017-09-22 12:26                                       ` Jeff Layton
2017-09-22 15:28                                         ` Stefan Hajnoczi
2017-09-22 16:23                                           ` Daniel P. Berrange
2017-09-22 18:31                                             ` Chuck Lever
2017-09-25  8:14                                               ` Daniel P. Berrange
2017-09-25 10:31                                                 ` Chuck Lever
2017-09-22 11:43                                   ` Chuck Lever
2017-09-22 11:55                                     ` Daniel P. Berrange
2017-09-22 12:00                                       ` Chuck Lever
2017-09-22 12:10                                         ` Daniel P. Berrange
2017-09-22 19:14                                       ` J. Bruce Fields
2017-09-25  8:30                                         ` Daniel P. Berrange
2017-09-26  2:08                                       ` NeilBrown
2017-09-26  3:40                                         ` J. Bruce Fields
2017-09-26 10:56                                           ` Stefan Hajnoczi
2017-09-26 11:07                                             ` Daniel P. Berrange
2017-09-26 18:32                                             ` J. Bruce Fields
2017-09-27  0:45                                             ` NeilBrown
2017-09-27 13:05                                               ` Stefan Hajnoczi
2017-09-27 22:21                                                 ` NeilBrown
2017-09-28 10:44                                                   ` Stefan Hajnoczi
2017-09-27 13:35                                               ` J. Bruce Fields
2017-09-27 22:25                                                 ` NeilBrown
2017-09-26 13:39                                           ` J. Bruce Fields
2017-09-26 13:42                                             ` J. Bruce Fields
2017-09-27 12:22                                               ` Stefan Hajnoczi
2017-09-27 13:46                                                 ` J. Bruce Fields
2017-09-28 10:34                                                   ` Stefan Hajnoczi
2017-09-19 17:37                             ` Stefan Hajnoczi
2017-09-19 19:56                             ` Chuck Lever
2017-09-19 20:42                               ` J. Bruce Fields
2017-09-19 21:09                                 ` Chuck Lever
2017-09-20 13:16                                   ` J. Bruce Fields
2017-09-20 14:40                                     ` Chuck Lever
2017-09-20 14:45                                       ` J. Bruce Fields
2017-09-20 14:59                                         ` Chuck Lever
2017-09-20 15:25                                           ` Frank Filz
2017-09-20 18:17                                             ` Trond Myklebust
2017-09-20 18:34                                               ` bfields
2017-09-20 18:38                                                 ` Trond Myklebust
2017-09-21 16:20                                                 ` Stefan Hajnoczi
2017-09-20 14:58                                     ` Daniel P. Berrange
2017-09-20 16:39                                       ` J. Bruce Fields

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=20170913102650.10377-14-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=mbenjami@redhat.com \
    --cc=neilb@suse.com \
    --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 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.