[PATCHES] messaging iov / recvfrom

Michael Adam obnox at samba.org
Mon Jun 2 13:39:25 MDT 2014


Comments?

On 2014-05-31 at 12:26 +0200, Michael Adam wrote:
> Andreas, Jeremy,
> 
> attached find a patchset that adds the required
> checks for the existence of msg_control.
> 
> It also makes samba use the same define name
> as socket_wrapper, so that we are consistent
> and slightly cleans the use of the defines
> in vfs_aio_fork.c, the only previous user
> of msg_control.
> 
> Review/push/comments appreciated!
> 
> Cheers - Michael
> 
> On 2014-05-30 at 15:39 -0700, Jeremy Allison wrote:
> > On Fri, May 30, 2014 at 09:35:06AM +0200, Andreas Schneider wrote:
> > > On Thursday 29 May 2014 14:31:55 Jeremy Allison wrote:
> > > > On Mon, May 26, 2014 at 05:07:44PM +0200, Michael Adam wrote:
> > > > > Oops, there was a bug in the first patch.
> > > > > Sorry for posting prematurely...
> > > > > Attaching a fixed version.
> > > > > 
> > > > > Thanks - Michael
> > > > > 
> > > > > On 2014-05-26 at 15:52 +0200, Michael Adam wrote:
> > > > > > Hi,
> > > > > > 
> > > > > > as a result of my work towards adding support for fd-passing
> > > > > > to our messaging, find attached two first preparatory patches
> > > > > > that might already be useful.
> > > > > > 
> > > > > > The first changes the send_fn to use struct  iovec
> > > > > > instead of data blob. (Volker has already looked
> > > > > > over this one.)
> > > > > > 
> > > > > > The second one lets unix_dgram_recv_handler()
> > > > > > use recvmsg() instead of recv().
> > > > > > 
> > > > > > Review/push/comments appreciated.
> > > > 
> > > > LGTM ! Pushed to autobuild.
> > > 
> > > 
> > > 
> > > 
> > > I gave a NAK! Why do you push it now?
> > 
> > Because the only complaint I saw from
> > you was clearly incorrect (the bit
> > around the dot-initialization).
> > 
> > I didn't notice the other issue, so
> > I assumed it was good to go.
> > 
> > Sorry !
> > 
> > Jeremy.

> From f662c6b6493d69de5be3f19a9ab277abe6c78722 Mon Sep 17 00:00:00 2001
> From: Michael Adam <obnox at samba.org>
> Date: Sat, 31 May 2014 11:58:01 +0200
> Subject: [PATCH 1/4] vfs:aio_fork: simplify checking of MSG_CONTROL and
>  MSG_ACCTRIGHTS
> 
> Signed-off-by: Michael Adam <obnox at samba.org>
> ---
>  source3/modules/vfs_aio_fork.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
> index dc33031..c3dc188 100644
> --- a/source3/modules/vfs_aio_fork.c
> +++ b/source3/modules/vfs_aio_fork.c
> @@ -27,6 +27,10 @@
>  #include "lib/async_req/async_sock.h"
>  #include "lib/util/tevent_unix.h"
>  
> +#if !defined(HAVE_MSGHDR_MSG_CONTROL) && !defined(HAVE_MSGHDR_MSG_ACCTRIGHTS)
> +# error Can not pass file descriptors
> +#endif
> +
>  #undef recvmsg
>  
>  #ifndef MAP_FILE
> @@ -152,9 +156,11 @@ static ssize_t read_fd(int fd, void *ptr, size_t nbytes, int *recvfd)
>  	ssize_t n;
>  #ifndef HAVE_MSGHDR_MSG_CONTROL
>  	int newfd;
> -#endif
>  
> -#ifdef	HAVE_MSGHDR_MSG_CONTROL
> +	msg.msg_accrights = (caddr_t) &newfd;
> +	msg.msg_accrightslen = sizeof(int);
> +#else
> +
>  	union {
>  	  struct cmsghdr	cm;
>  	  char				control[CMSG_SPACE(sizeof(int))];
> @@ -163,13 +169,6 @@ static ssize_t read_fd(int fd, void *ptr, size_t nbytes, int *recvfd)
>  
>  	msg.msg_control = control_un.control;
>  	msg.msg_controllen = sizeof(control_un.control);
> -#else
> -#if HAVE_MSGHDR_MSG_ACCTRIGHTS
> -	msg.msg_accrights = (caddr_t) &newfd;
> -	msg.msg_accrightslen = sizeof(int);
> -#else
> -#error Can not pass file descriptors
> -#endif
>  #endif
>  
>  	msg.msg_name = NULL;
> -- 
> 1.9.1
> 
> 
> From ddcf24406e4f02fddbfeab4411f212784b3949ac Mon Sep 17 00:00:00 2001
> From: Michael Adam <obnox at samba.org>
> Date: Sat, 31 May 2014 12:04:05 +0200
> Subject: [PATCH 2/4] build: rename HAVE_MSGHDR_MSG_CONTROL to
>  HAVE_STRUCT_MSGHDR_MSG_CONTROL
> 
> So that we are consistent with the socket_wrapper define.
> 
> Signed-off-by: Michael Adam <obnox at samba.org>
> ---
>  source3/modules/vfs_aio_fork.c | 8 ++++----
>  source3/wscript                | 4 ++--
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
> index c3dc188..d8a99b0 100644
> --- a/source3/modules/vfs_aio_fork.c
> +++ b/source3/modules/vfs_aio_fork.c
> @@ -27,7 +27,7 @@
>  #include "lib/async_req/async_sock.h"
>  #include "lib/util/tevent_unix.h"
>  
> -#if !defined(HAVE_MSGHDR_MSG_CONTROL) && !defined(HAVE_MSGHDR_MSG_ACCTRIGHTS)
> +#if !defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) && !defined(HAVE_MSGHDR_MSG_ACCTRIGHTS)
>  # error Can not pass file descriptors
>  #endif
>  
> @@ -154,7 +154,7 @@ static ssize_t read_fd(int fd, void *ptr, size_t nbytes, int *recvfd)
>  	struct msghdr msg;
>  	struct iovec iov[1];
>  	ssize_t n;
> -#ifndef HAVE_MSGHDR_MSG_CONTROL
> +#ifndef HAVE_STRUCT_MSGHDR_MSG_CONTROL
>  	int newfd;
>  
>  	msg.msg_accrights = (caddr_t) &newfd;
> @@ -184,7 +184,7 @@ static ssize_t read_fd(int fd, void *ptr, size_t nbytes, int *recvfd)
>  		return(n);
>  	}
>  
> -#ifdef	HAVE_MSGHDR_MSG_CONTROL
> +#ifdef	HAVE_STRUCT_MSGHDR_MSG_CONTROL
>  	if ((cmptr = CMSG_FIRSTHDR(&msg)) != NULL
>  	    && cmptr->cmsg_len == CMSG_LEN(sizeof(int))) {
>  		if (cmptr->cmsg_level != SOL_SOCKET) {
> @@ -218,7 +218,7 @@ static ssize_t write_fd(int fd, void *ptr, size_t nbytes, int sendfd)
>  	struct msghdr	msg;
>  	struct iovec	iov[1];
>  
> -#ifdef	HAVE_MSGHDR_MSG_CONTROL
> +#ifdef	HAVE_STRUCT_MSGHDR_MSG_CONTROL
>  	union {
>  		struct cmsghdr	cm;
>  		char control[CMSG_SPACE(sizeof(int))];
> diff --git a/source3/wscript b/source3/wscript
> index 3b38d19..25dfa2e 100644
> --- a/source3/wscript
> +++ b/source3/wscript
> @@ -552,7 +552,7 @@ union {
>  msg.msg_control = control_un.control;
>  msg.msg_controllen = sizeof(control_un.control);
>  ''',
> -        'HAVE_MSGHDR_MSG_CONTROL',
> +        'HAVE_STRUCT_MSGHDR_MSG_CONTROL',
>          msg='Checking if we can use msg_control for passing file descriptors',
>          headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
>      conf.CHECK_CODE('''
> @@ -1841,7 +1841,7 @@ main() {
>      if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
>          default_shared_modules.extend(TO_LIST('vfs_fileid'))
>  
> -    if (conf.CONFIG_SET('HAVE_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
> +    if (conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
>          default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
>  
>      if Options.options.with_pthreadpool:
> -- 
> 1.9.1
> 
> 
> From 26fbc81116d28b15b830d9151dc460f32ef8b3e7 Mon Sep 17 00:00:00 2001
> From: Michael Adam <obnox at samba.org>
> Date: Sat, 31 May 2014 12:05:50 +0200
> Subject: [PATCH 3/4] build: rename HAVE_MSGHDR_MSG_ACCTRIGHTS to
>  HAVE_STRUCT_MSGHDR_MSG_ACCTRIGHTS
> 
> for consistency.
> 
> Signed-off-by: Michael Adam <obnox at samba.org>
> ---
>  source3/modules/vfs_aio_fork.c | 2 +-
>  source3/wscript                | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
> index d8a99b0..97ec1cd 100644
> --- a/source3/modules/vfs_aio_fork.c
> +++ b/source3/modules/vfs_aio_fork.c
> @@ -27,7 +27,7 @@
>  #include "lib/async_req/async_sock.h"
>  #include "lib/util/tevent_unix.h"
>  
> -#if !defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) && !defined(HAVE_MSGHDR_MSG_ACCTRIGHTS)
> +#if !defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) && !defined(HAVE_STRUCT_MSGHDR_MSG_ACCTRIGHTS)
>  # error Can not pass file descriptors
>  #endif
>  
> diff --git a/source3/wscript b/source3/wscript
> index 25dfa2e..cf9d787 100644
> --- a/source3/wscript
> +++ b/source3/wscript
> @@ -561,7 +561,7 @@ int fd;
>  msg.msg_acctrights = (caddr_t) &fd;
>  msg.msg_acctrightslen = sizeof(fd);
>  ''',
> -        'HAVE_MSGHDR_MSG_ACCTRIGHTS',
> +        'HAVE_STRUCT_MSGHDR_MSG_ACCTRIGHTS',
>          msg='Checking if we can use msg_acctrights for passing file descriptors',
>          headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
>  
> @@ -1841,7 +1841,7 @@ main() {
>      if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
>          default_shared_modules.extend(TO_LIST('vfs_fileid'))
>  
> -    if (conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
> +    if (conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_ACCTRIGHTS')):
>          default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
>  
>      if Options.options.with_pthreadpool:
> -- 
> 1.9.1
> 
> 
> From e2f20a2b3bc3626ffc7cc807870d1fffb816c1fc Mon Sep 17 00:00:00 2001
> From: Michael Adam <obnox at samba.org>
> Date: Sat, 31 May 2014 12:16:08 +0200
> Subject: [PATCH 4/4] s3:messaging: protect use of msg_control with
>  HAVE_STRUCT_MSGHDR_MSG_CONTROL
> 
> Signed-off-by: Michael Adam <obnox at samba.org>
> ---
>  source3/lib/unix_msg/unix_msg.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c
> index bcabd28..602ecc6 100644
> --- a/source3/lib/unix_msg/unix_msg.c
> +++ b/source3/lib/unix_msg/unix_msg.c
> @@ -244,8 +244,10 @@ static void unix_dgram_recv_handler(struct poll_watch *w, int fd, short events,
>  	msg = (struct msghdr) {
>  		.msg_iov = &iov,
>  		.msg_iovlen = 1,
> +#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
>  		.msg_control = NULL,
>  		.msg_controllen = 0,
> +#endif
>  	};
>  
>  	received = recvmsg(fd, &msg, 0);
> @@ -509,8 +511,10 @@ static int unix_dgram_send(struct unix_dgram_ctx *ctx, const char *dst_sock,
>  	msg.msg_namelen = sizeof(addr);
>  	msg.msg_iov = discard_const_p(struct iovec, iov);
>  	msg.msg_iovlen = iovlen;
> +#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
>  	msg.msg_control = NULL;
>  	msg.msg_controllen = 0;
> +#endif
>  	msg.msg_flags = 0;
>  
>  	ret = sendmsg(ctx->sock, &msg, 0);
> -- 
> 1.9.1
> 



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20140602/c367bbc6/attachment.pgp>


More information about the samba-technical mailing list