From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774018925; cv=none; d=zohomail.com; s=zohoarc; b=l75X1TH7gsKNypqC43f15e05d1G+SE3zFz7qBg1WrdWVFH2wX45YPtUNj1Wzz4WMp9yxD/dhuYJnj2QDU2/80wwYIGR4G+OcBi+sgOZnT+idhhyThn5CpX9qgWih3wrQP1pdgemotL8/0B19LattIyGRi+f7qoMnlWDvzyaSG9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774018925; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xVitA9QfI8pYjyiyMqwV+9bQQuTZeeXyuUjW3egkMps=; b=NOmVCrbAX2lqOAlqZS2MQaB8pA2h5/g6oj7MKjTU92KtQZTvAl6ZefOoCoVghrxQqfyE9uGknT0QzqanYWfSOoeCGdem6sVlFfsPlmdlw3WC9/bNWcdUQ6tJMwCESDRJdXzO2nFKwmEtQMVznPh/Cpnh9b4yxcnna9FlL8wJQis= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774018925210698.3310176330262; Fri, 20 Mar 2026 08:02:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258097.1552265 (Exim 4.92) (envelope-from ) id 1w3bM3-00020g-P3; Fri, 20 Mar 2026 15:01:39 +0000 Received: by outflank-mailman (output) from mailman id 1258097.1552265; Fri, 20 Mar 2026 15:01:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bM3-00020Z-MV; Fri, 20 Mar 2026 15:01:39 +0000 Received: by outflank-mailman (input) for mailman id 1258097; Fri, 20 Mar 2026 15:01:38 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bM2-0001ko-AF for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:01:38 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id af1bc027-246d-11f1-9ccf-f158ae23cfc8; Fri, 20 Mar 2026 16:01:33 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8EE745BDF7; Fri, 20 Mar 2026 15:01:27 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6F22F42866; Fri, 20 Mar 2026 15:01:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 9A8BGkdhvWklXAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:01:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: af1bc027-246d-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018892; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xVitA9QfI8pYjyiyMqwV+9bQQuTZeeXyuUjW3egkMps=; b=XMIYwrezHJdLyDJW9qER38yfhWsvXSWgU+GReSZpkCKggxJ9IZQAajLEvXY3cM4MKxSoW4 nB3WiWT4+tDWAzyKTSBdi9Hb2QSMilpKn4MNBfh+1XdrKcCQO7ok/PCiy4p9C2WNUzkA41 +fyC6JGkYpIV2w2drra6jQxVx6HjqQE= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=SYGII5VN DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018887; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xVitA9QfI8pYjyiyMqwV+9bQQuTZeeXyuUjW3egkMps=; b=SYGII5VNzDgDbiK2Vqew2klU16gwU52rMGPw6CFurDToIEB2TK6GRb9r3TYQkHnaAKaQ8F eWETWH/RVOe/qHU59/t/ULFJacm9+dHal6FXW6zar9IiaNTU8uwKz+2xjWjWdLleIx/9E9 qwiyFGfJUwvVL04tmVo0qyiu9XeC+7M= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v2 01/12] tools/libs/store: add get- and set-quota related functions Date: Fri, 20 Mar 2026 16:01:09 +0100 Message-ID: <20260320150120.874878-2-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[libxenstore.map:url,suse.com:dkim,suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Queue-Id: 8EE745BDF7 X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1774018927208154100 Content-Type: text/plain; charset="utf-8" Add functions for getting and setting Xenstore quota to libxenstore: xs_get_quota_names(): get the names of the supported quota. xs_get_global_quota(): get the value of one global quota. xs_set_global_quota(): set the value of one global quota. xs_get_domain_quota(): get the value of one quota of a domain. xs_set_domain_quota(): set the value of one quota of a domain. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- V2: - make string parameters const (Anthony Perard) - add function descriptions to header (Anthony Perard) --- tools/include/xenstore.h | 37 +++++++++++ tools/libs/store/Makefile | 2 +- tools/libs/store/libxenstore.map | 8 +++ tools/libs/store/xs.c | 111 +++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 1 deletion(-) diff --git a/tools/include/xenstore.h b/tools/include/xenstore.h index 423422dc50..bf6d767a22 100644 --- a/tools/include/xenstore.h +++ b/tools/include/xenstore.h @@ -277,6 +277,43 @@ bool xs_get_features_domain(struct xs_handle *h, unsig= ned int domid, bool xs_set_features_domain(struct xs_handle *h, unsigned int domid, unsigned int features); =20 +/* Get names of supported quota. + * Returns an array of quota names supported by Xenstore. On return + * num will contain the number of quota names in the array. + * Will return NULL on failure. + * The returned array should be freed via free() after usage, this will + * free the array AND the strings of the quota names. + */ +const char **xs_get_quota_names(struct xs_handle *h, unsigned int *num); + +/* Get the value of one global quota. + * Returns the global quota value specified by "quota" in "value". + * Return false on failure. + */ +bool xs_get_global_quota(struct xs_handle *h, const char *quota, + unsigned int *value); + +/* Set the value of one global quota. + * Sets the global quota value specified by "quota" to "value". + * Return false on failure. + */ +bool xs_set_global_quota(struct xs_handle *h, const char *quota, + unsigned int value); + +/* Get the value of one domain quota. + * Returns a domain's quota value specified by "quota" in "value". + * Return false on failure. + */ +bool xs_get_domain_quota(struct xs_handle *h, unsigned int domid, + const char *quota, unsigned int *value); + +/* Set the value of one domain quota. + * Sets a domain's quota value specified by "quota" to "value". + * Return false on failure. + */ +bool xs_set_domain_quota(struct xs_handle *h, unsigned int domid, + const char *quota, unsigned int value); + char *xs_control_command(struct xs_handle *h, const char *cmd, void *data, unsigned int len); /* Deprecated: use xs_control_command() instead. */ diff --git a/tools/libs/store/Makefile b/tools/libs/store/Makefile index fed43b0008..b52d1f35ad 100644 --- a/tools/libs/store/Makefile +++ b/tools/libs/store/Makefile @@ -2,7 +2,7 @@ XEN_ROOT=3D$(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk =20 MAJOR =3D 4 -MINOR =3D 1 +MINOR =3D 2 version-script :=3D libxenstore.map =20 ifeq ($(CONFIG_Linux),y) diff --git a/tools/libs/store/libxenstore.map b/tools/libs/store/libxenstor= e.map index cd9df86749..a08ddd549f 100644 --- a/tools/libs/store/libxenstore.map +++ b/tools/libs/store/libxenstore.map @@ -45,3 +45,11 @@ VERS_4.1 { xs_get_features_domain; xs_set_features_domain; } VERS_4.0; +VERS_4.2 { + global: + xs_get_quota_names; + xs_get_global_quota; + xs_set_global_quota; + xs_get_domain_quota; + xs_set_domain_quota; +} VERS_4.1; diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c index 8f4b90a3cf..06462445e0 100644 --- a/tools/libs/store/xs.c +++ b/tools/libs/store/xs.c @@ -1456,6 +1456,117 @@ bool xs_set_features_domain(struct xs_handle *h, un= signed int domid, return xs_bool(xs_talkv(h, iov, ARRAY_SIZE(iov), NULL)); } =20 +const char **xs_get_quota_names(struct xs_handle *h, unsigned int *num) +{ + struct xsd_sockmsg msg =3D { .type =3D XS_GET_QUOTA }; + struct iovec iov[1]; + const char **quota; + char *reply; + char *c; + unsigned int i; + + iov[0].iov_base =3D &msg; + iov[0].iov_len =3D sizeof(msg); + + reply =3D xs_talkv(h, iov, ARRAY_SIZE(iov), NULL); + if (!reply) + return NULL; + + *num =3D 1; + for (c =3D reply; *c; c++) + if (*c =3D=3D ' ') + (*num)++; + + quota =3D malloc(*num * sizeof(char *) + strlen(reply) + 1); + c =3D (char *)(quota + *num); + strcpy(c, reply); + for (i =3D 0; i < *num; i++) { + quota[i] =3D c; + c =3D strchr(c, ' '); + if (c) { + *c =3D 0; + c++; + } + } + + return quota; +} + +bool xs_get_global_quota(struct xs_handle *h, const char *quota, + unsigned int *value) +{ + struct xsd_sockmsg msg =3D { .type =3D XS_GET_QUOTA }; + struct iovec iov[2]; + + iov[0].iov_base =3D &msg; + iov[0].iov_len =3D sizeof(msg); + iov[1].iov_base =3D (char *)quota; + iov[1].iov_len =3D strlen(quota) + 1; + + return xs_uint(xs_talkv(h, iov, ARRAY_SIZE(iov), NULL), value); +} + +bool xs_set_global_quota(struct xs_handle *h, const char *quota, + unsigned int value) +{ + struct xsd_sockmsg msg =3D { .type =3D XS_SET_QUOTA }; + char val_str[MAX_STRLEN(value)]; + struct iovec iov[3]; + + snprintf(val_str, sizeof(val_str), "%u", value); + + iov[0].iov_base =3D &msg; + iov[0].iov_len =3D sizeof(msg); + iov[1].iov_base =3D (char *)quota; + iov[1].iov_len =3D strlen(quota) + 1; + iov[2].iov_base =3D val_str; + iov[2].iov_len =3D strlen(val_str) + 1; + + return xs_bool(xs_talkv(h, iov, ARRAY_SIZE(iov), NULL)); +} + +bool xs_get_domain_quota(struct xs_handle *h, unsigned int domid, + const char *quota, unsigned int *value) +{ + struct xsd_sockmsg msg =3D { .type =3D XS_GET_QUOTA }; + char domid_str[MAX_STRLEN(domid)]; + struct iovec iov[3]; + + snprintf(domid_str, sizeof(domid_str), "%u", domid); + + iov[0].iov_base =3D &msg; + iov[0].iov_len =3D sizeof(msg); + iov[1].iov_base =3D domid_str; + iov[1].iov_len =3D strlen(domid_str) + 1; + iov[2].iov_base =3D (char *)quota; + iov[2].iov_len =3D strlen(quota) + 1; + + return xs_uint(xs_talkv(h, iov, ARRAY_SIZE(iov), NULL), value); +} + +bool xs_set_domain_quota(struct xs_handle *h, unsigned int domid, + const char *quota, unsigned int value) +{ + struct xsd_sockmsg msg =3D { .type =3D XS_SET_QUOTA }; + char domid_str[MAX_STRLEN(domid)]; + char val_str[MAX_STRLEN(value)]; + struct iovec iov[4]; + + snprintf(domid_str, sizeof(domid_str), "%u", domid); + snprintf(val_str, sizeof(val_str), "%u", value); + + iov[0].iov_base =3D &msg; + iov[0].iov_len =3D sizeof(msg); + iov[1].iov_base =3D domid_str; + iov[1].iov_len =3D strlen(domid_str) + 1; + iov[2].iov_base =3D (char *)quota; + iov[2].iov_len =3D strlen(quota) + 1; + iov[3].iov_base =3D val_str; + iov[3].iov_len =3D strlen(val_str) + 1; + + return xs_bool(xs_talkv(h, iov, ARRAY_SIZE(iov), NULL)); +} + char *xs_control_command(struct xs_handle *h, const char *cmd, void *data, unsigned int len) { --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774018918; cv=none; d=zohomail.com; s=zohoarc; b=ZWt+zaKK4xjpQItLlnboHx97Vzne61iwddWHokPHieqZHS43Eire5kp9VQglh0p3SWJvVSW4A57bn36TX34YYPFh0F85CPKr2L39QiCIWeYYbb4M4E8XDPtl6EYlRFiaYiR3ESdpGz1jSCRK4SnlErucaKcTgasBYz8oeqy2Vao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774018918; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UMmQvyab5G2G37hAWlU7WoprCOyLWbdVZgzV27fPe1Y=; b=dZrCPQVrY5Mf2vLAE5LXUIE5kz6r+vmj4IEaSM0uSuwPZCjbrdzDsiCt1057IMRglAuUzZXfkua1WHH7RF6j2g0RbUnnZt+3TKXET8NJfYxo7Jzp8RWrHsQz6E9G7K8Rzq63MR0Z3v2xFw054vsrAnho1jo0xZp1S8bohrJzh0c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774018918187190.83567197817365; Fri, 20 Mar 2026 08:01:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258096.1552258 (Exim 4.92) (envelope-from ) id 1w3bLz-0001l0-JP; Fri, 20 Mar 2026 15:01:35 +0000 Received: by outflank-mailman (output) from mailman id 1258096.1552258; Fri, 20 Mar 2026 15:01:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bLz-0001kp-F5; Fri, 20 Mar 2026 15:01:35 +0000 Received: by outflank-mailman (input) for mailman id 1258096; Fri, 20 Mar 2026 15:01:34 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bLy-0001Ve-B4 for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:01:34 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id af1e4f0b-246d-11f1-b164-2bf370ae4941; Fri, 20 Mar 2026 16:01:33 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 046424D27B; Fri, 20 Mar 2026 15:01:33 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D619B42868; Fri, 20 Mar 2026 15:01:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id cusPM0xhvWksXAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:01:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: af1e4f0b-246d-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UMmQvyab5G2G37hAWlU7WoprCOyLWbdVZgzV27fPe1Y=; b=sezfUz6RZ3nMFx6zUFekzrc3QDFxkgKQwMpcDYUOBQ95kiJWb3QS375tzfBQFb7z8gxjM+ eK+QZmeSjNOyrMl1/j22YLtQRKBWiPvl+MfwSmUAfgtsoiSWoeKdHgnuSCbs7mU6cWykSd chdAsTm4FXFtHYeUdWO62NdoidYQt/I= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=sezfUz6R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UMmQvyab5G2G37hAWlU7WoprCOyLWbdVZgzV27fPe1Y=; b=sezfUz6RZ3nMFx6zUFekzrc3QDFxkgKQwMpcDYUOBQ95kiJWb3QS375tzfBQFb7z8gxjM+ eK+QZmeSjNOyrMl1/j22YLtQRKBWiPvl+MfwSmUAfgtsoiSWoeKdHgnuSCbs7mU6cWykSd chdAsTm4FXFtHYeUdWO62NdoidYQt/I= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v2 02/12] tools/xenstored: add helper to parse domid Date: Fri, 20 Mar 2026 16:01:10 +0100 Message-ID: <20260320150120.874878-3-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.com:dkim,suse.com:mid,suse.com:email]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Queue-Id: 046424D27B X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1774018921188154100 Content-Type: text/plain; charset="utf-8" Today a domid passed in by a command is parsed using atoi(). This will still "succeed" even with a domid like "x", resulting in "0" to be used instead. Use a common domid parser instead rejecting everything but integers in the range 0..65535 like specified in docs/misc/xenstore.txt. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- V2: - new patch (kind of suggested by Anthony Perard) --- tools/xenstored/domain.c | 47 +++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index e453b3061f..a70acddf94 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -732,6 +732,18 @@ static char *talloc_domain_path(const void *context, u= nsigned int domid) return talloc_asprintf(context, "/local/domain/%u", domid); } =20 +/* Parse a domid. Sets errno either to 0 or EINVAL. */ +static unsigned int parse_domid(const char *input) +{ + unsigned long domid; + char *endptr; + + domid =3D strtoul(input, &endptr, 10); + errno =3D (*endptr !=3D 0 || domid > 65535) ? EINVAL : 0; + + return domid; +} + int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid) { @@ -1077,7 +1089,10 @@ int do_introduce(const void *ctx, struct connection = *conn, if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) return EINVAL; =20 - domid =3D atoi(vec[0]); + domid =3D parse_domid(vec[0]); + if (errno) + return errno; + /* Ignore the gfn, we don't need it. */ port =3D atoi(vec[2]); =20 @@ -1124,8 +1139,12 @@ int do_set_target(const void *ctx, struct connection= *conn, if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) return EINVAL; =20 - domid =3D atoi(vec[0]); - tdomid =3D atoi(vec[1]); + domid =3D parse_domid(vec[0]); + if (errno) + return errno; + tdomid =3D parse_domid(vec[1]); + if (errno) + return errno; =20 domain =3D find_connected_domain(domid); if (IS_ERR(domain)) @@ -1152,7 +1171,9 @@ static struct domain *onearg_domain(struct connection= *conn, if (!domid_str) return ERR_PTR(-EINVAL); =20 - domid =3D atoi(domid_str); + domid =3D parse_domid(domid_str); + if (errno) + return ERR_PTR(-errno); if (domid =3D=3D store_domid || domid =3D=3D priv_domid) return ERR_PTR(-EINVAL); =20 @@ -1200,11 +1221,15 @@ int do_get_domain_path(const void *ctx, struct conn= ection *conn, { char *path; const char *domid_str =3D onearg(in); + unsigned int domid; =20 if (!domid_str) return EINVAL; =20 - path =3D talloc_domain_path(ctx, atoi(domid_str)); + domid =3D parse_domid(domid_str); + if (errno) + return errno; + path =3D talloc_domain_path(ctx, domid); if (!path) return errno; =20 @@ -1223,7 +1248,9 @@ int do_is_domain_introduced(const void *ctx, struct c= onnection *conn, if (!domid_str) return EINVAL; =20 - domid =3D atoi(domid_str); + domid =3D parse_domid(domid_str); + if (errno) + return errno; if (domid =3D=3D DOMID_SELF) result =3D 1; else @@ -1261,7 +1288,9 @@ int do_get_feature(const void *ctx, struct connection= *conn, return EINVAL; =20 if (n_args =3D=3D 1) { - domid =3D atoi(vec[0]); + domid =3D parse_domid(vec[0]); + if (errno) + return errno; domain =3D find_or_alloc_existing_domain(domid); if (!domain) return ENOENT; @@ -1289,7 +1318,9 @@ int do_set_feature(const void *ctx, struct connection= *conn, if (get_strings(in, vec, ARRAY_SIZE(vec)) !=3D ARRAY_SIZE(vec)) return EINVAL; =20 - domid =3D atoi(vec[0]); + domid =3D parse_domid(vec[0]); + if (errno) + return errno; features =3D atoi(vec[1]); domain =3D find_or_alloc_existing_domain(domid); if (!domain) --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774018935; cv=none; d=zohomail.com; s=zohoarc; b=jcrVyu2c13bwJlUc11JMyMFl5i1eXu52LdRQ4lLEILRmxgRcnfYBgGdPceGKoKWiTjoy93Smp51epvncvJ+4uEpuD6v+fLdJHmKE8ZQqYFdznGaQUUGc6kz+ISrINUXwYKNN56iW8arllH0R3vBIFIBS5LFSSLCiRhLlOKCzyts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774018935; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/PcS/7XQ557sIjqSKbSX5CF48BnA+Ztcs9ICymueV/w=; b=GUSSwg263sJqgOvU7Urfq0VmlHZxZ4IBOk/fzhVVLktC2C8+ZK3Ubd6yQqXfduTIhak55pp1s8vz/3COkYKM/sKehQHuGz702VqwHg9pH4H4vHvUg0yl6w5JzcBXwoiOWclr6jQhZb9QRZ7aSs+cU5fu/ejOOdEaubN8Lz5OCFs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774018935027456.6585447798318; Fri, 20 Mar 2026 08:02:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258099.1552275 (Exim 4.92) (envelope-from ) id 1w3bME-0002LV-0l; Fri, 20 Mar 2026 15:01:50 +0000 Received: by outflank-mailman (output) from mailman id 1258099.1552275; Fri, 20 Mar 2026 15:01:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMD-0002LL-T7; Fri, 20 Mar 2026 15:01:49 +0000 Received: by outflank-mailman (input) for mailman id 1258099; Fri, 20 Mar 2026 15:01:48 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMC-0001Ve-Mg for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:01:48 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b7b941d6-246d-11f1-b164-2bf370ae4941; Fri, 20 Mar 2026 16:01:47 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6C9315BDF1; Fri, 20 Mar 2026 15:01:38 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4BD3842866; Fri, 20 Mar 2026 15:01:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Y4FYEVJhvWk/XAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:01:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b7b941d6-246d-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/PcS/7XQ557sIjqSKbSX5CF48BnA+Ztcs9ICymueV/w=; b=gy+MTAPWgRFjoGgXB1ttiyIPkAjxMVtyZdEUOgaB3d2DlHxd0WrsqKlHqnifDzVlzQSMDL 6sGO1hBya4UEn3XDGDbaUbmfK3HZYt+HZxO3S5Mt8610sRM4QxqlvB0u9ephMD4LqU+Izg YbLcgsyYyorCh0BE7I3phFBg8fO1Wyc= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=mo9MZ39Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018898; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/PcS/7XQ557sIjqSKbSX5CF48BnA+Ztcs9ICymueV/w=; b=mo9MZ39Y5662BNkZptfC09SxsSkiAc69252f8BV5wnxo7KdUdqaT7Rt06zYTdPb4uQhgR1 xNrFkjaSWYmqtnhcWG7ZEFbOYGqC6RnaVprSLd4TDAXDE6/bmVG0TXCJS8QdOsPAN4lY0R JjtXTzMIq0GNwetNUMU6Idh10eq9L3M= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v2 03/12] tools/xenstored: add central quota check functions Date: Fri, 20 Mar 2026 16:01:11 +0100 Message-ID: <20260320150120.874878-4-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:dkim,suse.com:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 6C9315BDF1 X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1774018937267154100 Content-Type: text/plain; charset="utf-8" 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(). While at it, make the returned error for exceeded quota consistent by changing one instance from "E2BIG" to "ENOSPC". Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- V2: - expand commit message (Anthony Perard) - rename domain_check_quota_*() to domain_quota_*_exceeds() (Jason Andryuk) --- tools/xenstored/core.c | 4 +- tools/xenstored/domain.c | 74 +++++++++++++++++------------------ tools/xenstored/domain.h | 6 +-- tools/xenstored/transaction.c | 2 +- tools/xenstored/watch.c | 4 +- 5 files changed, 42 insertions(+), 48 deletions(-) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index e4d2fd4876..e86d947be4 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -1539,7 +1539,7 @@ static struct node *create_node(struct connection *co= nn, const void *ctx, for (i =3D node; i; i =3D i->parent) { /* i->parent is set for each new node, so check quota. */ if (i->parent && - domain_nbentry(conn) >=3D hard_quotas[ACC_NODES].val) { + domain_quota_add_exceeds(conn->domain, ACC_NODES, 1)) { ret =3D ENOSPC; goto err; } @@ -2321,7 +2321,7 @@ void setup_structure(bool live_update) manual_node("/tool/xenstored", NULL); manual_node("@releaseDomain", NULL); manual_node("@introduceDomain", NULL); - domain_nbentry_fix(priv_domid, 5, true); + domain_nbentry_fix(priv_domid, 5); } } =20 diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index a70acddf94..21f6f13f83 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -389,6 +389,25 @@ void wrl_apply_debit_trans_commit(struct connection *c= onn) wrl_apply_debit_actual(conn->domain); } =20 +static bool domain_quota_val_exceeds(struct domain *d, enum accitem what, + unsigned int val) +{ + unsigned int quota =3D hard_quotas[what].val; + + if (!quota || !domid_is_unprivileged(d->domid)) + return false; + + return val >=3D quota; +} + +bool domain_quota_add_exceeds(struct domain *d, enum accitem what, int add) +{ + if (add < 0 || !d) + return false; + + return domain_quota_val_exceeds(d, what, d->acc[what].val + add); +} + static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) { return ((prod - cons) <=3D XENSTORE_RING_SIZE); @@ -490,10 +509,9 @@ static bool domain_can_read(struct connection *conn) if (domain_is_unprivileged(conn)) { if (domain->wrl_credit < 0) return false; - if (domain->acc[ACC_OUTST].val >=3D hard_quotas[ACC_OUTST].val) + if (domain_quota_add_exceeds(domain, ACC_OUTST, 0)) return false; - if (domain->acc[ACC_MEM].val >=3D hard_quotas[ACC_MEM].val && - hard_quotas[ACC_MEM].val) + if (domain_quota_add_exceeds(domain, ACC_MEM, 0)) return false; } =20 @@ -916,16 +934,20 @@ do { \ =20 int acc_fix_domains(struct list_head *head, bool chk_quota, bool update) { + struct domain *d; struct changed_domain *cd; - int cnt; =20 list_for_each_entry(cd, head, list) { - cnt =3D domain_nbentry_fix(cd->domid, cd->acc[ACC_NODES], update); - if (!update) { - if (chk_quota && cnt >=3D hard_quotas[ACC_NODES].val) - return ENOSPC; - if (cnt < 0) + if (update) { + domain_nbentry_fix(cd->domid, cd->acc[ACC_NODES]); + } else if (chk_quota) { + d =3D find_or_alloc_existing_domain(cd->domid); + + if (!d) return ENOMEM; + if (domain_quota_add_exceeds(d, ACC_NODES, + cd->acc[ACC_NODES])) + return ENOSPC; } } =20 @@ -1763,7 +1785,7 @@ bool domain_max_chk(const struct connection *conn, en= um accitem what, if (!conn || !conn->domain) return false; =20 - if (domain_is_unprivileged(conn) && val > hard_quotas[what].val) + if (domain_quota_val_exceeds(conn->domain, what, val)) return true; =20 domain_acc_valid_max(conn->domain, what, val); @@ -1783,21 +1805,9 @@ int domain_nbentry_dec(struct connection *conn, unsi= gned int domid) ? errno : 0; } =20 -int domain_nbentry_fix(unsigned int domid, int num, bool update) -{ - int ret; - - ret =3D domain_acc_add(NULL, domid, ACC_NODES, update ? num : 0, update); - if (ret < 0 || update) - return ret; - - return domid_is_unprivileged(domid) ? ret + num : 0; -} - -unsigned int domain_nbentry(struct connection *conn) +int domain_nbentry_fix(unsigned int domid, int num) { - return domain_is_unprivileged(conn) - ? domain_acc_add(conn, conn->id, ACC_NODES, 0, true) : 0; + return domain_acc_add(NULL, domid, ACC_NODES, num, true); } =20 static bool domain_chk_quota(struct connection *conn, unsigned int mem) @@ -1812,7 +1822,7 @@ static bool domain_chk_quota(struct connection *conn,= unsigned int mem) domain =3D conn->domain; now =3D time(NULL); =20 - if (mem >=3D hard_quotas[ACC_MEM].val && hard_quotas[ACC_MEM].val) { + if (domain_quota_val_exceeds(domain, ACC_MEM, mem)) { if (domain->hard_quota_reported) return true; syslog(LOG_ERR, "Domain %u exceeds hard memory quota, Xenstore interface= to domain stalled\n", @@ -1888,13 +1898,6 @@ void domain_watch_dec(struct connection *conn) domain_acc_add(conn, conn->id, ACC_WATCH, -1, true); } =20 -int domain_watch(struct connection *conn) -{ - return (domain_is_unprivileged(conn)) - ? domain_acc_add(conn, conn->id, ACC_WATCH, 0, true) - : 0; -} - void domain_outstanding_inc(struct connection *conn) { domain_acc_add(conn, conn->id, ACC_OUTST, 1, true); @@ -1915,13 +1918,6 @@ void domain_transaction_dec(struct connection *conn) domain_acc_add(conn, conn->id, ACC_TRANS, -1, true); } =20 -unsigned int domain_transaction_get(struct connection *conn) -{ - return (domain_is_unprivileged(conn)) - ? domain_acc_add(conn, conn->id, ACC_TRANS, 0, true) - : 0; -} - const char *dump_state_connections(FILE *fp) { const char *ret =3D NULL; diff --git a/tools/xenstored/domain.h b/tools/xenstored/domain.h index 28186ccac0..29b91fc783 100644 --- a/tools/xenstored/domain.h +++ b/tools/xenstored/domain.h @@ -113,8 +113,7 @@ int domain_alloc_permrefs(struct node_perms *perms); /* Quota manipulation */ int domain_nbentry_inc(struct connection *conn, unsigned int domid); int domain_nbentry_dec(struct connection *conn, unsigned int domid); -int domain_nbentry_fix(unsigned int domid, int num, bool update); -unsigned int domain_nbentry(struct connection *conn); +int domain_nbentry_fix(unsigned int domid, int num); int domain_memory_add(struct connection *conn, unsigned int domid, int mem, bool no_quota_check); =20 @@ -141,12 +140,10 @@ static inline void domain_memory_add_nochk(struct con= nection *conn, } void domain_watch_inc(struct connection *conn); void domain_watch_dec(struct connection *conn); -int domain_watch(struct connection *conn); void domain_outstanding_inc(struct connection *conn); void domain_outstanding_dec(struct connection *conn, unsigned int domid); void domain_transaction_inc(struct connection *conn); void domain_transaction_dec(struct connection *conn); -unsigned int domain_transaction_get(struct connection *conn); int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid); =20 @@ -161,6 +158,7 @@ int domain_max_global_acc(const void *ctx, struct conne= ction *conn); void domain_reset_global_acc(void); bool domain_max_chk(const struct connection *conn, enum accitem what, unsigned int val); +bool domain_quota_add_exceeds(struct domain *d, enum accitem what, int add= ); =20 extern long wrl_ntransactions; =20 diff --git a/tools/xenstored/transaction.c b/tools/xenstored/transaction.c index 167cd597fd..47cd6ecd3c 100644 --- a/tools/xenstored/transaction.c +++ b/tools/xenstored/transaction.c @@ -470,7 +470,7 @@ int do_transaction_start(const void *ctx, struct connec= tion *conn, if (conn->transaction) return EBUSY; =20 - if (domain_transaction_get(conn) > hard_quotas[ACC_TRANS].val) + if (domain_quota_add_exceeds(conn->domain, ACC_TRANS, 1)) return ENOSPC; =20 /* Attach transaction to ctx for autofree until it's complete */ diff --git a/tools/xenstored/watch.c b/tools/xenstored/watch.c index b66a9f1a39..becb9c339d 100644 --- a/tools/xenstored/watch.c +++ b/tools/xenstored/watch.c @@ -220,8 +220,8 @@ int do_watch(const void *ctx, struct connection *conn, = struct buffered_data *in) return EEXIST; } =20 - if (domain_watch(conn) > hard_quotas[ACC_WATCH].val) - return E2BIG; + if (domain_quota_add_exceeds(conn->domain, ACC_WATCH, 1)) + return ENOSPC; =20 watch =3D add_watch(conn, vec[0], vec[1], relative, false); if (!watch) --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774018945; cv=none; d=zohomail.com; s=zohoarc; b=LrpK3O+r5b2eu/8VeqkJUuFRIZTarqyP4KXgcC7JmC02e7tT6hZq5YExYFEixhzHh5VzM84aG8tUUPWwKoSelx52jqiGKmSs7jB7uyIS8OzJbPVkiXo/d4jdHyeOtAF0Vsc7Ebh2fA+F0sc0eqrikA925SyQKk3eZ4fAA3zOClg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774018945; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qdvDBarqGgiL43xd/vvQTmt16yx93JcWCKCmVqFw2vI=; b=lz34SEyYfOpYFKW3dOGIkZYC70YlP2eco9xI2q6Don6Gh4siHArzs+2YhpNOTLfrNTyPoT97iACsTbrKitACqpUyKA6Y1CDwnvsRDv4A5aNSi2CLkliS5MiuLdg48e3hIr1SfGpZBfpPVUGv+i4+RWE3E1glPsv1fYCimTR/yNc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774018945077972.7008148887862; Fri, 20 Mar 2026 08:02:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258100.1552284 (Exim 4.92) (envelope-from ) id 1w3bMF-0002aC-B6; Fri, 20 Mar 2026 15:01:51 +0000 Received: by outflank-mailman (output) from mailman id 1258100.1552284; Fri, 20 Mar 2026 15:01:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMF-0002a1-7E; Fri, 20 Mar 2026 15:01:51 +0000 Received: by outflank-mailman (input) for mailman id 1258100; Fri, 20 Mar 2026 15:01:49 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMD-0001Ve-Ms for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:01:49 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b7b1befc-246d-11f1-b164-2bf370ae4941; Fri, 20 Mar 2026 16:01:47 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DB28B4D283; Fri, 20 Mar 2026 15:01:43 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B9BB94286A; Fri, 20 Mar 2026 15:01:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 5qkuLFdhvWnIXAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:01:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b7b1befc-246d-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018907; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qdvDBarqGgiL43xd/vvQTmt16yx93JcWCKCmVqFw2vI=; b=dfEGX3AKjjWqhGOj0IZESdUAapuHSM78emCH0i9bbYOosKxcDABJy6vmqAmPdVyVVW//om 9FdpZX334eXePmHeOphKrXxj2rslJ3ggkS72vmnHIuks0KdxiKgtKKayZcXgAN8dPorQJt J33UMI2hJOK5ZK9CBkXLcfZmrsg4R8A= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="Z93Mv/u9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qdvDBarqGgiL43xd/vvQTmt16yx93JcWCKCmVqFw2vI=; b=Z93Mv/u9y2dtiHFRupINtCViI4zqk8cCCVnj7+Ba7fEFY16xsbOGGozjdby8gjlpD0s7dW noK92+GdsOdrArxgvWWRr+6mhAJsMZHbebpQ/oxt/weuMafSEtsHJRd/KcXb1onEuaFrwp 9glmz26IfP6yP9rK56Klfk5CLerhL3s= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v2 04/12] tools/xenstored: rework hard_quotas and soft_quotas arrays Date: Fri, 20 Mar 2026 16:01:12 +0100 Message-ID: <20260320150120.874878-5-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.com:mid,suse.com:dkim,suse.com:email]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: DB28B4D283 X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1774018945672158500 Content-Type: text/plain; charset="utf-8" Instead of having one array for hard quotas and one for soft quotas, split them differently: have one array with the quota names and descriptions, and one with the quota values (soft and hard) and the maximum value so far. This is in preparation of supporting per-domain quotas, as the layout of the second array elements will be reused in the domain data. While at it add an accessor for getting a soft quota value, as this will be needed for per-domain quotas, too. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- tools/xenstored/control.c | 24 ++++++++------- tools/xenstored/core.c | 33 +++++++++++--------- tools/xenstored/domain.c | 65 +++++++++++++++++++++------------------ tools/xenstored/domain.h | 15 +++++---- 4 files changed, 76 insertions(+), 61 deletions(-) diff --git a/tools/xenstored/control.c b/tools/xenstored/control.c index 2611a6fade..ca59d30d05 100644 --- a/tools/xenstored/control.c +++ b/tools/xenstored/control.c @@ -101,7 +101,7 @@ static int do_control_log(const void *ctx, struct conne= ction *conn, } =20 static int quota_show_current(const void *ctx, struct connection *conn, - const struct quota *quotas) + unsigned int idx) { char *resp; unsigned int i; @@ -111,11 +111,12 @@ static int quota_show_current(const void *ctx, struct= connection *conn, return ENOMEM; =20 for (i =3D 0; i < ACC_N; i++) { - if (!quotas[i].name) + if (!quota_adm[i].name || quotas[i].val[idx] =3D=3D Q_VAL_DISABLED) continue; resp =3D talloc_asprintf_append(resp, "%-17s: %8d %s\n", - quotas[i].name, quotas[i].val, - quotas[i].descr); + quota_adm[i].name, + quotas[i].val[idx], + quota_adm[i].descr); if (!resp) return ENOMEM; } @@ -126,7 +127,7 @@ static int quota_show_current(const void *ctx, struct c= onnection *conn, } =20 static int quota_set(const void *ctx, struct connection *conn, - const char **vec, int num, struct quota *quotas) + const char **vec, int num, unsigned int idx) { unsigned int i; int val; @@ -139,8 +140,9 @@ static int quota_set(const void *ctx, struct connection= *conn, return EINVAL; =20 for (i =3D 0; i < ACC_N; i++) { - if (quotas[i].name && !strcmp(vec[0], quotas[i].name)) { - quotas[i].val =3D val; + if (quota_adm[i].name && !strcmp(vec[0], quota_adm[i].name) && + quotas[i].val[idx] !=3D Q_VAL_DISABLED) { + quotas[i].val[idx] =3D val; send_ack(conn, XS_CONTROL); return 0; } @@ -178,10 +180,10 @@ static int do_control_quota(const void *ctx, struct c= onnection *conn, const char **vec, int num) { if (num =3D=3D 0) - return quota_show_current(ctx, conn, hard_quotas); + return quota_show_current(ctx, conn, Q_IDX_HARD); =20 if (!strcmp(vec[0], "set")) - return quota_set(ctx, conn, vec + 1, num - 1, hard_quotas); + return quota_set(ctx, conn, vec + 1, num - 1, Q_IDX_HARD); =20 if (!strcmp(vec[0], "max")) return quota_max(ctx, conn, vec + 1, num - 1); @@ -193,10 +195,10 @@ static int do_control_quota_s(const void *ctx, struct= connection *conn, const char **vec, int num) { if (num =3D=3D 0) - return quota_show_current(ctx, conn, soft_quotas); + return quota_show_current(ctx, conn, Q_IDX_SOFT); =20 if (!strcmp(vec[0], "set")) - return quota_set(ctx, conn, vec + 1, num - 1, soft_quotas); + return quota_set(ctx, conn, vec + 1, num - 1, Q_IDX_SOFT); =20 return EINVAL; } diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index e86d947be4..dc63c97658 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2614,10 +2614,9 @@ static void set_timeout(const char *arg) barf("unknown timeout \"%s\"\n", arg); } =20 -static void set_quota(const char *arg, bool soft) +static void set_quota(const char *arg, unsigned int idx) { const char *eq =3D strchr(arg, '=3D'); - struct quota *q =3D soft ? soft_quotas : hard_quotas; unsigned int val; unsigned int i; =20 @@ -2626,8 +2625,9 @@ static void set_quota(const char *arg, bool soft) val =3D get_optval_uint(eq + 1); =20 for (i =3D 0; i < ACC_N; i++) { - if (what_matches(arg, q[i].name)) { - q[i].val =3D val; + if (what_matches(arg, quota_adm[i].name) && + quotas[i].val[idx] !=3D Q_VAL_DISABLED) { + quotas[i].val[idx] =3D val; return; } } @@ -2635,6 +2635,11 @@ static void set_quota(const char *arg, bool soft) barf("unknown quota \"%s\"\n", arg); } =20 +static void set_one_quota(const char *arg, unsigned int idx, enum accitem = what) +{ + quotas[what].val[idx] =3D get_optval_uint(arg); +} + /* Sorted by bit values of TRACE_* flags. Flag is (1u << index). */ const char *const trace_switches[] =3D { "obj", "io", "wrl", "acc", "tdb", @@ -2688,7 +2693,7 @@ int main(int argc, char *argv[]) options, NULL)) !=3D -1) { switch (opt) { case 'E': - hard_quotas[ACC_NODES].val =3D get_optval_uint(optarg); + set_one_quota(optarg, Q_IDX_HARD, ACC_NODES); break; case 'F': pidfile =3D optarg; @@ -2700,10 +2705,10 @@ int main(int argc, char *argv[]) dofork =3D false; break; case 'S': - hard_quotas[ACC_NODESZ].val =3D get_optval_uint(optarg); + set_one_quota(optarg, Q_IDX_HARD, ACC_NODESZ); break; case 't': - hard_quotas[ACC_TRANS].val =3D get_optval_uint(optarg); + set_one_quota(optarg, Q_IDX_HARD, ACC_TRANS); break; case 'T': tracefile =3D optarg; @@ -2716,22 +2721,22 @@ int main(int argc, char *argv[]) keep_orphans =3D true; break; case 'W': - hard_quotas[ACC_WATCH].val =3D get_optval_uint(optarg); + set_one_quota(optarg, Q_IDX_HARD, ACC_WATCH); break; case 'A': - hard_quotas[ACC_NPERM].val =3D get_optval_uint(optarg); + set_one_quota(optarg, Q_IDX_HARD, ACC_NPERM); break; case 'M': - hard_quotas[ACC_PATHLEN].val =3D get_optval_uint(optarg); - hard_quotas[ACC_PATHLEN].val =3D + set_one_quota(optarg, Q_IDX_HARD, ACC_PATHLEN); + quotas[ACC_PATHLEN].val[Q_IDX_HARD] =3D min((unsigned int)XENSTORE_REL_PATH_MAX, - hard_quotas[ACC_PATHLEN].val); + quotas[ACC_PATHLEN].val[Q_IDX_HARD]); break; case 'Q': - set_quota(optarg, false); + set_quota(optarg, Q_IDX_HARD); break; case 'q': - set_quota(optarg, true); + set_quota(optarg, Q_IDX_SOFT); break; case 'w': set_timeout(optarg); diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 21f6f13f83..4e696a81a8 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -51,60 +51,60 @@ static evtchn_port_t virq_port; =20 xenevtchn_handle *xce_handle =3D NULL; =20 -struct quota hard_quotas[ACC_N] =3D { +struct quotaadm quota_adm[ACC_N] =3D { [ACC_NODES] =3D { .name =3D "nodes", .descr =3D "Nodes per domain", - .val =3D 1000, }, [ACC_WATCH] =3D { .name =3D "watches", .descr =3D "Watches per domain", - .val =3D 128, }, [ACC_OUTST] =3D { .name =3D "outstanding", .descr =3D "Outstanding requests per domain", - .val =3D 20, }, [ACC_MEM] =3D { .name =3D "memory", - .descr =3D "Total Xenstore memory per domain (error level)", - .val =3D 2 * 1024 * 1024 + 512 * 1024, /* 2.5 MB */ + .descr =3D "Total Xenstore memory per domain", }, [ACC_TRANS] =3D { .name =3D "transactions", .descr =3D "Active transactions per domain", - .val =3D 10, }, [ACC_TRANSNODES] =3D { .name =3D "transaction-nodes", .descr =3D "Max. number of accessed nodes per transaction", - .val =3D 1024, }, [ACC_NPERM] =3D { .name =3D "node-permissions", .descr =3D "Max. number of permissions per node", - .val =3D 5, }, [ACC_PATHLEN] =3D { .name =3D "path-max", .descr =3D "Max. length of a node path", - .val =3D XENSTORE_REL_PATH_MAX, }, [ACC_NODESZ] =3D { .name =3D "node-size", .descr =3D "Max. size of a node", - .val =3D 2048, }, }; =20 -struct quota soft_quotas[ACC_N] =3D { - [ACC_MEM] =3D { - .name =3D "memory", - .descr =3D "Total Xenstore memory per domain (warning level)", - .val =3D 2 * 1024 * 1024, /* 2.0 MB */ +struct quota quotas[ACC_N] =3D { + [ACC_NODES] =3D { .val =3D { 1000, Q_VAL_DISABLED }, }, + [ACC_WATCH] =3D { .val =3D { 128, Q_VAL_DISABLED }, }, + [ACC_OUTST] =3D { .val =3D { 20, Q_VAL_DISABLED }, }, + [ACC_MEM] =3D { + .val =3D { 2 * 1024 * 1024 + 512 * 1024, /* 2.5 MB */ + 2 * 1024 * 1024 /* 2.0 MB */ }, }, + [ACC_TRANS] =3D { .val =3D { 10, Q_VAL_DISABLED }, }, + [ACC_TRANSNODES] =3D { .val =3D { 1024, Q_VAL_DISABLED }, }, + [ACC_NPERM] =3D { .val =3D { 5, Q_VAL_DISABLED }, }, + [ACC_PATHLEN] =3D { + .val =3D { XENSTORE_REL_PATH_MAX, Q_VAL_DISABLED }, + }, + [ACC_NODESZ] =3D { .val =3D { 2048, Q_VAL_DISABLED }, }, }; =20 typedef int32_t wrl_creditt; @@ -389,10 +389,15 @@ void wrl_apply_debit_trans_commit(struct connection *= conn) wrl_apply_debit_actual(conn->domain); } =20 +static unsigned int domain_get_soft_quota(struct domain *d, enum accitem w= hat) +{ + return quotas[what].val[Q_IDX_SOFT]; +} + static bool domain_quota_val_exceeds(struct domain *d, enum accitem what, unsigned int val) { - unsigned int quota =3D hard_quotas[what].val; + unsigned int quota =3D quotas[what].val[Q_IDX_HARD]; =20 if (!quota || !domid_is_unprivileged(d->domid)) return false; @@ -777,10 +782,10 @@ int domain_get_quota(const void *ctx, struct connecti= on *conn, return ENOMEM; =20 for (i =3D 0; i < ACC_N; i++) { - if (!hard_quotas[i].name) + if (!quota_adm[i].name) continue; resp =3D talloc_asprintf_append(resp, "%-17s: %8u (max %8u)\n", - hard_quotas[i].name, + quota_adm[i].name, d->acc[i].val, d->acc[i].max); if (!resp) return ENOMEM; @@ -801,11 +806,10 @@ int domain_max_global_acc(const void *ctx, struct con= nection *conn) return ENOMEM; =20 for (i =3D 0; i < ACC_N; i++) { - if (!hard_quotas[i].name) + if (!quota_adm[i].name) continue; resp =3D talloc_asprintf_append(resp, "%-17s: %8u\n", - hard_quotas[i].name, - hard_quotas[i].max); + quota_adm[i].name, quotas[i].max); if (!resp) return ENOMEM; } @@ -1631,12 +1635,12 @@ static void domain_acc_valid_max(struct domain *d, = enum accitem what, unsigned int val) { assert(what < ARRAY_SIZE(d->acc)); - assert(what < ARRAY_SIZE(hard_quotas)); + assert(what < ARRAY_SIZE(quotas)); =20 if (val > d->acc[what].max) d->acc[what].max =3D val; - if (val > hard_quotas[what].max && domid_is_unprivileged(d->domid)) - hard_quotas[what].max =3D val; + if (val > quotas[what].max && domid_is_unprivileged(d->domid)) + quotas[what].max =3D val; } =20 static int domain_acc_add_valid(struct domain *d, enum accitem what, int a= dd) @@ -1773,7 +1777,7 @@ void domain_reset_global_acc(void) unsigned int i; =20 for (i =3D 0; i < ACC_N; i++) - hard_quotas[i].max =3D 0; + quotas[i].max =3D 0; =20 /* Set current max values seen. */ hashtable_iterate(domhash, domain_reset_global_acc_sub, NULL); @@ -1833,21 +1837,22 @@ static bool domain_chk_quota(struct connection *con= n, unsigned int mem) } =20 if (now - domain->mem_last_msg >=3D MEM_WARN_MINTIME_SEC) { + unsigned int soft_mem =3D domain_get_soft_quota(domain, ACC_MEM); + if (domain->hard_quota_reported) { domain->mem_last_msg =3D now; domain->hard_quota_reported =3D false; syslog(LOG_INFO, "Domain %u below hard memory quota again\n", domain->domid); } - if (mem >=3D soft_quotas[ACC_MEM].val && - soft_quotas[ACC_MEM].val && !domain->soft_quota_reported) { + if (mem >=3D soft_mem && soft_mem && + !domain->soft_quota_reported) { domain->mem_last_msg =3D now; domain->soft_quota_reported =3D true; syslog(LOG_WARNING, "Domain %u exceeds soft memory quota\n", domain->domid); } - if (mem < soft_quotas[ACC_MEM].val && - domain->soft_quota_reported) { + if (mem < soft_mem && domain->soft_quota_reported) { domain->mem_last_msg =3D now; domain->soft_quota_reported =3D false; syslog(LOG_INFO, "Domain %u below soft memory quota again\n", diff --git a/tools/xenstored/domain.h b/tools/xenstored/domain.h index 29b91fc783..3bedadb477 100644 --- a/tools/xenstored/domain.h +++ b/tools/xenstored/domain.h @@ -40,15 +40,18 @@ enum accitem { ACC_N, /* Number of elements per domain. */ }; =20 -struct quota { +extern struct quotaadm { const char *name; const char *descr; - unsigned int val; - unsigned int max; -}; +} quota_adm[ACC_N]; =20 -extern struct quota hard_quotas[ACC_N]; -extern struct quota soft_quotas[ACC_N]; +extern struct quota { + unsigned int val[2]; +#define Q_IDX_HARD 0 +#define Q_IDX_SOFT 1 +#define Q_VAL_DISABLED UINT_MAX + unsigned int max; +} quotas[ACC_N]; =20 void handle_event(void); =20 --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774018941; cv=none; d=zohomail.com; s=zohoarc; b=hB9MlTmGDPNIlnIw3QJg1gTwR7V6+yc2dSP02uvOegdlj63Tn1IZG79IeqB1JZWOAF8MmvMJgIbxY4tphjI+wLFH9CDx+BCVtHkn2mkb+epmHgNXEQrIZcOJx1kvim+SV45qbmJySJ6MXTK7bhwNANlriWLH2YJU5H1A8H4kKss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774018941; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=71OCtUN3V2d3sM2aEWOZPCVfbKJBQnPGkvk8gK9D9UI=; b=CqWo1kwFidQmu4rf7RD3t8GRRrqy9dMjd0gaWzUSSPMmX5iBr55l9EP5f83JPnvWziGN5xYGcZn3cxTJZJGC3FgkdIqESIouVZ3Wc11kgiHWVLSCMk6shgybLKQAe6UXHU0wCA+wg/boKnW8hRq1Jz9+SDYHYbUi/5xe7ULq8go= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774018941358812.3911118143678; Fri, 20 Mar 2026 08:02:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258101.1552293 (Exim 4.92) (envelope-from ) id 1w3bMH-0002qK-Kc; Fri, 20 Mar 2026 15:01:53 +0000 Received: by outflank-mailman (output) from mailman id 1258101.1552293; Fri, 20 Mar 2026 15:01:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMH-0002qD-FW; Fri, 20 Mar 2026 15:01:53 +0000 Received: by outflank-mailman (input) for mailman id 1258101; Fri, 20 Mar 2026 15:01:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMG-0001Ve-Hz for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:01:52 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ba0c9fcd-246d-11f1-b164-2bf370ae4941; Fri, 20 Mar 2026 16:01:51 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4C8894D282; Fri, 20 Mar 2026 15:01:49 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2D97042866; Fri, 20 Mar 2026 15:01:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 3ycOCl1hvWnNXAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:01:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ba0c9fcd-246d-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018909; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=71OCtUN3V2d3sM2aEWOZPCVfbKJBQnPGkvk8gK9D9UI=; b=hrfUx7Dp4ipwlA33mKY5qH08RvtebywdI4DCPPaHvQ+JJamb6otSfLnmWe1Pt41+Qb/E6s X8U61R47Lprp+3UkgqpOdyyfwrZie9ceJdvZHYJwikYixRCFkk2LwWZaxOYFXRYjznHDgk mQ2v8zhL45x4hJzrAIgy57ImZ4vB9no= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=hrfUx7Dp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018909; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=71OCtUN3V2d3sM2aEWOZPCVfbKJBQnPGkvk8gK9D9UI=; b=hrfUx7Dp4ipwlA33mKY5qH08RvtebywdI4DCPPaHvQ+JJamb6otSfLnmWe1Pt41+Qb/E6s X8U61R47Lprp+3UkgqpOdyyfwrZie9ceJdvZHYJwikYixRCFkk2LwWZaxOYFXRYjznHDgk mQ2v8zhL45x4hJzrAIgy57ImZ4vB9no= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v2 05/12] tools/xenstored: add GLOBAL_QUOTA_DATA record for live update Date: Fri, 20 Mar 2026 16:01:13 +0100 Message-ID: <20260320150120.874878-6-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:dkim,suse.com:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 4C8894D282 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1774018941617158500 Content-Type: text/plain; charset="utf-8" Communicate the global quota settings via the GLOBAL_QUOTA_DATA record to the new Xenstore instance. This avoids to lose global quota settings done via xenstore-control. In theory it would be possible to drop any quota related command line parameters in the live update case, but they don't do any harm, as the record data is applied on top of the command line data. For soft-quota just prepend "soft-" to the quota name. Use sub-functions for building and analyzing the quota part of the migration stream, as they will be reused for per-domain quotas. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- V2: - add macros for soft-quota name prefix and its length (Anthony Perard) - don't allow disabled quota in parse_quota_name() (Anthony Perard) - rename "len" to "rec_len" in dump_state_glb_quota() (Anthony Perard) - rename build_quota_data() parameter "name" to "names_buf" (Anthony Perard) - let get_quota_size() start with len 0 (Anthony Perard) --- tools/xenstored/domain.c | 132 +++++++++++++++++++++++++++++++++++++++ tools/xenstored/domain.h | 2 + tools/xenstored/lu.c | 6 ++ 3 files changed, 140 insertions(+) diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 4e696a81a8..cfc8fd0cb4 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -107,6 +107,9 @@ struct quota quotas[ACC_N] =3D { [ACC_NODESZ] =3D { .val =3D { 2048, Q_VAL_DISABLED }, }, }; =20 +#define SOFT_PREFIX "soft-" +#define SOFT_PREFIX_LEN (sizeof(SOFT_PREFIX) - 1) + typedef int32_t wrl_creditt; =20 struct domain @@ -1363,6 +1366,29 @@ int do_set_feature(const void *ctx, struct connectio= n *conn, return 0; } =20 +static bool parse_quota_name(const char *name, unsigned int *qidx, + unsigned int *idx) +{ + unsigned int q; + + if (strncmp(name, SOFT_PREFIX, SOFT_PREFIX_LEN)) { + *idx =3D Q_IDX_HARD; + } else { + *idx =3D Q_IDX_SOFT; + name +=3D SOFT_PREFIX_LEN; + } + for (q =3D 0; q < ACC_N; q++) { + if (quota_adm[q].name && !strcmp(quota_adm[q].name, name)) { + if (quotas[q].val[*idx] =3D=3D Q_VAL_DISABLED) + return true; + *qidx =3D q; + return false; + } + } + + return true; +} + static int close_xgt_handle(void *_handle) { xengnttab_close(*(xengnttab_handle **)_handle); @@ -2032,6 +2058,64 @@ void read_state_connection(const void *ctx, const vo= id *state) } } =20 +/* Returns number of quota and adds length of quota names to *len. */ +static unsigned int get_quota_size(struct quota *quota, unsigned int *len) +{ + unsigned int q; + unsigned int n =3D 0; + + *len =3D 0; + for (q =3D 0; q < ACC_N; q++) { + if (!quota_adm[q].name) + continue; + if (quota[q].val[Q_IDX_HARD] !=3D Q_VAL_DISABLED) { + n++; + *len +=3D strlen(quota_adm[q].name) + 1; + } + if (quota[q].val[Q_IDX_SOFT] !=3D Q_VAL_DISABLED) { + n++; + *len +=3D strlen(quota_adm[q].name) + SOFT_PREFIX_LEN + 1; + } + } + + return n; +} + +static void build_quota_data(struct quota *quota, uint32_t *val, + char *names_buf) +{ + unsigned int q; + unsigned int n =3D 0; + + for (q =3D 0; q < ACC_N; q++) { + if (!quota_adm[q].name) + continue; + if (quota[q].val[Q_IDX_HARD] !=3D Q_VAL_DISABLED) { + val[n++] =3D quota[q].val[Q_IDX_HARD]; + strcpy(names_buf, quota_adm[q].name); + names_buf +=3D strlen(names_buf) + 1; + } + if (quota[q].val[Q_IDX_SOFT] !=3D Q_VAL_DISABLED) { + val[n++] =3D quota[q].val[Q_IDX_SOFT]; + strcpy(names_buf, SOFT_PREFIX); + strcpy(names_buf + SOFT_PREFIX_LEN, quota_adm[q].name); + names_buf +=3D strlen(names_buf) + 1; + } + } +} + +static void parse_quota_data(const uint32_t *val, const char *name, + unsigned int n, struct quota *quota) +{ + unsigned int i, q, idx; + + for (i =3D 0; i < n; i++) { + if (!parse_quota_name(name, &q, &idx)) + quota[q].val[idx] =3D val[i]; + name +=3D strlen(name) + 1; + } +} + static int dump_state_domain(const void *k, void *v, void *arg) { struct domain *domain =3D v; @@ -2080,6 +2164,54 @@ void read_state_domain(const void *ctx, const void *= state, unsigned int version) domain->features =3D sd->features; } =20 +const char *dump_state_glb_quota(FILE *fp) +{ + struct xs_state_record_header *head; + struct xs_state_glb_quota *glb; + void *record; + unsigned int n_quota; + unsigned int rec_len; + size_t ret; + + n_quota =3D get_quota_size(quotas, &rec_len); + rec_len +=3D n_quota * sizeof(glb->quota_val[0]); + rec_len +=3D sizeof(*glb); + rec_len =3D ROUNDUP(rec_len, 3); + + record =3D talloc_size(NULL, rec_len + sizeof(*head)); + if (!record) + return "Dump global quota allocation error"; + + head =3D record; + head->type =3D XS_STATE_TYPE_GLB_QUOTA; + head->length =3D rec_len; + + glb =3D (struct xs_state_glb_quota *)(head + 1); + glb->n_dom_quota =3D n_quota; + glb->n_glob_quota =3D 0; + + build_quota_data(quotas, glb->quota_val, + (char *)(glb->quota_val + n_quota)); + + ret =3D fwrite(record, rec_len + sizeof(*head), 1, fp); + + talloc_free(record); + + if (ret !=3D 1 || dump_state_align(fp)) + return "Dump global quota error"; + + return NULL; +} + +void read_state_glb_quota(const void *ctx, const void *state) +{ + const struct xs_state_glb_quota *glb =3D state; + unsigned int n_quota =3D glb->n_dom_quota + glb->n_glob_quota; + const char *name =3D (const char *)(glb->quota_val + n_quota); + + parse_quota_data(glb->quota_val, name, n_quota, quotas); +} + struct domain_acc { unsigned int domid; int nodes; diff --git a/tools/xenstored/domain.h b/tools/xenstored/domain.h index 3bedadb477..8f23a82854 100644 --- a/tools/xenstored/domain.h +++ b/tools/xenstored/domain.h @@ -172,10 +172,12 @@ void wrl_apply_debit_trans_commit(struct connection *= conn); =20 const char *dump_state_connections(FILE *fp); const char *dump_state_domains(FILE *fp); +const char *dump_state_glb_quota(FILE *fp); =20 void read_state_connection(const void *ctx, const void *state); void read_state_domain(const void *ctx, const void *state, unsigned int version); +void read_state_glb_quota(const void *ctx, const void *state); =20 struct hashtable *domain_check_acc_init(void); void domain_check_acc_add(const struct node *node, struct hashtable *domai= ns); diff --git a/tools/xenstored/lu.c b/tools/xenstored/lu.c index fa8395eb1e..eaffdbc69e 100644 --- a/tools/xenstored/lu.c +++ b/tools/xenstored/lu.c @@ -192,6 +192,9 @@ void lu_read_state(void) case XS_STATE_TYPE_DOMAIN: read_state_domain(ctx, state.buf, version); break; + case XS_STATE_TYPE_GLB_QUOTA: + read_state_glb_quota(ctx, state.buf); + break; default: xprintf("live-update: unknown state record %08x\n", head.type); @@ -319,6 +322,9 @@ static const char *lu_dump_state(const void *ctx, struc= t connection *conn) } =20 ret =3D dump_state_global(fp); + if (ret) + goto out; + ret =3D dump_state_glb_quota(fp); if (ret) goto out; ret =3D dump_state_connections(fp); --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774018946; cv=none; d=zohomail.com; s=zohoarc; b=Hm+0c7RfRdbovkQnPDgeTttdchp/GsS0DO+X3fXJMTdN4vKUOLIB10zLmW7xeN/PtpTIQ8VwodwZTAyLxbqEdUfH4u+1EnylDbUNjNoHswp9g7uZV0h/XHWuYuS7DWGO5gDYua55kyCFpTLvtmyOj0gDtiOafqzpyRH+ojW96YY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774018946; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JqiRC8vY/BabN/ScKXSBNzHtV8BG2Sr2nwnaVeRBWB4=; b=PmeUG9nc62m9Rak+kuAdRucUQuSC5Dent8370wSMuAWXpdGAxi47tZ8OsJz7tPKQWrQYzOsoDUp3ShmY6noDuV/7DpE1qbY/fcOKFCi4iDewW5voAXRuQOQNT9LzTFKXDHUuBSakD60l87uUS4FlxQ+X/cIaU9pmxv29QANswBM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774018946077911.209472757707; Fri, 20 Mar 2026 08:02:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258105.1552303 (Exim 4.92) (envelope-from ) id 1w3bML-0003Ao-Sa; Fri, 20 Mar 2026 15:01:57 +0000 Received: by outflank-mailman (output) from mailman id 1258105.1552303; Fri, 20 Mar 2026 15:01:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bML-0003Af-NV; Fri, 20 Mar 2026 15:01:57 +0000 Received: by outflank-mailman (input) for mailman id 1258105; Fri, 20 Mar 2026 15:01:56 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMK-0001Ve-Sz for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:01:56 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id bcaca997-246d-11f1-b164-2bf370ae4941; Fri, 20 Mar 2026 16:01:56 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B637D4D27B; Fri, 20 Mar 2026 15:01:54 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 948E942866; Fri, 20 Mar 2026 15:01:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8GkuI2JhvWnZXAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:01:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bcaca997-246d-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018915; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JqiRC8vY/BabN/ScKXSBNzHtV8BG2Sr2nwnaVeRBWB4=; b=E1bB3zzQ9LYXvcwwL0yv+0OWTBTjjskmRHpH6qF5xj5O5qhY/gb4Q2tcMsWo9j1nuyBDi7 eNHLAnucRw6g7JGjPdY4UKH8OkVF5KhzpMwrxQiacPIGifBOgLCwEg/2y1QQNKRRnlUb/r /2HkFi1LzV0RO49bRHNiKF1hJmg7Jj0= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=KM6joA7O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018914; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JqiRC8vY/BabN/ScKXSBNzHtV8BG2Sr2nwnaVeRBWB4=; b=KM6joA7OitlDGMXG+C0o6AK8mDsKWfk11xwGvlgM06RWH2LQPnNPKROxxOXc48wgvngYYL zo5aHOUYFOjX6pq/iaYDjtOYQZmBqo8piUcz3nocJHpEMHcFLR0KOvpB8IhM+o/HAnf7cy UMKop0m7iI4zoeztaaHUOzo1Qh09MWA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v2 06/12] tools/xenstored: split acc[] array in struct domain Date: Fri, 20 Mar 2026 16:01:14 +0100 Message-ID: <20260320150120.874878-7-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[vates.tech:email,suse.com:dkim,suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Queue-Id: B637D4D27B X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1774018947214154100 Content-Type: text/plain; charset="utf-8" Prepare using per-domain quota by splitting the acc[] array in struct domain into an array with the current accounting data, and an array of type struct quota for the per-domain quota and the seen max value of the domain. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- tools/xenstored/domain.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index cfc8fd0cb4..b82f2d5167 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -143,10 +143,8 @@ struct domain bool introduced; =20 /* Accounting data for this domain. */ - struct acc { - unsigned int val; - unsigned int max; - } acc[ACC_N]; + unsigned int acc_val[ACC_N]; + struct quota acc[ACC_N]; =20 /* Memory quota data for this domain. */ bool soft_quota_reported; @@ -413,7 +411,7 @@ bool domain_quota_add_exceeds(struct domain *d, enum ac= citem what, int add) if (add < 0 || !d) return false; =20 - return domain_quota_val_exceeds(d, what, d->acc[what].val + add); + return domain_quota_val_exceeds(d, what, d->acc_val[what] + add); } =20 static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) @@ -585,7 +583,7 @@ static int domain_tree_remove_sub(const void *ctx, stru= ct connection *conn, ret =3D WALK_TREE_SKIP_CHILDREN; } =20 - return domain->acc[ACC_NODES].val ? ret : WALK_TREE_SUCCESS_STOP; + return domain->acc_val[ACC_NODES] ? ret : WALK_TREE_SUCCESS_STOP; } =20 static void domain_tree_remove(struct domain *domain) @@ -593,7 +591,7 @@ static void domain_tree_remove(struct domain *domain) int ret; struct walk_funcs walkfuncs =3D { .enter =3D domain_tree_remove_sub }; =20 - if (domain->acc[ACC_NODES].val) { + if (domain->acc_val[ACC_NODES]) { ret =3D walk_node_tree(domain, NULL, "/", &walkfuncs, domain); if (ret =3D=3D WALK_TREE_ERROR_STOP) syslog(LOG_ERR, @@ -789,7 +787,7 @@ int domain_get_quota(const void *ctx, struct connection= *conn, continue; resp =3D talloc_asprintf_append(resp, "%-17s: %8u (max %8u)\n", quota_adm[i].name, - d->acc[i].val, d->acc[i].max); + d->acc_val[i], d->acc[i].max); if (!resp) return ENOMEM; } @@ -1673,10 +1671,10 @@ static int domain_acc_add_valid(struct domain *d, e= num accitem what, int add) { unsigned int val; =20 - assert(what < ARRAY_SIZE(d->acc)); + assert(what < ARRAY_SIZE(d->acc_val)); =20 - if ((add < 0 && -add > d->acc[what].val) || - (add > 0 && (INT_MAX - d->acc[what].val) < add)) { + if ((add < 0 && -add > d->acc_val[what]) || + (add > 0 && (INT_MAX - d->acc_val[what]) < add)) { /* * In a transaction when a node is being added/removed AND the * same node has been added/removed outside the transaction in @@ -1687,7 +1685,7 @@ static int domain_acc_add_valid(struct domain *d, enu= m accitem what, int add) return (add < 0) ? 0 : INT_MAX; } =20 - val =3D d->acc[what].val + add; + val =3D d->acc_val[what] + add; domain_acc_valid_max(d, what, val); =20 return val; @@ -1746,10 +1744,10 @@ static int domain_acc_add(struct connection *conn, = unsigned int domid, } =20 trace_acc("global change domid %u: what=3D%u %u add %d\n", domid, what, - d->acc[what].val, add); - d->acc[what].val =3D domain_acc_add_valid(d, what, add); + d->acc_val[what], add); + d->acc_val[what] =3D domain_acc_add_valid(d, what, add); =20 - return d->acc[what].val; + return d->acc_val[what]; } =20 void acc_drop(struct connection *conn) @@ -1793,7 +1791,7 @@ static int domain_reset_global_acc_sub(const void *k,= void *v, void *arg) unsigned int i; =20 for (i =3D 0; i < ACC_N; i++) - d->acc[i].max =3D d->acc[i].val; + d->acc[i].max =3D d->acc_val[i]; =20 return 0; } @@ -2233,7 +2231,7 @@ static int domain_check_acc_init_sub(const void *k, v= oid *v, void *arg) * If everything is correct incrementing the value for each node will * result in dom->nodes being 0 at the end. */ - dom->nodes =3D -d->acc[ACC_NODES].val; + dom->nodes =3D -d->acc_val[ACC_NODES]; =20 if (hashtable_add(domains, &dom->domid, dom)) { talloc_free(dom); @@ -2288,7 +2286,7 @@ static int domain_check_acc_cb(const void *k, void *v= , void *arg) if (!d) return 0; =20 - d->acc[ACC_NODES].val +=3D dom->nodes; + d->acc_val[ACC_NODES] +=3D dom->nodes; =20 return 0; } --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774018946; cv=none; d=zohomail.com; s=zohoarc; b=GREg3yDkRiMs8zQvjADI4CQUzKej3ovLemN2GxTj7Rnvk1MtHRfpM/fjh3ag6TRuiMEvazl0eRg+cezKlCcrIxuLmxK1GyXx2PYYt5boN8xXtFs6qyXN6JqF517FgiDkih4jP1EcXTL9FjEow8jhJb6nq7PomHHVZ3sbm+8g0vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774018946; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=R+PpHjFLzvQIrf2KVCkmF/XhxpN/XcwoIQUr9KmYFoI=; b=igEGeAI0IOlggYAH4LUYFEtq147AM7UosLIj41a+nxSJ2tqRn11w35enzUuGN4aqlxg+5IxJuQfYzB6tMoTSXZD5tg7rd2ynXn0cHuld+uQ91j1b++hFXyZJzQKbJfkJz19LsnMenDtL4FZmh20yNCYDueb8ga9I5eWKN7gpyXk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 177401894691518.258106986397934; Fri, 20 Mar 2026 08:02:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258112.1552311 (Exim 4.92) (envelope-from ) id 1w3bMW-0003iU-84; Fri, 20 Mar 2026 15:02:08 +0000 Received: by outflank-mailman (output) from mailman id 1258112.1552311; Fri, 20 Mar 2026 15:02:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMW-0003iI-4c; Fri, 20 Mar 2026 15:02:08 +0000 Received: by outflank-mailman (input) for mailman id 1258112; Fri, 20 Mar 2026 15:02:06 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMU-0001ko-8s for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:02:06 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c0859742-246d-11f1-9ccf-f158ae23cfc8; Fri, 20 Mar 2026 16:02:02 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2D76A4D27B; Fri, 20 Mar 2026 15:02:00 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0D3EF42866; Fri, 20 Mar 2026 15:02:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id /qksAmhhvWneXAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:02:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c0859742-246d-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018922; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R+PpHjFLzvQIrf2KVCkmF/XhxpN/XcwoIQUr9KmYFoI=; b=KOvbaB3/47LkpwEa0g8TBdgM8H2CK5iLpCFU8NDRvvyvpRfg2v20GO5UNslIn6e9Lvstuf DAWr2KkK3AF+mWQCKrpeSwLh3haqLt3IzsJzVAugaAIokFFn1bSUme1PZhyqYwCc3ztbFy kMuQPWkbBw6JjeVnkFv/XLqwTgJcTIE= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018920; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R+PpHjFLzvQIrf2KVCkmF/XhxpN/XcwoIQUr9KmYFoI=; b=EUb/g56efp1Yf5qeMEHjfrDKfGpmopQp0grGgajiCZG26XH05kKKOZaUZZD73DCEFfiqyi oAg7v+SU6ez7b7U3XkFtw0Ie1eNQLUieFrJu97ix/SzZGnjT7wTAAy49ND/WvKCrOtGQwh m4oZuXitluJ0EXPZVM2wbufGDBf1hgA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v2 07/12] tools/xenstored: use per-domain quota settings Date: Fri, 20 Mar 2026 16:01:15 +0100 Message-ID: <20260320150120.874878-8-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.com:mid,suse.com:email,vates.tech:email] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1774018947813158500 Content-Type: text/plain; charset="utf-8" Initialize the per-domain quota values with the global ones at domain introduction. Use the per-domain quota settings when checking for current values to exceed the quota. Add per-domain quota support to live update. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- V2: - fix commit message (Anthony Perard) - rename "len" to "rec_len" in dump_state_domain() (Anthony Perard) --- tools/xenstored/domain.c | 60 ++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index b82f2d5167..7a8d285e64 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -392,6 +392,9 @@ void wrl_apply_debit_trans_commit(struct connection *co= nn) =20 static unsigned int domain_get_soft_quota(struct domain *d, enum accitem w= hat) { + if (d && d->acc[what].val[Q_IDX_SOFT] !=3D Q_VAL_DISABLED) + return d->acc[what].val[Q_IDX_SOFT]; + return quotas[what].val[Q_IDX_SOFT]; } =20 @@ -400,6 +403,9 @@ static bool domain_quota_val_exceeds(struct domain *d, = enum accitem what, { unsigned int quota =3D quotas[what].val[Q_IDX_HARD]; =20 + if (d->acc[what].val[Q_IDX_HARD] !=3D Q_VAL_DISABLED) + quota =3D d->acc[what].val[Q_IDX_HARD]; + if (!quota || !domid_is_unprivileged(d->domid)) return false; =20 @@ -824,6 +830,7 @@ static struct domain *alloc_domain(const void *context,= unsigned int domid, uint64_t unique_id) { struct domain *domain; + unsigned int q; =20 domain =3D talloc_zero(context, struct domain); if (!domain) { @@ -837,6 +844,11 @@ static struct domain *alloc_domain(const void *context= , unsigned int domid, domain->introduced =3D false; domain->features =3D XENSTORE_FEATURES; =20 + for (q =3D 0; q < ACC_N; q++) { + domain->acc[q].val[Q_IDX_HARD] =3D quotas[q].val[Q_IDX_HARD]; + domain->acc[q].val[Q_IDX_SOFT] =3D quotas[q].val[Q_IDX_SOFT]; + } + if (hashtable_add(domhash, &domain->domid, domain)) { talloc_free(domain); errno =3D ENOMEM; @@ -2118,25 +2130,39 @@ static int dump_state_domain(const void *k, void *v= , void *arg) { struct domain *domain =3D v; FILE *fp =3D arg; - struct xs_state_domain sd; - struct xs_state_record_header head; - - head.type =3D XS_STATE_TYPE_DOMAIN; - head.length =3D sizeof(sd); - memset(&sd, 0, sizeof(sd)); - sd.domain_id =3D domain->domid; + struct xs_state_domain *sd; + struct xs_state_record_header *head; + void *record; + unsigned int n_quota; + unsigned int rec_len; + size_t ret; =20 - if (lu_status->version > 1) - sd.features =3D domain->features; + n_quota =3D get_quota_size(domain->acc, &rec_len); + rec_len +=3D n_quota * sizeof(sd->quota_val[0]); + rec_len +=3D sizeof(*sd); + rec_len =3D ROUNDUP(rec_len, 3); =20 - if (fwrite(&head, sizeof(head), 1, fp) !=3D 1) - return 1; - if (fwrite(&sd, sizeof(sd), 1, fp) !=3D 1) - return 1; - if (dump_state_align(fp)) + record =3D talloc_size(NULL, rec_len + sizeof(*head)); + if (!record) return 1; =20 - return 0; + head =3D record; + head->type =3D XS_STATE_TYPE_DOMAIN; + head->length =3D rec_len; + + sd =3D (struct xs_state_domain *)(head + 1); + sd->domain_id =3D domain->domid; + sd->n_quota =3D n_quota; + sd->features =3D (lu_status->version > 1) ? domain->features : 0; + + build_quota_data(domain->acc, sd->quota_val, + (char *)(sd->quota_val + n_quota)); + + ret =3D fwrite(record, rec_len + sizeof(*head), 1, fp); + + talloc_free(record); + + return (ret !=3D 1 || dump_state_align(fp)) ? 1 : 0; } =20 const char *dump_state_domains(FILE *fp) @@ -2153,6 +2179,8 @@ void read_state_domain(const void *ctx, const void *s= tate, unsigned int version) { const struct xs_state_domain *sd =3D state; struct domain *domain; + unsigned int n_quota =3D sd->n_quota; + const char *name =3D (const char *)(sd->quota_val + n_quota); =20 domain =3D find_domain_struct(sd->domain_id); if (!domain) @@ -2160,6 +2188,8 @@ void read_state_domain(const void *ctx, const void *s= tate, unsigned int version) =20 if (version > 1) domain->features =3D sd->features; + + parse_quota_data(sd->quota_val, name, n_quota, domain->acc); } =20 const char *dump_state_glb_quota(FILE *fp) --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774019312; cv=none; d=zohomail.com; s=zohoarc; b=oD5yds/1artlLoZHCrakkdnBOSzRRq0eT/wzfOAD8KBp8Mq7fXGv0yD6PtT3k9R0WvlA+MtbA9fVj/yvUElE+z/6tAzIM7HYNsQUazRSyJp1wbbIhv9zKIOHjpwveBmy/cSzeo2fZDFSdDnbyocaoTSvwh3zKyBHjAwadc8vDIQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774019312; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1FYqa2/aDourOwOzPQpClM0FHHXiPvq6a2dggyIoDDM=; b=cKhwPNnTY8FZYATIMgWSH9CxSBiJl7SjppO9p84TE6WXPcwdW/n2Fi+0yaP2kqlnrs381dArjjG+qLlfoseCsYn+s8z7wQzKFfhPbpUA1QYqqYoEkGd1czeknh9/lkcIUULhlCTTAl2yscnC+Bb1/HslOCbxDzhmN7944SmTCWw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774019312571662.9090812179644; Fri, 20 Mar 2026 08:08:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258182.1552347 (Exim 4.92) (envelope-from ) id 1w3bSS-0007Fr-JG; Fri, 20 Mar 2026 15:08:16 +0000 Received: by outflank-mailman (output) from mailman id 1258182.1552347; Fri, 20 Mar 2026 15:08:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bSS-0007Fk-FN; Fri, 20 Mar 2026 15:08:16 +0000 Received: by outflank-mailman (input) for mailman id 1258182; Fri, 20 Mar 2026 15:08:15 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMX-0001Ve-1c for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:02:09 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c3e99463-246d-11f1-b164-2bf370ae4941; Fri, 20 Mar 2026 16:02:08 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 95F194D27B; Fri, 20 Mar 2026 15:02:05 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7554842866; Fri, 20 Mar 2026 15:02:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WniTG21hvWnjXAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:02:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c3e99463-246d-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018925; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1FYqa2/aDourOwOzPQpClM0FHHXiPvq6a2dggyIoDDM=; b=GBtKCSZwN71iawlNf2pdCyt1/RIcOJvcvlCzBXxiUw9lJ3UlgYmfNyl0TpI9JaBza2xR3j U1xys8D+qc99q0qW6tZAJkGgtHP6N1vAwlzKluHiAjEcQIW0hYZsydiSupsejnib/pRHOO UcDO6GqdG3/Nosj9LHy+qMiFcxLMPeg= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018925; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1FYqa2/aDourOwOzPQpClM0FHHXiPvq6a2dggyIoDDM=; b=GBtKCSZwN71iawlNf2pdCyt1/RIcOJvcvlCzBXxiUw9lJ3UlgYmfNyl0TpI9JaBza2xR3j U1xys8D+qc99q0qW6tZAJkGgtHP6N1vAwlzKluHiAjEcQIW0hYZsydiSupsejnib/pRHOO UcDO6GqdG3/Nosj9LHy+qMiFcxLMPeg= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v2 08/12] tools/xenstored: implement the GET/SET_QUOTA commands Date: Fri, 20 Mar 2026 16:01:16 +0100 Message-ID: <20260320150120.874878-9-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.com:mid,suse.com:email]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_THREE(0.00)[4]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1774019315223154100 Content-Type: text/plain; charset="utf-8" Add the implementation of the GET_QUOTA and SET_QUOTA wire commands. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- V2: - refuse quota value Q_VAL_DISABLED (Anthony Perard) - use talloc_strdup() (Anthony Perard) - drop comments in domain.h (Anthony Perard) --- tools/xenstored/core.c | 4 ++ tools/xenstored/domain.c | 111 +++++++++++++++++++++++++++++++++++++++ tools/xenstored/domain.h | 5 ++ 3 files changed, 120 insertions(+) diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index dc63c97658..4786a2a82e 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2035,6 +2035,10 @@ static struct { { "GET_FEATURE", do_get_feature, XS_FLAG_PRIV }, [XS_SET_FEATURE] =3D { "SET_FEATURE", do_set_feature, XS_FLAG_PRIV }, + [XS_GET_QUOTA] =3D + { "GET_QUOTA", do_get_quota, XS_FLAG_PRIV }, + [XS_SET_QUOTA] =3D + { "SET_QUOTA", do_set_quota, XS_FLAG_PRIV }, }; =20 static const char *sockmsg_string(enum xsd_sockmsg_type type) diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 7a8d285e64..1684f6dee7 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -1399,6 +1399,117 @@ static bool parse_quota_name(const char *name, unsi= gned int *qidx, return true; } =20 +int do_get_quota(const void *ctx, struct connection *conn, + struct buffered_data *in) +{ + const char *vec[2]; + unsigned int n_pars; + unsigned int domid; + unsigned int q; + unsigned int idx; + char *resp; + const char *name; + const struct quota *quota; + const struct domain *domain; + + n_pars =3D get_strings(in, vec, ARRAY_SIZE(vec)); + + if (n_pars > 2) + return EINVAL; + + if (n_pars =3D=3D 0) { + resp =3D talloc_strdup(ctx, ""); + if (!resp) + return ENOMEM; + for (q =3D 0; q < ACC_N; q++) { + if (!quota_adm[q].name) + continue; + if (quotas[q].val[Q_IDX_HARD] !=3D Q_VAL_DISABLED) { + resp =3D talloc_asprintf_append(resp, "%s%s", + *resp ? " " : "", quota_adm[q].name); + if (!resp) + return ENOMEM; + } + if (quotas[q].val[Q_IDX_SOFT] !=3D Q_VAL_DISABLED) { + resp =3D talloc_asprintf_append(resp, "%s%s%s", + *resp ? " " : "", SOFT_PREFIX, + quota_adm[q].name); + if (!resp) + return ENOMEM; + } + } + } else { + if (n_pars =3D=3D 1) { + quota =3D quotas; + name =3D vec[0]; + } else { + domid =3D parse_domid(vec[0]); + if (errno) + return errno; + domain =3D find_or_alloc_existing_domain(domid); + if (!domain) + return ENOENT; + quota =3D domain->acc; + name =3D vec[1]; + } + + if (parse_quota_name(name, &q, &idx)) + return EINVAL; + + resp =3D talloc_asprintf(ctx, "%u", quota[q].val[idx]); + if (!resp) + return ENOMEM; + } + + send_reply(conn, XS_GET_QUOTA, resp, strlen(resp) + 1); + + return 0; +} + +int do_set_quota(const void *ctx, struct connection *conn, + struct buffered_data *in) +{ + const char *vec[3]; + unsigned int n_pars; + unsigned int domid; + unsigned int q; + unsigned int idx; + const char *name; + unsigned int val; + struct quota *quota; + struct domain *domain; + + n_pars =3D get_strings(in, vec, ARRAY_SIZE(vec)); + + if (n_pars < 2 || n_pars > 3) + return EINVAL; + + if (n_pars =3D=3D 2) { + quota =3D quotas; + name =3D vec[0]; + val =3D atoi(vec[1]); + } else { + domid =3D parse_domid(vec[0]); + if (errno) + return errno; + domain =3D find_or_alloc_existing_domain(domid); + if (!domain) + return ENOENT; + quota =3D domain->acc; + name =3D vec[1]; + val =3D atoi(vec[2]); + } + + if (parse_quota_name(name, &q, &idx) || val =3D=3D Q_VAL_DISABLED) + return EINVAL; + + quota[q].val[idx] =3D val; + + send_ack(conn, XS_SET_QUOTA); + + return 0; +} + static int close_xgt_handle(void *_handle) { xengnttab_close(*(xengnttab_handle **)_handle); diff --git a/tools/xenstored/domain.h b/tools/xenstored/domain.h index 8f23a82854..ca38b5e0ea 100644 --- a/tools/xenstored/domain.h +++ b/tools/xenstored/domain.h @@ -93,6 +93,11 @@ int do_get_feature(const void *ctx, struct connection *c= onn, int do_set_feature(const void *ctx, struct connection *conn, struct buffered_data *in); =20 +int do_get_quota(const void *ctx, struct connection *conn, + struct buffered_data *in); +int do_set_quota(const void *ctx, struct connection *conn, + struct buffered_data *in); + void domain_early_init(void); void domain_init(int evtfd); void init_domains(bool live_update); --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774019508; cv=none; d=zohomail.com; s=zohoarc; b=EmwX5rrSBerKhYDZYO9m50xOvqwm+AyYSNrUQJr68MO5VX7krpWr4sIaDmlDyMmhbj3khIZywh6SmGu6zKu6/0HhJmDFLvYbcVcDZaD2g/9Q1wPe/bKyiQZYw7ak6MZrJVHmMsnNIDMPwkIBnlMItZcfhzscrZGL29DkL88WV78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774019508; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yEuehUlwv5fMYrq9vtoirIlozvH3dEV269XfkzYgNss=; b=BoMNgxvQPl5ZiBQJM02BdhMHW2uqQidmfGd3ZfKnn2uAqTdAQ/CtR/S2suCoCASTNGq7KfbJ0QCXIpTpIIjFnDBvdvSVnByeHS9z8WXbs5lqA+zdc6vqlLbNxzdP3i+I8C84zATnn0I2AOrJBx2L46m5JTz5HA6t35aK0FNX94I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774019508658391.8303505261898; Fri, 20 Mar 2026 08:11:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258213.1552365 (Exim 4.92) (envelope-from ) id 1w3bVd-0001Bb-6e; Fri, 20 Mar 2026 15:11:33 +0000 Received: by outflank-mailman (output) from mailman id 1258213.1552365; Fri, 20 Mar 2026 15:11:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bVd-0001BU-3b; Fri, 20 Mar 2026 15:11:33 +0000 Received: by outflank-mailman (input) for mailman id 1258213; Fri, 20 Mar 2026 15:11:32 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMl-0001ko-Gr for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:02:23 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cbde84f1-246d-11f1-9ccf-f158ae23cfc8; Fri, 20 Mar 2026 16:02:21 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0E3375BDF1; Fri, 20 Mar 2026 15:02:11 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DCB2F42866; Fri, 20 Mar 2026 15:02:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ll/PNHJhvWnpXAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:02:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cbde84f1-246d-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018935; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yEuehUlwv5fMYrq9vtoirIlozvH3dEV269XfkzYgNss=; b=T6DmaqxNH0Blb5cy10dYluQkE/UVVbMDbkyOC1lKBJUWBln5GrMVqMIEm9tb8VcXHYz2Xp 2cPIjSGlYyIQaGWUnYZ3sxzxWaXfADO7K+aqvBGoSAoI5PR8Qz4eWfJoELJw2z19Qg4iOi Rqee8A/RHXEanvQ3WTk18amsR2Aueso= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=qk+UQdiW DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018931; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yEuehUlwv5fMYrq9vtoirIlozvH3dEV269XfkzYgNss=; b=qk+UQdiWmj+Z6a59Nl9lfH2OfrCbGM/lZHDhziABoik4HjNjfuWCwagut55CdiHpviqeCS 2tMNFZuL+mSUotU9EuYgU2aB/sOEBbcKU11c5xj6wrnV7IHu8Bt50ggAfEKgviwbkl9bCs VH/mqJA7DE+uEnMzO08Yg+0VF2uHjS4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Nick Rosbrook , George Dunlap , Anthony PERARD Subject: [PATCH v2 09/12] tools/libxl: add functions for retrieving and setting xenstore quota Date: Fri, 20 Mar 2026 16:01:17 +0100 Message-ID: <20260320150120.874878-10-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:dkim,suse.com:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 0E3375BDF1 X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1774019509421158500 Content-Type: text/plain; charset="utf-8" Add some functions allowing to retrieve and set Xenstore quota (either global or domain specific). Signed-off-by: Juergen Gross Acked-by: Nick Rosbrook # golang stuff Reviewed-by: Anthony PERARD --- V2: - rename libxl functions to use "xs_quota" instead of "xsquota" (Anthony Perard) - rename the libxl_xs_quota_*_get() "q" parameter to "q_out" (Anthony Perard) - rename the struct xs_quota_set to xs_quota_list (Anthony Perard) - several style changes (Anthony Perard) --- tools/golang/xenlight/helpers.gen.go | 78 ++++++++++++++++++ tools/golang/xenlight/types.gen.go | 9 +++ tools/include/libxl.h | 20 +++++ tools/libs/light/Makefile | 1 + tools/libs/light/libxl_types.idl | 9 +++ tools/libs/light/libxl_xsquota.c | 116 +++++++++++++++++++++++++++ 6 files changed, 233 insertions(+) create mode 100644 tools/libs/light/libxl_xsquota.c diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index 8909fe8a1b..767b9e45f5 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -998,6 +998,84 @@ xc.policy =3D C.libxl_rdm_reserve_policy(x.Policy) return nil } =20 +// NewXsQuotaItem returns an instance of XsQuotaItem initialized with defa= ults. +func NewXsQuotaItem() (*XsQuotaItem, error) { +var ( +x XsQuotaItem +xc C.libxl_xs_quota_item) + +C.libxl_xs_quota_item_init(&xc) +defer C.libxl_xs_quota_item_dispose(&xc) + +if err :=3D x.fromC(&xc); err !=3D nil { +return nil, err } + +return &x, nil} + +func (x *XsQuotaItem) fromC(xc *C.libxl_xs_quota_item) error { + x.Name =3D C.GoString(xc.name) +x.Val =3D uint32(xc.val) + + return nil} + +func (x *XsQuotaItem) toC(xc *C.libxl_xs_quota_item) (err error){defer fun= c(){ +if err !=3D nil{ +C.libxl_xs_quota_item_dispose(xc)} +}() + +if x.Name !=3D "" { +xc.name =3D C.CString(x.Name)} +xc.val =3D C.uint32_t(x.Val) + + return nil + } + +// NewXsQuotaList returns an instance of XsQuotaList initialized with defa= ults. +func NewXsQuotaList() (*XsQuotaList, error) { +var ( +x XsQuotaList +xc C.libxl_xs_quota_list) + +C.libxl_xs_quota_list_init(&xc) +defer C.libxl_xs_quota_list_dispose(&xc) + +if err :=3D x.fromC(&xc); err !=3D nil { +return nil, err } + +return &x, nil} + +func (x *XsQuotaList) fromC(xc *C.libxl_xs_quota_list) error { + x.Quota =3D nil +if n :=3D int(xc.num_quota); n > 0 { +cQuota :=3D (*[1<<28]C.libxl_xs_quota_item)(unsafe.Pointer(xc.quota))[:n:n] +x.Quota =3D make([]XsQuotaItem, n) +for i, v :=3D range cQuota { +if err :=3D x.Quota[i].fromC(&v); err !=3D nil { +return fmt.Errorf("converting field Quota: %v", err) } +} +} + + return nil} + +func (x *XsQuotaList) toC(xc *C.libxl_xs_quota_list) (err error){defer fun= c(){ +if err !=3D nil{ +C.libxl_xs_quota_list_dispose(xc)} +}() + +if numQuota :=3D len(x.Quota); numQuota > 0 { +xc.quota =3D (*C.libxl_xs_quota_item)(C.malloc(C.ulong(numQuota)*C.sizeof_= libxl_xs_quota_item)) +xc.num_quota =3D C.int(numQuota) +cQuota :=3D (*[1<<28]C.libxl_xs_quota_item)(unsafe.Pointer(xc.quota))[:num= Quota:numQuota] +for i,v :=3D range x.Quota { +if err :=3D v.toC(&cQuota[i]); err !=3D nil { +return fmt.Errorf("converting field Quota: %v", err) +} +} +} + + return nil + } + // NewDomainBuildInfo returns an instance of DomainBuildInfo initialized w= ith defaults. func NewDomainBuildInfo(dtype DomainType) (*DomainBuildInfo, error) { var ( diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index ab9d4ca7b4..8dd610919d 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -543,6 +543,15 @@ Altp2MModeExternal Altp2MMode =3D 2 Altp2MModeLimited Altp2MMode =3D 3 ) =20 +type XsQuotaItem struct { +Name string +Val uint32 +} + +type XsQuotaList struct { +Quota []XsQuotaItem +} + type DomainBuildInfo struct { MaxVcpus int AvailVcpus Bitmap diff --git a/tools/include/libxl.h b/tools/include/libxl.h index bc35e412da..6d2910df34 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1537,6 +1537,18 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, = const libxl_mac *src); */ #define LIBXL_HAVE_XEN_PLATFORM_PCI_BAR_UC =20 +/* + * LIBXL_HAVE_XENSTORE_QUOTA + * + * If this is defined the Xenstore quota related functions + * libxl_xs_quota_global_get() + * libxl_xs_quota_global_set() + * libxl_xs_quota_domain_get() + * libxl_xs_quota_domain_set() + * are available. + */ +#define LIBXL_HAVE_XENSTORE_QUOTA + typedef char **libxl_string_list; void libxl_string_list_dispose(libxl_string_list *sl); int libxl_string_list_length(const libxl_string_list *sl); @@ -3011,6 +3023,14 @@ static inline int libxl_qemu_monitor_command_0x04120= 0(libxl_ctx *ctx, #define libxl_qemu_monitor_command libxl_qemu_monitor_command_0x041200 #endif =20 +/* Get/set global and per-domain Xenstore quota. */ +int libxl_xs_quota_global_get(libxl_ctx *ctx, libxl_xs_quota_list *q_out); +int libxl_xs_quota_global_set(libxl_ctx *ctx, libxl_xs_quota_list *q); +int libxl_xs_quota_domain_get(libxl_ctx *ctx, uint32_t domid, + libxl_xs_quota_list *q_out); +int libxl_xs_quota_domain_set(libxl_ctx *ctx, uint32_t domid, + libxl_xs_quota_list *q); + #include =20 /* diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index bc60c46558..ca22a40c6c 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -106,6 +106,7 @@ OBJS-y +=3D libxl_pvcalls.o OBJS-y +=3D libxl_vsnd.o OBJS-y +=3D libxl_vkb.o OBJS-y +=3D libxl_virtio.o +OBJS-y +=3D libxl_xsquota.o OBJS-y +=3D libxl_genid.o OBJS-y +=3D _libxl_types.o OBJS-y +=3D libxl_flask.o diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index d64a573ff3..1a63c8af76 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -574,6 +574,15 @@ libxl_altp2m_mode =3D Enumeration("altp2m_mode", [ (3, "limited"), ], init_val =3D "LIBXL_ALTP2M_MODE_DISABLED") =20 +libxl_xs_quota_item =3D Struct("xs_quota_item", [ + ("name", string), + ("val", uint32), + ]) + +libxl_xs_quota_list =3D Struct("xs_quota_list", [ + ("quota", Array(libxl_xs_quota_item, "num_quota")) + ]) + libxl_domain_build_info =3D Struct("domain_build_info",[ ("max_vcpus", integer), ("avail_vcpus", libxl_bitmap), diff --git a/tools/libs/light/libxl_xsquota.c b/tools/libs/light/libxl_xsqu= ota.c new file mode 100644 index 0000000000..4524442655 --- /dev/null +++ b/tools/libs/light/libxl_xsquota.c @@ -0,0 +1,116 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ + +/* Xenstore quota handling functions. */ + +#include "libxl_internal.h" + +static int get_quota(libxl_ctx *ctx, unsigned int domid, + libxl_xs_quota_list *q_out, + bool (func)(struct xs_handle *h, unsigned int domid, + const char *quota, unsigned int *value)) +{ + const char **names; + unsigned int num, i; + bool ok; + int rc; + GC_INIT(ctx); + + libxl_xs_quota_list_init(q_out); + names =3D xs_get_quota_names(ctx->xsh, &num); + if (!names) { + /* Xenstore quota support is optional! */ + if (errno !=3D ENOSYS) { + libxl_xs_quota_list_dispose(q_out); + rc =3D ERROR_FAIL; + } else { + rc =3D 0; + } + goto out; + } + + q_out->num_quota =3D num; + q_out->quota =3D libxl__calloc(NOGC, num, sizeof(*q_out->quota)); + for (i =3D 0; i < num; i++) { + q_out->quota[i].name =3D libxl__strdup(NOGC, names[i]); + ok =3D func(ctx->xsh, domid, q_out->quota[i].name, &q_out->quota[i= ].val); + if (!ok) { + libxl_xs_quota_list_dispose(q_out); + rc =3D ERROR_FAIL; + goto out; + } + } + + rc =3D 0; + + out: + free(names); + + GC_FREE; + return rc; +} + +static int set_quota(libxl_ctx *ctx, unsigned int domid, libxl_xs_quota_li= st *q, + bool (func)(struct xs_handle *h, unsigned int domid, + const char *quota, unsigned int value)) +{ + unsigned int i; + bool ok; + int rc; + GC_INIT(ctx); + + for (i =3D 0; i < q->num_quota; i++) { + ok =3D func(ctx->xsh, domid, q->quota[i].name, q->quota[i].val); + if (!ok) { + rc =3D ERROR_FAIL; + goto out; + } + } + + rc =3D 0; + + out: + GC_FREE; + return rc; +} + +static bool get_global_quota(struct xs_handle *h, unsigned int domid, + const char *quota, unsigned int *value) +{ + return xs_get_global_quota(h, quota, value); +} + +int libxl_xs_quota_global_get(libxl_ctx *ctx, libxl_xs_quota_list *q_out) +{ + return get_quota(ctx, 0, q_out, get_global_quota); +} + +static bool set_global_quota(struct xs_handle *h, unsigned int domid, + const char *quota, unsigned int value) +{ + return xs_set_global_quota(h, quota, value); +} + +int libxl_xs_quota_global_set(libxl_ctx *ctx, libxl_xs_quota_list *q) +{ + return set_quota(ctx, 0, q, set_global_quota);; +} + +int libxl_xs_quota_domain_get(libxl_ctx *ctx, uint32_t domid, + libxl_xs_quota_list *q_out) +{ + return get_quota(ctx, domid, q_out, xs_get_domain_quota); +} + +int libxl_xs_quota_domain_set(libxl_ctx *ctx, uint32_t domid, + libxl_xs_quota_list *q) +{ + return set_quota(ctx, domid, q, xs_set_domain_quota); +} + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774018967; cv=none; d=zohomail.com; s=zohoarc; b=EyFKly1VBZEXsfC4UcLFyZhJp4dhlD+m9LeAFlPnrAifZZgdDrL9QD8QdsWa7aaf/LpqSDoy8MNyumI1WpeGNQRF9yKZ+V8DJPdvzXxXJfDxt3K3UnUUHMKrOePjLZLP5TbFRTZt1mTt8F+aIjA0tchGAA/qUOnODWu3LGuL31I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774018967; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=N+38mOISGDZ5p4EBE7e3hZ5SrJSwJQ9+PpMenks7NFU=; b=Et7ArxiHx8a0NOHVagBW+jLXldO+QnzpynXMsyXeETYeHOhcXjurTSuUP4JC0q43e+5NlU5Og2ZLbwuqsYMCoH37w3pMYTw+avJU/Um01jNBbE9fdHLVGVv5LR0vScQvaTjNAqBr7W+33+7Kk6WSR/lqMjdR3AZAcjWSkqyOdhM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774018967518730.2936694972783; Fri, 20 Mar 2026 08:02:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258124.1552320 (Exim 4.92) (envelope-from ) id 1w3bMi-0004S7-Ep; Fri, 20 Mar 2026 15:02:20 +0000 Received: by outflank-mailman (output) from mailman id 1258124.1552320; Fri, 20 Mar 2026 15:02:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMi-0004S0-BE; Fri, 20 Mar 2026 15:02:20 +0000 Received: by outflank-mailman (input) for mailman id 1258124; Fri, 20 Mar 2026 15:02:18 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMg-0001ko-D6 for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:02:18 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c8f1a9c6-246d-11f1-9ccf-f158ae23cfc8; Fri, 20 Mar 2026 16:02:16 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7BC415BDF9; Fri, 20 Mar 2026 15:02:16 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 540EA42867; Fri, 20 Mar 2026 15:02:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id eE1xE3hhvWnzXAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:02:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c8f1a9c6-246d-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018936; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N+38mOISGDZ5p4EBE7e3hZ5SrJSwJQ9+PpMenks7NFU=; b=eOEZ7i0/vDm7ZasHeLy0eMGD0xP3Vlot+jn1kIxaqnsrwe9aFsE1uxoMF8jJqyp7R/a8hi 5XFyKGc5DLC6vr0OmsvGBF8nE/doqRngS9Y8+BYk1dsW3JPgcESvGB4PnthEuKlVZtR17l nsC49HzgrskYg1HJ3k4ZaY8dzhrFEBk= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018936; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N+38mOISGDZ5p4EBE7e3hZ5SrJSwJQ9+PpMenks7NFU=; b=eOEZ7i0/vDm7ZasHeLy0eMGD0xP3Vlot+jn1kIxaqnsrwe9aFsE1uxoMF8jJqyp7R/a8hi 5XFyKGc5DLC6vr0OmsvGBF8nE/doqRngS9Y8+BYk1dsW3JPgcESvGB4PnthEuKlVZtR17l nsC49HzgrskYg1HJ3k4ZaY8dzhrFEBk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Nick Rosbrook , George Dunlap , Anthony PERARD Subject: [PATCH v2 10/12] tools/libxl: add support for xenstore quota in domain_config Date: Fri, 20 Mar 2026 16:01:18 +0100 Message-ID: <20260320150120.874878-11-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.com:mid,suse.com:email]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -2.80 X-Spam-Level: X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1774018967812158500 Content-Type: text/plain; charset="utf-8" Add support for xenstore quota in the struct domain_config. Initially it will be used only for migration of a domain. Signed-off-by: Juergen Gross Acked-by: Nick Rosbrook # golang stuff Reviewed-by: Anthony PERARD --- V2: - use LOGED() for error logging (Anthony Perard) - mention additional struct member xenstore_quota in libxl.h (Anthony Perard) --- tools/golang/xenlight/helpers.gen.go | 6 ++++++ tools/golang/xenlight/types.gen.go | 1 + tools/include/libxl.h | 1 + tools/libs/light/libxl_dom.c | 8 ++++++++ tools/libs/light/libxl_domain.c | 11 +++++++++++ tools/libs/light/libxl_types.idl | 1 + 6 files changed, 28 insertions(+) diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index 767b9e45f5..b0c09da910 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1286,6 +1286,9 @@ if err :=3D x.TrapUnmappedAccesses.fromC(&xc.trap_unm= apped_accesses);err !=3D nil { return fmt.Errorf("converting field TrapUnmappedAccesses: %v", err) } x.XenstoreFeatureMask =3D uint32(xc.xenstore_feature_mask) +if err :=3D x.XenstoreQuota.fromC(&xc.xenstore_quota);err !=3D nil { +return fmt.Errorf("converting field XenstoreQuota: %v", err) +} =20 return nil} =20 @@ -1825,6 +1828,9 @@ if err :=3D x.TrapUnmappedAccesses.toC(&xc.trap_unmap= ped_accesses); err !=3D nil { return fmt.Errorf("converting field TrapUnmappedAccesses: %v", err) } xc.xenstore_feature_mask =3D C.uint32_t(x.XenstoreFeatureMask) +if err :=3D x.XenstoreQuota.toC(&xc.xenstore_quota); err !=3D nil { +return fmt.Errorf("converting field XenstoreQuota: %v", err) +} =20 return nil } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index 8dd610919d..e0fd78ec03 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -629,6 +629,7 @@ VmtraceBufKb int Vpmu Defbool TrapUnmappedAccesses Defbool XenstoreFeatureMask uint32 +XenstoreQuota XsQuotaList } =20 type DomainBuildInfoTypeUnion interface { diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 6d2910df34..80e3ec8de9 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1545,6 +1545,7 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, c= onst libxl_mac *src); * libxl_xs_quota_global_set() * libxl_xs_quota_domain_get() * libxl_xs_quota_domain_set() + * and the xenstore_quota member of struct domain_build_info * are available. */ #define LIBXL_HAVE_XENSTORE_QUOTA diff --git a/tools/libs/light/libxl_dom.c b/tools/libs/light/libxl_dom.c index 05ebc69534..4ff5f65f6f 100644 --- a/tools/libs/light/libxl_dom.c +++ b/tools/libs/light/libxl_dom.c @@ -509,6 +509,14 @@ retry_transaction: =20 xs_introduce_domain(ctx->xsh, domid, state->store_mfn, state->store_po= rt); =20 + if (info->xenstore_quota.num_quota) { + rc =3D libxl_xs_quota_domain_set(ctx, domid, &info->xenstore_quota= ); + if (rc) { + LOGED(ERROR, domid, "Failed to set Xenstore quota"); + goto out; + } + } + out: free(vm_path); return rc; diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domai= n.c index 5be47f687f..37fcd92871 100644 --- a/tools/libs/light/libxl_domain.c +++ b/tools/libs/light/libxl_domain.c @@ -2533,6 +2533,17 @@ static void retrieve_domain_configuration_end(libxl_= _egc *egc, } } =20 + /* Xenstore quota */ + { + libxl_xs_quota_list_dispose(&d_config->b_info.xenstore_quota); + rc =3D libxl_xs_quota_domain_get(CTX, domid, + &d_config->b_info.xenstore_quota); + if (rc) { + LOGED(ERROR, domid, "Fail to get xenstore quota"); + goto out; + } + } + /* Devices: disk, nic, vtpm, pcidev etc. */ =20 /* The MERGE macro implements following logic: diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 1a63c8af76..a7893460f0 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -760,6 +760,7 @@ libxl_domain_build_info =3D Struct("domain_build_info",[ ("vpmu", libxl_defbool), ("trap_unmapped_accesses", libxl_defbool), ("xenstore_feature_mask", uint32, {'init_val': '~0U'}), + ("xenstore_quota", libxl_xs_quota_list), =20 ], dir=3DDIR_IN, copy_deprecated_fn=3D"libxl__domain_build_info_copy_deprecated", --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774019275; cv=none; d=zohomail.com; s=zohoarc; b=SF1EfeaFThc6iv5nPbqEV1waq0g1M6MDW/sik4GsgbVx+lBqma+Tmx2j37fFt4/Lzu7cAoD3Vd/kwJEOJ0yYKPTXlugWNZDp6uC6bEsA/Z9bznqy7Ky4eMnyI2l4siyFIQHC4OmwA7ndMy9C3hp/A9x0KKA4yhtWjbW3Kjh2wzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774019275; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YI1ysKQoZ4KtpQt8LrU0cY4zBTnFx8A/2d0JHjXzvmY=; b=Txd9us03mmNIAZLHMDru/lRY5b+xkJ997QAUyJUZxiE1nqxAEUU+5FuWFyim+0qYcmmhDOFDrgTDzral/Z7KqwXpEFJ56gDX7+SQB1nU1LMKS1XYY4UGkrO2TLIR3aHI5xgdUjKsQK4PxcjFV/JeOF/53wIwg17Fj6UescQC5EQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774019275808399.59586646846924; Fri, 20 Mar 2026 08:07:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258162.1552329 (Exim 4.92) (envelope-from ) id 1w3bRi-0006HZ-Vl; Fri, 20 Mar 2026 15:07:30 +0000 Received: by outflank-mailman (output) from mailman id 1258162.1552329; Fri, 20 Mar 2026 15:07:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bRi-0006HS-SG; Fri, 20 Mar 2026 15:07:30 +0000 Received: by outflank-mailman (input) for mailman id 1258162; Fri, 20 Mar 2026 15:07:29 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMp-0001Ve-V4 for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:02:27 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cf05fdfb-246d-11f1-b164-2bf370ae4941; Fri, 20 Mar 2026 16:02:27 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DE87E5BDF3; Fri, 20 Mar 2026 15:02:21 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C33BD42866; Fri, 20 Mar 2026 15:02:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id N6GULn1hvWn5XAAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:02:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cf05fdfb-246d-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018941; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YI1ysKQoZ4KtpQt8LrU0cY4zBTnFx8A/2d0JHjXzvmY=; b=SIE3Wn8GWPLkL9ArQd8k4xcqVXtvyUsC2IkfepOHPe3I3rKZtGMsmHG6B9yu0xjw0RyeQr mfYgGNQxegMu9/XhiXVoRKzsZRkfe7bLLJujp0WxofqDGqfHkPLJ6mHrfnAeWGscJqxhWu EERxJRtFRBcFZeoYHKAnNDfVcoozdcM= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018941; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YI1ysKQoZ4KtpQt8LrU0cY4zBTnFx8A/2d0JHjXzvmY=; b=SIE3Wn8GWPLkL9ArQd8k4xcqVXtvyUsC2IkfepOHPe3I3rKZtGMsmHG6B9yu0xjw0RyeQr mfYgGNQxegMu9/XhiXVoRKzsZRkfe7bLLJujp0WxofqDGqfHkPLJ6mHrfnAeWGscJqxhWu EERxJRtFRBcFZeoYHKAnNDfVcoozdcM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Anthony PERARD Subject: [PATCH v2 11/12] tools/xl: add xl commands for xenstore quota operations Date: Fri, 20 Mar 2026 16:01:19 +0100 Message-ID: <20260320150120.874878-12-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:helo]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_THREE(0.00)[3]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1774019278676154100 Content-Type: text/plain; charset="utf-8" Add "xl xenstore-quota-get" and "xl xenstore-quota-set" commands for retrieving and setting global and per-domain Xenstore quota. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- V2: - s/quota data/quotas/ in cmdtable (Anthony Perard) - test for quota value to fit into type (Anthony Perard) - use libxl_xs_quota_list_init() (Anthony Perard) - use xcalloc() (Anthony Perard) --- tools/xl/Makefile | 1 + tools/xl/xl.h | 2 + tools/xl/xl_cmdtable.c | 10 +++++ tools/xl/xl_parse.c | 28 +++++++++++++ tools/xl/xl_parse.h | 1 + tools/xl/xl_xsquota.c | 90 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 tools/xl/xl_xsquota.c diff --git a/tools/xl/Makefile b/tools/xl/Makefile index 973ff0e1a2..e4eed8be13 100644 --- a/tools/xl/Makefile +++ b/tools/xl/Makefile @@ -24,6 +24,7 @@ XL_OBJS +=3D xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_= mem.o XL_OBJS +=3D xl_info.o xl_console.o xl_misc.o XL_OBJS +=3D xl_vmcontrol.o xl_saverestore.o xl_migrate.o XL_OBJS +=3D xl_vdispl.o xl_vsnd.o xl_vkb.o +XL_OBJS +=3D xl_xsquota.o =20 $(XL_OBJS): CFLAGS +=3D $(CFLAGS_libxentoollog) $(XL_OBJS): CFLAGS +=3D $(CFLAGS_XL) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 9000df00de..0efc07a6ba 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -217,6 +217,8 @@ int main_psr_mba_set(int argc, char **argv); int main_psr_mba_show(int argc, char **argv); #endif int main_qemu_monitor_command(int argc, char **argv); +int main_xsquota_get(int argc, char **argv); +int main_xsquota_set(int argc, char **argv); =20 void help(const char *command); =20 diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 06a0039718..5098f72ab4 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -649,6 +649,16 @@ const struct cmd_spec cmd_table[] =3D { "-h print this help\n" }, #endif + { "xenstore-quota-get", + &main_xsquota_get, 0, 0, + "List global or domain specific Xenstore quotas", + "|-g", + }, + { "xenstore-quota-set", + &main_xsquota_set, 0, 1, + "Set global or domain specific Xenstore quotas", + "|-g =3D...", + }, }; =20 const int cmdtable_len =3D ARRAY_SIZE(cmd_table); diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 1a2ea8b5d5..4b074fdb58 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1314,6 +1314,34 @@ out: return ret; } =20 +int parse_xsquota_item(const char *buf, struct libxl_xs_quota_item *item) +{ + const char *eq; + char *endptr; + unsigned long val; + + eq =3D strchr(buf, '=3D'); + if (!eq) { + fprintf(stderr, "Quota specification \"%s\" lacks \"=3D\".\n", buf= ); + return ERROR_INVAL; + } + errno =3D 0; + item->name =3D strndup(buf, eq - buf); + if (!item->name) + return ERROR_NOMEM; + val =3D strtoul(eq + 1, &endptr, 0); + if (errno || !eq[1] || *endptr || (unsigned int)val !=3D val) { + fprintf(stderr, + "Quota specification \"%s\" uses illegal value \"%s\".\n", + buf, eq + 1); + return ERROR_INVAL; + } + + item->val =3D val; + + return 0; +} + void parse_config_data(const char *config_source, const char *config_data, int config_len, diff --git a/tools/xl/xl_parse.h b/tools/xl/xl_parse.h index fe0d586cdd..57bb43a067 100644 --- a/tools/xl/xl_parse.h +++ b/tools/xl/xl_parse.h @@ -36,6 +36,7 @@ int parse_nic_config(libxl_device_nic *nic, XLU_Config **= config, char *token); int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token); int parse_vsnd_item(libxl_device_vsnd *vsnd, const char *spec); int parse_vkb_config(libxl_device_vkb *vkb, char *token); +int parse_xsquota_item(const char *buf, struct libxl_xs_quota_item *item); =20 int match_option_size(const char *prefix, size_t len, char *arg, char **argopt); diff --git a/tools/xl/xl_xsquota.c b/tools/xl/xl_xsquota.c new file mode 100644 index 0000000000..3533d22dae --- /dev/null +++ b/tools/xl/xl_xsquota.c @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ + +#include +#include +#include +#include + +#include "xl.h" +#include "xl_utils.h" +#include "xl_parse.h" + +int main_xsquota_get(int argc, char **argv) +{ + libxl_xs_quota_list q; + unsigned int i; + int rc; + + if (argc !=3D 2) { + fprintf(stderr, "Domain or \"-g\" must be specified.\n"); + return EXIT_FAILURE; + } + + libxl_xs_quota_list_init(&q); + + if (!strcmp(argv[1], "-g")) { + rc =3D libxl_xs_quota_global_get(ctx, &q); + } else { + uint32_t domid =3D find_domain(argv[1]); + + rc =3D libxl_xs_quota_domain_get(ctx, domid, &q); + } + + if (rc) { + libxl_xs_quota_list_dispose(&q); + fprintf(stderr, "Quota could not be obtained.\n"); + return EXIT_FAILURE; + } + + printf("Quota name Quota value\n"); + printf("--------------------------------\n"); + for (i =3D 0; i < q.num_quota; i++) + printf("%-20s %8u\n", q.quota[i].name, q.quota[i].val); + + libxl_xs_quota_list_dispose(&q); + + return EXIT_SUCCESS; +} + +int main_xsquota_set(int argc, char **argv) +{ + unsigned int i; + libxl_xs_quota_list q; + int rc =3D EXIT_FAILURE; + + if (argc < 3) { + fprintf(stderr, "Not enough parameters.\n"); + help("xenstore-quota-set"); + return EXIT_FAILURE; + } + + libxl_xs_quota_list_init(&q); + + q.num_quota =3D argc - 2; + q.quota =3D xcalloc(q.num_quota, sizeof(*q.quota)); + + for (i =3D 2; i < argc; i++) { + if (parse_xsquota_item(argv[i], q.quota + i - 2)) + goto err; + } + + if (!strcmp(argv[1], "-g")) { + rc =3D libxl_xs_quota_global_set(ctx, &q); + } else { + uint32_t domid =3D find_domain(argv[1]); + + rc =3D libxl_xs_quota_domain_set(ctx, domid, &q); + } + + if (rc) { + fprintf(stderr, "Quota could not be set.\n"); + rc =3D EXIT_FAILURE; + } else { + rc =3D EXIT_SUCCESS; + } + + err: + libxl_xs_quota_list_dispose(&q); + + return rc; +} --=20 2.53.0 From nobody Mon Mar 23 19:52:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1774019527; cv=none; d=zohomail.com; s=zohoarc; b=TQnDgzsKAuGgp9DwDlQWRuqKm7MObQ5nu0HXKWSK1S9MFy2TEWR2UaaRbUgLTte2YOKnAkYZGWo2Hk8MSki0BcExewSINgshVUe0l5e7oK52aCl5167Ohhew8JfOLvNRVA5tCtQXCYaxJuf5luuF24WZwa1r7p2rVZ2WYqgb4xc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774019527; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RvZyWf80UhIWQ1Ha92/GkHwBZUAkRxIiyYOr24YFL4c=; b=F6xRHt9AKTs0zULyZMfL9Zy2iy97Ta3cAcLeugHV0JA5Hu5wpDRmS92dfRvVM95NUxiBM0/ptVxFjFXY/hA8NHiXL/9dR/IR8zQvTN83CpIdYoS8xPkzG8jOqWx/knoCFeOBauMucflrXvfXVoLUxnR8M53dBJWwbma7ReicXX8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774019527883427.9589767096596; Fri, 20 Mar 2026 08:12:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1258221.1552374 (Exim 4.92) (envelope-from ) id 1w3bW0-0001h1-FM; Fri, 20 Mar 2026 15:11:56 +0000 Received: by outflank-mailman (output) from mailman id 1258221.1552374; Fri, 20 Mar 2026 15:11:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bW0-0001gu-CH; Fri, 20 Mar 2026 15:11:56 +0000 Received: by outflank-mailman (input) for mailman id 1258221; Fri, 20 Mar 2026 15:11:54 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w3bMv-0001ko-3N for xen-devel@lists.xenproject.org; Fri, 20 Mar 2026 15:02:33 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d1821fae-246d-11f1-9ccf-f158ae23cfc8; Fri, 20 Mar 2026 16:02:31 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4F34F5BDF1; Fri, 20 Mar 2026 15:02:27 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 328F242866; Fri, 20 Mar 2026 15:02:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id e5RHC4NhvWkQXQAAD6G6ig (envelope-from ); Fri, 20 Mar 2026 15:02:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d1821fae-246d-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018947; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RvZyWf80UhIWQ1Ha92/GkHwBZUAkRxIiyYOr24YFL4c=; b=u2wXVdKkXq1jVy9V9f9iklAiWJ5Kt3UogaAKILZjUMZ8+6H6zjmiSsBBPYECJAkcOZpIQx 96RgUK6eWPXG9IzikBjViC+o25mHnBc8u8N3nzfCqtvYVmT1krXOwZTwR+9pfuZVpcdowr ytNq900LHAh/UqcEAkP0twmudkMANe4= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=u2wXVdKk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1774018947; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RvZyWf80UhIWQ1Ha92/GkHwBZUAkRxIiyYOr24YFL4c=; b=u2wXVdKkXq1jVy9V9f9iklAiWJ5Kt3UogaAKILZjUMZ8+6H6zjmiSsBBPYECJAkcOZpIQx 96RgUK6eWPXG9IzikBjViC+o25mHnBc8u8N3nzfCqtvYVmT1krXOwZTwR+9pfuZVpcdowr ytNq900LHAh/UqcEAkP0twmudkMANe4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Anthony PERARD Subject: [PATCH v2 12/12] tools/xl: add support for xenstore quota setting via domain config Date: Fri, 20 Mar 2026 16:01:20 +0100 Message-ID: <20260320150120.874878-13-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320150120.874878-1-jgross@suse.com> References: <20260320150120.874878-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:dkim,suse.com:email,vates.tech:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 4F34F5BDF1 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1774019528767154101 Content-Type: text/plain; charset="utf-8" Add a new "xenstore_quota" domain config parameter for setting the Xenstore quota of a new domain via a list of =3D items. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- V2: - fix typo in commit message (Anthony Perard) - use xcalloc() (Anthony Perard) --- docs/man/xl.cfg.5.pod.in | 13 +++++++++++++ tools/xl/xl_parse.c | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 27c455210b..3aac0bc4fb 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -748,6 +748,19 @@ via the B command in dom0. The default value is B<0xffffffff>, meaning that all possible Xenstore features are visible by the guest. =20 +=3Ditem B + +Specifies Xenstore quota values of the domain, overriding the default +values of Xenstore. + +Each B is a B=3DB specification. The suppor= ted +B identifiers can be obtained by the B +command. B is a non-negative integer. + +As per-domain Xenstore quota are an optional Xenstore feature, the +B config parameter may not be supported by all Xenstore +implementations. + =3Dback =20 =3Dhead2 Devices diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 4b074fdb58..48c72dce9c 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1354,7 +1354,7 @@ void parse_config_data(const char *config_source, XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms, *usbctrls, *usbdevs, *p9devs, *vdispls, *pvcallsifs_dev= s; XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs, - *mca_caps, *smbios, *llc_colors; + *mca_caps, *smbios, *llc_colors, *xs_quota; int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian, num_mca_= caps; int num_smbios; int pci_power_mgmt =3D 0; @@ -1363,6 +1363,7 @@ void parse_config_data(const char *config_source, int pci_seize =3D 0; int i, e; int num_llc_colors; + int num_xs_quota; char *kernel_basename; =20 libxl_domain_create_info *c_info =3D &d_config->c_info; @@ -1470,6 +1471,22 @@ void parse_config_data(const char *config_source, if (!xlu_cfg_get_long (config, "xenstore_feature_mask", &l, 0)) b_info->xenstore_feature_mask =3D l; =20 + if (!xlu_cfg_get_list(config, "xenstore_quota", &xs_quota, &num_xs_quo= ta, 0)) { + b_info->xenstore_quota.num_quota =3D num_xs_quota; + b_info->xenstore_quota.quota =3D xcalloc(num_xs_quota, sizeof(* b_= info->xenstore_quota.quota)); + + for (i =3D 0; i < num_xs_quota; i++) { + buf =3D xlu_cfg_get_listitem(xs_quota, i); + if (!buf) { + fprintf(stderr, + "xl: Can't get element %d in Xenstore quota list\n= ", i); + exit(1); + } + if (parse_xsquota_item(buf, b_info->xenstore_quota.quota + i)) + exit(1); + } + } + libxl_domain_build_info_init_type(b_info, c_info->type); =20 if (b_info->type =3D=3D LIBXL_DOMAIN_TYPE_PVH) { --=20 2.53.0