From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH] kni: fix rte_kni_update_link Date: Tue, 5 Feb 2019 14:45:50 -0800 Message-ID: <20190205144550.10f76a1b@hermes.lan> References: <20190124204749.49912-1-iryzhov@nfware.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org, stable@dpdk.org To: Igor Ryzhov Return-path: Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 94B5758CB for ; Tue, 5 Feb 2019 23:46:01 +0100 (CET) Received: by mail-pg1-f195.google.com with SMTP id z11so2063518pgu.0 for ; Tue, 05 Feb 2019 14:46:01 -0800 (PST) In-Reply-To: <20190124204749.49912-1-iryzhov@nfware.com> 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 Thu, 24 Jan 2019 23:47:49 +0300 Igor Ryzhov wrote: > After read, file offset must be set to 0 before write. > Otherwise, the third byte will be overwritten instead of the first. > > Fixes: c6fd54f28c24 ("kni: add function to set link state on kernel interface") > Cc: stable@dpdk.org > > Signed-off-by: Igor Ryzhov > --- > lib/librte_kni/rte_kni.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c > index 73aeccccf..5899bb14a 100644 > --- a/lib/librte_kni/rte_kni.c > +++ b/lib/librte_kni/rte_kni.c > @@ -746,6 +746,12 @@ rte_kni_update_link(struct rte_kni *kni, unsigned int linkup) > } > old_linkup = (old_carrier[0] == '1'); > > + if (lseek(fd, 0, SEEK_SET) == -1) { > + RTE_LOG(ERR, KNI, "Failed to change file position: %s.\n", path); > + close(fd); > + return -1; > + } > + > new_carrier = linkup ? "1" : "0"; > ret = write(fd, new_carrier, 1); > if (ret < 1) { Why not use pwrite() which is atomic?