From e81aeff391148280d76609e5782bf7f0a115f72e Mon Sep 17 00:00:00 2001 From: Mike Crowe Date: Wed, 11 Aug 2021 15:55:55 +0100 Subject: [PATCH] pseudo: Path mismatch on now-ignored path should not be fatal If a database survives from before a change to PSEUDO_CLIENT_IGNORE_PATH then there's a risk that the now-ignored files have been deleted and their inodes re-used without pseudo noticing. Such files are reported as path mismatches which provoke aborts. Let's check to see whether the database filename would now be ignored, and if so just warn about the mismatch rather than aborting. Unfortunately the test case for this doesn't fit into the existing infrastructure since the server must be restarted during the test. Signed-off-by: Mike Crowe --- pseudo.c | 2 + run_tests.sh | 16 ++++++++ .../standalone-test-newly-ignored-mismatch.sh | 41 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100755 test/standalone-test-newly-ignored-mismatch.sh diff --git a/pseudo.c b/pseudo.c index 528fe1b..30b0a36 100644 --- a/pseudo.c +++ b/pseudo.c @@ -695,6 +695,8 @@ pseudo_op(pseudo_msg_t *msg, const char *program, const char *tag, char **respon */ pseudo_debug(PDBGF_FILE, "inode mismatch for '%s' -- old one was marked for deletion.\n", msg->path); + } else if (path_by_ino && pseudo_client_ignore_path(path_by_ino)) { + pseudo_diag("path mismatch on now-ignored '%s'", path_by_ino); } else { pseudo_diag("path mismatch [%d link%s]: ino %llu db '%s' req '%s'.\n", msg->nlink, diff --git a/run_tests.sh b/run_tests.sh index c637c27..a0b8675 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -48,5 +48,21 @@ do fi rm -rf var/pseudo/* done +for file in test/standalone-test*.sh +do + filename=${file#test/} + let num_tests++ + mkdir -p var/pseudo + $file ${opt_verbose} + if [ "$?" -eq "0" ]; then + let num_passed_tests++ + if [ "${opt_verbose}" == "-v" ]; then + echo "${filename%.sh}: Passed." + fi + else + echo "${filename/%.sh}: Failed." + fi + rm -rf var/pseudo/* +done echo "${num_passed_tests}/${num_tests} test(s) passed." diff --git a/test/standalone-test-newly-ignored-mismatch.sh b/test/standalone-test-newly-ignored-mismatch.sh new file mode 100755 index 0000000..bf7d5f7 --- /dev/null +++ b/test/standalone-test-newly-ignored-mismatch.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# +export PSEUDO_PREFIX=${PWD} +pseudo=bin/pseudo + +trap "rm -rf testdir" EXIT +rm -rf testdir +mkdir testdir || exit 1 + +mkdir -p testdir/to-be-ignored +mkdir -p testdir/not-ignored + +create_files() { + for i in a b c d e f g h i j; do + for j in 0 1 2 3 4 5 6 7 8 9; do + touch testdir/to-be-ignored/$i$j + done + done +} + +test_results() { + for i in a b c d e f g h i j; do + for j in 0 1 2 3 4 5 6 7 8 9; do + touch testdir/not-ignored/$i$j + done + done +} + +export -f create_files +export -f test_results + +export PSEUDO_IGNORE_PATHS=/initial + +$pseudo /bin/bash -c "create_files" +rm testdir/to-be-ignored/* + +# Kill server so that we can change the value of PSEUDO_IGNORE_PATHS +$pseudo -S +PSEUDO_IGNORE_PATHS=${PWD}/testdir/to-be-ignored $pseudo /bin/bash -c "test_results" -- 2.30.2