[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/6] virtio-9p-proxy: replace v9fs_receivefd with qe
From: |
Lei Li |
Subject: |
[Qemu-devel] [PATCH 5/6] virtio-9p-proxy: replace v9fs_receivefd with qemu_recv_with_fd |
Date: |
Wed, 8 Jan 2014 17:12:55 +0800 |
Signed-off-by: Lei Li <address@hidden>
---
hw/9pfs/virtio-9p-proxy.c | 60 ++------------------------------------------
1 files changed, 3 insertions(+), 57 deletions(-)
diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
index 5f44bb7..f34b845 100644
--- a/hw/9pfs/virtio-9p-proxy.c
+++ b/hw/9pfs/virtio-9p-proxy.c
@@ -14,6 +14,7 @@
#include "hw/virtio/virtio.h"
#include "virtio-9p.h"
#include "qemu/error-report.h"
+#include "qemu/fd-exchange.h"
#include "fsdev/qemu-fsdev.h"
#include "virtio-9p-proxy.h"
@@ -24,62 +25,6 @@ typedef struct V9fsProxy {
struct iovec out_iovec;
} V9fsProxy;
-/*
- * Return received file descriptor on success in *status.
- * errno is also returned on *status (which will be < 0)
- * return < 0 on transport error.
- */
-static int v9fs_receivefd(int sockfd, int *status)
-{
- struct iovec iov;
- struct msghdr msg;
- struct cmsghdr *cmsg;
- int retval, data, fd;
- union MsgControl msg_control;
-
- iov.iov_base = &data;
- iov.iov_len = sizeof(data);
-
- memset(&msg, 0, sizeof(msg));
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
- msg.msg_control = &msg_control;
- msg.msg_controllen = sizeof(msg_control);
-
- do {
- retval = recvmsg(sockfd, &msg, 0);
- } while (retval < 0 && errno == EINTR);
- if (retval <= 0) {
- return retval;
- }
- /*
- * data is set to V9FS_FD_VALID, if ancillary data is sent. If this
- * request doesn't need ancillary data (fd) or an error occurred,
- * data is set to negative errno value.
- */
- if (data != V9FS_FD_VALID) {
- *status = data;
- return 0;
- }
- /*
- * File descriptor (fd) is sent in the ancillary data. Check if we
- * indeed received it. One of the reasons to fail to receive it is if
- * we exceeded the maximum number of file descriptors!
- */
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
- if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)) ||
- cmsg->cmsg_level != SOL_SOCKET ||
- cmsg->cmsg_type != SCM_RIGHTS) {
- continue;
- }
- fd = *((int *)CMSG_DATA(cmsg));
- *status = fd;
- return 0;
- }
- *status = -ENFILE; /* Ancillary data sent but not received */
- return 0;
-}
-
static ssize_t socket_read(int sockfd, void *buff, size_t size)
{
ssize_t retval, total = 0;
@@ -307,6 +252,7 @@ static int v9fs_request(V9fsProxy *proxy, int type,
V9fsString *name, *value;
V9fsString *path, *oldpath;
struct iovec *iovec = NULL, *reply = NULL;
+ int data = V9FS_FD_VALID;
qemu_mutex_lock(&proxy->mutex);
@@ -548,7 +494,7 @@ static int v9fs_request(V9fsProxy *proxy, int type,
* A file descriptor is returned as response for
* T_OPEN,T_CREATE on success
*/
- if (v9fs_receivefd(proxy->sockfd, &retval) < 0) {
+ if (qemu_recv_with_fd(proxy->sockfd, &retval, &data, sizeof(data)) <
0) {
goto close_error;
}
break;
--
1.7.7.6
- Re: [Qemu-devel] [PATCH 1/6] qemu-fd-exchange: provide common methods for exchange fd, (continued)
- [Qemu-devel] [PATCH 2/6] qemu-bridge-helper: replace send_fd with qemu_send_with_fd, Lei Li, 2014/01/08
- [Qemu-devel] [PATCH 4/6] virtfs-proxy-helper: replace send_fd with qemu_send_with_fd, Lei Li, 2014/01/08
- [Qemu-devel] [PATCH 3/6] net/tap: replace recv_fd with qemu_recv_with_fd, Lei Li, 2014/01/08
- [Qemu-devel] [PATCH 5/6] virtio-9p-proxy: replace v9fs_receivefd with qemu_recv_with_fd,
Lei Li <=
- [Qemu-devel] [PATCH 6/6] migration-local: replace send_pipefd with qemu_send_with_fd, Lei Li, 2014/01/08
- Re: [Qemu-devel] [PATCH resend 0/6 RFC] Provide common methods for exchange FD, Lei Li, 2014/01/16
- Re: [Qemu-devel] [PATCH resend 0/6 RFC] Provide common methods for exchange FD, Daniel P. Berrange, 2014/01/16