--- /dev/null
+/* 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
+ */