[libvirt] [PATCH] storage: Do not override the exact error of createRawFile

virStorageBackendCreateRaw: createRawFile already reported the exact error. Before the fix: error: Failed to create vol vol-create.img error: cannot create path '/var/lib/libvirt/images/vol-create.img': Unknown error 18446744073709551597 After the fix: error: Failed to create vol vol-create.img error: cannot fill file '/var/lib/libvirt/images/vol-create.img': No space left on device --- src/storage/storage_backend.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a6e66e1..cee2010 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -299,6 +299,7 @@ createRawFile(int fd, virStorageVolDefPtr vol, { int ret = 0; unsigned long long remain; + off_t cur_pos = 0; /* Seek to the final size, so the capacity is available upfront * for progress reporting */ @@ -310,7 +311,12 @@ createRawFile(int fd, virStorageVolDefPtr vol, goto cleanup; } + cur_pos = lseek(fd, 0, SEEK_CUR); + + VIR_WARN("cur_pos = %jd", cur_pos); + remain = vol->allocation; + VIR_WARN("remain = %llu", remain); if (inputvol) { ret = virStorageBackendCopyToFD(vol, inputvol, fd, &remain, 1); @@ -399,12 +405,9 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, goto cleanup; } - if ((ret = createRawFile(fd, vol, inputvol)) < 0) { - virReportSystemError(-fd, - _("cannot create path '%s'"), - vol->target.path); + if ((ret = createRawFile(fd, vol, inputvol)) < 0) + /* createRawFile already reported the exact error. */ ret = -1; - } cleanup: VIR_FORCE_CLOSE(fd); -- 1.7.4

于 2011年07月04日 15:13, Osier Yang 写道:
virStorageBackendCreateRaw: createRawFile already reported the exact error.
Before the fix:
error: Failed to create vol vol-create.img error: cannot create path '/var/lib/libvirt/images/vol-create.img': Unknown error 18446744073709551597
After the fix:
error: Failed to create vol vol-create.img error: cannot fill file '/var/lib/libvirt/images/vol-create.img': No space left on device --- src/storage/storage_backend.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a6e66e1..cee2010 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -299,6 +299,7 @@ createRawFile(int fd, virStorageVolDefPtr vol, { int ret = 0; unsigned long long remain; + off_t cur_pos = 0;
/* Seek to the final size, so the capacity is available upfront * for progress reporting */ @@ -310,7 +311,12 @@ createRawFile(int fd, virStorageVolDefPtr vol, goto cleanup; }
+ cur_pos = lseek(fd, 0, SEEK_CUR); + + VIR_WARN("cur_pos = %jd", cur_pos); + remain = vol->allocation; + VIR_WARN("remain = %llu", remain);
Urgh, please skip this patch, a patch removes these debugging lines is following.

virStorageBackendCreateRaw: createRawFile already reported the exact error. Before the fix: error: Failed to create vol vol-create.img error: cannot create path '/var/lib/libvirt/images/vol-create.img': Unknown error 18446744073709551597 After the fix: error: Failed to create vol vol-create.img error: cannot fill file '/var/lib/libvirt/images/vol-create.img': No space left on device --- src/storage/storage_backend.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a6e66e1..708d7b2 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -399,12 +399,9 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, goto cleanup; } - if ((ret = createRawFile(fd, vol, inputvol)) < 0) { - virReportSystemError(-fd, - _("cannot create path '%s'"), - vol->target.path); + if ((ret = createRawFile(fd, vol, inputvol)) < 0) + /* createRawFile already reported the exact error. */ ret = -1; - } cleanup: VIR_FORCE_CLOSE(fd); -- 1.7.4

2011/7/4 Osier Yang <jyang@redhat.com>:
virStorageBackendCreateRaw: createRawFile already reported the exact error.
Before the fix:
error: Failed to create vol vol-create.img error: cannot create path '/var/lib/libvirt/images/vol-create.img': Unknown error 18446744073709551597
After the fix:
error: Failed to create vol vol-create.img error: cannot fill file '/var/lib/libvirt/images/vol-create.img': No space left on device --- src/storage/storage_backend.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a6e66e1..708d7b2 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -399,12 +399,9 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, goto cleanup; }
- if ((ret = createRawFile(fd, vol, inputvol)) < 0) { - virReportSystemError(-fd, - _("cannot create path '%s'"), - vol->target.path); + if ((ret = createRawFile(fd, vol, inputvol)) < 0) + /* createRawFile already reported the exact error. */ ret = -1; - }
You're also fixing the usage of the wrong value for the errno parameter of virReportSystemError by removing that call. It should have been -ret instead of -fd, that's why you see this large number in the overwriting error that is the result of an overflow. ACK. -- Matthias Bolte http://photron.blogspot.com

于 2011年07月04日 16:08, Matthias Bolte 写道:
2011/7/4 Osier Yang<jyang@redhat.com>:
virStorageBackendCreateRaw: createRawFile already reported the exact error.
Before the fix:
error: Failed to create vol vol-create.img error: cannot create path '/var/lib/libvirt/images/vol-create.img': Unknown error 18446744073709551597
After the fix:
error: Failed to create vol vol-create.img error: cannot fill file '/var/lib/libvirt/images/vol-create.img': No space left on device --- src/storage/storage_backend.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a6e66e1..708d7b2 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -399,12 +399,9 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, goto cleanup; }
- if ((ret = createRawFile(fd, vol, inputvol))< 0) { - virReportSystemError(-fd, - _("cannot create path '%s'"), - vol->target.path); + if ((ret = createRawFile(fd, vol, inputvol))< 0) + /* createRawFile already reported the exact error. */ ret = -1; - }
You're also fixing the usage of the wrong value for the errno parameter of virReportSystemError by removing that call. It should have been -ret instead of -fd, that's why you see this large number in the overwriting error that is the result of an overflow.
ACK.
Thanks, applied Osier
participants (2)
-
Matthias Bolte
-
Osier Yang