NFS: add AF_VSOCK support to NFS client
Subsystems (10)
RFC 1/10 SUNRPC: add AF_VSOCK support to addr.h
In reply to a message not in the archiveAF_VSOCK addresses are a Context ID (CID) and port number tuple. The CID is a unique address, similar to a IP address on a local subnet.
Extend the addr.h functions to handle AF_VSOCK addresses.
--- include/linux/sunrpc/addr.h | 6 +++++ net/sunrpc/addr.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+)
include/linux/sunrpc/addr.h +6 -0
@@ -10,6 +10,7 @@#include <linux/socket.h> #include <linux/in.h> #include <linux/in6.h> +#include <linux/vm_sockets.h> #include <net/ipv6.h> size_t rpc_ntop (const struct sockaddr *,char *,const size_t );
@@ -26,6 +27,8 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)return ntohs (((struct sockaddr_in *)sap)->sin_port);case AF_INET6 :return ntohs (((struct sockaddr_in6 *)sap)->sin6_port); +case AF_VSOCK : +return ((struct sockaddr_vm *)sap)->svm_port; }return 0 ; }
@@ -40,6 +43,9 @@ static inline void rpc_set_port(struct sockaddr *sap,case AF_INET6 : ((struct sockaddr_in6 *)sap)->sin6_port =htons (port);break ; +case AF_VSOCK : + ((struct sockaddr_vm *)sap)->svm_port = port; +break ; } }
net/sunrpc/addr.c +57 -0
92 lines not on this page · raw message
Signature · 6 lines
2.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 2/10 SUNRPC: rename "TCP" record parser to "stream" parser
In reply to a message not in the archiveThe TCP record parser is really a RFC 1831 record fragment parser. There is nothing TCP protocol-specific about parsing record fragments. The parser can be reused for any SOCK_STREAM socket.
This patch renames functions and fields but xs_stream_data_ready() still calls tcp_read_sock(). This is addressed in the next patch.
--- include/linux/sunrpc/xprtsock.h | 31 ++--- include/trace/events/sunrpc.h | 30 ++--- net/sunrpc/xprtsock.c | 276 ++++++++++++++++++++-------------------- 3 files changed, 169 insertions(+), 168 deletions(-)
include/linux/sunrpc/xprtsock.h +16 -15
@@ -27,17 +27,18 @@ struct sock_xprt {struct sock * inet;/* -* State of TCP reply receive +* State of SOCK_STREAM reply receive */ -__be32 tcp_fraghdr, - tcp_xid, - tcp_calldir; +__be32 stream_fraghdr, + stream_xid, + stream_calldir; -u32 tcp_offset, - tcp_reclen; +u32 stream_offset, + stream_reclen; + +unsigned long stream_copied, + stream_flags; -unsigned long tcp_copied, - tcp_flags;/* * Connection of transports
@@ -64,17 +65,17 @@ struct sock_xprt {/* * TCP receive state flags */ -#define TCP_RCV_LAST_FRAG (1UL << 0) -#define TCP_RCV_COPY_FRAGHDR (1UL << 1) -#define TCP_RCV_COPY_XID (1UL << 2) -#define TCP_RCV_COPY_DATA (1UL << 3) -#define TCP_RCV_READ_CALLDIR (1UL << 4) -#define TCP_RCV_COPY_CALLDIR (1UL << 5) +#define STREAM_RCV_LAST_FRAG (1UL << 0) +#define STREAM_RCV_COPY_FRAGHDR (1UL << 1) +#define STREAM_RCV_COPY_XID (1UL << 2) +#define STREAM_RCV_COPY_DATA (1UL << 3) +#define STREAM_RCV_READ_CALLDIR (1UL << 4) +#define STREAM_RCV_COPY_CALLDIR (1UL << 5)/* * TCP RPC flags */ -#define TCP_RPC_REPLY (1UL << 6) +#define STREAM_RPC_REPLY (1UL << 6)#endif /* __KERNEL__ */
include/trace/events/sunrpc.h +15 -15
@@ -371,7 +371,7 @@ DEFINE_EVENT(rpc_xprt_event, xprt_complete_rqst, TP_PROTO(struct rpc_xprt *xprt, __be32 xid, int status), TP_ARGS(xprt, xid, status)); -TRACE_EVENT(xs_tcp_data_ready, +TRACE_EVENT(xs_stream_data_ready, TP_PROTO(struct rpc_xprt *xprt, int err, unsigned int total), TP_ARGS(xprt, err, total),
@@ -400,15 +400,15 @@ TRACE_EVENT(xs_tcp_data_ready,#define rpc_show_sock_xprt_flags (flags) \ __print_flags(flags, "|", \ - { TCP_RCV_LAST_FRAG, "TCP_RCV_LAST_FRAG" }, \ - { TCP_RCV_COPY_FRAGHDR, "TCP_RCV_COPY_FRAGHDR" }, \ - { TCP_RCV_COPY_XID, "TCP_RCV_COPY_XID" }, \ - { TCP_RCV_COPY_DATA, "TCP_RCV_COPY_DATA" }, \ - { TCP_RCV_READ_CALLDIR, "TCP_RCV_READ_CALLDIR" }, \ - { TCP_RCV_COPY_CALLDIR, "TCP_RCV_COPY_CALLDIR" }, \ - { TCP_RPC_REPLY, "TCP_RPC_REPLY" }) - -TRACE_EVENT(xs_tcp_data_recv, + { STREAM_RCV_LAST_FRAG, "STREAM_RCV_LAST_FRAG" }, \ + { STREAM_RCV_COPY_FRAGHDR, "STREAM_RCV_COPY_FRAGHDR" }, \ + { STREAM_RCV_COPY_XID, "STREAM_RCV_COPY_XID" }, \ + { STREAM_RCV_COPY_DATA, "STREAM_RCV_COPY_DATA" }, \ + { STREAM_RCV_READ_CALLDIR, "STREAM_RCV_READ_CALLDIR" }, \ + { STREAM_RCV_COPY_CALLDIR, "STREAM_RCV_COPY_CALLDIR" }, \ + { STREAM_RPC_REPLY, "STREAM_RPC_REPLY" }) + +TRACE_EVENT(xs_stream_data_recv, TP_PROTO(struct sock_xprt *xs), TP_ARGS(xs),
@@ -426,11 +426,11 @@ TRACE_EVENT(xs_tcp_data_recv,TP_fast_assign ( __assign_str(addr, xs->xprt.address_strings[RPC_DISPLAY_ADDR]);__assign_str (port, xs->xprt.address_strings[RPC_DISPLAY_PORT ]); - __entry->xid = xs->tcp_xid; - __entry->flags = xs->tcp_flags; - __entry->copied = xs->tcp_copied; - __entry->reclen = xs->tcp_reclen; - __entry->offset = xs->tcp_offset; + __entry->xid = xs->stream_xid; + __entry->flags = xs->stream_flags; + __entry->copied = xs->stream_copied; + __entry->reclen = xs->stream_reclen; + __entry->offset = xs->stream_offset; ), TP_printk("peer=[%s]:%s xid=0x%x flags=%s copied=%lu reclen=%u offset=%lu",
net/sunrpc/xprtsock.c +138 -138
523 lines not on this page · raw message
Signature · 6 lines
2.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 7/10 SUNRPC: restrict backchannel svc IPPROTO_TCP check to IP
In reply to a message not in the archiveThe IPPROTO_TCP check only applies to AF_INET and AF_INET6.
--- net/sunrpc/svc.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
net/sunrpc/svc.c +10 -3
@@ -1365,9 +1365,16 @@ bc_svc_process(struct svc_serv *serv, struct rpc_rqst *req,/* reset result send buffer "put" position */ resv->iov_len =0 ; -if (rqstp->rq_prot !=IPPROTO_TCP ) { -printk (KERN_ERR "No support for Non-TCP transports!\n" ); -BUG (); +switch (((struct sockaddr *)&rqstp->rq_addr)->sa_family) { +case AF_INET : +case AF_INET6 : +if (rqstp->rq_prot !=IPPROTO_TCP ) { +printk (KERN_ERR "No support for Non-TCP transports!\n" ); +BUG (); + } +break ; +default : +break ; }/*
Signature · 6 lines
2.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Stefan Hajnoczi
maintainercover NFS: add AF_VSOCK support to NFS client
This patch series enables AF_VSOCK address family support in the NFS client. Please use the https://github.com/stefanha/linux.git vsock-nfs branch, which contains the dependencies for this series.
The AF_VSOCK address family provides dgram and stream socket communication between virtual machines and hypervisors. A VMware VMCI transport is currently available in-tree (see net/vmw_vsock) and I have posted virtio-vsock patches for use with QEMU/KVM: http://thread.gmane.org/gmane.linux.network/365205
The goal of this work is sharing files between virtual machines and hypervisors. AF_VSOCK is well-suited to this because it requires no configuration inside the virtual machine, making it simple to manage and reliable.
Why NFS over AF_VSOCK?
----------------------
It is unusual to add a new NFS transport, only TCP, RDMA, and UDP are currently supported. Here is the rationale for adding AF_VSOCK.
Sharing files with a virtual machine can be configured manually:
1. Add a dedicated network card to the virtual machine. It will be used for NFS traffic.
2. Configure a local subnet and assign IP addresses to the virtual machine and hypervisor
3. Configure an NFS export on the hypervisor and start the NFS server
4. Mount the export inside the virtual machine
Automating these steps poses a problem: modifying network configuration inside the virtual machine is invasive. It's hard to add a network interface to an arbitrary running system in an automated fashion, considering the network management tools, firewall rules, IP address usage, etc.
Furthermore, the user may disrupt file sharing by accident when they add firewall rules, restart networking, etc because the NFS network interface is visible alongside the network interfaces managed by the user.
AF_VSOCK is a zero-configuration network transport that avoids these problems. Adding it to a virtual machine is non-invasive. It also avoids accidental misconfiguration by the user. This is why "guest agents" and other services in various hypervisors (KVM, Xen, VMware, VirtualBox) do not use regular network interfaces.
This is why AF_VSOCK is appropriate for providing shared files as a hypervisor service.
The approach in this series
---------------------------AF_VSOCK stream sockets can be used for NFSv4.1 much in the same way as TCP. RFC 1831 record fragments divide messages since SOCK_STREAM semantics are present. The backchannel shares the connection just like the default TCP configuration.
Addresses are <Context ID, Port Number> pairs. These patches use "vsock:<cid>" string representation to distinguish AF_VSOCK addresses from IPv4 and IPv6 numeric addresses.
The patches cover the following areas:
Patch 1 - support struct sockaddr_vm in sunrpc addr.h
Patch 2-4 - make sunrpc TCP record fragment parser reusable for any stream
socket
Patch 5 - add tcp_read_sock()-like interface to AF_VSOCK sockets
Patch 6 - extend sunrpc xprtsock.c for AF_VSOCK RPC clients
Patch 7-9 - AF_VSOCK backchannel support
Patch 10 - add AF_VSOCK support to NFS client
The following example mounts /export from the hypervisor (CID 2) inside the virtual machine (CID 3):
# /sbin/mount.nfs 2:/export /mnt -o clientaddr=3,proto=vsock
Status
------
I am looking for feedback on this approach. There are TODOs remaining in the code.
Hopefully the way I add AF_VSOCK support to sunrpc is reasonable and something that can be standardized (a netid assigned and the uaddr string format decided).
See below for the nfs-utils patch. It can be made nice once glibc getnameinfo()/getaddrinfo() support AF_VSOCK.
The vsock_read_sock() implementation is dumb. Less of a NFS/SUNRPC issue and more of a vsock issue, but perhaps virtio_transport.c should use skbs for its receive queue instead of a custom packet struct. That would eliminate memory allocation and copying in vsock_read_sock().
The next step is tackling NFS server. In the meantime, I have tested the patches using the nc-vsock netcat-like utility that is available in my Linux kernel repo below.
Repositories
------------
* Linux kernel: https://github.com/stefanha/linux.git vsock-nfs
* QEMU virtio-vsock device: https://github.com/stefanha/qemu.git vsock
* nfs-utils vsock: https://github.com/stefanha/nfs-utils.git vsock
Stefan Hajnoczi (10):
SUNRPC: add AF_VSOCK support to addr.h
SUNRPC: rename "TCP" record parser to "stream" parser
SUNRPC: abstract tcp_read_sock() in record fragment parser
SUNRPC: extract xs_stream_reset_state()
VSOCK: add tcp_read_sock()-like vsock_read_sock() function
SUNRPC: add AF_VSOCK support to xprtsock.c
SUNRPC: restrict backchannel svc IPPROTO_TCP check to IP
SUNRPC: add vsock-bc backchannel
SUNRPC: add AF_VSOCK support to svc_xprt.c
NFS: add AF_VSOCK support to NFS client
drivers/vhost/vsock.c | 1 + fs/nfs/callback.c | 7 +- fs/nfs/client.c | 16 + fs/nfs/super.c | 10 + include/linux/sunrpc/addr.h | 6 + include/linux/sunrpc/svc_xprt.h | 12 + include/linux/sunrpc/xprt.h | 1 + include/linux/sunrpc/xprtsock.h | 37 +- include/linux/virtio_vsock.h | 4 + include/net/af_vsock.h | 5 + include/trace/events/sunrpc.h | 30 +- net/sunrpc/addr.c | 57 +++ net/sunrpc/svc.c | 13 +- net/sunrpc/svc_xprt.c | 13 + net/sunrpc/svcsock.c | 48 ++- net/sunrpc/xprtsock.c | 693 +++++++++++++++++++++++++------- net/vmw_vsock/af_vsock.c | 15 + net/vmw_vsock/virtio_transport.c | 1 + net/vmw_vsock/virtio_transport_common.c | 55 +++ net/vmw_vsock/vmci_transport.c | 8 + 20 files changed, 825 insertions(+), 207 deletions(-)
Signature · 1 line
2.4.2
Stefan Hajnoczi
maintainerRFC 3/10 SUNRPC: abstract tcp_read_sock() in record fragment parser
Use a function pointer to abstract tcp_read_sock()-like functions. For TCP this function will be tcp_read_sock(). For AF_VSOCK it will be vsock_read_sock().
--- include/linux/sunrpc/xprtsock.h | 6 ++++++ net/sunrpc/xprtsock.c | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
include/linux/sunrpc/xprtsock.h +6 -0
@@ -9,6 +9,9 @@#ifdef __KERNEL__ +/* TODO why does this header have no includes? */ +#include <net/tcp.h> /* for sk_read_actor_t */ +int init_socket_xprt (void );void cleanup_socket_xprt (void );
@@ -39,6 +42,9 @@ struct sock_xprt {unsigned long stream_copied, stream_flags; +int (*stream_read_sock)(struct sock *, +read_descriptor_t *, +sk_read_actor_t );/* * Connection of transports
net/sunrpc/xprtsock.c +7 -1
@@ -1395,6 +1395,7 @@ static int xs_stream_data_recv(read_descriptor_t *rd_desc, struct sk_buff *skb,static void xs_stream_data_ready (struct sock *sk) {struct rpc_xprt *xprt; +struct sock_xprt *transport;read_descriptor_t rd_desc;int read;unsigned long total =0 ;
@@ -1406,6 +1407,9 @@ static void xs_stream_data_ready(struct sock *sk) read =0 ; goto out; } + + transport = container_of(xprt, struct sock_xprt, xprt); +/* Any data means we had a useful conversation, so * the we don't need to delay the next reconnect */
@@ -1416,7 +1420,8 @@ static void xs_stream_data_ready(struct sock *sk) rd_desc.arg.data = xprt;do { rd_desc.count =65536 ; - read =tcp_read_sock (sk, &rd_desc, xs_stream_data_recv); + read = transport->stream_read_sock (sk, &rd_desc, + xs_stream_data_recv);if (read >0 ) total += read; }while (read >0 );
@@ -1458,6 +1463,7 @@ static void xs_tcp_state_change(struct sock *sk) transport->stream_copied =0 ; transport->stream_flags =STREAM_RCV_COPY_FRAGHDR |STREAM_RCV_COPY_XID ; + transport->stream_read_sock = tcp_read_sock; xprt->connect_cookie++;xprt_wake_pending_tasks (xprt, -EAGAIN );
Signature · 1 line
2.4.2
Stefan Hajnoczi
maintainerRFC 4/10 SUNRPC: extract xs_stream_reset_state()
In reply to Stefan HajnocziExtract a function to reset the record fragment parser.
--- net/sunrpc/xprtsock.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
net/sunrpc/xprtsock.c +23 -10
@@ -1431,6 +1431,28 @@ out: }/** +* xs_stream_reset_state - reset SOCK_STREAM record parser +* @transport: socket transport +* @read_sock: tcp_read_sock()-like function +* +*/ +static void xs_stream_reset_state (struct rpc_xprt *xprt, +int (*read_sock)(struct sock *, +read_descriptor_t *, +sk_read_actor_t )) +{ +struct sock_xprt *transport =container_of (xprt, + struct sock_xprt, xprt); + + transport->stream_offset =0 ; + transport->stream_reclen =0 ; + transport->stream_copied =0 ; + transport->stream_flags = +STREAM_RCV_COPY_FRAGHDR |STREAM_RCV_COPY_XID ; + transport->stream_read_sock = read_sock; +} + +/** * xs_tcp_state_change - callback to handle TCP socket state changes * @sk: socket whose state has changed *
@@ -1454,16 +1476,7 @@ static void xs_tcp_state_change(struct sock *sk)case TCP_ESTABLISHED :spin_lock (&xprt->transport_lock);if (!xprt_test_and_set_connected (xprt)) { -struct sock_xprt *transport =container_of (xprt, - struct sock_xprt, xprt); - -/* Reset stream record info */ - transport->stream_offset =0 ; - transport->stream_reclen =0 ; - transport->stream_copied =0 ; - transport->stream_flags = -STREAM_RCV_COPY_FRAGHDR |STREAM_RCV_COPY_XID ; - transport->stream_read_sock = tcp_read_sock; +xs_stream_reset_state (xprt, tcp_read_sock); xprt->connect_cookie++;xprt_wake_pending_tasks (xprt, -EAGAIN );
Signature · 1 line
2.4.2
Stefan Hajnoczi
maintainerRFC 5/10 VSOCK: add tcp_read_sock()-like vsock_read_sock() function
In reply to Stefan HajnocziThe tcp_read_sock() interface dequeues skbs and gives them to the caller's callback function for processing. This interface can avoid data copies since the caller accesses the skb instead of using its own receive buffer.
This patch implements vsock_read_sock() for AF_VSOCK SOCK_STREAM sockets. The implementation is only for virtio-vsock at this time, not for the VMware VMCI transport. It is not zero-copy yet because the virtio-vsock receive queue does not consist of skbs.
The tcp_read_sock()-like interface is needed for AF_VSOCK sunrpc support.
--- drivers/vhost/vsock.c | 1 + include/linux/virtio_vsock.h | 4 +++ include/net/af_vsock.h | 5 +++ net/vmw_vsock/af_vsock.c | 15 +++++++++ net/vmw_vsock/virtio_transport.c | 1 + net/vmw_vsock/virtio_transport_common.c | 55 +++++++++++++++++++++++++++++++++ net/vmw_vsock/vmci_transport.c | 8 +++++ 7 files changed, 89 insertions(+)
drivers/vhost/vsock.c +1 -0
@@ -556,6 +556,7 @@ static struct vsock_transport vhost_transport = { .stream_rcvhiwat = virtio_transport_stream_rcvhiwat, .stream_is_active = virtio_transport_stream_is_active, .stream_allow = virtio_transport_stream_allow, + .stream_read_sock = virtio_transport_stream_read_sock, .notify_poll_in = virtio_transport_notify_poll_in, .notify_poll_out = virtio_transport_notify_poll_out,
include/linux/virtio_vsock.h +4 -0
@@ -37,6 +37,7 @@#include <uapi/linux/virtio_vsock.h> #include <linux/socket.h> #include <net/sock.h> +#include <net/tcp.h> /* for sk_read_actor_t */ #define VIRTIO_VSOCK_DEFAULT_MIN_BUF_SIZE 128#define VIRTIO_VSOCK_DEFAULT_BUF_SIZE (1024 * 256)
@@ -176,6 +177,9 @@ int virtio_transport_notify_send_post_enqueue(struct vsock_sock *vsk,u64 virtio_transport_stream_rcvhiwat (struct vsock_sock *vsk);bool virtio_transport_stream_is_active (struct vsock_sock *vsk);bool virtio_transport_stream_allow (u32 cid,u32 port); +int virtio_transport_stream_read_sock (struct vsock_sock *vsk, +read_descriptor_t *desc, +sk_read_actor_t recv_actor);int virtio_transport_dgram_bind (struct vsock_sock *vsk,struct sockaddr_vm *addr);bool virtio_transport_dgram_allow (u32 cid,u32 port);
include/net/af_vsock.h +5 -0
@@ -19,6 +19,7 @@#include <linux/kernel.h> #include <linux/workqueue.h> #include <linux/vm_sockets.h> +#include <net/tcp.h> /* for sk_read_actor_t */ #include "vsock_addr.h"
@@ -69,6 +70,8 @@ struct vsock_sock {void *trans; }; +int vsock_read_sock (struct sock *sk,read_descriptor_t *desc, +sk_read_actor_t recv_actor);s64 vsock_stream_has_data (struct vsock_sock *vsk);s64 vsock_stream_has_space (struct vsock_sock *vsk);void vsock_pending_work (struct work_struct *work);
@@ -118,6 +121,8 @@ struct vsock_transport {u64 (*stream_rcvhiwat)(struct vsock_sock *);bool (*stream_is_active)(struct vsock_sock *);bool (*stream_allow)(u32 cid,u32 port); +int (*stream_read_sock)(struct vsock_sock *,read_descriptor_t *desc, +sk_read_actor_t recv_actor);/* Notification. */ int (*notify_poll_in)(struct vsock_sock *,size_t ,bool *);
net/vmw_vsock/af_vsock.c +15 -0
@@ -764,6 +764,21 @@ static void vsock_sk_destruct(struct sock *sk)put_cred (vsk->owner); } +int vsock_read_sock (struct sock *sk,read_descriptor_t *desc, +sk_read_actor_t recv_actor) +{ +struct vsock_sock *vsp =vsock_sk (sk); + +if (sk->sk_type !=SOCK_STREAM ) +return -EOPNOTSUPP ; + +if (sk->sk_state !=SS_CONNECTED && sk->sk_state !=SS_DISCONNECTING ) +return -ENOTCONN ; + +return transport->stream_read_sock (vsp, desc, recv_actor); +} +EXPORT_SYMBOL (vsock_read_sock); +static int vsock_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) {int err;
net/vmw_vsock/virtio_transport.c +1 -0
@@ -315,6 +315,7 @@ static struct vsock_transport virtio_transport = { .stream_rcvhiwat = virtio_transport_stream_rcvhiwat, .stream_is_active = virtio_transport_stream_is_active, .stream_allow = virtio_transport_stream_allow, + .stream_read_sock = virtio_transport_stream_read_sock, .notify_poll_in = virtio_transport_notify_poll_in, .notify_poll_out = virtio_transport_notify_poll_out,
net/vmw_vsock/virtio_transport_common.c +55 -0
61 lines not on this page · raw message
net/vmw_vsock/vmci_transport.c +8 -0
@@ -654,6 +654,13 @@ static bool vmci_transport_stream_allow(u32 cid, u32 port)return true; } +static int vmci_transport_stream_read_sock (struct vsock_sock *vsk, +read_descriptor_t *desc, +sk_read_actor_t recv_actor) +{ +return -EOPNOTSUPP ;/* not yet implemented */ +} +/* This is invoked as part of a tasklet that's scheduled when the VMCI * interrupt fires. This is run in bottom-half context but it defers most of * its work to the packet handling work queue.
@@ -2083,6 +2090,7 @@ static struct vsock_transport vmci_transport = { .stream_rcvhiwat = vmci_transport_stream_rcvhiwat, .stream_is_active = vmci_transport_stream_is_active, .stream_allow = vmci_transport_stream_allow, + .stream_read_sock = vmci_transport_stream_read_sock, .notify_poll_in = vmci_transport_notify_poll_in, .notify_poll_out = vmci_transport_notify_poll_out, .notify_recv_init = vmci_transport_notify_recv_init,
Signature · 1 line
2.4.2
Stefan Hajnoczi
maintainerRFC 6/10 SUNRPC: add AF_VSOCK support to xprtsock.c
In reply to Stefan Hajnoczi--- include/linux/sunrpc/xprt.h | 1 + net/sunrpc/xprtsock.c | 392 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 380 insertions(+), 13 deletions(-)
include/linux/sunrpc/xprt.h +1 -0
@@ -151,6 +151,7 @@ enum xprt_transports {XPRT_TRANSPORT_BC_TCP =IPPROTO_TCP |XPRT_TRANSPORT_BC ,XPRT_TRANSPORT_RDMA =256 ,XPRT_TRANSPORT_LOCAL =257 , + XPRT_TRANSPORT_VSOCK = 258, }; struct rpc_xprt {
net/sunrpc/xprtsock.c +379 -13
481 lines not on this page · raw message
Signature · 1 line
2.4.2
Stefan Hajnoczi
maintainerRFC 8/10 SUNRPC: add vsock-bc backchannel
In reply to Stefan HajnocziNote that this is currently a hack which unconditionally replaces "tcp-bc" with "vsock-bc". Need to find a way to select the appropriate backchannel name based on the address family.
--- fs/nfs/callback.c | 7 +++++-- net/sunrpc/svcsock.c | 48 ++++++++++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 20 deletions(-)
fs/nfs/callback.c +5 -2
@@ -106,8 +106,11 @@ static int nfs41_callback_up_net(struct svc_serv *serv, struct net *net)* fore channel connection. * Returns the input port (0) and sets the svc_serv bc_xprt on success */ -return svc_create_xprt (serv,"tcp-bc" , net,PF_INET ,0 , -SVC_SOCK_ANONYMOUS ); +/* return svc_create_xprt(serv, "tcp-bc", net, PF_INET, 0, +SVC_SOCK_ANONYMOUS); */ +/* TODO check address family and choose appropriately */ +return svc_create_xprt (serv,"vsock-bc" , net,AF_VSOCK ,0 , +SVC_SOCK_ANONYMOUS ); }/*
net/sunrpc/svcsock.c +30 -18
95 lines not on this page · raw message
Signature · 1 line
2.4.2
Stefan Hajnoczi
maintainerRFC 9/10 SUNRPC: add AF_VSOCK support to svc_xprt.c
In reply to Stefan HajnocziAllow creation of AF_VSOCK service xprts. This is needed for the "vsock-bc" backchannel.
--- include/linux/sunrpc/svc_xprt.h | 12 ++++++++++++ net/sunrpc/svc_xprt.c | 13 +++++++++++++ 2 files changed, 25 insertions(+)
include/linux/sunrpc/svc_xprt.h +12 -0
@@ -8,6 +8,7 @@#define SUNRPC_SVC_XPRT_H #include <linux/sunrpc/svc.h> +#include <linux/vm_sockets.h> struct module ;
@@ -150,12 +151,15 @@ static inline unsigned short svc_addr_port(const struct sockaddr *sa) {const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa; +const struct sockaddr_vm *svm = (const struct sockaddr_vm *)sa;switch (sa->sa_family) {case AF_INET :return ntohs (sin->sin_port);case AF_INET6 :return ntohs (sin6->sin6_port); +case AF_VSOCK : +return svm->svm_port; }return 0 ;
@@ -168,6 +172,8 @@ static inline size_t svc_addr_len(const struct sockaddr *sa)return sizeof (struct sockaddr_in );case AF_INET6 :return sizeof (struct sockaddr_in6 ); +case AF_VSOCK : +return sizeof (struct sockaddr_vm ); }BUG (); }
@@ -187,6 +193,7 @@ static inline char *__svc_print_addr(const struct sockaddr *addr, {const struct sockaddr_in *sin = (const struct sockaddr_in *)addr;const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)addr; +const struct sockaddr_vm *svm = (const struct sockaddr_vm *)addr;switch (addr->sa_family) {case AF_INET :
@@ -200,6 +207,11 @@ static inline char *__svc_print_addr(const struct sockaddr *addr, ntohs(sin6->sin6_port));break ; +case AF_VSOCK : +snprintf (buf, len,"%u, port=%u" , + svm->svm_cid, svm->svm_port); +break ; +default :snprintf (buf, len,"unknown address type: %d" , addr->sa_family);break ;
net/sunrpc/svc_xprt.c +13 -0
@@ -188,6 +188,13 @@ static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl, .sin6_port = htons(port), };#endif +#if IS_ENABLED (CONFIG_VSOCKETS ) +struct sockaddr_vm svm = { + .svm_family =AF_VSOCK , + .svm_cid =VMADDR_CID_ANY , + .svm_port =VMADDR_PORT_ANY , + }; +#endif struct sockaddr *sap;size_t len;
@@ -202,6 +209,12 @@ static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl, len =sizeof (sin6);break ;#endif +#if IS_ENABLED (CONFIG_VSOCKETS ) +case AF_VSOCK : + sap = (struct sockaddr *)&svm; + len =sizeof (svm); +break ; +#endif default :return ERR_PTR (-EAFNOSUPPORT ); }
Signature · 1 line
2.4.2
Stefan Hajnoczi
maintainerRFC 10/10 NFS: add AF_VSOCK support to NFS client
In reply to Stefan HajnocziThis patch adds AF_VSOCK to the NFS client. Mounts can now use the "vsock" proto option and pass "vsock:<cid>" address strings, which are interpreted by sunrpc for xprt creation.
--- fs/nfs/client.c | 16 ++++++++++++++++ fs/nfs/super.c | 10 ++++++++++ 2 files changed, 26 insertions(+)
fs/nfs/client.c +16 -0
@@ -34,6 +34,7 @@#include <linux/vfs.h> #include <linux/inet.h> #include <linux/in6.h> +#include <linux/vm_sockets.h> #include <linux/slab.h> #include <linux/idr.h> #include <net/ipv6.h>
@@ -354,6 +355,16 @@ static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1, (sin1->sin_port == sin2->sin_port); } +static int nfs_sockaddr_cmp_vsock (const struct sockaddr *sa1, +const struct sockaddr *sa2) +{ +const struct sockaddr_vm *svm1 = (const struct sockaddr_vm *)sa1; +const struct sockaddr_vm *svm2 = (const struct sockaddr_vm *)sa2; + +return svm1->svm_cid == svm2->svm_cid && + svm1->svm_port == svm2->svm_port; +} +#if defined(CONFIG_NFS_V4_1 )/* * Test if two socket addresses represent the same actual socket,
@@ -370,6 +381,8 @@ int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,return nfs_sockaddr_match_ipaddr4 (sa1, sa2);case AF_INET6 :return nfs_sockaddr_match_ipaddr6 (sa1, sa2); +default : +BUG (); }return 0 ; }
@@ -391,6 +404,8 @@ static int nfs_sockaddr_cmp(const struct sockaddr *sa1,return nfs_sockaddr_cmp_ip4 (sa1, sa2);case AF_INET6 :return nfs_sockaddr_cmp_ip6 (sa1, sa2); +case AF_VSOCK : +return nfs_sockaddr_cmp_vsock (sa1, sa2); }return 0 ; }
@@ -545,6 +560,7 @@ void nfs_init_timeout_values(struct rpc_timeout *to, int proto,switch (proto) {case XPRT_TRANSPORT_TCP :case XPRT_TRANSPORT_RDMA : +case XPRT_TRANSPORT_VSOCK :if (to->to_retries ==0 ) to->to_retries =NFS_DEF_TCP_RETRANS ;if (to->to_initval ==0 )
fs/nfs/super.c +10 -0
@@ -191,6 +191,7 @@ static const match_table_t nfs_mount_option_tokens = {enum { Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma, + Opt_xprt_vsock, Opt_xprt_err };
@@ -201,6 +202,7 @@ static const match_table_t nfs_xprt_protocol_tokens = { { Opt_xprt_tcp, "tcp" }, { Opt_xprt_tcp6, "tcp6" }, { Opt_xprt_rdma, "rdma" }, + { Opt_xprt_vsock, "vsock" }, { Opt_xprt_err, NULL } };
@@ -964,6 +966,8 @@ static int nfs_verify_server_address(struct sockaddr *addr)struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;return !ipv6_addr_any (sa); } +case AF_VSOCK : +return 1 ; }dfprintk (MOUNT ,"NFS: Invalid IP address specified\n" );
@@ -993,6 +997,7 @@ static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)case XPRT_TRANSPORT_UDP :case XPRT_TRANSPORT_TCP :case XPRT_TRANSPORT_RDMA : +case XPRT_TRANSPORT_VSOCK :break ;default : mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ;
@@ -1459,6 +1464,11 @@ static int nfs_parse_mount_options(char *raw, mnt->nfs_server.protocol =XPRT_TRANSPORT_RDMA ;xprt_load_transport (string);break ; +case Opt_xprt_vsock: + protofamily =AF_VSOCK ; + mnt->flags &= ~NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_VSOCK ; +break ;default :dfprintk (MOUNT ,"NFS: unrecognized " "transport protocol\n" );
Signature · 1 line
2.4.2
Quoted 45 lines · Stefan Hajnoczi
This patch series enables
AF_VSOCKaddress family support in the NFS client. Please use the https://github.com/stefanha/linux.git vsock-nfs branch, which contains the dependencies for this series.The
AF_VSOCKaddress family provides dgram and stream socket communication between virtual machines and hypervisors. A VMware VMCI transport is currently available in-tree (seenet/vmw_vsock) and I have posted virtio-vsock patches for use with QEMU/KVM: http://thread.gmane.org/gmane.linux.network/365205The goal of this work is sharing files between virtual machines and hypervisors.
AF_VSOCKis well-suited to this because it requires no configuration inside the virtual machine, making it simple to manage and reliable.Why NFS over
AF_VSOCK?
----------------------
It is unusual to add a new NFS transport, only TCP, RDMA, and UDP are currently supported. Here is the rationale for addingAF_VSOCK.Sharing files with a virtual machine can be configured manually:
1. Add a dedicated network card to the virtual machine. It will be used for NFS traffic.
2. Configure a local subnet and assign IP addresses to the virtual machine and hypervisor
3. Configure an NFS export on the hypervisor and start the NFS server
4. Mount the export inside the virtual machineAutomating these steps poses a problem: modifying network configuration inside the virtual machine is invasive. It's hard to add a network interface to an arbitrary running system in an automated fashion, considering the network management tools, firewall rules, IP address usage, etc.
Furthermore, the user may disrupt file sharing by accident when they add firewall rules, restart networking, etc because the NFS network interface is visible alongside the network interfaces managed by the user.
AF_VSOCKis a zero-configuration network transport that avoids these problems. Adding it to a virtual machine is non-invasive. It also avoids accidental misconfiguration by the user. This is why "guest agents" and other services in various hypervisors (KVM, Xen, VMware, VirtualBox) do not use regular network interfaces.This is why
AF_VSOCKis appropriate for providing shared files as a hypervisor service.
Quoted 6 lines
The approach in this series
---------------------------AF_VSOCKstream sockets can be used for NFSv4.1 much in the same way as TCP. RFC 1831 record fragments divide messages sinceSOCK_STREAMsemantics are present. The backchannel shares the connection just like the default TCP configuration.
So the NFSv4 backchannel isn't handled for now, I assume. And I guess NFSv2/v3 is out too thanks to rpcbind? Which maybe is fine.
Do we need an IETF draft or similar to document how NFS should work over AF_VSOCK?
NFS developers rely heavily on wireshark (and similar tools) for debugging. Is that still possible over AF_VSOCK?
Quoted 34 lines
Addresses are <Context ID, Port Number> pairs. These patches use "vsock:<cid>" string representation to distinguish
AF_VSOCKaddresses from IPv4 and IPv6 numeric addresses.The patches cover the following areas:
Patch 1 - support struct
sockaddr_vmin sunrpcaddr.hPatch 2-4 - make sunrpc TCP record fragment parser reusable for any stream
socketPatch 5 - add tcp_read_sock()-like interface to
AF_VSOCKsocketsPatch 6 - extend sunrpc
xprtsock.cforAF_VSOCKRPC clientsPatch 7-9 -
AF_VSOCKbackchannel supportPatch 10 - add
AF_VSOCKsupport to NFS clientThe following example mounts /export from the hypervisor (CID 2) inside the virtual machine (CID 3):
# /sbin/mount.nfs 2:/export /mnt -o clientaddr=3,proto=vsockStatus
------
I am looking for feedback on this approach. There are TODOs remaining in the code.Hopefully the way I add
AF_VSOCKsupport to sunrpc is reasonable and something that can be standardized (a netid assigned and the uaddr string format decided).See below for the nfs-utils patch. It can be made nice once glibc getnameinfo()/getaddrinfo() support
AF_VSOCK.
Quoted 8 lines
The
vsock_read_sock()implementation is dumb. Less of a NFS/SUNRPC issue and more of a vsock issue, but perhapsvirtio_transport.cshould use skbs for its receive queue instead of a custom packet struct. That would eliminate memory allocation and copying invsock_read_sock().The next step is tackling NFS server. In the meantime, I have tested the patches using the nc-vsock netcat-like utility that is available in my Linux kernel repo below.
So by a netcat-like utility, you mean it's proxying between client and a server so the client thinks the server is communicating over AF_VSOCK and the server thinks the client is using TCP? (Sorry, I haven't looked at the code.)
Once we have a server and client, how will you recommend testing them? (Will the server side need to run on real hardware?)
I guess if it works then the main question is whether it's worth supporting another transport type in order to get the zero-configuration host<->guest NFS setup. Or whether there's another way to get the same gains.
Seems like a useful thing to have.
--b.
Quoted 32 lines
Repositories
------------
* Linux kernel: https://github.com/stefanha/linux.git vsock-nfs
* QEMU virtio-vsock device: https://github.com/stefanha/qemu.git vsock
* nfs-utils vsock: https://github.com/stefanha/nfs-utils.git vsockStefan Hajnoczi (10):
SUNRPC: addAF_VSOCKsupport toaddr.h
SUNRPC: rename "TCP" record parser to "stream" parser
SUNRPC: abstracttcp_read_sock()in record fragment parser
SUNRPC: extractxs_stream_reset_state()
VSOCK: add tcp_read_sock()-likevsock_read_sock()function
SUNRPC: addAF_VSOCKsupport toxprtsock.c
SUNRPC: restrict backchannel svcIPPROTO_TCPcheck to IP
SUNRPC: add vsock-bc backchannel
SUNRPC: addAF_VSOCKsupport tosvc_xprt.c
NFS: addAF_VSOCKsupport to NFS clientdrivers/vhost/vsock.c | 1 + fs/nfs/callback.c | 7 +- fs/nfs/client.c | 16 + fs/nfs/super.c | 10 + include/linux/sunrpc/addr.h | 6 + include/linux/sunrpc/svc_xprt.h | 12 + include/linux/sunrpc/xprt.h | 1 + include/linux/sunrpc/xprtsock.h | 37 +- include/linux/virtio_vsock.h | 4 + include/net/af_vsock.h | 5 + include/trace/events/sunrpc.h | 30 +- net/sunrpc/addr.c | 57 +++ net/sunrpc/svc.c | 13 +-
Quoted 16 lines
net/sunrpc/svc_xprt.c | 13 + net/sunrpc/svcsock.c | 48 ++- net/sunrpc/xprtsock.c | 693 +++++++++++++++++++++++++------- net/vmw_vsock/af_vsock.c | 15 + net/vmw_vsock/virtio_transport.c | 1 + net/vmw_vsock/virtio_transport_common.c | 55 +++ net/vmw_vsock/vmci_transport.c | 8 + 20 files changed, 825 insertions(+), 207 deletions(-)Signature · 6 lines
2.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · J. Bruce Fields
Quoted 6 lines · Stefan Hajnoczi
The approach in this series
---------------------------AF_VSOCKstream sockets can be used for NFSv4.1 much in the same way as TCP. RFC 1831 record fragments divide messages sinceSOCK_STREAMsemantics are present. The backchannel shares the connection just like the default TCP configuration.So the NFSv4 backchannel isn't handled for now, I assume.
Right, I did not touch nfs4_callback_up_net(), only nfs41_callback_up_net().
If I'm reading the code right NFSv4 uses a separate listen port for the backchannel instead of sharing the client's socket?
This is possible to implement with AF_VSOCK but I have only tested NFSv4.1 so far. Should I go ahead and do this?
Quoted 2 lines
And I guess
NFSv2/v3 is out too thanks to rpcbind? Which maybe is fine.
Yes, I ignored rpcbind and didn't test NFSv2/v3.
Quoted 2 lines
Do we need an IETF draft or similar to document how NFS should work over
AF_VSOCK?
I am not familiar with the standards process but I came across a few places where it makes sense to have a standard:
* SUNRPC netid for AF_VSOCK (currently "tcp", "udp", and others exist)
* The uaddr string format ("vsock:...")
* Use of RFC 1831 record fragments (just like TCP) over AF_VSOCK SOCK_STREAM sockets
These are all at the SUNRPC level rather than at the NFS protocol level.
Any idea who I need to talk to?
Quoted 2 lines
NFS developers rely heavily on wireshark (and similar tools) for debugging. Is that still possible over
AF_VSOCK?
No, this will require kernel and libpcap patches. Something like drivers/net/nlmon.c is needed for AF_VSOCK. Basically a dummy network interface and code that clones skbs when monitoring is enabled.
It's on the TODO list and will be very useful.
Quoted 8 lines
Quoted 3 lines
The next step is tackling NFS server. In the meantime, I have tested the patches using the nc-vsock netcat-like utility that is available in my Linux kernel repo below.
So by a netcat-like utility, you mean it's proxying between client and a server so the client thinks the server is communicating over
AF_VSOCKand the server thinks the client is using TCP? (Sorry, I haven't looked at the code.)
Yes, exactly. It works since the TCP and AF_VSOCK streams are almost bit-compatible. I think the difference between the streams occurs when network addresses are transmitted (e.g. SUNRPC netids), but I haven't encountered that with NFSv4.1 and no pnfs or fancy features in use.
Quoted 2 lines
Once we have a server and client, how will you recommend testing them? (Will the server side need to run on real hardware?)
I have been testing nfsd on the host and nfs client in a virtual machine. Vice versa should work in the same way.
It's also possible to run nfsd in VM #1 and nfs client in VM #2 and use the netcat-like utility on the host to forward the traffic. That way any kernel panic happens in a VM and doesn't bring down the machine. I'll probably begin using this approach when I start nfsd work.
Quoted 4 lines
I guess if it works then the main question is whether it's worth supporting another transport type in order to get the zero-configuration host<->guest NFS setup. Or whether there's another way to get the same gains.
Thanks! If anyone has suggestions to avoid adding the AF_VSOCK transport I'd be interested to learn about that.
Stefan
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · J. Bruce Fields
Quoted 6 lines · Stefan Hajnoczi
The approach in this series
---------------------------AF_VSOCKstream sockets can be used for NFSv4.1 much in the same way as TCP. RFC 1831 record fragments divide messages sinceSOCK_STREAMsemantics are present. The backchannel shares the connection just like the default TCP configuration.
Quoted 7 lines
Quoted 1 line
So the NFSv4 backchannel isn't handled for now, I assume.
Right, I did not touch
nfs4_callback_up_net(), onlynfs41_callback_up_net().If I'm reading the code right NFSv4 uses a separate listen port for the backchannel instead of sharing the client's socket?
Right.
Quoted 2 lines
This is possible to implement with
AF_VSOCKbut I have only tested NFSv4.1 so far. Should I go ahead and do this?
Personally I'd make it a lower priority--I don't see why you can't make 4.1 a requirement for the new transport--but I'd be curious what others have to say.
Quoted 5 lines
Quoted 2 lines
And I guess
NFSv2/v3 is out too thanks to rpcbind? Which maybe is fine.Yes, I ignored rpcbind and didn't test NFSv2/v3.
Quoted 8 lines
Quoted 2 lines
Do we need an IETF draft or similar to document how NFS should work over
AF_VSOCK?I am not familiar with the standards process but I came across a few places where it makes sense to have a standard:
* SUNRPC netid for
AF_VSOCK(currently "tcp", "udp", and others exist)
* The uaddr string format ("vsock:...")
Off the top of my head I can't remember where else that's used in the protocol other than in setting up the 4.0 callback connection (and in rpcbind).
Quoted 2 lines
* Use of RFC 1831 record fragments (just like TCP) over
AF_VSOCKSOCK_STREAMsockets
As far as I can tell, 1831 claims to be independent of any transport protocol details: "The RPC protocol can be implemented on several different transport protocols. The RPC protocol does not care how a message is passed from one process to another, but only with specification and interpretation of messages." And: "When RPC messages are passed on top of a byte stream transport protocol (like TCP)".... So perhaps there's nothing more to say here.
Quoted 3 lines
These are all at the SUNRPC level rather than at the NFS protocol level.
Any idea who I need to talk to?
Anyay, if there is anything to be worked out, [email protected] is the place to go.
--b.
Stefan Hajnoczi
maintainerQuoted 7 lines · J. Bruce Fields
Quoted 3 lines · Stefan Hajnoczi
These are all at the SUNRPC level rather than at the NFS protocol level.
Any idea who I need to talk to?
Anyay, if there is anything to be worked out, [email protected] is the place to go.
Thanks, I can write a summary and send it there.
Stefan