diff mbox series

[5/6] vfs: Adjust fsinfo sample output

Message ID 153484533075.1183.12355648565791228863.stgit@warthog.procyon.org.uk (mailing list archive)
State New, archived
Headers show
Series [1/6] vfs: Fix vfs_dup_fs_context() | expand

Commit Message

David Howells Aug. 21, 2018, 9:55 a.m. UTC
Adjust the output of the test-fsinfo sample program to:

 (1) Print server addresses if of AF_INET or AF_INET6 family.

 (2) Not print parameter descriptions (the test-fs-query sample program can
     be used for that).

 (3) Only print non-blank parameter values so that parameters that just
     encode defaults don't clutter up the output.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 samples/statx/test-fsinfo.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
diff mbox series

Patch

diff --git a/samples/statx/test-fsinfo.c b/samples/statx/test-fsinfo.c
index 21714ef7ef5b..c08978acf08b 100644
--- a/samples/statx/test-fsinfo.c
+++ b/samples/statx/test-fsinfo.c
@@ -26,6 +26,7 @@ 
 #include <linux/fsinfo.h>
 #include <linux/socket.h>
 #include <sys/stat.h>
+#include <arpa/inet.h>
 
 static bool debug = 0;
 
@@ -304,6 +305,24 @@  static void dump_attr_VOLUME_UUID(union reply *r, int size)
 static void dump_attr_SERVER_ADDRESS(union reply *r, int size)
 {
 	struct fsinfo_server_address *f = &r->srv_addr;
+	struct sockaddr_in6 *sin6;
+	struct sockaddr_in *sin;
+	char buf[1024];
+
+	switch (f->address.ss_family) {
+	case AF_INET:
+		sin = (struct sockaddr_in *)&f->address;
+		if (!inet_ntop(AF_INET, &sin->sin_addr, buf, sizeof(buf)))
+			break;
+		printf("IPv4: %s\n", buf);
+		return;
+	case AF_INET6:
+		sin6 = (struct sockaddr_in6 *)&f->address;
+		if (!inet_ntop(AF_INET6, &sin6->sin6_addr, buf, sizeof(buf)))
+			break;
+		printf("IPv6: %s\n", buf);
+		return;
+	}
 
 	printf("family=%u\n", f->address.ss_family);
 }
@@ -426,6 +445,17 @@  static int try_one(const char *file, struct fsinfo_params *params, bool raw)
 		return 0;
 	}
 
+	switch (params->request) {
+	case FSINFO_ATTR_PARAM_DESCRIPTION:
+	case FSINFO_ATTR_PARAM_SPECIFICATION:
+	case FSINFO_ATTR_PARAM_NAME:
+	case FSINFO_ATTR_PARAM_ENUM:
+		return 0;
+	case FSINFO_ATTR_PARAMETER:
+		if (ret == 0)
+			return 0;
+	}
+
 	switch (about & 0xc000) {
 	case 0x0000:
 		printf("\e[33m%s\e[m: ",