[PATCH 5/6] SCSI Userspace Target: the packet socket interface changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Directly access the ring buffer provided by the packet socket mmapped IO.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx>
Signed-off-by: Mike Christie <michaelc@xxxxxxxxxxx>
---

 include/linux/if_packet.h |    2 +-
 include/net/af_packet.h   |    6 ++++++
 net/packet/af_packet.c    |   17 +++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletions(-)
 create mode 100644 include/net/af_packet.h

1d699e6f31ee90015042731e16a7d795ae0d67be
diff --git a/include/linux/if_packet.h b/include/linux/if_packet.h
index b925585..c66d555 100644
--- a/include/linux/if_packet.h
+++ b/include/linux/if_packet.h
@@ -48,7 +48,7 @@ struct tpacket_stats
 
 struct tpacket_hdr
 {
-	unsigned long	tp_status;
+	unsigned int	tp_status;
 #define TP_STATUS_KERNEL	0
 #define TP_STATUS_USER		1
 #define TP_STATUS_COPY		2
diff --git a/include/net/af_packet.h b/include/net/af_packet.h
new file mode 100644
index 0000000..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
-
: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux