mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
secret: Introduce virSecretObjDelete{Config|Data}
Move and rename secretDeleteSaved from secret_driver into virsecretobj and split it up into two parts since there is error path code that looks to just delete the secret data file
This commit is contained in:
parent
85ec94f870
commit
d467ac07ce
@ -648,6 +648,29 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets,
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virSecretObjDeleteConfig(virSecretObjPtr secret)
|
||||
{
|
||||
if (!secret->def->ephemeral &&
|
||||
unlink(secret->configFile) < 0 && errno != ENOENT) {
|
||||
virReportSystemError(errno, _("cannot unlink '%s'"),
|
||||
secret->configFile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virSecretObjDeleteData(virSecretObjPtr secret)
|
||||
{
|
||||
/* The configFile will already be removed, so secret won't be
|
||||
* loaded again if this fails */
|
||||
(void)unlink(secret->base64File);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virSecretLoadValidateUUID(virSecretDefPtr def,
|
||||
const char *file)
|
||||
|
@ -93,6 +93,10 @@ int virSecretObjListGetUUIDs(virSecretObjListPtr secrets,
|
||||
virSecretObjListACLFilter filter,
|
||||
virConnectPtr conn);
|
||||
|
||||
int virSecretObjDeleteConfig(virSecretObjPtr secret);
|
||||
|
||||
void virSecretObjDeleteData(virSecretObjPtr secret);
|
||||
|
||||
int virSecretLoadAllConfigs(virSecretObjListPtr secrets,
|
||||
const char *configDir);
|
||||
#endif /* __VIRSECRETOBJ_H__ */
|
||||
|
@ -896,6 +896,8 @@ virDomainObjListRename;
|
||||
|
||||
# conf/virsecretobj.h
|
||||
virSecretLoadAllConfigs;
|
||||
virSecretObjDeleteConfig;
|
||||
virSecretObjDeleteData;
|
||||
virSecretObjEndAPI;
|
||||
virSecretObjListAdd;
|
||||
virSecretObjListExport;
|
||||
|
@ -176,19 +176,6 @@ secretSaveValue(const virSecretObj *secret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
secretDeleteSaved(const virSecretObj *secret)
|
||||
{
|
||||
if (unlink(secret->configFile) < 0 && errno != ENOENT)
|
||||
return -1;
|
||||
|
||||
/* When the XML is missing, the rest may waste disk space, but the secret
|
||||
won't be loaded again, so we have succeeded already. */
|
||||
(void)unlink(secret->base64File);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Driver functions */
|
||||
|
||||
static int
|
||||
@ -326,8 +313,10 @@ secretDefineXML(virConnectPtr conn,
|
||||
goto restore_backup;
|
||||
}
|
||||
} else if (backup && !backup->ephemeral) {
|
||||
if (secretDeleteSaved(secret) < 0)
|
||||
if (virSecretObjDeleteConfig(secret) < 0)
|
||||
goto restore_backup;
|
||||
|
||||
virSecretObjDeleteData(secret);
|
||||
}
|
||||
/* Saved successfully - drop old values */
|
||||
new_attrs = NULL;
|
||||
@ -490,10 +479,11 @@ secretUndefine(virSecretPtr obj)
|
||||
if (virSecretUndefineEnsureACL(obj->conn, secret->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!secret->def->ephemeral &&
|
||||
secretDeleteSaved(secret) < 0)
|
||||
if (virSecretObjDeleteConfig(secret) < 0)
|
||||
goto cleanup;
|
||||
|
||||
virSecretObjDeleteData(secret);
|
||||
|
||||
virSecretObjListRemove(driver->secrets, secret);
|
||||
|
||||
ret = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user