Skip to content

Commit

Permalink
tap: add support for IOCB_NOWAIT
Browse files Browse the repository at this point in the history
The tap driver already supports passing in nonblocking state based
on O_NONBLOCK, add support for checking IOCB_NOWAIT as well. With that
done, we can flag it with FMODE_NOWAIT as well.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Link: https://lore.kernel.org/r/8f859870-e6e2-09ca-9c0f-a2aa7c984fb2@kernel.dk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jens Axboe authored and Jakub Kicinski committed Mar 11, 2023
1 parent 438b406 commit f758bfe
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions drivers/net/tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ static int tap_open(struct inode *inode, struct file *file)
goto err_put;
}

/* tap groks IOCB_NOWAIT just fine, mark it as such */
file->f_mode |= FMODE_NOWAIT;

dev_put(tap->dev);

rtnl_unlock();
Expand Down Expand Up @@ -771,8 +774,12 @@ static ssize_t tap_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
struct file *file = iocb->ki_filp;
struct tap_queue *q = file->private_data;
int noblock = 0;

if ((file->f_flags & O_NONBLOCK) || (iocb->ki_flags & IOCB_NOWAIT))
noblock = 1;

return tap_get_user(q, NULL, from, file->f_flags & O_NONBLOCK);
return tap_get_user(q, NULL, from, noblock);
}

/* Put packet to the user space buffer */
Expand Down Expand Up @@ -888,8 +895,12 @@ static ssize_t tap_read_iter(struct kiocb *iocb, struct iov_iter *to)
struct file *file = iocb->ki_filp;
struct tap_queue *q = file->private_data;
ssize_t len = iov_iter_count(to), ret;
int noblock = 0;

if ((file->f_flags & O_NONBLOCK) || (iocb->ki_flags & IOCB_NOWAIT))
noblock = 1;

ret = tap_do_read(q, to, file->f_flags & O_NONBLOCK, NULL);
ret = tap_do_read(q, to, noblock, NULL);
ret = min_t(ssize_t, ret, len);
if (ret > 0)
iocb->ki_pos = ret;
Expand Down

0 comments on commit f758bfe

Please sign in to comment.