Skip to content

Commit be5e0a4

Browse files
authored
Merge pull request #358 from salvete/main
Add stress test for erofs
2 parents 7ace045 + 115be8d commit be5e0a4

File tree

7 files changed

+1885
-9
lines changed

7 files changed

+1885
-9
lines changed

src/overlaybd/tar/erofs/erofs_fs.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,35 @@ ssize_t ErofsFile::pread(void *buf, size_t count, off_t offset)
285285
return read;
286286
}
287287

288+
ssize_t ErofsFile::fgetxattr(const char *name, void *value, size_t size)
289+
{
290+
ssize_t value_size = 0;
291+
292+
value_size = erofs_getxattr(&file_private->inode, name, NULL, 0);
293+
if (value_size < 0)
294+
LOG_ERROR_RETURN(-1, size, "[erofs] fail to get xattr `", name);
295+
if ((size_t)value_size > size)
296+
LOG_ERROR_RETURN(-1, -1, "[erofs] buffer is too small to put xattr value of `", name);
297+
return erofs_getxattr(&file_private->inode, name, (char*)value, value_size);
298+
}
299+
300+
ssize_t ErofsFile::flistxattr(char *list, size_t size)
301+
{
302+
ssize_t kllen;
303+
304+
kllen = erofs_listxattr(&file_private->inode, NULL, 0);
305+
if (kllen < 0)
306+
LOG_ERROR_RETURN(-1, kllen, "[erofs] fail to list xattr");
307+
if ((size_t)kllen > size)
308+
LOG_ERROR_RETURN(-1, -1, "[erofs buffer size is too small to put xattrs");
309+
if (erofs_listxattr(&file_private->inode, list, kllen) != kllen)
310+
LOG_ERROR_RETURN(-1, -1, "[erofs] fail to list xattr");
311+
return kllen;
312+
}
313+
314+
EROFS_UNIMPLEMENTED_FUNC(int, ErofsFile, fsetxattr(const char *name, const void *value, size_t size, int flags), -EROFS_UNIMPLEMENTED)
315+
EROFS_UNIMPLEMENTED_FUNC(int, ErofsFile, fremovexattr(const char *name), -EROFS_UNIMPLEMENTED)
316+
288317
// ErofsFileSystem
289318
EROFS_UNIMPLEMENTED_FUNC(photon::fs::IFile*, ErofsFileSystem, open(const char *pathname, int flags, mode_t mode), NULL)
290319
EROFS_UNIMPLEMENTED_FUNC(photon::fs::IFile*, ErofsFileSystem, creat(const char *pathname, mode_t mode), NULL)

src/overlaybd/tar/erofs/erofs_fs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,18 @@ class ErofsFileSystem: public photon::fs::IFileSystem {
5858
friend class ErofsFile;
5959
};
6060

61-
class ErofsFile: public photon::fs::VirtualReadOnlyFile {
61+
class ErofsFile: public photon::fs::VirtualReadOnlyFile, public photon::fs::IFileXAttr {
6262
public:
6363
ErofsFile(ErofsFileSystem *fs);
6464
~ErofsFile();
6565
photon::fs::IFileSystem *filesystem();
6666
int fstat(struct stat *buf);
6767
int fiemap(struct photon::fs::fiemap *map);
6868
ssize_t pread(void *buf, size_t count, off_t offset);
69+
ssize_t fgetxattr(const char *name, void *value, size_t size);
70+
ssize_t flistxattr(char *list, size_t size);
71+
int fsetxattr(const char *name, const void *value, size_t size, int flags);
72+
int fremovexattr(const char *name);
6973
private:
7074
ErofsFileSystem *fs;
7175
struct ErofsFileInt;

src/overlaybd/tar/erofs/test/CMakeLists.txt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,34 @@ link_directories($ENV{GFLAGS}/lib)
44
include_directories($ENV{GTEST}/googletest/include)
55
link_directories($ENV{GTEST}/lib)
66

7-
add_executable(erofs_test test.cpp)
8-
target_include_directories(erofs_test PUBLIC ${PHOTON_INCLUDE_DIR})
9-
target_link_libraries(erofs_test gtest gtest_main pthread photon_static
7+
# erofs simple test
8+
add_executable(erofs_simple_test erofs_simple.cpp)
9+
target_include_directories(erofs_simple_test PUBLIC ${PHOTON_INCLUDE_DIR})
10+
target_link_libraries(erofs_simple_test gtest gtest_main pthread photon_static
1011
tar_lib lsmt_lib gzip_lib gzindex_lib checksum_lib overlaybd_image_lib)
1112

12-
target_include_directories(erofs_test PUBLIC
13+
target_include_directories(erofs_simple_test PUBLIC
1314
${PHOTON_INCLUDE_DIR}
1415
${rapidjson_SOURCE_DIR}/include
1516
)
1617

1718
add_test(
18-
NAME erofs_test
19-
COMMAND ${EXECUTABLE_OUTPUT_PATH}/erofs_test
19+
NAME erofs_simple_test
20+
COMMAND ${EXECUTABLE_OUTPUT_PATH}/erofs_simple_test
21+
)
22+
23+
# erofs stress test
24+
add_executable(erofs_stress_test erofs_stress.cpp erofs_stress_base.cpp)
25+
target_include_directories(erofs_stress_test PUBLIC ${PHOTON_INCLUDE_DIR})
26+
target_link_libraries(erofs_stress_test gtest gtest_main pthread photon_static
27+
tar_lib lsmt_lib gzip_lib gzindex_lib checksum_lib overlaybd_image_lib)
28+
29+
target_include_directories(erofs_stress_test PUBLIC
30+
${PHOTON_INCLUDE_DIR}
31+
${rapidjson_SOURCE_DIR}/include
32+
)
33+
34+
add_test(
35+
NAME erofs_stress_test
36+
COMMAND ${EXECUTABLE_OUTPUT_PATH}/erofs_stress_test
2037
)

src/overlaybd/tar/erofs/test/test.cpp renamed to src/overlaybd/tar/erofs/test/erofs_simple.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
#include "../../../gzip/gz.h"
3333
#include "../../../../tools/sha256file.h"
3434
#include "../../../../tools/comm_func.h"
35-
35+
#include "../erofs_fs.h"
3636

3737
#define FILE_SIZE (2 * 1024 * 1024)
3838
#define IMAGE_SIZE 512UL<<20
39+
3940
class ErofsTest : public ::testing::Test {
4041
public:
4142
static int inflate(std::string output_file, unsigned char *data, unsigned int size) {
@@ -841,7 +842,6 @@ class ErofsTestCleanIncremental: public ::testing::Test {
841842
}
842843
delete host_fs;
843844
}
844-
845845
int traverse_fs(photon::fs::IFileSystem *fs, photon::fs::IFile *out) {
846846
std::vector<string> items;
847847

0 commit comments

Comments
 (0)