mirror of
https://github.com/drasko/codezero.git
synced 2026-01-16 12:53:16 +01:00
Capability accounting for quantitative capabilities - First part done.
Need to make sure accounting charges correct containers during init. Therefore kernel resource spending must also be accounted for.
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
*/
|
||||
#include <l4/generic/resource.h>
|
||||
#include <l4/generic/capability.h>
|
||||
#include <l4/generic/cap-types.h>
|
||||
#include <l4/api/errno.h>
|
||||
#include <l4/lib/printk.h>
|
||||
|
||||
void capability_init(struct capability *cap)
|
||||
{
|
||||
@@ -12,6 +15,19 @@ void capability_init(struct capability *cap)
|
||||
link_init(&cap->list);
|
||||
}
|
||||
|
||||
/*
|
||||
* Boot-time function to create capability without
|
||||
* capability checking
|
||||
*/
|
||||
struct capability *boot_capability_create(void)
|
||||
{
|
||||
struct capability *cap = boot_alloc_capability();
|
||||
|
||||
capability_init(cap);
|
||||
|
||||
return cap;
|
||||
}
|
||||
|
||||
struct capability *capability_create(void)
|
||||
{
|
||||
struct capability *cap = alloc_capability();
|
||||
@@ -21,3 +37,33 @@ struct capability *capability_create(void)
|
||||
return cap;
|
||||
}
|
||||
|
||||
int capability_consume(struct capability *cap, int quantity)
|
||||
{
|
||||
if (cap->size < cap->used + quantity)
|
||||
return -ENOCAP;
|
||||
else
|
||||
cap->used += quantity;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int capability_free(struct capability *cap, int quantity)
|
||||
{
|
||||
BUG_ON((cap->used -= quantity) < 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find a capability from a list by its resource type
|
||||
*/
|
||||
struct capability *capability_find_by_rtype(struct cap_list *clist,
|
||||
unsigned int rtype)
|
||||
{
|
||||
struct capability *cap;
|
||||
|
||||
list_foreach_struct(cap, &clist->caps, list) {
|
||||
if ((cap->type & CAP_RTYPE_MASK) == rtype)
|
||||
return cap;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user