From patchwork Thu Nov 24 16:22:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 83926 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp153727qgi; Thu, 24 Nov 2016 07:27:29 -0800 (PST) X-Received: by 10.55.4.19 with SMTP id 19mr2487013qke.18.1480001249301; Thu, 24 Nov 2016 07:27:29 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u41si15355959qtu.283.2016.11.24.07.27.29; Thu, 24 Nov 2016 07:27:29 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id ED43562EAA; Thu, 24 Nov 2016 15:27:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 0CEAD62DDF; Thu, 24 Nov 2016 15:25:27 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 4B70562DAB; Thu, 24 Nov 2016 15:25:14 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id 8C41462DA9 for ; Thu, 24 Nov 2016 15:22:59 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id o141so31126549lff.1 for ; Thu, 24 Nov 2016 07:22:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=suYQPlu7GHU7zcTL4zX05yF8YaKMsoXOWMrSooel9ew=; b=Xm/Otd6hbVkk/gVvE8CwYd4Ayn/paath1mXyEu2j5AGQtkj7EeReoT66loigSsjUmg KzQq9x1ZNH9wV+Dkc8fUxYDD/zUoIaA0978MvGEvzdLQ3/+/A6kdluv/QVJUsgv2E0XT o4iu/yzf2C5Vu6u0iUpgOfbttHOfKj87OK7SjPROAAXrReUWQXr6L928N2EhC6O/4IQ/ TK2rR7E4uWTfilLQiqKfe4j9RxMj8r6yxCQAQM23woYgpeeqMp12K8GoJFwrq7WFH0tB f99Hq94a+kgzyHrjgQhL6q4LEuTC1Ek2QD3x8BZwmxCxVDy2sejSihjCaev4zi8DAvmW b1dg== X-Gm-Message-State: AKaTC03xp4HCZuXSyAFR19JfEMigNB75QUeQDWiSa8PBC/AY5RkByv7GSGLTMT4m1rPMK3wfO/I= X-Received: by 10.25.22.210 with SMTP id 79mr1321207lfw.170.1480000978305; Thu, 24 Nov 2016 07:22:58 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id x142sm8215976lfa.32.2016.11.24.07.22.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Nov 2016 07:22:57 -0800 (PST) From: Christophe Milard To: maxim.uvarov@linaro.com, mike.holmes@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Thu, 24 Nov 2016 17:22:20 +0100 Message-Id: <1480004553-46760-3-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480004553-46760-1-git-send-email-christophe.milard@linaro.org> References: <1480004553-46760-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv9 02/15] linux-gen: init: removing possible obsolete ODP files at startup X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" When an ODP program is killed, some odp files may remain in /tmp and the huge page mount point. As signal KILL cannot be caught, there is not much one can do to prevent that. But when an new odp session is started, all files prefixed with the opd prefix ("odp--") can be safely removed as the PID is unique and therefore, there cannot be another ODP instance with the same PID. This patch does this cleanup at startup. Signed-off-by: Christophe Milard --- platform/linux-generic/odp_init.c | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) -- 2.7.4 diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index d4a8e09..6e58ab6 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -10,15 +10,71 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include + +#define _ODP_FILES_FMT "odp-%d-" +#define _ODP_TMPDIR "/tmp" struct odp_global_data_s odp_global_data; +/* remove all files staring with "odp-" from a directory "dir" */ +static int cleanup_files(const char *dirpath, int odp_pid) +{ + struct dirent *e; + DIR *dir; + char prefix[PATH_MAX]; + char *fullpath; + int d_len = strlen(dirpath); + int p_len; + int f_len; + + dir = opendir(dirpath); + if (!dir) { + /* ok if the dir does not exist. no much to delete then! */ + ODP_DBG("opendir failed for %s: %s\n", + dirpath, strerror(errno)); + return 0; + } + snprintf(prefix, PATH_MAX, _ODP_FILES_FMT, odp_pid); + p_len = strlen(prefix); + while ((e = readdir(dir)) != NULL) { + if (strncmp(e->d_name, prefix, p_len) == 0) { + f_len = strlen(e->d_name); + fullpath = malloc(d_len + f_len + 2); + if (fullpath == NULL) { + closedir(dir); + return -1; + } + snprintf(fullpath, PATH_MAX, "%s/%s", + dirpath, e->d_name); + ODP_DBG("deleting obsolete file: %s\n", fullpath); + if (unlink(fullpath)) + ODP_ERR("unlink failed for %s: %s\n", + fullpath, strerror(errno)); + free(fullpath); + } + } + closedir(dir); + + return 0; +} + int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params) { + char *hpdir; + memset(&odp_global_data, 0, sizeof(struct odp_global_data_s)); odp_global_data.main_pid = getpid(); + cleanup_files(_ODP_TMPDIR, odp_global_data.main_pid); + if (platform_params) odp_global_data.ipc_ns = platform_params->ipc_ns; @@ -49,6 +105,10 @@ int odp_init_global(odp_instance_t *instance, ODP_ERR("ODP system_info init failed.\n"); goto init_failed; } + hpdir = odp_global_data.hugepage_info.default_huge_page_dir; + /* cleanup obsolete huge page files, if any */ + if (hpdir) + cleanup_files(hpdir, odp_global_data.main_pid); stage = SYSINFO_INIT; if (_odp_fdserver_init_global()) {