From ddafdb21ab22f943abd8c65aca708467061799c5 Mon Sep 17 00:00:00 2001 From: David Howells Date: Tue, 23 Jun 2020 18:12:09 +0100 Subject: [PATCH] cmd: Implement "vos listvldb" Signed-off-by: David Howells --- kafs/Makefile | 3 +- kafs/kafs.h | 1 + kafs/vl_volumes.c | 14 +++--- kafs/vos_listvldb.c | 120 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 kafs/vos_listvldb.c diff --git a/kafs/Makefile b/kafs/Makefile index d1c5c99..b8a1944 100644 --- a/kafs/Makefile +++ b/kafs/Makefile @@ -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)) diff --git a/kafs/kafs.h b/kafs/kafs.h index f98fa21..11f8b47 100644 --- a/kafs/kafs.h +++ b/kafs/kafs.h @@ -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; diff --git a/kafs/vl_volumes.c b/kafs/vl_volumes.c index 9749d75..b93886d 100644 --- a/kafs/vl_volumes.c +++ b/kafs/vl_volumes.c @@ -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 index 0000000..f0afc4c --- /dev/null +++ b/kafs/vos_listvldb.c @@ -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 +#include +#include +#include +#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 ]" + * ARG: "[-server ]" + * ARG: "[-partition ]" + * ARG: "[-locked]" + * ARG: "[-quiet]" + * ARG: "[-nosort]" + * ARG: "[-cell ]" + * 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 + */ -- 2.50.1