From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ferruh Yigit Subject: Re: [PATCH v4 1/6] kni: add API to set link status on kernel interface Date: Thu, 18 Oct 2018 14:44:25 +0100 Message-ID: <2f51725f-c9f0-ccad-90e4-9ca8e4a8072d@intel.com> References: <20180911232906.18352-1-dg@adax.com> <20181017010412.23141-2-dg@adax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: Igor Ryzhov , Stephen Hemminger To: Dan Gora , dev@dpdk.org Return-path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 860A25F25 for ; Thu, 18 Oct 2018 15:44:29 +0200 (CEST) In-Reply-To: <20181017010412.23141-2-dg@adax.com> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 10/17/2018 2:04 AM, Dan Gora wrote: > Add a new API function to KNI, rte_kni_update_link() to allow DPDK > applications to update the link status for KNI network interfaces in > the linux kernel. > > Signed-off-by: Dan Gora > --- > lib/librte_kni/rte_kni.c | 41 ++++++++++++++++++++++++++++++ > lib/librte_kni/rte_kni.h | 20 +++++++++++++++ > lib/librte_kni/rte_kni_version.map | 6 +++++ > 3 files changed, 67 insertions(+) > > diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c > index b8edd40f4..c9726d4f8 100644 > --- a/lib/librte_kni/rte_kni.c > +++ b/lib/librte_kni/rte_kni.c > @@ -717,6 +717,47 @@ rte_kni_unregister_handlers(struct rte_kni *kni) > > return 0; > } > + > +int __rte_experimental > +rte_kni_update_link(struct rte_kni *kni, unsigned int linkup) > +{ > + char path[64]; > + char old_carrier[2]; > + const char *new_carrier; > + int old_linkup; > + int fd, ret; > + > + if (kni == NULL) > + return -1; > + > + snprintf(path, sizeof(path), "/sys/devices/virtual/net/%s/carrier", > + kni->name); > + > + fd = open(path, O_RDWR); > + if (fd == -1) { > + RTE_LOG(ERR, KNI, "Failed to open file: %s.\n", path); > + return -1; > + } > + > + ret = read(fd, old_carrier, 2); > + if (ret < 1) { > + close(fd); > + return -1; > + } > + old_linkup = (old_carrier[0] == '1'); > + > + new_carrier = linkup ? "1" : "0"; > + ret = write(fd, new_carrier, 1); KNI sample application calls this API each 100ms, so this keeps writing "carrier" file. What do you think writing to "carrier" file only if status changed? And it is possible to register to RTE_ETH_EVENT_INTR_LSC event in sample application instead of polling but not sure if all drivers supports it. Or what do you think storing the link status in sample application and call this function only if link status changed?