From e615757a31892d45433e10415621502662ce96ca Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 23 Jun 2020 18:12:09 +0100 Subject: [PATCH] Implement "vos listvldb" Signed-off-by: David Howells --- kafs/Makefile | 3 +- kafs/vos_listvldb.C | 107 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 kafs/vos_listvldb.C diff --git a/kafs/Makefile b/kafs/Makefile index ff2ba22..95973a2 100644 --- a/kafs/Makefile +++ b/kafs/Makefile @@ -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 index 0000000..c5964b5 --- /dev/null +++ b/kafs/vos_listvldb.C @@ -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 +#include +#include +#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 ]" + * ARG: "[-server ]" + * ARG: "[-partition ]" + * ARG: "[-locked]" + * ARG: "[-quiet]" + * ARG: "[-nosort]" + * ARG: "[-cell ]" + * 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 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 + */ -- 2.49.0