Skip to content

Commit 3794c48

Browse files
committed
turn lz4e compress and decompress into submodules, rename module dir to lz4e_bdev. Add more Makefile targets, add target for building lib without block device
1 parent b1cf3b6 commit 3794c48

29 files changed

+167
-103
lines changed

.clang-format-ignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Do not format lz4 library sources
22
lz4e/*
3-
include/lz4e/*
3+
lz4e/include/*

Kbuild

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
include $(PWD)/flags.mk
22

3-
lz4e-y := module/lz4e_module.o \
4-
module/lz4e_dev.o \
5-
module/lz4e_under_dev.o \
6-
module/lz4e_req.o \
7-
module/lz4e_chunk.o \
8-
module/lz4e_stats.o
9-
10-
lz4e-y += lz4e/lz4e_compress.o \
11-
lz4e/lz4e_decompress.o
12-
13-
obj-m := lz4e.o
3+
obj-m += lz4e/
4+
obj-m += lz4e_bdev/

Makefile

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,87 @@
11
KERNEL_VERSION := $(shell uname -r)
22
KERNEL_SOURCES_DIR := /lib/modules/$(KERNEL_VERSION)/build
33

4-
OUTPUT_DIR := $(PWD)/build
5-
COMPILE_COMMANDS := $(PWD)/compile_commands.json
4+
LIB_NAME := lz4e
5+
COMPRESS_NAME := $(LIB_NAME)_compress
6+
DECOMPRESS_NAME := $(LIB_NAME)_decompress
7+
BDEV_NAME := $(LIB_NAME)_bdev
8+
9+
ALL := $(PWD)
10+
LIB := $(ALL)/$(LIB_NAME)
11+
BDEV := $(ALL)/$(BDEV_NAME)
12+
13+
OUTPUT_ALL := $(PWD)/build
14+
OUTPUT_LIB := $(OUTPUT_ALL)/$(LIB_NAME)
15+
OUTPUT_BDEV := $(OUTPUT_ALL)/$(BDEV_NAME)
16+
17+
COMPRESS_OBJ := $(OUTPUT_LIB)/$(COMPRESS_NAME).ko
18+
DECOMPRESS_OBJ := $(OUTPUT_LIB)/$(DECOMPRESS_NAME).ko
19+
BDEV_OBJ := $(OUTPUT_BDEV)/$(BDEV_NAME).ko
20+
21+
TEST_ALL := $(PWD)/test/test_all.sh
22+
23+
# ---------------- All, lib and block dev----------------
624

725
.PHONY: all
8-
all: build
26+
all:
27+
$(MAKE) -j -C $(KERNEL_SOURCES_DIR) M=$(ALL) MO=$(OUTPUT_ALL) modules
928

10-
.PHONY: build
11-
build:
12-
$(MAKE) -j -C $(KERNEL_SOURCES_DIR) M=$(PWD) MO=$(OUTPUT_DIR) modules
29+
.PHONY: install
30+
install:
31+
$(MAKE) -j -C $(KERNEL_SOURCES_DIR) M=$(ALL) MO=$(OUTPUT_ALL) modules_install
1332

1433
.PHONY: clean
1534
clean:
16-
rm -rf $(OUTPUT_DIR) $(COMPILE_COMMANDS)
35+
$(MAKE) -j -C $(KERNEL_SOURCES_DIR) M=$(ALL) MO=$(OUTPUT_ALL) clean
36+
rm -rf $(OUTPUT_ALL)
37+
38+
.PHONY: insert
39+
insert:
40+
insmod $(COMPRESS_OBJ)
41+
insmod $(DECOMPRESS_OBJ)
42+
insmod $(BDEV_OBJ)
43+
44+
.PHONY: remove
45+
remove:
46+
rmmod $(BDEV_NAME) || true
47+
rmmod $(DECOMPRESS_NAME) || true
48+
rmmod $(COMPRESS_NAME) || true
49+
50+
.PHONY: reinsert
51+
reinsert:
52+
$(MAKE) remove && $(MAKE) insert
53+
54+
# ---------------- Lib only ----------------
55+
56+
.PHONY: lib
57+
lib:
58+
$(MAKE) -j -C $(KERNEL_SOURCES_DIR) M=$(LIB) MO=$(OUTPUT_LIB) modules
59+
60+
.PHONY: lib_install
61+
lib_install:
62+
$(MAKE) -j -C $(KERNEL_SOURCES_DIR) M=$(LIB) MO=$(OUTPUT_LIB) modules_install
63+
64+
.PHONY: lib_clean
65+
lib_clean:
66+
$(MAKE) -j -C $(KERNEL_SOURCES_DIR) M=$(LIB) MO=$(OUTPUT_LIB) clean
67+
rm -rf $(OUTPUT_LIB)
68+
69+
.PHONY: lib_insert
70+
lib_insert:
71+
insmod $(COMPRESS_OBJ)
72+
insmod $(DECOMPRESS_OBJ)
73+
74+
.PHONY: lib_remove
75+
lib_remove:
76+
rmmod $(DECOMPRESS_NAME) || true
77+
rmmod $(COMPRESS_NAME) || true
78+
79+
.PHONY: lib_reinsert
80+
lib_reinsert:
81+
$(MAKE) lib_remove && $(MAKE) lib_insert
82+
83+
# ---------------- Testing ----------------
84+
85+
.PHONY: test
86+
test:
87+
$(MAKE) && $(SHELL) $(TEST_ALL)

include/lz4e/.clang-tidy

Lines changed: 0 additions & 18 deletions
This file was deleted.

lz4e/Kbuild

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include $(PWD)/flags.mk
2+
3+
obj-m += lz4e_compress.o
4+
obj-m += lz4e_decompress.o
File renamed without changes.

lz4e/lz4e_compress.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@
3535
**************************************/
3636
#include <linux/bio.h>
3737
#include <linux/bvec.h>
38+
#include <linux/export.h>
3839
#include <linux/module.h>
3940
#include <linux/kernel.h>
4041

41-
#include "include/lz4e/lz4e.h"
42-
#include "include/lz4e/lz4e_defs.h"
42+
#include "include/lz4e.h"
43+
#include "include/lz4e_defs.h"
4344

4445
/*-******************************
4546
* Compression functions
@@ -565,3 +566,8 @@ int LZ4E_compress_default(const struct bio_vec *src, struct bio_vec *dst,
565566
return LZ4E_compress_fast_extState(wrkmem, src, dst, srcIter,
566567
dstIter, LZ4E_ACCELERATION_DEFAULT);
567568
}
569+
EXPORT_SYMBOL(LZ4E_compress_default);
570+
571+
MODULE_AUTHOR("Alexander Bugaev");
572+
MODULE_DESCRIPTION("LZ4 compression for scatter-gather buffers");
573+
MODULE_LICENSE("GPL");

lz4e/lz4e_decompress.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333
/*-************************************
3434
* Dependencies
3535
**************************************/
36+
#include <linux/export.h>
3637
#include <linux/init.h>
3738
#include <linux/module.h>
3839
#include <linux/kernel.h>
3940
#include <linux/unaligned.h>
4041

41-
#include "include/lz4e/lz4e.h"
42-
#include "include/lz4e/lz4e_defs.h"
42+
#include "include/lz4e.h"
43+
#include "include/lz4e_defs.h"
4344

4445
/*-*****************************
4546
* Decompression functions
@@ -466,3 +467,8 @@ int LZ4E_decompress_safe(const char *source, char *dest,
466467
endOnInputSize, decode_full_block,
467468
noDict, (BYTE *)dest, NULL, 0);
468469
}
470+
EXPORT_SYMBOL(LZ4E_decompress_safe);
471+
472+
MODULE_AUTHOR("");
473+
MODULE_DESCRIPTION("LZ4 decompression for scatter-gather buffers");
474+
MODULE_LICENSE("GPL");

lz4e_bdev/Kbuild

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include $(PWD)/flags.mk
2+
3+
lz4e_bdev-y := lz4e_module.o \
4+
lz4e_dev.o \
5+
lz4e_under_dev.o \
6+
lz4e_req.o \
7+
lz4e_chunk.o \
8+
lz4e_stats.o
9+
10+
obj-m := lz4e_bdev.o

0 commit comments

Comments
 (0)