]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Implement "vos listvldb"
authorDavid Howells <dhowells@redhat.com>
Tue, 23 Jun 2020 17:12:09 +0000 (18:12 +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_listvldb.C [new file with mode: 0644]

index ff2ba2271501ac3d33dcbf5e661c3bbf0c87f3aa..95973a2ce1b30ceb724a432c81f3492538372939 100644 (file)
@@ -32,7 +32,8 @@ PTS_SRCS := \
 
 VOS_SRCS := \
        vos.C \
-       vos_help.C
+       vos_help.C \
+       vos_listvldb.C
 
 CORE_OBJS := $(patsubst %.C,%.o,$(CORE_SRCS))
 BOS_OBJS  :=  $(patsubst %.C,%.o,$(BOS_SRCS))
diff --git a/kafs/vos_listvldb.C b/kafs/vos_listvldb.C
new file mode 100644 (file)
index 0000000..c5964b5
--- /dev/null
@@ -0,0 +1,107 @@
+/* The "vos listvldb" 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 <iostream>
+#include <algorithm>
+#include <fmt/ostream.h>
+#include "kafs.H"
+#include "vlservice.H"
+#include "afs_xg.H"
+#include "display.H"
+
+using rxrpc::ref;
+
+static void print_vl_record(kafs::Context *ctx,
+                           kafs::Vldb_entry *vldb)
+{
+       unsigned int flags = vldb->flags;
+
+       std::cout << vldb->name << "\n"
+                 << "   ";
+       if (flags & kafs::afs::VLF_RWEXISTS)   fmt::print(" RWrite: {:<12d}", vldb->volume_id[0]);
+       if (flags & kafs::afs::VLF_ROEXISTS)   fmt::print(" ROnly: {:<12d}", vldb->volume_id[1]);
+       if (flags & kafs::afs::VLF_BACKEXISTS) fmt::print(" Backup: {:<12d}", vldb->volume_id[2]);
+       std::cout << "\n";
+       kafs::display_vldb_site_list(ctx, vldb, "    ");
+       std::cout << "\n";
+}
+
+static bool cmp_entries_by_name(kafs::Vldb_entry *a, kafs::Vldb_entry *b)
+{
+       return a->name < b->name;
+}
+
+/***
+ * COMMAND: vos listvldb - Query the VLDB
+ * ARG: "[-name <volume name>]"
+ * ARG: "[-server <machine name>]"
+ * ARG: "[-partition <partition name>]"
+ * ARG: "[-locked]"
+ * ARG: "[-quiet]"
+ * ARG: "[-nosort]"
+ * ARG: "[-cell <cell name>]"
+ * ARG: "[-noauth]"                            - Auth
+ * ARG: "[-localauth]"                         - Auth
+ * ARG: "[-verbose]"
+ * ARG: "[-encrypt]"                           - Auth
+ * ARG: "[-noresolve]"
+ * NOCOMBINE: name, server
+ * NOCOMBINE: name, partition
+ * NOCOMBINE: name, locked
+ *
+ * Displays a volume's VLDB entry
+ */
+void COMMAND_vos_listvldb(
+       kafs::Context                   *ctx,
+       kafs::Volume_spec               &a_name,
+       kafs::Fileserver_spec           &a_server,
+       kafs::Partition_spec            &a_partition,
+       bool                            a_locked,
+       bool                            a_quiet,
+       bool                            a_nosort,
+       bool                            a_verbose,
+       bool                            a_noresolve)
+{
+       kafs::Vldb_entry_list vlist;
+       unsigned int i;
+
+       _enter("");
+
+       ctx->no_resolve = a_noresolve;
+
+       ref<kafs::VL_service> vlservice = new kafs::VL_service(ctx);
+
+       if (a_name.specified &&
+           !a_server.specified &&
+           !a_partition.specified &&
+           !a_locked &&
+           a_name.name.find('*') == std::string::npos) {
+               vlservice->look_up_volume_by_name(a_name, vlist);
+               print_vl_record(ctx, vlist[0]);
+       } else {
+               vlservice->look_up_volumes_by_attributes(a_server, a_partition,
+                                                        a_locked, a_name.name, vlist);
+               if (!a_quiet && a_server.specified)
+                       std::cout << "VLDB entries for server " << a_server.name << "\n";
+
+               if (!a_nosort)
+                       std::sort(vlist.begin(), vlist.end(), cmp_entries_by_name);
+
+               for (i = 0; i < vlist.size(); i++)
+                       print_vl_record(ctx, vlist[i]);
+               if (!a_quiet)
+                       std::cout << "Total entries: " << vlist.size() << "\n";
+       }
+}
+
+/***
+ * ALIAS: vos listloc - listvldb
+ */