Eliminate reserveSpace flag
This commit is contained in:
		
							parent
							
								
									5a64e66268
								
							
						
					
					
						commit
						28e7e29abd
					
				
					 10 changed files with 33 additions and 37 deletions
				
			
		|  | @ -608,6 +608,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) | |||
| 
 | ||||
|     state.shouldDelete = options.action == GCOptions::gcDeleteDead || options.action == GCOptions::gcDeleteSpecific; | ||||
| 
 | ||||
|     if (state.shouldDelete && pathExists(reservedPath)) | ||||
|         deletePath(reservedPath); | ||||
| 
 | ||||
|     /* Acquire the global GC root.  This prevents
 | ||||
|        a) New roots from being added. | ||||
|        b) Processes from creating new temporary root files. */ | ||||
|  |  | |||
|  | @ -216,8 +216,9 @@ void checkStoreNotSymlink() | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| LocalStore::LocalStore(bool reserveSpace) | ||||
|     : didSetSubstituterEnv(false) | ||||
| LocalStore::LocalStore() | ||||
|     : reservedPath(settings.nixDBPath + "/reserved") | ||||
|     , didSetSubstituterEnv(false) | ||||
| { | ||||
|     schemaPath = settings.nixDBPath + "/schema"; | ||||
| 
 | ||||
|  | @ -276,25 +277,20 @@ LocalStore::LocalStore(bool reserveSpace) | |||
|        needed, we reserve some dummy space that we can free just | ||||
|        before doing a garbage collection. */ | ||||
|     try { | ||||
|         Path reservedPath = settings.nixDBPath + "/reserved"; | ||||
|         if (reserveSpace) { | ||||
|             struct stat st; | ||||
|             if (stat(reservedPath.c_str(), &st) == -1 || | ||||
|                 st.st_size != settings.reservedSize) | ||||
|             { | ||||
|                 AutoCloseFD fd = open(reservedPath.c_str(), O_WRONLY | O_CREAT, 0600); | ||||
|                 int res = -1; | ||||
|         struct stat st; | ||||
|         if (stat(reservedPath.c_str(), &st) == -1 || | ||||
|             st.st_size != settings.reservedSize) | ||||
|         { | ||||
|             AutoCloseFD fd = open(reservedPath.c_str(), O_WRONLY | O_CREAT, 0600); | ||||
|             int res = -1; | ||||
| #if HAVE_POSIX_FALLOCATE | ||||
|                 res = posix_fallocate(fd, 0, settings.reservedSize); | ||||
|             res = posix_fallocate(fd, 0, settings.reservedSize); | ||||
| #endif | ||||
|                 if (res == -1) { | ||||
|                     writeFull(fd, string(settings.reservedSize, 'X')); | ||||
|                     ftruncate(fd, settings.reservedSize); | ||||
|                 } | ||||
|             if (res == -1) { | ||||
|                 writeFull(fd, string(settings.reservedSize, 'X')); | ||||
|                 ftruncate(fd, settings.reservedSize); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|             deletePath(reservedPath); | ||||
|     } catch (SysError & e) { /* don't care about errors */ | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -88,11 +88,13 @@ private: | |||
| 
 | ||||
|     Path linksDir; | ||||
| 
 | ||||
|     Path reservedPath; | ||||
| 
 | ||||
| public: | ||||
| 
 | ||||
|     /* Initialise the local store, upgrading the schema if
 | ||||
|        necessary. */ | ||||
|     LocalStore(bool reserveSpace = true); | ||||
|     LocalStore(); | ||||
| 
 | ||||
|     ~LocalStore(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -49,7 +49,7 @@ RemoteStore::RemoteStore(size_t maxConnections) | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| ref<RemoteStore::Connection> RemoteStore::openConnection(bool reserveSpace) | ||||
| ref<RemoteStore::Connection> RemoteStore::openConnection() | ||||
| { | ||||
|     auto conn = make_ref<Connection>(); | ||||
| 
 | ||||
|  | @ -106,7 +106,7 @@ ref<RemoteStore::Connection> RemoteStore::openConnection(bool reserveSpace) | |||
|         } | ||||
| 
 | ||||
|         if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 11) | ||||
|             conn->to << reserveSpace; | ||||
|             conn->to << false; | ||||
| 
 | ||||
|         conn->processStderr(); | ||||
|     } | ||||
|  |  | |||
|  | @ -106,7 +106,7 @@ private: | |||
| 
 | ||||
|     ref<Pool<Connection>> connections; | ||||
| 
 | ||||
|     ref<Connection> openConnection(bool reserveSpace = true); | ||||
|     ref<Connection> openConnection(); | ||||
| 
 | ||||
|     void setOptions(ref<Connection> conn); | ||||
| }; | ||||
|  |  | |||
|  | @ -320,7 +320,7 @@ void Store::exportPaths(const Paths & paths, | |||
| namespace nix { | ||||
| 
 | ||||
| 
 | ||||
| ref<Store> openStoreAt(const std::string & uri, bool reserveSpace) | ||||
| ref<Store> openStoreAt(const std::string & uri) | ||||
| { | ||||
|     if (std::string(uri, 0, 7) == "file://") { | ||||
|         auto store = make_ref<LocalBinaryCacheStore>(std::shared_ptr<Store>(0), | ||||
|  | @ -345,13 +345,13 @@ ref<Store> openStoreAt(const std::string & uri, bool reserveSpace) | |||
| 
 | ||||
|     return mode == mDaemon | ||||
|         ? (ref<Store>) make_ref<RemoteStore>() | ||||
|         : (ref<Store>) make_ref<LocalStore>(reserveSpace); | ||||
|         : (ref<Store>) make_ref<LocalStore>(); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| ref<Store> openStore(bool reserveSpace) | ||||
| ref<Store> openStore() | ||||
| { | ||||
|     return openStoreAt(getEnv("NIX_REMOTE"), reserveSpace); | ||||
|     return openStoreAt(getEnv("NIX_REMOTE")); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -432,16 +432,12 @@ void removeTempRoots(); | |||
| 
 | ||||
|    If ‘uri’ is empty, it defaults to ‘direct’ or ‘daemon’ depending on | ||||
|    whether the user has write access to the local Nix store/database. | ||||
| 
 | ||||
|    The Boolean ‘reserveSpace’ denotes whether some disk space should | ||||
|    be reserved to enable future garbage collector runs. It should be | ||||
|    set to true *unless* you're going to collect garbage. | ||||
| */ | ||||
| ref<Store> openStoreAt(const std::string & uri, bool reserveSpace = true); | ||||
|    set to true *unless* you're going to collect garbage. */ | ||||
| ref<Store> openStoreAt(const std::string & uri); | ||||
| 
 | ||||
| 
 | ||||
| /* Open the store indicated by the ‘NIX_REMOTE’ environment variable. */ | ||||
| ref<Store> openStore(bool reserveSpace = true); | ||||
| ref<Store> openStore(); | ||||
| 
 | ||||
| 
 | ||||
| /* Display a set of paths in human-readable form (i.e., between quotes
 | ||||
|  |  | |||
|  | @ -82,7 +82,7 @@ int main(int argc, char * * argv) | |||
| 
 | ||||
|         // Run the actual garbage collector.
 | ||||
|         if (!dryRun) { | ||||
|             auto store = openStore(false); | ||||
|             auto store = openStore(); | ||||
|             options.action = GCOptions::gcDeleteDead; | ||||
|             GCResults results; | ||||
|             PrintFreed freed(true, results); | ||||
|  |  | |||
|  | @ -562,9 +562,8 @@ static void processConnection(bool trusted) | |||
|     if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) | ||||
|         setAffinityTo(readInt(from)); | ||||
| 
 | ||||
|     bool reserveSpace = true; | ||||
|     if (GET_PROTOCOL_MINOR(clientVersion) >= 11) | ||||
|         reserveSpace = readInt(from) != 0; | ||||
|         readInt(from); // obsolete reserveSpace
 | ||||
| 
 | ||||
|     /* Send startup error messages to the client. */ | ||||
|     startWork(); | ||||
|  | @ -582,7 +581,7 @@ static void processConnection(bool trusted) | |||
| #endif | ||||
| 
 | ||||
|         /* Open the store. */ | ||||
|         auto store = make_ref<LocalStore>(reserveSpace); | ||||
|         auto store = make_ref<LocalStore>(); | ||||
| 
 | ||||
|         stopWork(); | ||||
|         to.flush(); | ||||
|  |  | |||
|  | @ -1131,7 +1131,7 @@ int main(int argc, char * * argv) | |||
|         if (!op) throw UsageError("no operation specified"); | ||||
| 
 | ||||
|         if (op != opDump && op != opRestore) /* !!! hack */ | ||||
|             store = openStore(op != opGC); | ||||
|             store = openStore(); | ||||
| 
 | ||||
|         op(opFlags, opArgs); | ||||
|     }); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue