linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Javier Martinez Canillas <javier@collabora.co.uk>
To: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
	Lennart Poettering <lennart@poettering.net>,
	Kay Sievers <kay.sievers@vrfy.org>,
	Alban Crequy <alban.crequy@collabora.co.uk>,
	Bart Cerneels <bart.cerneels@collabora.co.uk>,
	Rodrigo Moya <rodrigo.moya@collabora.co.uk>,
	Sjoerd Simons <sjoerd.simons@collabora.co.uk>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 07/10] af_unix: implement poll(POLLOUT) for multicast sockets
Date: Mon, 20 Feb 2012 17:33:46 +0100	[thread overview]
Message-ID: <1329755629-10644-4-git-send-email-javier@collabora.co.uk> (raw)
In-Reply-To: <1329755629-10644-1-git-send-email-javier@collabora.co.uk>

From: Alban Crequy <alban.crequy@collabora.co.uk>

When a socket subscribed to a multicast group has its incoming queue full, it
can either block the emission to the multicast group or let the messages be
dropped. The latter is useful to monitor all messages without slowing down the
traffic.

It is specified with the flag UNIX_MREQ_DROP_WHEN_FULL when the multicast group
is joined.

poll(POLLOUT) is implemented by checking all receiving queues of subscribed
sockets. If only one of them has its receiving queue full and does not have
UNIX_MREQ_DROP_WHEN_FULL, the multicast socket is not writeable.

Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
Reviewed-by: Ian Molton <ian.molton@collabora.co.uk>
---
 net/unix/af_unix.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index a6b489c..bd9dc58 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2974,6 +2974,11 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
 {
 	struct sock *sk = sock->sk, *other;
 	unsigned int mask, writable;
+#ifdef CONFIG_UNIX_MULTICAST
+	struct sock_set *others;
+	int err = 0;
+	int i;
+#endif
 
 	sock_poll_wait(file, sk_sleep(sk), wait);
 	mask = 0;
@@ -3011,6 +3016,48 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
 			if (unix_recvq_full(other))
 				writable = 0;
 		}
+
+#ifdef CONFIG_UNIX_MULTICAST
+		/*
+		 * On multicast sockets, we need to check if the receiving
+		 * queue is full on all peers who don't have
+		 * UNIX_MREQ_DROP_WHEN_FULL.
+		 */
+
+		/* Don't let the group die under us */
+		unix_state_lock(other);
+		if (sock_flag(other, SOCK_DEAD)
+			|| !unix_sk(other)->mcast_group) {
+			unix_state_unlock(other);
+			goto skip_multicast;
+		}
+		atomic_inc(&unix_sk(other)->mcast_group->refcnt);
+		unix_state_unlock(other);
+
+		others = unix_find_multicast_recipients(sk,
+			unix_sk(other)->mcast_group, &err);
+		if (!others)
+			goto skip_multicast_peers;
+		for (i = others->offset ; i < others->cnt ; i++) {
+			if (others->items[i].flags & UNIX_MREQ_DROP_WHEN_FULL)
+				continue;
+			if (unix_peer(others->items[i].s) != sk) {
+				sock_poll_wait(file,
+					&unix_sk(others->items[i].s)
+						->peer_wait, wait);
+				if (unix_recvq_full(others->items[i].s)) {
+					writable = 0;
+					break;
+				}
+			}
+		}
+		up_sock_set(others);
+skip_multicast_peers:
+		if (atomic_dec_and_test(&unix_sk(other)->mcast_group->refcnt))
+			destroy_mcast_group(unix_sk(other)->mcast_group);
+
+skip_multicast:
+#endif
 		sock_put(other);
 	}
 
-- 
1.7.7.6


  parent reply	other threads:[~2012-02-20 16:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-20 16:33 [PATCH 04/10] af_unix: create, join and leave multicast groups with setsockopt Javier Martinez Canillas
2012-02-20 16:33 ` [PATCH 05/10] af_unix: find the recipients of a multicast group Javier Martinez Canillas
2012-02-20 16:33 ` [PATCH 06/10] af_unix: Deliver message to several recipients in case of multicast Javier Martinez Canillas
2012-02-20 16:33 ` Javier Martinez Canillas [this message]
2012-02-20 16:33 ` [PATCH 08/10] af_unix: Unsubscribe sockets from their multicast groups on RCV_SHUTDOWN Javier Martinez Canillas
2012-02-20 16:33 ` [PATCH 09/10] Allow server side of SOCK_SEQPACKET sockets to accept a new member on the multicast groujoin seqpacket multicast group Javier Martinez Canillas
2012-02-20 16:33 ` [PATCH 10/10] af_unix: Add a peer BPF for multicast Unix sockets Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1329755629-10644-4-git-send-email-javier@collabora.co.uk \
    --to=javier@collabora.co.uk \
    --cc=alban.crequy@collabora.co.uk \
    --cc=bart.cerneels@collabora.co.uk \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=kay.sievers@vrfy.org \
    --cc=lennart@poettering.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rodrigo.moya@collabora.co.uk \
    --cc=sjoerd.simons@collabora.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).