From patchwork Fri Dec 2 09:42:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 86248 Delivered-To: patch@linaro.org Received: by 10.182.112.6 with SMTP id im6csp196426obb; Fri, 2 Dec 2016 00:43:29 -0800 (PST) X-Received: by 10.55.100.67 with SMTP id y64mr36957429qkb.118.1480668209209; Fri, 02 Dec 2016 00:43:29 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j6si2416785qtd.330.2016.12.02.00.43.28; Fri, 02 Dec 2016 00:43: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 DB4FA62EC9; Fri, 2 Dec 2016 08:43: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=-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 13C4160967; Fri, 2 Dec 2016 08:43:25 +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 706F460EEA; Fri, 2 Dec 2016 08:43:22 +0000 (UTC) Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com [209.85.215.52]) by lists.linaro.org (Postfix) with ESMTPS id 31C9A62EA7 for ; Fri, 2 Dec 2016 08:43:18 +0000 (UTC) Received: by mail-lf0-f52.google.com with SMTP id c13so189906281lfg.0 for ; Fri, 02 Dec 2016 00:43:18 -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; bh=GFNxi7QMPZbw189l1rag7pkg9Hq3SOM2I32c/jXPDQA=; b=kW0Hm7AL1ren6Elrx/5pZg26/xh4Aaiuh75JC4/Or+Jewi+KS/HL0qt/S1zubI8d1H avHkyHst1xrDrzvmgsnpGZKJWPKWP5g2TAv4kenkljtM+uqPbjoC3pGKukAmzz/g/bAC PlJy7AFgAwv9v+MdWypfj/JKgWBv/AQJrPCsaO+C6tGH/QiEQBld0tgLVFRUZP8mis22 he7qdGpc5umIJ4e6ktAiYGsR23x71xq5Dbyx1QCo5xjFa1VqaHKaQgqgKZXOi+I910lE jVE7b8H+tkijovxv7qPdc/zNN/A4Uar0EEgSYIxlYteAjkQ79bgmm/Sus21n7g/w7uhP clMA== X-Gm-Message-State: AKaTC01jMzGLma7mbgR0cFyXj8rsJZBPRr0j9T6CXhxmQP+e2lbS5XUzLdeXBWFdSFlsxpBCFG8= X-Received: by 10.25.92.131 with SMTP id u3mr17154759lfi.15.1480668196920; Fri, 02 Dec 2016 00:43:16 -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 t15sm621436lfe.13.2016.12.02.00.43.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Dec 2016 00:43:16 -0800 (PST) From: Christophe Milard To: maxim.uvarov@linaro.com, mike.holmes@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Fri, 2 Dec 2016 10:42:44 +0100 Message-Id: <1480671764-10451-1-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [lng-odp] [API-NEXT PATCH] linux-gen: _ishm: unlinking files asap for cleaner termination 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" _ishm now unlinks the created files as soon as possible, hence reducing the chance to see left-overs, if ODP terminates abnormaly. This does not provide 100% guaranty: if we are unlucky enough, ODP may be killed between open() and unlink(). Also this method excludes exported files (flag _ODP_ISHM_EXPORT), whose names shall be seen in the file system. Signed-off-by: Christophe Milard --- platform/linux-generic/_ishm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c index 449e357..84d5225 100644 --- a/platform/linux-generic/_ishm.c +++ b/platform/linux-generic/_ishm.c @@ -71,6 +71,7 @@ #include #include #include +#include /* * Maximum number of internal shared memory blocks. @@ -159,6 +160,7 @@ typedef struct ishm_block { char exptname[ISHM_FILENAME_MAXLEN]; /* name of the export file */ uint32_t user_flags; /* any flags the user want to remember. */ uint32_t flags; /* block creation flags. */ + uint32_t external_fd; /* block FD was externaly provided */ uint64_t user_len; /* length, as requested at reserve time. */ void *start; /* only valid if _ODP_ISHM_SINGLE_VA is set*/ uint64_t len; /* length. multiple of page size. 0 if free*/ @@ -452,15 +454,17 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, ODP_ERR("ftruncate failed: fd=%d, err=%s.\n", fd, strerror(errno)); close(fd); + unlink(filename); return -1; } - strncpy(new_block->filename, filename, ISHM_FILENAME_MAXLEN - 1); /* if _ODP_ISHM_EXPORT is set, create a description file for * external ref: */ if (flags & _ODP_ISHM_EXPORT) { + strncpy(new_block->filename, filename, + ISHM_FILENAME_MAXLEN - 1); snprintf(new_block->exptname, ISHM_FILENAME_MAXLEN, ISHM_EXPTNAME_FORMAT, odp_global_data.main_pid, @@ -483,6 +487,8 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len, } } else { new_block->exptname[0] = 0; + /* remove the file from the filesystem, keeping its fd open */ + unlink(filename); } return fd; @@ -814,6 +820,9 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd, return -1; } new_block->huge = EXTERNAL; + new_block->external_fd = 1; + } else { + new_block->external_fd = 0; } /* Otherwise, Try first huge pages when possible and needed: */ @@ -865,8 +874,9 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd, /* if neither huge pages or normal pages works, we cannot proceed: */ if ((fd < 0) || (addr == NULL) || (len == 0)) { - if ((new_block->filename[0]) && (fd >= 0)) + if ((!new_block->external_fd) && (fd >= 0)) close(fd); + delete_file(new_block); odp_spinlock_unlock(&ishm_tbl->lock); ODP_ERR("_ishm_reserve failed.\n"); return -1;