storagePoolRefreshFailCleanup: Clear volumes on failed refresh

If pool refresh failed, then the internal table of volumes is
probably left in inconsistent or incomplete state anyways. Clear
it out then. This has an advantage that we can move the
virStoragePoolObjClearVols() from those very few backends that
do call it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Michal Privoznik 2019-02-28 18:07:02 +01:00
parent bd45cedbe5
commit ccc7ffb4ef
5 changed files with 6 additions and 16 deletions

View File

@ -402,8 +402,6 @@ virStorageBackendGlusterRefreshPool(virStoragePoolObjPtr pool)
if (dir) if (dir)
glfs_closedir(dir); glfs_closedir(dir);
virStorageBackendGlusterClose(state); virStorageBackendGlusterClose(state);
if (ret < 0)
virStoragePoolObjClearVols(pool);
return ret; return ret;
} }

View File

@ -760,14 +760,13 @@ virStorageBackendLogicalRefreshPool(virStoragePoolObjPtr pool)
2 2
}; };
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
int ret = -1;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
virWaitForDevices(); virWaitForDevices();
/* Get list of all logical volumes */ /* Get list of all logical volumes */
if (virStorageBackendLogicalFindLVs(pool, NULL) < 0) if (virStorageBackendLogicalFindLVs(pool, NULL) < 0)
goto cleanup; return -1;
cmd = virCommandNewArgList(VGS, cmd = virCommandNewArgList(VGS,
"--separator", ":", "--separator", ":",
@ -788,14 +787,9 @@ virStorageBackendLogicalRefreshPool(virStoragePoolObjPtr pool)
pool, pool,
"vgs", "vgs",
NULL) < 0) NULL) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
if (ret < 0)
virStoragePoolObjClearVols(pool);
return ret;
} }
/* /*

View File

@ -648,10 +648,8 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr pool)
goto cleanup; goto cleanup;
} }
if (virStoragePoolObjAddVol(pool, vol) < 0) { if (virStoragePoolObjAddVol(pool, vol) < 0)
virStoragePoolObjClearVols(pool);
goto cleanup; goto cleanup;
}
vol = NULL; vol = NULL;
} }

View File

@ -82,6 +82,8 @@ storagePoolRefreshFailCleanup(virStorageBackendPtr backend,
{ {
virErrorPtr orig_err = virSaveLastError(); virErrorPtr orig_err = virSaveLastError();
virStoragePoolObjClearVols(obj);
if (stateFile) if (stateFile)
unlink(stateFile); unlink(stateFile);
if (backend->stopPool) if (backend->stopPool)

View File

@ -3620,8 +3620,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_DIR_CLOSE(dir); VIR_DIR_CLOSE(dir);
if (ret < 0)
virStoragePoolObjClearVols(pool);
return ret; return ret;
} }