Skip to content

Commit 115be8d

Browse files
author
Hongzhen Luo
committed
[EROFS] test: add test for mtime
Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
1 parent f4969c1 commit 115be8d

3 files changed

Lines changed: 87 additions & 3 deletions

File tree

src/overlaybd/tar/erofs/test/erofs_stress.cpp

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ class StressInterImpl: public StressGenInter {
160160
return true;
161161
}
162162

163+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
164+
size_t now = time(nullptr);
165+
time_t time_sec = get_randomint(now, now + 24 * 60 * 60);
166+
struct tm *time_info = localtime(&time_sec);
167+
char buffer[256];
168+
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", time_info);
169+
std::ostringstream oss;
170+
oss << buffer;
171+
meta->mtime_date = oss.str();
172+
meta->mtime = time_sec;
173+
return true;
174+
}
163175
/* generate a random dir or file name in the current layer */
164176
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
165177
std::string res;
@@ -198,6 +210,10 @@ class StressInterImpl: public StressGenInter {
198210
return true;
199211
}
200212

213+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
214+
return build_gen_mtime(node, meta);
215+
}
216+
201217
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
202218
photon::fs::IFileSystemXAttr *xattr_ops = dynamic_cast<photon::fs::IFileSystemXAttr*>(host_fs);
203219
if (xattr_ops == nullptr)
@@ -219,6 +235,7 @@ class StressInterImpl: public StressGenInter {
219235
LOG_ERRNO_RETURN(-1, false, "fail to stat file `", file_info->path);
220236
node->node_stat.st_uid = meta->uid;
221237
node->node_stat.st_gid = meta->gid;
238+
node->node_stat.st_mtime = meta->mtime;
222239

223240
return true;
224241
}
@@ -228,6 +245,7 @@ class StressInterImpl: public StressGenInter {
228245
LOG_ERROR_RETURN(-1, false, "fail to stat dir `", path);
229246
node->node_stat.st_uid = meta->uid;
230247
node->node_stat.st_gid = meta->gid;
248+
node->node_stat.st_mtime = meta->mtime;
231249
return true;
232250
}
233251

@@ -257,6 +275,9 @@ class StressCase001: public StressBase, public StressInterImpl {
257275
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
258276
return StressInterImpl::build_gen_own(node, meta);
259277
}
278+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
279+
return StressInterImpl::build_gen_mtime(node, meta);
280+
}
260281
bool build_stat_file(StressNode *node, StressHostFile *file, struct in_mem_meta *meta) override {
261282
return StressInterImpl::build_stat_file(node, file, meta);
262283
}
@@ -267,6 +288,9 @@ class StressCase001: public StressBase, public StressInterImpl {
267288
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
268289
return StressInterImpl::build_dir_own(node, meta);
269290
}
291+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
292+
return StressInterImpl::build_dir_mtime(node, meta);
293+
}
270294
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
271295
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
272296
}
@@ -296,8 +320,8 @@ class StressCase001: public StressBase, public StressInterImpl {
296320
std::vector<int> layer_dirs(int idx) {
297321
std::vector<int> ret;
298322

299-
ret.emplace_back(50);
300-
ret.emplace_back(50);
323+
ret.emplace_back(3);
324+
ret.emplace_back(3);
301325
return ret;
302326
}
303327
};
@@ -320,6 +344,9 @@ class StressCase002: public StressBase, public StressInterImpl {
320344
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
321345
return StressInterImpl::build_gen_own(node, meta);
322346
}
347+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
348+
return StressInterImpl::build_gen_mtime(node, meta);
349+
}
323350
bool build_gen_content(StressNode *node, StressHostFile *file) override {
324351
return StressInterImpl::build_gen_content(node, file);
325352
}
@@ -333,6 +360,9 @@ class StressCase002: public StressBase, public StressInterImpl {
333360
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
334361
return StressInterImpl::build_dir_own(node, meta);
335362
}
363+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
364+
return StressInterImpl::build_dir_mtime(node, meta);
365+
}
336366
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
337367
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
338368
}
@@ -388,6 +418,9 @@ class StressCase003: public StressBase, public StressInterImpl {
388418
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
389419
return StressInterImpl::build_gen_own(node, meta);
390420
}
421+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
422+
return StressInterImpl::build_gen_mtime(node, meta);
423+
}
391424
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
392425
return StressInterImpl::build_gen_xattrs(node, file);
393426
}
@@ -401,6 +434,9 @@ class StressCase003: public StressBase, public StressInterImpl {
401434
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
402435
return StressInterImpl::build_dir_own(node, meta);
403436
}
437+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
438+
return StressInterImpl::build_dir_mtime(node, meta);
439+
}
404440
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
405441
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
406442
}
@@ -449,6 +485,9 @@ class StressCase004: public StressBase, public StressInterImpl {
449485
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
450486
return StressInterImpl::build_gen_own(node, meta);
451487
}
488+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
489+
return StressInterImpl::build_gen_mtime(node, meta);
490+
}
452491
bool build_gen_mod(StressNode *node, StressHostFile *file) override {
453492
return StressInterImpl::build_gen_mod(node, file);
454493
}
@@ -462,6 +501,9 @@ class StressCase004: public StressBase, public StressInterImpl {
462501
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
463502
return StressInterImpl::build_dir_own(node, meta);
464503
}
504+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
505+
return StressInterImpl::build_dir_mtime(node, meta);
506+
}
465507
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
466508
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
467509
}
@@ -510,6 +552,9 @@ class StressCase005: public StressBase, public StressInterImpl {
510552
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
511553
return StressInterImpl::build_gen_own(node, meta);
512554
}
555+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
556+
return StressInterImpl::build_gen_mtime(node, meta);
557+
}
513558
bool build_stat_file(StressNode *node, StressHostFile *file, struct in_mem_meta *meta) override {
514559
return StressInterImpl::build_stat_file(node, file, meta);
515560
}
@@ -520,6 +565,9 @@ class StressCase005: public StressBase, public StressInterImpl {
520565
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
521566
return StressInterImpl::build_dir_own(node, meta);
522567
}
568+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
569+
return StressInterImpl::build_dir_mtime(node, meta);
570+
}
523571
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
524572
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
525573
}
@@ -568,6 +616,9 @@ class StressCase006: public StressBase, public StressInterImpl {
568616
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
569617
return StressInterImpl::build_gen_own(node, meta);
570618
}
619+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
620+
return StressInterImpl::build_gen_mtime(node, meta);
621+
}
571622
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
572623
return StressInterImpl::build_gen_xattrs(node, file);
573624
}
@@ -584,6 +635,9 @@ class StressCase006: public StressBase, public StressInterImpl {
584635
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
585636
return StressInterImpl::build_dir_own(node, meta);
586637
}
638+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
639+
return StressInterImpl::build_dir_mtime(node, meta);
640+
}
587641
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
588642
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
589643
}
@@ -636,6 +690,9 @@ class StressCase007: public StressBase, public StressInterImpl {
636690
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
637691
return StressInterImpl::build_gen_own(node, meta);
638692
}
693+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
694+
return StressInterImpl::build_gen_mtime(node, meta);
695+
}
639696
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
640697
return StressInterImpl::build_gen_xattrs(node, file);
641698
}
@@ -652,6 +709,9 @@ class StressCase007: public StressBase, public StressInterImpl {
652709
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
653710
return StressInterImpl::build_dir_own(node, meta);
654711
}
712+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
713+
return StressInterImpl::build_dir_mtime(node, meta);
714+
}
655715
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
656716
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
657717
}
@@ -724,6 +784,9 @@ class StressCase008: public StressBase, public StressInterImpl {
724784
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
725785
return StressInterImpl::build_gen_own(node, meta);
726786
}
787+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
788+
return StressInterImpl::build_gen_mtime(node, meta);
789+
}
727790
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
728791
return StressInterImpl::build_gen_xattrs(node, file);
729792
}
@@ -740,6 +803,9 @@ class StressCase008: public StressBase, public StressInterImpl {
740803
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
741804
return StressInterImpl::build_dir_own(node, meta);
742805
}
806+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
807+
return StressInterImpl::build_dir_mtime(node, meta);
808+
}
743809
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
744810
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
745811
}
@@ -821,6 +887,9 @@ class StressCase009: public StressBase, public StressInterImpl {
821887
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
822888
return StressInterImpl::build_gen_own(node, meta);
823889
}
890+
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
891+
return StressInterImpl::build_gen_mtime(node, meta);
892+
}
824893
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
825894
return StressInterImpl::build_gen_xattrs(node, file);
826895
}
@@ -837,6 +906,9 @@ class StressCase009: public StressBase, public StressInterImpl {
837906
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
838907
return StressInterImpl::build_dir_own(node, meta);
839908
}
909+
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
910+
return StressInterImpl::build_dir_mtime(node, meta);
911+
}
840912
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
841913
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
842914
}

src/overlaybd/tar/erofs/test/erofs_stress_base.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static bool append_tar(bool first, std::string tar_name, std::string tmp_tar, st
157157
{
158158
std::string cmd = std::string("tar --create --file=") + (first ? tar_name : tmp_tar) + " --xattrs --xattrs-include='*'";
159159
if (meta)
160-
cmd = cmd + " --owner=" + std::to_string(meta->uid) + " --group=" + std::to_string(meta->gid);
160+
cmd = cmd + " --owner=" + std::to_string(meta->uid) + " --group=" + std::to_string(meta->gid) + " --mtime=\"" + meta->mtime_date + "\"";
161161
cmd = cmd + " -C " + prefix + " " + file_name;
162162

163163
if (system(cmd.c_str()))
@@ -205,6 +205,7 @@ bool StressBase::create_layer(int idx) {
205205
meta_maps[layer_tree->pwd] = new struct in_mem_meta();
206206
res = build_dir_mod(node, layer_tree->pwd.c_str(), host_fs) &&
207207
build_dir_own(node, meta_maps[layer_tree->pwd]) &&
208+
build_dir_mtime(node, meta_maps[layer_tree->pwd]) &&
208209
build_dir_xattrs(node, layer_tree->pwd.c_str(), host_fs) &&
209210
build_stat_dir(node, layer_tree->pwd.c_str(), host_fs, meta_maps[layer_tree->pwd]);
210211
if (!res)
@@ -250,6 +251,7 @@ bool StressBase::create_layer(int idx) {
250251
meta_maps[prefix + filename] = new struct in_mem_meta();
251252
res = build_gen_mod(node, file_info) &&
252253
build_gen_own(node, meta_maps[prefix + filename]) &&
254+
build_gen_mtime(node, meta_maps[prefix + filename]) &&
253255
build_gen_xattrs(node, file_info) &&
254256
build_gen_content(node, file_info) &&
255257
build_stat_file(node, file_info, meta_maps[prefix + filename]);
@@ -297,6 +299,7 @@ bool StressBase::create_layer(int idx) {
297299
meta_maps[next->pwd] = new struct in_mem_meta();
298300
res = build_dir_mod(dir_node, next->pwd.c_str(), host_fs) &&
299301
build_dir_own(dir_node, meta_maps[next->pwd]) &&
302+
build_dir_mtime(dir_node, meta_maps[next->pwd]) &&
300303
build_dir_xattrs(dir_node, next->pwd.c_str(), host_fs) &&
301304
build_stat_dir(dir_node, next->pwd.c_str(), host_fs, meta_maps[next->pwd]);
302305
if (!res)

src/overlaybd/tar/erofs/test/erofs_stress_base.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ class StressNode {
109109
*/
110110
if (type != NODE_DIR && node_stat.st_size != ano->node_stat.st_size)
111111
LOG_ERROR_RETURN(-1, false, "file size ` not equal to ` (`)", node_stat.st_size, ano->node_stat.st_size, path);
112+
113+
if (node_stat.st_mtime != ano->node_stat.st_mtime)
114+
LOG_ERRNO_RETURN(-1, false, "mtime ` not equal to ` (`)", node_stat.st_mtime,
115+
ano->node_stat.st_mtime,
116+
path);
112117
return true;
113118
}
114119
};
@@ -139,6 +144,8 @@ class StressHostFile {
139144
struct in_mem_meta{
140145
uid_t uid;
141146
gid_t gid;
147+
std::string mtime_date;
148+
time_t mtime;
142149
};
143150

144151
/* interface to generate corresponding values for in-mem nodes and host-fs files */
@@ -148,13 +155,15 @@ class StressGenInter {
148155
/* generate content for in-memory inodes and host files (prepare layers phase) */
149156
virtual bool build_gen_mod(StressNode *node /* out */, StressHostFile *file_info /* out */) = 0;
150157
virtual bool build_gen_own(StressNode *node /* out */, struct in_mem_meta *meta /* out */) = 0;
158+
virtual bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) = 0;
151159
virtual bool build_gen_xattrs(StressNode *node /* out */, StressHostFile *file_info /* out */) = 0;
152160
virtual bool build_gen_content(StressNode *node /* out */, StressHostFile *file_info /* out */) = 0;
153161
virtual bool build_stat_file(StressNode *node /* out */, StressHostFile *file_info /* out */, struct in_mem_meta *meta) = 0;
154162

155163
/* for a single dir (node) */
156164
virtual bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) = 0;
157165
virtual bool build_dir_own(StressNode *node, struct in_mem_meta *meta) = 0;
166+
virtual bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) = 0;
158167
virtual bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) = 0;
159168
virtual bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs, struct in_mem_meta *meta) = 0;
160169

0 commit comments

Comments
 (0)