From patchwork Tue Dec 6 17:25:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 86869 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp2103571qgi; Tue, 6 Dec 2016 08:26:23 -0800 (PST) X-Received: by 10.36.135.130 with SMTP id f124mr3030697ite.57.1481041583331; Tue, 06 Dec 2016 08:26:23 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 77si14534887ioj.23.2016.12.06.08.26.22; Tue, 06 Dec 2016 08:26:23 -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 C494362D4A; Tue, 6 Dec 2016 16:26:22 +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=0.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SUSPICIOUS_RECIPS 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 D22EA60BFC; Tue, 6 Dec 2016 16:26:16 +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 BDF5060C00; Tue, 6 Dec 2016 16:26:14 +0000 (UTC) Received: from mail-wj0-f175.google.com (mail-wj0-f175.google.com [209.85.210.175]) by lists.linaro.org (Postfix) with ESMTPS id BA75660BFB for ; Tue, 6 Dec 2016 16:26:13 +0000 (UTC) Received: by mail-wj0-f175.google.com with SMTP id tk12so32902082wjb.3 for ; Tue, 06 Dec 2016 08:26:13 -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=UFcf8GoykEtEe5P4uELT89ykRkluGGfW7W4EbkeZ/Bo=; b=bxEfPLf+5rPmbmkYugEaP9N9/15cJGh9fqeEvi1+RYAx75KuTrK5TGTKPWwJOEiPXw BA2k4aBAnXW+BraGIjqcKhA02hT4AdO4TYQMdVPa7ybOD3hSzLGF7TRpivXvLqadTy5Y XW/Q8TFHFETIQQVpMAVFdYNVfu7USkPPCcMFUr3Zzt5ccZHKdFRgDQwqLdAbl1IdkcUk 5xT8AK1Nn/x7LwvOPKMMl+iDiFxHPUvPcrzi5tM6PqBpDKBjMdV7DFBn+eSCOy+9YuFH I4mZiMEN4JSKhs2UGbI7Kpv3Lr231ZTfy+IfppBWm88oQIoKCwD1MYaTa00I9op8J0wP qFMA== X-Gm-Message-State: AKaTC03srAnrDSDiMobikUTCBFRPLIEADLGOKX3PrGqrRnxWksywddOfS28Y7V7ucbSQXGUZV/4= X-Received: by 10.25.74.193 with SMTP id x184mr23746195lfa.146.1481041572738; Tue, 06 Dec 2016 08:26:12 -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 s189sm4026239lja.3.2016.12.06.08.26.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 08:26:12 -0800 (PST) From: Christophe Milard To: maxim.uvarov@linaro.com, mike.holmes@linaro.org, yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Tue, 6 Dec 2016 18:25:32 +0100 Message-Id: <1481045132-61171-1-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [lng-odp] [API-NEXT PATCHv2] 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 --- Since V1: -flag size reduced to 1 bit (maxim) -typo fix (Maxim) 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..efdb7bc 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:1; /* block FD was externally 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;