%if %{with lustre_tests}
mkdir -p $basemodpath-tests/fs
mv $basemodpath/fs/llog_test.ko $basemodpath-tests/fs/llog_test.ko
+mv $basemodpath/fs/obd_test.ko $basemodpath-tests/fs/obd_test.ko
mkdir -p $RPM_BUILD_ROOT%{_libdir}/lustre/tests/kernel/
mv $basemodpath/fs/kinode.ko $RPM_BUILD_ROOT%{_libdir}/lustre/tests/kernel/
%endif
-MODULES := obdclass llog_test
+# SPDX-License-Identifier: GPL-2.0
+
+#
+# This file is part of Lustre, http://www.lustre.org/
+#
+# lustre/obdclass/Makefile.in
+#
+# Makefile template for obdclass
+#
+
+MODULES := obdclass llog_test obd_test
default: all
EXTRA_PRE_CFLAGS := -I@LINUX@/fs -I@LDISKFS_DIR@ -I@LDISKFS_DIR@/ldiskfs
-EXTRA_DIST = $(obdclass-all-objs:.o=.c) llog_test.c llog_internal.h
+EXTRA_DIST = $(obdclass-all-objs:.o=.c) llog_test.c obd_test.c llog_internal.h
EXTRA_DIST += cl_internal.h local_storage.h
EXTRA_DIST += range_lock.c interval_tree.c
+# SPDX-License-Identifier: GPL-2.0
+
+#
+# This file is part of Lustre, http://www.lustre.org/
+#
+# lustre/obdclass/autoMakefile.am
+#
+# autoMakefile for obdclass
+#
+
if MODULES
if LINUX
modulefs_DATA = obdclass$(KMODEXT)
if TESTS
modulefs_DATA += llog_test$(KMODEXT)
+modulefs_DATA += obd_test$(KMODEXT)
endif # TESTS
endif # LINUX
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Copyright (c) 2023, Amazon and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ */
+
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ *
+ * lustre/obdclass/obd_test.c
+ *
+ * Simple OBD device for:
+ * 1) testing OBD device lifecycle management
+ * 2) demonstrating a simple OBD device
+ *
+ * Author: Timothy Day <timday@amazon.com>
+ *
+ */
+
+#include <linux/module.h>
+
+#include <obd_class.h>
+
+static int verbose;
+module_param(verbose, int, 0644);
+MODULE_PARM_DESC(verbose, "Set the logging level for the module");
+
+static int obd_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
+{
+ if (verbose >= 1)
+ pr_info("Lustre: OBD: %s", __func__);
+
+ if (verbose >= 2) {
+ int obd_minor_found;
+
+ pr_info("Lustre: OBD: obd_name: %s, obd_num: %i, obd_uuid: %s",
+ obd->obd_name, obd->obd_minor, obd->obd_uuid.uuid);
+
+ obd_minor_found = class_name2dev(obd->obd_name);
+ pr_info("Lustre: OBD: class_name2dev(): %i, %s",
+ obd_minor_found,
+ obd_minor_found == obd->obd_minor ? "PASS" : "FAIL");
+
+ obd_minor_found = class_uuid2dev(&obd->obd_uuid);
+ pr_info("Lustre: OBD: class_uuid2dev(): %i, %s",
+ obd_minor_found,
+ obd_minor_found == obd->obd_minor ? "PASS" : "FAIL");
+
+ obd_minor_found = class_name2obd(obd->obd_name)->obd_minor;
+ pr_info("Lustre: OBD: class_name2obd(): %i, %s",
+ obd_minor_found,
+ obd_minor_found == obd->obd_minor ? "PASS" : "FAIL");
+
+ obd_minor_found = class_uuid2obd(&obd->obd_uuid)->obd_minor;
+ pr_info("Lustre: OBD: class_uuid2obd(): %i, %s",
+ obd_minor_found,
+ obd_minor_found == obd->obd_minor ? "PASS" : "FAIL");
+ }
+
+ return 0;
+}
+
+static int obd_test_cleanup(struct obd_device *obd)
+{
+ if (verbose >= 1)
+ pr_info("Lustre: OBD: %s", __func__);
+
+ return 0;
+}
+
+static const struct obd_ops obd_test_obd_ops = {
+ .o_owner = THIS_MODULE,
+ .o_setup = obd_test_setup,
+ .o_cleanup = obd_test_cleanup,
+};
+
+static int __init obd_test_init(void)
+{
+ return class_register_type(&obd_test_obd_ops, NULL, false,
+ "obd_test", NULL);
+}
+
+static void __exit obd_test_exit(void)
+{
+ class_unregister_type("obd_test");
+}
+
+MODULE_AUTHOR("Amazon, Inc. <timday@amazon.com>");
+MODULE_DESCRIPTION("Lustre OBD test module");
+MODULE_VERSION(LUSTRE_VERSION_STRING);
+MODULE_LICENSE("GPL");
+
+module_init(obd_test_init);
+module_exit(obd_test_exit);
BUILT_MODULE_NAME[\${#BUILT_MODULE_NAME[@]}]="llog_test"
BUILT_MODULE_LOCATION[\${#BUILT_MODULE_LOCATION[@]}]="lustre/obdclass/"
DEST_MODULE_LOCATION[\${#DEST_MODULE_LOCATION[@]}]="/${kmoddir}/lustre/"
+BUILT_MODULE_NAME[\${#BUILT_MODULE_NAME[@]}]="obd_test"
+BUILT_MODULE_LOCATION[\${#BUILT_MODULE_LOCATION[@]}]="lustre/obdclass/"
+DEST_MODULE_LOCATION[\${#DEST_MODULE_LOCATION[@]}]="/${kmoddir}/lustre/"
BUILT_MODULE_NAME[\${#BUILT_MODULE_NAME[@]}]="lod"
BUILT_MODULE_LOCATION[\${#BUILT_MODULE_LOCATION[@]}]="lustre/lod/"
DEST_MODULE_LOCATION[\${#DEST_MODULE_LOCATION[@]}]="/${kmoddir}/lustre/"
}
run_test 54e "console/tty device works in lustre ======================"
+test_55a() {
+ local dev_path="/sys/kernel/debug/lustre/devices"
+
+ load_module obdclass/obd_test verbose=2 || error "load_module failed"
+
+ # This must be run in iteractive mode, since attach and setup
+ # are stateful
+ eval "$LCTL <<-EOF || error 'OBD device creation failed'
+ attach obd_test obd_name obd_uuid
+ setup obd_test
+ EOF"
+
+ echo "Devices:"
+ cat "$dev_path" | tail -n 10
+
+ $LCTL --device "obd_name" cleanup
+ $LCTL --device "obd_name" detach
+
+ dmesg | tail -n 25 | grep "Lustre: OBD:.*FAIL" &&
+ error "OBD unit test failed"
+
+ rmmod -v obd_test ||
+ error "rmmod failed (may trigger a failure in a later test)"
+}
+run_test 55a "OBD device life cycle unit tests"
+
+test_55b() {
+ local dev_path="/sys/kernel/debug/lustre/devices"
+ local dev_count="$(wc -l $dev_path | awk '{print $1}')"
+ local num_dev_to_create="$((8192 - $dev_count))"
+
+ load_module obdclass/obd_test || error "load_module failed"
+
+ local start=$SECONDS
+
+ # This must be run in iteractive mode, since attach and setup
+ # are stateful
+ for ((i = 1; i <= num_dev_to_create; i++)); do
+ echo "attach obd_test obd_name_$i obd_uuid_$i"
+ echo "setup obd_test_$i"
+ done | $LCTL || error "OBD device creation failed"
+
+ echo "Load time: $((SECONDS - start))"
+ echo "Devices:"
+ cat "$dev_path" | tail -n 10
+
+ for ((i = 1; i <= num_dev_to_create; i++)); do
+ echo "--device obd_name_$i cleanup"
+ echo "--device obd_name_$i detach"
+ done | $LCTL || error "OBD device cleanup failed"
+
+ echo "Unload time: $((SECONDS - start))"
+
+ rmmod -v obd_test ||
+ error "rmmod failed (may trigger a failure in a later test)"
+}
+run_test 55b "Load and unload max OBD devices"
+
test_56a() {
local numfiles=3
local numdirs=2
%dir %{modules_fs_path}/%{lustre_name}-tests
%dir %{modules_fs_path}/%{lustre_name}-tests/fs
%{modules_fs_path}/%{lustre_name}-tests/fs/llog_test.ko
+%{modules_fs_path}/%{lustre_name}-tests/fs/obd_test.ko