]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
cmd: Implement "vos listvldb"
authorDavid Howells <dhowells@redhat.com>
Tue, 23 Jun 2020 17:12:09 +0000 (18:12 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 5 May 2023 09:05:31 +0000 (10:05 +0100)
Signed-off-by: David Howells <dhowells@redhat.com>
kafs/Makefile
kafs/kafs.h
kafs/vl_volumes.c
kafs/vos_listvldb.c [new file with mode: 0644]

index d1c5c99b70688c95cfee454edf0465bbe666077c..b8a1944ed8bf16290d689e97269cae672449ddad 100644 (file)
@@ -28,7 +28,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))
index f98fa21a2fac4c3e7d653ae22aae8ab893d01ccb..11f8b47ebb64432a7cb86de1e9ccb4f51bcc5159 100644 (file)
@@ -23,6 +23,7 @@
 #define FS_SERVICE             1       /* AFS File Service ID */
 #define VL_PORT                        7003    /* Volume location service port */
 #define VL_SERVICE             52      /* RxRPC service ID for the Volume Location service */
+#define YFS_VOL_SERVICE                2502    /* Service ID for AuriStor upgraded volume service */
 #define YFS_VL_SERVICE         2503    /* Service ID for AuriStor upgraded VL service */
 
 typedef unsigned long long kafs_volume_id_t;
index 9749d75e1263bb5faa6bffb7e00abf3004b8c862..b93886d7807f52977c092561157ec45a0c41cad5 100644 (file)
@@ -433,7 +433,7 @@ bool kafs_VL_ListAttributes(struct kafs_context *ctx,
 }
 
 /**
- * kafs_look_up_volume_by_name - Look up a volume by attributes and/or name pattern.
+ * kafs_look_up_volumes_by_attributes - Look up a volume by attributes and/or name pattern.
  * @ctx: The cell and authentication context
  * @fsspec: A fileserver address filter (or NULL)
  * @partition: A partition filter (or NULL)
@@ -448,12 +448,12 @@ bool kafs_VL_ListAttributes(struct kafs_context *ctx,
  * If successful, the resulting records are appended to the list.  These
  * records may be cached locally.
  */
-bool kafs_look_up_vlist_by_attributes(struct kafs_context *ctx,
-                                     struct kafs_fileserver_spec *fsspec,
-                                     struct kafs_partition *partition,
-                                     bool locked,
-                                     const char *volume_name_pattern,
-                                     struct kafs_vldb_entry_list *vlist)
+bool kafs_look_up_volumes_by_attributes(struct kafs_context *ctx,
+                                       struct kafs_fileserver_spec *fsspec,
+                                       struct kafs_partition *partition,
+                                       bool locked,
+                                       const char *volume_name_pattern,
+                                       struct kafs_vldb_entry_list *vlist)
 {
        struct VldbListByAttributes attr = { .Mask = 0 };
        struct sockaddr_in *sin;
diff --git a/kafs/vos_listvldb.c b/kafs/vos_listvldb.c
new file mode 100644 (file)
index 0000000..f0afc4c
--- /dev/null
@@ -0,0 +1,120 @@
+/* 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 <stdio.h>
+#include <string.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include "kafs.h"
+#include "vlservice.h"
+#include "afs_xg.h"
+#include "display.h"
+
+static void kafs_print_vl_record(struct kafs_context *ctx,
+                                struct kafs_vldb_entry *vldb)
+{
+       unsigned int flags;
+
+       printf("%s\n", vldb->name);
+       printf("   ");
+       flags = vldb->flags;
+       if (flags & VLF_RWEXISTS)   printf(" RWrite: %-12llu", vldb->volume_id[0]);
+       if (flags & VLF_ROEXISTS)   printf(" ROnly: %-12llu",  vldb->volume_id[1]);
+       if (flags & VLF_BACKEXISTS) printf(" Backup: %-12llu", vldb->volume_id[2]);
+       printf("\n");
+       kafs_display_vldb_site_list(ctx, vldb, "    ");
+       printf("\n");
+}
+
+static int kafs_cmp_entries_by_name(const void *_a, const void *_b)
+{
+       struct kafs_vldb_entry *const *a = _a, *const *b = _b;
+
+       return strcmp((*a)->name, (*b)->name);
+}
+
+/***
+ * COMMAND: vos listvldb - Query the VLDB
+ * ARG: "[-name <volume name>]"
+ * ARG: "[-server <machine name>]"
+ * ARG: "[-partition <partition name>]"
+ * ARG: "[-locked]"
+ * ARG: "[-quiet]"
+ * ARG: "[-nosort]"
+ * ARG: "[-cell <cell name>]"
+ * 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
+ */
+bool COMMAND_vos_listvldb(
+       struct kafs_context             *ctx,
+       struct kafs_volume_spec         *a_name,
+       struct kafs_fileserver_spec     *a_server,
+       struct kafs_partition           *a_partition,
+       bool                            a_locked,
+       bool                            a_quiet,
+       bool                            a_nosort,
+       bool                            a_verbose,
+       bool                            a_noresolve)
+{
+       struct kafs_vldb_entry_list vlist = {};
+       int i;
+
+       _enter("");
+
+       ctx->no_resolve = a_noresolve;
+
+       if (!kafs_open_vl_service(ctx))
+               return false;
+
+       if (a_name &&
+           !a_server &&
+           !a_partition &&
+           !a_locked &&
+           !strchr(a_name->name, '*')) {
+               if (!kafs_look_up_volume_by_name(ctx, a_name, &vlist))
+                       return false;
+               kafs_print_vl_record(ctx, vlist.entries[0]);
+       } else {
+               if (!kafs_look_up_volumes_by_attributes(ctx, a_server,
+                                                       a_partition, a_locked,
+                                                       a_name ? a_name->name : NULL,
+                                                       &vlist))
+                       return false;
+               if (!a_quiet && a_server)
+                       printf("VLDB entries for server %s\n", a_server->name);
+
+               if (!a_nosort)
+                       qsort(vlist.entries, vlist.nr_entries,
+                             sizeof(vlist.entries[0]),
+                             kafs_cmp_entries_by_name);
+
+               for (i = 0; i < vlist.nr_entries; i++)
+                       kafs_print_vl_record(ctx, vlist.entries[i]);
+               if (!a_quiet)
+                       printf("Total entries: %u\n", vlist.nr_entries);
+       }
+
+       clear_kafs_vldb_entry_list(&vlist);
+       _leave(" = t");
+       return true;
+}
+
+/***
+ * ALIAS: vos listloc - listvldb
+ */