|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v8 8/8] libxc: add xc_domain_get_memory_claims()
Add xc_domain_get_memory_claims() with *nr_claims as the
array capacity on input and the entry count on output.
- Use an output-only bounce buffer, copying back only the
returned entries on success and nothing on failure.
- This leaves unused array capacity untouched and preserves
the caller's claims array on failure.
- If capacity is insufficient, fail with errno set to ENOBUFS
and update *nr_claims to the required count without modifying
the claims array.
- Pass NULL for claims and set *nr_claims to zero to query the
count.
- Add the query interfaces to the memory-claims changelog entry.
Assisted-by: Vibe:Mistral-Medium-3.5, Copilot:claude-opus-5-5 # review
Assisted-by: Copilot:gpt-6.2-astra, Copilot:gpt-6.2-sol # review
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@xxxxxxxxxx>
---
v8:
- Refactor the submission into smaller topic-focused patches.
- Split and rename the wrapper to xc_domain_get_memory_claims().
- Use the new domctl operation XEN_DOMCTL_get_memory_claims.
- For consistency across the wrappers and claim path, rename
the function arguments and pass the array before its count.
- Drop the mode argument. This dedicated get wrapper uses
XC_HYPERCALL_BUFFER_BOUNCE_OUT because the array is output-only.
- Copy back only the entries returned by Xen.
- Add XEN_DOMCTL_get_memory_claims/xc_domain_get_memory_claims()
to CHANGELOG.md.
---
tools/include/xenctrl.h | 12 ++++++++++++
tools/libs/ctrl/xc_domain.c | 27 +++++++++++++++++++++++++++
CHANGELOG.md | 1 +
3 files changed, 40 insertions(+)
diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index f2ce836c9c..94ba904de8 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2680,6 +2680,18 @@ int xc_domain_set_memory_claims(xc_interface *xch,
uint32_t domid,
const xen_domctl_memory_claim_t *claims,
uint32_t nr_claims);
+/*
+ * Get the memory claims of a domain.
+ * *nr_claims is the array capacity on input and the number of entries
+ * returned on success. If the capacity is too small, fail with errno set
+ * to ENOBUFS, set *nr_claims to the required size in entries, and leave the
+ * array unchanged. Pass NULL for claims and set *nr_claims to zero to
+ * query the count.
+ */
+int xc_domain_get_memory_claims(xc_interface *xch, uint32_t domid,
+ xen_domctl_memory_claim_t *claims,
+ uint32_t *nr_claims);
+
#if defined(__arm__) || defined(__aarch64__)
int xc_dt_overlay(xc_interface *xch, void *overlay_fdt,
uint32_t overlay_fdt_size, uint8_t overlay_op);
diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c
index 35143d00db..5653b3d4ca 100644
--- a/tools/libs/ctrl/xc_domain.c
+++ b/tools/libs/ctrl/xc_domain.c
@@ -2246,6 +2246,33 @@ int xc_domain_set_memory_claims(xc_interface *xch,
uint32_t domid,
return ret;
}
+int xc_domain_get_memory_claims(xc_interface *xch, uint32_t domid,
+ xen_domctl_memory_claim_t *claims,
+ uint32_t *nr_claims)
+{
+ struct xen_domctl domctl = {};
+ DECLARE_HYPERCALL_BOUNCE(claims, sizeof(*claims) * *nr_claims,
+ XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+ int ret;
+
+ if ( xc_hypercall_bounce_pre(xch, claims) )
+ return -1;
+
+ domctl.cmd = XEN_DOMCTL_get_memory_claims;
+ domctl.domain = domid;
+ domctl.u.memory_claims.nr_claims = *nr_claims;
+ set_xen_guest_handle(domctl.u.memory_claims.claims, claims);
+
+ ret = do_domctl(xch, &domctl);
+ *nr_claims = domctl.u.memory_claims.nr_claims;
+
+ /* Claims are returned only on success; copy back just those. */
+ HYPERCALL_BOUNCE_SET_SIZE(claims, ret ? 0 : sizeof(*claims) * *nr_claims);
+ xc_hypercall_bounce_post(xch, claims);
+
+ return ret;
+}
+
/*
* Local variables:
* mode: C
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 64c0f87062..60543964d3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/)
on selected NUMA nodes while building a domain:
- XEN_DOMCTL_set_memory_claims/xc_domain_set_memory_claims() atomically
sets a domain's host-wide claim and per-node claims.
+ - XEN_DOMCTL_get_memory_claims/xc_domain_get_memory_claims() reads them.
### Removed
- On Arm:
--
2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |