From: Simon Schubert Date: Tue, 4 Aug 2009 14:23:57 +0000 (+0200) Subject: hammer util: avoid running concurrent cleanups X-Git-Tag: v2.4.0~295^2~7 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/5bd5f172451bff7c7aea85c80d7e60b825fcd742 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. --- 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); /*