Skip to content

Commit 9a2b7d6

Browse files
committed
criu: use libuuid for criu_run_id generation
criu_run_id will be used in upcoming changes to create and remove network rules for network locking. Instead of trying to come up with a way to create unique IDs, just use an existing library. libuuid should be installed on most systems as it is indirectly required by systemd (via libmount). Signed-off-by: Adrian Reber <[email protected]>
1 parent b3869c9 commit 9a2b7d6

26 files changed

Lines changed: 48 additions & 24 deletions

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ task:
3636
ln -sf /usr/include/google/protobuf/descriptor.proto images/google/protobuf/descriptor.proto
3737
dnf config-manager --set-enabled crb # Same as CentOS 8 powertools
3838
dnf -y install epel-release epel-next-release
39-
dnf -y install --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python-devel python-PyYAML python-protobuf python-junit_xml python3-importlib-metadata xmlto libdrm-devel
39+
dnf -y install --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python-devel python-PyYAML python-protobuf python-junit_xml python3-importlib-metadata xmlto libdrm-devel libuuid-devel
4040
# The image has a too old version of nettle which does not work with gnutls.
4141
# Just upgrade to the latest to make the error go away.
4242
dnf -y upgrade nettle nettle-devel

.github/workflows/check-commits.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
# Checkout pull request HEAD commit instead of merge commit
2020
ref: ${{ github.event.pull_request.head.sha }}
2121
- name: Install dependencies
22-
run: sudo scripts/ci/apt-install libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler protobuf-compiler python3-protobuf libnl-3-dev libnet-dev libcap-dev
22+
run: sudo scripts/ci/apt-install libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler protobuf-compiler python3-protobuf libnl-3-dev libnet-dev libcap-dev uuid-dev
2323
- name: Configure git user details
2424
run: |
2525
git config --global user.email "[email protected]"

compel/include/uapi/infect-util.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33

44
#include "common/compiler.h"
55

6+
/**
7+
* The length of the hash is based on what libuuid provides.
8+
* According to the manpage this is:
9+
*
10+
* The uuid_unparse() function converts the supplied UUID uu from the binary
11+
* representation into a 36-byte string (plus trailing '\0')
12+
*/
13+
#define RUN_ID_HASH_LENGTH 37
14+
615
/*
716
* compel_run_id is a unique value of the current run. It can be used to
817
* generate resource ID-s to avoid conflicts with other processes.
918
*/
10-
extern uint64_t compel_run_id;
19+
extern char compel_run_id[RUN_ID_HASH_LENGTH];
1120

1221
struct parasite_ctl;
1322
extern int __must_check compel_util_send_fd(struct parasite_ctl *ctl, int fd);

compel/src/lib/infect-util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "infect-rpc.h"
88
#include "infect-util.h"
99

10-
uint64_t compel_run_id;
10+
char compel_run_id[RUN_ID_HASH_LENGTH];
1111

1212
int compel_util_send_fd(struct parasite_ctl *ctl, int fd)
1313
{

compel/src/lib/infect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static int gen_parasite_saddr(struct sockaddr_un *saddr, int key)
427427
int sun_len;
428428

429429
saddr->sun_family = AF_UNIX;
430-
snprintf(saddr->sun_path, UNIX_PATH_MAX, "X/crtools-pr-%d-%" PRIx64, key, compel_run_id);
430+
snprintf(saddr->sun_path, UNIX_PATH_MAX, "X/crtools-pr-%d-%s", key, compel_run_id);
431431

432432
sun_len = SUN_LEN(saddr);
433433
*saddr->sun_path = '\0';

criu/Makefile.packages

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ REQ-RPM-PKG-NAMES += protobuf-devel
66
REQ-RPM-PKG-NAMES += protobuf-python
77
REQ-RPM-PKG-NAMES += libnl3-devel
88
REQ-RPM-PKG-NAMES += libcap-devel
9+
REQ-RPM-PKG-NAMES += libuuid-devel
910

1011
REQ-RPM-PKG-TEST-NAMES += libaio-devel
1112

@@ -16,6 +17,7 @@ REQ-DEB-PKG-NAMES += protobuf-compiler
1617
REQ-DEB-PKG-NAMES += $(PYTHON)-protobuf
1718
REQ-DEB-PKG-NAMES += libnl-3-dev
1819
REQ-DEB-PKG-NAMES += libcap-dev
20+
REQ-DEB-PKG-NAMES += uuid-dev
1921

2022
REQ-DEB-PKG-TEST-NAMES += $(PYTHON)-yaml
2123
REQ-DEB-PKG-TEST-NAMES += libaio-dev
@@ -25,7 +27,7 @@ REQ-DEB-PKG-TEST-NAMES += libaio-dev
2527
REQ-RPM-PKG-TEST-NAMES += $(PYTHON)-PyYAML
2628

2729

28-
export LIBS += -lprotobuf-c -ldl -lnl-3 -lsoccr -Lsoccr/ -lnet
30+
export LIBS += -lprotobuf-c -ldl -lnl-3 -lsoccr -Lsoccr/ -lnet -luuid
2931

3032
check-packages-failed:
3133
$(warning Can not find some of the required libraries)

criu/fdstore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int fdstore_init(void)
5858
}
5959

6060
addr.sun_family = AF_UNIX;
61-
addrlen = snprintf(addr.sun_path, sizeof(addr.sun_path), "X/criu-fdstore-%" PRIx64 "-%" PRIx64, st.st_ino,
61+
addrlen = snprintf(addr.sun_path, sizeof(addr.sun_path), "X/criu-fdstore-%" PRIx64 "-%s", st.st_ino,
6262
criu_run_id);
6363
addrlen += sizeof(addr.sun_family);
6464

criu/files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ static int receive_fd(struct fdinfo_list_entry *fle);
978978
static void transport_name_gen(struct sockaddr_un *addr, int *len, int pid)
979979
{
980980
addr->sun_family = AF_UNIX;
981-
snprintf(addr->sun_path, UNIX_PATH_MAX, "x/crtools-fd-%d-%" PRIx64, pid, criu_run_id);
981+
snprintf(addr->sun_path, UNIX_PATH_MAX, "x/crtools-fd-%d-%s", pid, criu_run_id);
982982
*len = SUN_LEN(addr);
983983
*addr->sun_path = '\0';
984984
}

criu/include/util.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "log.h"
2222
#include "common/err.h"
2323

24+
#include "compel/infect-util.h"
25+
2426
#define PREF_SHIFT_OP(pref, op, size) ((size)op(pref##BYTES_SHIFT))
2527
#define KBYTES_SHIFT 10
2628
#define MBYTES_SHIFT 20
@@ -420,7 +422,7 @@ extern int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void
420422
* criu_run_id is a unique value of the current run. It can be used to
421423
* generate resource ID-s to avoid conflicts with other CRIU processes.
422424
*/
423-
extern uint64_t criu_run_id;
425+
extern char criu_run_id[RUN_ID_HASH_LENGTH];
424426
extern void util_init(void);
425427

426428
extern char *resolve_mountpoint(char *path);

criu/pidfd-store.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int init_pidfd_store_sk(pid_t pid, int sk)
9999
goto err;
100100
}
101101

102-
addrlen = snprintf(addr.sun_path, sizeof(addr.sun_path), "X/criu-pidfd-store-%d-%d-%" PRIx64, pid, sk,
102+
addrlen = snprintf(addr.sun_path, sizeof(addr.sun_path), "X/criu-pidfd-store-%d-%d-%s", pid, sk,
103103
criu_run_id);
104104
addrlen += sizeof(addr.sun_family);
105105

0 commit comments

Comments
 (0)