netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tadeusz Struk <tadeusz.struk@intel.com>
To: davem@davemloft.net
Cc: linux-aio@kvack.org, herbert@gondor.apana.org.au,
	netdev@vger.kernel.org, ying.xue@windriver.com, bcrl@kvack.org,
	viro@ZenIV.linux.org.uk, linux-fsdevel@vger.kernel.org,
	hch@lst.de, linux-crypto@vger.kernel.org
Subject: [PATCH v2 net-next 1/4] net: socket: add support for async operations
Date: Mon, 16 Mar 2015 09:15:14 -0700	[thread overview]
Message-ID: <20150316161514.16418.67336.stgit@tstruk-mobl1> (raw)
In-Reply-To: <20150316161508.16418.23674.stgit@tstruk-mobl1>

Add support for async operations.

Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
---
 include/linux/net.h |    5 ++++
 net/socket.c        |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/include/linux/net.h b/include/linux/net.h
index e74114b..e9180bf 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -25,6 +25,7 @@
 #include <linux/kmemcheck.h>
 #include <linux/rcupdate.h>
 #include <linux/jump_label.h>
+#include <linux/aio.h>
 #include <uapi/linux/net.h>
 
 struct poll_table_struct;
@@ -173,6 +174,10 @@ struct proto_ops {
 	 */
 	int		(*recvmsg)   (struct socket *sock, struct msghdr *m,
 				      size_t total_len, int flags);
+	int		(*aio_sendmsg)(struct kiocb *iocb, struct socket *sock,
+				       struct msghdr *m);
+	int		(*aio_recvmsg)(struct kiocb *iocb, struct socket *sock,
+				       struct msghdr *m, int flags);
 	int		(*mmap)	     (struct file *file, struct socket *sock,
 				      struct vm_area_struct * vma);
 	ssize_t		(*sendpage)  (struct socket *sock, struct page *page,
diff --git a/net/socket.c b/net/socket.c
index 95d3085..1364dfb 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -132,6 +132,11 @@ static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
 				struct pipe_inode_info *pipe, size_t len,
 				unsigned int flags);
 
+static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
+			     unsigned long nr_segs, loff_t loff);
+static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov,
+			      unsigned long nr_segs, loff_t loff);
+
 /*
  *	Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
  *	in the operation structures but are done directly via the socketcall() multiplexor.
@@ -144,6 +149,8 @@ static const struct file_operations socket_file_ops = {
 	.write =	new_sync_write,
 	.read_iter =	sock_read_iter,
 	.write_iter =	sock_write_iter,
+	.aio_read =	sock_aio_read,
+	.aio_write =	sock_aio_write,
 	.poll =		sock_poll,
 	.unlocked_ioctl = sock_ioctl,
 #ifdef CONFIG_COMPAT
@@ -836,6 +843,62 @@ static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	return res;
 }
 
+static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
+			     unsigned long nr_segs, loff_t loff)
+{
+	struct file *file = iocb->ki_filp;
+	struct socket *sock = file->private_data;
+	struct iov_iter iter;
+	struct msghdr msg = {0};
+	ssize_t res;
+
+	if (file->f_flags & O_NONBLOCK)
+		msg.msg_flags = MSG_DONTWAIT;
+
+	if (iocb->ki_pos != 0)
+		return -ESPIPE;
+
+	if (iocb->ki_nbytes == 0)
+		return 0;
+
+	if (sock->ops->aio_recvmsg) {
+		iov_iter_init(&iter, READ, iov, nr_segs, iocb->ki_nbytes);
+		msg.msg_iter = iter;
+		res = sock->ops->aio_recvmsg(iocb, sock, &msg, msg.msg_flags);
+	} else {
+		res = -EOPNOTSUPP;
+	}
+	return res;
+}
+
+static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov,
+			      unsigned long nr_segs, loff_t loff)
+{
+	struct file *file = iocb->ki_filp;
+	struct socket *sock = file->private_data;
+	struct iov_iter iter;
+	struct msghdr msg = {0};
+	ssize_t res;
+
+	if (iocb->ki_pos != 0)
+		return -ESPIPE;
+
+	if (file->f_flags & O_NONBLOCK)
+		msg.msg_flags = MSG_DONTWAIT;
+
+	if (sock->type == SOCK_SEQPACKET)
+		msg.msg_flags |= MSG_EOR;
+
+	if (sock->ops->aio_sendmsg) {
+		iov_iter_init(&iter, WRITE, iov, nr_segs, iocb->ki_nbytes);
+		msg.msg_iter = iter;
+		res = sock->ops->aio_sendmsg(iocb, sock, &msg);
+	} else {
+		res = -EOPNOTSUPP;
+	}
+	return res;
+}
+
 /*
  * Atomic setting of ioctl hooks to avoid race
  * with module unload.

  reply	other threads:[~2015-03-16 16:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-16 16:15 [PATCH v2 net-next 0/4] Add support for async socket operations Tadeusz Struk
2015-03-16 16:15 ` Tadeusz Struk [this message]
2015-03-19 16:20   ` [PATCH v2 net-next 1/4] net: socket: add support for async operations Al Viro
2015-03-19 17:43     ` Tadeusz Struk
2015-03-19 18:13       ` Al Viro
2015-03-16 16:15 ` [PATCH v2 net-next 2/4] aio: prefer aio_op op over iter_op Tadeusz Struk
2015-03-19 16:22   ` Al Viro
2015-03-16 16:15 ` [PATCH v2 net-next 3/4] crypto: af_alg - Allow to link sgl Tadeusz Struk
2015-03-16 16:15 ` [PATCH v2 net-next 4/4] crypto: algif - change algif_skcipher to be asynchronous Tadeusz Struk
2015-03-18 20:59 ` [PATCH v2 net-next 0/4] Add support for async socket operations Tadeusz Struk
2015-03-18 23:29   ` David Miller

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=20150316161514.16418.67336.stgit@tstruk-mobl1 \
    --to=tadeusz.struk@intel.com \
    --cc=bcrl@kvack.org \
    --cc=davem@davemloft.net \
    --cc=hch@lst.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-aio@kvack.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    --cc=ying.xue@windriver.com \
    /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).