Patchwork [06/15] nsdbparams: Delete subcommand should report missing NSDB entry

login
register
mail settings
Submitter Chuck Lever
Date Oct. 25, 2011, 4:49 p.m.
Message ID <20111025164906.18584.66616.stgit@seurat.1015granger.net>
Download mbox | patch
Permalink /patch/121765/
State Accepted
Headers show

Comments

Chuck Lever - Oct. 25, 2011, 4:49 p.m.
Currently, the "delete" subcommand reports that an NSDB entry
in the connection parameter database was successfully removed
even if the requested NSDB entry was not there to begin with.
This is somewhat confusing.

Have "nsdbparams delete" report when the NSDB entry is missing.
This is still treated as a success.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 src/nsdbparams/main.c |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

Patch

diff --git a/src/nsdbparams/main.c b/src/nsdbparams/main.c
index 220d9c6..c91ce81 100644
--- a/src/nsdbparams/main.c
+++ b/src/nsdbparams/main.c
@@ -188,17 +188,37 @@  static int
 nsdbparams_delete(const char *progname, const char *nsdbname,
 		const unsigned short nsdbport)
 {
+	FedFsStatus status;
+	nsdb_t host;
+
 	if (nsdbname == NULL) {
 		xlog(L_ERROR, "Missing required command line argument\n");
 		nsdbparams_usage(progname);
 		return EXIT_FAILURE;
 	}
 
-	if (nsdb_delete_nsdb(nsdbname, nsdbport) != FEDFS_OK)
+	status = nsdb_lookup_nsdb(nsdbname, nsdbport, &host, NULL);
+	switch (status) {
+	case FEDFS_OK:
+		nsdb_free_nsdb(host);
+		status = nsdb_delete_nsdb(nsdbname, nsdbport);
+		if (status != FEDFS_OK) {
+			xlog(L_ERROR, "nsdb_delete_nsdb returned %s",
+				nsdb_display_fedfsstatus(status));
+			return EXIT_FAILURE;
+		}
+		printf("%s:%u was deleted successfully\n", nsdbname, nsdbport);
+		break;
+	case FEDFS_ERR_NSDB_PARAMS:
+		xlog(L_ERROR, "No record for %s:%u was found",
+			nsdbname, nsdbport);
+		break;
+	default:
+		xlog(L_ERROR, "nsdb_lookup_nsdb returned %s",
+			nsdb_display_fedfsstatus(status));
 		return EXIT_FAILURE;
+	}
 
-	printf("%s: %s:%u deleted successfully\n",
-		progname, nsdbname, nsdbport);
 	return EXIT_SUCCESS;
 }