... |
... |
@@ -197,30 +197,54 @@ class Context(): |
197
|
197
|
"\nValid values are, for example: 800M 10G 1T 50%\n"
|
198
|
198
|
.format(str(e))) from e
|
199
|
199
|
|
200
|
|
- # If we are asked not to set a quota, we set it to the maximum
|
201
|
|
- # disk space available minus a headroom of 2GB, such that we
|
202
|
|
- # at least try to avoid raising Exceptions.
|
|
200
|
+ if 'BST_TEST_SUITE' in os.environ:
|
|
201
|
+ headroom = 0
|
|
202
|
+ else:
|
|
203
|
+ headroom = 2e9
|
|
204
|
+
|
|
205
|
+ stat = os.statvfs(artifactdir_volume)
|
|
206
|
+ available_space = (stat.f_bsize * stat.f_bavail)
|
|
207
|
+ # Place a slight headroom (2e9 (2GB) on the cache_quota) into
|
|
208
|
+ # bst_available_space to try and avoid exceptions.
|
203
|
209
|
#
|
204
|
210
|
# Of course, we might still end up running out during a build
|
205
|
211
|
# if we end up writing more than 2G, but hey, this stuff is
|
206
|
212
|
# already really fuzzy.
|
207
|
213
|
#
|
208
|
|
- if cache_quota is None:
|
209
|
|
- stat = os.statvfs(artifactdir_volume)
|
210
|
|
- # Again, the artifact directory may not yet have been
|
211
|
|
- # created
|
212
|
|
- if not os.path.exists(self.artifactdir):
|
213
|
|
- cache_size = 0
|
214
|
|
- else:
|
215
|
|
- cache_size = utils._get_dir_size(self.artifactdir)
|
216
|
|
- cache_quota = cache_size + stat.f_bsize * stat.f_bavail
|
|
214
|
+ bst_available_space = available_space - headroom
|
217
|
215
|
|
218
|
|
- if 'BST_TEST_SUITE' in os.environ:
|
219
|
|
- headroom = 0
|
|
216
|
+ # Again, the artifact directory may not yet have been created yet
|
|
217
|
+ #
|
|
218
|
+ if not os.path.exists(self.artifactdir):
|
|
219
|
+ cache_size = 0
|
220
|
220
|
else:
|
221
|
|
- headroom = 2e9
|
|
221
|
+ cache_size = utils._get_dir_size(self.artifactdir)
|
222
|
222
|
|
223
|
|
- self.cache_quota = cache_quota - headroom
|
|
223
|
+ # Ensure system has enough storage for the cache_quota
|
|
224
|
+ #
|
|
225
|
+ # If cache_quota is none, set it to the maximum it could possibly be.
|
|
226
|
+ #
|
|
227
|
+ if cache_quota is None: # Infinity, set to max system storage
|
|
228
|
+ cache_quota = cache_size + available_space
|
|
229
|
+ elif cache_quota < headroom:
|
|
230
|
+ raise LoadError(LoadErrorReason.INVALID_DATA,
|
|
231
|
+ "Invalid cache quota ({}): ".format(utils._pretty_size(cache_quota)) +
|
|
232
|
+ "BuildStream requires a minimum cache quota of 2GB.")
|
|
233
|
+ elif cache_size + cache_quota > bst_available_space:
|
|
234
|
+ raise LoadError(LoadErrorReason.INVALID_DATA,
|
|
235
|
+ ("Your system does not have enough available " +
|
|
236
|
+ "space to support the cache quota specified.\n" +
|
|
237
|
+ "You currently have:\n" +
|
|
238
|
+ "- {used} of cache in use at {local_cache_path}\n" +
|
|
239
|
+ "- {available} of available system storage.\n" +
|
|
240
|
+ "Note: BuildStream requires the cache quota be at least {headroom} " +
|
|
241
|
+ "smaller than your available system storage").format(
|
|
242
|
+ used=utils._pretty_size(cache_size),
|
|
243
|
+ local_cache_path=self.artifactdir,
|
|
244
|
+ available=utils._pretty_size(available_space),
|
|
245
|
+ headroom=utils._pretty_size(headroom)))
|
|
246
|
+
|
|
247
|
+ self.cache_quota = cache_quota
|
224
|
248
|
self.cache_lower_threshold = self.cache_quota / 2
|
225
|
249
|
|
226
|
250
|
# Load artifact share configuration
|