[CRIU] Re: [PATCH 04/10] util-net: Add send_fds and recv_fds
Pavel Emelyanov
xemul at parallels.com
Wed Mar 28 05:56:06 EDT 2012
On 03/27/2012 08:23 PM, Cyrill Gorcunov wrote:
>
> We will need these helpers to transfer file
> descriptors from dumpee to our space.
>
> Also make send_fd/recv_fd to be a wrappers over
> send_fds/revc_fds to not duplicate the code.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
> include/util-net.h | 22 +++++++-
> util-net.c | 144 ++++++++++++++++++++++++++++++++++++---------------
> 2 files changed, 120 insertions(+), 46 deletions(-)
>
> +static int *scm_fdset_init(struct scm_fdset *fdset, struct sockaddr_un *saddr, int saddr_len)
> {
> - char cmsgbuf[CMSG_SPACE(sizeof(int))];
> - struct msghdr hdr = { };
> - struct iovec data = { };
> - struct cmsghdr* cmsg;
> - int *cmsg_data;
> - char dummy = '*';
> + struct cmsghdr *cmsg;
>
> - data.iov_base = &dummy;
> - data.iov_len = sizeof(dummy);
> + BUILD_BUG_ON(CR_SCM_MAX_FD > SCM_MAX_FD);
> + BUILD_BUG_ON(sizeof(fdset->msg_buf) < (CMSG_SPACE(sizeof(int) * CR_SCM_MAX_FD)));
>
> - hdr.msg_name = (struct sockaddr *)saddr;
> - hdr.msg_namelen = len;
> - hdr.msg_iov = &data;
> - hdr.msg_iovlen = 1;
> + fdset->msg = 0;
>
> - hdr.msg_control = &cmsgbuf;
> - hdr.msg_controllen = CMSG_LEN(sizeof(int));
> + fdset->iov.iov_base = &fdset->msg;
> + fdset->iov.iov_len = sizeof(fdset->msg);
>
> - cmsg = CMSG_FIRSTHDR(&hdr);
> - cmsg->cmsg_len = hdr.msg_controllen;
> - cmsg->cmsg_level = SOL_SOCKET;
> - cmsg->cmsg_type = SCM_RIGHTS;
> + fdset->hdr.msg_iov = &fdset->iov;
> + fdset->hdr.msg_iovlen = 1;
> + fdset->hdr.msg_name = (struct sockaddr *)saddr;
> + fdset->hdr.msg_namelen = saddr_len;
>
> - cmsg_data = (int *)CMSG_DATA(cmsg);
> - *cmsg_data = fd;
> + fdset->hdr.msg_control = &fdset->msg_buf;
> + fdset->hdr.msg_controllen = CMSG_LEN(sizeof(int) * CR_SCM_MAX_FD);
>
> - return sys_sendmsg(sock, &hdr, 0);
> + cmsg = CMSG_FIRSTHDR(&fdset->hdr);
> + cmsg->cmsg_len = fdset->hdr.msg_controllen;
> + cmsg->cmsg_level = SOL_SOCKET;
> + cmsg->cmsg_type = SCM_RIGHTS;
> +
> + return (int *)CMSG_DATA(cmsg);
> +}
> +
> +static int scm_fdset_send(int sock, struct scm_fdset *fdset)
> +{
> + int ret = sys_sendmsg(sock, &fdset->hdr, 0);
> + if (ret <= 0)
> + return ret ? : -1;
> + return 0;
> }
You did three changes here.
1. Move all on-stack vars into one one-stack structure
2. Changed the way message (char dummy) is sent
3. Added support for more than one fd per message
Please, remove step #2 and make steps 1 and 3 be in separate patches.
Thanks,
Pavel
More information about the CRIU
mailing list