>From d842f320f0ee911d7d219bba7baa45240edcbe6d Mon Sep 17 00:00:00 2001 From: Roel Janssen Date: Tue, 3 Apr 2018 11:22:16 +0200 Subject: [PATCH] guix-daemon: Add option to disable garbage collection. * nix/libstore/gc.cc: Return early on deleterious functions. * nix/libstore/globals.hh (disableGarbageCollection): New settings variable. * nix/nix-daemon/guix-daemon.cc: Implement new settings variable. * nix/nix-daemon/nix-daemon.cc: Show appropriate message. --- nix/libstore/gc.cc | 20 ++++++++++++++++++++ nix/libstore/globals.hh | 3 +++ nix/nix-daemon/guix-daemon.cc | 6 ++++++ nix/nix-daemon/nix-daemon.cc | 5 +++++ 4 files changed, 34 insertions(+) diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc index 72eff5242..b811cacd1 100644 --- a/nix/libstore/gc.cc +++ b/nix/libstore/gc.cc @@ -393,6 +393,10 @@ bool LocalStore::isActiveTempFile(const GCState & state, void LocalStore::deleteGarbage(GCState & state, const Path & path) { + if (settings.disableGarbageCollection) { + return; + } + unsigned long long bytesFreed; deletePath(path, bytesFreed); state.results.bytesFreed += bytesFreed; @@ -401,6 +405,10 @@ void LocalStore::deleteGarbage(GCState & state, const Path & path) void LocalStore::deletePathRecursive(GCState & state, const Path & path) { + if (settings.disableGarbageCollection) { + return; + } + checkInterrupt(); unsigned long long size = 0; @@ -513,6 +521,10 @@ bool LocalStore::canReachRoot(GCState & state, PathSet & visited, const Path & p void LocalStore::tryToDelete(GCState & state, const Path & path) { + if (settings.disableGarbageCollection) { + return; + } + checkInterrupt(); if (path == linksDir || path == state.trashDir) return; @@ -552,6 +564,10 @@ void LocalStore::tryToDelete(GCState & state, const Path & path) the link count. */ void LocalStore::removeUnusedLinks(const GCState & state) { + if (settings.disableGarbageCollection) { + return; + } + AutoCloseDir dir = opendir(linksDir.c_str()); if (!dir) throw SysError(format("opening directory `%1%'") % linksDir); @@ -595,6 +611,10 @@ void LocalStore::removeUnusedLinks(const GCState & state) void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) { + if (settings.disableGarbageCollection) { + return; + } + GCState state(results); state.options = options; state.trashDir = settings.nixStore + "/trash"; diff --git a/nix/libstore/globals.hh b/nix/libstore/globals.hh index 1293625e1..54e04f218 100644 --- a/nix/libstore/globals.hh +++ b/nix/libstore/globals.hh @@ -218,6 +218,9 @@ struct Settings { /* Whether the importNative primop should be enabled */ bool enableImportNative; + /* Whether the disable garbage collection. */ + bool disableGarbageCollection; + private: SettingsMap settings, overrides; diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc index b71b100f6..13811cd99 100644 --- a/nix/nix-daemon/guix-daemon.cc +++ b/nix/nix-daemon/guix-daemon.cc @@ -89,6 +89,7 @@ builds derivations on behalf of its clients."); #define GUIX_OPT_TIMEOUT 18 #define GUIX_OPT_MAX_SILENT_TIME 19 #define GUIX_OPT_LOG_COMPRESSION 20 +#define GUIX_OPT_DISABLE_GC 21 static const struct argp_option options[] = { @@ -133,6 +134,8 @@ static const struct argp_option options[] = n_("disable automatic file \"deduplication\" in the store") }, { "disable-store-optimization", GUIX_OPT_DISABLE_DEDUPLICATION, 0, OPTION_ALIAS | OPTION_HIDDEN, NULL }, + { "disable-gc", GUIX_OPT_DISABLE_GC, 0, 0, + n_("disable garbage collection.") }, { "impersonate-linux-2.6", GUIX_OPT_IMPERSONATE_LINUX_26, 0, #ifdef HAVE_SYS_PERSONALITY_H @@ -225,6 +228,9 @@ parse_opt (int key, char *arg, struct argp_state *state) case GUIX_OPT_DISABLE_DEDUPLICATION: settings.autoOptimiseStore = false; break; + case GUIX_OPT_DISABLE_GC: + settings.disableGarbageCollection = true; + break; case GUIX_OPT_CACHE_FAILURES: settings.cacheFailure = true; break; diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc index deb7003d7..5af8ec796 100644 --- a/nix/nix-daemon/nix-daemon.cc +++ b/nix/nix-daemon/nix-daemon.cc @@ -529,6 +529,11 @@ static void performOp(bool trusted, unsigned int clientVersion, } case wopCollectGarbage: { + if (settings.disableGarbageCollection) { + throw Error("Garbage collection is disabled."); + break; + } + GCOptions options; options.action = (GCOptions::GCAction) readInt(from); options.pathsToDelete = readStorePaths(from); -- 2.16.1