Skip to contentSkip to conversation

kni: fix rte_kni_update_link

PATCH In review Igor Ryzhov 3 participants 5 messages Jan 24, 2019 – Feb 5, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kni: fix rte_kni_update_link

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")
---
 lib/librte_kni/rte_kni.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/librte_kni/rte_kni.c +6 -0
index 73aeccccf..5899bb14a 100644
@@ -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) {
Signature · 1 line
2.20.1
#1 lore raw

Hi Ferruh,

Can you, please, take a look at this patch?
The current implementation is broken, I think the patch should be merged into 19.02 and 18.11.1.

Best regards,
Igor

Quoted 35 lines · Igor Ryzhov

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: [email protected]

---
 lib/librte_kni/rte_kni.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/librte_kni/rte_kni.c +6 -0
index 73aeccccf..5899bb14a 100644
@@ -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) {

--
2.20.1

#2 lore raw

Hi again,

Sorry for bothering, I should have done more testing. It works as it is now. So, self NACK on the patch.

Best regards,
Igor

Quoted 46 lines · Igor Ryzhov

Hi Ferruh,

Can you, please, take a look at this patch?
The current implementation is broken, I think the patch should be merged into 19.02 and 18.11.1.

Best regards,
Igor

Quoted 35 lines · Igor Ryzhov

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: [email protected]

---
 lib/librte_kni/rte_kni.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/librte_kni/rte_kni.c +6 -0
index 73aeccccf..5899bb14a 100644
@@ -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) {

--
2.20.1

#3 lore raw
Quoted 4 lines · Igor Ryzhov

Hi again,

Sorry for bothering, I should have done more testing. It works as it is now. So, self NACK on the patch.

Thanks for the update Igor.

Since the file is pseudo-file, sysfs, I would expect no seek operation should be required, your update confirms this.
Meanwhile there is a unit test 'kni_autotest' when you want to test link update.

Thanks,
ferruh

Quoted 53 lines

Best regards,
Igor

Quoted 46 lines · Igor Ryzhov

Hi Ferruh,

Can you, please, take a look at this patch?
The current implementation is broken, I think the patch should be merged into 19.02 and 18.11.1.

Best regards,
Igor

Quoted 35 lines · Igor Ryzhov

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: [email protected]

---
 lib/librte_kni/rte_kni.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/librte_kni/rte_kni.c +6 -0
index 73aeccccf..5899bb14a 100644
@@ -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) {

--
2.20.1

#4 lore raw
In reply to Igor Ryzhov
Quoted 18 lines · On Thu, 24 Jan 2019 23:47:49 +0300 Igor Ryzhov <[email protected]> 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")
---
 lib/librte_kni/rte_kni.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/librte_kni/rte_kni.c +0 -0
index 73aeccccf..5899bb14a 100644
@@ -746,6 +746,12 @@ rte_kni_update_link(struct rte_kni *kni, unsigned int linkup)
 	}
 	old_linkup = (old_carrier[0] == '1');

lib/librte_kni/rte_kni.c rte_kni_update_link(struct rte_kni *kni, unsigned int linkup) · line 757

Quoted 10 lines
lib/librte_kni/rte_kni.c +6 -0
 
+	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?