]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Implement "vos partinfo"
authorDavid Howells <dhowells@redhat.com>
Thu, 13 Aug 2020 15:30:25 +0000 (16:30 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 5 May 2023 10:53:26 +0000 (11:53 +0100)
Signed-off-by: David Howells <dhowells@redhat.com>
kafs/Makefile
kafs/vol_query.C
kafs/volservice.H
kafs/vos_partinfo.C [new file with mode: 0644]

index 9bbd49ecd5f80c822b8281caee91edf941bda15d..2c52d0f37b982d723a395662520acc4b650f55c8 100644 (file)
@@ -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))
index 1ab47502033ec40ea1e30462934d956de9326235..da2f9391182e40dc36da52a94c4b1618b68be813 100644 (file)
@@ -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;
+       }
+}
index 2412c1f86e402d0c6d4df6859dddcf269c11888d..8039144b8cb5684b559820ef33ecb92f55b15b42 100644 (file)
@@ -112,6 +112,18 @@ struct Volume_info {
 
 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.
  */
@@ -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 (file)
index 0000000..fd25da9
--- /dev/null
@@ -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 <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));
+               }
+       }
+}