tools/testing/selftests/bpf/prog_tests/lsm_bdev.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/lsm_bdev.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/lsm_bdev.c- Extension
.c- Size
- 5712 bytes
- Lines
- 222
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
test_progs.hfcntl.hstdio.hstdlib.hstring.hsys/stat.hsys/types.hunistd.hlsm_bdev.skel.h
Detected Declarations
struct verity_infofunction run_cmdfunction has_prerequisitesfunction test_lsm_bdev
Annotated Snippet
struct verity_info {
__u8 has_roothash;
__u8 sig_valid;
__u32 setintegrity_cnt;
};
#define DATA_SIZE_MB 8
#define HASH_SIZE_MB 1
#define DM_NAME "bpf_test_verity"
#define DM_DEV_PATH "/dev/mapper/" DM_NAME
/* Run a command and optionally capture the first line of stdout. */
static int run_cmd(const char *cmd, char *out, size_t out_sz)
{
FILE *fp;
int ret;
fp = popen(cmd, "r");
if (!fp)
return -1;
if (out && out_sz > 0) {
if (!fgets(out, out_sz, fp))
out[0] = '\0';
/* strip trailing newline */
out[strcspn(out, "\n")] = '\0';
}
ret = pclose(fp);
return WIFEXITED(ret) ? WEXITSTATUS(ret) : -1;
}
static bool has_prerequisites(void)
{
if (getuid() != 0) {
printf("SKIP: must be root\n");
return false;
}
if (run_cmd("modprobe loop 2>/dev/null", NULL, 0) &&
run_cmd("ls /dev/loop-control 2>/dev/null", NULL, 0)) {
printf("SKIP: no loop device support\n");
return false;
}
if (run_cmd("modprobe dm-verity 2>/dev/null", NULL, 0) &&
run_cmd("dmsetup targets 2>/dev/null | grep -q verity", NULL, 0)) {
printf("SKIP: dm-verity module not available\n");
return false;
}
if (run_cmd("which veritysetup >/dev/null 2>&1", NULL, 0)) {
printf("SKIP: veritysetup not found\n");
return false;
}
return true;
}
void test_lsm_bdev(void)
{
char data_img[] = "/tmp/bpf_verity_data_XXXXXX";
char hash_img[] = "/tmp/bpf_verity_hash_XXXXXX";
char data_loop[64] = {};
char hash_loop[64] = {};
char roothash[256] = {};
char cmd[512];
int data_fd = -1, hash_fd = -1;
struct lsm_bdev *skel = NULL;
struct verity_info val;
struct stat st;
__u32 dev_key;
int err;
if (!has_prerequisites()) {
test__skip();
return;
}
/* Clean up any stale device from a previous crashed run. */
snprintf(cmd, sizeof(cmd), "dmsetup remove %s 2>/dev/null", DM_NAME);
run_cmd(cmd, NULL, 0);
/* Create temporary image files. */
data_fd = mkstemp(data_img);
if (!ASSERT_OK_FD(data_fd, "mkstemp data"))
return;
hash_fd = mkstemp(hash_img);
if (!ASSERT_OK_FD(hash_fd, "mkstemp hash"))
Annotation
- Immediate include surface: `test_progs.h`, `fcntl.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/stat.h`, `sys/types.h`, `unistd.h`.
- Detected declarations: `struct verity_info`, `function run_cmd`, `function has_prerequisites`, `function test_lsm_bdev`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.