From 7c36e124e019facba42c6be532dd3ddb4e2dadcc Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 7 Dec 2010 01:14:01 +0100 Subject: scullp: Change work_struct to delayed_work and change scullc_aio_[read | write] handlers --- scullp/main.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'scullp/main.c') diff --git a/scullp/main.c b/scullp/main.c index f2564ad..0aba67d 100644 --- a/scullp/main.c +++ b/scullp/main.c @@ -399,31 +399,40 @@ loff_t scullp_llseek (struct file *filp, loff_t off, int whence) struct async_work { struct kiocb *iocb; int result; - struct work_struct work; + struct delayed_work work; }; /* * "Complete" an asynchronous operation. */ -static void scullp_do_deferred_op(void *p) +static void scullp_do_deferred_op(struct work_struct *work) { - struct async_work *stuff = (struct async_work *) p; + struct async_work *stuff = container_of(work, struct async_work, work.work); aio_complete(stuff->iocb, stuff->result, 0); kfree(stuff); } -static int scullp_defer_op(int write, struct kiocb *iocb, char __user *buf, - size_t count, loff_t pos) +static int scullp_defer_op(int write, struct kiocb *iocb, const struct iovec *iovec, + unsigned long nr_segs, loff_t pos) { struct async_work *stuff; - int result; + int result = 0; + size_t len = 0; + unsigned long seg = 0; /* Copy now while we can access the buffer */ - if (write) - result = scullp_write(iocb->ki_filp, buf, count, &pos); - else - result = scullp_read(iocb->ki_filp, buf, count, &pos); + for (seg = 0; seg < nr_segs; seg++) { + if (write) + len = scullp_write(iocb->ki_filp, iovec[seg].iov_base, iovec[seg].iov_len, &pos); + else + len = scullp_read(iocb->ki_filp, iovec[seg].iov_base, iovec[seg].iov_len, &pos); + + if (len < 0) + return len; + + result += len; + } /* If this is a synchronous IOCB, we return our status now. */ if (is_sync_kiocb(iocb)) @@ -435,22 +444,22 @@ static int scullp_defer_op(int write, struct kiocb *iocb, char __user *buf, return result; /* No memory, just complete now */ stuff->iocb = iocb; stuff->result = result; - INIT_WORK(&stuff->work, scullp_do_deferred_op, stuff); + INIT_DELAYED_WORK(&stuff->work, scullp_do_deferred_op); schedule_delayed_work(&stuff->work, HZ/100); return -EIOCBQUEUED; } -static ssize_t scullp_aio_read(struct kiocb *iocb, char __user *buf, size_t count, - loff_t pos) +static ssize_t scullp_aio_read(struct kiocb *iocb, const struct iovec *iovec, + unsigned long nr_segs, loff_t pos) { - return scullp_defer_op(0, iocb, buf, count, pos); + return scullp_defer_op(0, iocb, iovec, nr_segs, pos); } -static ssize_t scullp_aio_write(struct kiocb *iocb, const char __user *buf, - size_t count, loff_t pos) +static ssize_t scullp_aio_write(struct kiocb *iocb, const struct iovec *iovec, + unsigned long nr_segs, loff_t pos) { - return scullp_defer_op(1, iocb, (char __user *) buf, count, pos); + return scullp_defer_op(1, iocb, iovec, nr_segs, pos); } -- cgit v1.2.1-18-gbd029