Commit Graph

966 Commits

Author SHA1 Message Date
Thomas Lamprecht
e4394777d2 tools: code-style cleanup file_set_contents
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-10-19 16:42:43 +02:00
Thomas Lamprecht
f1fe7a0733 file set contents: fix error handling with or-operator precedence
In perl the `or` and the `||` operator do mostly the same thing but
with a different precedence level [0].

A statement like:
`$foo += bar() or die "error"`
is basically equivalent to:
`($foo += bar()) or die "error"`

That means as long as bar only returns zero or positive integers the
`or die` can only happen the first time, as otherwise $foo is bigger
than zero and thus will never evaluate to false. This can be
reproduced by perl -we 'my $foo = 1; $foo += 0 or die "wont happen";'

While one could switch to the `||` operator, this is a bit to subtle,
so to fix this, separate tracking the total bytes written from getting
the bytes written by the current call, this avoids the error potential
completely.

[0]: https://perldoc.perl.org/perlop#Logical-or-and-Exclusive-Or

Reported-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-10-14 11:14:23 +02:00
Filip Schauer
ef0bcc98ad tools: file_set_contents: use syswrite instead of print
The use of `print` can be inefficient for writing larger files due to
its default buffering in 8 KiB blocks.

This is especially problematic on `pmxcfs` where files are written in
4 KiB blocks due to the defaults of `libfuse2`. This leads to
significant write amplification on files larger than 4 KiB.

Patch (fix #5728: pmxcfs: allow bigger writes than 4k for fuse) [1]
addresses this by enabling `big_writes`, allowing up to 128 KiB blocks.
But due to the use of `print` in `file_set_contents`, writes are still
only buffered in 8 KiB blocks.

To further address this, this commit switches to using `syswrite`
instead of `print` to mitigate the block size limit imposed by `print`.
Combined with patch [1], file writes to `/etc/pve/` are now buffered in
128 KiB blocks.

The table below illustrates the drastic reduction in write
amplification when writing files of different sizes to `/etc/pve/` using
`file_set_contents`:

           print                big_writes+print     big_writes+syswrite
file size  written     amplif.  written     amplif.  written    amplif.
    1 KiB      48 KiB     48.0      45 KiB     45.0     41 KiB     41.0
    2 KiB      48 KiB     24.0      45 KiB     22.5     62 KiB     31.0
    4 KiB      82 KiB     20.5      80 KiB     20.0     73 KiB     18.3
    8 KiB     121 KiB     15.1      90 KiB     11.3     89 KiB     11.1
   16 KiB     217 KiB     13.6     146 KiB      9.1    113 KiB      7.1
   32 KiB     506 KiB     15.8     314 KiB      9.8    158 KiB      4.9
   64 KiB    1472 KiB     23.0     826 KiB     12.9    259 KiB      4.0
  128 KiB    5585 KiB     43.6    3765 KiB     29.4    452 KiB      3.5
  256 KiB   20424 KiB     79.8   10743 KiB     42.0   2351 KiB      9.2
  512 KiB   86715 KiB    169.4   43650 KiB     85.3   3204 KiB      6.3
 1024 KiB  369568 KiB    360.9  187496 KiB    183.1  15845 KiB     15.5

Since `file_set_contents` also performs a `rename` after writing, the
following table shows the results when the file is written without
renaming it afterwards:

           print                big_writes+print     big_writes+syswrite
file size  written     amplif.  written     amplif.  written     amplif.
    1 KiB      29 KiB     29.0      29 KiB     29.0     25 KiB      25.0
    2 KiB      29 KiB     14.5      30 KiB     15.0     25 KiB      12.5
    4 KiB      37 KiB      9.3      44 KiB     11.0     41 KiB      10.3
    8 KiB      61 KiB      7.6      45 KiB      5.6     45 KiB       5.6
   16 KiB     143 KiB      8.9      86 KiB      5.4     57 KiB       3.6
   32 KiB     396 KiB     12.4     225 KiB      7.0     69 KiB       2.2
   64 KiB    1281 KiB     20.0     673 KiB     10.5    105 KiB       1.6
  128 KiB    4789 KiB     37.4    3478 KiB     27.2    169 KiB       1.3
  256 KiB   18868 KiB     73.7    9976 KiB     39.0    572 KiB       2.2
  512 KiB   79304 KiB    154.9   42714 KiB     83.4   2150 KiB       4.2
 1024 KiB  347929 KiB    339.8  182483 KiB    178.2  11133 KiB      10.9

[1] https://lists.proxmox.com/pipermail/pve-devel/2024-September/065396.html

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
2024-10-14 10:23:50 +02:00
Fabian Grünbichler
e83d895594 method schema: rename 'download' parameter to 'download_allowed'
to make it more obvious what it does, but keep old variant for now.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-09-23 10:19:20 +02:00
Fabian Grünbichler
c1ed9e3ee6 download handling: adapt cycle check to check value
instead of whether the key exists in the schema instance, just in case somebody
wants to set "download => 0".

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-09-23 10:19:20 +02:00
Fabian Grünbichler
6dbb3e0e78 schema: adapt description of method's download key
with the newly introduced strict checks in the API handler, the download key
actually marks which endpoints/methods are allowed to use the download
functionality of the REST server, and the "directly return filename to be
downloaded" part is no longer supported as a result.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-09-23 10:19:20 +02:00
Thomas Lamprecht
e068c3d30a cli handler: print correct command prefix for alias in asciidoc output
Otherwise only the base exename is printed, even if the alias is for
sub-command.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-07-31 20:24:04 +02:00
Fabian Grünbichler
48da50c2be Revert "section config: document package and its methods with POD"
This reverts commit d41bd420f8.
2024-07-24 13:44:45 +02:00
Fabian Grünbichler
b3ed595212 Revert "section config: update code style"
This reverts commit 29292d2a5d.
2024-07-24 13:44:40 +02:00
Fabian Grünbichler
50f0b6d0be Revert "section config: clean up parser logic"
This reverts commit 6cba8d7660.
2024-07-24 13:44:37 +02:00
Thomas Lamprecht
4386716c5a REST handler: use double-hyphen as argument prefix for doc and CLI help output
Use "modern" double-hyphen style, we're not some odd BSD derived
tool..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-07-22 19:10:28 +02:00
Wolfgang Bumiller
b64a40a506 fix #5529: cgroup: correctly handle change_cpu_quota without a quota
The function can be called with
- neither quota nor period
- only a period (quota will be 'max')
- both

$quota was therefore defaulted to 'max' and the check for whether
values were provided should use $period instead of $quota.
Also move the defaulting-assignment into the condition for clarity.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-07-22 19:07:36 +02:00
Dominik Csapak
06f436f126 fix #5486: tools: encode_text: add '%' to list of encoded characters
all text that is going through encode_text will at a later point be
decoded by 'decode_text'. The latter is decoding all percent encoded
characters, even those not originally encoded by 'encode_text'.

This means, to preserve the original data, we first have to at least
percent encode the '%' itself, otherwise it's impossible to properly
store e.g. '%20' there.

It would get saved as '%20' directly, but on the next read, it gets
decoded to ' ', which is not the original data. instead we have to save
it as '%2520', which gets then correctly decoded to '%20' again

This is especially important for the vm/ct/node description, as there
users can store external links, which already include percent encoded
characters.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2024-07-04 10:54:48 +02:00
Max Carrara
6cba8d7660 section config: clean up parser logic
In order to make the parser somewhat more maintainable in the future,
this commit cleans up its logic and makes its control flow easier to
follow.

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
2024-07-04 10:54:48 +02:00
Max Carrara
29292d2a5d section config: update code style
Replace `foreach` with `for` and use postfix deref instead of block
(circumfix) dereference (`$foo->%*` instead of `%$foo`).

Furthermore, make `format_config_line` a private sub instead of
unnecessarily declaring it as an anonymous subroutine, which avoids
the `&$sub_ref(...)` syntax altogether.

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
2024-07-04 10:54:48 +02:00
Max Carrara
d41bd420f8 section config: document package and its methods with POD
Apart from the obvious benefits that documentation has, this also
allows LSPs to provide docstrings e.g. via 'textDocument/hover' [0].

Tested with Perl Navigator [1].

[0]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover
[1]: https://github.com/bscan/PerlNavigator

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
2024-07-04 10:54:48 +02:00
Jing Luo via pve-devel
6dc7a73bd5 tools: fix syscall mknod()
b792e8df81 introduced a bug that can cause this:

Undefined subroutine &PVE::Syscall::SYS_mknod called at /usr/share/perl5/PVE/Syscall.pm line 11

It should be mknod, not SYS_mknod. This caused other pve perl lib failing
to build. I couldn't reproduce this on amd64 build, but I could reproduce this
on arm64 build; however this didn't seem to fix the issue, unless I revert
b792e8df81.

cf: b792e8df81
Signed-off-by: Jing Luo <jing@jing.rocks>
2024-07-03 10:25:21 +02:00
Wolfgang Bumiller
b518bbd5f9 interfaces: support stanzas without types/methods
This is allowed in ifupdown2 and previously interfaces named
'vmbr\d+' were recognized as bridges even if they used this mode.
With commit e68ebda4f1 this is no longer the case.

Fixes: e68ebda4f1 ("fix #545: interfaces: allow arbitrary bridge names in network config")
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-04-23 15:19:43 +02:00
Stefan Hanreich
e68ebda4f1 fix #545: interfaces: allow arbitrary bridge names in network config
Similar to other interface types, we can detect a bridge by the
presence of its bridge_ports attribute, rather than solely relying on
the "vmbr" ifname prefix heuristic. For OVS bridges we need to examine
the OVS type instead.

The check needs to be moved up since other prefixes could
theoretically be included in a bridge name and then would otherwise
get picked up wrongly.

Also added a warning for interfaces named vmbrX that are not bridges
to catch possible misconfigurations.

Originally-by: Jillian Morgan <jillian.morgan@primordial.ca>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2024-04-21 11:22:10 +02:00
Fiona Ebner
c302a28a21 json schema: add format description for pve-storage-id standard option
so that the option can be used as part of a property string.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-04-11 17:19:52 +02:00
Folke Gleumes
a656f674c2 docs: add missing prefix
include 'PVEAPIToken=' prefix in the example for target-endpoint which
is mainly used for remote migrations.

Signed-off-by: Folke Gleumes <f.gleumes@proxmox.com>
2024-04-08 18:01:35 +02:00
Max Carrara
ff39327769 ticket: remove fallback for SHA1-base64 CSRF prevention tokens
Signed-off-by: Max Carrara <m.carrara@proxmox.com>
2024-03-06 12:03:10 +01:00
Wolfgang Bumiller
68b234f35e add PVE::Systemd::is_unit_active
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-03-06 11:57:22 +01:00
Wolfgang Bumiller
c6ec71d846 schema: fixup description vs format_description in remote_format
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-01-22 12:52:41 +01:00
Fabian Grünbichler
80ed66dc17 fix #5141: network parser: fix accidental RE result re-use
$1 and friends are not cleared if a RE fails to match, in which case they will
contain the captured values from a previous successful match in the same scope.

deduplicate the two branches to avoid accidental re-introduction.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-01-03 12:16:14 +01:00
Fabian Grünbichler
fcc97ec96d network parser: iterate deterministically
makes the behaviour easier to analyze, and also helps when testing since it
allows constructing test cases that trigger certain order of parsing.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-01-03 12:15:37 +01:00
Wolfgang Bumiller
63b74c5089 expose SYS_prctl
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-12-14 10:09:48 +01:00
Thomas Lamprecht
7ccdc805e3 section config: avoid unamed boolean parameter use hash
Even with just one param it's extra work to check what it refers too,
with named ones in a hash one hasn't that issue even with many params.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-11-17 09:58:01 +01:00
Dominik Csapak
7887b1cb0e section config: allow full property-isolation for plugins
When using 'init(property_isolation => 1)', the code saves the
property lists per type instead of a big one, and using
create/updateSchema creates a new schema with the options as 'oneOf'
and/or 'instance-types' (depending if the schemas match).

With that, we change how we work with the options hash:

It's not needed anymore to specify options that are specified in the
type specific propertyList, except if it's 'fixed => 1' (since that does
not exist in the schema)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
 [ TL: ensure consistency with new property-isolation terminology ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-11-17 09:57:34 +01:00
Dominik Csapak
942583468f json schema: implement 'oneOf' schema
a schema can now have the 'oneOf' property which is an array of regular
schemas. In the default case any of that has to match. If the
'type-property'/'instance-types' are given, only the schema for the specific
type will be checked (and handles as 'additionalProperties' if there is
no matching type)

the field found in 'type-property' has to be on the same level
(so for oneOf the nested schemas should not include that).

Documentation is adapted so that options are grouped per `type-property=value`
after the regular options (with their individual descriptions/types/etc.)

oneOfs without 'type-property'/'instance-tyeps' simply show up twice for
now with an 'or' line in between.

command line parsing is a bit weird for now since Getopt::Long
can't have multiple variants for the same property (but works fine with
pvesh for our current use cases). it gets shown as '--foo <multiple' if
they are not optional.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-11-17 09:24:09 +01:00
Dominik Csapak
15645af168 tools: add is_deeply
to compare nested hashes/lists and scalar values recursively.
Also includes some tests

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-11-17 09:24:09 +01:00
Filip Schauer
fe468fad74 tools: Add mount flag constants
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
2023-11-13 15:08:58 +01:00
Filip Schauer
b792e8df81 tools: Add mknod syscall
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
2023-11-13 15:08:58 +01:00
Gabriel Goller
a992ba134c fix #4162: added Auto-Submitted header to email body
`Auto-Submitted` is defined in the rfc 5436 [1] and describes how
an automatic response (f.e. ooo replies, etc.) should behave on the
emails. When using `Auto-Submitted: auto-generated` (or any value
other than `none`) automatic replies won't be triggered.

[1]: https://www.rfc-editor.org/rfc/rfc3834.html

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
2023-11-06 18:39:48 +01:00
Dominik Csapak
b4b17fd95b pbs client: add 'tar' parameter to file_restore_extract
so that we can get a 'tar.zst' from proxmox-file-restore by passing
'--format tar --zstd' to the file-restore binary

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-11-06 18:33:38 +01:00
Lukas Wagner
2943910ec3 tools: allow to force UTF-8 encoding for file_set_contents
Rationale: This is used from cfs_write_file, which is now also used to
write utf8-encoded strings that come from Rust. If no encoding is
specified while writing the file, we run into problems with certain
special characters (e.g. 'ü').

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
[FG: use flag parameter instead of encoding as a string
     use stricter 'UTF-8' instaed of 'utf8' (see 'perldoc Enocode')]
Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
[FE: implement changes suggested by Fabian
     move binmode call to where $fh is known to be set]
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2023-09-11 13:42:07 +02:00
Fiona Ebner
41ed439635 run fork with timeout: only special case timeout error in list context
run_with_timeout() will treat a timeout error differently when called
in list context and run_fork_with_timeout() should do the same. Ensure
this by calling run_with_timeout() in list context if and only if
run_fork_with_timeout() is called in list context too.

Fixes: a6aa0ae ("run with timeout: return if timeout happened in list context")
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2023-08-30 16:44:40 +02:00
Fiona Ebner
eac8b4b872 run with timeout: only special-case timeout error in list-context
and not other errors too.

Fixes: a6aa0ae ("run with timeout: return if timeout happened in list context")
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2023-08-30 16:44:40 +02:00
Dominik Csapak
d2a6411cab SectionConfig: fix handling unknown sections
if we're parsing an unknown section, we cannot check the schema with
`is_array` to check if it's an array type or not, thus we have to
handle that separately.

fix this by handling data in unknown sections like an array similar to
"cb2646c7b4974e33f4148752deec71f0d589b0f3" in proxmox-section-config.
This way we can write unknown section out again like we parsed it.

Add a regression test for an unknown field not in the schema.

This fixes an issue, where calling `qm destroy ID --purge` removed much
of the configs ob backup jobs (since there we parse an 'unknown' section
and run into the `is_array` error)
(Reported in the forum: https://forum.proxmox.com/threads/132091)

Suggested-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2023-08-16 11:19:26 +02:00
Christoph Heiss
741bf653ae section config: allow base properties for {create, update}Schema()
This works the same way as e.g. get_standard_option does it.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
2023-08-11 13:22:16 +02:00
Christoph Heiss
10de5bfc2a ldap: handle errors explicitly everywhere instead of simply dieing
Most codepaths already have explicit error handling (by the means of
checking the return value), which is essential dead code due to setting
`onerror`.

As LDAP errors might get presented to users due to upcoming changes, the
error location should not be present in these error messages, thus
switch to explicit handling.

Only two calls were missing such explicit handling of errors, so these
are amended as appropriate. Further, some `die`s were missing newlines
at the end of the message, which - again - would cause the error
location to be included.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
2023-08-11 13:21:13 +02:00
Philipp Hufnagl
4bb9bfe70b fix whitespaces
Signed-off-by: Philipp Hufnagl <p.hufnagl@proxmox.com>

FG: removed hunks that changed alignment..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-08-04 13:47:10 +02:00
Fabian Grünbichler
0bf2e89a39 download file from url: improve cleanup
don't attempt cleanup if temp files don't exist (anymore, or not yet).

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-08-04 13:47:10 +02:00
Fabian Grünbichler
a4df83987b download file from url: simplify error handling
the top-level error handling ensures the temporary downloaded file gets
removed in case of an error, so there is no need to also handle that when
decompression fails..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-08-04 12:50:40 +02:00
Fabian Grünbichler
bf8f0ca200 download file from url: fix indentation
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-08-04 12:48:23 +02:00
Philipp Hufnagl
7c3e155b28 fix #4849: download file from url: add opt parameter for a decompression command
Signed-off-by: Philipp Hufnagl <p.hufnagl@proxmox.com>
2023-08-04 12:45:35 +02:00
Lukas Wagner
13ae568f8e JSONSchema: increase maxLength of config-digest to 64
The new notification backend is implemented in Rust where we use SHA256
for config digests.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-07-24 11:44:22 +02:00
Thomas Lamprecht
a6aa0ae945 run with timeout: return if timeout happened in list context
This can be relevant info do differentiate if an undef return value
happened due to the closure returning it or if it happened due to a
timeout.

While for quite a few cases this could be handled by a
variable captured by the passed closure code reference, acting as
messenger, that might often require needless wrapping.

Also run_fork_with_timeout warned errors of execution, but any such
error handling for an actual timeout is better handled at the call
site, as a context-less "got timeout" at STDERR or journal is really
not helpful.

I checked all call sites of both, run_fork_with_timeout and
run_with_timeout most do not use the result at all, and the ones that
do are in scalar context.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-07-01 18:45:11 +02:00
Thomas Lamprecht
0c4641dcf8 network: cope with non-existing interfaces config
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-06-26 14:15:37 +02:00
Thomas Lamprecht
26db1a619b api dump: ignore proxyto_callback code refs
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-06-17 13:52:25 +02:00