Commit 386e0d83 authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo
Browse files

perf tools: Remove also guest kcore_dir with host kcore_dir



Copies of /proc/kallsyms, /proc/modules and an extract of /proc/kcore can
be stored in the perf.data output directory under the subdirectory named
kcore_dir. Guest machines will have their files also under subdirectories
beginning kcore_dir__ followed by the machine pid. Remove these also when
removing kcore_dir.

Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Acked-by: default avatarIan Rogers <irogers@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: kvm@vger.kernel.org
Link: https://lore.kernel.org/r/20220711093218.10967-21-adrian.hunter@intel.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 13a133b2
Loading
Loading
Loading
Loading
+35 −2
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ static int rm_rf_depth_pat(const char *path, int depth, const char **pat)
	return rmdir(path);
}

static int rm_rf_kcore_dir(const char *path)
static int rm_rf_a_kcore_dir(const char *path, const char *name)
{
	char kcore_dir_path[PATH_MAX];
	const char *pat[] = {
@@ -210,11 +210,44 @@ static int rm_rf_kcore_dir(const char *path)
		NULL,
	};

	snprintf(kcore_dir_path, sizeof(kcore_dir_path), "%s/kcore_dir", path);
	snprintf(kcore_dir_path, sizeof(kcore_dir_path), "%s/%s", path, name);

	return rm_rf_depth_pat(kcore_dir_path, 0, pat);
}

static bool kcore_dir_filter(const char *name __maybe_unused, struct dirent *d)
{
	const char *pat[] = {
		"kcore_dir",
		"kcore_dir__[1-9]*",
		NULL,
	};

	return match_pat(d->d_name, pat);
}

static int rm_rf_kcore_dir(const char *path)
{
	struct strlist *kcore_dirs;
	struct str_node *nd;
	int ret;

	kcore_dirs = lsdir(path, kcore_dir_filter);

	if (!kcore_dirs)
		return 0;

	strlist__for_each_entry(nd, kcore_dirs) {
		ret = rm_rf_a_kcore_dir(path, nd->s);
		if (ret)
			return ret;
	}

	strlist__delete(kcore_dirs);

	return 0;
}

int rm_rf_perf_data(const char *path)
{
	const char *pat[] = {