Gentoo Archives: gentoo-commits

From: Joonas Niilola <juippis@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-fs/bees/, sys-fs/bees/files/
Date: Thu, 28 Nov 2019 16:34:59
Message-Id: 1574958875.b2a8f934671d15ac008f42976e5c4de087e31607.juippis@gentoo
1 commit: b2a8f934671d15ac008f42976e5c4de087e31607
2 Author: Kai Krakow <hurikhan77+bgo <AT> gmail <DOT> com>
3 AuthorDate: Thu Nov 28 11:23:02 2019 +0000
4 Commit: Joonas Niilola <juippis <AT> gentoo <DOT> org>
5 CommitDate: Thu Nov 28 16:34:35 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b2a8f934
7
8 sys-fs/bees: Bump to v0.6.1-r1
9
10 Closes: https://bugs.gentoo.org/685714
11 Package-Manager: Portage-2.3.76, Repoman-2.3.16
12 Signed-off-by: Kai Krakow <hurikhan77+bgo <AT> gmail.com>
13 Signed-off-by: Joonas Niilola <juippis <AT> gentoo.org>
14
15 sys-fs/bees/bees-0.6.1-r1.ebuild | 86 ++++++++++++++++++++
16 ...-local-lambda-expression-cannot-have-a-ca.patch | 38 +++++++++
17 ...karound-to-prevent-LOGICAL_INO-and-btrfs-.patch | 95 ++++++++++++++++++++++
18 3 files changed, 219 insertions(+)
19
20 diff --git a/sys-fs/bees/bees-0.6.1-r1.ebuild b/sys-fs/bees/bees-0.6.1-r1.ebuild
21 new file mode 100644
22 index 00000000000..5d44fcd0182
23 --- /dev/null
24 +++ b/sys-fs/bees/bees-0.6.1-r1.ebuild
25 @@ -0,0 +1,86 @@
26 +# Copyright 1999-2019 Gentoo Authors
27 +# Distributed under the terms of the GNU General Public License v2
28 +
29 +EAPI=7
30 +
31 +inherit linux-info systemd
32 +
33 +DESCRIPTION="Best-Effort Extent-Same, a btrfs dedup agent"
34 +HOMEPAGE="https://github.com/Zygo/bees"
35 +
36 +if [[ ${PV} == "9999" ]] ; then
37 + EGIT_REPO_URI="https://github.com/Zygo/bees.git"
38 + inherit git-r3
39 +else
40 + SRC_URI="https://github.com/Zygo/bees/archive/v${PV}.tar.gz -> ${P}.tar.gz"
41 + KEYWORDS="~amd64"
42 +fi
43 +
44 +LICENSE="GPL-3"
45 +SLOT="0"
46 +IUSE="tools"
47 +
48 +DEPEND="
49 + >=sys-apps/util-linux-2.30.2
50 + >=sys-fs/btrfs-progs-4.1
51 +"
52 +RDEPEND="${DEPEND}"
53 +
54 +CONFIG_CHECK="~BTRFS_FS"
55 +ERROR_BTRFS_FS="CONFIG_BTRFS_FS: bees does currently only work with btrfs"
56 +
57 +PATCHES=(
58 + "${FILESDIR}/6001-lib-fix-non-local-lambda-expression-cannot-have-a-ca.patch"
59 + "${FILESDIR}/6002-context-workaround-to-prevent-LOGICAL_INO-and-btrfs-.patch"
60 +)
61 +
62 +pkg_pretend() {
63 + if [[ ${MERGE_TYPE} != buildonly ]]; then
64 + if kernel_is -lt 4 4 3; then
65 + ewarn "Kernel versions below 4.4.3 lack critical features needed for bees to"
66 + ewarn "properly operate, so it won't work. It's recommended to run at least"
67 + ewarn "kernel version 4.11 for best performance and reliability."
68 + ewarn
69 + elif kernel_is -lt 4 11; then
70 + ewarn "With kernel versions below 4.11, bees may severely degrade system performance"
71 + ewarn "and responsiveness. Especially, the kernel may deadlock while bees is"
72 + ewarn "running, it's recommended to run at least kernel 4.11."
73 + ewarn
74 + elif kernel_is -lt 4 14 29; then
75 + ewarn "With kernel versions below 4.14.29, bees may generate a lot of bogus WARN_ON()"
76 + ewarn "messages in the kernel log. These messages can be ignored and this is fixed"
77 + ewarn "with more recent kernels:"
78 + ewarn "# WARNING: CPU: 3 PID: 18172 at fs/btrfs/backref.c:1391 find_parent_nodes+0xc41/0x14e0"
79 + ewarn
80 + fi
81 + if kernel_is -lt 5 3 4; then
82 + ewarn "With kernel versions below 5.3.4, bees may trigger a btrfs bug when running"
83 + ewarn "btrfs-balance in parallel. This may lead to meta-data corruption in the worst"
84 + ewarn "case. Especially, kernels 5.1.21 and 5.2.21 should be avoided. Kernels 5.0.x"
85 + ewarn "after 5.0.21 should be safe. In the best case, affected kernels may force"
86 + ewarn "the device RO without writing corrupted meta-data. More details:"
87 + ewarn "https://github.com/Zygo/bees/blob/master/docs/btrfs-kernel.md"
88 + ewarn
89 + fi
90 + elog "Bees recommends running the latest current kernel for performance and"
91 + elog "reliability reasons, see README.md."
92 + fi
93 +}
94 +
95 +src_configure() {
96 + cat >localconf <<-EOF || die
97 + LIBEXEC_PREFIX=/usr/libexec
98 + PREFIX=/usr
99 + LIBDIR="$(get_libdir)"
100 + SYSTEMD_SYSTEM_UNIT_DIR="$(systemd_get_systemunitdir)"
101 + DEFAULT_MAKE_TARGET=all
102 + EOF
103 + if [[ ${PV} != "9999" ]] ; then
104 + cat >>localconf <<-EOF || die
105 + BEES_VERSION=v${PV}
106 + EOF
107 + fi
108 + if use tools; then
109 + echo OPTIONAL_INSTALL_TARGETS=install_tools >>localconf || die
110 + fi
111 +}
112
113 diff --git a/sys-fs/bees/files/6001-lib-fix-non-local-lambda-expression-cannot-have-a-ca.patch b/sys-fs/bees/files/6001-lib-fix-non-local-lambda-expression-cannot-have-a-ca.patch
114 new file mode 100644
115 index 00000000000..60ab748eb2b
116 --- /dev/null
117 +++ b/sys-fs/bees/files/6001-lib-fix-non-local-lambda-expression-cannot-have-a-ca.patch
118 @@ -0,0 +1,38 @@
119 +From 566df54a3f7458559b75455a95b1991b515ba6bf Mon Sep 17 00:00:00 2001
120 +From: Zygo Blaxell <zblaxell@××××××××××××××××××××.org>
121 +Date: Wed, 12 Jun 2019 21:27:50 -0400
122 +Subject: [PATCH 1/2] lib: fix non-local lambda expression cannot have a
123 + capture-default
124 +
125 +We got away with this because GCC 4.8 (and apparently every GCC prior
126 +to 9) didn't notice or care, and because there is nothing referenced
127 +inside the lambda function body that isn't accessible from any other
128 +kind of function body (i.e. the capture wasn't needed at all).
129 +
130 +GCC 9 now enforces what the C++ standard said all along: there is
131 +no need to allow capture-default in this case, so it is not.
132 +
133 +Fix by removing the offending capture-default.
134 +
135 +Fixes: https://github.com/Zygo/bees/issues/112
136 +Signed-off-by: Zygo Blaxell <bees@×××××××××××.org>
137 +---
138 + lib/error.cc | 2 +-
139 + 1 file changed, 1 insertion(+), 1 deletion(-)
140 +
141 +diff --git a/lib/error.cc b/lib/error.cc
142 +index f2a6db0..1d16a0a 100644
143 +--- a/lib/error.cc
144 ++++ b/lib/error.cc
145 +@@ -32,7 +32,7 @@ namespace crucible {
146 +
147 + // FIXME: could probably avoid some of these levels of indirection
148 + static
149 +- function<void(string s)> current_catch_explainer = [&](string s) {
150 ++ function<void(string s)> current_catch_explainer = [](string s) {
151 + cerr << s << endl;
152 + };
153 +
154 +--
155 +2.23.0
156 +
157
158 diff --git a/sys-fs/bees/files/6002-context-workaround-to-prevent-LOGICAL_INO-and-btrfs-.patch b/sys-fs/bees/files/6002-context-workaround-to-prevent-LOGICAL_INO-and-btrfs-.patch
159 new file mode 100644
160 index 00000000000..6d8d2ea530d
161 --- /dev/null
162 +++ b/sys-fs/bees/files/6002-context-workaround-to-prevent-LOGICAL_INO-and-btrfs-.patch
163 @@ -0,0 +1,95 @@
164 +From f731ea8016c570243c783adef96681b535d9c927 Mon Sep 17 00:00:00 2001
165 +From: Zygo Blaxell <bees@×××××××××××.org>
166 +Date: Tue, 19 Nov 2019 16:01:31 -0500
167 +Subject: [PATCH 2/2] context: workaround to prevent LOGICAL_INO and btrfs
168 + balance from running concurrently
169 +
170 +This avoids some kernel bugs. One of them is fixed in 5.3.4 and later:
171 +
172 + efad8a853a "Btrfs: fix use-after-free when using the tree modification log"
173 +
174 +There are apparently others in current kernels, so for now just put bees
175 +on pause until the balance is done.
176 +
177 +At some point we may want to provide an option to disable this
178 +workaround; however, running bees and balance at the same time makes
179 +neither particularly fast, so maybe we'll just leave it this way.
180 +
181 +Signed-off-by: Zygo Blaxell <bees@×××××××××××.org>
182 +---
183 + src/bees-context.cc | 31 +++++++++++++++++++++++++++++++
184 + src/bees.h | 4 ++++
185 + 2 files changed, 35 insertions(+)
186 +
187 +diff --git a/src/bees-context.cc b/src/bees-context.cc
188 +index 4e0a43e..0665019 100644
189 +--- a/src/bees-context.cc
190 ++++ b/src/bees-context.cc
191 +@@ -760,11 +760,42 @@ BeesResolveAddrResult::BeesResolveAddrResult()
192 + {
193 + }
194 +
195 ++void
196 ++BeesContext::wait_for_balance()
197 ++{
198 ++ Timer balance_timer;
199 ++ BEESNOTE("WORKAROUND: waiting for balance to stop");
200 ++ while (true) {
201 ++ btrfs_ioctl_balance_args args;
202 ++ memset_zero<btrfs_ioctl_balance_args>(&args);
203 ++ const int ret = ioctl(root_fd(), BTRFS_IOC_BALANCE_PROGRESS, &args);
204 ++ if (ret < 0) {
205 ++ // Either can't get balance status or not running, exit either way
206 ++ break;
207 ++ }
208 ++
209 ++ if (!(args.state & BTRFS_BALANCE_STATE_RUNNING)) {
210 ++ // Balance not running, doesn't matter if paused or cancelled
211 ++ break;
212 ++ }
213 ++
214 ++ BEESLOGDEBUG("WORKAROUND: Waiting " << balance_timer << "s for balance to stop");
215 ++ sleep(BEES_BALANCE_POLL_INTERVAL);
216 ++ }
217 ++}
218 ++
219 + BeesResolveAddrResult
220 + BeesContext::resolve_addr_uncached(BeesAddress addr)
221 + {
222 + THROW_CHECK1(invalid_argument, addr, !addr.is_magic());
223 + THROW_CHECK0(invalid_argument, !!root_fd());
224 ++
225 ++ // Is there a bug where resolve and balance cause a crash (BUG_ON at fs/btrfs/ctree.c:1227)?
226 ++ // Apparently yes, and more than one.
227 ++ // Wait for the balance to finish before we run LOGICAL_INO
228 ++ wait_for_balance();
229 ++
230 ++ // Time how long this takes
231 + Timer resolve_timer;
232 +
233 + // There is no performance benefit if we restrict the buffer size.
234 +diff --git a/src/bees.h b/src/bees.h
235 +index da87d88..5c9375c 100644
236 +--- a/src/bees.h
237 ++++ b/src/bees.h
238 +@@ -114,6 +114,9 @@ const size_t BEES_TRANSID_FACTOR = 10;
239 + // The actual limit in LOGICAL_INO seems to be 2730, but let's leave a little headroom
240 + const size_t BEES_MAX_EXTENT_REF_COUNT = 2560;
241 +
242 ++// Wait this long for a balance to stop
243 ++const double BEES_BALANCE_POLL_INTERVAL = 60.0;
244 ++
245 + // Flags
246 + const int FLAGS_OPEN_COMMON = O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC | O_NOATIME | O_LARGEFILE | O_NOCTTY;
247 + const int FLAGS_OPEN_DIR = FLAGS_OPEN_COMMON | O_RDONLY | O_DIRECTORY;
248 +@@ -708,6 +711,7 @@ class BeesContext : public enable_shared_from_this<BeesContext> {
249 + void set_root_fd(Fd fd);
250 +
251 + BeesResolveAddrResult resolve_addr_uncached(BeesAddress addr);
252 ++ void wait_for_balance();
253 +
254 + BeesFileRange scan_one_extent(const BeesFileRange &bfr, const Extent &e);
255 + void rewrite_file_range(const BeesFileRange &bfr);
256 +--
257 +2.23.0
258 +