qga: add vsock-listen
cover qga: add vsock-listen
This patch series adds virtio-vsock support to the QEMU guest agent.
$ qemu-system-x86_64 -device vhost-vsock-pci,guest-cid=3 ... (guest)# qemu-ga -m vsock-listen -p 3:1234
You can interact with the qga monitor using the nc-vsock utility:
https://raw.githubusercontent.com/stefanha/linux/dd0d6a2aa62c0fd6cdc9dbd4b3dc4bfd0828c329/nc-vsock.c
$ nc-vsock 3 1234
{'execute': 'guest-info'}
...For more information about virtio-vsock, see
http://qemu-project.org/Features/VirtioVsock.
Stefan Hajnoczi (4):
qga: drop unused sockaddr in accept(2) call
qga: drop unnecessary GA_CHANNEL_UNIX_LISTEN checks
sockets: add AF_VSOCK support
qga: add vsock-listen method
qapi-schema.json | 23 +++++- qga/channel-posix.c | 36 +++++++-- qga/channel.h | 1 + qga/main.c | 6 +- util/qemu-sockets.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 277 insertions(+), 11 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/4 qga: drop unused sockaddr in accept(2) call
ga_channel_listen_accept() is currently hard-coded to support only AF_UNIX because the struct sockaddr_un type is used. This function should work with any address family.
Drop the sockaddr since the client address is unused and is an optional argument to accept(2).
--- qga/channel-posix.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
qga/channel-posix.c +1 -4
@@ -26,13 +26,10 @@ static gboolean ga_channel_listen_accept(GIOChannel *channel,GAChannel *c = data;int ret, client_fd;bool accepted = false; -struct sockaddr_un addr; -socklen_t addrlen =sizeof (addr);g_assert (channel !=NULL ); - client_fd =qemu_accept (g_io_channel_unix_get_fd (channel), - (struct sockaddr *)&addr, &addrlen); + client_fd =qemu_accept (g_io_channel_unix_get_fd (channel),NULL ,NULL );if (client_fd ==-1 ) {g_warning ("error converting fd to gsocket: %s" ,strerror (errno)); goto out;
Signature · 1 line
2.7.4
PATCH 2/4 qga: drop unnecessary GA_CHANNEL_UNIX_LISTEN checks
In reply to Stefan HajnocziThroughout the code there are c->listen_channel checks which manage the listen socket file descriptor (waiting for accept(2), closing the file descriptor, etc). These checks are currently preceded by explicit c->method == GA_CHANNEL_UNIX_LISTEN checks.
Explicit GA_CHANNEL_UNIX_LISTEN checks are not necessary since serial channel types do not create the listen channel (c->listen_channel).
As more listen channel types are added, explicitly checking all of them becomes messy. Rely on c->listen_channel to determine whether or not a listen socket file descriptor is used.
--- qga/channel-posix.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
qga/channel-posix.c +2 -4
@@ -61,7 +61,6 @@ static void ga_channel_listen_add(GAChannel *c, int listen_fd, bool create)static void ga_channel_listen_close (GAChannel *c) { -g_assert (c->method ==GA_CHANNEL_UNIX_LISTEN );g_assert (c->listen_channel);g_io_channel_shutdown (c->listen_channel, true,NULL );g_io_channel_unref (c->listen_channel);
@@ -77,7 +76,7 @@ static void ga_channel_client_close(GAChannel *c)g_io_channel_shutdown (c->client_channel, true,NULL );g_io_channel_unref (c->client_channel); c->client_channel =NULL ; -if (c->method ==GA_CHANNEL_UNIX_LISTEN && c->listen_channel) { +if (c->listen_channel) {ga_channel_listen_add (c,0 , false); } }
@@ -255,8 +254,7 @@ GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path,void ga_channel_free (GAChannel *c) { -if (c->method ==GA_CHANNEL_UNIX_LISTEN - && c->listen_channel) { +if (c->listen_channel) {ga_channel_listen_close (c); }if (c->client_channel) {
Signature · 1 line
2.7.4
PATCH 3/4 sockets: add AF_VSOCK support
In reply to Stefan HajnocziAdd the AF_VSOCK address family so that qemu-ga will be able to use virtio-vsock.
The AF_VSOCK address family uses <cid, port> address tuples. The cid is the unique identifier comparable to an IP address. AF_VSOCK does not use name resolution so it's seasy to convert between struct sockaddr_vm and strings.
This patch defines a VsockSocketAddress instead of trying to piggy-back on InetSocketAddress. This is cleaner in the long run since it avoids lots of IPv4 vs IPv6 vs vsock special casing.
--- qapi-schema.json | 23 +++++- util/qemu-sockets.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+), 1 deletion(-)
qapi-schema.json +22 -1
@@ -987,12 +987,14 @@ # # @unix: unix socket # +# @vsock: vsock family (since 2.8) +# # @unknown: otherwise # # Since: 2.1 ## { 'enum': 'NetworkAddressFamily', - 'data': [ 'ipv4', 'ipv6', 'unix', 'unknown' ] } + 'data': [ 'ipv4', 'ipv6', 'unix', 'vsock', 'unknown' ] } ## # @VncBasicInfo
@@ -3017,6 +3019,24 @@ 'path': 'str' } } ## +# @VsockSocketAddress +# +# Captures a socket address in the vsock namespace. +# +# @cid: unique host identifier +# @port: port +# +# Note that string types are used to allow for possible future hostname or +# service resolution support. +# +# Since 2.8 +## +{ 'struct': 'VsockSocketAddress', + 'data': { + 'cid': 'str', + 'port': 'str' } } + +## # @SocketAddress # # Captures the address of a socket, which could also be a named file descriptor
@@ -3027,6 +3047,7 @@ 'data': { 'inet': 'InetSocketAddress', 'unix': 'UnixSocketAddress', + 'vsock': 'VsockSocketAddress', 'fd': 'String' } } ##
util/qemu-sockets.c +222 -0
276 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 4/4 qga: add vsock-listen method
In reply to Stefan HajnocziAdd AF_VSOCK (virtio-vsock) support as an alternative to virtio-serial.
$ qemu-system-x86_64 -device vhost-vsock-pci,guest-cid=3 ... (guest)# qemu-ga -m vsock-listen -p 3:1234
--- qga/channel-posix.c | 25 +++++++++++++++++++++++++ qga/channel.h | 1 + qga/main.c | 6 ++++-- 3 files changed, 30 insertions(+), 2 deletions(-)
qga/channel-posix.c +25 -0
@@ -193,6 +193,31 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethodga_channel_listen_add (c, fd, true);break ; } +case GA_CHANNEL_VSOCK_LISTEN : { +Error *local_err =NULL ; +SocketAddress *addr; +char *addr_str; +int fd; + + addr_str =g_strdup_printf ("vsock:%s" , path); + addr =socket_parse (addr_str, &local_err); +g_free (addr_str); +if (local_err !=NULL ) { +g_critical ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +return false; + } + + fd =socket_listen (addr, &local_err); +qapi_free_SocketAddress (addr); +if (local_err !=NULL ) { +g_critical ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +return false; + } +ga_channel_listen_add (c, fd, true); +break ; + }default :g_critical ("error binding/listening to specified socket" );return false;
qga/channel.h +1 -0
@@ -19,6 +19,7 @@ typedef enum {GA_CHANNEL_VIRTIO_SERIAL ,GA_CHANNEL_ISA_SERIAL ,GA_CHANNEL_UNIX_LISTEN , +GA_CHANNEL_VSOCK_LISTEN , } GAChannelMethod;typedef gboolean (*GAChannelCallback )(GIOCondition condition,gpointer opaque);
qga/main.c +4 -2
@@ -190,8 +190,8 @@ static void usage(const char *cmd)"Usage: %s [-m <method> -p <path>] [<options>]\n" "QEMU Guest Agent %s\n" "\n" -" -m, --method transport method: one of unix-listen, virtio-serial, or\n" -" isa-serial (virtio-serial is the default)\n" +" -m, --method transport method: one of unix-listen, virtio-serial,\n" +" isa-serial, or vsock-listen (virtio-serial is the default)\n" " -p, --path device/socket path (the default for virtio-serial is:\n" " %s,\n" " the default for isa-serial is:\n"
@@ -659,6 +659,8 @@ static gboolean channel_init(GAState *s, const gchar *method, const gchar *path) channel_method =GA_CHANNEL_ISA_SERIAL ; }else if (strcmp (method,"unix-listen" ) ==0 ) { channel_method =GA_CHANNEL_UNIX_LISTEN ; + }else if (strcmp (method,"vsock-listen" ) ==0 ) { + channel_method =GA_CHANNEL_VSOCK_LISTEN ; }else {g_critical ("unsupported channel method/type: %s" , method);return false;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 3/4] sockets: add AF_VSOCK support
In reply to Stefan HajnocziQuoted 6 lines · Stefan Hajnoczi
Add the
AF_VSOCKaddress family so that qemu-ga will be able to use virtio-vsock.The
AF_VSOCKaddress family uses <cid, port> address tuples. The cid is the unique identifier comparable to an IP address.AF_VSOCKdoes not use name resolution so it's seasy to convert between structsockaddr_vm
s/seasy/easy/
Quoted 5 lines
and strings.
This patch defines a VsockSocketAddress instead of trying to piggy-back on InetSocketAddress. This is cleaner in the long run since it avoids lots of IPv4 vs IPv6 vs vsock special casing.
At any rate, it seems like SocketAddress would be a better fit for a tri-state union between InetSocketAddress, UnixSocketAddress, and VnetSocketAddress.
Quoted 13 lines
Signed-off-by Stefan Hajnoczi <[email protected]>--- qapi-schema.json | 23 +++++- util/qemu-sockets.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+), 1 deletion(-)qapi-schema.json +1
-0+## # @SocketAddress # # Captures the address of a socket, which could also be a named file descriptor
qapi-schema.json line 3051
Quoted 5 lines
qapi-schema.json +1
-0@@ -3027,6 +3047,7 @@ 'data': { 'inet': 'InetSocketAddress', 'unix': 'UnixSocketAddress', + 'vsock': 'VsockSocketAddress', 'fd': 'String' } }
Which is in fact what you did.
Quoted 4 lines
util/qemu-sockets.c +4
-0+static int vsock_connect_addr (const struct sockaddr_vm *svm,bool *in_progress, +ConnectState *connect_state,Error **errp) +{ +int sock, rc;
util/qemu-sockets.c int inet_connect(const char *str, Error **errp) · line 700
Quoted 10 lines
util/qemu-sockets.c +10
-0+ + *in_progress = false; + + sock =qemu_socket (AF_VSOCK ,SOCK_STREAM ,0 ); +if (sock <0 ) { +error_setg_errno (errp, errno,"Failed to create socket" ); +return -1 ; + } +if (connect_state !=NULL ) { +qemu_set_nonblock (sock);
Isn't the presence of vsock support sufficient to prove that we have SOCK_NONBLOCK support as part of our socket() call? In which case, wouldn't it be better to pass that option up front to atomically get a non-blocking socket, rather than having to change its state after the fact?
util/qemu-sockets.c int inet_connect(const char *str, Error **errp) · line 792
Quoted 7 lines
util/qemu-sockets.c +7
-0+static VsockSocketAddress *vsock_parse (const char *str,Error **errp) +{ +VsockSocketAddress *addr =NULL ; +char cid[33 ]; +char port[33 ]; + +if (sscanf (str,"%32[^:]:%32[^,]" , cid, port) !=2 ) {
Would it be a wise idea to also use %n to ensure that you aren't ignoring trailing garbage?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/4] sockets: add AF_VSOCK support
Quoted 12 lines · Eric Blake
Quoted 11 lines · Stefan Hajnoczi
util/qemu-sockets.c +11
-0+static int vsock_connect_addr (const struct sockaddr_vm *svm,bool *in_progress, +ConnectState *connect_state,Error **errp) +{ +int sock, rc; + + *in_progress = false; + + sock =qemu_socket (AF_VSOCK ,SOCK_STREAM ,0 ); +if (sock <0 ) { +error_setg_errno (errp, errno,"Failed to create socket" ); +return -1 ;
Quoted 8 lines
util/qemu-sockets.c int inet_connect(const char *str, Error **errp) · line 700
Quoted 3 lines
util/qemu-sockets.c +3
-0+ } +if (connect_state !=NULL ) { +qemu_set_nonblock (sock);Isn't the presence of vsock support sufficient to prove that we have
SOCK_NONBLOCKsupport as part of oursocket()call? In which case, wouldn't it be better to pass that option up front to atomically get a non-blocking socket, rather than having to change its state after the fact?
I'm sending a separate patch series to introduce a QemuSockFlags argument for qemu_socket() and qemu_accept(). It will convert existing qemu_set_nonblock() callers too.
Quoted 10 lines
util/qemu-sockets.c int inet_connect(const char *str, Error **errp) · line 792
Quoted 7 lines
util/qemu-sockets.c +7
-0+static VsockSocketAddress *vsock_parse (const char *str,Error **errp) +{ +VsockSocketAddress *addr =NULL ; +char cid[33 ]; +char port[33 ]; + +if (sscanf (str,"%32[^:]:%32[^,]" , cid, port) !=2 ) {Would it be a wise idea to also use %n to ensure that you aren't ignoring trailing garbage?
Okay, will fix in the next version.
Re: [Qemu-devel] [PATCH 2/4] qga: drop unnecessary GA_CHANNEL_UNIX_LISTEN checks
In reply to Stefan HajnocziQuoting Stefan Hajnoczi (2016-10-06 11:40:16)
Quoted 5 lines
Throughout the code there are
c->listen_channelchecks which manage the listen socket file descriptor (waiting for accept(2), closing the file descriptor, etc). These checks are currently preceded by explicitc->method==GA_CHANNEL_UNIX_LISTENchecks.
Quoted 8 lines
Explicit
GA_CHANNEL_UNIX_LISTENchecks are not necessary since serial channel types do not create the listen channel (c->listen_channel).As more listen channel types are added, explicitly checking all of them becomes messy. Rely on
c->listen_channelto determine whether or not a listen socket file descriptor is used.Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 38 lines
--- qga/channel-posix.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)qga/channel-posix.c +2
-4@@ -61,7 +61,6 @@ static void ga_channel_listen_add(GAChannel *c, int listen_fd, bool create)static void ga_channel_listen_close (GAChannel *c) { -g_assert (c->method ==GA_CHANNEL_UNIX_LISTEN );g_assert (c->listen_channel);g_io_channel_shutdown (c->listen_channel, true,NULL );g_io_channel_unref (c->listen_channel);@@ -77,7 +76,7 @@ static void ga_channel_client_close(GAChannel *c)g_io_channel_shutdown (c->client_channel, true,NULL );g_io_channel_unref (c->client_channel); c->client_channel =NULL ; -if (c->method ==GA_CHANNEL_UNIX_LISTEN && c->listen_channel) { +if (c->listen_channel) {ga_channel_listen_add (c,0 , false); } }@@ -255,8 +254,7 @@ GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path,void ga_channel_free (GAChannel *c) { -if (c->method ==GA_CHANNEL_UNIX_LISTEN - && c->listen_channel) { +if (c->listen_channel) {ga_channel_listen_close (c); }if (c->client_channel) {Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/4] qga: drop unused sockaddr in accept(2) call
In reply to Stefan HajnocziQuoting Stefan Hajnoczi (2016-10-06 11:40:15)
Quoted 8 lines
ga_channel_listen_accept()is currently hard-coded to support onlyAF_UNIXbecause the structsockaddr_untype is used. This function should work with any address family.Drop the sockaddr since the client address is unused and is an optional argument to accept(2).
Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 26 lines
--- qga/channel-posix.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)qga/channel-posix.c +1
-4@@ -26,13 +26,10 @@ static gboolean ga_channel_listen_accept(GIOChannel *channel,GAChannel *c = data;int ret, client_fd;bool accepted = false; -struct sockaddr_un addr; -socklen_t addrlen =sizeof (addr);g_assert (channel !=NULL ); - client_fd =qemu_accept (g_io_channel_unix_get_fd (channel), - (struct sockaddr *)&addr, &addrlen); + client_fd =qemu_accept (g_io_channel_unix_get_fd (channel),NULL ,NULL );if (client_fd ==-1 ) {g_warning ("error converting fd to gsocket: %s" ,strerror (errno)); goto out;Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 3/4] sockets: add AF_VSOCK support
In reply to Stefan HajnocziQuoting Stefan Hajnoczi (2016-10-06 11:40:17)
Quoted 48 lines
Add the
AF_VSOCKaddress family so that qemu-ga will be able to use virtio-vsock.The
AF_VSOCKaddress family uses <cid, port> address tuples. The cid is the unique identifier comparable to an IP address.AF_VSOCKdoes not use name resolution so it's seasy to convert between structsockaddr_vmand strings.This patch defines a VsockSocketAddress instead of trying to piggy-back on InetSocketAddress. This is cleaner in the long run since it avoids lots of IPv4 vs IPv6 vs vsock special casing.
Signed-off-by Stefan Hajnoczi <[email protected]>--- qapi-schema.json | 23 +++++- util/qemu-sockets.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+), 1 deletion(-)qapi-schema.json +9
-1@@ -987,12 +987,14 @@ # # @unix: unix socket # +# @vsock: vsock family (since 2.8) +# # @unknown: otherwise # # Since: 2.1 ## { 'enum': 'NetworkAddressFamily', - 'data': [ 'ipv4', 'ipv6', 'unix', 'unknown' ] } + 'data': [ 'ipv4', 'ipv6', 'unix', 'vsock', 'unknown' ] } ## # @VncBasicInfo@@ -3017,6 +3019,24 @@ 'path': 'str' } } ## +# @VsockSocketAddress +# +# Captures a socket address in the vsock namespace. +# +# @cid: unique host identifier +# @port: port
qapi-schema.json line 3037
Quoted 10 lines
qapi-schema.json +10
-0+# +# Note that string types are used to allow for possible future hostname or +# service resolution support. +# +# Since 2.8 +## +{ 'struct': 'VsockSocketAddress', + 'data': { + 'cid': 'str', + 'port': 'str' } }
Is there any reason to not define these as uint32_t? Not sure if there are other reasons for this, but if it's just for consistency with how Inet is handled, the code seems to do straight atoi()<->printf("%d") to covert between numerical and string representation so it doesn't seem like we need to account for any differences between command-line and internal representation in sockaddr_vm.
Re: [Qemu-devel] [PATCH 4/4] qga: add vsock-listen method
In reply to Stefan HajnocziQuoting Stefan Hajnoczi (2016-10-06 11:40:18)
Quoted 6 lines
Add
AF_VSOCK(virtio-vsock) support as an alternative to virtio-serial.$ qemu-system-x86_64 -device vhost-vsock-pci,guest-cid=3 ... (guest)# qemu-ga -m vsock-listen -p 3:1234Signed-off-by Stefan Hajnoczi <[email protected]>
I still need to get a vsock environment set up to test with, but looks good other than minor comments in patch 3.
Quoted 81 lines
--- qga/channel-posix.c | 25 +++++++++++++++++++++++++ qga/channel.h | 1 + qga/main.c | 6 ++++-- 3 files changed, 30 insertions(+), 2 deletions(-)qga/channel-posix.c +25
-0@@ -193,6 +193,31 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethodga_channel_listen_add (c, fd, true);break ; } +case GA_CHANNEL_VSOCK_LISTEN : { +Error *local_err =NULL ; +SocketAddress *addr; +char *addr_str; +int fd; + + addr_str =g_strdup_printf ("vsock:%s" , path); + addr =socket_parse (addr_str, &local_err); +g_free (addr_str); +if (local_err !=NULL ) { +g_critical ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +return false; + } + + fd =socket_listen (addr, &local_err); +qapi_free_SocketAddress (addr); +if (local_err !=NULL ) { +g_critical ("%s" ,error_get_pretty (local_err)); +error_free (local_err); +return false; + } +ga_channel_listen_add (c, fd, true); +break ; + }default :g_critical ("error binding/listening to specified socket" );return false;qga/channel.h +1
-0@@ -19,6 +19,7 @@ typedef enum {GA_CHANNEL_VIRTIO_SERIAL ,GA_CHANNEL_ISA_SERIAL ,GA_CHANNEL_UNIX_LISTEN , +GA_CHANNEL_VSOCK_LISTEN , } GAChannelMethod;typedef gboolean (*GAChannelCallback )(GIOCondition condition,gpointer opaque);qga/main.c +4
-2@@ -190,8 +190,8 @@ static void usage(const char *cmd)"Usage: %s [-m <method> -p <path>] [<options>]\n" "QEMU Guest Agent %s\n" "\n" -" -m, --method transport method: one of unix-listen, virtio-serial, or\n" -" isa-serial (virtio-serial is the default)\n" +" -m, --method transport method: one of unix-listen, virtio-serial,\n" +" isa-serial, or vsock-listen (virtio-serial is the default)\n" " -p, --path device/socket path (the default for virtio-serial is:\n" " %s,\n" " the default for isa-serial is:\n" @@ -659,6 +659,8 @@ static gboolean channel_init(GAState *s, const gchar *method, const gchar *path) channel_method =GA_CHANNEL_ISA_SERIAL ; }else if (strcmp (method,"unix-listen" ) ==0 ) { channel_method =GA_CHANNEL_UNIX_LISTEN ; + }else if (strcmp (method,"vsock-listen" ) ==0 ) { + channel_method =GA_CHANNEL_VSOCK_LISTEN ; }else {g_critical ("unsupported channel method/type: %s" , method);return false;Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 3/4] sockets: add AF_VSOCK support
In reply to Michael RothQuoted 58 lines · Michael Roth
Quoting Stefan Hajnoczi (2016-10-06 11:40:17)
Quoted 57 lines
Add the
AF_VSOCKaddress family so that qemu-ga will be able to use virtio-vsock.The
AF_VSOCKaddress family uses <cid, port> address tuples. The cid is the unique identifier comparable to an IP address.AF_VSOCKdoes not use name resolution so it's seasy to convert between structsockaddr_vmand strings.This patch defines a VsockSocketAddress instead of trying to piggy-back on InetSocketAddress. This is cleaner in the long run since it avoids lots of IPv4 vs IPv6 vs vsock special casing.
Signed-off-by Stefan Hajnoczi <[email protected]>--- qapi-schema.json | 23 +++++- util/qemu-sockets.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+), 1 deletion(-)qapi-schema.json +18
-1@@ -987,12 +987,14 @@ # # @unix: unix socket # +# @vsock: vsock family (since 2.8) +# # @unknown: otherwise # # Since: 2.1 ## { 'enum': 'NetworkAddressFamily', - 'data': [ 'ipv4', 'ipv6', 'unix', 'unknown' ] } + 'data': [ 'ipv4', 'ipv6', 'unix', 'vsock', 'unknown' ] } ## # @VncBasicInfo@@ -3017,6 +3019,24 @@ 'path': 'str' } } ## +# @VsockSocketAddress +# +# Captures a socket address in the vsock namespace. +# +# @cid: unique host identifier +# @port: port +# +# Note that string types are used to allow for possible future hostname or +# service resolution support. +# +# Since 2.8 +## +{ 'struct': 'VsockSocketAddress', + 'data': { + 'cid': 'str',
Quoted 8 lines
qapi-schema.json line 3037
Quoted 1 line
qapi-schema.json +1
-0+ 'port': 'str' } }Is there any reason to not define these as
uint32_t? Not sure if there are other reasons for this, but if it's just for consistency with how Inet is handled, the code seems to do straight atoi()<->printf("%d") to covert between numerical and string representation so it doesn't seem like we need to account for any differences between command-line and internal representation insockaddr_vm.
Just in case AF_VSOCK ever supports name and service resolution like TCP/IP. In that case cid could be a host name and port could be a service name.
(I mentioned this in the doc comment.)
Stefan
Re: [Qemu-devel] [PATCH 4/4] qga: add vsock-listen method
In reply to Michael RothQuoted 6 lines · Michael Roth
Quoting Stefan Hajnoczi (2016-10-06 11:40:18)
Quoted 5 lines
Add
AF_VSOCK(virtio-vsock) support as an alternative to virtio-serial.$ qemu-system-x86_64 -device vhost-vsock-pci,guest-cid=3 ... (guest)# qemu-ga -m vsock-listen -p 3:1234
Quoted 6 lines
Quoted 1 line
Signed-off-by Stefan Hajnoczi <[email protected]>Reviewed-by Michael Roth <[email protected]>I still need to get a vsock environment set up to test with, but looks good other than minor comments in patch 3.
Linux 4.8 has the guest and vhost drivers:
CONFIG_VSOCKETS=mCONFIG_VIRTIO_VSOCKETS=mCONFIG_VIRTIO_VSOCKETS_COMMON=mCONFIG_VHOST_VSOCK=m
Stefan
Re: [Qemu-devel] [PATCH 3/4] sockets: add AF_VSOCK support
In reply to Stefan HajnocziQuoting Stefan Hajnoczi (2016-10-12 10:06:10)
Quoted 68 lines · Michael Roth
Quoted 58 lines
Quoting Stefan Hajnoczi (2016-10-06 11:40:17)
Quoted 57 lines
Add the
AF_VSOCKaddress family so that qemu-ga will be able to use virtio-vsock.The
AF_VSOCKaddress family uses <cid, port> address tuples. The cid is the unique identifier comparable to an IP address.AF_VSOCKdoes not use name resolution so it's seasy to convert between structsockaddr_vmand strings.This patch defines a VsockSocketAddress instead of trying to piggy-back on InetSocketAddress. This is cleaner in the long run since it avoids lots of IPv4 vs IPv6 vs vsock special casing.
Signed-off-by Stefan Hajnoczi <[email protected]>--- qapi-schema.json | 23 +++++- util/qemu-sockets.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+), 1 deletion(-)qapi-schema.json +18
-1@@ -987,12 +987,14 @@ # # @unix: unix socket # +# @vsock: vsock family (since 2.8) +# # @unknown: otherwise # # Since: 2.1 ## { 'enum': 'NetworkAddressFamily', - 'data': [ 'ipv4', 'ipv6', 'unix', 'unknown' ] } + 'data': [ 'ipv4', 'ipv6', 'unix', 'vsock', 'unknown' ] } ## # @VncBasicInfo@@ -3017,6 +3019,24 @@ 'path': 'str' } } ## +# @VsockSocketAddress +# +# Captures a socket address in the vsock namespace. +# +# @cid: unique host identifier +# @port: port +# +# Note that string types are used to allow for possible future hostname or +# service resolution support. +# +# Since 2.8 +## +{ 'struct': 'VsockSocketAddress', + 'data': { + 'cid': 'str',Quoted 8 lines
qapi-schema.json line 3037
Quoted 1 line
qapi-schema.json +1
-0+ 'port': 'str' } }Is there any reason to not define these as
uint32_t? Not sure if there are other reasons for this, but if it's just for consistency with how Inet is handled, the code seems to do straight atoi()<->printf("%d") to covert between numerical and string representation so it doesn't seem like we need to account for any differences between command-line and internal representation insockaddr_vm.
Quoted 5 lines
Just in case
AF_VSOCKever supports name and service resolution like TCP/IP. In that case cid could be a host name and port could be a service name.(I mentioned this in the doc comment.)
Ahh, sorry I missed that completely. Makes perfect sense then.
Quoted 2 lines
Stefan
Re: [Qemu-devel] [PATCH 4/4] qga: add vsock-listen method
In reply to Stefan HajnocziQuoting Stefan Hajnoczi (2016-10-12 10:07:33)
Quoted 14 lines · Michael Roth
Quoted 6 lines
Quoting Stefan Hajnoczi (2016-10-06 11:40:18)
Quoted 5 lines
Add
AF_VSOCK(virtio-vsock) support as an alternative to virtio-serial.$ qemu-system-x86_64 -device vhost-vsock-pci,guest-cid=3 ... (guest)# qemu-ga -m vsock-listen -p 3:1234Quoted 6 lines
Quoted 1 line
Signed-off-by Stefan Hajnoczi <[email protected]>Reviewed-by Michael Roth <[email protected]>I still need to get a vsock environment set up to test with, but looks good other than minor comments in patch 3.
Quoted 6 lines
Linux 4.8 has the guest and vhost drivers:
CONFIG_VSOCKETS=mCONFIG_VIRTIO_VSOCKETS=mCONFIG_VIRTIO_VSOCKETS_COMMON=mCONFIG_VHOST_VSOCK=m
I still need to do some work to get this fully integrated into my test set up, but I ran these patches through some basic testing with a 4.8.0 host and 4.9 guest and everything seems to be in working order. I think Eric had some comments related to parameter parsing in patch 3, but otherwise looks good.
Quoted 2 lines
Stefan