Re: Update of file offset on write() etc. is non-atomic with I/O

From: Al Viro
Date: Mon Mar 03 2014 - 19:23:53 EST


On Mon, Mar 03, 2014 at 03:59:36PM -0800, Linus Torvalds wrote:

> I doubt it's worth caring about. Even when passing things in memory,
> the end result isn't that much worse than the fget_light() model that
> passes just one of the two fields in memory.

I'm not sure if that's the right approach, TBH. I wonder if something
like
static inline struct fd fdget(int fd)
{
unsigned long v = __fdget(fd);
return (struct fd){(struct file *)(v & ~1), v & 1};
}
would not be a better starting point, with __fdget(fd) being
{
struct files_struct *files = current->files;
struct file *file;
if (atomic_read(&files->count) == 1) {
file = __fcheck_files(files, fd);
if (file && (file->f_mode & FMODE_PATH))
return 0;
return (unsigned long)file;
} else {
file = __fget(fd, FMODE_PATH);
return file ? 1 | (unsigned long)file : 0;
}
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/