Source file quota_interface.ml
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
122
123
124
125
126
127
128
129
130
131
132
133
include Namespace.Unsupported
let ( |> ) a b = b a
let read t (perms : Perms.t) (path : Store.Path.t) =
Perms.has perms Perms.CONFIGURE;
match Store.Path.to_string_list path with
| [] -> ""
| "default" :: [] -> ""
| "entries-per-domain" :: [] -> ""
| "number-of-entries" :: [] -> ""
| "number-of-registered-watches" :: [] -> ""
| "number-of-active-transactions" :: [] -> ""
| "number-of-queued-watch-events" :: [] -> ""
| [ "default"; "number-of-entries" ] -> string_of_int !Quota.maxent
| [ "default"; "entry-length" ] -> string_of_int !Quota.maxsize
| [ "default"; "number-of-registered-watches" ] ->
string_of_int !Quota.maxwatch
| [ "default"; "number-of-active-transactions" ] ->
string_of_int !Quota.maxtransaction
| [ "default"; "number-of-queued-watch-events" ] ->
string_of_int !Quota.maxwatchevent
| [ "entries-per-domain"; domid ] ->
let q = t.Transaction.store.Store.quota in
let domid = int_of_string domid in
let n = Quota.get q domid in
string_of_int n
| [ "number-of-entries"; domid ] -> (
match Quota.get_override Quota.maxent_overrides (int_of_string domid) with
| Some x -> string_of_int x
| None -> Store.Path.doesnt_exist path)
| [ "number-of-registered-watches"; domid ] -> (
match
Quota.get_override Quota.maxwatch_overrides (int_of_string domid)
with
| Some x -> string_of_int x
| None -> Store.Path.doesnt_exist path)
| [ "number-of-active-transactions"; domid ] -> (
match
Quota.get_override Quota.maxtransaction_overrides (int_of_string domid)
with
| Some x -> string_of_int x
| None -> Store.Path.doesnt_exist path)
| [ "number-of-queued-watch-events"; domid ] -> (
match
Quota.get_override Quota.maxwatchevent_overrides (int_of_string domid)
with
| Some x -> string_of_int x
| None -> Store.Path.doesnt_exist path)
| _ -> Store.Path.doesnt_exist path
let exists t perms path =
try
ignore (read t perms path);
true
with Store.Path.Doesnt_exist _ -> false
let write _t _creator perms path value =
Perms.has perms Perms.CONFIGURE;
match Store.Path.to_string_list path with
| [ "default"; "number-of-entries" ] -> Quota.maxent := int_of_string value
| [ "default"; "entry-length" ] -> Quota.maxsize := int_of_string value
| [ "default"; "number-of-registered-watches" ] ->
Quota.maxwatch := int_of_string value
| [ "default"; "number-of-active-transactions" ] ->
Quota.maxtransaction := int_of_string value
| [ "default"; "number-of-queued-watch-events" ] ->
Quota.maxwatchevent := int_of_string value
| [ "number-of-entries"; domid ] ->
Quota.set_override Quota.maxent_overrides (int_of_string domid)
(Some (int_of_string value))
| [ "number-of-registered-watches"; domid ] ->
Quota.set_override Quota.maxwatch_overrides (int_of_string domid)
(Some (int_of_string value))
| [ "number-of-active-transactions"; domid ] ->
Quota.set_override Quota.maxtransaction_overrides (int_of_string domid)
(Some (int_of_string value))
| [ "number-of-queued-watch-events"; domid ] ->
Quota.set_override Quota.maxwatchevent_overrides (int_of_string domid)
(Some (int_of_string value))
| _ -> Store.Path.doesnt_exist path
let list t perms path =
Perms.has perms Perms.CONFIGURE;
match Store.Path.to_string_list path with
| [] ->
[
"default"
; "entries-per-domain"
; "number-of-entries"
; "number-of-registered-watches"
; "number-of-active-transactions"
; "number-of-queued-watch-events"
]
| [ "default" ] ->
[
"number-of-entries"
; "entry-length"
; "number-of-registered-watches"
; "number-of-active-transactions"
; "number-of-queued-watch-events"
]
| [ "entries-per-domain" ] ->
let q = t.Transaction.store.Store.quota in
Quota.list q |> List.map fst |> List.map string_of_int
| [ "number-of-entries" ] ->
Quota.list_overrides Quota.maxent_overrides
|> List.map fst |> List.map string_of_int
| [ "number-of-registered-watches" ] ->
Quota.list_overrides Quota.maxwatch_overrides
|> List.map fst |> List.map string_of_int
| [ "number-of-active-transactions" ] ->
Quota.list_overrides Quota.maxtransaction_overrides
|> List.map fst |> List.map string_of_int
| [ "number-of-queued-watch-events" ] ->
Quota.list_overrides Quota.maxwatchevent_overrides
|> List.map fst |> List.map string_of_int
| _ -> []
let rm _t perms path =
Perms.has perms Perms.CONFIGURE;
match Store.Path.to_string_list path with
| [ "number-of-entries"; domid ] ->
Quota.set_override Quota.maxent_overrides (int_of_string domid) None
| [ "number-of-registered-watches"; domid ] ->
Quota.set_override Quota.maxwatch_overrides (int_of_string domid) None
| [ "number-of-active-transactions"; domid ] ->
Quota.set_override Quota.maxtransaction_overrides (int_of_string domid)
None
| [ "number-of-queued-watch-events"; domid ] ->
Quota.set_override Quota.maxwatchevent_overrides (int_of_string domid)
None
| _ -> raise Perms.Permission_denied