block/raw-posix: Fixes for preallocation
cover block/raw-posix: Fixes for preallocation
This series brings some (minor) fixes for full preallocation in raw-posix; thanks to László for finding these bugs.
Since the fixes are not too grave, I would be fine with not getting them into 2.2. But because they are rather simple and they are bug fixes after all, I sent this series with the "for-2.2" infix.
Max Reitz (3):
block/raw-posix: Fix preallocating write() loop block/raw-posix: Only sync after successful preallocation block/raw-posix: Catch fsync() errors
block/raw-posix.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.3
PATCH 1/3 block/raw-posix: Fix preallocating write() loop
write() may write less bytes than requested; in this case, the number of bytes written is returned. This is the byte count we should be subtracting from the number of bytes still to be written, and not the byte count we requested to write.
---
An interesting anecdote: My German man page for write(2) says the following about its return value:
Quoted 1 line
Bei Erfolg wird Null zurückgegeben.
Which translates to:
Quoted 1 line
On success, zero is returned.
Whereas write(2) for LANG=C says the following (which is correct):
Quoted 2 lines
On success, the number of bytes written is returned (zero indicates nothing was written).
I think I know why I somehow prefer the English versions...
--- block/raw-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/raw-posix.c +1 -1
@@ -1457,7 +1457,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) "Could not write to the new file");break ; } - left -= num; + left -= result; }fsync (fd);g_free (buf);
Signature · 1 line
1.9.3
PATCH 2/3 block/raw-posix: Only sync after successful preallocation
In reply to Max ReitzThe loop which filled the file with zeroes may have been left early due to an error. In that case, the fsync() should be skipped.
--- block/raw-posix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/raw-posix.c +3 -1
@@ -1459,7 +1459,9 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) } left -= result; } -fsync (fd); +if (result >=0 ) { +fsync (fd); + }g_free (buf);break ; }
Signature · 1 line
1.9.3
PATCH 3/3 block/raw-posix: Catch fsync() errors
In reply to Max Reitzfsync() may fail, and that case should be handled.
--- block/raw-posix.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
block/raw-posix.c +6 -1
@@ -1460,7 +1460,12 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) left -= result; }if (result >=0 ) { -fsync (fd); + result =fsync (fd); +if (result <0 ) { + result = -errno; +error_setg_errno (errp, -result, +"Could not flush new file to disk" ); + } }g_free (buf);break ;
Signature · 1 line
1.9.3
Kevin Wolf
AppliedAm 18.11.2014 um 11:23 hat Max Reitz geschrieben:
Quoted 6 lines
This series brings some (minor) fixes for full preallocation in raw-posix; thanks to László for finding these bugs.
Since the fixes are not too grave, I would be fine with not getting them into 2.2. But because they are rather simple and they are bug fixes after all, I sent this series with the "for-2.2" infix.
Thanks, applied to the block branch.
Kevin