From 28759f32698e9bc52a0697f3da1191604be68ef0 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 16 Jun 2021 15:52:08 -0700 Subject: [PATCH] Rotate srch files as log trees items are reclaimed The log merging work deletes log trees items once their item roots are merged back into the fs root. Those deleted items could still have populated srch files that would be lost. We force rotation of the srch files in the items as they're reclaimed to turn them into rotated srch files that can be compacted. Signed-off-by: Zach Brown --- kmod/src/server.c | 14 ++++++++++++-- kmod/src/srch.c | 5 +++-- kmod/src/srch.h | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/kmod/src/server.c b/kmod/src/server.c index 15d3f6ed..9e8307b8 100644 --- a/kmod/src/server.c +++ b/kmod/src/server.c @@ -823,7 +823,7 @@ static int server_commit_log_trees(struct super_block *sb, /* try to rotate the srch log when big enough */ mutex_lock(&server->srch_mutex); ret = scoutfs_srch_rotate_log(sb, &server->alloc, &server->wri, - &super->srch_root, <.srch_file); + &super->srch_root, <.srch_file, false); mutex_unlock(&server->srch_mutex); if (ret < 0) { scoutfs_err(sb, "server error, rotating srch log: %d", ret); @@ -922,6 +922,16 @@ static int reclaim_open_log_tree(struct super_block *sb, u64 rid) goto out; } + /* for srch log file rotation if it's populated */ + mutex_lock(&server->srch_mutex); + ret = scoutfs_srch_rotate_log(sb, &server->alloc, &server->wri, + &super->srch_root, <.srch_file, true); + mutex_unlock(&server->srch_mutex); + if (ret < 0) { + scoutfs_err(sb, "server error, reclaim rotating srch log: %d", ret); + goto out; + } + /* * All of these can return errors after having modified the * allocator trees. We have to try and update the roots in the @@ -944,7 +954,7 @@ static int reclaim_open_log_tree(struct super_block *sb, u64 rid) err = scoutfs_btree_update(sb, &server->alloc, &server->wri, &super->logs_root, &key, <, sizeof(lt)); - BUG_ON(err != 0); /* alloc and log item roots out of sync */ + BUG_ON(err != 0); /* alloc, log, srch items out of sync */ out: mutex_unlock(&server->logs_mutex); diff --git a/kmod/src/srch.c b/kmod/src/srch.c index 372be7fe..9fbaaeb7 100644 --- a/kmod/src/srch.c +++ b/kmod/src/srch.c @@ -989,12 +989,13 @@ int scoutfs_srch_rotate_log(struct super_block *sb, struct scoutfs_alloc *alloc, struct scoutfs_block_writer *wri, struct scoutfs_btree_root *root, - struct scoutfs_srch_file *sfl) + struct scoutfs_srch_file *sfl, bool force) { struct scoutfs_key key; int ret; - if (le64_to_cpu(sfl->blocks) < SCOUTFS_SRCH_LOG_BLOCK_LIMIT) + if (sfl->ref.blkno == 0 || + (!force && le64_to_cpu(sfl->blocks) < SCOUTFS_SRCH_LOG_BLOCK_LIMIT)) return 0; init_srch_key(&key, SCOUTFS_SRCH_LOG_TYPE, diff --git a/kmod/src/srch.h b/kmod/src/srch.h index 69448ab3..7f30f04c 100644 --- a/kmod/src/srch.h +++ b/kmod/src/srch.h @@ -37,7 +37,7 @@ int scoutfs_srch_rotate_log(struct super_block *sb, struct scoutfs_alloc *alloc, struct scoutfs_block_writer *wri, struct scoutfs_btree_root *root, - struct scoutfs_srch_file *sfl); + struct scoutfs_srch_file *sfl, bool force); int scoutfs_srch_get_compact(struct super_block *sb, struct scoutfs_alloc *alloc, struct scoutfs_block_writer *wri,