mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +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
|
static int
|
||||||
virSecretLoadValidateUUID(virSecretDefPtr def,
|
virSecretLoadValidateUUID(virSecretDefPtr def,
|
||||||
const char *file)
|
const char *file)
|
||||||
|
@ -93,6 +93,10 @@ int virSecretObjListGetUUIDs(virSecretObjListPtr secrets,
|
|||||||
virSecretObjListACLFilter filter,
|
virSecretObjListACLFilter filter,
|
||||||
virConnectPtr conn);
|
virConnectPtr conn);
|
||||||
|
|
||||||
|
int virSecretObjDeleteConfig(virSecretObjPtr secret);
|
||||||
|
|
||||||
|
void virSecretObjDeleteData(virSecretObjPtr secret);
|
||||||
|
|
||||||
int virSecretLoadAllConfigs(virSecretObjListPtr secrets,
|
int virSecretLoadAllConfigs(virSecretObjListPtr secrets,
|
||||||
const char *configDir);
|
const char *configDir);
|
||||||
#endif /* __VIRSECRETOBJ_H__ */
|
#endif /* __VIRSECRETOBJ_H__ */
|
||||||
|
@ -896,6 +896,8 @@ virDomainObjListRename;
|
|||||||
|
|
||||||
# conf/virsecretobj.h
|
# conf/virsecretobj.h
|
||||||
virSecretLoadAllConfigs;
|
virSecretLoadAllConfigs;
|
||||||
|
virSecretObjDeleteConfig;
|
||||||
|
virSecretObjDeleteData;
|
||||||
virSecretObjEndAPI;
|
virSecretObjEndAPI;
|
||||||
virSecretObjListAdd;
|
virSecretObjListAdd;
|
||||||
virSecretObjListExport;
|
virSecretObjListExport;
|
||||||
|
@ -176,19 +176,6 @@ secretSaveValue(const virSecretObj *secret)
|
|||||||
return ret;
|
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 */
|
/* Driver functions */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -326,8 +313,10 @@ secretDefineXML(virConnectPtr conn,
|
|||||||
goto restore_backup;
|
goto restore_backup;
|
||||||
}
|
}
|
||||||
} else if (backup && !backup->ephemeral) {
|
} else if (backup && !backup->ephemeral) {
|
||||||
if (secretDeleteSaved(secret) < 0)
|
if (virSecretObjDeleteConfig(secret) < 0)
|
||||||
goto restore_backup;
|
goto restore_backup;
|
||||||
|
|
||||||
|
virSecretObjDeleteData(secret);
|
||||||
}
|
}
|
||||||
/* Saved successfully - drop old values */
|
/* Saved successfully - drop old values */
|
||||||
new_attrs = NULL;
|
new_attrs = NULL;
|
||||||
@ -490,10 +479,11 @@ secretUndefine(virSecretPtr obj)
|
|||||||
if (virSecretUndefineEnsureACL(obj->conn, secret->def) < 0)
|
if (virSecretUndefineEnsureACL(obj->conn, secret->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!secret->def->ephemeral &&
|
if (virSecretObjDeleteConfig(secret) < 0)
|
||||||
secretDeleteSaved(secret) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
virSecretObjDeleteData(secret);
|
||||||
|
|
||||||
virSecretObjListRemove(driver->secrets, secret);
|
virSecretObjListRemove(driver->secrets, secret);
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user