fsstress: cleanup flist with test directory together
authorZorro Lang <zlang@redhat.com>
Wed, 17 May 2017 15:48:47 +0000 (23:48 +0800)
committerEryu Guan <eguan@redhat.com>
Fri, 19 May 2017 07:06:23 +0000 (15:06 +0800)
The "-c" option of fsstress will clean up the test directory after
each run. But it only does "rm -rf $dir". If run fsstress likes:

  fsstress -d $test_dir -n 1000 -p 10 -l 0 -c

fsstress will remove all test directories at the end of each run,
but the flist still save those *deleted* entries. It'll cause
more and more useless ENOENT failures. So we need to release all
entries in flist too.

Signed-off-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
ltp/fsstress.c

index 6d8f1172e4d416e1aebba894c7665a8821111f4f..e9fd2769274caf4b1708d99bb7b21d675772a00d 100644 (file)
@@ -280,6 +280,7 @@ int attr_list_path(pathname_t *, char *, const int, int, attrlist_cursor_t *);
 int    attr_remove_path(pathname_t *, const char *, int);
 int    attr_set_path(pathname_t *, const char *, const char *, const int, int);
 void   check_cwd(void);
 int    attr_remove_path(pathname_t *, const char *, int);
 int    attr_set_path(pathname_t *, const char *, const char *, const int, int);
 void   check_cwd(void);
+void   cleanup_flist(void);
 int    creat_path(pathname_t *, mode_t);
 void   dcache_enter(int, int);
 void   dcache_init(void);
 int    creat_path(pathname_t *, mode_t);
 void   dcache_enter(int, int);
 void   dcache_init(void);
@@ -794,6 +795,25 @@ check_cwd(void)
 #endif
 }
 
 #endif
 }
 
+/*
+ * go thru flist and release all entries
+ *
+ * NOTE: this function shouldn't be called until the end of a process
+ */
+void
+cleanup_flist(void)
+{
+       flist_t *flp;
+       int     i;
+
+       for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
+               flp->nslots = 0;
+               flp->nfiles = 0;
+               free(flp->fents);
+               flp->fents = NULL;
+       }
+}
+
 int
 creat_path(pathname_t *name, mode_t mode)
 {
 int
 creat_path(pathname_t *name, mode_t mode)
 {
@@ -945,6 +965,7 @@ errout:
        if (cleanup) {
                sprintf(cmd, "rm -rf %s", buf);
                system(cmd);
        if (cleanup) {
                sprintf(cmd, "rm -rf %s", buf);
                system(cmd);
+               cleanup_flist();
        }
 }
 
        }
 }