From a0026161e3e8f1f30081671f9bb9a080e424f9e2 Mon Sep 17 00:00:00 2001 From: David Howells Date: Mon, 30 Sep 2019 10:13:00 +0100 Subject: [PATCH] Implement basic test of looking up the root.afs volume for a cell 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 --- lib/.gitignore | 1 + lib/Makefile | 11 +++- lib/vldb_test.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 lib/.gitignore create mode 100644 lib/vldb_test.c diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 0000000..88fe8a3 --- /dev/null +++ b/lib/.gitignore @@ -0,0 +1 @@ +vldb_test diff --git a/lib/Makefile b/lib/Makefile index e50daab..bcc2cab 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -10,7 +10,7 @@ LIB_OBJS := $(patsubst %.c,%.o,$(LIB_SRCS)) %.o: %.c $(CC) $(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) @@ -21,7 +21,16 @@ 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 +# +# [!] NOTE !!! DON'T USE RPATH!!! +# +vldb_test: vldb_test.o libkafs_utils.a + $(CC) -o $@ vldb_test.o -L. -lkafs_utils -lkafs_client -Wl,-rpath,$(PWD) + clean: $(RM) *~ *.o afs_xg.[ch] *.so *.a $(DEPS) + $(RM) vldb_test diff --git a/lib/vldb_test.c b/lib/vldb_test.c new file mode 100644 index 0000000..9520ce2 --- /dev/null +++ b/lib/vldb_test.c @@ -0,0 +1,144 @@ +/* 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 +#include +#include +#include +#include +#include +#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 rxrpc_local_endpoint *endpoint; + struct kafs_server_addr *ad; + struct kafs_server_list *vll; + struct kafs_server *vl; + struct kafs_cell *cell; + struct uvldbentry entry; + struct rxrpc_result result; + struct rxrpc_call_params params; + int i; + + struct kafs_lookup_context ctx = { + .report.error = error_report, + .report.verbose = verbose, + .report.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); + } + + memset(¶ms, 0, sizeof(params)); + 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 (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(¶ms.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(¶ms.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: + + endpoint = rxrpc_new_local_endpoint(NULL, 0); + if (!endpoint) { + perror("Local endpoint"); + exit(1); + } + + params.endpoint = endpoint; + params.upgrade_service = true; + if (!VL_GetEntryByNameU(¶ms, "root.cell", &entry, &result)) { + fprintf(stderr, "VL_GetEntryByNameU failed (abort %d): %m\n", + result.abort_code); + exit(1); + } + + printf("ENTRY: '%s'\n", entry.name); + + rxrpc_free_local_endpoint(endpoint); + exit(0); +} -- 2.50.1