X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=datapath%2Fdp_sysfs_if.c;h=219a260683902c16265e255b8b5eab41380a8cd2;hb=a8643e447601201aabd1159966bd716e48378f97;hp=c37e11fd19dbe89159b8ecfe452c6b8753afbadf;hpb=df2c07f4338faac04f4969f243fe4e8083b309ac;p=sliver-openvswitch.git diff --git a/datapath/dp_sysfs_if.c b/datapath/dp_sysfs_if.c index c37e11fd1..219a26068 100644 --- a/datapath/dp_sysfs_if.c +++ b/datapath/dp_sysfs_if.c @@ -1,17 +1,23 @@ /* - * Copyright (c) 2009, 2010 Nicira Networks. - * Distributed under the terms of the GNU GPL version 2. + * Copyright (c) 2007-2012 Nicira, Inc. * - * Significant portions of this file may be copied from parts of the Linux - * kernel, by Linus Torvalds and others. - */ - -/* - * Sysfs attributes of bridge ports for Open vSwitch + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. * - * This has been shamelessly copied from the kernel sources. + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -31,7 +37,7 @@ struct brport_attribute { }; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) -#define BRPORT_ATTR(_name,_mode,_show,_store) \ +#define BRPORT_ATTR(_name, _mode, _show, _store) \ struct brport_attribute brport_attr_##_name = { \ .attr = {.name = __stringify(_name), \ .mode = _mode }, \ @@ -39,10 +45,10 @@ struct brport_attribute brport_attr_##_name = { \ .store = _store, \ }; #else -#define BRPORT_ATTR(_name,_mode,_show,_store) \ -struct brport_attribute brport_attr_##_name = { \ - .attr = {.name = __stringify(_name), \ - .mode = _mode, \ +#define BRPORT_ATTR(_name, _mode, _show, _store) \ +struct brport_attribute brport_attr_##_name = { \ + .attr = {.name = __stringify(_name), \ + .mode = _mode, \ .owner = THIS_MODULE, }, \ .show = _show, \ .store = _store, \ @@ -126,22 +132,19 @@ static ssize_t show_port_state(struct vport *p, char *buf) } static BRPORT_ATTR(state, S_IRUGO, show_port_state, NULL); -static ssize_t show_message_age_timer(struct vport *p, - char *buf) +static ssize_t show_message_age_timer(struct vport *p, char *buf) { return sprintf(buf, "%d\n", 0); } static BRPORT_ATTR(message_age_timer, S_IRUGO, show_message_age_timer, NULL); -static ssize_t show_forward_delay_timer(struct vport *p, - char *buf) +static ssize_t show_forward_delay_timer(struct vport *p, char *buf) { return sprintf(buf, "%d\n", 0); } static BRPORT_ATTR(forward_delay_timer, S_IRUGO, show_forward_delay_timer, NULL); -static ssize_t show_hold_timer(struct vport *p, - char *buf) +static ssize_t show_hold_timer(struct vport *p, char *buf) { return sprintf(buf, "%d\n", 0); } @@ -168,32 +171,32 @@ static struct brport_attribute *brport_attrs[] = { #define to_vport_attr(_at) container_of(_at, struct brport_attribute, attr) #define to_vport(obj) container_of(obj, struct vport, kobj) -static ssize_t brport_show(struct kobject * kobj, - struct attribute * attr, char * buf) +static ssize_t brport_show(struct kobject *kobj, + struct attribute *attr, char *buf) { - struct brport_attribute * brport_attr = to_vport_attr(attr); - struct vport * p = to_vport(kobj); + struct brport_attribute *brport_attr = to_vport_attr(attr); + struct vport *p = to_vport(kobj); return brport_attr->show(p, buf); } -static ssize_t brport_store(struct kobject * kobj, - struct attribute * attr, - const char * buf, size_t count) +static ssize_t brport_store(struct kobject *kobj, + struct attribute *attr, + const char *buf, size_t count) { - struct vport * p = to_vport(kobj); + struct vport *p = to_vport(kobj); ssize_t ret = -EINVAL; if (!capable(CAP_NET_ADMIN)) return -EPERM; - printk("%s: xxx writing port parms not supported yet!\n", - dp_name(p->dp)); + pr_warning("%s: xxx writing port parms not supported yet!\n", + ovs_dp_name(p->dp)); return ret; } -struct sysfs_ops brport_sysfs_ops = { +struct sysfs_ops ovs_brport_sysfs_ops = { .show = brport_show, .store = brport_store, }; @@ -203,25 +206,33 @@ struct sysfs_ops brport_sysfs_ops = { * Creates a brport subdirectory with bridge attributes. * Puts symlink in bridge's brport subdirectory */ -int dp_sysfs_add_if(struct vport *p) +int ovs_dp_sysfs_add_if(struct vport *p) { - struct kobject *kobj = vport_get_kobj(p); struct datapath *dp = p->dp; + struct vport *local_port = ovs_vport_rtnl(dp, OVSP_LOCAL); struct brport_attribute **a; int err; /* Create /sys/class/net//brport directory. */ - if (!kobj) + if (!p->ops->get_kobj) return -ENOENT; - err = kobject_add(&p->kobj, kobj, SYSFS_BRIDGE_PORT_ATTR); +#ifdef CONFIG_NET_NS + /* Due to bug in 2.6.32 kernel, sysfs_create_group() could panic + * in other namespace than init_net. Following check is to avoid it. */ + + if (!p->kobj.sd) + return -ENOENT; +#endif + + err = kobject_add(&p->kobj, p->ops->get_kobj(p), + SYSFS_BRIDGE_PORT_ATTR); if (err) goto err; /* Create symlink from /sys/class/net//brport/bridge to * /sys/class/net/. */ - err = sysfs_create_link(&p->kobj, - vport_get_kobj(rtnl_dereference(dp->ports[OVSP_LOCAL])), + err = sysfs_create_link(&p->kobj, local_port->ops->get_kobj(local_port), SYSFS_BRIDGE_PORT_LINK); /* "bridge" */ if (err) goto err_del; @@ -235,10 +246,10 @@ int dp_sysfs_add_if(struct vport *p) /* Create symlink from /sys/class/net//brif/ to * /sys/class/net//brport. */ - err = sysfs_create_link(&dp->ifobj, &p->kobj, vport_get_name(p)); + err = sysfs_create_link(&dp->ifobj, &p->kobj, p->ops->get_name(p)); if (err) goto err_del; - strcpy(p->linkname, vport_get_name(p)); + strcpy(p->linkname, p->ops->get_name(p)); kobject_uevent(&p->kobj, KOBJ_ADD); @@ -251,7 +262,7 @@ err: return err; } -int dp_sysfs_del_if(struct vport *p) +int ovs_dp_sysfs_del_if(struct vport *p) { if (p->linkname[0]) { sysfs_remove_link(&p->dp->ifobj, p->linkname);