drivers/net/bonding/bond_sysfs.c
Source file repositories/reference/linux-study-clean/drivers/net/bonding/bond_sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/bonding/bond_sysfs.c- Extension
.c- Size
- 24216 bytes
- Lines
- 865
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/device.hlinux/sched/signal.hlinux/fs.hlinux/types.hlinux/string.hlinux/netdevice.hlinux/inetdevice.hlinux/in.hlinux/sysfs.hlinux/ctype.hlinux/inet.hlinux/rtnetlink.hlinux/etherdevice.hnet/net_namespace.hnet/netns/generic.hlinux/nsproxy.hnet/bonding.h
Detected Declarations
function Copyrightfunction list_for_each_entry_rcufunction list_for_each_entryfunction bonding_store_bondsfunction bonding_sysfs_store_optionfunction bonding_show_slavesfunction bond_for_each_slave_rcufunction bonding_show_modefunction bonding_show_xmit_hashfunction bonding_show_arp_validatefunction bonding_show_arp_all_targetsfunction bonding_show_fail_over_macfunction bonding_show_arp_intervalfunction bonding_show_arp_targetsfunction bonding_show_missed_maxfunction bonding_show_downdelayfunction bonding_show_updelayfunction bonding_show_peer_notif_delayfunction bonding_show_lacp_activefunction bonding_show_lacp_ratefunction bonding_show_min_linksfunction bonding_show_ad_selectfunction bonding_show_num_peer_notiffunction bonding_show_miimonfunction bonding_show_primaryfunction bonding_show_primary_reselectfunction bonding_show_carrierfunction bonding_show_active_slavefunction bonding_show_mii_statusfunction bonding_show_ad_aggregatorfunction bonding_show_ad_num_portsfunction bonding_show_ad_actor_keyfunction bonding_show_ad_partner_keyfunction bonding_show_ad_partner_macfunction bonding_show_queue_idfunction bond_for_each_slave_rcufunction bonding_show_slaves_activefunction bonding_show_resend_igmpfunction bonding_show_lp_intervalfunction bonding_show_tlb_dynamic_lbfunction bonding_show_packets_per_slavefunction bonding_show_ad_actor_sys_priofunction bonding_show_ad_actor_systemfunction bonding_show_ad_user_port_keyfunction bond_create_sysfsfunction bond_destroy_sysfsfunction bond_prepare_sysfs_group
Annotated Snippet
if (res > (PAGE_SIZE - IFNAMSIZ)) {
/* not enough space for another interface name */
if ((PAGE_SIZE - res) > 10)
res = PAGE_SIZE - 10;
res += sysfs_emit_at(buf, res, "++more++ ");
break;
}
res += sysfs_emit_at(buf, res, "%s ", bond->dev->name);
}
if (res)
buf[res-1] = '\n'; /* eat the leftover space */
rcu_read_unlock();
return res;
}
static struct net_device *bond_get_by_name(const struct bond_net *bn, const char *ifname)
{
struct bonding *bond;
list_for_each_entry(bond, &bn->dev_list, bond_list) {
if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
return bond->dev;
}
return NULL;
}
/* "store" function for the bond_masters attribute. This is what
* creates and deletes entire bonds.
*
* The class parameter is ignored.
*/
static ssize_t bonding_store_bonds(const struct class *cls,
const struct class_attribute *attr,
const char *buffer, size_t count)
{
const struct bond_net *bn =
container_of_const(attr, struct bond_net, class_attr_bonding_masters);
char command[IFNAMSIZ + 1] = {0, };
char *ifname;
int rv, res = count;
sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
ifname = command + 1;
if ((strlen(command) <= 1) ||
!dev_valid_name(ifname))
goto err_no_cmd;
if (command[0] == '+') {
pr_info("%s is being created...\n", ifname);
rv = bond_create(bn->net, ifname);
if (rv) {
if (rv == -EEXIST)
pr_info("%s already exists\n", ifname);
else
pr_info("%s creation failed\n", ifname);
res = rv;
}
} else if (command[0] == '-') {
struct net_device *bond_dev;
rtnl_lock();
bond_dev = bond_get_by_name(bn, ifname);
if (bond_dev) {
pr_info("%s is being deleted...\n", ifname);
unregister_netdevice(bond_dev);
} else {
pr_err("unable to delete non-existent %s\n", ifname);
res = -ENODEV;
}
rtnl_unlock();
} else
goto err_no_cmd;
/* Always return either count or an error. If you return 0, you'll
* get called forever, which is bad.
*/
return res;
err_no_cmd:
pr_err("no command found in bonding_masters - use +ifname or -ifname\n");
return -EPERM;
}
/* class attribute for bond_masters file. This ends up in /sys/class/net */
static const struct class_attribute class_attr_bonding_masters = {
.attr = {
.name = "bonding_masters",
.mode = 0644,
},
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/device.h`, `linux/sched/signal.h`, `linux/fs.h`, `linux/types.h`, `linux/string.h`, `linux/netdevice.h`.
- Detected declarations: `function Copyright`, `function list_for_each_entry_rcu`, `function list_for_each_entry`, `function bonding_store_bonds`, `function bonding_sysfs_store_option`, `function bonding_show_slaves`, `function bond_for_each_slave_rcu`, `function bonding_show_mode`, `function bonding_show_xmit_hash`, `function bonding_show_arp_validate`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.