Skip to content

Commit 8a99dd2

Browse files
author
Hongzhen Luo
committed
[EROFS] test: add stat check
Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
1 parent c43d8f1 commit 8a99dd2

3 files changed

Lines changed: 138 additions & 102 deletions

File tree

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

Lines changed: 101 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,6 @@ class StressInterImpl: public StressGenInter {
146146
mode = std::stoi(str_mode, nullptr, 8);
147147
if (file->file->fchmod(mode))
148148
LOG_ERROR_RETURN(-1, false, "fail to set mode ` for file `", str_mode, file->path);
149-
node->mod = str_mode;
150-
return true;
151-
}
152-
153-
/* mode in verify phase */
154-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
155-
struct stat st;
156-
std::ostringstream oss;
157-
158-
if (erofs_file->fstat(&st))
159-
LOG_ERROR_RETURN(-1, false, "fail to stat erofs file");
160-
oss << std::oct << std::setfill('0') << std::setw(3) << (st.st_mode & 0777);
161-
node->mod = oss.str();
162149
return true;
163150
}
164151

@@ -169,17 +156,6 @@ class StressInterImpl: public StressGenInter {
169156

170157
if (file->file->fchown(uid, gid))
171158
LOG_ERROR_RETURN(-1,false, "failt to chown of file `", file->path);
172-
node->own = std::to_string(uid) + std::to_string(gid);
173-
return true;
174-
}
175-
176-
/* own in verify phase */
177-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
178-
struct stat st;
179-
180-
if (erofs_file->fstat(&st))
181-
LOG_ERROR_RETURN(-1, false, "fail to stat erofs file");
182-
node->own = std::to_string(st.st_uid) + std::to_string(st.st_gid);
183159
return true;
184160
}
185161

@@ -209,7 +185,6 @@ class StressInterImpl: public StressGenInter {
209185
mode = std::stoi(str_mode, nullptr, 8);
210186
if (host_fs->chmod(path, mode))
211187
LOG_ERROR_RETURN(-1, false, "fail to set mode ` for dir `", str_mode, path);
212-
node->mod = str_mode;
213188
return true;
214189
}
215190

@@ -219,7 +194,6 @@ class StressInterImpl: public StressGenInter {
219194

220195
if (host_fs->chown(path, uid, gid))
221196
LOG_ERROR_RETURN(-1,false, "failt to chown of dir `", path);
222-
node->own = std::to_string(uid) + std::to_string(gid);
223197
return true;
224198
}
225199

@@ -238,6 +212,24 @@ class StressInterImpl: public StressGenInter {
238212
}
239213
return true;
240214
}
215+
216+
bool build_stat_file(StressNode *node, StressHostFile *file_info) override {
217+
if (file_info->file->fstat(&node->node_stat))
218+
LOG_ERRNO_RETURN(-1, false, "fail to stat file `", file_info->path);
219+
return true;
220+
}
221+
222+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
223+
if (host_fs->stat(path, &node->node_stat))
224+
LOG_ERROR_RETURN(-1, false, "fail to stat dir `", path);
225+
return true;
226+
}
227+
228+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
229+
if (erofs_file->fstat(&node->node_stat))
230+
LOG_ERRNO_RETURN(-1, false, "fail to stat erofs_file");
231+
return true;
232+
}
241233
};
242234

243235
/*
@@ -257,6 +249,9 @@ class StressCase001: public StressBase, public StressInterImpl {
257249
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, build_gen_own(StressNode *node, StressHostFile *file), true)
258250
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, build_gen_xattrs(StressNode *node, StressHostFile *file), true)
259251
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, build_gen_content(StressNode *node, StressHostFile *file), true)
252+
bool build_stat_file(StressNode *node, StressHostFile *file) override {
253+
return StressInterImpl::build_stat_file(node, file);
254+
}
260255

261256
bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
262257
return StressInterImpl::build_dir_mod(node, path, host_fs);
@@ -267,17 +262,16 @@ class StressCase001: public StressBase, public StressInterImpl {
267262
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
268263
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
269264
}
270-
271-
/* create empty nodes in verify phase */
272-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
273-
return node->type ==NODE_DIR ? StressInterImpl::verify_gen_mod(node, erofs_file) : true;
274-
}
275-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
276-
return node->type == NODE_DIR ? StressInterImpl::verify_gen_own(node, erofs_file) : true;
265+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
266+
return StressInterImpl::build_stat_dir(node, path, host_fs);
277267
}
268+
278269
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
279270
return node->type == NODE_DIR ? StressInterImpl::verify_gen_xattrs(node, erofs_file): true;
280271
}
272+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
273+
return StressInterImpl::verify_stat(node, erofs_file);
274+
}
281275

282276
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)
283277

@@ -319,6 +313,9 @@ class StressCase002: public StressBase, public StressInterImpl {
319313
bool build_gen_content(StressNode *node, StressHostFile *file) override {
320314
return StressInterImpl::build_gen_content(node, file);
321315
}
316+
bool build_stat_file(StressNode *node, StressHostFile *file) override {
317+
return StressInterImpl::build_stat_file(node, file);
318+
}
322319

323320
bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
324321
return StressInterImpl::build_dir_mod(node, path, host_fs);
@@ -329,20 +326,19 @@ class StressCase002: public StressBase, public StressInterImpl {
329326
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
330327
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
331328
}
332-
333-
/* leave mod/own/xattr empty */
334-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
335-
return node->type ==NODE_DIR ? StressInterImpl::verify_gen_mod(node, erofs_file) : true;
336-
}
337-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
338-
return node->type == NODE_DIR ? StressInterImpl::verify_gen_own(node, erofs_file) : true;
329+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
330+
return StressInterImpl::build_stat_dir(node, path, host_fs);
339331
}
332+
340333
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
341334
return node->type == NODE_DIR ? StressInterImpl::verify_gen_xattrs(node, erofs_file): true;
342335
}
343336
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
344337
return StressInterImpl::verify_gen_content(node, erofs_file);
345338
}
339+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
340+
return StressInterImpl::verify_stat(node, erofs_file);
341+
}
346342

347343
/* simplely generate random dir and file names */
348344
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
@@ -381,6 +377,9 @@ class StressCase003: public StressBase, public StressInterImpl {
381377
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
382378
return StressInterImpl::build_gen_xattrs(node, file);
383379
}
380+
bool build_stat_file(StressNode *node, StressHostFile *file) override {
381+
return StressInterImpl::build_stat_file(node, file);
382+
}
384383

385384
bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
386385
return StressInterImpl::build_dir_mod(node, path, host_fs);
@@ -391,18 +390,17 @@ class StressCase003: public StressBase, public StressInterImpl {
391390
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
392391
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
393392
}
394-
395-
/* leave mod/own/content empty */
396-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
397-
return node->type ==NODE_DIR ? StressInterImpl::verify_gen_mod(node, erofs_file) : true;
398-
}
399-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
400-
return node->type == NODE_DIR ? StressInterImpl::verify_gen_own(node, erofs_file) : true;
393+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
394+
return StressInterImpl::build_stat_dir(node, path, host_fs);
401395
}
402-
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)
396+
403397
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
404398
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
405399
}
400+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
401+
return StressInterImpl::verify_stat(node, erofs_file);
402+
}
403+
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)
406404

407405
/* simplely generate random dir and file names */
408406
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
@@ -438,6 +436,9 @@ class StressCase004: public StressBase, public StressInterImpl {
438436
bool build_gen_mod(StressNode *node, StressHostFile *file) override {
439437
return StressInterImpl::build_gen_mod(node, file);
440438
}
439+
bool build_stat_file(StressNode *node, StressHostFile *file) override {
440+
return StressInterImpl::build_stat_file(node, file);
441+
}
441442

442443
bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
443444
return StressInterImpl::build_dir_mod(node, path, host_fs);
@@ -448,17 +449,17 @@ class StressCase004: public StressBase, public StressInterImpl {
448449
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
449450
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
450451
}
452+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
453+
return StressInterImpl::build_stat_dir(node, path, host_fs);
454+
}
451455

452456
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)
453-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
454-
return StressInterImpl::verify_gen_mod(node, erofs_file);
455-
}
456-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
457-
return node->type == NODE_DIR ? StressInterImpl::verify_gen_own(node, erofs_file) : true;
458-
}
459457
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
460458
return node->type == NODE_DIR ? StressInterImpl::verify_gen_xattrs(node, erofs_file): true;
461459
}
460+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
461+
return StressInterImpl::verify_stat(node, erofs_file);
462+
}
462463

463464
/* simplely generate random dir and file names */
464465
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
@@ -493,6 +494,9 @@ class StressCase005: public StressBase, public StressInterImpl {
493494
bool build_gen_own(StressNode *node, StressHostFile *file) override {
494495
return StressInterImpl::build_gen_own(node, file);
495496
}
497+
bool build_stat_file(StressNode *node, StressHostFile *file) override {
498+
return StressInterImpl::build_stat_file(node, file);
499+
}
496500

497501
bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
498502
return StressInterImpl::build_dir_mod(node, path, host_fs);
@@ -503,17 +507,17 @@ class StressCase005: public StressBase, public StressInterImpl {
503507
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
504508
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
505509
}
506-
507-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
508-
return node->type ==NODE_DIR ? StressInterImpl::verify_gen_mod(node, erofs_file) : true;
509-
}
510-
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)
511-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
512-
return StressInterImpl::verify_gen_own(node, erofs_file);
510+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
511+
return StressInterImpl::build_stat_dir(node, path, host_fs);
513512
}
513+
514514
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
515515
return node->type == NODE_DIR ? StressInterImpl::verify_gen_xattrs(node, erofs_file): true;
516516
}
517+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
518+
return StressInterImpl::verify_stat(node, erofs_file);
519+
}
520+
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)
517521

518522
/* simplely generate random dir and file names */
519523
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
@@ -554,6 +558,9 @@ class StressCase006: public StressBase, public StressInterImpl {
554558
bool build_gen_content(StressNode *node, StressHostFile *file) override {
555559
return StressInterImpl::build_gen_content(node, file);
556560
}
561+
bool build_stat_file(StressNode *node, StressHostFile *file) override {
562+
return StressInterImpl::build_stat_file(node, file);
563+
}
557564

558565
bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
559566
return StressInterImpl::build_dir_mod(node, path, host_fs);
@@ -564,19 +571,19 @@ class StressCase006: public StressBase, public StressInterImpl {
564571
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
565572
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
566573
}
567-
568-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
569-
return StressInterImpl::verify_gen_mod(node, erofs_file);
570-
}
571-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
572-
return StressInterImpl::verify_gen_own(node, erofs_file);
574+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
575+
return StressInterImpl::build_stat_dir(node, path, host_fs);
573576
}
577+
574578
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
575579
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
576580
}
577581
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
578582
return StressInterImpl::verify_gen_content(node, erofs_file);
579583
}
584+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
585+
return StressInterImpl::verify_stat(node, erofs_file);
586+
}
580587

581588
/* simplely generate random dir and file names */
582589
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
@@ -619,6 +626,9 @@ class StressCase007: public StressBase, public StressInterImpl {
619626
bool build_gen_content(StressNode *node, StressHostFile *file) override {
620627
return StressInterImpl::build_gen_content(node, file);
621628
}
629+
bool build_stat_file(StressNode *node, StressHostFile *file) override {
630+
return StressInterImpl::build_stat_file(node, file);
631+
}
622632

623633
bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
624634
return StressInterImpl::build_dir_mod(node, path, host_fs);
@@ -629,19 +639,19 @@ class StressCase007: public StressBase, public StressInterImpl {
629639
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
630640
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
631641
}
632-
633-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
634-
return StressInterImpl::verify_gen_mod(node, erofs_file);
635-
}
636-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
637-
return StressInterImpl::verify_gen_own(node, erofs_file);
642+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
643+
return StressInterImpl::build_stat_dir(node, path, host_fs);
638644
}
645+
639646
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
640647
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
641648
}
642649
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
643650
return StressInterImpl::verify_gen_content(node, erofs_file);
644651
}
652+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
653+
return StressInterImpl::verify_stat(node, erofs_file);
654+
}
645655

646656
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
647657
std::string res;
@@ -704,6 +714,9 @@ class StressCase008: public StressBase, public StressInterImpl {
704714
bool build_gen_content(StressNode *node, StressHostFile *file) override {
705715
return StressInterImpl::build_gen_content(node, file);
706716
}
717+
bool build_stat_file(StressNode *node, StressHostFile *file) override {
718+
return StressInterImpl::build_stat_file(node, file);
719+
}
707720

708721
bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
709722
return StressInterImpl::build_dir_mod(node, path, host_fs);
@@ -714,19 +727,19 @@ class StressCase008: public StressBase, public StressInterImpl {
714727
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
715728
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
716729
}
717-
718-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
719-
return StressInterImpl::verify_gen_mod(node, erofs_file);
720-
}
721-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
722-
return StressInterImpl::verify_gen_own(node, erofs_file);
730+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
731+
return StressInterImpl::build_stat_dir(node, path, host_fs);
723732
}
733+
724734
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
725735
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
726736
}
727737
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
728738
return StressInterImpl::verify_gen_content(node, erofs_file);
729739
}
740+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
741+
return StressInterImpl::verify_stat(node, erofs_file);
742+
}
730743

731744
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
732745
std::string res;
@@ -798,6 +811,9 @@ class StressCase009: public StressBase, public StressInterImpl {
798811
bool build_gen_content(StressNode *node, StressHostFile *file) override {
799812
return StressInterImpl::build_gen_content(node, file);
800813
}
814+
bool build_stat_file(StressNode *node, StressHostFile *file) override {
815+
return StressInterImpl::build_stat_file(node, file);
816+
}
801817

802818
bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
803819
return StressInterImpl::build_dir_mod(node, path, host_fs);
@@ -808,19 +824,19 @@ class StressCase009: public StressBase, public StressInterImpl {
808824
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
809825
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
810826
}
811-
812-
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
813-
return StressInterImpl::verify_gen_mod(node, erofs_file);
814-
}
815-
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
816-
return StressInterImpl::verify_gen_own(node, erofs_file);
827+
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
828+
return StressInterImpl::build_stat_dir(node, path, host_fs);
817829
}
830+
818831
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
819832
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
820833
}
821834
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
822835
return StressInterImpl::verify_gen_content(node, erofs_file);
823836
}
837+
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
838+
return StressInterImpl::verify_stat(node, erofs_file);
839+
}
824840

825841
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
826842
std::string res;

0 commit comments

Comments
 (0)