* @configDir: directory to place secret config files
* @oldDef: Former secret def (e.g. a reload path perhaps)
*
- * Add the new @newdef to the secret obj table hash
+ * Add the new @newdef to the secret obj table hash. Upon
+ * successful the virSecret object is the owner of @newdef and
+ * callers should use virSecretObjGetDef() if they need to access
+ * the definition as @newdef is set to NULL.
*
* Returns: locked and ref'd secret or NULL if failure to add
*/
virSecretObj *
virSecretObjListAdd(virSecretObjList *secrets,
- virSecretDef *newdef,
+ virSecretDef **newdef,
const char *configDir,
virSecretDef **oldDef)
{
if (oldDef)
*oldDef = NULL;
- virUUIDFormat(newdef->uuid, uuidstr);
+ virUUIDFormat((*newdef)->uuid, uuidstr);
/* Is there a secret already matching this UUID */
if ((obj = virSecretObjListFindByUUIDLocked(secrets, uuidstr))) {
virObjectLock(obj);
objdef = obj->def;
- if (STRNEQ_NULLABLE(objdef->usage_id, newdef->usage_id)) {
+ if (STRNEQ_NULLABLE(objdef->usage_id, (*newdef)->usage_id)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("a secret with UUID %s is already defined for "
"use with %s"),
goto cleanup;
}
- if (objdef->isprivate && !newdef->isprivate) {
+ if (objdef->isprivate && !(*newdef)->isprivate) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot change private flag on existing secret"));
goto cleanup;
*oldDef = objdef;
else
virSecretDefFree(objdef);
- obj->def = newdef;
+ obj->def = g_steal_pointer(newdef);
} else {
/* No existing secret with same UUID,
* try look for matching usage instead */
if ((obj = virSecretObjListFindByUsageLocked(secrets,
- newdef->usage_type,
- newdef->usage_id))) {
+ (*newdef)->usage_type,
+ (*newdef)->usage_id))) {
virObjectLock(obj);
objdef = obj->def;
virUUIDFormat(objdef->uuid, uuidstr);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("a secret with UUID %s already defined for "
"use with %s"),
- uuidstr, newdef->usage_id);
+ uuidstr, (*newdef)->usage_id);
goto cleanup;
}
if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0)
goto cleanup;
- obj->def = newdef;
+ obj->def = g_steal_pointer(newdef);
virObjectRef(obj);
}
if (virSecretLoadValidateUUID(def, file) < 0)
goto cleanup;
- if (!(obj = virSecretObjListAdd(secrets, def, configDir, NULL)))
+ if (!(obj = virSecretObjListAdd(secrets, &def, configDir, NULL)))
goto cleanup;
- def = NULL;
if (virSecretLoadValue(obj) < 0) {
virSecretObjListRemove(secrets, obj);
if (virSecretDefineXMLEnsureACL(conn, def) < 0)
goto cleanup;
- if (!(obj = virSecretObjListAdd(driver->secrets, def,
+ if (!(obj = virSecretObjListAdd(driver->secrets, &def,
driver->configDir, &backup)))
goto cleanup;
- objDef = g_steal_pointer(&def);
+ objDef = virSecretObjGetDef(obj);
if (!objDef->isephemeral) {
if (backup && backup->isephemeral) {