From 200a46b76c4db0c831c8688af35dc92445e38c61 Mon Sep 17 00:00:00 2001 From: David Howells Date: Mon, 6 Jul 2020 10:37:26 +0100 Subject: [PATCH] Implement "vos status" Signed-off-by: David Howells --- kafs/Makefile | 3 +- kafs/vos_status.C | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 kafs/vos_status.C diff --git a/kafs/Makefile b/kafs/Makefile index 95973a2..5dcad56 100644 --- a/kafs/Makefile +++ b/kafs/Makefile @@ -33,7 +33,8 @@ PTS_SRCS := \ VOS_SRCS := \ vos.C \ vos_help.C \ - vos_listvldb.C + vos_listvldb.C \ + vos_status.C CORE_OBJS := $(patsubst %.C,%.o,$(CORE_SRCS)) BOS_OBJS := $(patsubst %.C,%.o,$(BOS_SRCS)) diff --git a/kafs/vos_status.C b/kafs/vos_status.C new file mode 100644 index 0000000..2ef51ae --- /dev/null +++ b/kafs/vos_status.C @@ -0,0 +1,92 @@ +/* The "vos status" 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 "kafs.H" +#include "arg_parse.H" +#include "volservice.H" +#include "afs_xg.H" +#include "display.H" +#include + +using rxrpc::ref; + +static void dump_transactions(kafs::Vol_transaction_info_list &transactions) +{ + fmt::print("--------------------------------------------\n"); + for (unsigned int i = 0; i < transactions.size(); i++) { + kafs::Vol_transaction_info &trans = transactions[i]; + std::string attach_mode; + unsigned int iflags = trans.iflags; + + fmt::print("transaction: {:d} created: {:s}\n", + trans.tid, kafs::sprint_time(trans.creation_time)); + fmt::print("lastActiveTime: {}\n", kafs::sprint_time(trans.time)); + if (iflags & kafs::afs::ITOffline) + attach_mode = "offline"; + else if (iflags & kafs::afs::ITBusy) + attach_mode = "busy"; + else if (iflags & kafs::afs::ITReadOnly) + attach_mode = "readonly"; + else if (iflags & kafs::afs::ITCreate) + attach_mode = "create"; + else if (iflags & kafs::afs::ITCreateVolID) + attach_mode = "createvolid"; + else + attach_mode = fmt::format("{:d}", trans.iflags); + fmt::print("attachFlags: {}\n", attach_mode); + fmt::print("volume: {:d} partition {:s} procedure {:s}", + trans.volid, + kafs::sprint_partition(trans.partition), + trans.last_proc_name); + fmt::print("packetRead: {} lastReceiveTime: {} packetSend: {}\n", + trans.read_next, + trans.last_receive_time.seconds(), + trans.transmit_next); + fmt::print(" lastSendTime: ", trans.last_send_time.seconds(), "\n"); + fmt::print("--------------------------------------------\n"); + } +} + +/*** + * COMMAND: vos status - Report a volume server's status + * ARG: "-server " + * ARG: "[-cell ]" + * ARG: "[-noauth]" - Auth + * ARG: "[-localauth]" - Auth + * ARG: "[-verbose]" + * ARG: "[-encrypt]" - Auth + * ARG: "[-noresolve]" + * + * Report a volume server's status + */ +void COMMAND_vos_status( + kafs::Context *ctx, + kafs::Volserver_spec &a_server, + bool a_verbose, + bool a_noresolve) +{ + kafs::Vol_transaction_info_list transactions; + ref server; + ref site; + + _enter(""); + + ctx->no_resolve = a_noresolve; + + site = kafs::resolve_server_spec(ctx, a_server); + server = new kafs::Volserver(ctx, site); + server->vol_monitor_transaction(transactions); + + if (transactions.size() == 0) + fmt::print("No active transactions on {}\n", server->name()); + else + dump_transactions(transactions); +} -- 2.50.1