]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Implement "vos listaddrs"
authorDavid Howells <dhowells@redhat.com>
Wed, 8 Jul 2020 21:36:15 +0000 (22:36 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 5 May 2023 10:53:26 +0000 (11:53 +0100)
Signed-off-by: David Howells <dhowells@redhat.com>
kafs/Makefile
kafs/vos_listaddrs.C [new file with mode: 0644]

index bde79f6fa71ba09f4939c41c0e8e15eac5aa795b..504b93b19436553d8511feddc099231851cc0e18 100644 (file)
@@ -34,6 +34,7 @@ VOS_SRCS := \
        vos.C \
        vos_examine.C \
        vos_help.C \
+       vos_listaddrs.C \
        vos_listvldb.C \
        vos_status.C
 
diff --git a/kafs/vos_listaddrs.C b/kafs/vos_listaddrs.C
new file mode 100644 (file)
index 0000000..13e4249
--- /dev/null
@@ -0,0 +1,120 @@
+/* The "vos listaddrs" command
+ *
+ * Copyright (C) 2020 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <fmt/core.h>
+#include "kafs.H"
+#include "vlservice.H"
+#include "arg_parse.H"
+#include "display.H"
+#include "afs_xg.H"
+
+using rxrpc::ref;
+
+static void vos_listaddrs_one(kafs::Context *ctx,
+                             bool a_printuuid,
+                             kafs::FS_site *site)
+{
+       char buf[1024];
+       unsigned int i;
+
+       if (a_printuuid) {
+               uuid_unparse(site->uuid.uuid, buf);
+               fmt::print("UUID: {}\n", buf);
+       }
+
+       for (i = 0; i < site->vs_addrs.size(); i++)
+               fmt::print("{}\n", kafs::sprint_address(ctx, site->vs_addrs[i]));
+
+       if (a_printuuid)
+               fmt::print("\n");
+}
+
+static void vos_listaddrs_all(kafs::Context *ctx,
+                             kafs::VL_service *vlservice,
+                             bool a_printuuid)
+{
+       kafs::afs::VL_Callback vl_callback;
+       std::vector<uint32_t> blkaddr;
+       int32_t nentries;
+       unsigned int i;
+       int found;
+
+       kafs::afs::VL::GetAddrs(&vlservice->vl_params, 0, 0, vl_callback, nentries, blkaddr);
+
+       found = nentries;
+       for (i = 1; i < 65536; i++) {
+               ref<kafs::FS_site> site;
+
+               try {
+                       site = vlservice->look_up_fileserver_by_index(i);
+               } catch (const kafs::afs::VL::AbortVL_NOENT &) {
+                       continue;
+               } catch (const kafs::afs::VL::AbortVL_INDEXERANGE &) {
+                       return;
+               }
+
+               vos_listaddrs_one(ctx, a_printuuid, site);
+               found--;
+               if (found <= 0)
+                       break;
+       }
+}
+
+/***
+ * COMMAND: vos listaddrs - List all of the file server registrations.
+ * ARG: "[-uuid <uuid of server>]"
+ * ARG: "[-host <address of host>]"
+ * ARG: "[-printuuid]"
+ * ARG: "[-cell <cell name>]"
+ * ARG: "[-noauth]"                            - Auth
+ * ARG: "[-localauth]"                         - Auth
+ * ARG: "[-verbose]"
+ * ARG: "[-encrypt]"                           - Auth
+ * ARG: "[-noresolve]"
+ * NOCOMBINE: uuid, host
+ *
+ * Display a list of registered volume servers.
+ */
+void COMMAND_vos_listaddrs(
+       kafs::Context                   *ctx,
+       kafs::Uuid_spec                 &a_uuid,
+       kafs::Fileserver_spec           &a_host,
+       bool                            a_printuuid,
+       bool                            a_quiet,
+       bool                            a_nosort,
+       bool                            a_verbose,
+       bool                            a_noresolve)
+{
+       ref<kafs::FS_site> server, spec;
+
+       _enter("");
+
+       ctx->no_resolve = a_noresolve;
+
+       ref<kafs::VL_service> vlservice = new kafs::VL_service(ctx);
+
+       if (!a_uuid.specified && !a_host.specified)
+               return vos_listaddrs_all(ctx, vlservice, a_printuuid);
+
+       if (a_uuid.specified) {
+               server = vlservice->look_up_fileserver_by_uuid(a_uuid.uuid);
+       } else {
+               spec = kafs::resolve_server_spec(ctx, a_host);
+               server = vlservice->look_up_fileserver_by_addr(spec->fs_addrs[0]);
+       }
+
+       if (server)
+               vos_listaddrs_one(ctx, a_printuuid, server);
+}
+
+/***
+ * ALIAS: vos listfs - listaddrs
+ */