kmod: dkms support

This commit is contained in:
Miroslav Crnic
2025-07-08 10:53:45 +00:00
parent 66eed220f1
commit c007b763dc
17 changed files with 80 additions and 43 deletions

3
.gitignore vendored
View File

@@ -12,5 +12,6 @@ kmod/test-out
kmod/trace
kmod/vm-out
linux-*.tar.gz
eggs-integrationtest.*
tern-integrationtest.*
.go-cache
ternfs-client*

8
kmod/.gitignore vendored
View File

@@ -11,6 +11,12 @@ modules.order
ternfs-client-*
linux*
*.img
revision.c
html
Doxyfile
revision.c
crc32c.c
gf_tables.c
iscsi.h
rs_core.c
debian/debhelper-build-stamp
debian/files

View File

@@ -1,9 +1,9 @@
KDIR ?= /lib/modules/$(shell uname -r)/build
LLVM ?= 0
obj-m += ternfs.o
obj-m += ternfs-client.o
ternfs-objs += \
ternfs-client-objs += \
dir.o \
err.o \
export.o \
@@ -37,19 +37,40 @@ export CF = -Wbitwise -Wcontext -Wcast_truncate -Wsparse-all -Wno-shadow -Wnopoi
revision.c:
printf "#include \"sysfs.h\"\nconst char* ternfs_revision = \"$(shell git describe --always --dirty)\";\n" > revision.c
EXTRA_FILES := ../cpp/crc32c/crc32c.c ../cpp/rs/gf_tables.c ../cpp/crc32c/iscsi.h ../cpp/rs/rs_core.c
extra-files: $(EXTRA_FILES)
$(foreach file,$(EXTRA_FILES),cp $(file) .;)
LOCAL_FILES := $(notdir $(EXTRA_FILES))
extra-files-clean:
rm -f $(LOCAL_FILES) revision.c *.o
# C=1 builds with sparse
kmod: revision.c
ternfs-client-tests: revision.c extra-files
$(MAKE) -C $(KDIR) M=$(PWD) C=1 modules
# Target to build the kmod when packaging it up (e.g. via dkms)
# Targets to build/clean the kmod when packaging it up (e.g. via dkms)
# We'll generate revision.c separatedly, and we also don't want
# sparse as a dependency.
kmod_package:
ternfs-client:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
ternfs-client-clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
rm -f bincode_tests rs_tests
rm -f *.o *.ko
ternfs-client-local: revision.c extra-files
$(MAKE) -C $(KDIR) M=$(PWD) modules
bincode_tests: bincode_tests.c bincodegen.h bincode.h
gcc -Wall -g -O2 -fsanitize=undefined,address -fno-sanitize-recover=all bincode_tests.c -o bincode_tests
bincode_tests-clean:
rm -f bincode_tests rs_tests ubuntu.img test-out trace vm-out dmesg
rm -rf tmp
deb-package: revision.c extra-files
dpkg-buildpackage -us -uc
clean: ternfs-client-clean bincode_tests-clean

View File

@@ -1,26 +0,0 @@
#!/bin/bash
set -e
VERSION=${1:?}
BASE_DIR="eggsfs-client-${VERSION}"
MOD_DIR="${BASE_DIR}/lib/modules/$(uname -r)/fs/eggsfs"
SVC_DIR="${BASE_DIR}/etc/systemd/system"
MOD_LOAD_DIR="${BASE_DIR}/etc/modules-load.d"
mkdir -p ${BASE_DIR}/DEBIAN
cat debian/control | sed "s/##VERSION##/${VERSION}/g" > ${BASE_DIR}/DEBIAN/control
mkdir -p ${MOD_LOAD_DIR}
cp debian/eggsfs_load.conf ${MOD_LOAD_DIR}/eggsfs.conf
mkdir -p ${MOD_DIR}
cp eggsfs.ko ${MOD_DIR}
mkdir -p ${SVC_DIR}
cp debian/eggsfs-client.service ${SVC_DIR}
mkdir -p ${BASE_DIR}/mnt/eggsfs
dpkg-deb --build --root-owner-group ${BASE_DIR}

View File

@@ -34,7 +34,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR
# build kernel module
make "KDIR=${SCRIPT_DIR}/linux" -j kmod
make "KDIR=${SCRIPT_DIR}/linux" -j ternfs-client-local
# start VM in the background
function cleanup {
@@ -49,7 +49,7 @@ trap cleanup EXIT
# Wait for VM to go up by trying to copy the kernel module to it
chmod 0600 image-key
scp_attempts=0
while ! scp -v -P 2223 -o StrictHostKeyChecking=no -i image-key ternfs.ko fmazzol@localhost: ; do
while ! scp -v -P 2223 -o StrictHostKeyChecking=no -i image-key ternfs-client.ko fmazzol@localhost: ; do
sleep 1
scp_attempts=$((scp_attempts + 1))
if [ $scp_attempts -ge 20 ]; then
@@ -62,7 +62,7 @@ done
./vm_deploy.py
# Insert module
ssh -p 2223 -i image-key fmazzol@localhost "sudo insmod ternfs.ko"
ssh -p 2223 -i image-key fmazzol@localhost "sudo insmod ternfs-client.ko"
# Set up permissions to read kmsg
ssh -p 2223 -i image-key fmazzol@localhost "sudo chmod 666 /dev/kmsg"

View File

@@ -1 +0,0 @@
../cpp/crc32c/crc32c.c

5
kmod/debian/changelog Normal file
View File

@@ -0,0 +1,5 @@
ternfs-client (1.0-xxxxxx) unstable; urgency=low
* Initial release.
-- Miroslav Crnic <miroslav.crnic@xtxmarkets.com> Mon, 07 Jul 2025 11:23:34 +0000

1
kmod/debian/compat Normal file
View File

@@ -0,0 +1 @@
10

11
kmod/debian/control Normal file
View File

@@ -0,0 +1,11 @@
Source: ternfs-client
Section: misc
Priority: optional
Maintainer: restech
Build-Depends: debhelper (>= 10), dkms
Package: ternfs-client-dkms
Architecture: amd64
Depends: dkms (>= 2.2), ${misc:Depends}, linux-headers-generic
Description: ternfs client module (DKMS)
Builds and installs the ternfs kernel module for all installed kernels.

9
kmod/debian/dkms Normal file
View File

@@ -0,0 +1,9 @@
PACKAGE_NAME="ternfs-client"
PACKAGE_VERSION="1.0-xxxxxx"
BUILT_MODULE_NAME[0]="$PACKAGE_NAME" # build from top-level
DEST_MODULE_LOCATION[0]="/kernel/drivers/extra"
MAKE[0]="make \"KDIR=${kernel_source_dir}\" ternfs-client"
CLEAN="make ternfs-client-clean"
AUTOINSTALL="yes"

3
kmod/debian/install Normal file
View File

@@ -0,0 +1,3 @@
*.c /usr/src/ternfs-client-1.0-xxxxxx/
*.h /usr/src/ternfs-client-1.0-xxxxxx/
Makefile /usr/src/ternfs-client-1.0-xxxxxx/

6
kmod/debian/rules Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/make -f
%:
dh $@ --with dkms
override_dh_auto_clean:
make clean

View File

@@ -0,0 +1 @@
3.0 (native)

View File

@@ -0,0 +1,3 @@
tar-ignore = "linux*"

View File

@@ -1 +0,0 @@
../cpp/rs/gf_tables.c

View File

@@ -1 +0,0 @@
../cpp/crc32c/iscsi.h

View File

@@ -1 +0,0 @@
../cpp/rs/rs_core.c