Commit 3af0bfe5 authored by Al Viro's avatar Al Viro

switch macvtap to ->read_iter()

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 9b067034
...@@ -831,64 +831,55 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q, ...@@ -831,64 +831,55 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
} }
static ssize_t macvtap_do_read(struct macvtap_queue *q, static ssize_t macvtap_do_read(struct macvtap_queue *q,
const struct iovec *iv, unsigned long segs, struct iov_iter *to,
unsigned long len,
int noblock) int noblock)
{ {
DEFINE_WAIT(wait); DEFINE_WAIT(wait);
struct sk_buff *skb; struct sk_buff *skb;
ssize_t ret = 0; ssize_t ret = 0;
struct iov_iter iter;
while (len) { if (!iov_iter_count(to))
return 0;
while (1) {
if (!noblock) if (!noblock)
prepare_to_wait(sk_sleep(&q->sk), &wait, prepare_to_wait(sk_sleep(&q->sk), &wait,
TASK_INTERRUPTIBLE); TASK_INTERRUPTIBLE);
/* Read frames from the queue */ /* Read frames from the queue */
skb = skb_dequeue(&q->sk.sk_receive_queue); skb = skb_dequeue(&q->sk.sk_receive_queue);
if (!skb) { if (skb)
if (noblock) { break;
ret = -EAGAIN; if (noblock) {
break; ret = -EAGAIN;
} break;
if (signal_pending(current)) {
ret = -ERESTARTSYS;
break;
}
/* Nothing to read, let's sleep */
schedule();
continue;
} }
iov_iter_init(&iter, READ, iv, segs, len); if (signal_pending(current)) {
ret = macvtap_put_user(q, skb, &iter); ret = -ERESTARTSYS;
break;
}
/* Nothing to read, let's sleep */
schedule();
}
if (skb) {
ret = macvtap_put_user(q, skb, to);
kfree_skb(skb); kfree_skb(skb);
break;
} }
if (!noblock) if (!noblock)
finish_wait(sk_sleep(&q->sk), &wait); finish_wait(sk_sleep(&q->sk), &wait);
return ret; return ret;
} }
static ssize_t macvtap_aio_read(struct kiocb *iocb, const struct iovec *iv, static ssize_t macvtap_read_iter(struct kiocb *iocb, struct iov_iter *to)
unsigned long count, loff_t pos)
{ {
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct macvtap_queue *q = file->private_data; struct macvtap_queue *q = file->private_data;
ssize_t len, ret = 0; ssize_t len = iov_iter_count(to), ret;
len = iov_length(iv, count); ret = macvtap_do_read(q, to, file->f_flags & O_NONBLOCK);
if (len < 0) {
ret = -EINVAL;
goto out;
}
ret = macvtap_do_read(q, iv, count, len, file->f_flags & O_NONBLOCK);
ret = min_t(ssize_t, ret, len); ret = min_t(ssize_t, ret, len);
if (ret > 0) if (ret > 0)
iocb->ki_pos = ret; iocb->ki_pos = ret;
out:
return ret; return ret;
} }
...@@ -1089,7 +1080,8 @@ static const struct file_operations macvtap_fops = { ...@@ -1089,7 +1080,8 @@ static const struct file_operations macvtap_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = macvtap_open, .open = macvtap_open,
.release = macvtap_release, .release = macvtap_release,
.aio_read = macvtap_aio_read, .read = new_sync_read,
.read_iter = macvtap_read_iter,
.aio_write = macvtap_aio_write, .aio_write = macvtap_aio_write,
.poll = macvtap_poll, .poll = macvtap_poll,
.llseek = no_llseek, .llseek = no_llseek,
...@@ -1112,11 +1104,12 @@ static int macvtap_recvmsg(struct kiocb *iocb, struct socket *sock, ...@@ -1112,11 +1104,12 @@ static int macvtap_recvmsg(struct kiocb *iocb, struct socket *sock,
int flags) int flags)
{ {
struct macvtap_queue *q = container_of(sock, struct macvtap_queue, sock); struct macvtap_queue *q = container_of(sock, struct macvtap_queue, sock);
struct iov_iter to;
int ret; int ret;
if (flags & ~(MSG_DONTWAIT|MSG_TRUNC)) if (flags & ~(MSG_DONTWAIT|MSG_TRUNC))
return -EINVAL; return -EINVAL;
ret = macvtap_do_read(q, m->msg_iov, m->msg_iovlen, total_len, iov_iter_init(&to, READ, m->msg_iov, m->msg_iovlen, total_len);
flags & MSG_DONTWAIT); ret = macvtap_do_read(q, &to, flags & MSG_DONTWAIT);
if (ret > total_len) { if (ret > total_len) {
m->msg_flags |= MSG_TRUNC; m->msg_flags |= MSG_TRUNC;
ret = flags & MSG_TRUNC ? ret : total_len; ret = flags & MSG_TRUNC ? ret : total_len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment