From patchwork Thu Nov 24 08:24:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 83801 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp25529qgi; Wed, 23 Nov 2016 23:26:13 -0800 (PST) X-Received: by 10.55.21.81 with SMTP id f78mr723951qkh.210.1479972373575; Wed, 23 Nov 2016 23:26:13 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o19si14312220qtf.198.2016.11.23.23.26.13; Wed, 23 Nov 2016 23:26:13 -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 4666262DC9; Thu, 24 Nov 2016 07:26:13 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 BCE1E62DCB; Thu, 24 Nov 2016 07:25:04 +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 08D9162CAF; Thu, 24 Nov 2016 07:24:59 +0000 (UTC) Received: from mail-lf0-f45.google.com (mail-lf0-f45.google.com [209.85.215.45]) by lists.linaro.org (Postfix) with ESMTPS id BC0DA62CA4 for ; Thu, 24 Nov 2016 07:24:57 +0000 (UTC) Received: by mail-lf0-f45.google.com with SMTP id b14so21583510lfg.2 for ; Wed, 23 Nov 2016 23:24:57 -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=C5K0liDmfMg+1dx9MTNVlt4GAcYi+TFXWpxgki2e+ds=; b=Hl5CJu9p0WHZk+Hq2RptzKmYrO3C4zK8Snt+Yz/zBhooSWhoW3WZbdcQaQgCjd9Chi uXXXgZ5Wqvk1pV4SuA23grXKqEOHDdwN7D6k0cYjozYqGFCmZrrFAVEq1r337cAqhAZr S4WggDZI7ygw4RaaLabx3/riSSjH8YCvPe0t/paBHn8LbwGFPjCymNcUobCtqLLEgNtB Ohqq8XHKRjOSYnlR04Qz9h76g6IPKjl4zE8NDJyn2zTI8BP38FzO82zhmmY+uG3QpeXj 5Zx3jm+mopDkoUG6//TnaPzBvrPHRrG4VqfOTWXK10EtibdxR2zaFZyN24qNhYjHEvmq h+xQ== X-Gm-Message-State: AKaTC01DHAeBKZLqKRj9zUMLjkmVLXW3JeXlis25hoNZgdVKoWHgVm6q+sc2sCE4q8ClSW404mE= X-Received: by 10.46.9.21 with SMTP id 21mr529577ljj.0.1479972296621; Wed, 23 Nov 2016 23:24:56 -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 37sm7794110lfw.31.2016.11.23.23.24.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Nov 2016 23:24:56 -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 09:24:19 +0100 Message-Id: <1479975872-4945-3-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479975872-4945-1-git-send-email-christophe.milard@linaro.org> References: <1479975872-4945-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv8 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 | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) -- 2.7.4 diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index d4a8e09..6f63a4a 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -10,15 +10,62 @@ #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); + sprintf(prefix, _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) + return -1; + sprintf(fullpath, "%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 +96,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()) {