Skip to content

Commit 1a8e56e

Browse files
author
Hendrik Muhs
committed
[ML] Fix deletion forecast overflow (elastic#110)
Use forecast ID to create a subdirectory when overflowing models to disk for forecasting. This fixes a failing 2nd forecast call because the 1st one deleted the tmp directory.
1 parent af9b29e commit 1a8e56e

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

lib/api/CForecastRunner.cc

+4
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ bool CForecastRunner::pushForecastJob(const std::string& controlMessage,
350350
LOG_INFO(<< "Forecast of large model requested (requires "
351351
<< std::to_string(1 + (totalMemoryUsage >> 20)) << " MB), using disk.");
352352

353+
// create a subdirectory using the unique forecast id
354+
temporaryFolder /= forecastJob.s_ForecastId;
355+
forecastJob.s_TemporaryFolder = temporaryFolder.string();
356+
353357
boost::system::error_code errorCode;
354358
boost::filesystem::create_directories(temporaryFolder, errorCode);
355359
if (errorCode) {

lib/seccomp/CSystemCallFilter_Linux.cc

+16-15
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,27 @@ const struct sock_filter FILTER[] = {
5151
// Load the system call number into accumulator
5252
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SECCOMP_DATA_NR_OFFSET),
5353
// Only applies to X86_64 arch. Jump to disallow for calls using the x32 ABI
54-
BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, UPPER_NR_LIMIT, 34, 0),
54+
BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, UPPER_NR_LIMIT, 35, 0),
5555
// If any sys call filters are added or removed then the jump
5656
// destination for each statement including the one above must
5757
// be updated accordingly
5858

5959
// Allowed sys calls, jump to return allow on match
60-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_read, 34, 0),
61-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_write, 33, 0),
62-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_writev, 32, 0),
63-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_lseek, 31, 0),
64-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_lstat, 30, 0),
65-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_readlink, 29, 0),
66-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_stat, 28, 0),
67-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_fstat, 27, 0),
68-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_open, 26, 0),
69-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_close, 25, 0),
70-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_connect, 24, 0),
71-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_clone, 23, 0),
72-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_statfs, 22, 0),
73-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_dup2, 21, 0),
60+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_read, 35, 0),
61+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_write, 34, 0),
62+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_writev, 33, 0),
63+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_lseek, 32, 0),
64+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_lstat, 31, 0),
65+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_readlink, 30, 0),
66+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_stat, 29, 0),
67+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_fstat, 28, 0),
68+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_open, 27, 0),
69+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_close, 26, 0),
70+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_connect, 25, 0),
71+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_clone, 24, 0),
72+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_statfs, 23, 0),
73+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_dup2, 22, 0),
74+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_mkdir, 21, 0), // for forecast temp storage
7475
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_rmdir, 20, 0), // for forecast temp storage
7576
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_getdents, 19, 0), // for forecast temp storage
7677
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_openat, 18, 0), // for forecast temp storage

lib/seccomp/unittest/CSystemCallFilterTest.cc

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
#include <test/CTestTmpDir.h>
2020

21+
#include <boost/filesystem.hpp>
22+
#include <boost/system/error_code.hpp>
23+
2124
#include <cstdlib>
2225
#include <string>
2326

@@ -172,6 +175,8 @@ void CSystemCallFilterTest::testSystemCallFilter() {
172175
// Operations that must function after seccomp is initialised
173176
openPipeAndRead(readPipeName);
174177
openPipeAndWrite(writePipeName);
178+
179+
makeAndRemoveDirectory(ml::test::CTestTmpDir::tmpDir());
175180
}
176181

177182
void CSystemCallFilterTest::openPipeAndRead(const std::string& filename) {
@@ -229,3 +234,15 @@ void CSystemCallFilterTest::openPipeAndWrite(const std::string& filename) {
229234
CPPUNIT_ASSERT_EQUAL(TEST_SIZE, threadReader.data().length());
230235
CPPUNIT_ASSERT_EQUAL(std::string(TEST_SIZE, TEST_CHAR), threadReader.data());
231236
}
237+
238+
void CSystemCallFilterTest::makeAndRemoveDirectory(const std::string& dirname) {
239+
240+
boost::filesystem::path temporaryFolder(dirname);
241+
temporaryFolder /= "test-directory";
242+
243+
boost::system::error_code errorCode;
244+
boost::filesystem::create_directories(temporaryFolder, errorCode);
245+
CPPUNIT_ASSERT(errorCode == 0);
246+
boost::filesystem::remove_all(temporaryFolder, errorCode);
247+
CPPUNIT_ASSERT(errorCode == 0);
248+
}

lib/seccomp/unittest/CSystemCallFilterTest.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CSystemCallFilterTest : public CppUnit::TestFixture {
1919
private:
2020
void openPipeAndRead(const std::string& filename);
2121
void openPipeAndWrite(const std::string& filename);
22+
void makeAndRemoveDirectory(const std::string& dirname);
2223
};
2324

2425
#endif // INCLUDED_CSystemCallFilterTest_h

lib/seccomp/unittest/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ include $(CPP_SRC_HOME)/mk/defines.mk
88
TARGET=ml_test$(EXE_EXT)
99

1010
USE_BOOST=1
11+
USE_BOOST_FILESYSTEM_LIBS=1
1112
LIBS:=$(LIB_ML_SECCOMP)
1213
LDFLAGS:=$(ML_SECCOMP_LDFLAGS)
1314

0 commit comments

Comments
 (0)