Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755156AbbBTTHx (ORCPT ); Fri, 20 Feb 2015 14:07:53 -0500 Received: from e28smtp03.in.ibm.com ([122.248.162.3]:60668 "EHLO e28smtp03.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752484AbbBTTHv (ORCPT ); Fri, 20 Feb 2015 14:07:51 -0500 Message-ID: <54E78601.40707@linux.vnet.ibm.com> Date: Sat, 21 Feb 2015 00:37:45 +0530 From: Hemant Kumar User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Masami Hiramatsu , Arnaldo Carvalho de Melo CC: Peter Zijlstra , Adrian Hunter , linux-kernel@vger.kernel.org, Ingo Molnar , Paul Mackerras , Jiri Olsa , Namhyung Kim , Borislav Petkov Subject: Re: [perf/core PATCH v4 2/2] perf buildid-cache: Add --purge FILE to remove all caches of FILE References: <20150220094145.4942.22046.stgit@localhost.localdomain> <20150220094150.4942.13002.stgit@localhost.localdomain> In-Reply-To: <20150220094150.4942.13002.stgit@localhost.localdomain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15022019-0009-0000-0000-0000040AF99A Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3417 Lines: 120 Hi Masami, Just a small suggestion below. On 02/20/2015 03:11 PM, Masami Hiramatsu wrote: > [SNIP] > + > +struct strlist *build_id_cache__list_build_ids(const char *pathname) > +{ > + struct strlist *list; > + char *dirname; > + DIR *dir; > + struct dirent *d; > + > + list = strlist__new(true, NULL); > + dirname = build_id_cache__dirname_from_path(pathname, false, false); > + if (!list || !dirname) > + goto error_free; > + > + /* List up all dirents */ > + dir = opendir(dirname); > + if (!dir) > + goto error_free; > + while ((d = readdir(dir)) != NULL) { > + if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) > + continue; > + strlist__add(list, d->d_name); > + } > + closedir(dir); > + > + free(dirname); > + return list; > + > +error_free: > + free(dirname); > + if (list) > + strlist__delete(list); Maybe we don't need the "if (list)" check here as strlist__delete already checks for this. > + return NULL; > +} > + > int build_id_cache__add_s(const char *sbuild_id, const char *name, > bool is_kallsyms, bool is_vdso) > { > const size_t size = PATH_MAX; > - char *realname, *filename = zalloc(size), > + char *realname = NULL, *filename = NULL, *dirname = NULL, > *linkname = zalloc(size), *targetname, *tmp; > - int len, err = -1; > - bool slash = is_kallsyms || is_vdso; > + int err = -1; > > - if (is_kallsyms) { > - if (symbol_conf.kptr_restrict) { > - pr_debug("Not caching a kptr_restrict'ed /proc/kallsyms\n"); > - err = 0; > - goto out_free; > - } > - realname = (char *) name; > - } else > + if (!is_kallsyms) { > realname = realpath(name, NULL); > + if (!realname) > + goto out_free; > + } > > - if (realname == NULL || filename == NULL || linkname == NULL) > + dirname = build_id_cache__dirname_from_path(name, is_kallsyms, is_vdso); > + if (!dirname) > goto out_free; > > - len = scnprintf(filename, size, "%s%s%s", > - buildid_dir, slash ? "/" : "", > - is_vdso ? DSO__NAME_VDSO : realname); > - if (mkdir_p(filename, 0755)) > + if (mkdir_p(dirname, 0755)) > goto out_free; > > - snprintf(filename + len, size - len, "/%s", sbuild_id); > + if (asprintf(&filename, "%s/%s", dirname, sbuild_id) < 0) { > + filename = NULL; > + goto out_free; > + } > > if (access(filename, F_OK)) { > if (is_kallsyms) { > @@ -337,6 +388,7 @@ out_free: > if (!is_kallsyms) > free(realname); > free(filename); > + free(dirname); > free(linkname); > return err; > } > diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h > index 2a09498..cbcadea 100644 > --- a/tools/perf/util/build-id.h > +++ b/tools/perf/util/build-id.h > @@ -22,6 +22,7 @@ bool perf_session__read_build_ids(struct perf_session *session, bool with_hits); > int perf_session__write_buildid_table(struct perf_session *session, int fd); > int perf_session__cache_build_ids(struct perf_session *session); > > +struct strlist *build_id_cache__list_build_ids(const char *pathname); > bool build_id_cache__cached(const char *sbuild_id); > int build_id_cache__add_s(const char *sbuild_id, > const char *name, bool is_kallsyms, bool is_vdso); > -- Thanks, Hemant Kumar -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/