net/devlink/devl_internal.h
Source file repositories/reference/linux-study-clean/net/devlink/devl_internal.h
File Facts
- System
- Linux kernel
- Corpus path
net/devlink/devl_internal.h- Extension
.h- Size
- 10778 bytes
- Lines
- 334
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/etherdevice.hlinux/mutex.hlinux/netdevice.hlinux/notifier.hlinux/types.hlinux/workqueue.hlinux/xarray.hnet/devlink.hnet/net_namespace.hnet/rtnetlink.hrdma/ib_verbs.hnetlink_gen.h
Detected Declarations
struct devlink_relstruct devlink_dev_statsstruct devlinkstruct devlink_nl_dump_statestruct devlink_obj_descstruct devlink_resourceenum devlink_multicast_groupsfunction __devl_is_registeredfunction devl_is_registeredfunction devl_dev_lockfunction devl_dev_unlockfunction devlink_dump_statefunction devlink_nl_put_handlefunction devlink_nl_put_u64function devlink_nl_notify_needfunction devlink_nl_obj_desc_initfunction devlink_nl_obj_desc_port_setfunction devlink_nl_notify_send_descfunction devlink_nl_notify_sendfunction devlink_reload_supported
Annotated Snippet
const struct device_driver *dev_driver;
possible_net_t _net;
/* Serializes access to devlink instance specific objects such as
* port, sb, dpipe, resource, params, region, traps and more.
*/
struct mutex lock;
struct lock_class_key lock_key;
u8 reload_failed:1;
refcount_t refcount;
struct rcu_work rwork;
struct devlink_rel *rel;
struct xarray nested_rels;
char priv[] __aligned(NETDEV_ALIGN);
};
extern struct xarray devlinks;
extern struct genl_family devlink_nl_family;
struct devlink *__devlink_alloc(const struct devlink_ops *ops, size_t priv_size,
struct net *net, struct device *dev,
const struct device_driver *dev_driver);
#define devl_warn(devlink, format, args...) \
do { \
if ((devlink)->dev) \
dev_warn((devlink)->dev, format, ##args); \
else \
pr_warn("devlink (%s): " format, \
devlink_dev_name(devlink), ##args); \
} while (0)
/* devlink instances are open to the access from the user space after
* devlink_register() call. Such logical barrier allows us to have certain
* expectations related to locking.
*
* Before *_register() - we are in initialization stage and no parallel
* access possible to the devlink instance. All drivers perform that phase
* by implicitly holding device_lock.
*
* After *_register() - users and driver can access devlink instance at
* the same time.
*/
#define ASSERT_DEVLINK_REGISTERED(d) \
WARN_ON_ONCE(!xa_get_mark(&devlinks, (d)->index, DEVLINK_REGISTERED))
#define ASSERT_DEVLINK_NOT_REGISTERED(d) \
WARN_ON_ONCE(xa_get_mark(&devlinks, (d)->index, DEVLINK_REGISTERED))
/* Iterate over devlink pointers which were possible to get reference to.
* devlink_put() needs to be called for each iterated devlink pointer
* in loop body in order to release the reference.
*/
#define devlinks_xa_for_each_registered_get(net, index, devlink) \
for (index = 0; (devlink = devlinks_xa_find_get(net, &index)); index++)
struct devlink *devlinks_xa_find_get(struct net *net, unsigned long *indexp);
struct devlink *devlinks_xa_lookup_get(struct net *net, unsigned long index);
static inline bool __devl_is_registered(struct devlink *devlink)
{
return xa_get_mark(&devlinks, devlink->index, DEVLINK_REGISTERED);
}
static inline bool devl_is_registered(struct devlink *devlink)
{
devl_assert_locked(devlink);
return __devl_is_registered(devlink);
}
static inline void devl_dev_lock(struct devlink *devlink, bool dev_lock)
{
if (dev_lock && devlink->dev)
device_lock(devlink->dev);
devl_lock(devlink);
}
static inline void devl_dev_unlock(struct devlink *devlink, bool dev_lock)
{
devl_unlock(devlink);
if (dev_lock && devlink->dev)
device_unlock(devlink->dev);
}
typedef void devlink_rel_notify_cb_t(struct devlink *devlink, u32 obj_index);
typedef void devlink_rel_cleanup_cb_t(struct devlink *devlink, u32 obj_index,
u32 rel_index);
void devlink_rel_nested_in_clear(u32 rel_index);
int devlink_rel_nested_in_add(u32 *rel_index, u32 devlink_index,
u32 obj_index, devlink_rel_notify_cb_t *notify_cb,
devlink_rel_cleanup_cb_t *cleanup_cb,
Annotation
- Immediate include surface: `linux/device.h`, `linux/etherdevice.h`, `linux/mutex.h`, `linux/netdevice.h`, `linux/notifier.h`, `linux/types.h`, `linux/workqueue.h`, `linux/xarray.h`.
- Detected declarations: `struct devlink_rel`, `struct devlink_dev_stats`, `struct devlink`, `struct devlink_nl_dump_state`, `struct devlink_obj_desc`, `struct devlink_resource`, `enum devlink_multicast_groups`, `function __devl_is_registered`, `function devl_is_registered`, `function devl_dev_lock`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern implementation candidate.
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.