nbd patches for 2021-05-11

- fix fd passing to qemu-storage-daemon --nbd-server
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAmCa2l4ACgkQp6FrSiUn
 Q2qErQf/c3GERpk9FP8QQuSjnuDFbT0eQKAqAtAOASTsyqipW+xED2Rf0+NWHQdD
 0NXWb6fLokLK/ut7qBvamBgHJxG8EjIU/iAidBjrKDzgJ9zrmBRqVUJQQpVVD/Fm
 CfO548a6/zuUWvxcSm89oZ60/u/N8yiJbfghx5ej8AgxXpe0nQtyS+bPfbhp08ej
 CeEy8HXosncUQgmOu5B8iNuCDLKHXPwFrWr1FPGcNR0rcGBdD6B6vwGPeJ2GMKz9
 TZ9Y0oHZjg4g2XBWh6OFnUdT1u2T9iDXkGWk9ugKOxmpGRc7rI6jp8QHSAT2Mn5d
 /nxHEgtyxy7PYPbPnGnJPQwcJy+Vjg==
 =WRjo
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2021-05-11' into staging

nbd patches for 2021-05-11

- fix fd passing to qemu-storage-daemon --nbd-server

# gpg: Signature made Tue 11 May 2021 20:26:22 BST
# gpg:                using RSA key 71C2CC22B1C4602927D2F3AAA7A16B4A2527436A
# gpg: Good signature from "Eric Blake <eblake@redhat.com>" [full]
# gpg:                 aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" [full]
# gpg:                 aka "[jpeg image of size 6874]" [full]
# Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2  F3AA A7A1 6B4A 2527 436A

* remotes/ericb/tags/pull-nbd-2021-05-11:
  sockets: update SOCKET_ADDRESS_TYPE_FD listen(2) backlog

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2021-05-21 09:54:56 +01:00
commit da9076f323

View File

@ -1116,14 +1116,10 @@ fail:
return NULL; return NULL;
} }
static int socket_get_fd(const char *fdstr, int num, Error **errp) static int socket_get_fd(const char *fdstr, Error **errp)
{ {
Monitor *cur_mon = monitor_cur(); Monitor *cur_mon = monitor_cur();
int fd; int fd;
if (num != 1) {
error_setg_errno(errp, EINVAL, "socket_get_fd: too many connections");
return -1;
}
if (cur_mon) { if (cur_mon) {
fd = monitor_get_fd(cur_mon, fdstr, errp); fd = monitor_get_fd(cur_mon, fdstr, errp);
if (fd < 0) { if (fd < 0) {
@ -1159,7 +1155,7 @@ int socket_connect(SocketAddress *addr, Error **errp)
break; break;
case SOCKET_ADDRESS_TYPE_FD: case SOCKET_ADDRESS_TYPE_FD:
fd = socket_get_fd(addr->u.fd.str, 1, errp); fd = socket_get_fd(addr->u.fd.str, errp);
break; break;
case SOCKET_ADDRESS_TYPE_VSOCK: case SOCKET_ADDRESS_TYPE_VSOCK:
@ -1187,7 +1183,26 @@ int socket_listen(SocketAddress *addr, int num, Error **errp)
break; break;
case SOCKET_ADDRESS_TYPE_FD: case SOCKET_ADDRESS_TYPE_FD:
fd = socket_get_fd(addr->u.fd.str, num, errp); fd = socket_get_fd(addr->u.fd.str, errp);
if (fd < 0) {
return -1;
}
/*
* If the socket is not yet in the listen state, then transition it to
* the listen state now.
*
* If it's already listening then this updates the backlog value as
* requested.
*
* If this socket cannot listen because it's already in another state
* (e.g. unbound or connected) then we'll catch the error here.
*/
if (listen(fd, num) != 0) {
error_setg_errno(errp, errno, "Failed to listen on fd socket");
closesocket(fd);
return -1;
}
break; break;
case SOCKET_ADDRESS_TYPE_VSOCK: case SOCKET_ADDRESS_TYPE_VSOCK: