From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 634465683 for ; Wed, 9 Dec 2015 08:30:03 +0100 (CET) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 9DB153D495; Wed, 9 Dec 2015 07:30:02 +0000 (UTC) Received: from sopuli.koti.laiskiainen.org (vpn1-5-27.ams2.redhat.com [10.36.5.27]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tB97U11K015248; Wed, 9 Dec 2015 02:30:02 -0500 To: Kamil Rytarowski , dev@dpdk.org References: <1449513365-22282-1-git-send-email-Kamil.Rytarowski@caviumnetworks.com> <1449588833-485-1-git-send-email-Kamil.Rytarowski@caviumnetworks.com> <1449588833-485-2-git-send-email-Kamil.Rytarowski@caviumnetworks.com> From: Panu Matilainen Message-ID: <5667D879.9020006@redhat.com> Date: Wed, 9 Dec 2015 09:30:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <1449588833-485-2-git-send-email-Kamil.Rytarowski@caviumnetworks.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Subject: Re: [dpdk-dev] [PATCH v4 2/2] eal/linux: Add support for handling built-in kernel modules X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Dec 2015 07:30:03 -0000 On 12/08/2015 05:33 PM, Kamil Rytarowski wrote: > Currently rte_eal_check_module() detects Linux kernel modules via reading > /proc/modules. Built-in ones aren't listed there and therefore they are not > being found by the script. > > Add support for checking built-in modules with parsing the sysfs files > > This commit obsoletes the /proc/modules parsing approach. > > Signed-off-by: Kamil Rytarowski > Signed-off-by: David Marchand > --- > lib/librte_eal/linuxapp/eal/eal.c | 34 ++++++++++++++++++++-------------- > 1 file changed, 20 insertions(+), 14 deletions(-) > > diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c > index 635ec36..92482a0 100644 > --- a/lib/librte_eal/linuxapp/eal/eal.c > +++ b/lib/librte_eal/linuxapp/eal/eal.c > @@ -901,27 +901,33 @@ int rte_eal_has_hugepages(void) > int > rte_eal_check_module(const char *module_name) > { > - char mod_name[30]; /* Any module names can be longer than 30 bytes? */ > - int ret = 0; > + char sysfs_mod_name[PATH_MAX]; > + struct stat st; > int n; > > if (NULL == module_name) > return -1; > > - FILE *fd = fopen("/proc/modules", "r"); > - if (NULL == fd) { > - RTE_LOG(ERR, EAL, "Open /proc/modules failed!" > - " error %i (%s)\n", errno, strerror(errno)); > + /* Check if there is sysfs mounted */ > + if (stat("/sys/module", &st) != 0) { > + RTE_LOG(DEBUG, EAL, "sysfs is not mounted! error %i (%s)\n", > + errno, strerror(errno)); > return -1; > } > - while (!feof(fd)) { > - n = fscanf(fd, "%29s %*[^\n]", mod_name); > - if ((n == 1) && !strcmp(mod_name, module_name)) { > - ret = 1; > - break; > - } > + > + /* A module might be built-in, therefore try sysfs */ > + n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name); > + if (n < 0 || n > PATH_MAX) { > + RTE_LOG(DEBUG, EAL, "Could not format module path\n"); > + return -1; > } > - fclose(fd); > > - return ret; > + if (stat(sysfs_mod_name, &st) != 0) { > + RTE_LOG(DEBUG, EAL, "Open %s failed! error %i (%s)\n", > + sysfs_mod_name, errno, strerror(errno)); > + return 0; > + } Like with /sys/module, its not trying to *open* sysfs_mod_name directory either so it shouldn't claim to do so. I did use plural on purpose when I said "the debug messages are incorrect/misleading. It's certainly not trying to *open* these directories so it should not claim to do so" in my previous mail :) - Panu -