]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Implement basic test of looking up the root.afs volume for a cell
authorDavid Howells <dhowells@redhat.com>
Mon, 30 Sep 2019 09:13:00 +0000 (10:13 +0100)
committerDavid Howells <dhowells@redhat.com>
Fri, 5 May 2023 09:06:50 +0000 (10:06 +0100)
Implement basic test of looking up the root.afs volume for a cell, using
kafs_client to find the cell.

Signed-off-by: David Howells <dhowells@redhat.com>
lib/.gitignore [new file with mode: 0644]
lib/Makefile
lib/vldb_test.C [new file with mode: 0644]

diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644 (file)
index 0000000..88fe8a3
--- /dev/null
@@ -0,0 +1 @@
+vldb_test
index 8228645f45a798143c8df6a56fa6c87addef5546..b7dd23448fe9a6829f2d6979c55f9d7ee04441c0 100644 (file)
@@ -1,8 +1,9 @@
-CFLAGS         := -g -Wall -Wformat -fpic -O2 -Wno-pointer-arith
+CFLAGS         := -g -Wall -Wformat -fpic -Wno-pointer-arith
 
 RXGEN          := ../rxgen/rxgen.py
 RPC_HEADERS    := $(wildcard ../rpc-api/*.h)
 RPC_DEFS       := $(filter-out %test.xg, $(sort $(wildcard ../rpc-api/*.xg)))
+
 #RPC_HEADERS   := ../rpc-api/test.h
 #RPC_DEFS      := ../rpc-api/test.xg
 
@@ -12,7 +13,7 @@ LIB_OBJS      := $(patsubst %.C,%.o,$(LIB_SRCS))
 %.o: %.C
        $(CXX) $(CPPFLAGS) -MMD -MF .$@.d $(CFLAGS) -o $@ -c $<
 
-all: libkafs_utils.a
+all: libkafs_utils.a vldb_test
 
 libkafs_utils.a: $(LIB_OBJS)
        $(AR) rcs -o $@ $(LIB_OBJS)
@@ -25,7 +26,13 @@ afs_xg.C afs_xg.H: $(RPC_HEADERS) $(RPC_DEFS) $(wildcard ../rxgen/*.py) Makefile
 DEPS           := $(wildcard .*.o.d)
 ifneq ($(DEPS),)
 include $(DEPS)
+else
+vldb_test.o $(LIB_OBJS): afs_xg.H
 endif
 
+vldb_test: vldb_test.o libkafs_utils.a
+       $(CXX) -o $@ vldb_test.o -L. -lkafs_utils -lkafs_client -lfmt
+
 clean:
        $(RM) *~ afs_xg.[CH] *.o *.so *.a $(DEPS)
+       $(RM) vldb_test
diff --git a/lib/vldb_test.C b/lib/vldb_test.C
new file mode 100644 (file)
index 0000000..a41d413
--- /dev/null
@@ -0,0 +1,152 @@
+/* VLDB query test
+ *
+ * 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 <iostream>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cerrno>
+extern "C" {
+#include <kafs/cellserv.h>
+}
+#include "rxrpc.H"
+#include "afs_xg.H"
+
+#define AFS_VL_PORT            7003    /* volume location service port */
+#define VL_SERVICE             52      /* RxRPC service ID for the Volume Location service */
+#define YFS_VL_SERVICE         2503    /* Service ID for AuriStor upgraded VL service */
+
+static void error_report(const char *fmt, ...)
+{
+       va_list va;
+
+       va_start(va, fmt);
+       vfprintf(stderr, fmt, va);
+       fputc('\n', stderr);
+       va_end(va);
+}
+
+static void verbose(const char *fmt, ...)
+{
+       va_list va;
+
+       va_start(va, fmt);
+       //printf("[V] ");
+       //vprintf(fmt, va);
+       //putchar('\n');
+       va_end(va);
+}
+
+int main(int argc, char *argv[])
+{
+       struct kafs_server_addr *ad;
+       struct kafs_server_list *vll;
+       struct kafs_server *vl;
+       struct kafs_cell *cell;
+       kafs::afs::uvldbentry entry;
+       rxrpc::Call_params params;
+
+       struct kafs_lookup_context ctx = {
+               .report = {
+                       .error          = error_report,
+                       .verbose        = verbose,
+                       .verbose2       = verbose,
+               },
+               .want_ipv4_addrs        = true,
+               .want_ipv6_addrs        = true,
+       };
+
+       if (argc < 2) {
+               fprintf(stderr, "No cell specified\n");
+               exit(2);
+       }
+
+       if (kafs_init_lookup_context(&ctx) < 0)
+               exit(1);
+
+       if (kafs_read_config(NULL, &ctx.report) < 0)
+               exit(ctx.report.bad_config ? 3 : 1);
+
+       cell = kafs_lookup_cell(argv[1], &ctx);
+       if (!cell) {
+               fprintf(stderr, "%s: Unknown cell\n", argv[1]);
+               exit(1);
+       }
+
+       vll = cell->vlservers;
+       if (vll->nr_servers == 0) {
+               fprintf(stderr, "%s: No VL servers\n", argv[1]);
+               exit(1);
+       }
+
+       params.peer.srx_family = AF_RXRPC;
+       params.peer.srx_service = VL_SERVICE;
+       params.peer.transport_type = SOCK_DGRAM;
+       params.peer_len = sizeof(params.peer);
+
+       for (unsigned int i = 0; i < vll->nr_servers; i++) {
+               vl = &vll->servers[i];
+               printf("VL: %s %u\n", vl->name, vl->nr_addrs);
+               if (!vl->nr_addrs)
+                       continue;
+
+               ad = &vl->addrs[0];
+               switch (ad->sin.sin_family) {
+               case AF_INET:
+                       params.peer.transport_len = sizeof(params.peer.transport.sin);
+                       memcpy(&params.peer.transport, &ad->sin, params.peer.transport_len);
+                       if (!params.peer.transport.sin.sin_port)
+                               params.peer.transport.sin.sin_port = htons(AFS_VL_PORT);
+                       break;
+               case AF_INET6:
+                       params.peer.transport_len = sizeof(params.peer.transport.sin6);
+                       memcpy(&params.peer.transport, &ad->sin6, params.peer.transport_len);
+                       if (!params.peer.transport.sin6.sin6_port)
+                               params.peer.transport.sin6.sin6_port = htons(AFS_VL_PORT);
+                       break;
+               default:
+                       fprintf(stderr, "%s: Unsupported address family\n", argv[1]);
+                       exit(1);
+               }
+               goto found;
+       }
+
+       fprintf(stderr, "%s: No VL addresses\n", argv[1]);
+       exit(1);
+found:
+
+       try {
+               rxrpc::find_transport();
+               rxrpc::ref<rxrpc::Endpoint> endpoint = rxrpc::new_local_endpoint(NULL);
+
+               params.endpoint = endpoint;
+               params.upgrade_service = true;
+               kafs::afs::VL::GetEntryByNameU(&params, "root.cell", entry);
+               printf("ENTRY: '%s'\n", entry.name);
+               exit(0);
+       } catch (const rxrpc::rx_abort &ab) {
+               std::cerr << ab.what() << " (" << ab.get_abort_code() << ")\n";
+               exit(1);
+       } catch (const rxrpc::network_error &e) {
+               std::cerr << "Network failure: " << e.what() << "\n";
+               exit(1);
+       } catch (const rxrpc::syserror &e) {
+               std::cerr << "Local failure: " << e.what() << "\n";
+               exit(1);
+       } catch (const std::runtime_error &a) {
+               std::cerr << a.what() << "\n";
+               exit(1);
+       } catch (const std::invalid_argument &a) {
+               std::cerr << a.what() << "\n";
+               exit(2);
+       }
+}