All of lore.kernel.org
 help / color / mirror / Atom feed
From: Knut Omang <knut.omang@oracle.com>
To: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org,
	Shuah Khan <shuah@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Michal Marek <michal.lkml@markovi.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Shreyans Devendra Doshi <0xinfosect0r@gmail.com>,
	Alan Maguire <alan.maguire@oracle.com>,
	Brendan Higgins <brendanhiggins@google.com>,
	Kevin Hilman <khilman@baylibre.com>,
	Hidenori Yamaji <hidenori.yamaji@sony.com>,
	Frank Rowand <frowand.list@gmail.com>,
	Timothy Bird <Tim.Bird@sony.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	"Theodore Ts'o" <tytso@mit.edu>, Daniel Vetter <daniel@ffwll.ch>,
	Stephen Boyd <sboyd@kernel.org>,
	Knut Omang <knut.omang@oracle.com>
Subject: [RFC 08/19] ktf: Configurable context support for network info setup
Date: Tue, 13 Aug 2019 08:09:23 +0200	[thread overview]
Message-ID: <ddf9f91c347d1c731b4cceea318783bb293676c3.1565676440.git-series.knut.omang@oracle.com> (raw)
In-Reply-To: <cover.92d76bb4f6dcedc971d0b72a49e8e459a98bca54.1565676440.git-series.knut.omang@oracle.com>

An implementation of configurable contexts for exchanging network
information, to make it easier to run network tests potentially
involving more than one kernel.

ktf_netctx.h:    Configurable context setup for multinode network tests

Signed-off-by: Knut Omang <knut.omang@oracle.com>
---
 tools/testing/selftests/ktf/kernel/ktf_netctx.c | 132 +++++++++++++++++-
 tools/testing/selftests/ktf/kernel/ktf_netctx.h |  64 ++++++++-
 2 files changed, 196 insertions(+)
 create mode 100644 tools/testing/selftests/ktf/kernel/ktf_netctx.c
 create mode 100644 tools/testing/selftests/ktf/kernel/ktf_netctx.h

diff --git a/tools/testing/selftests/ktf/kernel/ktf_netctx.c b/tools/testing/selftests/ktf/kernel/ktf_netctx.c
new file mode 100644
index 0000000..84ef6ac
--- /dev/null
+++ b/tools/testing/selftests/ktf/kernel/ktf_netctx.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ *    Author: Knut Omang <knut.omang@oracle.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * ktf_netcfg.h: Configurable context setup for multinode network tests
+ *
+ */
+
+#include "ktf.h"
+#include "ktf_netctx.h"
+#include <linux/in.h>
+
+/* Configuration callback to configure a network context */
+
+int ktf_netctx_cb(struct ktf_context *ctx, const void *data, size_t data_sz)
+{
+	struct ktf_netctx *nc = container_of(ctx, struct ktf_netctx, k);
+	struct ktf_addrinfo *kai = (struct ktf_addrinfo *)data;
+	short n = kai->n;
+	size_t param_sz;
+
+	if (n < 2) {
+		terr("Unsupported number of nodes (%d) - must be at least 2", n);
+		return -EINVAL;
+	}
+
+	param_sz = sizeof(*kai) + sizeof(kai->a) * (n - 2);
+
+	if (n > nc->max_nodes || n < nc->min_nodes) {
+		terr("Unsupported number of nodes (%d) - must be between %d and %d!",
+		     n, nc->min_nodes, nc->max_nodes);
+		return -EINVAL;
+	}
+
+	if (param_sz != data_sz) {
+		terr("Expected %lu bytes of parameter data, received %lu!",
+		     param_sz, data_sz);
+		return -EINVAL;
+	}
+
+	if (nc->a && nc->a_sz != data_sz) {
+		kfree(nc->a);
+		nc->a = NULL;
+	}
+
+	if (!nc->a) {
+		nc->a = kzalloc(data_sz, GFP_KERNEL);
+		if (!nc->a)
+			return -ENOMEM;
+	}
+
+	memcpy(nc->a, kai, data_sz);
+	return 0;
+}
+EXPORT_SYMBOL(ktf_netctx_cb);
+
+void ktf_netctx_cleanup(struct ktf_context *ctx)
+{
+	struct ktf_netctx *nc = container_of(ctx, struct ktf_netctx, k);
+
+	kfree(nc->a);
+}
+EXPORT_SYMBOL(ktf_netctx_cleanup);
+
+/* Make network contexts dynamically allocatable from user mode
+ * Caller must supply desired values for callback functions in @nct.
+ */
+int ktf_netctx_enable(struct ktf_handle *handle, struct ktf_netctx_type *nct,
+		      short min_nodes, short max_nodes)
+{
+	struct ktf_context *lo_ctx;
+	struct ktf_addrinfo ai = {
+		.n = 2,
+		.rank = 0
+	};
+	int ret;
+	int i;
+
+	ret = ktf_handle_add_ctx_type(handle, &nct->t);
+	if (ret)
+		return ret;
+
+	nct->min_nodes = min_nodes;
+	nct->max_nodes = max_nodes;
+	strcpy(nct->t.name, "netctx");
+
+	for (i = 0; i < 2; i++) {
+		struct sockaddr_in *ai_in = (struct sockaddr_in *)&ai.a[i].addr;
+
+		ai.a[i].addr.ss_family = AF_INET;
+		strcpy(ai.a[i].ifname, "lo");
+		ai_in->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+	}
+
+	/* create and configure the loopback network context */
+	lo_ctx = ktf_context_add_from(handle, "lo", &nct->t);
+	if (!lo_ctx)
+		return -ENOMEM;
+
+	ret = ktf_context_set_config(lo_ctx, &ai, sizeof(ai));
+	if (ret)
+		return ret;
+
+	return 0;
+}
+EXPORT_SYMBOL(ktf_netctx_enable);
+
+struct sockaddr_storage *ktf_netctx_addr(struct ktf_netctx *ctx, short rank)
+{
+	return &ctx->a->a[rank].addr;
+}
+EXPORT_SYMBOL(ktf_netctx_addr);
+
+const char *ktf_netctx_ifname(struct ktf_netctx *ctx, short rank)
+{
+	return ctx->a->a[rank].ifname;
+}
+EXPORT_SYMBOL(ktf_netctx_ifname);
+
+short ktf_netctx_rank(struct ktf_netctx *ctx)
+{
+	return ctx->a->rank;
+}
+EXPORT_SYMBOL(ktf_netctx_rank);
+
+short ktf_netctx_n(struct ktf_netctx *ctx)
+{
+	return ctx->a->n;
+}
+EXPORT_SYMBOL(ktf_netctx_n);
diff --git a/tools/testing/selftests/ktf/kernel/ktf_netctx.h b/tools/testing/selftests/ktf/kernel/ktf_netctx.h
new file mode 100644
index 0000000..414c744
--- /dev/null
+++ b/tools/testing/selftests/ktf/kernel/ktf_netctx.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ *    Author: Knut Omang <knut.omang@oracle.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * ktf_netctx.h: Configurable context setup for multinode network tests
+ *
+ * KTF implements handling on the kernel side for this but leaves
+ * user space implementation to construct the corresponding
+ * stuct ktf_addrinfo parameter block
+ */
+
+#ifndef _KTF_NETCTX_H
+#define _KTF_NETCTX_H
+
+/* KTF matches against this type id as a possible discriminator: */
+#define KTF_NETCTX_TYPE_ID 0x2222
+
+#define IFNAMSZ 16
+
+struct ktf_peer_address
+{
+	struct sockaddr_storage addr; /* Address to use for this peer */
+	char ifname[IFNAMSZ];	    /* Local name of the interface with this address at peer */
+};
+
+struct ktf_addrinfo
+{
+	short n;		    /* Number of nodes involved, including the local */
+	short rank;		    /* Index into ktf_peer_address that corresponds to local host */
+	struct ktf_peer_address a[2]; /* KTF expects size n instead of 2 here */
+};
+
+#ifdef __KERNEL__
+
+struct ktf_netctx {
+	struct ktf_context k;
+	struct ktf_addrinfo *a; /* Addr.info dyn.allocated based on incoming data */
+	size_t a_sz;		/* Size of the allocation in a, if any */
+	short min_nodes;	/* Minimum number of nodes for this context */
+	short max_nodes;	/* Maximum number of nodes this context supports */
+};
+
+struct ktf_netctx_type {
+	struct ktf_context_type t;
+	short min_nodes;	/* Minimum number of nodes for the context type */
+	short max_nodes;	/* Maximum number of nodes for the context type */
+};
+
+int ktf_netctx_enable(struct ktf_handle *handle, struct ktf_netctx_type *nct,
+		      short min_nodes, short max_nodes);
+
+int ktf_netctx_cb(struct ktf_context *ctx, const void *data, size_t data_sz);
+void ktf_netctx_cleanup(struct ktf_context *ctx);
+
+struct sockaddr_storage *ktf_netctx_addr(struct ktf_netctx *ctx, short rank);
+const char *ktf_netctx_ifname(struct ktf_netctx *ctx, short rank);
+short ktf_netctx_rank(struct ktf_netctx *ctx);
+short ktf_netctx_n(struct ktf_netctx *ctx);
+
+#endif
+
+#endif
-- 
git-series 0.9.1

  parent reply	other threads:[~2019-08-13  6:11 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-13  6:09 [RFC 00/19] Integration of Kernel Test Framework (KTF) into the kernel tree Knut Omang
2019-08-13  6:09 ` [RFC 01/19] kbuild: Fixes to rules for host-cshlib and host-cxxshlib Knut Omang
2019-08-13 14:01   ` Masahiro Yamada
2019-08-13 14:01     ` Masahiro Yamada
2019-08-13 16:19     ` Knut Omang
2019-08-13 16:19       ` Knut Omang
2019-08-14  2:02       ` Masahiro Yamada
2019-08-14  2:02         ` Masahiro Yamada
2019-08-14  5:50         ` Knut Omang
2019-08-14  5:50           ` Knut Omang
2019-08-14  5:52         ` Knut Omang
2019-08-14  5:52           ` Knut Omang
2019-08-14 12:52           ` Knut Omang
2019-08-14 12:52             ` Knut Omang
2019-08-21  1:47             ` Masahiro Yamada
2019-08-21  1:47               ` Masahiro Yamada
2019-08-21  4:03               ` Knut Omang
2019-08-21  4:03                 ` Knut Omang
2019-08-13  6:09 ` [RFC 02/19] ktf: Introduce the main part of the kernel side of ktf Knut Omang
2019-09-09  1:23   ` Brendan Higgins
2019-09-10  6:15     ` Knut Omang
2019-08-13  6:09 ` [RFC 03/19] ktf: Introduce a generic netlink protocol for test result communication Knut Omang
2019-09-09  1:28   ` Brendan Higgins
2019-09-10  6:30     ` Knut Omang
2019-08-13  6:09 ` [RFC 04/19] ktf: An implementation of a generic associative array container Knut Omang
2019-08-13  6:09 ` [RFC 05/19] ktf: Implementation of ktf support for overriding function entry and return Knut Omang
2019-08-13  6:09 ` [RFC 06/19] ktf: A simple debugfs interface to test results Knut Omang
2019-08-13  8:21   ` Greg Kroah-Hartman
2019-08-14 17:17     ` Knut Omang
2019-08-15  8:49       ` Greg Kroah-Hartman
2019-08-15 10:35         ` Knut Omang
2019-08-15 10:52           ` Greg Kroah-Hartman
2019-08-13  6:09 ` [RFC 07/19] ktf: Simple coverage support Knut Omang
2019-08-13  6:09 ` Knut Omang [this message]
2019-08-13  6:09 ` [RFC 09/19] ktf: resolve: A helper utility to aid in exposing private kernel symbols to KTF tests Knut Omang
2019-08-13  6:09 ` [RFC 10/19] ktf: Add documentation for Kernel Test Framework (KTF) Knut Omang
2019-08-13  6:09 ` [RFC 11/19] ktf: Add a small test suite with a few tests to test KTF itself Knut Omang
2019-08-13  6:09 ` [RFC 12/19] ktf: Main part of user land library for executing tests Knut Omang
2019-08-13  6:09 ` [RFC 13/19] ktf: Integration logic for running ktf tests from googletest Knut Omang
2019-08-13  6:09 ` [RFC 14/19] ktf: Internal debugging facilities Knut Omang
2019-08-13  6:09 ` [RFC 15/19] ktf: Some simple examples Knut Omang
2019-08-13  6:09 ` [RFC 16/19] ktf: Some user applications to run tests Knut Omang
2019-08-13  6:09 ` [RFC 17/19] ktf: Toplevel ktf Makefile/makefile includes and scripts to run from kselftest Knut Omang
2019-08-13  6:09 ` [RFC 18/19] kselftests: Enable building ktf Knut Omang
2019-08-13  6:09 ` [RFC 19/19] Documentation/dev-tools: Add index entry for KTF documentation Knut Omang
2019-08-13  8:10 ` [RFC 00/19] Integration of Kernel Test Framework (KTF) into the kernel tree Brendan Higgins
2019-08-13  8:10   ` Brendan Higgins
2019-08-13  8:17 ` Brendan Higgins
2019-08-13  8:17   ` Brendan Higgins
2019-08-13 11:29   ` Knut Omang
2019-08-13 11:29     ` Knut Omang
2019-08-13 17:50     ` Brendan Higgins
2019-08-13 17:50       ` Brendan Higgins
2019-08-13  8:23 ` Greg Kroah-Hartman
2019-08-13  9:51   ` Knut Omang
2019-08-13 17:02     ` Brendan Higgins
2019-08-13 17:02       ` Brendan Higgins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ddf9f91c347d1c731b4cceea318783bb293676c3.1565676440.git-series.knut.omang@oracle.com \
    --to=knut.omang@oracle.com \
    --cc=0xinfosect0r@gmail.com \
    --cc=Tim.Bird@sony.com \
    --cc=alan.maguire@oracle.com \
    --cc=brendanhiggins@google.com \
    --cc=corbet@lwn.net \
    --cc=daniel@ffwll.ch \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hidenori.yamaji@sony.com \
    --cc=khilman@baylibre.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=sboyd@kernel.org \
    --cc=shuah@kernel.org \
    --cc=tytso@mit.edu \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.