On 2026-03-05 08:51, Juergen Gross wrote:
Add central functions for checking a value (either an absolute one or
the current domain value plus an offset) against a specific quota.

This is in preparation of introducing per-domain quota.

The required changes allow to drop the "update" parameter from
domain_nbentry_fix().

Signed-off-by: Juergen Gross <[email protected]>

diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
index e453b3061f..1df9265ad5 100644
--- a/tools/xenstored/domain.c
+++ b/tools/xenstored/domain.c
@@ -389,6 +389,25 @@ void wrl_apply_debit_trans_commit(struct connection *conn)
        wrl_apply_debit_actual(conn->domain);
  }
+static bool domain_check_quota_val(struct domain *d, enum accitem what,
+                                  unsigned int val)
+{
+       unsigned int quota = hard_quotas[what].val;
+
+       if (!quota || !domid_is_unprivileged(d->domid))
+               return false;
+
+       return val >= quota;

Personally, I don't like the naming of *check* where the "good" return is false. That seems backwards from what I expect. So I'd suggest either flipping the return value or renaming. domain_quota_fail() or something?

+}
+
+bool domain_check_quota_add(struct domain *d, enum accitem what, int add)
+{
+       if (add < 0 || !d)
+               return false;
+
+       return domain_check_quota_val(d, what, d->acc[what].val + add);
+}
+
  static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod)
  {
        return ((prod - cons) <= XENSTORE_RING_SIZE);

As an example, here "good" is true.

I see Anthony already gave an R-b, so just consider it as a suggestion.

Thanks,
Jason

Reply via email to