From 07c9edb58fe00666213579cad0877dc7a4883e7a Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Fri, 2 Aug 2019 10:24:57 -0700 Subject: [PATCH] scoutfs: warn on compaction stale seg reads It's possible to trigger stale segment reads during compaction. This shouldn't be possible during regular operation because the server protects the input segments while the compaction is pending. Stale segment reads can only happen to client reads which aren't serialized with segment allocation and writes. Warn if we see a stale segment read during compaction. It means that we either have a bug in the server or someone armed a stale segment read trigger that hit compaction. Signed-off-by: Zach Brown --- kmod/src/compact.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kmod/src/compact.c b/kmod/src/compact.c index cfca5fd8..b220a771 100644 --- a/kmod/src/compact.c +++ b/kmod/src/compact.c @@ -608,8 +608,10 @@ static int prepare_curs(struct super_block *sb, struct compact_cursor *curs, * segments, then generating the response that describes the output * segments. * - * The server will either commit our response or cleanup the request - * if we return an error that the caller sends in response. + * The server will either commit our response or cleanup the request if + * we return an error that the caller sends in response. The server + * protects the input segments so they shouldn't be overwritten by other + * compactions or allocations. We shouldn't get stale segment reads. */ int scoutfs_compact(struct super_block *sb, struct scoutfs_net_compact_request *req, @@ -668,8 +670,11 @@ int scoutfs_compact(struct super_block *sb, ret = 0; out: - if (ret == -ESTALE) + /* server protects input segments, shouldn't be possible */ + if (WARN_ON_ONCE(ret == -ESTALE)) { scoutfs_inc_counter(sb, compact_stale_error); + ret = -EIO; + } free_cseg_list(sb, &curs.csegs); free_cseg_list(sb, &results);