Remove virConnectPtr from secret XML APIs

The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in secret_conf.{h,c} and update all callers to
match
This commit is contained in:
Daniel P. Berrange 2010-02-10 12:33:34 +00:00
parent a70e599d80
commit c4dcf043ca
4 changed files with 81 additions and 86 deletions

View File

@ -60,7 +60,7 @@ virSecretDefFree(virSecretDefPtr def)
} }
static int static int
virSecretDefParseUsage(virConnectPtr conn, xmlXPathContextPtr ctxt, virSecretDefParseUsage(xmlXPathContextPtr ctxt,
virSecretDefPtr def) virSecretDefPtr def)
{ {
char *type_str; char *type_str;
@ -68,13 +68,13 @@ virSecretDefParseUsage(virConnectPtr conn, xmlXPathContextPtr ctxt,
type_str = virXPathString("string(./usage/@type)", ctxt); type_str = virXPathString("string(./usage/@type)", ctxt);
if (type_str == NULL) { if (type_str == NULL) {
virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", virSecretReportError(VIR_ERR_XML_ERROR, "%s",
_("unknown secret usage type")); _("unknown secret usage type"));
return -1; return -1;
} }
type = virSecretUsageTypeTypeFromString(type_str); type = virSecretUsageTypeTypeFromString(type_str);
if (type < 0) { if (type < 0) {
virSecretReportError(conn, VIR_ERR_XML_ERROR, virSecretReportError(VIR_ERR_XML_ERROR,
_("unknown secret usage type %s"), type_str); _("unknown secret usage type %s"), type_str);
VIR_FREE(type_str); VIR_FREE(type_str);
return -1; return -1;
@ -88,14 +88,14 @@ virSecretDefParseUsage(virConnectPtr conn, xmlXPathContextPtr ctxt,
case VIR_SECRET_USAGE_TYPE_VOLUME: case VIR_SECRET_USAGE_TYPE_VOLUME:
def->usage.volume = virXPathString("string(./usage/volume)", ctxt); def->usage.volume = virXPathString("string(./usage/volume)", ctxt);
if (!def->usage.volume) { if (!def->usage.volume) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("volume usage specified, but volume path is missing")); _("volume usage specified, but volume path is missing"));
return -1; return -1;
} }
break; break;
default: default:
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected secret usage type %d"), _("unexpected secret usage type %d"),
def->usage_type); def->usage_type);
return -1; return -1;
@ -104,7 +104,7 @@ virSecretDefParseUsage(virConnectPtr conn, xmlXPathContextPtr ctxt,
} }
static virSecretDefPtr static virSecretDefPtr
secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root) secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
{ {
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
virSecretDefPtr def = NULL, ret = NULL; virSecretDefPtr def = NULL, ret = NULL;
@ -112,7 +112,7 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root)
char *uuidstr = NULL; char *uuidstr = NULL;
if (!xmlStrEqual(root->name, BAD_CAST "secret")) { if (!xmlStrEqual(root->name, BAD_CAST "secret")) {
virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", virSecretReportError(VIR_ERR_XML_ERROR, "%s",
_("incorrect root element")); _("incorrect root element"));
goto cleanup; goto cleanup;
} }
@ -136,7 +136,7 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root)
else if (STREQ(prop, "no")) else if (STREQ(prop, "no"))
def->ephemeral = 0; def->ephemeral = 0;
else { else {
virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", virSecretReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid value of 'ephemeral'")); _("invalid value of 'ephemeral'"));
goto cleanup; goto cleanup;
} }
@ -150,7 +150,7 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root)
else if (STREQ(prop, "no")) else if (STREQ(prop, "no"))
def->private = 0; def->private = 0;
else { else {
virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", virSecretReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid value of 'private'")); _("invalid value of 'private'"));
goto cleanup; goto cleanup;
} }
@ -160,13 +160,13 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root)
uuidstr = virXPathString("string(./uuid)", ctxt); uuidstr = virXPathString("string(./uuid)", ctxt);
if (!uuidstr) { if (!uuidstr) {
if (virUUIDGenerate(def->uuid)) { if (virUUIDGenerate(def->uuid)) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate UUID")); "%s", _("Failed to generate UUID"));
goto cleanup; goto cleanup;
} }
} else { } else {
if (virUUIDParse(uuidstr, def->uuid) < 0) { if (virUUIDParse(uuidstr, def->uuid) < 0) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed uuid element")); "%s", _("malformed uuid element"));
goto cleanup; goto cleanup;
} }
@ -175,7 +175,7 @@ secretXMLParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root)
def->description = virXPathString("string(./description)", ctxt); def->description = virXPathString("string(./description)", ctxt);
if (virXPathNode("./usage", ctxt) != NULL if (virXPathNode("./usage", ctxt) != NULL
&& virSecretDefParseUsage(conn, ctxt, def) < 0) && virSecretDefParseUsage(ctxt, def) < 0)
goto cleanup; goto cleanup;
ret = def; ret = def;
def = NULL; def = NULL;
@ -194,19 +194,17 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if (ctxt) { if (ctxt) {
virConnectPtr conn = ctxt->_private;
if (virGetLastError() == NULL && if (virGetLastError() == NULL &&
ctxt->lastError.level == XML_ERR_FATAL && ctxt->lastError.level == XML_ERR_FATAL &&
ctxt->lastError.message != NULL) { ctxt->lastError.message != NULL) {
virSecretReportError(conn, VIR_ERR_XML_DETAIL, _("at line %d: %s"), virSecretReportError(VIR_ERR_XML_DETAIL, _("at line %d: %s"),
ctxt->lastError.line, ctxt->lastError.message); ctxt->lastError.line, ctxt->lastError.message);
} }
} }
} }
static virSecretDefPtr static virSecretDefPtr
virSecretDefParse(virConnectPtr conn, const char *xmlStr, const char *filename) virSecretDefParse(const char *xmlStr, const char *filename)
{ {
xmlParserCtxtPtr pctxt; xmlParserCtxtPtr pctxt;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
@ -217,7 +215,6 @@ virSecretDefParse(virConnectPtr conn, const char *xmlStr, const char *filename)
if (pctxt == NULL || pctxt->sax == NULL) if (pctxt == NULL || pctxt->sax == NULL)
goto cleanup; goto cleanup;
pctxt->sax->error = catchXMLError; pctxt->sax->error = catchXMLError;
pctxt->_private = conn;
if (filename != NULL) if (filename != NULL)
xml = xmlCtxtReadFile(pctxt, filename, NULL, xml = xmlCtxtReadFile(pctxt, filename, NULL,
@ -228,20 +225,20 @@ virSecretDefParse(virConnectPtr conn, const char *xmlStr, const char *filename)
XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOWARNING); XML_PARSE_NOWARNING);
if (xml == NULL) { if (xml == NULL) {
if (conn->err.code == VIR_ERR_NONE) if (virGetLastError() == NULL)
virSecretReportError(conn, VIR_ERR_XML_ERROR, "%s", virSecretReportError(VIR_ERR_XML_ERROR, "%s",
_("failed to parse xml document")); _("failed to parse xml document"));
goto cleanup; goto cleanup;
} }
root = xmlDocGetRootElement(xml); root = xmlDocGetRootElement(xml);
if (root == NULL) { if (root == NULL) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing root element")); _("missing root element"));
goto cleanup; goto cleanup;
} }
ret = secretXMLParseNode(conn, xml, root); ret = secretXMLParseNode(xml, root);
cleanup: cleanup:
xmlFreeDoc(xml); xmlFreeDoc(xml);
@ -250,26 +247,26 @@ virSecretDefParse(virConnectPtr conn, const char *xmlStr, const char *filename)
} }
virSecretDefPtr virSecretDefPtr
virSecretDefParseString(virConnectPtr conn, const char *xmlStr) virSecretDefParseString(const char *xmlStr)
{ {
return virSecretDefParse(conn, xmlStr, NULL); return virSecretDefParse(xmlStr, NULL);
} }
virSecretDefPtr virSecretDefPtr
virSecretDefParseFile(virConnectPtr conn, const char *filename) virSecretDefParseFile(const char *filename)
{ {
return virSecretDefParse(conn, NULL, filename); return virSecretDefParse(NULL, filename);
} }
static int static int
virSecretDefFormatUsage(virConnectPtr conn, virBufferPtr buf, virSecretDefFormatUsage(virBufferPtr buf,
const virSecretDefPtr def) const virSecretDefPtr def)
{ {
const char *type; const char *type;
type = virSecretUsageTypeTypeToString(def->usage_type); type = virSecretUsageTypeTypeToString(def->usage_type);
if (type == NULL) { if (type == NULL) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected secret usage type %d"), _("unexpected secret usage type %d"),
def->usage_type); def->usage_type);
return -1; return -1;
@ -286,7 +283,7 @@ virSecretDefFormatUsage(virConnectPtr conn, virBufferPtr buf,
break; break;
default: default:
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected secret usage type %d"), _("unexpected secret usage type %d"),
def->usage_type); def->usage_type);
return -1; return -1;
@ -297,7 +294,7 @@ virSecretDefFormatUsage(virConnectPtr conn, virBufferPtr buf,
} }
char * char *
virSecretDefFormat(virConnectPtr conn, const virSecretDefPtr def) virSecretDefFormat(const virSecretDefPtr def)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned char *uuid; unsigned char *uuid;
@ -314,7 +311,7 @@ virSecretDefFormat(virConnectPtr conn, const virSecretDefPtr def)
virBufferEscapeString(&buf, " <description>%s</description>\n", virBufferEscapeString(&buf, " <description>%s</description>\n",
def->description); def->description);
if (def->usage_type != VIR_SECRET_USAGE_TYPE_NONE && if (def->usage_type != VIR_SECRET_USAGE_TYPE_NONE &&
virSecretDefFormatUsage(conn, &buf, def) < 0) virSecretDefFormatUsage(&buf, def) < 0)
goto error; goto error;
virBufferAddLit(&buf, "</secret>\n"); virBufferAddLit(&buf, "</secret>\n");

View File

@ -26,8 +26,8 @@
#include "internal.h" #include "internal.h"
#include "util.h" #include "util.h"
#define virSecretReportError(conn, code, fmt...) \ #define virSecretReportError(code, fmt...) \
virReportErrorHelper(conn, VIR_FROM_SECRET, code, __FILE__, \ virReportErrorHelper(NULL, VIR_FROM_SECRET, code, __FILE__, \
__FUNCTION__, __LINE__, fmt) __FUNCTION__, __LINE__, fmt)
VIR_ENUM_DECL(virSecretUsageType) VIR_ENUM_DECL(virSecretUsageType)
@ -46,8 +46,8 @@ struct _virSecretDef {
}; };
void virSecretDefFree(virSecretDefPtr def); void virSecretDefFree(virSecretDefPtr def);
virSecretDefPtr virSecretDefParseString(virConnectPtr conn, const char *xml); virSecretDefPtr virSecretDefParseString(const char *xml);
virSecretDefPtr virSecretDefParseFile(virConnectPtr conn, const char *filename); virSecretDefPtr virSecretDefParseFile(const char *filename);
char *virSecretDefFormat(virConnectPtr conn, const virSecretDefPtr def); char *virSecretDefFormat(const virSecretDefPtr def);
#endif #endif

View File

@ -222,16 +222,14 @@ secretComputePath(virSecretDriverStatePtr driver,
} }
static char * static char *
secretXMLPath(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, secretXMLPath(virSecretDriverStatePtr driver,
virSecretDriverStatePtr driver,
const virSecretEntry *secret) const virSecretEntry *secret)
{ {
return secretComputePath(driver, secret, ".xml"); return secretComputePath(driver, secret, ".xml");
} }
static char * static char *
secretBase64Path(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, secretBase64Path(virSecretDriverStatePtr driver,
virSecretDriverStatePtr driver,
const virSecretEntry *secret) const virSecretEntry *secret)
{ {
return secretComputePath(driver, secret, ".base64"); return secretComputePath(driver, secret, ".base64");
@ -249,7 +247,7 @@ secretEnsureDirectory(virSecretDriverStatePtr driver)
} }
static int static int
secretSaveDef(virConnectPtr conn, virSecretDriverStatePtr driver, secretSaveDef(virSecretDriverStatePtr driver,
const virSecretEntry *secret) const virSecretEntry *secret)
{ {
char *filename = NULL, *xml = NULL; char *filename = NULL, *xml = NULL;
@ -258,10 +256,10 @@ secretSaveDef(virConnectPtr conn, virSecretDriverStatePtr driver,
if (secretEnsureDirectory(driver) < 0) if (secretEnsureDirectory(driver) < 0)
goto cleanup; goto cleanup;
filename = secretXMLPath(conn, driver, secret); filename = secretXMLPath(driver, secret);
if (filename == NULL) if (filename == NULL)
goto cleanup; goto cleanup;
xml = virSecretDefFormat(conn, secret->def); xml = virSecretDefFormat(secret->def);
if (xml == NULL) if (xml == NULL)
goto cleanup; goto cleanup;
@ -277,7 +275,7 @@ cleanup:
} }
static int static int
secretSaveValue(virConnectPtr conn, virSecretDriverStatePtr driver, secretSaveValue(virSecretDriverStatePtr driver,
const virSecretEntry *secret) const virSecretEntry *secret)
{ {
char *filename = NULL, *base64 = NULL; char *filename = NULL, *base64 = NULL;
@ -289,7 +287,7 @@ secretSaveValue(virConnectPtr conn, virSecretDriverStatePtr driver,
if (secretEnsureDirectory(driver) < 0) if (secretEnsureDirectory(driver) < 0)
goto cleanup; goto cleanup;
filename = secretBase64Path(conn, driver, secret); filename = secretBase64Path(driver, secret);
if (filename == NULL) if (filename == NULL)
goto cleanup; goto cleanup;
base64_encode_alloc((const char *)secret->value, secret->value_size, base64_encode_alloc((const char *)secret->value, secret->value_size,
@ -311,16 +309,16 @@ cleanup:
} }
static int static int
secretDeleteSaved(virConnectPtr conn, virSecretDriverStatePtr driver, secretDeleteSaved(virSecretDriverStatePtr driver,
const virSecretEntry *secret) const virSecretEntry *secret)
{ {
char *xml_filename = NULL, *value_filename = NULL; char *xml_filename = NULL, *value_filename = NULL;
int ret = -1; int ret = -1;
xml_filename = secretXMLPath(conn, driver, secret); xml_filename = secretXMLPath(driver, secret);
if (xml_filename == NULL) if (xml_filename == NULL)
goto cleanup; goto cleanup;
value_filename = secretBase64Path(conn, driver, secret); value_filename = secretBase64Path(driver, secret);
if (value_filename == NULL) if (value_filename == NULL)
goto cleanup; goto cleanup;
@ -339,7 +337,7 @@ cleanup:
} }
static int static int
secretLoadValidateUUID(virConnectPtr conn, virSecretDefPtr def, secretLoadValidateUUID(virSecretDefPtr def,
const char *xml_basename) const char *xml_basename)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
@ -347,7 +345,7 @@ secretLoadValidateUUID(virConnectPtr conn, virSecretDefPtr def,
virUUIDFormat(def->uuid, uuidstr); virUUIDFormat(def->uuid, uuidstr);
if (!virFileMatchesNameSuffix(xml_basename, uuidstr, ".xml")) { if (!virFileMatchesNameSuffix(xml_basename, uuidstr, ".xml")) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
_("<uuid> does not match secret file name '%s'"), _("<uuid> does not match secret file name '%s'"),
xml_basename); xml_basename);
return -1; return -1;
@ -357,7 +355,7 @@ secretLoadValidateUUID(virConnectPtr conn, virSecretDefPtr def,
} }
static int static int
secretLoadValue(virConnectPtr conn, virSecretDriverStatePtr driver, secretLoadValue(virSecretDriverStatePtr driver,
virSecretEntryPtr secret) virSecretEntryPtr secret)
{ {
int ret = -1, fd = -1; int ret = -1, fd = -1;
@ -365,7 +363,7 @@ secretLoadValue(virConnectPtr conn, virSecretDriverStatePtr driver,
char *filename = NULL, *contents = NULL, *value = NULL; char *filename = NULL, *contents = NULL, *value = NULL;
size_t value_size; size_t value_size;
filename = secretBase64Path(conn, driver, secret); filename = secretBase64Path(driver, secret);
if (filename == NULL) if (filename == NULL)
goto cleanup; goto cleanup;
@ -383,7 +381,7 @@ secretLoadValue(virConnectPtr conn, virSecretDriverStatePtr driver,
goto cleanup; goto cleanup;
} }
if ((size_t)st.st_size != st.st_size) { if ((size_t)st.st_size != st.st_size) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
_("'%s' file does not fit in memory"), filename); _("'%s' file does not fit in memory"), filename);
goto cleanup; goto cleanup;
} }
@ -400,7 +398,7 @@ secretLoadValue(virConnectPtr conn, virSecretDriverStatePtr driver,
fd = -1; fd = -1;
if (!base64_decode_alloc(contents, st.st_size, &value, &value_size)) { if (!base64_decode_alloc(contents, st.st_size, &value, &value_size)) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid base64 in '%s'"), filename); _("invalid base64 in '%s'"), filename);
goto cleanup; goto cleanup;
} }
@ -431,7 +429,7 @@ cleanup:
} }
static virSecretEntryPtr static virSecretEntryPtr
secretLoad(virConnectPtr conn, virSecretDriverStatePtr driver, secretLoad(virSecretDriverStatePtr driver,
const char *xml_basename) const char *xml_basename)
{ {
virSecretDefPtr def = NULL; virSecretDefPtr def = NULL;
@ -443,12 +441,12 @@ secretLoad(virConnectPtr conn, virSecretDriverStatePtr driver,
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
def = virSecretDefParseFile(conn, xml_filename); def = virSecretDefParseFile(xml_filename);
if (def == NULL) if (def == NULL)
goto cleanup; goto cleanup;
VIR_FREE(xml_filename); VIR_FREE(xml_filename);
if (secretLoadValidateUUID(conn, def, xml_basename) < 0) if (secretLoadValidateUUID(def, xml_basename) < 0)
goto cleanup; goto cleanup;
if (VIR_ALLOC(secret) < 0) { if (VIR_ALLOC(secret) < 0) {
@ -458,7 +456,7 @@ secretLoad(virConnectPtr conn, virSecretDriverStatePtr driver,
secret->def = def; secret->def = def;
def = NULL; def = NULL;
if (secretLoadValue(conn, driver, secret) < 0) if (secretLoadValue(driver, secret) < 0)
goto cleanup; goto cleanup;
ret = secret; ret = secret;
@ -472,7 +470,7 @@ cleanup:
} }
static int static int
loadSecrets(virConnectPtr conn, virSecretDriverStatePtr driver, loadSecrets(virSecretDriverStatePtr driver,
virSecretEntryPtr *dest) virSecretEntryPtr *dest)
{ {
int ret = -1; int ret = -1;
@ -496,7 +494,7 @@ loadSecrets(virConnectPtr conn, virSecretDriverStatePtr driver,
if (!virFileHasSuffix(de->d_name, ".xml")) if (!virFileHasSuffix(de->d_name, ".xml"))
continue; continue;
secret = secretLoad(conn, driver, de->d_name); secret = secretLoad(driver, de->d_name);
if (secret == NULL) { if (secret == NULL) {
virErrorPtr err = virGetLastError(); virErrorPtr err = virGetLastError();
@ -632,7 +630,7 @@ secretLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
if (secret == NULL) { if (secret == NULL) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(uuid, uuidstr); virUUIDFormat(uuid, uuidstr);
virSecretReportError(conn, VIR_ERR_NO_SECRET, virSecretReportError(VIR_ERR_NO_SECRET,
_("no secret with matching uuid '%s'"), uuidstr); _("no secret with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -659,7 +657,7 @@ secretLookupByUsage(virConnectPtr conn, int usageType, const char *usageID)
secret = secretFindByUsage(driver, usageType, usageID); secret = secretFindByUsage(driver, usageType, usageID);
if (secret == NULL) { if (secret == NULL) {
virSecretReportError(conn, VIR_ERR_NO_SECRET, virSecretReportError(VIR_ERR_NO_SECRET,
_("no secret with matching usage '%s'"), usageID); _("no secret with matching usage '%s'"), usageID);
goto cleanup; goto cleanup;
} }
@ -685,7 +683,7 @@ secretDefineXML(virConnectPtr conn, const char *xml,
virSecretDefPtr backup = NULL; virSecretDefPtr backup = NULL;
virSecretDefPtr new_attrs; virSecretDefPtr new_attrs;
new_attrs = virSecretDefParseString(conn, xml); new_attrs = virSecretDefParseString(xml);
if (new_attrs == NULL) if (new_attrs == NULL)
return NULL; return NULL;
@ -699,7 +697,7 @@ secretDefineXML(virConnectPtr conn, const char *xml,
if (secret) { if (secret) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(secret->def->uuid, uuidstr); virUUIDFormat(secret->def->uuid, uuidstr);
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
_("a secret with UUID %s already defined for use with %s"), _("a secret with UUID %s already defined for use with %s"),
uuidstr, usageID); uuidstr, usageID);
goto cleanup; goto cleanup;
@ -719,14 +717,14 @@ secretDefineXML(virConnectPtr conn, const char *xml,
if (STRNEQ(oldUsageID, newUsageID)) { if (STRNEQ(oldUsageID, newUsageID)) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(secret->def->uuid, uuidstr); virUUIDFormat(secret->def->uuid, uuidstr);
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, virSecretReportError(VIR_ERR_INTERNAL_ERROR,
_("a secret with UUID %s is already defined for use with %s"), _("a secret with UUID %s is already defined for use with %s"),
uuidstr, oldUsageID); uuidstr, oldUsageID);
goto cleanup; goto cleanup;
} }
if (secret->def->private && !new_attrs->private) { if (secret->def->private && !new_attrs->private) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot change private flag on existing secret")); _("cannot change private flag on existing secret"));
goto cleanup; goto cleanup;
} }
@ -738,15 +736,15 @@ secretDefineXML(virConnectPtr conn, const char *xml,
if (!new_attrs->ephemeral) { if (!new_attrs->ephemeral) {
if (backup && backup->ephemeral) { if (backup && backup->ephemeral) {
if (secretSaveValue(conn, driver, secret) < 0) if (secretSaveValue(driver, secret) < 0)
goto restore_backup; goto restore_backup;
} }
if (secretSaveDef(conn, driver, secret) < 0) { if (secretSaveDef(driver, secret) < 0) {
if (backup && backup->ephemeral) { if (backup && backup->ephemeral) {
char *filename; char *filename;
/* Undo the secretSaveValue() above; ignore errors */ /* Undo the secretSaveValue() above; ignore errors */
filename = secretBase64Path(conn, driver, secret); filename = secretBase64Path(driver, secret);
if (filename != NULL) if (filename != NULL)
(void)unlink(filename); (void)unlink(filename);
VIR_FREE(filename); VIR_FREE(filename);
@ -754,7 +752,7 @@ secretDefineXML(virConnectPtr conn, const char *xml,
goto restore_backup; goto restore_backup;
} }
} else if (backup && !backup->ephemeral) { } else if (backup && !backup->ephemeral) {
if (secretDeleteSaved(conn, driver, secret) < 0) if (secretDeleteSaved(driver, secret) < 0)
goto restore_backup; goto restore_backup;
} }
/* Saved successfully - drop old values */ /* Saved successfully - drop old values */
@ -774,7 +772,7 @@ restore_backup:
} else { } else {
/* "secret" was added to the head of the list above */ /* "secret" was added to the head of the list above */
if (listUnlink(&driverState->secrets) != secret) if (listUnlink(&driverState->secrets) != secret)
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("list of secrets is inconsistent")); _("list of secrets is inconsistent"));
else else
secretFree(secret); secretFree(secret);
@ -800,12 +798,12 @@ secretGetXMLDesc(virSecretPtr obj, unsigned int flags ATTRIBUTE_UNUSED)
if (secret == NULL) { if (secret == NULL) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(obj->uuid, uuidstr); virUUIDFormat(obj->uuid, uuidstr);
virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, virSecretReportError(VIR_ERR_NO_SECRET,
_("no secret with matching uuid '%s'"), uuidstr); _("no secret with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
ret = virSecretDefFormat(obj->conn, secret->def); ret = virSecretDefFormat(secret->def);
cleanup: cleanup:
secretDriverUnlock(driver); secretDriverUnlock(driver);
@ -834,7 +832,7 @@ secretSetValue(virSecretPtr obj, const unsigned char *value,
if (secret == NULL) { if (secret == NULL) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(obj->uuid, uuidstr); virUUIDFormat(obj->uuid, uuidstr);
virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, virSecretReportError(VIR_ERR_NO_SECRET,
_("no secret with matching uuid '%s'"), uuidstr); _("no secret with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -846,7 +844,7 @@ secretSetValue(virSecretPtr obj, const unsigned char *value,
secret->value = new_value; secret->value = new_value;
secret->value_size = value_size; secret->value_size = value_size;
if (!secret->def->ephemeral) { if (!secret->def->ephemeral) {
if (secretSaveValue(obj->conn, driver, secret) < 0) if (secretSaveValue(driver, secret) < 0)
goto restore_backup; goto restore_backup;
} }
/* Saved successfully - drop old value */ /* Saved successfully - drop old value */
@ -886,7 +884,7 @@ secretGetValue(virSecretPtr obj, size_t *value_size, unsigned int flags)
if (secret == NULL) { if (secret == NULL) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(obj->uuid, uuidstr); virUUIDFormat(obj->uuid, uuidstr);
virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, virSecretReportError(VIR_ERR_NO_SECRET,
_("no secret with matching uuid '%s'"), uuidstr); _("no secret with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -894,14 +892,14 @@ secretGetValue(virSecretPtr obj, size_t *value_size, unsigned int flags)
if (secret->value == NULL) { if (secret->value == NULL) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(obj->uuid, uuidstr); virUUIDFormat(obj->uuid, uuidstr);
virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, virSecretReportError(VIR_ERR_NO_SECRET,
_("secret '%s' does not have a value"), uuidstr); _("secret '%s' does not have a value"), uuidstr);
goto cleanup; goto cleanup;
} }
if ((flags & VIR_SECRET_GET_VALUE_INTERNAL_CALL) == 0 && if ((flags & VIR_SECRET_GET_VALUE_INTERNAL_CALL) == 0 &&
secret->def->private) { secret->def->private) {
virSecretReportError(obj->conn, VIR_ERR_OPERATION_DENIED, "%s", virSecretReportError(VIR_ERR_OPERATION_DENIED, "%s",
_("secret is private")); _("secret is private"));
goto cleanup; goto cleanup;
} }
@ -932,13 +930,13 @@ secretUndefine(virSecretPtr obj)
if (secret == NULL) { if (secret == NULL) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(obj->uuid, uuidstr); virUUIDFormat(obj->uuid, uuidstr);
virSecretReportError(obj->conn, VIR_ERR_NO_SECRET, virSecretReportError(VIR_ERR_NO_SECRET,
_("no secret with matching uuid '%s'"), uuidstr); _("no secret with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
if (!secret->def->ephemeral && if (!secret->def->ephemeral &&
secretDeleteSaved(obj->conn, driver, secret) < 0) secretDeleteSaved(driver, secret) < 0)
goto cleanup; goto cleanup;
if (driver->secrets == secret) { if (driver->secrets == secret) {
@ -1018,7 +1016,7 @@ secretDriverStartup(int privileged)
goto out_of_memory; goto out_of_memory;
VIR_FREE(base); VIR_FREE(base);
if (loadSecrets(NULL, driverState, &driverState->secrets) < 0) if (loadSecrets(driverState, &driverState->secrets) < 0)
goto error; goto error;
secretDriverUnlock(driverState); secretDriverUnlock(driverState);
@ -1043,7 +1041,7 @@ secretDriverReload(void)
secretDriverLock(driverState); secretDriverLock(driverState);
if (loadSecrets(NULL, driverState, &new_secrets) < 0) if (loadSecrets(driverState, &new_secrets) < 0)
goto end; goto end;
/* Keep ephemeral secrets from current state. Discard non-ephemeral secrets /* Keep ephemeral secrets from current state. Discard non-ephemeral secrets

View File

@ -385,8 +385,8 @@ virStorageGenerateSecretUUID(virConnectPtr conn,
for (attempt = 0; attempt < 65536; attempt++) { for (attempt = 0; attempt < 65536; attempt++) {
virSecretPtr tmp; virSecretPtr tmp;
if (virUUIDGenerate(uuid) < 0) { if (virUUIDGenerate(uuid) < 0) {
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("unable to generate uuid")); _("unable to generate uuid"));
return -1; return -1;
} }
tmp = conn->secretDriver->lookupByUUID(conn, uuid); tmp = conn->secretDriver->lookupByUUID(conn, uuid);
@ -396,8 +396,8 @@ virStorageGenerateSecretUUID(virConnectPtr conn,
virSecretFree(tmp); virSecretFree(tmp);
} }
virSecretReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("too many conflicts when generating an uuid")); _("too many conflicts when generating an uuid"));
return -1; return -1;
} }
@ -448,7 +448,7 @@ virStorageGenerateQcowEncryption(virConnectPtr conn,
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
xml = virSecretDefFormat(conn, def); xml = virSecretDefFormat(def);
virSecretDefFree(def); virSecretDefFree(def);
def = NULL; def = NULL;
if (xml == NULL) if (xml == NULL)