From: Li Yang <liyang.fnst(a)cn.fujitsu.com>
When a secret's usage is specified, for example:
<secret ephemeral='no' private='no'>
<uuid>540c56d1-f4b3-5031-b76d-33e99e9b5c64</uuid>
<usage type='volume'>
<volume>/tmp/test</volume>
</usage>
</secret>
If another volume '/tmp/test1' isn't used, the current
secret's usage can bo modified to '/tmp/test1'.
If '/tmp/test1' has been used for another secret,
error message will be outputed.
Signed-off-by: Li Yang <liyang.fnst(a)cn.fujitsu.com>
---
src/secret/secret_driver.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 4123e6e..78fd054 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -781,6 +781,7 @@ secretDefineXML(virConnectPtr conn, const char *xml,
virSecretDriverStatePtr driver = conn->secretPrivateData;
virSecretPtr ret = NULL;
virSecretEntryPtr secret;
+ virSecretEntryPtr new_secret;
virSecretDefPtr backup = NULL;
virSecretDefPtr new_attrs;
@@ -804,7 +805,7 @@ secretDefineXML(virConnectPtr conn, const char *xml,
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(secret->def->uuid, uuidstr);
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("a secret with UUID %s already defined for use with
%s"),
+ _("a secret with UUID %s is already defined for use with
%s"),
uuidstr, usageID);
goto cleanup;
}
@@ -819,12 +820,15 @@ secretDefineXML(virConnectPtr conn, const char *xml,
const char *newUsageID = secretUsageIDForDef(new_attrs);
const char *oldUsageID = secretUsageIDForDef(secret->def);
if (STRNEQ(oldUsageID, newUsageID)) {
- char uuidstr[VIR_UUID_STRING_BUFLEN];
- virUUIDFormat(secret->def->uuid, uuidstr);
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("a secret with UUID %s is already defined for use with
%s"),
- uuidstr, oldUsageID);
- goto cleanup;
+ new_secret = secretFindByUsage(driver, new_attrs->usage_type,
newUsageID);
+ if (new_secret){
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+ virUUIDFormat(new_secret->def->uuid, uuidstr);
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("a secret with UUID %s is already defined for use
with %s"),
+ uuidstr, newUsageID);
+ goto cleanup;
+ }
}
if (secret->def->private && !new_attrs->private) {
--
1.7.1