]> git.proxmox.com Git - lxc.git/blob - debian/patches/extra/0002-cgfsng-deduplicate-freeze-code.patch
merge fix for busy-looping on cgroup events
[lxc.git] / debian / patches / extra / 0002-cgfsng-deduplicate-freeze-code.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Fri, 15 May 2020 15:07:07 +0200
4 Subject: [PATCH] cgfsng: deduplicate freeze code
5
6 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
7 ---
8 src/lxc/cgroups/cgfsng.c | 65 ++++++++++++----------------------------
9 1 file changed, 19 insertions(+), 46 deletions(-)
10
11 diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
12 index 892fd915b..7136d27a8 100644
13 --- a/src/lxc/cgroups/cgfsng.c
14 +++ b/src/lxc/cgroups/cgfsng.c
15 @@ -2042,7 +2042,11 @@ static int freezer_cgroup_events_cb(int fd, uint32_t events, void *cbdata,
16 return LXC_MAINLOOP_CONTINUE;
17 }
18
19 -static int cg_unified_freeze(struct cgroup_ops *ops, int timeout)
20 +static int cg_unified_freeze_do(struct cgroup_ops *ops, int timeout,
21 + const char *state_string,
22 + int state_num,
23 + const char *epoll_error,
24 + const char *wait_error)
25 {
26 __do_close int fd = -EBADF;
27 call_cleaner(lxc_mainloop_close) struct lxc_epoll_descr *descr_ptr = NULL;
28 @@ -2067,26 +2071,33 @@ static int cg_unified_freeze(struct cgroup_ops *ops, int timeout)
29
30 ret = lxc_mainloop_open(&descr);
31 if (ret)
32 - return log_error_errno(-1, errno, "Failed to create epoll instance to wait for container freeze");
33 + return log_error_errno(-1, errno, "%s", epoll_error);
34
35 /* automatically cleaned up now */
36 descr_ptr = &descr;
37
38 - ret = lxc_mainloop_add_handler(&descr, fd, freezer_cgroup_events_cb, INT_TO_PTR((int){1}));
39 + ret = lxc_mainloop_add_handler(&descr, fd, freezer_cgroup_events_cb, INT_TO_PTR(state_num));
40 if (ret < 0)
41 return log_error_errno(-1, errno, "Failed to add cgroup.events fd handler to mainloop");
42 }
43
44 - ret = lxc_write_openat(h->container_full_path, "cgroup.freeze", "1", 1);
45 + ret = lxc_write_openat(h->container_full_path, "cgroup.freeze", state_string, 1);
46 if (ret < 0)
47 return log_error_errno(-1, errno, "Failed to open cgroup.freeze file");
48
49 if (timeout != 0 && lxc_mainloop(&descr, timeout))
50 - return log_error_errno(-1, errno, "Failed to wait for container to be frozen");
51 + return log_error_errno(-1, errno, "%s", wait_error);
52
53 return 0;
54 }
55
56 +static int cg_unified_freeze(struct cgroup_ops *ops, int timeout)
57 +{
58 + return cg_unified_freeze_do(ops, timeout, "1", 1,
59 + "Failed to create epoll instance to wait for container freeze",
60 + "Failed to wait for container to be frozen");
61 +}
62 +
63 __cgfsng_ops static int cgfsng_freeze(struct cgroup_ops *ops, int timeout)
64 {
65 if (!ops->hierarchies)
66 @@ -2112,47 +2123,9 @@ static int cg_legacy_unfreeze(struct cgroup_ops *ops)
67
68 static int cg_unified_unfreeze(struct cgroup_ops *ops, int timeout)
69 {
70 - __do_close int fd = -EBADF;
71 - call_cleaner(lxc_mainloop_close)struct lxc_epoll_descr *descr_ptr = NULL;
72 - int ret;
73 - struct lxc_epoll_descr descr;
74 - struct hierarchy *h;
75 -
76 - h = ops->unified;
77 - if (!h)
78 - return ret_set_errno(-1, ENOENT);
79 -
80 - if (!h->container_full_path)
81 - return ret_set_errno(-1, EEXIST);
82 -
83 - if (timeout != 0) {
84 - __do_free char *events_file = NULL;
85 -
86 - events_file = must_make_path(h->container_full_path, "cgroup.events", NULL);
87 - fd = open(events_file, O_RDONLY | O_CLOEXEC);
88 - if (fd < 0)
89 - return log_error_errno(-1, errno, "Failed to open cgroup.events file");
90 -
91 - ret = lxc_mainloop_open(&descr);
92 - if (ret)
93 - return log_error_errno(-1, errno, "Failed to create epoll instance to wait for container unfreeze");
94 -
95 - /* automatically cleaned up now */
96 - descr_ptr = &descr;
97 -
98 - ret = lxc_mainloop_add_handler(&descr, fd, freezer_cgroup_events_cb, INT_TO_PTR((int){0}));
99 - if (ret < 0)
100 - return log_error_errno(-1, errno, "Failed to add cgroup.events fd handler to mainloop");
101 - }
102 -
103 - ret = lxc_write_openat(h->container_full_path, "cgroup.freeze", "0", 1);
104 - if (ret < 0)
105 - return log_error_errno(-1, errno, "Failed to open cgroup.freeze file");
106 -
107 - if (timeout != 0 && lxc_mainloop(&descr, timeout))
108 - return log_error_errno(-1, errno, "Failed to wait for container to be unfrozen");
109 -
110 - return 0;
111 + return cg_unified_freeze_do(ops, timeout, "0", 0,
112 + "Failed to create epoll instance to wait for container unfreeze",
113 + "Failed to wait for container to be unfrozen");
114 }
115
116 __cgfsng_ops static int cgfsng_unfreeze(struct cgroup_ops *ops, int timeout)