Skip to contentSkip to conversation

sctp: loading sctp when load sctp_probe

PATCH Applied Wang Weidong 4 participants 10 messages Dec 13, 2013 – Dec 17, 2013

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

PATCH v2 1/1 sctp: loading sctp when load sctp_probe

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

---
 net/sctp/probe.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/sctp/probe.c +16 -1
index 53c452e..5e68b94 100644
@@ -38,6 +38,7 @@
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
 
+MODULE_SOFTDEP("pre: sctp");
 MODULE_AUTHOR("Wei Yongjun <[email protected]>");
 MODULE_DESCRIPTION("SCTP snooper");
 MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
 	.entry	= jsctp_sf_eat_sack,
 };
 
+static __init int sctp_setup_jprobe(void)
+{
+	int ret = register_jprobe(&sctp_recv_probe);
+
+	if (ret) {
+		if (request_module("sctp"))
+			goto out;
+		ret = register_jprobe(&sctp_recv_probe);
+	}
+
+out:
+	return ret;
+}
+
 static __init int sctpprobe_init(void)
 {
 	int ret = -ENOMEM;
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
 			 &sctpprobe_fops))
 		goto free_kfifo;
 
-	ret = register_jprobe(&sctp_recv_probe);
+	ret = sctp_setup_jprobe();
 	if (ret)
 		goto remove_proc;
 
Signature · 1 line
1.7.12
#1 lore raw
Quoted 46 lines · Wang Weidong

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

---
 net/sctp/probe.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/sctp/probe.c +15 -0
index 53c452e..5e68b94 100644
@@ -38,6 +38,7 @@
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
 
+MODULE_SOFTDEP("pre: sctp");
 MODULE_AUTHOR("Wei Yongjun <[email protected]>");
 MODULE_DESCRIPTION("SCTP snooper");
 MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
 	.entry	= jsctp_sf_eat_sack,
 };
 
+static __init int sctp_setup_jprobe(void)
+{
+	int ret = register_jprobe(&sctp_recv_probe);
+
+	if (ret) {
+		if (request_module("sctp"))
+			goto out;
+		ret = register_jprobe(&sctp_recv_probe);
+	}
+
+out:
+	return ret;
+}
+
 static __init int sctpprobe_init(void)
 {
 	int ret = -ENOMEM;

net/sctp/probe.c static __init int sctpprobe_init(void) · line 220

Quoted 5 lines
net/sctp/probe.c +1 -1
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
 			 &sctpprobe_fops))
 		goto free_kfifo;
 
-	ret = register_jprobe(&sctp_recv_probe);
+	ret = sctp_setup_jprobe();

You don't need to create your own function for this, you can collapse it down to a call to try_then_request_module(regitser_jprobe(...), "sctp"); Neil

Quoted 3 lines
net/sctp/probe.c +0 -0
 	if (ret)
 		goto remove_proc;
 
#2 lore raw

From: Wang weidong <[email protected]>

Quoted 50 lines · Neil Horman
Quoted 49 lines · Wang Weidong

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

---
  net/sctp/probe.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
net/sctp/probe.c +15 -0
index 53c452e..5e68b94 100644
@@ -38,6 +38,7 @@
  #include <net/sctp/sctp.h>
  #include <net/sctp/sm.h>
 
+MODULE_SOFTDEP("pre: sctp");
  MODULE_AUTHOR("Wei Yongjun <[email protected]>");
  MODULE_DESCRIPTION("SCTP snooper");
  MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
  	.entry	= jsctp_sf_eat_sack,
  };
 
+static __init int sctp_setup_jprobe(void)
+{
+	int ret = register_jprobe(&sctp_recv_probe);
+
+	if (ret) {
+		if (request_module("sctp"))
+			goto out;
+		ret = register_jprobe(&sctp_recv_probe);
+	}
+
+out:
+	return ret;
+}
+
  static __init int sctpprobe_init(void)
  {
  	int ret = -ENOMEM;
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
  			 &sctpprobe_fops))
  		goto free_kfifo;
 
Quoted 6 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 220

Quoted 2 lines
net/sctp/probe.c +1 -1
-	ret = register_jprobe(&sctp_recv_probe);
+	ret = sctp_setup_jprobe();

You don't need to create your own function for this, you can collapse it down to a call to try_then_request_module(regitser_jprobe(...), "sctp"); Neil

It looks good. Thanks. I will try to use it and fix in v3.

Regards.
Wang

Quoted 9 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 223

Quoted 4 lines
net/sctp/probe.c +0 -0
  	if (ret)
  		goto remove_proc;
 

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Neil Horman
Quoted 50 lines · Neil Horman
Quoted 49 lines · Wang Weidong

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

---
 net/sctp/probe.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/sctp/probe.c +15 -0
index 53c452e..5e68b94 100644
@@ -38,6 +38,7 @@
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
 
+MODULE_SOFTDEP("pre: sctp");
 MODULE_AUTHOR("Wei Yongjun <[email protected]>");
 MODULE_DESCRIPTION("SCTP snooper");
 MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
 	.entry	= jsctp_sf_eat_sack,
 };
 
+static __init int sctp_setup_jprobe(void)
+{
+	int ret = register_jprobe(&sctp_recv_probe);
+
+	if (ret) {
+		if (request_module("sctp"))
+			goto out;
+		ret = register_jprobe(&sctp_recv_probe);
+	}
+
+out:
+	return ret;
+}
+
 static __init int sctpprobe_init(void)
 {
 	int ret = -ENOMEM;
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
 			 &sctpprobe_fops))
 		goto free_kfifo;
 
Quoted 6 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 220

Quoted 2 lines
net/sctp/probe.c +1 -1
-	ret = register_jprobe(&sctp_recv_probe);
+	ret = sctp_setup_jprobe();

You don't need to create your own function for this, you can collapse it down to a call to try_then_request_module(regitser_jprobe(...), "sctp"); Neil

Hi Neil,

I try to use try_then_request_module(!regitser_jprobe(...), "sctp"); I found that if I used this, I couldn't get the ture value which returned by register_jprobe(). Is the returned value not important? The problem("if sctp.ko doesn't exist") you had pointed out is exist as well.

Regards.
Wang

Quoted 7 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 223

Quoted 4 lines
net/sctp/probe.c +0 -0
 	if (ret)
 		goto remove_proc;
 

.

#4 lore raw
Quoted 59 lines · Wang Weidong
Quoted 50 lines · Neil Horman
Quoted 49 lines · Wang Weidong

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

---
 net/sctp/probe.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/sctp/probe.c +15 -0
index 53c452e..5e68b94 100644
@@ -38,6 +38,7 @@
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
 
+MODULE_SOFTDEP("pre: sctp");
 MODULE_AUTHOR("Wei Yongjun <[email protected]>");
 MODULE_DESCRIPTION("SCTP snooper");
 MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
 	.entry	= jsctp_sf_eat_sack,
 };
 
+static __init int sctp_setup_jprobe(void)
+{
+	int ret = register_jprobe(&sctp_recv_probe);
+
+	if (ret) {
+		if (request_module("sctp"))
+			goto out;
+		ret = register_jprobe(&sctp_recv_probe);
+	}
+
+out:
+	return ret;
+}
+
 static __init int sctpprobe_init(void)
 {
 	int ret = -ENOMEM;
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
 			 &sctpprobe_fops))
 		goto free_kfifo;
 
Quoted 6 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 220

Quoted 2 lines
net/sctp/probe.c +1 -1
-	ret = register_jprobe(&sctp_recv_probe);
+	ret = sctp_setup_jprobe();

You don't need to create your own function for this, you can collapse it down to a call to try_then_request_module(regitser_jprobe(...), "sctp"); Neil

Hi Neil,

Quoted 7 lines

I try to use try_then_request_module(!regitser_jprobe(...), "sctp"); I found that if I used this, I couldn't get the ture value which returned by register_jprobe(). Is the returned value not important? The problem("if sctp.ko doesn't exist") you had pointed out is exist as well.

Regards.
Wang

Not sure I follow. There appear to be lots of examples in the kernel where exactly what you are trying to do is done. try_then_request_module calls your requested method, and if it returns non-zero, calls request_module, then calls your requested method again, returning the final result. What problem are you running into?
Neil

Quoted 10 lines
Quoted 7 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 223

Quoted 4 lines
net/sctp/probe.c +0 -0
 	if (ret)
 		goto remove_proc;
 

.

#5 lore raw

From: Wang Weidong <[email protected]>

Quoted 65 lines · Neil Horman
Quoted 64 lines · Wang Weidong
Quoted 50 lines · Neil Horman
Quoted 49 lines · Wang Weidong

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

---
  net/sctp/probe.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
net/sctp/probe.c +15 -0
index 53c452e..5e68b94 100644
@@ -38,6 +38,7 @@
  #include <net/sctp/sctp.h>
  #include <net/sctp/sm.h>
 
+MODULE_SOFTDEP("pre: sctp");
  MODULE_AUTHOR("Wei Yongjun <[email protected]>");
  MODULE_DESCRIPTION("SCTP snooper");
  MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
  	.entry	= jsctp_sf_eat_sack,
  };
 
+static __init int sctp_setup_jprobe(void)
+{
+	int ret = register_jprobe(&sctp_recv_probe);
+
+	if (ret) {
+		if (request_module("sctp"))
+			goto out;
+		ret = register_jprobe(&sctp_recv_probe);
+	}
+
+out:
+	return ret;
+}
+
  static __init int sctpprobe_init(void)
  {
  	int ret = -ENOMEM;
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
  			 &sctpprobe_fops))
  		goto free_kfifo;
 
Quoted 6 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 220

Quoted 2 lines
net/sctp/probe.c +1 -1
-	ret = register_jprobe(&sctp_recv_probe);
+	ret = sctp_setup_jprobe();

You don't need to create your own function for this, you can collapse it down to a call to try_then_request_module(regitser_jprobe(...), "sctp"); Neil

Hi Neil,

I try to use try_then_request_module(!regitser_jprobe(...), "sctp"); I found that if I used this, I couldn't get the ture value which returned by register_jprobe(). Is the returned value not important? The problem("if sctp.ko doesn't exist") you had pointed out is exist as well.

Quoted 4 lines
Quoted 2 lines

Regards.
Wang

Not sure I follow. There appear to be lots of examples in the kernel where

I do this just like the dccp/probe.c do. So I think it can be an example.

Quoted 2 lines

exactly what you are trying to do is done. try_then_request_module calls your requested method, and if it returns non-zero, calls request_module, then calls

No actually. Just look the definition:

#define try_then_request_module(x, mod...) \
         ((x) ?: (__request_module(true, mod), (x)))

if x return non-zero, it will return the value, not call request_module.

Quoted 4 lines

your requested method again, returning the final result. What problem are you running into?
Neil

So I only can use it like this:
try_then_request_module(!regitser_jprobe(...), "sctp");

when register_jprobe return 0 indicates success, I get the value is 1. It is OK.

when register_jprobe is non-zero indicates failed, then calls request_module, and last calls register_jprobe. Here,
1)maybe it will failed return non-zero, what I get the value is !register_jprobe is 0 with losing the value.
2)request_module failed with the sctp is not exist, it will do the register_jprobe as well.

Is there I am wrong somewhere?

Regards.
Wang

Quoted 15 lines
Quoted 10 lines
Quoted 7 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 223

Quoted 4 lines
net/sctp/probe.c +0 -0
  	if (ret)
  		goto remove_proc;
 

.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Acked-by
#6 lore raw
Quoted 68 lines · Wang Weidong

From: Wang Weidong <[email protected]>

Quoted 65 lines · Neil Horman
Quoted 64 lines · Wang Weidong
Quoted 50 lines · Neil Horman
Quoted 49 lines · Wang Weidong

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

---
 net/sctp/probe.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/sctp/probe.c +15 -0
index 53c452e..5e68b94 100644
@@ -38,6 +38,7 @@
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
 
+MODULE_SOFTDEP("pre: sctp");
 MODULE_AUTHOR("Wei Yongjun <[email protected]>");
 MODULE_DESCRIPTION("SCTP snooper");
 MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
 	.entry	= jsctp_sf_eat_sack,
 };
 
+static __init int sctp_setup_jprobe(void)
+{
+	int ret = register_jprobe(&sctp_recv_probe);
+
+	if (ret) {
+		if (request_module("sctp"))
+			goto out;
+		ret = register_jprobe(&sctp_recv_probe);
+	}
+
+out:
+	return ret;
+}
+
 static __init int sctpprobe_init(void)
 {
 	int ret = -ENOMEM;
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
 			 &sctpprobe_fops))
 		goto free_kfifo;
 
Quoted 6 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 220

Quoted 2 lines
net/sctp/probe.c +1 -1
-	ret = register_jprobe(&sctp_recv_probe);
+	ret = sctp_setup_jprobe();

You don't need to create your own function for this, you can collapse it down to a call to try_then_request_module(regitser_jprobe(...), "sctp"); Neil

Hi Neil,

I try to use try_then_request_module(!regitser_jprobe(...), "sctp"); I found that if I used this, I couldn't get the ture value which returned by register_jprobe(). Is the returned value not important? The problem("if sctp.ko doesn't exist") you had pointed out is exist as well.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Regards.
Wang

Not sure I follow. There appear to be lots of examples in the kernel where

I do this just like the dccp/probe.c do. So I think it can be an example.

Ah thats right, I remember doing this before now. My bad.

Quoted 18 lines
Quoted 2 lines

exactly what you are trying to do is done. try_then_request_module calls your requested method, and if it returns non-zero, calls request_module, then calls

No actually. Just look the definition:

#define try_then_request_module(x, mod...) \
         ((x) ?: (__request_module(true, mod), (x)))

if x return non-zero, it will return the value, not call request_module.

Quoted 4 lines

your requested method again, returning the final result. What problem are you running into?
Neil

So I only can use it like this:
try_then_request_module(!regitser_jprobe(...), "sctp");

when register_jprobe return 0 indicates success, I get the value is 1. It is OK.

Quoted 9 lines

when register_jprobe is non-zero indicates failed, then calls request_module, and last calls register_jprobe. Here,
1)maybe it will failed return non-zero, what I get the value is !register_jprobe is 0 with losing the value.
2)request_module failed with the sctp is not exist, it will do the register_jprobe as well.

Is there I am wrong somewhere?

It really seems like there should be a way to roll up what you want into the try_then_request_module macro. What about:

ret = try_then_request_module((register_jprobe(...) = 0), "sctp");

That seems like it should work. It will mask the actual return value of register_jprobe though I think, which kind of sucks. Its almost like we need another variant of this macro that accepts an expected condition result so the macro can use it to compare, something like:

#define try_then_request_module_cond(x, result, mod...) \
	((x) = (result) ?: __request_module(true, mod), (x)))

that would let you set an expected comparison value for your macro, but get the result of the method if it still fails after the module is loaded, or if it fails to load.

Thats probably a cleanup for a second patch. I think your version two is probably as close as we're going to get right now. So for v2:

#7 lore raw

From: Wang Weidong <[email protected]>

Quoted 104 lines · Neil Horman
Quoted 68 lines · Wang Weidong

From: Wang Weidong <[email protected]>

Quoted 65 lines · Neil Horman
Quoted 64 lines · Wang Weidong
Quoted 50 lines · Neil Horman
Quoted 49 lines · Wang Weidong

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

---
  net/sctp/probe.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
net/sctp/probe.c +15 -0
index 53c452e..5e68b94 100644
@@ -38,6 +38,7 @@
  #include <net/sctp/sctp.h>
  #include <net/sctp/sm.h>
 
+MODULE_SOFTDEP("pre: sctp");
  MODULE_AUTHOR("Wei Yongjun <[email protected]>");
  MODULE_DESCRIPTION("SCTP snooper");
  MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
  	.entry	= jsctp_sf_eat_sack,
  };
 
+static __init int sctp_setup_jprobe(void)
+{
+	int ret = register_jprobe(&sctp_recv_probe);
+
+	if (ret) {
+		if (request_module("sctp"))
+			goto out;
+		ret = register_jprobe(&sctp_recv_probe);
+	}
+
+out:
+	return ret;
+}
+
  static __init int sctpprobe_init(void)
  {
  	int ret = -ENOMEM;
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
  			 &sctpprobe_fops))
  		goto free_kfifo;
 
Quoted 6 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 220

Quoted 2 lines
net/sctp/probe.c +1 -1
-	ret = register_jprobe(&sctp_recv_probe);
+	ret = sctp_setup_jprobe();

You don't need to create your own function for this, you can collapse it down to a call to try_then_request_module(regitser_jprobe(...), "sctp"); Neil

Hi Neil,

I try to use try_then_request_module(!regitser_jprobe(...), "sctp"); I found that if I used this, I couldn't get the ture value which returned by register_jprobe(). Is the returned value not important? The problem("if sctp.ko doesn't exist") you had pointed out is exist as well.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Regards.
Wang

Not sure I follow. There appear to be lots of examples in the kernel where

I do this just like the dccp/probe.c do. So I think it can be an example.

Ah thats right, I remember doing this before now. My bad.

Quoted 25 lines
Quoted 2 lines

exactly what you are trying to do is done. try_then_request_module calls your requested method, and if it returns non-zero, calls request_module, then calls

No actually. Just look the definition:

#define try_then_request_module(x, mod...) \
          ((x) ?: (__request_module(true, mod), (x)))

if x return non-zero, it will return the value, not call request_module.

Quoted 4 lines

your requested method again, returning the final result. What problem are you running into?
Neil

So I only can use it like this:
try_then_request_module(!regitser_jprobe(...), "sctp");

when register_jprobe return 0 indicates success, I get the value is 1. It is OK.

when register_jprobe is non-zero indicates failed, then calls request_module, and last calls register_jprobe. Here,
1)maybe it will failed return non-zero, what I get the value is !register_jprobe is 0 with losing the value.
2)request_module failed with the sctp is not exist, it will do the register_jprobe as well.

Quoted 8 lines
Quoted 2 lines

Is there I am wrong somewhere?

It really seems like there should be a way to roll up what you want into the try_then_request_module macro. What about:

ret = try_then_request_module((register_jprobe(...) == 0), "sctp");

The first problem maybe exist. because the last value is x. So if use this it always return (register_jprobe(...) == 0) while the value is only 1 or 0.

Quoted 11 lines

That seems like it should work. It will mask the actual return value of register_jprobe though I think, which kind of sucks. Its almost like we need another variant of this macro that accepts an expected condition result so the macro can use it to compare, something like:

#define try_then_request_module_cond(x, result, mod...) \
	((x) == (result) ?: __request_module(true, mod), (x)))

that would let you set an expected comparison value for your macro, but get the result of the method if it still fails after the module is loaded, or if it fails to load.

I think this is a good idea.

Quoted 6 lines

Thats probably a cleanup for a second patch. I think your version two is probably as close as we're going to get right now. So for v2:

Thanks.

Will you send the cleanup patch?

Regards.
Wang

#8 lore raw
Quoted 133 lines · Wang Weidong

From: Wang Weidong <[email protected]>

Quoted 104 lines · Neil Horman
Quoted 68 lines · Wang Weidong

From: Wang Weidong <[email protected]>

Quoted 65 lines · Neil Horman
Quoted 64 lines · Wang Weidong
Quoted 50 lines · Neil Horman
Quoted 49 lines · Wang Weidong

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

---
 net/sctp/probe.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/sctp/probe.c +15 -0
index 53c452e..5e68b94 100644
@@ -38,6 +38,7 @@
 #include <net/sctp/sctp.h>
 #include <net/sctp/sm.h>
 
+MODULE_SOFTDEP("pre: sctp");
 MODULE_AUTHOR("Wei Yongjun <[email protected]>");
 MODULE_DESCRIPTION("SCTP snooper");
 MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
 	.entry	= jsctp_sf_eat_sack,
 };
 
+static __init int sctp_setup_jprobe(void)
+{
+	int ret = register_jprobe(&sctp_recv_probe);
+
+	if (ret) {
+		if (request_module("sctp"))
+			goto out;
+		ret = register_jprobe(&sctp_recv_probe);
+	}
+
+out:
+	return ret;
+}
+
 static __init int sctpprobe_init(void)
 {
 	int ret = -ENOMEM;
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
 			 &sctpprobe_fops))
 		goto free_kfifo;
 
Quoted 6 lines

net/sctp/probe.c static __init int sctpprobe_init(void) · line 220

Quoted 2 lines
net/sctp/probe.c +1 -1
-	ret = register_jprobe(&sctp_recv_probe);
+	ret = sctp_setup_jprobe();

You don't need to create your own function for this, you can collapse it down to a call to try_then_request_module(regitser_jprobe(...), "sctp"); Neil

Hi Neil,

I try to use try_then_request_module(!regitser_jprobe(...), "sctp"); I found that if I used this, I couldn't get the ture value which returned by register_jprobe(). Is the returned value not important? The problem("if sctp.ko doesn't exist") you had pointed out is exist as well.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Regards.
Wang

Not sure I follow. There appear to be lots of examples in the kernel where

I do this just like the dccp/probe.c do. So I think it can be an example.

Ah thats right, I remember doing this before now. My bad.

Quoted 25 lines
Quoted 2 lines

exactly what you are trying to do is done. try_then_request_module calls your requested method, and if it returns non-zero, calls request_module, then calls

No actually. Just look the definition:

#define try_then_request_module(x, mod...) \
         ((x) ?: (__request_module(true, mod), (x)))

if x return non-zero, it will return the value, not call request_module.

Quoted 4 lines

your requested method again, returning the final result. What problem are you running into?
Neil

So I only can use it like this:
try_then_request_module(!regitser_jprobe(...), "sctp");

when register_jprobe return 0 indicates success, I get the value is 1. It is OK.

when register_jprobe is non-zero indicates failed, then calls request_module, and last calls register_jprobe. Here,
1)maybe it will failed return non-zero, what I get the value is !register_jprobe is 0 with losing the value.
2)request_module failed with the sctp is not exist, it will do the register_jprobe as well.

Quoted 8 lines
Quoted 2 lines

Is there I am wrong somewhere?

It really seems like there should be a way to roll up what you want into the try_then_request_module macro. What about:

ret = try_then_request_module((register_jprobe(...) = 0), "sctp");

The first problem maybe exist. because the last value is x. So if use this it always return (register_jprobe(...) = 0) while the value is only 1 or 0.

Quoted 11 lines

That seems like it should work. It will mask the actual return value of register_jprobe though I think, which kind of sucks. Its almost like we need another variant of this macro that accepts an expected condition result so the macro can use it to compare, something like:

#define try_then_request_module_cond(x, result, mod...) \
	((x) = (result) ?: __request_module(true, mod), (x)))

that would let you set an expected comparison value for your macro, but get the result of the method if it still fails after the module is loaded, or if it fails to load.

I think this is a good idea.

Quoted 1 line
Quoted 9 lines
Quoted 5 lines

Thats probably a cleanup for a second patch. I think your version two is probably as close as we're going to get right now. So for v2:

Thanks.

Will you send the cleanup patch?

Yeah, I'll look into developing a new macro and cleaning it up as soon as I can.

Thanks
Neil

maintainer Applied
#9 lore raw
In reply to Wang Weidong

From: Wang Weidong <[email protected]>
Date: Fri, 13 Dec 2013 11:00:10 +0800

Quoted 8 lines

when I modprobe sctp_probe, it failed with "FATAL: ". I found that sctp should load before sctp_probe register jprobe. So I add a sctp_setup_jprobe for loading 'sctp' when first failed to register jprobe, just do this similar to dccp_probe.

v2: add MODULE_SOFTDEP and check of request_module, as suggested by Neil

Applied.