From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 36339A046B for ; Wed, 24 Jul 2019 10:20:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E26D41C191; Wed, 24 Jul 2019 10:20:46 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 2E1741C132; Wed, 24 Jul 2019 10:20:40 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id f17so16554654pfn.6; Wed, 24 Jul 2019 01:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=o9hAIxdLsO8Gp9eacLXb8RYmP9AGNx2ipEa34GtRYV4=; b=aAJZto37xQ/64NM+5CZ4n+6tS1yBkKsrhcGhd7hWAeFGxznApWi0afjVUW0fTl5W1J TxRedrI58rcsrF/0OK1mvrh3tpdwoyce1+hGge3oFFMNXy8udLzXm5CSOLSlruGabW1M 8BjU3RmHrSW0lKbuS1v6Gd98v+Jg6dGKLHoo2VGqiG5WvH8JhZbBKrs5WHdZ8DAdGmSZ 12XImu74AE4/y15bgNhGhqOgCmmsoVYBo8mkrvjDcIh+74+d2gF5bmikNDHn8E1Fu3Hz AKaMJ5ckq4O0i5GCTU4MyPHe3hekBax100CZvhD0sUeiGiuTsoHukGPrQMwuNmouQ4A1 HRlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=o9hAIxdLsO8Gp9eacLXb8RYmP9AGNx2ipEa34GtRYV4=; b=si9LZxnU4RPxOZ1AOj3Q5syNSyM+O+Dc5K0iHeGEVqALed28W0B/mtRhPRx6NSQKvC STj4VOVl3DPORMElvzbTAXwk/qXoeUkZeiGfotnG7C94NxsA4ddGjH6AWErBeHe8k+m5 ldWghw5uIHAhFj9OzNBTa6zKIRgEt248nghAqBjusCa5S1Zm/oUGP9w+tXSi4Rsc88zs lGoYn9dj1NM0VlkuGu7b0NAzDXVHT6X11a3z5xPh9fYwNr1ca1bvXP6oypoIspLRHOR3 KHLhakhp/QueVzlJ9s+aVKh4eUBu8p4ZWEJ1dFThDS/cZXxF//+KzX0ihf9L32XeSs58 eeRg== X-Gm-Message-State: APjAAAV0iCTaouaga68ZUahuCTAPyLMTGA8Nc8SBVug+hqFzxrOTN/36 7znBzJ7N2qJOb7jHwmPr8+0= X-Google-Smtp-Source: APXvYqy2kp1I1Im78qVvyv3/hA3T6rT/9JHT7A4zcxo6f5/oDl5X/loWv5BWTwCfoGn7hde0XCq0dg== X-Received: by 2002:a62:27c2:: with SMTP id n185mr1963248pfn.79.1563956439509; Wed, 24 Jul 2019 01:20:39 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id w22sm48842558pfi.175.2019.07.24.01.20.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jul 2019 01:20:39 -0700 (PDT) From: yasufum.o@gmail.com To: anatoly.burakov@intel.com, david.marchand@redhat.com Cc: dev@dpdk.org, stable@dpdk.org, yasufum.o@gmail.com, Yasufumi Ogawa Date: Wed, 24 Jul 2019 17:20:31 +0900 Message-Id: <20190724082031.45546-2-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190724082031.45546-1-yasufum.o@gmail.com> References: <20190711103148.9187-1-yasufum.o@gmail.com> <20190724082031.45546-1-yasufum.o@gmail.com> Subject: [dpdk-dev] [PATCH v4 1/1] fbarray: get fbarrays from containerized secondary X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Yasufumi Ogawa In secondary_msl_create_walk(), it creates a file for fbarrays with its PID for reserving unique name among secondary processes. However, it does not work if secondary is run as app container because each of containerized secondary has PID 1. To reserve unique name, use hostname instead of PID because hostname is assigned as a short form of 64 digits full container ID in docker. Cc: stable@dpdk.org Signed-off-by: Yasufumi Ogawa --- lib/librte_eal/linux/eal/eal_memalloc.c | 28 +++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c index 1f6a7c18f..356b304a8 100644 --- a/lib/librte_eal/linux/eal/eal_memalloc.c +++ b/lib/librte_eal/linux/eal/eal_memalloc.c @@ -1366,6 +1366,7 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl, struct rte_memseg_list *primary_msl, *local_msl; char name[PATH_MAX]; int msl_idx, ret; + char proc_id[33] = { 0 }; /* 32bytes is enough if using hostname */ if (msl->external) return 0; @@ -1375,8 +1376,31 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl, local_msl = &local_memsegs[msl_idx]; /* create distinct fbarrays for each secondary */ - snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i", - primary_msl->memseg_arr.name, getpid()); + /* If run secondary in a container, the name of fbarray file should + * not be decided with pid because getpid() always returns 1. + * In docker, hostname is assigned as a short form of full container + * ID. So use hostname as unique ID among containers instead. + */ + if (getpid() == 1) { + FILE *hn_fp; + hn_fp = fopen("/etc/hostname", "r"); + if (hn_fp == NULL) { + RTE_LOG(ERR, EAL, + "Cannot open '/etc/hostname' for secondary\n"); + return -1; + } + + /* with docker, /etc/hostname just has one entry of hostname */ + if (fscanf(hn_fp, "%32s", proc_id) == EOF) { + fclose(hn_fp); + return -1; + } + fclose(hn_fp); + } else + sprintf(proc_id, "%d", (int)getpid()); + + snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s", + primary_msl->memseg_arr.name, proc_id); ret = rte_fbarray_init(&local_msl->memseg_arr, name, primary_msl->memseg_arr.len, -- 2.17.1