[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 05/32] qemu-sockets: introduce socket_address_parse_named_fd()
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v4 05/32] qemu-sockets: introduce socket_address_parse_named_fd() |
Date: |
Thu, 10 Jun 2021 13:07:35 +0300 |
Add function that transforms named fd inside SocketAddress structure
into number representation. This way it may be then used in a context
where current monitor is not available.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
include/qemu/sockets.h | 14 ++++++++++++++
util/qemu-sockets.c | 19 +++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index 7d1f813576..1f4f18a44a 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -111,4 +111,18 @@ SocketAddress *socket_remote_address(int fd, Error **errp);
*/
SocketAddress *socket_address_flatten(SocketAddressLegacy *addr);
+/**
+ * socket_address_parse_named_fd:
+ *
+ * Modify @addr, replacing named fd by corresponding number.
+ *
+ * Parsing named fd (by sockget_get_fd) is not possible in context where
+ * current monitor is not available. So, SocketAddress user may first call
+ * socket_parse_named_fd() to parse named fd in advance, and then pass @addr to
+ * the context where monitor is not available.
+ *
+ * Return 0 on success.
+ */
+int socket_address_parse_named_fd(SocketAddress *addr, Error **errp);
+
#endif /* QEMU_SOCKETS_H */
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 2463c49773..86316b6314 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -1141,6 +1141,25 @@ static int socket_get_fd(const char *fdstr, Error **errp)
return fd;
}
+int socket_address_parse_named_fd(SocketAddress *addr, Error **errp)
+{
+ int fd;
+
+ if (addr->type != SOCKET_ADDRESS_TYPE_FD) {
+ return 0;
+ }
+
+ fd = socket_get_fd(addr->u.fd.str, errp);
+ if (fd < 0) {
+ return fd;
+ }
+
+ g_free(addr->u.fd.str);
+ addr->u.fd.str = g_strdup_printf("%d", fd);
+
+ return 0;
+}
+
int socket_connect(SocketAddress *addr, Error **errp)
{
int fd;
--
2.29.2
- [PATCH v4 10/32] block/nbd: simplify waking of nbd_co_establish_connection(), (continued)
- [PATCH v4 10/32] block/nbd: simplify waking of nbd_co_establish_connection(), Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 17/32] nbd: move connection code from block/nbd to nbd/client-connection, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 12/32] block/nbd: bs-independent interface for nbd_co_establish_connection(), Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 18/32] nbd/client-connection: use QEMU_LOCK_GUARD, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 19/32] nbd/client-connection: add possibility of negotiation, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 11/32] block/nbd: drop thr->state, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 05/32] qemu-sockets: introduce socket_address_parse_named_fd(),
Vladimir Sementsov-Ogievskiy <=
- [PATCH v4 13/32] block/nbd: make nbd_co_establish_connection_cancel() bs-independent, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 15/32] block/nbd: introduce nbd_client_connection_new(), Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 21/32] nbd/client-connection: shutdown connection on release, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 25/32] block/nbd: drop BDRVNBDState::sioc, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 27/32] block-coroutine-wrapper: allow non bdrv_ prefix, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 16/32] block/nbd: introduce nbd_client_connection_release(), Vladimir Sementsov-Ogievskiy, 2021/06/10