[pve-devel] [RFC common] add libpve-common-sys-perl package for platform dependent modules

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Apr 28 18:08:06 CEST 2017


This builds a second package, libpve-common-sys-perl, which is in
contrary to libpve-common-perl not architecture independent but
contains architecture specific modules.
Currently it contains a single module with the mapping of Linux
syscall numbers for x86_64 and ARM 64

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

As libpve-common-perl is marked as architecture dependent I had to put this
elsewhere.
Resolving dynamically seemed also a bit to hacky and is an unneeded cost, imo.
After a discussion with Fabian this seemed the "most Debian like" way.

 Makefile                                  | 11 +++++++----
 debian/control                            | 11 ++++++++++-
 debian/libpve-common-perl.install         |  1 +
 debian/libpve-common-sys-perl.install     |  1 +
 src/Makefile                              |  5 +++++
 src/PVE/ArchDependent/SyscallMap_amd64.pm | 16 ++++++++++++++++
 src/PVE/ArchDependent/SyscallMap_arm64.pm | 16 ++++++++++++++++
 src/PVE/Tools.pm                          | 16 +++++++++-------
 9 files changed, 68 insertions(+), 12 deletions(-)
 create mode 100644 debian/libpve-common-perl.install
 create mode 100644 debian/libpve-common-sys-perl.install
 create mode 100644 src/PVE/ArchDependent/SyscallMap_amd64.pm
 create mode 100644 src/PVE/ArchDependent/SyscallMap_arm64.pm

diff --git a/Makefile b/Makefile
index ecc27ca..1c04a0e 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,7 @@ VERSION=5.0
 PKGREL=8
 
 PACKAGE=libpve-common-perl
+SYS_PACKAGE=libpve-common-sys-perl
 
 PREFIX=/usr
 BINDIR=${PREFIX}/bin
@@ -11,9 +12,11 @@ MAN1DIR=${MANDIR}/man1/
 PERLDIR=${PREFIX}/share/perl5
 
 ARCH=all
+SYS_ARCH:=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
 GITVERSION:=$(shell cat .git/refs/heads/master)
 
-DEB=${PACKAGE}_${VERSION}-${PKGREL}_${ARCH}.deb
+DEB=${PACKAGE}_${VERSION}-${PKGREL}_${ARCH}.deb \
+    ${SYS_PACKAGE}_${VERSION}-${PKGREL}_${SYS_ARCH}.deb
 
 all: ${DEB}
 
@@ -23,8 +26,7 @@ dinstall: deb
 
 
 .PHONY: deb
-deb ${DEB}:
-	$(MAKE) -C test check
+deb ${DEB}: check
 	rm -rf build
 	rsync -a src/ build
 	rsync -a debian/ build/debian
@@ -34,13 +36,14 @@ deb ${DEB}:
 
 .PHONY: clean
 clean: 	
-	rm -rf *~ *.deb *.changes build ${PACKAGE}-*.tar.gz *.buildinfo
+	rm -rf *~ *.deb *.changes build ${PACKAGE}-*.tar.gz *.buildinfo src/PVE/SyscallMap.pm src/PVE/ArchDependent/SyscallMap.pm
 
 .PHONY: distclean
 distclean: clean
 
 .PHONY: check
 check:
+	cp src/PVE/ArchDependent/SyscallMap_${SYS_ARCH}.pm src/PVE/ArchDependent/SyscallMap.pm
 	$(MAKE) -C test check
 
 .PHONY: upload
diff --git a/debian/control b/debian/control
index 56aa891..f3cfb30 100644
--- a/debian/control
+++ b/debian/control
@@ -7,7 +7,16 @@ Standards-Version: 3.8.4
 
 Package: libpve-common-perl
 Architecture: all
-Depends: ${perl:Depends} ${misc:Depends}, libclone-perl, libdevel-cycle-perl, libwww-perl, libjson-perl, liblinux-inotify2-perl, libio-stringy-perl, liburi-perl, libstring-shellquote-perl, libnet-ip-perl, libfilesys-df-perl, libnet-dbus-perl, libcrypt-openssl-rsa-perl, libcrypt-openssl-random-perl, libmime-base32-perl
+Depends: ${perl:Depends} ${misc:Depends}, libclone-perl, libdevel-cycle-perl, libwww-perl, libjson-perl, liblinux-inotify2-perl, libio-stringy-perl, liburi-perl, libstring-shellquote-perl, libnet-ip-perl, libfilesys-df-perl, libnet-dbus-perl, libcrypt-openssl-rsa-perl, libcrypt-openssl-random-perl, libmime-base32-perl, libpve-common-sys-perl
 Breaks: qemu-server (<< 4.0-109), pve-container (<< 1.0-93)
 Description: Proxmox VE base library
  This package contains the base library used by other Proxmox VE components.
+
+Package: libpve-common-sys-perl
+Section: perl
+Priority: extra
+Architecture: any
+Depends: ${perl:Depends}
+Description: Proxmox VE architecture dependent modules
+ This package contains the architecture depended modules from base library used
+ by other Proxmox VE components.
diff --git a/debian/libpve-common-perl.install b/debian/libpve-common-perl.install
new file mode 100644
index 0000000..f99efd5
--- /dev/null
+++ b/debian/libpve-common-perl.install
@@ -0,0 +1 @@
+usr/share/perl5/PVE/*.pm
diff --git a/debian/libpve-common-sys-perl.install b/debian/libpve-common-sys-perl.install
new file mode 100644
index 0000000..75526be
--- /dev/null
+++ b/debian/libpve-common-sys-perl.install
@@ -0,0 +1 @@
+usr/share/perl5/PVE/ArchDependent
diff --git a/src/Makefile b/src/Makefile
index a45effb..887750a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -6,6 +6,8 @@ DOCDIR=${PREFIX}/share/doc
 MAN1DIR=${MANDIR}/man1/
 PERLDIR=${PREFIX}/share/perl5
 
+SYS_ARCH:=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
+
 LIB_SOURCES=			\
 	OTP.pm			\
 	Ticket.pm		\
@@ -24,12 +26,15 @@ LIB_SOURCES=			\
 	Tools.pm		\
 	Exception.pm
 
+LIB_SYS_SOURCES=SyscallMap
+
 all:
 
 .PHONY: install
 install:
 	install -d -m 0755 ${DESTDIR}${PERLDIR}/PVE
 	for i in ${LIB_SOURCES}; do install -D -m 0644 PVE/$$i ${DESTDIR}${PERLDIR}/PVE/$$i; done
+	for i in ${LIB_SYS_SOURCES}; do install -D -m 0644 PVE/ArchDependent/$${i}_${SYS_ARCH}.pm ${DESTDIR}${PERLDIR}/PVE/ArchDependent/$${i}.pm; done
 
 
 .PHONY: clean
diff --git a/src/PVE/ArchDependent/SyscallMap_amd64.pm b/src/PVE/ArchDependent/SyscallMap_amd64.pm
new file mode 100644
index 0000000..1c6229e
--- /dev/null
+++ b/src/PVE/ArchDependent/SyscallMap_amd64.pm
@@ -0,0 +1,16 @@
+package PVE::ArchDependent::SyscallMap;
+
+use strict;
+use warnings;
+
+use constant {O_TMPFILE     => '0x00410000', # This includes O_DIRECTORY
+              SYS_unshare   =>  272,
+              SYS_setns     =>  308,
+              SYS_syncfs    =>  306,
+              SYS_openat    =>  257,
+              SYS_close     =>    3,
+              SYS_mkdirat   =>  258,
+              SYS_faccessat =>  269,
+};
+
+1;
diff --git a/src/PVE/ArchDependent/SyscallMap_arm64.pm b/src/PVE/ArchDependent/SyscallMap_arm64.pm
new file mode 100644
index 0000000..8640b87
--- /dev/null
+++ b/src/PVE/ArchDependent/SyscallMap_arm64.pm
@@ -0,0 +1,16 @@
+package PVE::ArchDependent::SyscallMap;
+
+use strict;
+use warnings;
+
+use constant {O_TMPFILE     => '0x00404000', # This includes O_DIRECTORY
+	      SYS_unshare   =>   97,
+	      SYS_setns     =>  268,
+	      SYS_syncfs    =>  267,
+	      SYS_openat    =>   56,
+	      SYS_close     =>   57,
+	      SYS_mkdirat   =>   34,
+	      SYS_faccessat =>   48,
+};
+
+1;
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 1f0ec75..28ddbd8 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -2,6 +2,8 @@ package PVE::Tools;
 
 use strict;
 use warnings;
+
+use PVE::ArchDependent::SyscallMap;
 use POSIX qw(EINTR EEXIST EOPNOTSUPP);
 use IO::Socket::IP;
 use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED AI_CANONNAME SOCK_DGRAM);
@@ -82,7 +84,7 @@ use constant {CLONE_NEWNS   => 0x00020000,
               CLONE_NEWNET  => 0x40000000};
 
 use constant {O_PATH    => 0x00200000,
-              O_TMPFILE => 0x00410000}; # This includes O_DIRECTORY
+              O_TMPFILE => PVE::ArchDependent::SyscallMap::O_TMPFILE};
 
 sub run_with_timeout {
     my ($timeout, $code, @param) = @_;
@@ -1231,17 +1233,17 @@ sub parse_host_and_port {
 
 sub unshare($) {
     my ($flags) = @_;
-    return 0 == syscall(272, $flags);
+    return 0 == syscall(PVE::ArchDependent::SyscallMap::SYS_unshare, $flags);
 }
 
 sub setns($$) {
     my ($fileno, $nstype) = @_;
-    return 0 == syscall(308, $fileno, $nstype);
+    return 0 == syscall(PVE::ArchDependent::SyscallMap::SYS_setns, $fileno, $nstype);
 }
 
 sub syncfs($) {
     my ($fileno) = @_;
-    return 0 == syscall(306, $fileno);
+    return 0 == syscall(PVE::ArchDependent::SyscallMap::SYS_syncfs, $fileno);
 }
 
 sub sync_mountpoint {
@@ -1373,7 +1375,7 @@ sub validate_ssh_public_keys {
 
 sub openat($$$;$) {
     my ($dirfd, $pathname, $flags, $mode) = @_;
-    my $fd = syscall(257, $dirfd, $pathname, $flags, $mode//0);
+    my $fd = syscall(PVE::ArchDependent::SyscallMap::SYS_openat, $dirfd, $pathname, $flags, $mode//0);
     return undef if $fd < 0;
     # sysopen() doesn't deal with numeric file descriptors apparently
     # so we need to convert to a mode string for IO::Handle->new_from_fd
@@ -1381,14 +1383,14 @@ sub openat($$$;$) {
     my $handle = IO::Handle->new_from_fd($fd, $flagstr);
     return $handle if $handle;
     my $err = $!; # save error before closing the raw fd
-    syscall(3, $fd); # close
+    syscall(PVE::ArchDependent::SyscallMap::SYS_close, $fd); # close
     $! = $err;
     return undef;
 }
 
 sub mkdirat($$$) {
     my ($dirfd, $name, $mode) = @_;
-    return syscall(258, $dirfd, $name, $mode) == 0;
+    return syscall(PVE::ArchDependent::SyscallMap::SYS_mkdirat, $dirfd, $name, $mode) == 0;
 }
 
 # NOTE: This calls the dbus main loop and must not be used when another dbus
-- 
2.11.0





More information about the pve-devel mailing list