get_host_arch
O_PATH
O_TMPFILE
+AT_EMPTY_PATH
+AT_FDCWD
+CLONE_NEWNS
+CLONE_NEWUTS
+CLONE_NEWIPC
+CLONE_NEWUSER
+CLONE_NEWPID
+CLONE_NEWNET
);
my $pvelogdir = "/var/log/pve";
use constant {O_PATH => 0x00200000,
O_TMPFILE => 0x00410000}; # This includes O_DIRECTORY
-use constant {AT_EMPTY_PATH => 0x1000};
+use constant {AT_EMPTY_PATH => 0x1000,
+ AT_FDCWD => -100};
sub run_with_timeout {
my ($timeout, $code, @param) = @_;
return next_unused_port(5900, 6000, $family, $address);
}
+sub spice_port_range {
+ return (61000, 61999);
+}
+
sub next_spice_port {
my ($family, $address) = @_;
- return next_unused_port(61000, 61099, $family, $address);
+ return next_unused_port(spice_port_range(), $family, $address);
}
sub must_stringify {
my $res = eval { run_fork_with_timeout($timeout, $df) } // {};
warn $@ if $@;
- # untaint the values
- my ($blocks, $used, $bavail) = map { defined($_) ? (/^(\d+)$/) : 0 }
+ # untaint, but be flexible: PB usage can result in scientific notation
+ my ($blocks, $used, $bavail) = map { defined($_) ? (/^([\d\.e\-+]+)$/) : 0 }
$res->@{qw(blocks used bavail)};
return {
}
my $host_arch;
-sub get_host_arch() {
+sub get_host_arch {
$host_arch = (POSIX::uname())[4] if !$host_arch;
return $host_arch;
}
return $return_arr;
}
+sub open_tree($$$) {
+ my ($dfd, $pathname, $flags) = @_;
+ return PVE::Syscall::file_handle_result(syscall(
+ &PVE::Syscall::open_tree,
+ $dfd,
+ $pathname,
+ $flags,
+ ));
+}
+
+sub move_mount($$$$$) {
+ my ($from_dirfd, $from_pathname, $to_dirfd, $to_pathname, $flags) = @_;
+ return 0 == syscall(
+ &PVE::Syscall::move_mount,
+ $from_dirfd,
+ $from_pathname,
+ $to_dirfd,
+ $to_pathname,
+ $flags,
+ );
+}
+
+sub fsopen($$) {
+ my ($fsname, $flags) = @_;
+ return PVE::Syscall::file_handle_result(syscall(&PVE::Syscall::fsopen, $fsname, $flags));
+}
+
+sub fsmount($$$) {
+ my ($fd, $flags, $mount_attrs) = @_;
+ return PVE::Syscall::file_handle_result(syscall(
+ &PVE::Syscall::fsmount,
+ $fd,
+ $flags,
+ $mount_attrs,
+ ));
+}
+
+sub fspick($$$) {
+ my ($dirfd, $pathname, $flags) = @_;
+ return PVE::Syscall::file_handle_result(syscall(
+ &PVE::Syscall::fspick,
+ $dirfd,
+ $pathname,
+ $flags,
+ ));
+}
+
+sub fsconfig($$$$$) {
+ my ($fd, $command, $key, $value, $aux) = @_;
+ return 0 == syscall(&PVE::Syscall::fsconfig, $fd, $command, $key, $value, $aux);
+}
+
+# "raw" mount, old api, not for generic use (as it does not invoke any helpers).
+# use for lower level stuff such as bind/remount/... or simple tmpfs mounts
+sub mount($$$$$) {
+ my ($source, $target, $filesystemtype, $mountflags, $data) = @_;
+ return 0 == syscall(
+ &PVE::Syscall::mount,
+ $source,
+ $target,
+ $filesystemtype,
+ $mountflags,
+ $data,
+ );
+}
+
+sub safe_compare {
+ my ($left, $right, $cmp) = @_;
+
+ return 0 if !defined($left) && !defined($right);
+ return -1 if !defined($left);
+ return 1 if !defined($right);
+ return $cmp->($left, $right);
+}
1;