Skip to contentSkip to conversation

aio_read const struct iovec *

DISCUSSION Sergey Senozhatsky 2 participants 2 messages Sep 9, 2009 VFS

lore
Share & tools
lore
#0 lore raw

Hello,
I have the following question:

struct file_operations {
	ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
	ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
At the same time:
	ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
	ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);

'const struct iovec *' both for aio_write and aio_read. And "char __user *" and "const char __user *" for read/write.

For example,
pipe_read(struct kiocb *iocb, const struct iovec *_iov,
unsigned long nr_segs, loff_t ppos)

{
	struct iovec *iov = (struct iovec *)_iov; 

Could we avoid 'struct iovec *iov = (struct iovec *)_iov;' by changing aio_read 'const struct iovec *'
to 'struct iovec *'?

Sergey

#1 lore raw
Quoted 12 lines · Sergey Senozhatsky

Hello,
I have the following question:

struct file_operations {
	ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
	ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
At the same time:
	ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
	ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);

'const struct iovec *' both for aio_write and aio_read. And "char __user *" and "const char __user *" for read/write.

Quoted 8 lines

For example,
pipe_read(struct kiocb *iocb, const struct iovec *_iov,
unsigned long nr_segs, loff_t ppos)

{
	struct iovec *iov = (struct iovec *)_iov; 

Could we avoid 'struct iovec *iov = (struct iovec *)_iov;' by changing aio_read 'const struct iovec *'
to 'struct iovec *'?

If you try it, it'll be educational for you to see where it fails ;-)

But if you're too impatient, aio_rw_vect_retry() will be (one of) the problems:

ssize_t (*rw_op)(struct kiocb *, const struct iovec *,
unsigned long, loff_t);
[...]

                rw_op = file->f_op->aio_read;
[...]
                rw_op = file->f_op->aio_write;

so aio_read and aio_write need to have the same prototype.

Now, I'm not sure why it's more beneficial to have a lying const in the aio_read prototype than simply omitting the const from the aio_write prototype ... but I'm sure if you try that, you'll find a good reason too.

Signature · 4 lines
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."