From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw0-f175.google.com (mail-yw0-f175.google.com [209.85.161.175]) by dpdk.org (Postfix) with ESMTP id 348C36CCE for ; Fri, 13 May 2016 03:22:24 +0200 (CEST) Received: by mail-yw0-f175.google.com with SMTP id j74so90023381ywg.1 for ; Thu, 12 May 2016 18:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=7gefDRU8G1wlgJykB6mEhRseeG/dYy84FKUZrmBBISU=; b=a+3s+YgtCgs3No7AlOo5RT6Zbr4EvsB/P7DbTHEDcYIxkgBj0RigRk3LN0625gJyp2 ytf49EmxtsP/U0EWijJAK0ikSd59NLBTlYKQS1cSS2BtUVFwjth2xGzBXinLid74nE33 ijCDARW64DJGqxFcdptPpVEgmosbFB/DJTJ1k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=7gefDRU8G1wlgJykB6mEhRseeG/dYy84FKUZrmBBISU=; b=IocvaWNzKBaNjQnpVydXDqKO0Ojt8IjTld38/YgiCdgqajMEqN4gEQdq2N/3jRquNh i2VrwwUHEo/lisvH9VpbiOcJKlgMVnXMUfR2cNqVFdRX8+twnYTbooUWPTOpYsWl3II4 EaZcXQGsLKWJFIaN8IcTjSKpcUbc3hJwy0AM0nEeyRfewQMOaoFwS6ytpBpG2sxQZYq7 klLAaQhBxxfKxuuWaAhBhSU/AFvjNgvJt54Lupmujfag1FKdXkIxmo+Wo2T5DLscqToY mtrsYQzdiWhzU1jZ+wwS1hYACNZNeovFdnAAt42JtyU63eNRDiH0gd3cvcVe8S1cw5QA ErCA== X-Gm-Message-State: AOPr4FVULHPE3qV7q+ioq9wP+WfdAHsodc3zqGx3boMX+Y/qoLvkLebO7aT1NFPaLxg1vAWEQnjtuuWfndqLp+fm MIME-Version: 1.0 X-Received: by 10.37.10.4 with SMTP id 4mr6224922ybk.160.1463102543614; Thu, 12 May 2016 18:22:23 -0700 (PDT) Received: by 10.37.223.2 with HTTP; Thu, 12 May 2016 18:22:23 -0700 (PDT) In-Reply-To: <1462542490-15556-4-git-send-email-viktorin@rehivetech.com> References: <1451682326-5834-1-git-send-email-viktorin@rehivetech.com> <1462542490-15556-1-git-send-email-viktorin@rehivetech.com> <1462542490-15556-4-git-send-email-viktorin@rehivetech.com> Date: Fri, 13 May 2016 09:22:23 +0800 Message-ID: From: Jianbo Liu To: Jan Viktorin Cc: dev@dpdk.org, David Marchand , Thomas Monjalon , Bruce Richardson , Declan Doherty , Jerin Jacob , Keith Wiles , Stephen Hemminger Content-Type: text/plain; charset=UTF-8 Subject: Re: [dpdk-dev] [PATCH v1 03/28] eal/linux: extract function rte_eal_unbind_kernel_driver 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: Fri, 13 May 2016 01:22:24 -0000 On 6 May 2016 at 21:47, Jan Viktorin wrote: > Generalize the PCI-specific pci_unbind_kernel_driver. It is now divided into > two parts. First, determination of the path and string identification of the > device to be unbound. Second, the actual unbind operation which is generic. > > Signed-off-by: Jan Viktorin > --- > lib/librte_eal/common/eal_private.h | 13 +++++++++++++ > lib/librte_eal/linuxapp/eal/eal.c | 26 ++++++++++++++++++++++++++ > lib/librte_eal/linuxapp/eal/eal_pci.c | 33 +++++++++------------------------ > 3 files changed, 48 insertions(+), 24 deletions(-) > > diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h > index 81816a6..3fb8353 100644 > --- a/lib/librte_eal/common/eal_private.h > +++ b/lib/librte_eal/common/eal_private.h > @@ -289,6 +289,19 @@ int rte_eal_alarm_init(void); > int rte_eal_check_module(const char *module_name); > > /** > + * Unbind kernel driver bound to the device specified by the given devpath, > + * and its string identification. > + * > + * @param devpath path to the device directory ("/sys/.../devices/") > + * @param devid identification of the device () > + * > + * @return > + * -1 unbind has failed > + * 0 module has been unbound > + */ > +int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid); > + > +/** > * Get cpu core_id. > * > * This function is private to the EAL. > diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c > index e8fce6b..844f958 100644 > --- a/lib/librte_eal/linuxapp/eal/eal.c > +++ b/lib/librte_eal/linuxapp/eal/eal.c > @@ -949,3 +949,29 @@ rte_eal_check_module(const char *module_name) > /* Module has been found */ > return 1; > } > + > +int > +rte_eal_unbind_kernel_driver(const char *devpath, const char *devid) > +{ > + char filename[PATH_MAX]; > + FILE *f; > + > + snprintf(filename, sizeof(filename), > + "%s/driver/unbind", devpath); > + > + f = fopen(filename, "w"); > + if (f == NULL) /* device was not bound */ > + return 0; > + > + if (fwrite(devid, strlen(devid), 1, f) == 0) { > + RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__, > + filename); > + goto error; > + } > + > + fclose(f); > + return 0; > +error: > + fclose(f); > + return -1; > +} > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c > index fd7e34f..312cb14 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c > @@ -59,38 +59,23 @@ int > pci_unbind_kernel_driver(struct rte_pci_device *dev) > { > int n; > - FILE *f; > - char filename[PATH_MAX]; > - char buf[BUFSIZ]; > + char devpath[PATH_MAX]; > + char devid[BUFSIZ]; > struct rte_pci_addr *loc = &dev->addr; > > - /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */ > - snprintf(filename, sizeof(filename), > - SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind", > + /* devpath /sys/bus/pci/devices/AAAA:BB:CC.D */ > + snprintf(devpath, sizeof(devpath), > + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT, > loc->domain, loc->bus, loc->devid, loc->function); > > - f = fopen(filename, "w"); > - if (f == NULL) /* device was not bound */ > - return 0; > - > - n = snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n", > + n = snprintf(devid, sizeof(devid), PCI_PRI_FMT "\n", > loc->domain, loc->bus, loc->devid, loc->function); > - if ((n < 0) || (n >= (int)sizeof(buf))) { > + if ((n < 0) || (n >= (int)sizeof(devid))) { Is it better to move "(n >= (int)sizeof(devid))" before snprintf and it has different reason from "n < 0"? > RTE_LOG(ERR, EAL, "%s(): snprintf failed\n", __func__); > - goto error; > - } > - if (fwrite(buf, n, 1, f) == 0) { > - RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__, > - filename); > - goto error; > + return -1; > } > > - fclose(f); > - return 0; > - > -error: > - fclose(f); > - return -1; > + return rte_eal_unbind_kernel_driver(devpath, devid); > } > > static int > -- > 2.8.0 >