projects/linux·blob master · refs

49 lines · 1.6 KiB

1/* SPDX-License-Identifier: GPL-2.0 */
2
3/*
4 * Copyright (c) 2025, Google LLC.
5 * Pasha Tatashin <[email protected]>
6 *
7 * Utility functions for LUO kselftests.
8 */
9
10#ifndef SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H
11#define SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H
12
13#include <errno.h>
14#include <string.h>
15#include <linux/liveupdate.h>
16#include "../../../kselftest.h"
17
18#define LUO_DEVICE "/dev/liveupdate"
19
20#define fail_exit(fmt, ...) \
21 ksft_exit_fail_msg("[%s:%d] " fmt " (errno: %s)\n", \
22 __func__, __LINE__, ##__VA_ARGS__, strerror(errno))
23
24int luo_open_device(void);
25int luo_create_session(int luo_fd, const char *name);
26int luo_retrieve_session(int luo_fd, const char *name);
27int luo_session_finish(int session_fd);
28int luo_get_session_name(int session_fd, char *name, size_t name_len);
29
30int luo_ensure_nofile_limit(long min_limit);
31int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
32int luo_session_retrieve_fd(int session_fd, __u64 token);
33
34int create_and_preserve_memfd(int session_fd, int token, const char *data);
35int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
36
37void create_state_file(int luo_fd, const char *session_name, int token,
38 int next_stage);
39void restore_and_read_stage(int state_session_fd, int token, int *stage);
40
41void daemonize_and_wait(void);
42
43typedef void (*luo_test_stage1_fn)(int luo_fd);
44typedef void (*luo_test_stage2_fn)(int luo_fd, int state_session_fd);
45
46int luo_test(int argc, char *argv[], const char *state_session_name,
47 luo_test_stage1_fn stage1, luo_test_stage2_fn stage2);
48
49#endif /* SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H */