net/devlink/resource.c
Source file repositories/reference/linux-study-clean/net/devlink/resource.c
File Facts
- System
- Linux kernel
- Corpus path
net/devlink/resource.c- Extension
.c- Size
- 19294 bytes
- Lines
- 731
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
devl_internal.h
Detected Declarations
struct devlink_resourcefunction __devlink_resource_findfunction list_for_each_entryfunction devlink_resource_findfunction devlink_resource_validate_childrenfunction devlink_resource_validate_sizefunction devlink_nl_resource_set_doitfunction devlink_resource_size_params_putfunction devlink_resource_occ_putfunction devlink_resource_putfunction list_for_each_entryfunction devlink_resource_list_fillfunction list_for_each_entryfunction devlink_resource_fillfunction devlink_nl_resource_dump_doitfunction devlink_resource_dump_fill_onefunction devlink_nl_resource_dump_onefunction devlink_nl_resource_dump_dumpitfunction devlink_resources_validatefunction list_for_each_entryfunction __devl_resource_registerfunction devl_resource_registerfunction devlink_resource_unregisterfunction list_for_each_entry_safefunction __devl_resources_unregisterfunction list_for_each_entry_safefunction devl_resources_unregisterfunction devlink_resources_unregisterfunction devl_resource_size_getfunction devl_resource_occ_get_registerfunction devl_resource_occ_get_unregisterfunction devl_port_resource_registerfunction devl_port_resources_unregisterexport devl_resource_registerexport devl_resources_unregisterexport devlink_resources_unregisterexport devl_resource_size_getexport devl_resource_occ_get_registerexport devl_resource_occ_get_unregisterexport devl_port_resource_registerexport devl_port_resources_unregister
Annotated Snippet
struct devlink_resource {
const char *name;
u64 id;
u64 size;
u64 size_new;
bool size_valid;
struct devlink_resource *parent;
struct devlink_resource_size_params size_params;
struct list_head list;
struct list_head resource_list;
devlink_resource_occ_get_t *occ_get;
void *occ_get_priv;
};
static struct devlink_resource *
__devlink_resource_find(struct list_head *resource_list_head,
struct devlink_resource *resource,
u64 resource_id)
{
struct list_head *resource_list;
if (resource)
resource_list = &resource->resource_list;
else
resource_list = resource_list_head;
list_for_each_entry(resource, resource_list, list) {
struct devlink_resource *child_resource;
if (resource->id == resource_id)
return resource;
child_resource = __devlink_resource_find(resource_list_head,
resource,
resource_id);
if (child_resource)
return child_resource;
}
return NULL;
}
static struct devlink_resource *
devlink_resource_find(struct devlink *devlink,
struct devlink_resource *resource, u64 resource_id)
{
return __devlink_resource_find(&devlink->resource_list,
resource, resource_id);
}
static void
devlink_resource_validate_children(struct devlink_resource *resource)
{
struct devlink_resource *child_resource;
bool size_valid = true;
u64 parts_size = 0;
if (list_empty(&resource->resource_list))
goto out;
list_for_each_entry(child_resource, &resource->resource_list, list)
parts_size += child_resource->size_new;
if (parts_size > resource->size_new)
size_valid = false;
out:
resource->size_valid = size_valid;
}
static int
devlink_resource_validate_size(struct devlink_resource *resource, u64 size,
struct netlink_ext_ack *extack)
{
u64 reminder;
int err = 0;
if (size > resource->size_params.size_max) {
NL_SET_ERR_MSG(extack, "Size larger than maximum");
err = -EINVAL;
}
if (size < resource->size_params.size_min) {
NL_SET_ERR_MSG(extack, "Size smaller than minimum");
err = -EINVAL;
}
div64_u64_rem(size, resource->size_params.size_granularity, &reminder);
if (reminder) {
NL_SET_ERR_MSG(extack, "Wrong granularity");
err = -EINVAL;
}
Annotation
- Immediate include surface: `devl_internal.h`.
- Detected declarations: `struct devlink_resource`, `function __devlink_resource_find`, `function list_for_each_entry`, `function devlink_resource_find`, `function devlink_resource_validate_children`, `function devlink_resource_validate_size`, `function devlink_nl_resource_set_doit`, `function devlink_resource_size_params_put`, `function devlink_resource_occ_put`, `function devlink_resource_put`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.