[PATCH] generic_file_buffered_write(): handle zero-length iovec segments

The recent generic_file_write() deadlock fix caused
generic_file_buffered_write() to loop inifinitely when presented with a
zero-length iovec segment.  Fix.

Note that this fix deliberately avoids calling ->prepare_write(),
->commit_write() etc with a zero-length write.  This is because I don't trust
all filesystems to get that right.

This is a cautious approach, for 2.6.17.x.  For 2.6.18 we should just go ahead
and call ->prepare_write() and ->commit_write() with the zero length and fix
any broken filesystems.  So I'll make that change once this code is stabilised
and backported into 2.6.17.x.

The reason for preferring to call ->prepare_write() and ->commit_write() with
the zero-length segment: a zero-length segment _should_ be sufficiently
uncommon that this is the correct way of handling it.  We don't want to
optimise for poorly-written userspace at the expense of well-written
userspace.

Cc: "Vladimir V. Saveliev" <[email protected]>
Cc: Neil Brown <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Chris Wright <[email protected]>
Cc: Greg KH <[email protected]>
Cc: <[email protected]>
Cc: walt <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
Andrew Morton 2006-06-29 02:24:26 -07:00 • committed by Linus Torvalds
commit 81b0c87133
2 changed files with 10 additions and 3 deletions

View file

@ -2125,6 +2125,12 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov,
break;
}
if (unlikely(bytes == 0)) {
status = 0;
copied = 0;
goto zero_length_segment;
}
status = a_ops->prepare_write(file, page, offset, offset+bytes);
if (unlikely(status)) {
loff_t isize = i_size_read(inode);
@ -2154,7 +2160,8 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov,
page_cache_release(page);
continue;
}
if (likely(copied > 0)) {
zero_length_segment:
if (likely(copied >= 0)) {
if (!status)
status = copied;