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;
+ }
+}
typedef std::vector<Volume_info> 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.
*/
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 */
--- /dev/null
+/* 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 <fmt/core.h>
+#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 <machine name>"
+ * ARG: "[-partition <machine name>]"
+ * ARG: "[-summary]"
+ * ARG: "[-cell <cell name>]"
+ * 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<kafs::Volserver> server;
+ ref<kafs::FS_site> 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));
+ }
+ }
+}