Provide some consistency over error message variable name and usage
when saving error messages across possible other errors or possibility
of resetting of the last error.
Instead of virSaveLastError paired up with virSetError and virFreeError,
we should use the newer virErrorPreserveLast and virRestoreError.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/storage/storage_backend_disk.c | 5 ++---
src/storage/storage_backend_logical.c | 5 ++---
src/storage/storage_driver.c | 8 +++-----
3 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 5bf704bcc8..d2f7b94224 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -918,10 +918,9 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
/* Best effort to remove the partition. Ignore any errors
* since we could be calling this with vol->target.path == NULL
*/
- save_err = virSaveLastError();
+ virErrorPreserveLast(&save_err);
ignore_value(virStorageBackendDiskDeleteVol(pool, vol, 0));
- virSetError(save_err);
- virFreeError(save_err);
+ virErrorRestore(&save_err);
return -1;
}
diff --git a/src/storage/storage_backend_logical.c
b/src/storage/storage_backend_logical.c
index 6e468b3579..bfedb06a91 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -969,10 +969,9 @@ virStorageBackendLogicalCreateVol(virStoragePoolObjPtr pool,
return 0;
error:
- err = virSaveLastError();
+ virErrorPreserveLast(&err);
virStorageBackendLogicalDeleteVol(pool, vol, 0);
- virSetError(err);
- virFreeError(err);
+ virErrorRestore(&err);
return -1;
}
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 6516b0943d..e8551ba57e 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -81,18 +81,16 @@ storagePoolRefreshFailCleanup(virStorageBackendPtr backend,
virStoragePoolObjPtr obj,
const char *stateFile)
{
- virErrorPtr orig_err = virSaveLastError();
+ virErrorPtr orig_err;
+ virErrorPreserveLast(&orig_err);
virStoragePoolObjClearVols(obj);
if (stateFile)
unlink(stateFile);
if (backend->stopPool)
backend->stopPool(obj);
- if (orig_err) {
- virSetError(orig_err);
- virFreeError(orig_err);
- }
+ virErrorRestore(&orig_err);
}
--
2.20.1