Skip to content

Commit

Permalink
stress-swap: force remove any pre-existing swap files
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Ian King <[email protected]>
  • Loading branch information
ColinIanKing committed Jul 31, 2023
1 parent 3975fab commit 9959ae0
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion stress-swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,33 @@ static void stress_swap_check_swapped(
free(vec);
}

static void stress_swap_clean_dir(const stress_args_t *args)
{
char path[PATH_MAX];
DIR *dir;
struct dirent *d;

stress_temp_dir(path, sizeof(path), args->name, args->pid, args->instance);
dir = opendir(path);
if (!dir)
return;

while ((d = readdir(dir)) != NULL) {
struct stat stat_buf;
char filename[PATH_MAX];

stress_mk_filename(filename, sizeof(filename), path, d->d_name);
if (stat(filename, &stat_buf) == 0) {
if (S_ISREG(stat_buf.st_mode)) {
(void)stress_swapoff(filename);
(void)unlink(filename);
}
}
}
(void)closedir(dir);
rmdir(path);
}

/*
* stress_swap_child()
* stress swap operations
Expand All @@ -260,6 +287,7 @@ static int stress_swap_child(const stress_args_t *args, void *context)
goto tidy_ret;
}

stress_swap_clean_dir(args);
ret = stress_temp_dir_mk_args(args);
if (ret < 0) {
ret = stress_exit_status(-ret);
Expand Down Expand Up @@ -430,12 +458,17 @@ static int stress_swap_child(const stress_args_t *args, void *context)
(void)munmap((void *)page, page_size);
tidy_ret:
stress_set_proc_state(args->name, STRESS_STATE_DEINIT);
stress_swap_clean_dir(args);
return ret;
}

static int stress_swap(const stress_args_t *args)
{
return stress_oomable_child(args, NULL, stress_swap_child, STRESS_OOMABLE_NORMAL);
int ret;

ret = stress_oomable_child(args, NULL, stress_swap_child, STRESS_OOMABLE_NORMAL);
stress_swap_clean_dir(args);
return ret;
}

stressor_info_t stress_swap_info = {
Expand Down

0 comments on commit 9959ae0

Please sign in to comment.