On 09/05/12 08:28, Osier Yang wrote:
Simply returns the object list. No filtering.
src/secret/secret_driver.c: Implement listAllSecrets
---
src/secret/secret_driver.c | 59 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 58 insertions(+), 1 deletions(-)
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 7f92776..ed759ed 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -601,7 +601,6 @@ cleanup:
return -1;
}
-
Please don't include this hunk here. Two empty lines between functions
are pretty common (this patch adds that too at the end of
secretListAllSecrets().
static const char *
secretUsageIDForDef(virSecretDefPtr def)
{
@@ -620,6 +619,63 @@ secretUsageIDForDef(virSecretDefPtr def)
}
}
+static int
+secretListAllSecrets(virConnectPtr conn,
+ virSecretPtr **secrets,
+ unsigned int flags) {
+ virSecretDriverStatePtr driver = conn->secretPrivateData;
+ virSecretPtr *tmp_secrets = NULL;
+ int nsecrets = 0;
+ int ret_nsecrets = 0;
+ virSecretPtr secret = NULL;
+ virSecretEntryPtr entry = NULL;
+ int i = 0;
+ int ret = -1;
+
+ virCheckFlags(0, -1);
+
+ secretDriverLock(driver);
+
+ for (entry = driver->secrets; entry != NULL; entry = entry->next)
+ nsecrets++;
+
+ if (!secrets) {
+ ret = nsecrets;
+ goto cleanup;
+ }
+
+ if (VIR_ALLOC_N(tmp_secrets, nsecrets + 1) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ for (entry = driver->secrets; entry != NULL; entry = entry->next) {
+ if (!(secret = virGetSecret(conn,
+ entry->def->uuid,
+ entry->def->usage_type,
+ secretUsageIDForDef(entry->def))))
+ goto cleanup;
+ tmp_secrets[ret_nsecrets++] = secret;
+ }
+
+ *secrets = tmp_secrets;
+ tmp_secrets = NULL;
+ ret = ret_nsecrets;
+
+ cleanup:
+ secretDriverUnlock(driver);
+ if (tmp_secrets) {
+ for (i = 0; i < ret_nsecrets; i ++) {
+ if (tmp_secrets[i])
+ virSecretFree(tmp_secrets[i]);
+ }
+ }
+ VIR_FREE(tmp_secrets);
+
+ return ret;
+}
+
+
static virSecretPtr
secretLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
Otherwise looks OK.
Peter