Skip to contentSkip to conversation

libnetlink: check flag NLM_F_DUMP_INTR during dumps

PATCH Superseded Nicolas Dichtel 3 participants 8 messages Mar 22, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnetlink: check flag NLM_F_DUMP_INTR during dumps

When this flag is set, it means that dump was interrupted and result may be wrong. Ask user to restart.

---
 lib/libnetlink.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/libnetlink.c +6 -0
index f262959..91991cf 100644
@@ -230,6 +230,12 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 				    h->nlmsg_seq != rth->dump)
 					goto skip_it;
 
+				if (h->nlmsg_flags & NLM_F_DUMP_INTR) {
+					fprintf(stderr,
+						"Dump was interrupted, please restart.\n");
+					return -1;
+				}
+
 				if (h->nlmsg_type == NLMSG_DONE) {
 					found_done = 1;
 					break; /* process next filter */
Signature · 1 line
1.8.0.1
#1 lore raw
Quoted 4 lines · Nicolas Dichtel

When this flag is set, it means that dump was interrupted and result may be wrong. Ask user to restart.

Do we have a guarantee this will complete eventually, on some hosts constantly adding removing entries ?

#2 lore raw
Quoted 10 lines · Eric Dumazet
Quoted 4 lines · Nicolas Dichtel

When this flag is set, it means that dump was interrupted and result may be wrong. Ask user to restart.

Do we have a guarantee this will complete eventually, on some hosts constantly adding removing entries ?

No. You mean it will be better to just print a warning and continue the dump?

#3 lore raw
Quoted 8 lines · Nicolas Dichtel
Quoted 7 lines · Eric Dumazet
Quoted 4 lines · Nicolas Dichtel

When this flag is set, it means that dump was interrupted and result may be wrong. Ask user to restart.

Quoted 6 lines
Quoted 3 lines

Do we have a guarantee this will complete eventually, on some hosts constantly adding removing entries ?

No. You mean it will be better to just print a warning and continue the dump? --

I would not break the dump, return the indication, so that caller can chose to restart the loop one or two times.

#4 lore raw
Quoted 9 lines · Eric Dumazet
Quoted 8 lines · Nicolas Dichtel
Quoted 7 lines · Eric Dumazet
Quoted 4 lines · Nicolas Dichtel

When this flag is set, it means that dump was interrupted and result may be wrong. Ask user to restart.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Do we have a guarantee this will complete eventually, on some hosts constantly adding removing entries ?

No. You mean it will be better to just print a warning and continue the dump?

I would not break the dump, return the indication, so that caller can chose to restart the loop one or two times.

Right, I would do it on an informal level at first. In fact libnl will do an automatic restart of cache refills but I'm considering to make it configurable for the application.

#5 lore raw

PATCH v2 1/1 libnetlink: check flag NLM_F_DUMP_INTR during dumps

When this flag is set, it means that dump was interrupted and result may be wrong. Inform the user and let him choose to restart or not.

---

v2: do not stop the dump, only display a warning

 lib/libnetlink.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/libnetlink.c +4 -0
index f262959..1a882b2 100644
@@ -230,6 +230,10 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 				    h->nlmsg_seq != rth->dump)
 					goto skip_it;
 
+				if (h->nlmsg_flags & NLM_F_DUMP_INTR)
+					fprintf(stderr,
+						"Dump was interrupted and may be wrong.\n");
+
 				if (h->nlmsg_type == NLMSG_DONE) {
 					found_done = 1;
 					break; /* process next filter */
Signature · 1 line
1.8.0.1
#6 lore raw
Quoted 16 lines · Nicolas Dichtel

When this flag is set, it means that dump was interrupted and result may be wrong. Inform the user and let him choose to restart or not.

---

v2: do not stop the dump, only display a warning

 lib/libnetlink.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/libnetlink.c +0 -0
index f262959..1a882b2 100644

lib/libnetlink.c int rtnl_dump_filter_l(struct rtnl_handle *rth, · line 239

Quoted 10 lines
lib/libnetlink.c +4 -0
@@ -230,6 +230,10 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 				    h->nlmsg_seq != rth->dump)
 					goto skip_it;
 
+				if (h->nlmsg_flags & NLM_F_DUMP_INTR)
+					fprintf(stderr,
+						"Dump was interrupted and may be wrong.\n");
+
 				if (h->nlmsg_type == NLMSG_DONE) {
 					found_done = 1;
 					break; /* process next filter */

How many times this will be displayed ?

Please try to cook something that wont emit one warning per 8KB fetched from the kernel ;)

#7 lore raw

PATCH v3 1/1 libnetlink: check flag NLM_F_DUMP_INTR during dumps

When this flag is set, it means that dump was interrupted and result may be inconsistent.

---

v3: display the warning only once
v2: do not stop the dump, only display a warning

 lib/libnetlink.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
lib/libnetlink.c +9 -1
index f262959..04201cd 100644
@@ -194,6 +194,7 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 		.msg_iovlen = 1,
 	};
 	char buf[16384];
+	int dump_intr = 0;
 
 	iov.iov_base = buf;
 	while (1) {
@@ -230,6 +231,9 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 				    h->nlmsg_seq != rth->dump)
 					goto skip_it;
 
+				if (h->nlmsg_flags & NLM_F_DUMP_INTR)
+					dump_intr = 1;
+
 				if (h->nlmsg_type == NLMSG_DONE) {
 					found_done = 1;
 					break; /* process next filter */
@@ -254,8 +258,12 @@ skip_it:
 			}
 		}
 
-		if (found_done)
+		if (found_done) {
+			if (dump_intr)
+				fprintf(stderr,
+					"Dump was interrupted and may be inconsistent.\n");
 			return 0;
+		}
 
 		if (msg.msg_flags & MSG_TRUNC) {
 			fprintf(stderr, "Message truncated\n");
Signature · 1 line
1.8.0.1