let add quota diff =
Hashtbl.iter (fun id nb -> set_entry quota id (get_entry quota id + nb)) diff.cur
+
+let merge orig_quota mod_quota dest_quota =
+ Hashtbl.iter (fun id nb -> let diff = nb - (get_entry orig_quota id) in
+ if diff <> 0 then
+ set_entry dest_quota id ((get_entry dest_quota id) + diff)) mod_quota.cur
with Not_found -> node, false
let set_node rnode path nnode =
- let quota = Quota.create () in
- if !Quota.activate then Node.recurse (fun node -> Quota.add_entry quota (Node.get_owner node)) nnode;
if path = [] then
- nnode, quota
+ nnode
else
let set_node node name =
try
let ent = Node.find node name in
- if !Quota.activate then Node.recurse (fun node -> Quota.del_entry quota (Node.get_owner node)) ent;
Node.replace_child node ent nnode
with Not_found ->
Node.add_child node nnode
in
- apply_modify rnode path set_node, quota
+ apply_modify rnode path set_node
(* read | ls | getperms use this *)
let rec lookup node path fct =
(* modifying functions with quota udpate *)
-let set_node store path node =
- let root, quota_diff = Path.set_node store.root path node in
+let set_node store path node orig_quota mod_quota =
+ let root = Path.set_node store.root path node in
store.root <- root;
- Quota.add store.quota quota_diff
+ Quota.merge orig_quota mod_quota store.quota
let write store perm path value =
let node, existing = get_deepest_existing_node store path in
type t = {
ty: ty;
store: Store.t;
+ quota: Quota.t;
mutable ops: (Xenbus.Xb.Op.operation * Store.Path.t) list;
mutable read_lowpath: Store.Path.t option;
mutable write_lowpath: Store.Path.t option;
{
ty = ty;
store = if id = none then store else Store.copy store;
+ quota = Quota.copy store.Store.quota;
ops = [];
read_lowpath = None;
write_lowpath = None;
(* it has to be in the store, otherwise it means bugs
in the lowpath registration. we don't need to handle none. *)
- maybe (fun n -> Store.set_node cstore p n) n;
+ maybe (fun n -> Store.set_node cstore p n t.quota store.Store.quota) n;
Logging.write_coalesce ~tid:(get_id t) ~con (Store.Path.to_string p);
) t.write_lowpath;
maybe (fun p ->