Re: [PATCH] Packet socket: directly access the mmapped ring buffer

2006-02-08 Thread Evgeniy Polyakov
On Wed, Feb 08, 2006 at 02:26:32PM +0900, FUJITA Tomonori ([EMAIL PROTECTED]) 
wrote:
> Mike Christie and I've developed the SCSI Userspace target
> framework. Target LLDs (for Fibre channel, iSCSI HBAs, etc) pass SCSI
> commands to SCSI commands to the user-space daemon. The daemon
> executes the commands and sends the results back to the LLDs.
> 
> Please refer scsi-ml for further details.
> 
> http://thread.gmane.org/gmane.linux.scsi/22409
> 
> We need efficient kernel and user-space communication interface and
> used netlink. Jeff Garzik suggested the packet socket mmap'd ring
> buffer.
> 
> The mmap'd ring buffer is really nice, but we want to access directly
> the ring buffer withough going through the networking stack to avoid
> memory allocation and overhead.

Depending on calling context, it can be not sufficient to leave sofirqs
enabled in that function.
 
> Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
> Signed-off-by: Mike Christie <[EMAIL PROTECTED]>
> ---
> 
>  include/net/af_packet.h |6 ++
>  net/packet/af_packet.c  |   17 +
>  2 files changed, 23 insertions(+), 0 deletions(-)
>  create mode 100644 include/net/af_packet.h
> 
> c627f3a1da6e5e7e9e46d58401adcf168ea45787
> diff --git a/include/net/af_packet.h b/include/net/af_packet.h
> new file mode 100644
> index 000..5a75e07
> --- /dev/null
> +++ b/include/net/af_packet.h
> @@ -0,0 +1,6 @@
> +#ifndef __LINUX_NET_AFPACKET_H
> +#define __LINUX_NET_AFPACKET_H
> +
> +extern struct tpacket_hdr *packet_socket_frame(struct sock *sk);
> +
> +#endif
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 9db7dbd..b5fbd74 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -562,6 +562,23 @@ drop:
>  }
>  
>  #ifdef CONFIG_PACKET_MMAP
> +struct tpacket_hdr *packet_socket_frame(struct sock *sk)
> +{
> + struct packet_sock *po;
> + struct tpacket_hdr *h;
> +
> + po = pkt_sk(sk);
> + spin_lock(&sk->sk_receive_queue.lock);
> + h = (struct tpacket_hdr *) packet_lookup_frame(po, po->head);
> + if (h->tp_status)
> + h = ERR_PTR(-ENOBUFS);
> + else
> + po->head = po->head != po->frame_max ? po->head+1 : 0;
> + spin_unlock(&sk->sk_receive_queue.lock);
> + return h;
> +}
> +EXPORT_SYMBOL_GPL(packet_socket_frame);
> +
>  static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct 
> packet_type *pt, struct net_device *orig_dev)
>  {
>   struct sock *sk;
> -- 
> 1.1.3

-- 
Evgeniy Polyakov
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Packet socket: directly access the mmapped ring buffer

2006-02-07 Thread FUJITA Tomonori
Mike Christie and I've developed the SCSI Userspace target
framework. Target LLDs (for Fibre channel, iSCSI HBAs, etc) pass SCSI
commands to SCSI commands to the user-space daemon. The daemon
executes the commands and sends the results back to the LLDs.

Please refer scsi-ml for further details.

http://thread.gmane.org/gmane.linux.scsi/22409

We need efficient kernel and user-space communication interface and
used netlink. Jeff Garzik suggested the packet socket mmap'd ring
buffer.

The mmap'd ring buffer is really nice, but we want to access directly
the ring buffer withough going through the networking stack to avoid
memory allocation and overhead.


Signed-off-by: FUJITA Tomonori <[EMAIL PROTECTED]>
Signed-off-by: Mike Christie <[EMAIL PROTECTED]>
---

 include/net/af_packet.h |6 ++
 net/packet/af_packet.c  |   17 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 include/net/af_packet.h

c627f3a1da6e5e7e9e46d58401adcf168ea45787
diff --git a/include/net/af_packet.h b/include/net/af_packet.h
new file mode 100644
index 000..5a75e07
--- /dev/null
+++ b/include/net/af_packet.h
@@ -0,0 +1,6 @@
+#ifndef __LINUX_NET_AFPACKET_H
+#define __LINUX_NET_AFPACKET_H
+
+extern struct tpacket_hdr *packet_socket_frame(struct sock *sk);
+
+#endif
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 9db7dbd..b5fbd74 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -562,6 +562,23 @@ drop:
 }
 
 #ifdef CONFIG_PACKET_MMAP
+struct tpacket_hdr *packet_socket_frame(struct sock *sk)
+{
+   struct packet_sock *po;
+   struct tpacket_hdr *h;
+
+   po = pkt_sk(sk);
+   spin_lock(&sk->sk_receive_queue.lock);
+   h = (struct tpacket_hdr *) packet_lookup_frame(po, po->head);
+   if (h->tp_status)
+   h = ERR_PTR(-ENOBUFS);
+   else
+   po->head = po->head != po->frame_max ? po->head+1 : 0;
+   spin_unlock(&sk->sk_receive_queue.lock);
+   return h;
+}
+EXPORT_SYMBOL_GPL(packet_socket_frame);
+
 static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct 
packet_type *pt, struct net_device *orig_dev)
 {
struct sock *sk;
-- 
1.1.3
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html