summaryrefslogtreecommitdiff
blob: 7616b90947878542d4cb8eef5b869668054249f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
From f38a815a54000ca51ff5165b2863d60b6bbea49c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= <edwin.torok@cloud.com>
Date: Wed, 31 Jan 2024 10:52:56 +0000
Subject: [PATCH 59/67] tools/oxenstored: Make Quota.t pure
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Now that we no longer have a hashtable inside we can make Quota.t pure, and
push the mutable update to its callers.  Store.t already had a mutable Quota.t
field.

No functional change.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Acked-by: Christian Lindig <christian.lindig@cloud.com>
(cherry picked from commit 098d868e52ac0165b7f36e22b767ea70cef70054)
---
 tools/ocaml/xenstored/quota.ml |  8 ++++----
 tools/ocaml/xenstored/store.ml | 17 ++++++++++-------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/tools/ocaml/xenstored/quota.ml b/tools/ocaml/xenstored/quota.ml
index ee8dd22581..b3ab678c72 100644
--- a/tools/ocaml/xenstored/quota.ml
+++ b/tools/ocaml/xenstored/quota.ml
@@ -33,7 +33,7 @@ module DomidMap = Map.Make(Domid)
 type t = {
 	maxent: int;               (* max entities per domU *)
 	maxsize: int;              (* max size of data store in one node *)
-	mutable cur: int DomidMap.t; (* current domains quota *)
+	cur: int DomidMap.t; (* current domains quota *)
 }
 
 let to_string quota domid =
@@ -76,10 +76,10 @@ let update_entry quota_cur id diff =
 	else DomidMap.add id nb quota_cur
 
 let del_entry quota id =
-	quota.cur <- update_entry quota.cur id (-1)
+	{quota with cur = update_entry quota.cur id (-1)}
 
 let add_entry quota id =
-	quota.cur <- update_entry quota.cur id (+1)
+	{quota with cur = update_entry quota.cur id (+1)}
 
 let merge orig_quota mod_quota dest_quota =
 	let fold_merge id nb dest =
@@ -87,5 +87,5 @@ let merge orig_quota mod_quota dest_quota =
 		| 0 -> dest (* not modified *)
 		| diff -> update_entry dest id diff (* update with [x=x+diff] *)
 	in
-	dest_quota.cur <- DomidMap.fold fold_merge mod_quota.cur dest_quota.cur
+	{dest_quota with cur = DomidMap.fold fold_merge mod_quota.cur dest_quota.cur}
 	(* dest_quota = dest_quota + (mod_quota - orig_quota) *)
diff --git a/tools/ocaml/xenstored/store.ml b/tools/ocaml/xenstored/store.ml
index c94dbf3a62..5dd965db15 100644
--- a/tools/ocaml/xenstored/store.ml
+++ b/tools/ocaml/xenstored/store.ml
@@ -85,7 +85,9 @@ let check_owner node connection =
 		raise Define.Permission_denied;
 	end
 
-let rec recurse fct node = fct node; SymbolMap.iter (fun _ -> recurse fct) node.children
+let rec recurse fct node acc =
+	let acc = fct node acc in
+	SymbolMap.fold (fun _ -> recurse fct) node.children acc
 
 (** [recurse_filter_map f tree] applies [f] on each node in the tree recursively,
     possibly removing some nodes.
@@ -408,7 +410,7 @@ let dump_buffer store = dump_store_buf store.root
 let set_node store path node orig_quota mod_quota =
 	let root = Path.set_node store.root path node in
 	store.root <- root;
-	Quota.merge orig_quota mod_quota store.quota
+	store.quota <- Quota.merge orig_quota mod_quota store.quota
 
 let write store perm path value =
 	let node, existing = get_deepest_existing_node store path in
@@ -422,7 +424,7 @@ let write store perm path value =
 	let root, node_created = path_write store perm path value in
 	store.root <- root;
 	if node_created
-	then Quota.add_entry store.quota owner
+	then store.quota <- Quota.add_entry store.quota owner
 
 let mkdir store perm path =
 	let node, existing = get_deepest_existing_node store path in
@@ -431,7 +433,7 @@ let mkdir store perm path =
 	if not (existing || (Perms.Connection.is_dom0 perm)) then Quota.check store.quota owner 0;
 	store.root <- path_mkdir store perm path;
 	if not existing then
-	Quota.add_entry store.quota owner
+	store.quota <- Quota.add_entry store.quota owner
 
 let rm store perm path =
 	let rmed_node = Path.get_node store.root path in
@@ -439,7 +441,7 @@ let rm store perm path =
 	| None -> raise Define.Doesnt_exist
 	| Some rmed_node ->
 		store.root <- path_rm store perm path;
-		Node.recurse (fun node -> Quota.del_entry store.quota (Node.get_owner node)) rmed_node
+		store.quota <- Node.recurse (fun node quota -> Quota.del_entry quota (Node.get_owner node)) rmed_node store.quota
 
 let setperms store perm path nperms =
 	match Path.get_node store.root path with
@@ -450,8 +452,9 @@ let setperms store perm path nperms =
 		if not ((old_owner = new_owner) || (Perms.Connection.is_dom0 perm)) then
 			raise Define.Permission_denied;
 		store.root <- path_setperms store perm path nperms;
-		Quota.del_entry store.quota old_owner;
-		Quota.add_entry store.quota new_owner
+		store.quota <-
+			let quota = Quota.del_entry store.quota old_owner in
+			Quota.add_entry quota new_owner
 
 let reset_permissions store domid =
 	Logging.info "store|node" "Cleaning up xenstore ACLs for domid %d" domid;
-- 
2.44.0