From 78d04b141761f438723631b162a3102007ef3038 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sat, 11 Nov 2017 14:48:34 -0500 Subject: [PATCH 1/7] chatter: use static function to control timestamping behavior Use a static function instead of embedding side-effects in the constructor of an unrelated class. Signed-off-by: Zygo Blaxell (cherry picked from commit 85106bd9a9fb3be2c574df1a3aed6674e3951465) --- include/crucible/chatter.h | 7 ++----- lib/chatter.cc | 15 ++++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/crucible/chatter.h b/include/crucible/chatter.h index e42620e..f00e1e4 100644 --- a/include/crucible/chatter.h +++ b/include/crucible/chatter.h @@ -45,6 +45,8 @@ namespace crucible { template Chatter &operator<<(const T& arg); ~Chatter(); + + static void enable_timestamp(bool prefix_timestamp); }; template @@ -86,11 +88,6 @@ namespace crucible { } }; - class ChatterTimestamp { - public: - ChatterTimestamp(int); - }; - class ChatterBox { string m_file; int m_line; diff --git a/lib/chatter.cc b/lib/chatter.cc index 60dbb61..696c274 100644 --- a/lib/chatter.cc +++ b/lib/chatter.cc @@ -17,7 +17,7 @@ namespace crucible { static shared_ptr> chatter_names; static const char *SPACETAB = " \t"; - static int chatter_prefix_timestamp = 1; + static bool add_prefix_timestamp = true; static void @@ -49,11 +49,17 @@ namespace crucible { { } + void + Chatter::enable_timestamp(bool prefix_timestamp) + { + add_prefix_timestamp = prefix_timestamp; + } + Chatter::~Chatter() { ostringstream header_stream; - if (chatter_prefix_timestamp) { + if (add_prefix_timestamp) { time_t ltime; DIE_IF_MINUS_ONE(time(<ime)); struct tm ltm; @@ -97,11 +103,6 @@ namespace crucible { c.m_oss.str(""); } - ChatterTimestamp::ChatterTimestamp(int prefix_timestamp) - { - chatter_prefix_timestamp = prefix_timestamp; - } - set ChatterBox::s_boxes; set& ChatterBox::all_boxes() From 71514e72295d5833c85eb0fa5bda4073d54c660f Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sat, 11 Nov 2017 14:49:53 -0500 Subject: [PATCH 2/7] main: use static function to control timestamps in log output Adjust bees to match changes in Chatter's interface. Signed-off-by: Zygo Blaxell (cherry picked from commit 66fd28830d42acbd837dfb08b89a1f9c05c6d474) --- src/bees.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bees.cc b/src/bees.cc index a79d1fc..9458c91 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -598,7 +598,7 @@ bees_main(int argc, char *argv[]) THROW_CHECK1(invalid_argument, argc, argc >= 0); // Defaults - int chatter_prefix_timestamp = 1; + bool chatter_prefix_timestamp = true; // Parse options int c; @@ -617,10 +617,10 @@ bees_main(int argc, char *argv[]) switch (c) { case 'T': - chatter_prefix_timestamp = 0; + chatter_prefix_timestamp = false; break; case 't': - chatter_prefix_timestamp = 1; + chatter_prefix_timestamp = true; break; case 'h': do_cmd_help(argv); @@ -629,7 +629,7 @@ bees_main(int argc, char *argv[]) } } - ChatterTimestamp cts(chatter_prefix_timestamp); + Chatter::enable_timestamp(chatter_prefix_timestamp); // Create a context and start crawlers bool did_subscription = false; From bfb768a07960163e0db8a81acff89f8e3b46f58d Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 14 Nov 2017 06:53:48 +0100 Subject: [PATCH 3/7] Fix a fallthrough error in GCC 7+ GCC 7 and higher turn a previous warning into an error for implicit fallthrough. Let's hint the compiler that this is intentional here. Signed-off-by: Kai Krakow (cherry picked from commit 270a91cf17783813edaa75fb9766858dcf8e1689) --- src/bees.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bees.cc b/src/bees.cc index 9458c91..63a39db 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -623,7 +623,7 @@ bees_main(int argc, char *argv[]) chatter_prefix_timestamp = true; break; case 'h': - do_cmd_help(argv); + do_cmd_help(argv); // fallthrough default: return 2; } From 40112faf0f2d21c6c9f8ef3442583a5d824cbd96 Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Thu, 21 Dec 2017 13:26:45 +0300 Subject: [PATCH 4/7] Makefile add scripts target for correctly packaging Currently scheme lead to path like: /tmp/makepkg/bees-git/pkg/bees-git/usr/lib/bees/bees While packaging, so allow do: make make scripts make install ... make install_scripts ... Signed-off-by: Timofey Titovets --- Makefile | 9 +++++++-- scripts/{beesd@.service => beesd@.service.in} | 0 2 files changed, 7 insertions(+), 2 deletions(-) rename scripts/{beesd@.service => beesd@.service.in} (100%) diff --git a/Makefile b/Makefile index 11567ec..c856be8 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,11 @@ test: lib src scripts/beesd: scripts/beesd.in sed -e's#@LIBEXEC_PREFIX@#$(LIBEXEC_PREFIX)#' -e's#@PREFIX@#$(PREFIX)#' "$<" >"$@" +scripts/beesd@.service: scripts/beesd@.service.in + sed -e's#@LIBEXEC_PREFIX@#$(LIBEXEC_PREFIX)#' -e's#@PREFIX@#$(PREFIX)#' "$<" >"$@" + +scripts: scripts/beesd scripts/beesd@.service + README.html: README.md $(MARKDOWN) README.md > README.html.new mv -f README.html.new README.html @@ -35,10 +40,10 @@ README.html: README.md install: ## Install bees + libs install: lib src test install -Dm644 lib/libcrucible.so $(PREFIX)/usr/lib/libcrucible.so - install -Dm755 bin/bees $(LIBEXEC_PREFIX)/bees + install -Dm755 bin/bees $(LIBEXEC_PREFIX)/bees install_scripts: ## Install scipts -install_scripts: scripts/beesd +install_scripts: install -Dm755 scripts/beesd $(PREFIX)/usr/sbin/beesd install -Dm644 scripts/beesd.conf.sample $(PREFIX)/etc/bees/beesd.conf.sample install -Dm644 scripts/beesd@.service $(PREFIX)/lib/systemd/system/beesd@.service diff --git a/scripts/beesd@.service b/scripts/beesd@.service.in similarity index 100% rename from scripts/beesd@.service rename to scripts/beesd@.service.in From 649ae5bb40d2bd594b5db42bbca84fab2bf9d154 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 26 Jan 2017 22:08:02 -0500 Subject: [PATCH 5/7] makeflags: fix missing -D_FILE_OFFSET_BITS=64 in comment Interesting things happen when blindly swapping the release-build CCFLAGS with the debug-build commented-out CCFLAGS. None of these things that happen are good. Signed-off-by: Zygo Blaxell --- makeflags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makeflags b/makeflags index d1f6dcf..f5983cb 100644 --- a/makeflags +++ b/makeflags @@ -1,4 +1,4 @@ CCFLAGS = -Wall -Wextra -Werror -O3 -march=native -I../include -ggdb -fpic -D_FILE_OFFSET_BITS=64 -# CCFLAGS = -Wall -Wextra -Werror -O0 -I../include -ggdb -fpic +# CCFLAGS = -Wall -Wextra -Werror -O0 -I../include -ggdb -fpic -D_FILE_OFFSET_BITS=64 CFLAGS = $(CCFLAGS) -std=c99 CXXFLAGS = $(CCFLAGS) -std=c++11 -Wold-style-cast From 77614a0e99abbfa7942d842999198338409b39b1 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 21 Dec 2017 13:32:08 -0500 Subject: [PATCH 6/7] scan: insert toxic matched extents into hash table as they are discovered When a toxic extent is discovered, insert the offending hash/address/toxic entry into the hash table. When a previously discovered toxic extent is encountered, do nothing, i.e. allow the offending hash/address/toxic entry in the hash table to expire. Previously both inserts were removed from the code, but the former one is required. The latter prevents bees from forgiving toxic extents (or any hash matching one) should they be relocated, deleted, or simply become non-toxic. Signed-off-by: Zygo Blaxell --- src/bees-context.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/bees-context.cc b/src/bees-context.cc index e18711f..9823011 100644 --- a/src/bees-context.cc +++ b/src/bees-context.cc @@ -431,6 +431,7 @@ BeesContext::scan_one_extent(const BeesFileRange &bfr, const Extent &e) if (found_addr.is_toxic()) { BEESINFO("WORKAROUND: abandoned toxic match for hash " << hash << " addr " << found_addr); // Don't push these back in because we'll never delete them. + // Extents may become non-toxic so give them a chance to expire. // hash_table->push_front_hash_addr(hash, found_addr); BEESCOUNT(scan_toxic_hash); return bfr; @@ -447,12 +448,10 @@ BeesContext::scan_one_extent(const BeesFileRange &bfr, const Extent &e) if (resolved.is_toxic()) { BEESINFO("WORKAROUND: abandoned toxic match at found_addr " << found_addr << " matching bbd " << bbd); BEESCOUNT(scan_toxic_match); -#if 0 - // Don't push these back in because we'll never delete them. - // Make sure we never see this hash again + // Make sure we never see this hash again. + // It has become toxic since it was inserted into the hash table. found_addr.set_toxic(); hash_table->push_front_hash_addr(hash, found_addr); -#endif abandon_extent = true; } else if (!resolved.count()) { BEESCOUNT(scan_resolve_zero); From 07751885d2d92595edb7214d22f50507cb87bc5e Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 21 Dec 2017 14:00:17 -0500 Subject: [PATCH 7/7] error: drop redundant CHECK_CONSTRAINT CHECK_CONSTRAINT is just THROW_CHECK1 with an inconsistent name. Remove it. Signed-off-by: Zygo Blaxell --- include/crucible/error.h | 6 ------ lib/fs.cc | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/include/crucible/error.h b/include/crucible/error.h index 0b57869..170b5ba 100644 --- a/include/crucible/error.h +++ b/include/crucible/error.h @@ -100,12 +100,6 @@ namespace crucible { } while (0) // macros for checking a constraint -#define CHECK_CONSTRAINT(value, expr) do { \ - if (!(expr)) { \ - THROW_ERROR(out_of_range, #value << " = " << value << " failed constraint check (" << #expr << ")"); \ - } \ -} while(0) - #define THROW_CHECK0(type, expr) do { \ if (!(expr)) { \ THROW_ERROR(type, "failed constraint check (" << #expr << ")"); \ diff --git a/lib/fs.cc b/lib/fs.cc index 366934f..5e49544 100644 --- a/lib/fs.cc +++ b/lib/fs.cc @@ -625,7 +625,7 @@ namespace crucible { void Fiemap::do_ioctl(int fd) { - CHECK_CONSTRAINT(m_min_count, m_min_count <= m_max_count); + THROW_CHECK1(out_of_range, m_min_count, m_min_count <= m_max_count); auto extent_count = m_min_count; vector ioctl_arg = vector_copy_struct(this);