From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 48B551FF16F
	for <inbox@lore.proxmox.com>; Thu, 19 Dec 2024 17:05:41 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 76E87C29A;
	Thu, 19 Dec 2024 17:05:41 +0100 (CET)
From: Daniel Kral <d.kral@proxmox.com>
To: f.gruenbichler@proxmox.com
Date: Thu, 19 Dec 2024 17:05:34 +0100
Message-Id: <20241219160534.185499-1-d.kral@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20240416122054.733817-11-f.gruenbichler@proxmox.com>
References: <20240416122054.733817-11-f.gruenbichler@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.003 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH v2 manager 1/4] api: pools: add limits
 management
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Cc: pve-devel@lists.proxmox.com
Content-Type: multipart/mixed; boundary="===============4041517636012261506=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============4041517636012261506==
Content-Transfer-Encoding: quoted-printable

On 16/04/2024 14:20, Fabian Gr=C3=BCnbichler wrote:=0D
> allow to set/update limits, and return them when querying individual pool=
s.=0D
> =0D
> Signed-off-by: Fabian Gr=C3=BCnbichler <f.gruenbichler@proxmox.com>=0D
> ---=0D
> =0D
> Notes:=0D
>     requires bumped pve-access-control=0D
>     =0D
>     v2:=0D
>     - unify run vs config limit checks into helper=0D
>     - avoid hard-coding resource kinds=0D
> =0D
>  PVE/API2/Pool.pm | 50 ++++++++++++++++++++++++++++++++++++++++++++----=0D
>  1 file changed, 46 insertions(+), 4 deletions(-)=0D
> =0D
> diff --git a/PVE/API2/Pool.pm b/PVE/API2/Pool.pm=0D
> index 54e744558..031f0160f 100644=0D
> --- a/PVE/API2/Pool.pm=0D
> +++ b/PVE/API2/Pool.pm=0D
> @@ -7,6 +7,7 @@ use PVE::AccessControl;=0D
>  use PVE::Cluster qw (cfs_read_file cfs_write_file);=0D
>  use PVE::Exception qw(raise_param_exc);=0D
>  use PVE::INotify;=0D
> +use PVE::JSONSchema qw(get_standard_option parse_property_string print_p=
roperty_string);=0D
>  use PVE::Storage;=0D
>  =0D
>  use PVE::SafeSyslog;=0D
> @@ -47,10 +48,7 @@ __PACKAGE__->register_method ({=0D
>  	    type =3D> "object",=0D
>  	    properties =3D> {=0D
>  		poolid =3D> { type =3D> 'string' },=0D
> -		comment =3D> {=0D
> -		    type =3D> 'string',=0D
> -		    optional =3D> 1,=0D
> -		},=0D
> +		comment =3D> { type =3D> 'string', optional =3D> 1 },=0D
>  		members =3D> {=0D
>  		    type =3D> 'array',=0D
>  		    optional =3D> 1,=0D
> @@ -79,6 +77,7 @@ __PACKAGE__->register_method ({=0D
>  			},=0D
>  		    },=0D
>  		},=0D
> +		limits =3D> { type =3D> 'string', optional =3D> 1 },=0D
>  	    },=0D
>  	},=0D
>  	links =3D> [ { rel =3D> 'child', href =3D> "{poolid}" } ],=0D
> @@ -136,6 +135,8 @@ __PACKAGE__->register_method ({=0D
>  		members =3D> $members,=0D
>  	    };=0D
>  	    $pool_info->{comment} =3D $pool_config->{comment} if defined($pool_=
config->{comment});=0D
> +	    $pool_info->{limits} =3D print_property_string($pool_config->{limit=
s}, 'pve-pool-limits')=0D
> +		if defined($pool_config->{limits});=0D
>  	    $pool_info->{poolid} =3D $poolid;=0D
>  =0D
>  	    push @$res, $pool_info;=0D
> @@ -153,6 +154,26 @@ __PACKAGE__->register_method ({=0D
>  	return $res;=0D
>      }});=0D
>  =0D
> +my $check_run_vs_config_limits =3D sub {=0D
> +    my ($limits) =3D @_;=0D
> +=0D
> +    my $exception;=0D
> +=0D
> +    for my $resource (keys $limits->%*) {=0D
> +	next if $resource !~ m/-run$/;=0D
> +=0D
> +	my $config =3D $resource;=0D
> +	$config =3D~ s/-run$/-config/;=0D
> +=0D
> +	if (defined($limits->{$config}) && $limits->{$config} < $limits->{$reso=
urce}) {=0D
> +	    my $msg =3D "run limit must be below config limit!";=0D
> +	    $exception->{$resource} =3D $msg;=0D
> +	}=0D
> +    }=0D
> +=0D
> +    raise_param_exc($exception) if $exception;=0D
> +};=0D
> +=0D
>  __PACKAGE__->register_method ({=0D
>      name =3D> 'create_pool',=0D
>      protected =3D> 1,=0D
> @@ -173,6 +194,7 @@ __PACKAGE__->register_method ({=0D
>  		type =3D> 'string',=0D
>  		optional =3D> 1,=0D
>  	    },=0D
> +	    limits =3D> get_standard_option('pve-pool-limits'),=0D
>  	},=0D
>      },=0D
>      returns =3D> { type =3D> 'null' },=0D
> @@ -196,6 +218,10 @@ __PACKAGE__->register_method ({=0D
>  	    };=0D
>  =0D
>  	    $usercfg->{pools}->{$pool}->{comment} =3D $param->{comment} if $par=
am->{comment};=0D
> +	    if (my $limits =3D parse_property_string('pve-pool-limits', $param-=
>{limits} // '')) {=0D
> +		$check_run_vs_config_limits->($limits);=0D
> +		$usercfg->{pools}->{$pool}->{limits} =3D $limits;=0D
> +	    }=0D
>  =0D
>  	    cfs_write_file("user.cfg", $usercfg);=0D
>  	}, "create pool failed");=0D
> @@ -288,6 +314,9 @@ __PACKAGE__->register_method ({=0D
>  		optional =3D> 1,=0D
>  		default =3D> 0,=0D
>  	    },=0D
> +	    limits =3D> get_standard_option("pve-pool-limits", {=0D
> +		description =3D> "Update pool limits. Passing '0' for a specific limit=
 will remove any currently configured value.",=0D
> +	    }),=0D
>  	},=0D
>      },=0D
>      returns =3D> { type =3D> 'null' },=0D
> @@ -346,6 +375,18 @@ __PACKAGE__->register_method ({=0D
>  		}=0D
>  	    }=0D
>  =0D
> +	    if (my $update =3D parse_property_string('pve-pool-limits', $param-=
>{limits} // '')) {=0D
=0D
Bug: Something like a=0D
=0D
`$pool_config->{limits} =3D {} if !defined($pool_config->{limits});`=0D
=0D
is missing here. Without this, a pool created without any pool usage=0D
limits set will not be able to add them as the limits added in `$limits`=0D
will never be written to the reference in `$pool_config->{limits}`.=0D
=0D
Since we already default everywhere to the values in=0D
`pool_usage_default`, an empty hash would not overwrite any settings=0D
that weren't set yet.=0D
=0D
> +		my $limits =3D $pool_config->{limits};=0D
> +		for my $kind (sort keys $update->%*) {=0D
> +		    if ($update->{$kind} =3D=3D 0) {=0D
> +			delete $limits->{$kind};=0D
> +		    } else {=0D
> +			$limits->{$kind} =3D $update->{$kind};=0D
> +		    }=0D
> +		}=0D
> +		$check_run_vs_config_limits->($limits);=0D
> +	    }=0D
> +=0D
>  	    cfs_write_file("user.cfg", $usercfg);=0D
>  	}, "update pools failed");=0D
>  =0D
> @@ -409,6 +450,7 @@ __PACKAGE__->register_method ({=0D
>  		    },=0D
>  		},=0D
>  	    },=0D
> +	    limits =3D> get_standard_option("pve-pool-limits"),=0D
>  	},=0D
>      },=0D
>      code =3D> sub {=0D
> -- =0D
> 2.39.2=0D
=0D
=0D
=0D
=0D
=0D



--===============4041517636012261506==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

--===============4041517636012261506==--