* f_owner.lock and file->pos updates
@ 2007-03-07 19:17 Michael K. Edwards
2007-03-08 0:48 ` Alan Cox
0 siblings, 1 reply; 4+ messages in thread
From: Michael K. Edwards @ 2007-03-07 19:17 UTC (permalink / raw)
To: Linux Kernel Mailing List
Suppose I want to create an atomic llseek+writev operation. Is this
more or less sufficient:
ssize_t ret = -EBADF;
file = fget_light(fd, &fput_needed);
if (file) {
if (unlikely(origin > 2)) {
ret = -EINVAL;
} else {
write_lock_irq(&file->f_owner.lock);
pos = vfs_llseek(file, ((loff_t) offset_high <<
32) | offset_low, origin);
ret = (ssize_t)pos;
if (likely(ret >= 0)) {
ret = vfs_writev(file, vec, vlen, &pos);
file_pos_write(file, pos);
}
write_unlock_irq(&file->f_owner.lock);
}
fput_light(file, fput_needed);
}
Or is this the wrong sort of lock to be using to protect against
having file->pos altered by another thread executing through the same
code?
Cheers,
- Michael
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: f_owner.lock and file->pos updates
2007-03-07 19:17 f_owner.lock and file->pos updates Michael K. Edwards
@ 2007-03-08 0:48 ` Alan Cox
2007-03-08 1:50 ` Michael K. Edwards
0 siblings, 1 reply; 4+ messages in thread
From: Alan Cox @ 2007-03-08 0:48 UTC (permalink / raw)
To: Michael K. Edwards; +Cc: Linux Kernel Mailing List
On Wed, 7 Mar 2007 11:17:36 -0800
"Michael K. Edwards" <medwards.linux@gmail.com> wrote:
> Suppose I want to create an atomic llseek+writev operation. Is this
> more or less sufficient:
The right way IMHO would be to do the work that was done for pread/pwrite
and implement preadv/pwritev. The moment you want to do atomic things
with the file->f_pos instead of doing it with a local passed pos value it
gets ugly.. why do you need to do it with f_pos ?
Alan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: f_owner.lock and file->pos updates
2007-03-08 0:48 ` Alan Cox
@ 2007-03-08 1:50 ` Michael K. Edwards
2007-03-08 2:12 ` Michael K. Edwards
0 siblings, 1 reply; 4+ messages in thread
From: Michael K. Edwards @ 2007-03-08 1:50 UTC (permalink / raw)
To: Alan Cox; +Cc: Linux Kernel Mailing List
On 3/7/07, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> The right way IMHO would be to do the work that was done for pread/pwrite
> and implement preadv/pwritev. The moment you want to do atomic things
> with the file->f_pos instead of doing it with a local passed pos value it
> gets ugly.. why do you need to do it with f_pos ?
I didn't see any clean way to intersperse overwrites and appends to a
record-structured file without using vfs_llseek, which steps on f_pos.
Actually, we may already have a problem with append races in
sys_write/sys_writev. If it's possible for two threads to write() to
the same file in different threads (both intending to append), they
may wind up passing the same "pos" value into vfs_write(). Or does
fget_light/fput_light do some sort of locking that I'm not seeing?
Cheers,
- Michael
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: f_owner.lock and file->pos updates
2007-03-08 1:50 ` Michael K. Edwards
@ 2007-03-08 2:12 ` Michael K. Edwards
0 siblings, 0 replies; 4+ messages in thread
From: Michael K. Edwards @ 2007-03-08 2:12 UTC (permalink / raw)
To: Alan Cox; +Cc: Linux Kernel Mailing List
I wrote:
> I didn't see any clean way to intersperse overwrites and appends to a
> record-structured file without using vfs_llseek, which steps on f_pos.
The context, of course, is an attempt to fix -ENOPATCH with regard to
the netlink-based AIO submission scheme I outlined a couple of days
ago. :-)
Maybe f_pos should be advanced atomically by the number of bytes
expected to be read/written, before entering the vfs_(read|write)(|v)
call? And then if the read/write doesn't complete normally, f_pos
should be decremented by the number of bytes we failed to read/write?
Or do we have to make absolutely, positively sure that sampling f_pos
from another thread never returns any value outside (before)..(before
+ bytes read/written)? If so, the only way to cure the worst symptom
of the append race appears to be to hold a per-fd lock for the
duration of the sys_(read|write).
Cheers,
- Michael
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-03-08 2:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-07 19:17 f_owner.lock and file->pos updates Michael K. Edwards
2007-03-08 0:48 ` Alan Cox
2007-03-08 1:50 ` Michael K. Edwards
2007-03-08 2:12 ` Michael K. Edwards
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®