From 5bd5f172451bff7c7aea85c80d7e60b825fcd742 Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Tue, 4 Aug 2009 16:23:57 +0200 Subject: [PATCH] hammer util: avoid running concurrent cleanups If hammer cleanup gets called more frequently than the cleanup runs take, they build up, all trying to run in parallel. Prevent this by locking the config file while cleanup is running. If cleanup finds the config file locked for a PFS, it will skip processing. --- sbin/hammer/cmd_cleanup.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sbin/hammer/cmd_cleanup.c b/sbin/hammer/cmd_cleanup.c index 0cd1f09ceb..f1ffd9cb16 100644 --- a/sbin/hammer/cmd_cleanup.c +++ b/sbin/hammer/cmd_cleanup.c @@ -249,6 +249,15 @@ do_cleanup(const char *path) return; } + if (flock(fileno(fp), LOCK_EX|LOCK_NB) == -1) { + if (errno == EWOULDBLOCK) + printf(" PFS #%d locked by other process\n", pfs.pfs_id); + else + printf(" can not lock %s: %s\n", config_path, strerror(errno)); + fclose(fp); + return; + } + printf(" handle PFS #%d using %s\n", pfs.pfs_id, snapshots_path); /* -- 2.41.0