struct device_config {
struct rcu_head rcu;
+ char peer_name[IFNAMSIZ];
unsigned char eth_addr[ETH_ALEN];
unsigned int mtu;
};
char name[IFNAMSIZ];
/* Protected by RTNL lock. */
- char peer_name[IFNAMSIZ];
struct hlist_node hash_node;
struct vport __rcu *peer;
kfree(peer_table);
}
-static int set_config(struct vport *vport, const void *config)
+static int set_config(struct vport *vport, const void *config,
+ struct device_config *devconf)
{
struct patch_vport *patch_vport = patch_vport_priv(vport);
char peer_name[IFNAMSIZ];
if (!strcmp(patch_vport->name, peer_name))
return -EINVAL;
- strcpy(patch_vport->peer_name, peer_name);
+ strcpy(devconf->peer_name, peer_name);
return 0;
}
{
struct vport *vport;
struct patch_vport *patch_vport;
+ const char *peer_name;
int err;
vport = vport_alloc(sizeof(struct patch_vport), &patch_vport_ops, parms);
strcpy(patch_vport->name, parms->name);
- err = set_config(vport, parms->config);
- if (err)
- goto error_free_vport;
-
patch_vport->devconf = kmalloc(sizeof(struct device_config), GFP_KERNEL);
if (!patch_vport->devconf) {
err = -ENOMEM;
goto error_free_vport;
}
+ err = set_config(vport, parms->config, patch_vport->devconf);
+ if (err)
+ goto error_free_devconf;
+
vport_gen_rand_ether_addr(patch_vport->devconf->eth_addr);
/* Make the default MTU fairly large so that it doesn't become the
* bottleneck on systems using jumbo frames. */
patch_vport->devconf->mtu = 65535;
- hlist_add_head(&patch_vport->hash_node, hash_bucket(patch_vport->peer_name));
+ peer_name = patch_vport->devconf->peer_name;
+ hlist_add_head(&patch_vport->hash_node, hash_bucket(peer_name));
- rcu_assign_pointer(patch_vport->peer, vport_locate(patch_vport->peer_name));
+ rcu_assign_pointer(patch_vport->peer, vport_locate(peer_name));
update_peers(patch_vport->name, vport);
return vport;
+error_free_devconf:
+ kfree(patch_vport->devconf);
error_free_vport:
vport_free(vport);
error:
static int patch_modify(struct vport *vport, struct odp_port *port)
{
- int err = set_config(vport, port->config);
- if (!err) {
- struct patch_vport *patch_vport = patch_vport_priv(vport);
+ struct patch_vport *patch_vport = patch_vport_priv(vport);
+ struct device_config *devconf;
+ int err;
- hlist_del(&patch_vport->hash_node);
- rcu_assign_pointer(patch_vport->peer, vport_locate(patch_vport->peer_name));
- hlist_add_head(&patch_vport->hash_node, hash_bucket(patch_vport->peer_name));
+ devconf = kmemdup(patch_vport->devconf, sizeof(struct device_config), GFP_KERNEL);
+ if (!devconf) {
+ err = -ENOMEM;
+ goto error;
}
+
+ err = set_config(vport, port->config, devconf);
+ if (err)
+ goto error_free;
+
+ assign_config_rcu(vport, devconf);
+
+ hlist_del(&patch_vport->hash_node);
+
+ rcu_assign_pointer(patch_vport->peer, vport_locate(devconf->peer_name));
+ hlist_add_head(&patch_vport->hash_node, hash_bucket(devconf->peer_name));
+
+ return 0;
+
+error_free:
+ kfree(devconf);
+error:
return err;
}
struct patch_vport *peer_vport;
struct hlist_node *node;
- hlist_for_each_entry(peer_vport, node, bucket, hash_node)
- if (!strcmp(peer_vport->peer_name, name))
+ hlist_for_each_entry(peer_vport, node, bucket, hash_node) {
+ const char *peer_name;
+
+ peer_name = rtnl_dereference(peer_vport->devconf)->peer_name;
+ if (!strcmp(peer_name, name))
rcu_assign_pointer(peer_vport->peer, vport);
+ }
}
static int patch_set_mtu(struct vport *vport, int mtu)
return rcu_dereference_rtnl(patch_vport->devconf)->eth_addr;
}
+static void patch_get_config(const struct vport *vport, void *config)
+{
+ const struct patch_vport *patch_vport = patch_vport_priv(vport);
+ const char *peer_name;
+
+ peer_name = rcu_dereference_rtnl(patch_vport->devconf)->peer_name;
+ strlcpy(config, peer_name, VPORT_CONFIG_SIZE);
+}
+
static int patch_get_mtu(const struct vport *vport)
{
const struct patch_vport *patch_vport = patch_vport_priv(vport);
.set_addr = patch_set_addr,
.get_name = patch_get_name,
.get_addr = patch_get_addr,
+ .get_config = patch_get_config,
.get_dev_flags = vport_gen_get_dev_flags,
.is_running = vport_gen_is_running,
.get_operstate = vport_gen_get_operstate,
int vport_get_iflink(const struct vport *);
int vport_get_mtu(const struct vport *);
+void vport_get_config(const struct vport *, void *);
int vport_send(struct vport *, struct sk_buff *);
* May be null if not supported.
* @get_name: Get the device's name.
* @get_addr: Get the device's MAC address.
+ * @get_config: Get the device's configuration.
* @get_kobj: Get the kobj associated with the device (may return null).
* @get_stats: Fill in the transmit/receive stats. May be null if stats are
* not supported or if generic stats are in use. If defined and
/* Called with rcu_read_lock or RTNL lock. */
const char *(*get_name)(const struct vport *);
const unsigned char *(*get_addr)(const struct vport *);
+ void (*get_config)(const struct vport *, void *);
struct kobject *(*get_kobj)(const struct vport *);
int (*get_stats)(const struct vport *, struct rtnl_link_stats64 *);