Patchwork [5/7] nsdbc: Update NSDB client tools to display the FsnTTL.

login
register
mail settings
Submitter Chuck Lever
Date Nov. 20, 2012, 8:27 p.m.
Message ID <20121120202709.47389.48192.stgit@seurat.1015granger.net>
Download mbox | patch
Permalink /patch/200509/
State Accepted
Headers show

Comments

Chuck Lever - Nov. 20, 2012, 8:27 p.m.
Now that nsdb_resolve_fsn_s() returns a TTL, various tools are
altered to display it.

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

 doc/man/nsdb-resolve-fsn.8   |    4 ++++
 src/nfsref/lookup.c          |   28 ++++++++++++++++++++++++++++
 src/nsdbc/nsdb-resolve-fsn.c |   40 ++++++++++++++++++++++++++++++++++++----
 3 files changed, 68 insertions(+), 4 deletions(-)

Patch

diff --git a/doc/man/nsdb-resolve-fsn.8 b/doc/man/nsdb-resolve-fsn.8
index aa8647c..45466aa 100644
--- a/doc/man/nsdb-resolve-fsn.8
+++ b/doc/man/nsdb-resolve-fsn.8
@@ -250,6 +250,10 @@  $ nsdb-resolve-fsn -e o=fedfs \\
 .sp
 For FSN UUID 8e246ddc-7b46-11e0-8252-000c297fd679
 .br
+    FSN TTL  600
+.sp
+------------------------------------------------------
+.br
 dn: fedfsFslUuid=323c5068-7c11-11e0-8d38-000c297fd679,
 .br
     fedfsFsnUuid=8e246ddc-7b46-11e0-8252-000c297fd679,o=fedfs
diff --git a/src/nfsref/lookup.c b/src/nfsref/lookup.c
index 2c34090..acd3769 100644
--- a/src/nfsref/lookup.c
+++ b/src/nfsref/lookup.c
@@ -267,8 +267,10 @@  nfsref_lookup_resolve_fsn(const char *fsn_uuid, nsdb_t host)
 {
 	int status = EXIT_FAILURE;
 	struct fedfs_fsl *fsls;
+	struct fedfs_fsn *fsn;
 	unsigned int ldap_err;
 	FedFsStatus retval;
+	int fsn_ttl;
 
 	xlog(D_GENERAL, "%s: resolving FSN UUID %s with NSDB %s:%u",
 		__func__, fsn_uuid, nsdb_hostname(host), nsdb_port(host));
@@ -276,11 +278,36 @@  nfsref_lookup_resolve_fsn(const char *fsn_uuid, nsdb_t host)
 	if (nsdb_open_nsdb(host, NULL, NULL, &ldap_err) != FEDFS_OK)
 		return status;
 
+	retval = nsdb_get_fsn_s(host, NULL, fsn_uuid, &fsn, &ldap_err);
+	switch (retval) {
+	case FEDFS_OK:
+		fsn_ttl = fsn->fn_fsnttl;
+		nsdb_free_fedfs_fsn(fsn);
+		break;
+	case FEDFS_ERR_NSDB_NOFSN:
+		xlog(L_ERROR, "%s: No FSN %s found",
+			__func__, fsn_uuid);
+		goto out_close;
+	case FEDFS_ERR_NSDB_LDAP_VAL:
+		xlog(L_ERROR, "%s: NSDB operation failed with %s",
+			__func__, ldap_err2string(ldap_err));
+		goto out_close;
+	default:
+		xlog(L_ERROR, "%s: Failed to retrieve FSN %s: %s",
+			__func__, fsn_uuid, nsdb_display_fedfsstatus(status));
+		goto out_close;
+	}
+
 	retval = nsdb_resolve_fsn_s(host, NULL, fsn_uuid, &fsls, &ldap_err);
 	switch (retval) {
 	case FEDFS_OK:
+		printf("fedfsFsnUuid:\t%s\n", fsn_uuid);
+		printf("NSDB:\t\t%s:%u\n", nsdb_hostname(host), nsdb_port(host));
+		printf("fedfsFsnTTL:\t%d\n", fsn_ttl);
+
 		nfsref_lookup_display_fedfs_fsls(fsls);
 		nsdb_free_fedfs_fsls(fsls);
+
 		status = EXIT_SUCCESS;
 		break;
 	case FEDFS_ERR_NSDB_NOFSL:
@@ -300,6 +327,7 @@  nfsref_lookup_resolve_fsn(const char *fsn_uuid, nsdb_t host)
 			__func__, fsn_uuid, nsdb_display_fedfsstatus(status));
 	}
 
+out_close:
 	nsdb_close_nsdb(host);
 	return status;
 }
diff --git a/src/nsdbc/nsdb-resolve-fsn.c b/src/nsdbc/nsdb-resolve-fsn.c
index aead4f7..3cebeab 100644
--- a/src/nsdbc/nsdb-resolve-fsn.c
+++ b/src/nsdbc/nsdb-resolve-fsn.c
@@ -147,6 +147,7 @@  nsdb_resolve_fsn_display_fsl(struct fedfs_fsl *fsl)
 {
 	int i;
 
+	printf("------------------------------------------------------\n");
 	printf("dn: %s\n\n", fsl->fl_dn);
 
 	printf(" FSN UUID:\t\t%s\n", fsl->fl_fsnuuid);
@@ -197,11 +198,12 @@  main(int argc, char **argv)
 	char *progname, *nsdbname;
 	unsigned short nsdbport;
 	struct fedfs_fsl *fsls;
+	struct fedfs_fsn *fsn;
 	unsigned int ldap_err;
 	char *nce, *fsn_uuid;
 	FedFsStatus retval;
+	int fsn_ttl, arg;
 	nsdb_t host;
-	int arg;
 
 	(void)umask(S_IRWXO);
 
@@ -309,10 +311,38 @@  main(int argc, char **argv)
 		goto out_free;
 	}
 
+	retval = nsdb_get_fsn_s(host, nce, fsn_uuid, &fsn, &ldap_err);
+	switch (retval) {
+	case FEDFS_OK:
+		fsn_ttl = fsn->fn_fsnttl;
+		nsdb_free_fedfs_fsn(fsn);
+		break;
+	case FEDFS_ERR_NSDB_NONCE:
+		if (nce == NULL)
+			fprintf(stderr, "NSDB %s:%u has no NCE\n",
+				nsdbname, nsdbport);
+		else
+			fprintf(stderr, "NCE %s does not exist\n", nce);
+		goto out_close;
+	case FEDFS_ERR_NSDB_NOFSN:
+		fprintf(stderr, "Failed to find FSN %s\n", fsn_uuid);
+		goto out_close;
+	case FEDFS_ERR_NSDB_LDAP_VAL:
+		fprintf(stderr, "NSDB LDAP error: %s\n",
+			ldap_err2string(ldap_err));
+		goto out_close;
+	default:
+		fprintf(stderr, "FedFsStatus code "
+			"while retrieving FSN UUID %s: %s\n",
+			fsn_uuid, nsdb_display_fedfsstatus(retval));
+		goto out_close;
+	}
+
 	retval = nsdb_resolve_fsn_s(host, nce, fsn_uuid, &fsls, &ldap_err);
 	switch (retval) {
 	case FEDFS_OK:
-		printf("For FSN UUID %s:\n\n", fsn_uuid);
+		printf("For FSN UUID: %s\n", fsn_uuid);
+		printf("    FSN TTL: %d\n\n", fsn_ttl);
 		nsdb_resolve_fsn_display_fsls(fsls);
 		nsdb_free_fedfs_fsls(fsls);
 		break;
@@ -324,8 +354,9 @@  main(int argc, char **argv)
 			fprintf(stderr, "NCE %s does not exist\n", nce);
 		break;
 	case FEDFS_ERR_NSDB_NOFSL:
-		fprintf(stderr, "Failed to find FSL entries for FSN %s\n",
-			fsn_uuid);
+		printf("For FSN UUID: %s\n", fsn_uuid);
+		printf("    FSN TTL: %d\n", fsn_ttl);
+		printf("    No FSL entries found\n");
 		break;
 	case FEDFS_ERR_NSDB_NOFSN:
 		fprintf(stderr, "Failed to find FSN %s\n", fsn_uuid);
@@ -340,6 +371,7 @@  main(int argc, char **argv)
 			fsn_uuid, nsdb_display_fedfsstatus(retval));
 	}
 
+out_close:
 	nsdb_close_nsdb(host);
 
 out_free: