qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation
@ 2014-11-18 10:23 Max Reitz
  2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 1/3] block/raw-posix: Fix preallocating write() loop Max Reitz
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Max Reitz @ 2014-11-18 10:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, László Érsek, Stefan Hajnoczi,
	Max Reitz

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(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH for-2.2 1/3] block/raw-posix: Fix preallocating write() loop
  2014-11-18 10:23 [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation Max Reitz
@ 2014-11-18 10:23 ` Max Reitz
  2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 2/3] block/raw-posix: Only sync after successful preallocation Max Reitz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Max Reitz @ 2014-11-18 10:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, László Érsek, Stefan Hajnoczi,
	Max Reitz

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.

Reported-by: László Érsek <lersek@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
An interesting anecdote: My German man page for write(2) says the
following about its return value:

> Bei Erfolg wird Null zurückgegeben.

Which translates to:

> On success, zero is returned.

Whereas write(2) for LANG=C says the following (which is correct):

> 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(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index e100ae2..4e6552f 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -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);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH for-2.2 2/3] block/raw-posix: Only sync after successful preallocation
  2014-11-18 10:23 [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation Max Reitz
  2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 1/3] block/raw-posix: Fix preallocating write() loop Max Reitz
@ 2014-11-18 10:23 ` Max Reitz
  2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 3/3] block/raw-posix: Catch fsync() errors Max Reitz
  2014-11-18 11:11 ` [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation Kevin Wolf
  3 siblings, 0 replies; 5+ messages in thread
From: Max Reitz @ 2014-11-18 10:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, László Érsek, Stefan Hajnoczi,
	Max Reitz

The loop which filled the file with zeroes may have been left early due
to an error. In that case, the fsync() should be skipped.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/raw-posix.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 4e6552f..f67fb11 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -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;
     }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH for-2.2 3/3] block/raw-posix: Catch fsync() errors
  2014-11-18 10:23 [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation Max Reitz
  2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 1/3] block/raw-posix: Fix preallocating write() loop Max Reitz
  2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 2/3] block/raw-posix: Only sync after successful preallocation Max Reitz
@ 2014-11-18 10:23 ` Max Reitz
  2014-11-18 11:11 ` [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation Kevin Wolf
  3 siblings, 0 replies; 5+ messages in thread
From: Max Reitz @ 2014-11-18 10:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, László Érsek, Stefan Hajnoczi,
	Max Reitz

fsync() may fail, and that case should be handled.

Reported-by: László Érsek <lersek@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/raw-posix.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index f67fb11..666cdec 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -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;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation
  2014-11-18 10:23 [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation Max Reitz
                   ` (2 preceding siblings ...)
  2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 3/3] block/raw-posix: Catch fsync() errors Max Reitz
@ 2014-11-18 11:11 ` Kevin Wolf
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2014-11-18 11:11 UTC (permalink / raw)
  To: Max Reitz; +Cc: László Érsek, qemu-devel, Stefan Hajnoczi

Am 18.11.2014 um 11:23 hat Max Reitz geschrieben:
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-11-18 11:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-18 10:23 [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation Max Reitz
2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 1/3] block/raw-posix: Fix preallocating write() loop Max Reitz
2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 2/3] block/raw-posix: Only sync after successful preallocation Max Reitz
2014-11-18 10:23 ` [Qemu-devel] [PATCH for-2.2 3/3] block/raw-posix: Catch fsync() errors Max Reitz
2014-11-18 11:11 ` [Qemu-devel] [PATCH for-2.2 0/3] block/raw-posix: Fixes for preallocation Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).