From: David Howells Date: Thu, 13 Aug 2020 15:30:25 +0000 (+0100) Subject: Implement "vos partinfo" X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=53980c03d9cf0cc27d88d1540a2247716d900e37;p=users%2Fdhowells%2Fkafs-utils.git Implement "vos partinfo" Signed-off-by: David Howells --- diff --git a/kafs/Makefile b/kafs/Makefile index 9bbd49e..2c52d0f 100644 --- a/kafs/Makefile +++ b/kafs/Makefile @@ -38,6 +38,7 @@ VOS_SRCS := \ vos_listpart.C \ vos_listvldb.C \ vos_listvol.C \ + vos_partinfo.C \ vos_status.C CORE_OBJS := $(patsubst %.C,%.o,$(CORE_SRCS)) diff --git a/kafs/vol_query.C b/kafs/vol_query.C index 1ab4750..da2f939 100644 --- a/kafs/vol_query.C +++ b/kafs/vol_query.C @@ -365,3 +365,43 @@ void Volserver::list_partitions(Partition_list &partitions) for (i = 0; i < ents.size(); i++) partitions[i].id = ents[i]; } + +/** + * Volserver::query_partition_info - Get partition information. + * @name: The name of the partition + * @partition: Where to store the partition information. + * + * Query a volume server for information on a partition by name. + */ +void Volserver::query_partition_info(const std::string &name, + Partition_info &partition) +{ + try { + afs::diskPartition64v2 part; + + afs::YFSVOL::PartitionInfo64v2(&vs_params, name, part); + partition.name = part.name; + partition.dev_name = part.devName; + partition.locked = part.locked; + partition.total_usable = part.totalUsable; + partition.free = part.free; + partition.min_free = part.minFree; + return; + + } catch (const rxrpc::AbortRXGEN_OPCODE &) { + goto fallback_PI; + } + +fallback_PI: + { + afs::diskPartition part; + + afs::VOLSER::PartitionInfo(&vs_params, name, part); + partition.name = part.name; + partition.dev_name = part.devName; + partition.locked = part.lock_fd; + partition.total_usable = part.totalUsable; + partition.free = part.free; + partition.min_free = part.minFree; + } +} diff --git a/kafs/volservice.H b/kafs/volservice.H index 2412c1f..8039144 100644 --- a/kafs/volservice.H +++ b/kafs/volservice.H @@ -112,6 +112,18 @@ struct Volume_info { typedef std::vector Volume_info_list; +/* + * Disk partition information. + */ +struct Partition_info { + std::string name; + std::string dev_name; + unsigned int locked; + unsigned long long total_usable; + unsigned long long free; + unsigned long long min_free; +}; + /* * List of partitions. */ @@ -156,6 +168,7 @@ public: void query_volume_state(Partition_spec &, Volume_id, bool, Volume_info_list &); void query_volume_states(Partition_spec &, bool, Volume_info_list &); + void query_partition_info(const std::string &, Partition_info &); }; } /* end namespace kafs */ diff --git a/kafs/vos_partinfo.C b/kafs/vos_partinfo.C new file mode 100644 index 0000000..fd25da9 --- /dev/null +++ b/kafs/vos_partinfo.C @@ -0,0 +1,77 @@ +/* The "vos partinfo" 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 "kafs.H" +#include "volservice.H" +#include "arg_parse.H" +#include "display.H" +#include "afs_xg.H" + +using rxrpc::ref; + +/*** + * COMMAND: vos partinfo - Report the available and total space on a partition + * ARG: "-server " + * ARG: "[-partition ]" + * ARG: "[-summary]" + * ARG: "[-cell ]" + * ARG: "[-noauth]" - Auth + * ARG: "[-localauth]" - Auth + * ARG: "[-verbose]" + * ARG: "[-encrypt]" - Auth + * ARG: "[-noresolve]" + * + * Report the available and total space on a partition + */ +void COMMAND_vos_partinfo( + kafs::Context *ctx, + kafs::Volserver_spec &a_server, + kafs::Partition_spec &a_partition, + bool a_summary, + bool a_verbose, + bool a_noresolve) +{ + kafs::Partition_list partitions; + ref server; + ref site; + unsigned int i; + + _enter(""); + + ctx->no_resolve = a_noresolve; + + site = kafs::resolve_server_spec(ctx, a_server); + server = new kafs::Volserver(ctx, site); + + if (a_partition.specified) + partitions.push_back(a_partition); + else + server->list_partitions(partitions); + + for (i = 0; i < partitions.size(); i++) { + if (partitions[i].id == 0xffffffff) + continue; + + std::string name = kafs::sprint_partition(partitions[i]); + + try { + kafs::Partition_info part; + + server->query_partition_info(name, part); + fmt::print("Free space on partition {}: {} K blocks out of total {}\n", + part.name, part.free, part.total_usable); + } catch (const kafs::afs::VOLSER::AbortVOLSERILLEGAL_PARTITION &a) { + throw std::runtime_error( + fmt::format("partition {} does not exist on the server", name)); + } + } +}