[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/5] virtfs-proxy-helper: replace send_fd with qemu_
From: |
Lei Li |
Subject: |
[Qemu-devel] [PATCH 4/5] virtfs-proxy-helper: replace send_fd with qemu_send_with_fd |
Date: |
Thu, 23 Jan 2014 16:27:42 +0800 |
Signed-off-by: Lei Li <address@hidden>
---
fsdev/virtfs-proxy-helper.c | 51 ++++++------------------------------------
hw/9pfs/virtio-9p-proxy.h | 5 ----
2 files changed, 8 insertions(+), 48 deletions(-)
diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index 713a7b2..44c6e61 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -23,6 +23,7 @@
#include "qemu-common.h"
#include "qemu/sockets.h"
#include "qemu/xattr.h"
+#include "qemu/fd-exchange.h"
#include "virtio-9p-marshal.h"
#include "hw/9pfs/virtio-9p-proxy.h"
#include "fsdev/virtio-9p-marshal.h"
@@ -203,48 +204,6 @@ static int read_request(int sockfd, struct iovec *iovec,
ProxyHeader *header)
return 0;
}
-static int send_fd(int sockfd, int fd)
-{
- struct msghdr msg;
- struct iovec iov;
- int retval, data;
- struct cmsghdr *cmsg;
- 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;
- /* No ancillary data on error */
- if (fd < 0) {
- /* fd is really negative errno if the request failed */
- data = fd;
- } else {
- data = V9FS_FD_VALID;
- msg.msg_control = &msg_control;
- msg.msg_controllen = sizeof(msg_control);
-
- cmsg = &msg_control.cmsg;
- cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd));
- }
-
- do {
- retval = sendmsg(sockfd, &msg, 0);
- } while (retval < 0 && errno == EINTR);
- if (fd >= 0) {
- close(fd);
- }
- if (retval < 0) {
- return retval;
- }
- return 0;
-}
-
static int send_status(int sockfd, struct iovec *iovec, int status)
{
ProxyHeader header;
@@ -784,11 +743,17 @@ static void usage(char *prog)
static int process_reply(int sock, int type,
struct iovec *out_iovec, int retval)
{
+ int data = V9FS_FD_VALID;
+
switch (type) {
case T_OPEN:
case T_CREATE:
- if (send_fd(sock, retval) < 0) {
+ if (qemu_send_with_fd(sock, retval, &data, sizeof(data)) < 0) {
return -1;
+ } else {
+ if (retval >= 0) {
+ close(retval);
+ }
}
break;
case T_MKNOD:
diff --git a/hw/9pfs/virtio-9p-proxy.h b/hw/9pfs/virtio-9p-proxy.h
index 005c1ad..e359ac5 100644
--- a/hw/9pfs/virtio-9p-proxy.h
+++ b/hw/9pfs/virtio-9p-proxy.h
@@ -24,11 +24,6 @@
#define proxy_marshal(out_sg, offset, fmt, args...) \
v9fs_marshal(out_sg, 1, offset, 0, fmt, ##args)
-union MsgControl {
- struct cmsghdr cmsg;
- char control[CMSG_SPACE(sizeof(int))];
-};
-
typedef struct {
uint32_t type;
uint32_t size;
--
1.7.7.6
- [Qemu-devel] [PATCH 0/5 v2] Provide common methods for exchange FD, Lei Li, 2014/01/23
- [Qemu-devel] [PATCH 2/5] qemu-bridge-helper: replace send_fd with qemu_send_with_fd, Lei Li, 2014/01/23
- [Qemu-devel] [PATCH 1/5] qemu-fd-exchange: provide common methods for exchange fd, Lei Li, 2014/01/23
- [Qemu-devel] [PATCH 4/5] virtfs-proxy-helper: replace send_fd with qemu_send_with_fd,
Lei Li <=
- [Qemu-devel] [PATCH 5/5] virtio-9p-proxy: replace v9fs_receivefd with qemu_recv_with_fd, Lei Li, 2014/01/23
- [Qemu-devel] [PATCH 3/5] net/tap: replace recv_fd with qemu_recv_with_fd, Lei Li, 2014/01/23
- Re: [Qemu-devel] [PATCH 0/5 v2] Provide common methods for exchange FD, Antonios Motakis, 2014/01/23