Re: [patch net-next-2.6 1/2] net: allow to change carrier via sysfs

From
Jiri Pirko <hidden>
Date
2011-08-30 15:19:31
Reply to
Ben Hutchings, 2011-08-30
Tue, Aug 30, 2011 at 05:14:22PM CEST, bhutchings@solarflare.com wrote:
On Tue, 2011-08-30 at 16:46 +0200, Jiri Pirko wrote:
quoted
Allow to write to "carrier" attribute. Devices may implement ndo_change_carrier
callback to allow changing carrier from userspace.
[...]
quoted
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 56e42ab..c8f2ca4 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -126,6 +126,30 @@ static ssize_t show_broadcast(struct device *dev,
 	return -EINVAL;
 }
 
+static ssize_t store_carrier(struct device *dev, struct device_attribute *attr,
+			     const char *buf, size_t len)
+{
+	struct net_device *netdev = to_net_dev(dev);
+	ssize_t ret;
+	int new_value;
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
+	if (!netif_running(netdev))
+		return -EINVAL;
Not sure that's the right error code.
I stayed consistent with show_carrier in this.
quoted
+	if (sscanf(buf, "%d", &new_value) != 1)
+		return -EINVAL;
kstrtoint()
Okay.
(Or maybe we should have kstrobool().)
quoted
+	if (!rtnl_trylock())
+		return restart_syscall();
[...]

This is consistent with other attributes, but it seems like a really bad
practice as it will generally result in the process busy-waiting on the
RTNL lock!  I think it would be better to add and use an
rtnl_lock_interruptible().
Right. But as you said, this is the same as with others. I would replace
this in another patch.
Ben.

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
Thread (22 messages) 22 messages, 6 authors, last reply 2011-09-01
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help