Skip to contentSkip to conversation

net: core: add netdev_class_has_file_ns() helper function

PATCH In review Taehee Yoo 2 participants 5 messages Apr 4, 2020 – Apr 5, 2020

Subsystems (2)
lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH v2 2/3 net: core: add netdev_class_has_file_ns() helper function

This helper function is to check whether the class file "/sys/class/net/*" is existing or not.
In the next patch, this helper function will be used.

Reported-by [email protected]
Fixes b76cdba9cdb2 ("[PATCH] bonding: add sysfs functionality to bonding (large)")

---

v1 -> v2:
- use class_has_file_ns(), which is introduced by the first patch.

 include/linux/netdevice.h | 2 +-
 net/core/net-sysfs.c      | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/netdevice.h +1 -1
index 130a668049ab..a04c487c0975 100644
@@ -4555,7 +4555,7 @@ int netdev_class_create_file_ns(const struct class_attribute *class_attr,
 				const void *ns);
 void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
 				 const void *ns);
-
+bool netdev_class_has_file_ns(const char *name, const void *ns);
 static inline int netdev_class_create_file(const struct class_attribute *class_attr)
 {
 	return netdev_class_create_file_ns(class_attr, NULL);
net/core/net-sysfs.c +6 -0
index cf0215734ceb..8a20d658eff0 100644
@@ -1914,6 +1914,12 @@ void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
 }
 EXPORT_SYMBOL(netdev_class_remove_file_ns);
 
+bool netdev_class_has_file_ns(const char *name, const void *ns)
+{
+	return class_has_file_ns(&net_class, name, ns);
+}
+EXPORT_SYMBOL(netdev_class_has_file_ns);
+
 int __init netdev_kobject_init(void)
 {
 	kobj_ns_type_register(&net_ns_type_operations);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 34 lines · Taehee Yoo

This helper function is to check whether the class file "/sys/class/net/*" is existing or not.
In the next patch, this helper function will be used.

Reported-by [email protected]
Fixes b76cdba9cdb2 ("[PATCH] bonding: add sysfs functionality to bonding (large)")

---

v1 -> v2:
- use class_has_file_ns(), which is introduced by the first patch.

 include/linux/netdevice.h | 2 +-
 net/core/net-sysfs.c      | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/netdevice.h +1 -1
index 130a668049ab..a04c487c0975 100644
@@ -4555,7 +4555,7 @@ int netdev_class_create_file_ns(const struct class_attribute *class_attr,
 				const void *ns);
 void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
 				 const void *ns);
-
+bool netdev_class_has_file_ns(const char *name, const void *ns);
 static inline int netdev_class_create_file(const struct class_attribute *class_attr)
 {
 	return netdev_class_create_file_ns(class_attr, NULL);
net/core/net-sysfs.c +0 -0
index cf0215734ceb..8a20d658eff0 100644

net/core/net-sysfs.c void netdev_class_remove_file_ns(const struct class_attribute *class_attr, · line 1921

Quoted 8 lines
net/core/net-sysfs.c +5 -0
@@ -1914,6 +1914,12 @@ void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
 }
 EXPORT_SYMBOL(netdev_class_remove_file_ns);
 
+bool netdev_class_has_file_ns(const char *name, const void *ns)
+{
+	return class_has_file_ns(&net_class, name, ns);
+}
+EXPORT_SYMBOL(netdev_class_has_file_ns);

Again, this feels broken, it can not solve a race condition.

greg k-h

author
#2 lore raw
Quoted 1 line · Greg KH

Hi Greg,
Thank you for your review!

Quoted 38 lines · Taehee Yoo
Quoted 37 lines

This helper function is to check whether the class file "/sys/class/net/*" is existing or not.
In the next patch, this helper function will be used.

Reported-by [email protected]
Fixes b76cdba9cdb2 ("[PATCH] bonding: add sysfs functionality to bonding (large)")

---

v1 -> v2:
- use class_has_file_ns(), which is introduced by the first patch.

 include/linux/netdevice.h | 2 +-
 net/core/net-sysfs.c      | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/netdevice.h +1 -1
index 130a668049ab..a04c487c0975 100644
@@ -4555,7 +4555,7 @@ int netdev_class_create_file_ns(const struct class_attribute *class_attr,
                              const void *ns);
 void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
                               const void *ns);
-
+bool netdev_class_has_file_ns(const char *name, const void *ns);
 static inline int netdev_class_create_file(const struct class_attribute *class_attr)
 {
      return netdev_class_create_file_ns(class_attr, NULL);
net/core/net-sysfs.c +0 -0
index cf0215734ceb..8a20d658eff0 100644
@@ -1914,6 +1914,12 @@ void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
 }
 EXPORT_SYMBOL(netdev_class_remove_file_ns);
 
Quoted 8 lines

net/core/net-sysfs.c void netdev_class_remove_file_ns(const struct class_attribute *class_attr, · line 1921

Quoted 5 lines
net/core/net-sysfs.c +5 -0
+bool netdev_class_has_file_ns(const char *name, const void *ns)
+{
+     return class_has_file_ns(&net_class, name, ns);
+}
+EXPORT_SYMBOL(netdev_class_has_file_ns);

Again, this feels broken, it can not solve a race condition.

This function is considered to be used under rtnl mutex and I assume that no one could use "/sys/class/net/*" outside of rtnl mutex. So, I think it returns the correct information under rtnl mutex.

Thanks a lot!
Taehee Yoo

#3 lore raw
Quoted 53 lines · Taehee Yoo
Quoted 1 line · Greg KH

Hi Greg,
Thank you for your review!

Quoted 38 lines · Taehee Yoo
Quoted 37 lines

This helper function is to check whether the class file "/sys/class/net/*" is existing or not.
In the next patch, this helper function will be used.

Reported-by [email protected]
Fixes b76cdba9cdb2 ("[PATCH] bonding: add sysfs functionality to bonding (large)")

---

v1 -> v2:
- use class_has_file_ns(), which is introduced by the first patch.

 include/linux/netdevice.h | 2 +-
 net/core/net-sysfs.c      | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/netdevice.h +1 -1
index 130a668049ab..a04c487c0975 100644
@@ -4555,7 +4555,7 @@ int netdev_class_create_file_ns(const struct class_attribute *class_attr,
                              const void *ns);
 void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
                               const void *ns);
-
+bool netdev_class_has_file_ns(const char *name, const void *ns);
 static inline int netdev_class_create_file(const struct class_attribute *class_attr)
 {
      return netdev_class_create_file_ns(class_attr, NULL);
net/core/net-sysfs.c +0 -0
index cf0215734ceb..8a20d658eff0 100644
@@ -1914,6 +1914,12 @@ void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
 }
 EXPORT_SYMBOL(netdev_class_remove_file_ns);
 
Quoted 8 lines

net/core/net-sysfs.c void netdev_class_remove_file_ns(const struct class_attribute *class_attr, · line 1921

Quoted 5 lines
net/core/net-sysfs.c +5 -0
+bool netdev_class_has_file_ns(const char *name, const void *ns)
+{
+     return class_has_file_ns(&net_class, name, ns);
+}
+EXPORT_SYMBOL(netdev_class_has_file_ns);

Again, this feels broken, it can not solve a race condition.

Quoted 3 lines

This function is considered to be used under rtnl mutex and I assume that no one could use "/sys/class/net/*" outside of rtnl mutex. So, I think it returns the correct information under rtnl mutex.

But you are creating a globally exported function that can be called from anywhere, and as such, is not useful because it has no locking or hints of how to use it correctly at all.

Again, don't push this "solution" down to sysfs to solve, you know if you have a device that is not cleaned up yet, so don't try to rename/create a device of the same name before that is finished.

thanks,

greg k-h

author
#4 lore raw
Quoted 1 line · Greg KH

Hi Greg,
Thank you for the review!

Quoted 54 lines · Taehee Yoo
Quoted 53 lines · Greg KH
Quoted 1 line

Hi Greg,
Thank you for your review!

Quoted 46 lines · Taehee Yoo
Quoted 34 lines

This helper function is to check whether the class file "/sys/class/net/*" is existing or not.
In the next patch, this helper function will be used.

Reported-by [email protected]
Fixes b76cdba9cdb2 ("[PATCH] bonding: add sysfs functionality to bonding (large)")

---

v1 -> v2:
- use class_has_file_ns(), which is introduced by the first patch.

 include/linux/netdevice.h | 2 +-
 net/core/net-sysfs.c      | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/netdevice.h +1 -1
index 130a668049ab..a04c487c0975 100644
@@ -4555,7 +4555,7 @@ int netdev_class_create_file_ns(const struct class_attribute *class_attr,
                              const void *ns);
 void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
                               const void *ns);
-
+bool netdev_class_has_file_ns(const char *name, const void *ns);
 static inline int netdev_class_create_file(const struct class_attribute *class_attr)
 {
      return netdev_class_create_file_ns(class_attr, NULL);
net/core/net-sysfs.c +0 -0
index cf0215734ceb..8a20d658eff0 100644

net/core/net-sysfs.c void netdev_class_remove_file_ns(const struct class_attribute *class_attr, · line 1921

Quoted 8 lines
net/core/net-sysfs.c +5 -0
@@ -1914,6 +1914,12 @@ void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
 }
 EXPORT_SYMBOL(netdev_class_remove_file_ns);
 
+bool netdev_class_has_file_ns(const char *name, const void *ns)
+{
+     return class_has_file_ns(&net_class, name, ns);
+}
+EXPORT_SYMBOL(netdev_class_has_file_ns);

Again, this feels broken, it can not solve a race condition.

Quoted 8 lines
Quoted 3 lines

This function is considered to be used under rtnl mutex and I assume that no one could use "/sys/class/net/*" outside of rtnl mutex. So, I think it returns the correct information under rtnl mutex.

But you are creating a globally exported function that can be called from anywhere, and as such, is not useful because it has no locking or hints of how to use it correctly at all.

Yes, I agree with that.

Quoted 4 lines

Again, don't push this "solution" down to sysfs to solve, you know if you have a device that is not cleaned up yet, so don't try to rename/create a device of the same name before that is finished.

Okay, Thank you for that.
I will find another way to fix it.

Thanks a lot!
Taehee Yoo