diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..e007879 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* xihuan.yang@citrix.com lin.liu@citrix.com diff --git a/LICENSE b/LICENSE index d4728c3..1555eec 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015, Citrix Systems +Copyright (C) Cloud Software Group, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/Makefile b/Makefile index c65cc0b..fb69538 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -PRODUCT_MAJOR_VERSION=6 -PRODUCT_MINOR_VERSION=6 -PRODUCT_MICRO_VERSION=80 +PRODUCT_MAJOR_VERSION=8 +PRODUCT_MINOR_VERSION=4 +PRODUCT_MICRO_VERSION=0 PRODUCT_VERSION = $(PRODUCT_MAJOR_VERSION).$(PRODUCT_MINOR_VERSION).$(PRODUCT_MICRO_VERSION) GO_BUILD = go build @@ -13,6 +13,7 @@ GOBUILDDIR = $(BUILDDIR)/gobuild STAGEDIR = $(BUILDDIR)/stage OBJECTDIR = $(BUILDDIR)/obj DISTDIR = $(BUILDDIR)/dist +VENDORDIR = $(REPO)/vendor/$(shell basename $(REPO)) OBJECTS := OBJECTS += $(OBJECTDIR)/xe-daemon @@ -21,23 +22,27 @@ OBJECTS += $(OBJECTDIR)/xenstore PACKAGE = xe-guest-utilities VERSION = $(PRODUCT_VERSION) RELEASE := $(shell git rev-list HEAD | wc -l) -ARCH := $(shell go version|awk -F'/' '{print $$2}') +ifeq ($(GOARCH),) + ARCH := $(shell go version|awk -F'/' '{print $$2}') +else + ARCH := $(GOARCH) +endif ifeq ($(ARCH), amd64) ARCH = x86_64 endif XE_DAEMON_SOURCES := -XE_DAEMON_SOURCES += ./xe-daemon/xe-daemon.go -XE_DAEMON_SOURCES += ./syslog/syslog.go -XE_DAEMON_SOURCES += ./system/system.go -XE_DAEMON_SOURCES += ./guestmetric/guestmetric.go -XE_DAEMON_SOURCES += ./guestmetric/guestmetric_linux.go -XE_DAEMON_SOURCES += ./xenstoreclient/xenstore.go +XE_DAEMON_SOURCES += xe-daemon/xe-daemon.go +XE_DAEMON_SOURCES += syslog/syslog.go +XE_DAEMON_SOURCES += system/system.go +XE_DAEMON_SOURCES += guestmetric/guestmetric.go +XE_DAEMON_SOURCES += guestmetric/guestmetric_linux.go +XE_DAEMON_SOURCES += xenstoreclient/xenstore.go XENSTORE_SOURCES := -XENSTORE_SOURCES += ./xenstore/xenstore.go -XENSTORE_SOURCES += ./xenstoreclient/xenstore.go +XENSTORE_SOURCES += xenstore/xenstore.go +XENSTORE_SOURCES += xenstoreclient/xenstore.go .PHONY: build build: $(DISTDIR)/$(PACKAGE)_$(VERSION)-$(RELEASE)_$(ARCH).tgz @@ -47,6 +52,7 @@ clean: $(RM) -rf $(BUILDDIR) $(DISTDIR)/$(PACKAGE)_$(VERSION)-$(RELEASE)_$(ARCH).tgz: $(OBJECTS) + $(info ***** Create build direcotry *****) ( mkdir -p $(DISTDIR) ; \ install -d $(STAGEDIR)/etc/init.d/ ; \ install -m 755 $(SOURCEDIR)/xe-linux-distribution.init $(STAGEDIR)/etc/init.d/xe-linux-distribution ; \ @@ -66,18 +72,21 @@ $(DISTDIR)/$(PACKAGE)_$(VERSION)-$(RELEASE)_$(ARCH).tgz: $(OBJECTS) install -d $(STAGEDIR)/etc/udev/rules.d/ ; \ install -m 644 $(SOURCEDIR)/xen-vcpu-hotplug.rules $(STAGEDIR)/etc/udev/rules.d/z10_xen-vcpu-hotplug.rules ; \ cd $(STAGEDIR) ; \ - tar cf $@ * \ + tar zcf $@ * \ ) $(OBJECTDIR)/xe-daemon: $(XE_DAEMON_SOURCES:%=$(GOBUILDDIR)/%) + $(info ***** Build xe-daemon ******) mkdir -p $(OBJECTDIR) $(GO_BUILD) $(GO_FLAGS) -o $@ $< -$(OBJECTDIR)/xenstore: $(XENSTORE_SOURCES:%=$(GOBUILDDIR)/%) $(GOROOT) +$(OBJECTDIR)/xenstore: $(XENSTORE_SOURCES:%=$(GOBUILDDIR)/%) + $(info ***** Build xenstore ******) mkdir -p $(OBJECTDIR) $(GO_BUILD) $(GO_FLAGS) -o $@ $< $(GOBUILDDIR)/%: $(REPO)/% + $(info ****** Replace product version for: [$<] *****) mkdir -p $$(dirname $@) cat $< | \ sed -e "s/@PRODUCT_MAJOR_VERSION@/$(PRODUCT_MAJOR_VERSION)/g" | \ @@ -85,4 +94,3 @@ $(GOBUILDDIR)/%: $(REPO)/% sed -e "s/@PRODUCT_MICRO_VERSION@/$(PRODUCT_MICRO_VERSION)/g" | \ sed -e "s/@NUMERIC_BUILD_NUMBER@/$(RELEASE)/g" \ > $@ - diff --git a/README.md b/README.md index 0cea099..2cf17f3 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,163 @@ [![Build Status](https://travis-ci.org/xenserver/xe-guest-utilities.svg?branch=master)](https://travis-ci.org/xenserver/xe-guest-utilities) -go-guest-utilites -=================== +# Introduction This is the golang guest utilities for XenServer +XenStore golang client library +----------- +xe-guest-utilities.git/xenstoreclient + + XenStore CLI ----------- xe-guest-utilities.git/xenstore -XenServer Guest Utilities +Guest Utilities ----------- xe-guest-utilities.git/xe-daemon -Build Instructions -=================== +# Build Instructions + [Go development environment](https://golang.org/doc/install) is required to build the guest utilities. -Type `make` or `make build` to build the xenstore and xe-daemon. +After commit [94942cd597e](https://github.com/xenserver/xe-guest-utilities/commit/94942cd597ede2fb27a6b6a85ee6de364f19882c) guest utilities not support version <= 1.11, with modern go versions (later than 1.11) we can build with below guides: +## Build with GO111MODULE=off +In this case, project and source files are expected to put in GOPATH/src +1. Make sure go is installed in your environment, and set correctly in $PATH +2. Setup your go environment configurations + +`GOROOT` +In newer versions, we don't need to set up the $GOROOT variable unless you use different Go versions + +`GOPATH` +Go gets librarys from the directory `GOPATH`, so for the build to work, you need read/write permissions there. With `GO111MODULE` disabled, $GOPATH directory are expected to has below hierarchy. +```bash +└── src + ├── github.com + │   └── xenserver + │   └── xe-guest-utilities + | + └── golang.org + └── x + └── sys +``` + +`GO111MODULE` +Set `GO111MODULE` disabled +e.g. +let's say your project directory is /home/xe-guest-utilities-7.30.0 +```bash +export GOPATH=/home/xe-guest-utilities-7.30.0 +export GO111MODULE=off +``` +3. Get the project + +```bash +git clone https://github.com/xenserver/xe-guest-utilities.git $GOPATH/src/github.com/xenserver/xe-guest-utilities +``` + +4. Get external library + +This project uses the `golang.org/x/sys/unix` library, you can use different methods to set the external library you use in your source code +```bash +go get -u golang.org/x/sys@latest +``` +or +```bash +git clone git@github.com:golang/sys.git $GOPATH/src/golang.org/x/sys +``` +5. Build +Go into the right directory `cd $GOPATH/src/github.com/xenserver/xe-guest-utilities` +now you can `make build` or `make`. Then you can get resulting files in `build/`, same layout as explained below +----------- +* The binarys will be in `build/obj` +* In `build/stage` are all required files and where they go when installed. +* In `build/dist` is a tarball with all files,symlinks and permissions. +----------- + +## Build with GO111MODULE=on + +In this case, we can place our project outside `$GOPATH` +1. Make sure go is installed in your environment, and set correctly in `$PATH` +2. Setup your go environment configurations + +`GOPATH` +Go gets librarys from the `GOPATH`, so for this to work, you need read/write permissions there.If in doubt, set `GOPATH` to a temporary location, ie: `export GOPATH=$(pwd)` sets `GOPATH` to the local folder + +`GO111MODULE` +With `GO111MODULE` enabled, go projects are no longer confined to $GOPATH, instead it use go.mod to keep track fo each package and it's version + +e.g. +let's say your project directory is /home/xe-guest-utilities-7.30.0 +```bash +# export GOPATH=/home/xe-guest-utilities-7.30.0 +# export GO111MODULE=on +``` +3. Get the project +```bash +git clone https://github.com/xenserver/xe-guest-utilities.git $GOPATH/xe-guest-utilities` +``` + +4. Set external library + +This project uses the `golang.org/x/sys/unix` library, you can use different method to set the external library +* Download to `$GOPATH` manually +```bash +git clone git@github.com:golang/sys.git $GOPATH/golang.org/x/sys +``` +And then add below content into `go.mod` before `require golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0` to manually point to the correct place to get module from the specific place. +```bash +replace golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 => ../golang.org/x/sys +``` +Then sync the vendor directory by `go mod vendor` + +* Use go module tool to get +Sync the vendor directory by `go mod vendor` +In this process go will download `golang.org/x/sys` of the version `v0.0.0-20210414055047-fe65e336abe0` to the the vendor directory and refresh `vendor/modules.txt` + +5. Build + +Go into the right directory `cd $GOPATH/xe-guest-utilities/`, then you can use `make build` or `make`. +resulting files are in `build/`, same layout as explained above + + +# Collected information, by lifetime + +## static + +* from /var/cache/xe-linux-distribution + * data/os_* +* compiled in + * attr/PVAddons/Installed = 1 + * attr/PVAddons/MajorVersion + * attr/PVAddons/MinorVersion + * attr/PVAddons/MicroVersion + * attr/PVAddons/BuildVersion +* runtime-dependant + * control/feature-balloon = [01] + +## changes on event (network config, hotplug, resume, migration...) + +* from ifconfig/ip + * attr/vif/$VIFID/ipv[46]/%d = $ADDR + * xenserver/attr/net-sriov-vf/$VIFID/ipv[46]/%d = $ADDR +* from pvs, mount, /sys/block/, xenstore + * data/volumes/%d/... + * .../extents/0 = $BACKEND + * .../name = /dev/xvd$X$N($PARTUUID) or /dev/xvd$X$N + * .../size = $SIZE_IN_BYTES + * .../mount_points/0 = $DIR or "[LVM]" + * .../filesystem = $FSTYPE +* from /proc/meminfo + * data/meminfo_total (or even static?) + +## ephemeral +* from /proc/meminfo + * data/meminfo_free +* from pvs or free + * data/volumes/%d/free +* data/updated: date of last update \ No newline at end of file diff --git a/analyze.py b/analyze.py index abea29f..4739b68 100644 --- a/analyze.py +++ b/analyze.py @@ -9,14 +9,14 @@ def cnt_on_rule_id(issues, rule_id): def write_issue(f, issue, idx): f.write('Issue %d\\n' % idx) - for k, v in issue.iteritems(): + for k, v in issue.items(): f.write('|%s|%s|\\n' % (k, v)) def analyze(js, formatted_issues_f): issues = js['Issues'] if not issues: - print "Security check: no security issue detected" + print("Security check: no security issue detected") return 0 for issue in issues: @@ -36,16 +36,16 @@ def analyze(js, formatted_issues_f): with open(formatted_issues_f, 'w') as f: idx = 1 f.write('\\n*Must fix issues*\\n') - print '======== Must fix the potential security issues ========' + print('======== Must fix the potential security issues ========') for issue in must_fix: - print json.dumps(issue, indent=4) + print(json.dumps(issue, indent=4)) write_issue(f, issue, idx) idx += 1 f.write('\\n----\\n*Optinal fix issues*\\n') - print '======== Optional to fix the potential security issues ========' + print('======== Optional to fix the potential security issues ========') for issue in better_fix: - print json.dumps(issue, indent=4) + print(json.dumps(issue, indent=4)) write_issue(f, issue, idx) idx += 1 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3934b43 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/xenserver/xe-guest-utilities + +go 1.19 + +require golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..29942b0 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 h1:g9s1Ppvvun/fI+BptTMj909BBIcGrzQ32k9FNlcevOE= +golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/guestmetric/guestmetric_linux.go b/guestmetric/guestmetric_linux.go index e61ccca..609869c 100644 --- a/guestmetric/guestmetric_linux.go +++ b/guestmetric/guestmetric_linux.go @@ -1,10 +1,10 @@ package guestmetric import ( - xenstoreclient "../xenstoreclient" "bufio" "bytes" "fmt" + xenstoreclient "github.com/xenserver/xe-guest-utilities/xenstoreclient" "os" "path/filepath" "regexp" @@ -57,18 +57,24 @@ func (c *Collector) CollectMisc() (GuestMetric, error) { func (c *Collector) CollectMemory() (GuestMetric, error) { current := make(GuestMetric, 0) - f, err := os.OpenFile("/proc/meminfo", os.O_RDONLY, 0666) + f, err := os.Open("/proc/meminfo") if err != nil { return nil, err } defer f.Close() scanner := bufio.NewScanner(f) + foundMemAvailabel := false for scanner.Scan() { parts := regexp.MustCompile(`\w+`).FindAllString(scanner.Text(), -1) switch parts[0] { case "MemTotal": current["meminfo_total"] = parts[1] case "MemFree": + if !foundMemAvailabel{ + current["meminfo_free"] = parts[1] + } + case "MemAvailable": + foundMemAvailabel = true current["meminfo_free"] = parts[1] } } @@ -182,7 +188,7 @@ func (c *Collector) CollectNetworkAddr() (GuestMetric, error) { current := make(GuestMetric, 0) var paths []string - vifNamePrefixList := [...]string{"eth", "eno", "ens", "emp", "enx"} + vifNamePrefixList := [...]string{"eth", "eno", "ens", "emp", "enx", "enX"} for _, prefix := range vifNamePrefixList { prefixPaths, err := filepath.Glob(fmt.Sprintf("/sys/class/net/%s*", prefix)) if err != nil { @@ -250,7 +256,7 @@ func (c *Collector) CollectDisk() (GuestMetric, error) { return nil, err } blocksize := 512 - if bs, err := readSysfs(fmt.Sprintf("/sys/block/%s/queue/physical_block_size", p)); err == nil { + if bs, err := readSysfs(fmt.Sprintf("/sys/block/%s/queue/physical_block_size", disk)); err == nil { if bs1, err := strconv.Atoi(bs); err == nil { blocksize = bs1 } diff --git a/mk/Citrix.repo b/mk/Citrix.repo deleted file mode 100644 index a3414b8..0000000 --- a/mk/Citrix.repo +++ /dev/null @@ -1,7 +0,0 @@ -[citrix] -name=@PRODUCT_BRAND@ @PRODUCT_VERSION@ updates for ^DISTRO^ -mirrorlist=http://updates.vmd.citrix.com/@PRODUCT_BRAND@/@PRODUCT_VERSION@/^DISTRO^/mirrorlist -#baseurl=http://updates.vmd.citrix.com/@PRODUCT_BRAND@/@PRODUCT_VERSION@/^DISTRO^/ -gpgcheck=1 -gpgkey=http://updates.vmd.citrix.com/@PRODUCT_BRAND@/RPM-GPG-KEY-@PRODUCT_VERSION@ -enabled=1 diff --git a/mk/Makefile.deb b/mk/Makefile.deb index c435c31..0a99175 100644 --- a/mk/Makefile.deb +++ b/mk/Makefile.deb @@ -52,11 +52,9 @@ SOURCES += $(SOURCEDIR)/xe-linux-distribution SOURCES += $(SOURCEDIR)/xe-daemon SOURCES += $(SOURCEDIR)/xenstore SOURCES += $(SOURCEDIR)/LICENSE -SOURCES += $(SOURCEDIR)/citrix.list SOURCES += $(SOURCEDIR)/xen-vcpu-hotplug.rules SOURCES += $(DEBIANDIR)/xe-linux-distribution.init SOURCES += $(DEBIANDIR)/xe-guest-utilities.postinst -SOURCES += $(DEBIANDIR)/xe-guest-utilities.prerm SOURCES += $(DEBIANDIR)/control SOURCES += $(DEBIANDIR)/changelog SOURCES += $(DEBIANDIR)/rules @@ -95,9 +93,6 @@ $(SOURCEDIR)/%: $(REPO)/mk/% mkdir -p $(SOURCEDIR) $(call brand,$<) | $(call local-brand) > $@ -$(SOURCEDIR)/citrix.list: citrix.list - $(call brand,$<) > $@ - $(SOURCEDIR)/xe-daemon: $(XE_DAEMON_GO_SOURCES:%=$(GOBUILDDIR)/%) $(GOROOT) $(GOBIN) build $(GOFLAGS) -o $@ $< diff --git a/mk/Makefile.rpm b/mk/Makefile.rpm index 954fda6..7eddee6 100644 --- a/mk/Makefile.rpm +++ b/mk/Makefile.rpm @@ -50,7 +50,6 @@ SOURCES += $(RPM_SOURCESDIR)/xe-linux-distribution.init SOURCES += $(RPM_SOURCESDIR)/xe-daemon SOURCES += $(RPM_SOURCESDIR)/xenstore -SOURCES += $(RPM_SOURCESDIR)/Citrix.repo SOURCES += $(RPM_SOURCESDIR)/xen-vcpu-hotplug.rules SOURCES += $(RPM_SOURCESDIR)/LICENSE diff --git a/mk/Makefile.tgz b/mk/Makefile.tgz index db2d327..e538a18 100644 --- a/mk/Makefile.tgz +++ b/mk/Makefile.tgz @@ -53,7 +53,6 @@ SOURCES += $(SOURCEDIR)/xe-linux-distribution SOURCES += $(SOURCEDIR)/xe-linux-distribution.init SOURCES += $(SOURCEDIR)/xe-daemon SOURCES += $(SOURCEDIR)/xenstore -SOURCES += $(SOURCEDIR)/citrix.list SOURCES += $(SOURCEDIR)/xen-vcpu-hotplug.rules 822_DATE := $(shell date -R) @@ -78,8 +77,6 @@ $(SOURCEDIR)/%: $(REPO)/mk/% mkdir -p $(SOURCEDIR) $(call brand,$<) | $(call local-brand) > $@ -$(SOURCEDIR)/citrix.list: citrix.list - $(call brand,$<) > $@ $(SOURCEDIR)/xe-daemon: $(XE_DAEMON_GO_SOURCES:%=$(GOBUILDDIR)/%) $(GOROOT) $(GOBIN) build $(GOFLAGS) -o $@ $< diff --git a/mk/citrix.list b/mk/citrix.list deleted file mode 100644 index 4bf18c5..0000000 --- a/mk/citrix.list +++ /dev/null @@ -1,2 +0,0 @@ -deb http://updates.vmd.citrix.com/@PRODUCT_BRAND@/@PRODUCT_VERSION@/debian/ ^DISTRO^ main -deb-src http://updates.vmd.citrix.com/@PRODUCT_BRAND@/@PRODUCT_VERSION@/debian/ ^DISTRO^ main diff --git a/mk/debian/control b/mk/debian/control index 7d00985..bb0e0d6 100644 --- a/mk/debian/control +++ b/mk/debian/control @@ -1,7 +1,7 @@ Source: xe-guest-utilities Section: main/admin Priority: optional -Maintainer: Citrix Systems, Inc. +Maintainer: Cloud Software Group Holdings, Inc. Standards-Version: 3.7.2 Build-Depends: debhelper (>= 4.0.0) diff --git a/mk/debian/rules b/mk/debian/rules index afc341c..51fb04b 100644 --- a/mk/debian/rules +++ b/mk/debian/rules @@ -26,14 +26,14 @@ binary-arch: build install -d $(DESTDIR)/usr/bin/ install -m 755 xenstore $(DESTDIR)/usr/bin/xenstore - ln -s /usr/bin/xenstore $(DESTDIR)/usr/bin/xenstore-read - ln -s /usr/bin/xenstore $(DESTDIR)/usr/bin/xenstore-write - ln -s /usr/bin/xenstore $(DESTDIR)/usr/bin/xenstore-exists - ln -s /usr/bin/xenstore $(DESTDIR)/usr/bin/xenstore-rm - ln -s /usr/bin/xenstore $(DESTDIR)/usr/bin/xenstore-list - ln -s /usr/bin/xenstore $(DESTDIR)/usr/bin/xenstore-ls - ln -s /usr/bin/xenstore $(DESTDIR)/usr/bin/xenstore-chmod - ln -s /usr/bin/xenstore $(DESTDIR)/usr/bin/xenstore-watch + ln -s xenstore $(DESTDIR)/usr/bin/xenstore-read + ln -s xenstore $(DESTDIR)/usr/bin/xenstore-write + ln -s xenstore $(DESTDIR)/usr/bin/xenstore-exists + ln -s xenstore $(DESTDIR)/usr/bin/xenstore-rm + ln -s xenstore $(DESTDIR)/usr/bin/xenstore-list + ln -s xenstore $(DESTDIR)/usr/bin/xenstore-ls + ln -s xenstore $(DESTDIR)/usr/bin/xenstore-chmod + ln -s xenstore $(DESTDIR)/usr/bin/xenstore-watch cp xe-daemon $(DESTDIR)/usr/sbin/xe-daemon chmod 0755 $(DESTDIR)/usr/sbin/xe-daemon @@ -42,8 +42,6 @@ binary-arch: build dh_installinit --name xe-linux-distribution - dh_install citrix.list /usr/share/xe-guest-utilities - dh_installdocs LICENSE dh_strip diff --git a/mk/debian/xe-guest-utilities.postinst b/mk/debian/xe-guest-utilities.postinst index 8b19a52..fb93e9b 100755 --- a/mk/debian/xe-guest-utilities.postinst +++ b/mk/debian/xe-guest-utilities.postinst @@ -12,9 +12,6 @@ if [ X"$1" = X"configure" ] ; then esac if [ -n "${distro}" ] ; then rm -f /etc/apt/sources.list.d/xensource.list # contains deprecated urls - sed -e "s/\^DISTRO\^/${distro}/g" \ - < /usr/share/xe-guest-utilities/citrix.list \ - > /etc/apt/sources.list.d/citrix.list fi fi fi diff --git a/mk/debian/xe-guest-utilities.prerm b/mk/debian/xe-guest-utilities.prerm deleted file mode 100755 index 68f2184..0000000 --- a/mk/debian/xe-guest-utilities.prerm +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -if [ X"$1" = X"remove" ] && [ -e /etc/apt/sources.list.d/citrix.list ] ; then - rm /etc/apt/sources.list.d/citrix.list -fi - -#DEBHELPER# diff --git a/mk/testcases/almalinux-8.3 b/mk/testcases/almalinux-8.3 new file mode 100644 index 0000000..e2e01fd --- /dev/null +++ b/mk/testcases/almalinux-8.3 @@ -0,0 +1 @@ +AlmaLinux release 8.3 (Purple Manul) diff --git a/mk/testcases/centos-stream-8 b/mk/testcases/centos-stream-8 new file mode 100644 index 0000000..c1171d1 --- /dev/null +++ b/mk/testcases/centos-stream-8 @@ -0,0 +1 @@ +CentOS Stream release 8 diff --git a/mk/testcases/centos5 b/mk/testcases/centos5 deleted file mode 100644 index e1d8ca0..0000000 --- a/mk/testcases/centos5 +++ /dev/null @@ -1 +0,0 @@ -CentOS release 5 (Final) diff --git a/mk/testcases/centos6.10 b/mk/testcases/centos6.10 new file mode 100644 index 0000000..d87bfa9 --- /dev/null +++ b/mk/testcases/centos6.10 @@ -0,0 +1 @@ +CentOS Linux release 6.10 \ No newline at end of file diff --git a/mk/testcases/centos7 b/mk/testcases/centos7 new file mode 100644 index 0000000..4319cd9 --- /dev/null +++ b/mk/testcases/centos7 @@ -0,0 +1 @@ +CentOS Linux release 7.0.1406 (Core) diff --git a/mk/testcases/centos7.9 b/mk/testcases/centos7.9 new file mode 100644 index 0000000..2c36b44 --- /dev/null +++ b/mk/testcases/centos7.9 @@ -0,0 +1 @@ +CentOS Linux release 7.9.2009 (Core) diff --git a/mk/testcases/debian-10.6 b/mk/testcases/debian-10.6 new file mode 100644 index 0000000..12c0281 --- /dev/null +++ b/mk/testcases/debian-10.6 @@ -0,0 +1 @@ +10.6 diff --git a/mk/testcases/debian-sarge b/mk/testcases/debian-sarge deleted file mode 100644 index 8c50098..0000000 --- a/mk/testcases/debian-sarge +++ /dev/null @@ -1 +0,0 @@ -3.1 diff --git a/mk/testcases/debian10.13 b/mk/testcases/debian10.13 new file mode 100644 index 0000000..4e31022 --- /dev/null +++ b/mk/testcases/debian10.13 @@ -0,0 +1 @@ +10.13 diff --git a/mk/testcases/debian11.6 b/mk/testcases/debian11.6 new file mode 100644 index 0000000..1ed6da4 --- /dev/null +++ b/mk/testcases/debian11.6 @@ -0,0 +1 @@ +11.6 diff --git a/mk/testcases/gooroom2 b/mk/testcases/gooroom2 new file mode 100644 index 0000000..3649ff6 --- /dev/null +++ b/mk/testcases/gooroom2 @@ -0,0 +1,5 @@ +DISTRIB_ID=Gooroom +DISTRIB_RELEASE=2.0 +DISTRIB_CODENAME=gooroom-2.0-unstable +BASE_DISTRIB_CODENAME=buster +DISTRIB_DESCRIPTION="Gooroom Platform 2.0" diff --git a/mk/testcases/lsb-coreos-367.1.0 b/mk/testcases/lsb-coreos-367.1.0 deleted file mode 100644 index b5ebcc7..0000000 --- a/mk/testcases/lsb-coreos-367.1.0 +++ /dev/null @@ -1,4 +0,0 @@ -DISTRIB_ID=CoreOS -DISTRIB_RELEASE=367.1.0 -DISTRIB_CODENAME="Red Dog" -DISTRIB_DESCRIPTION="CoreOS 367.1.0" \ No newline at end of file diff --git a/mk/testcases/lsb-ubuntu-6.10 b/mk/testcases/lsb-ubuntu-6.10 deleted file mode 100644 index 5a6f488..0000000 --- a/mk/testcases/lsb-ubuntu-6.10 +++ /dev/null @@ -1,3 +0,0 @@ -ID="Ubuntu" -DESCRPITON="Ubuntu 6.10" -RELEASE="6.10" diff --git a/mk/testcases/lsb-ubuntu-7.04 b/mk/testcases/lsb-ubuntu-7.04 deleted file mode 100644 index c857156..0000000 --- a/mk/testcases/lsb-ubuntu-7.04 +++ /dev/null @@ -1,3 +0,0 @@ -ID="Ubuntu" -DESCRIPTION="Ubuntu 7.04" -RELEASE="7.04" diff --git a/mk/testcases/lsb-ubuntu1804 b/mk/testcases/lsb-ubuntu1804 new file mode 100644 index 0000000..e8ab606 --- /dev/null +++ b/mk/testcases/lsb-ubuntu1804 @@ -0,0 +1,4 @@ +DISTRIB_ID=Ubuntu +DISTRIB_RELEASE=18.04 +DISTRIB_CODENAME=bionic +DISTRIB_DESCRIPTION="Ubuntu 18.04.6 LTS" diff --git a/mk/testcases/lsb-ubuntu2004 b/mk/testcases/lsb-ubuntu2004 new file mode 100644 index 0000000..e3394f9 --- /dev/null +++ b/mk/testcases/lsb-ubuntu2004 @@ -0,0 +1,4 @@ +DISTRIB_ID=Ubuntu +DISTRIB_RELEASE=20.04 +DISTRIB_CODENAME=focal +DISTRIB_DESCRIPTION="Ubuntu 20.04.5 LTS" diff --git a/mk/testcases/lsb-ubuntu2204 b/mk/testcases/lsb-ubuntu2204 new file mode 100644 index 0000000..87045df --- /dev/null +++ b/mk/testcases/lsb-ubuntu2204 @@ -0,0 +1,4 @@ +DISTRIB_ID=Ubuntu +DISTRIB_RELEASE=22.04 +DISTRIB_CODENAME=jammy +DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS" diff --git a/mk/testcases/oracle-5 b/mk/testcases/oracle-5 deleted file mode 100644 index 542c826..0000000 --- a/mk/testcases/oracle-5 +++ /dev/null @@ -1 +0,0 @@ -Enterprise Linux Enterprise Linux Server release 5 (Carthage) diff --git a/mk/testcases/oracle-5u1 b/mk/testcases/oracle-5u1 deleted file mode 100644 index fad6c3c..0000000 --- a/mk/testcases/oracle-5u1 +++ /dev/null @@ -1 +0,0 @@ -Enterprise Linux Enterprise Linux Server release 5.1 (Carthage) diff --git a/mk/testcases/oracle7.9 b/mk/testcases/oracle7.9 new file mode 100644 index 0000000..1c41687 --- /dev/null +++ b/mk/testcases/oracle7.9 @@ -0,0 +1 @@ +Oracle Linux Server release 7.9 diff --git a/mk/testcases/oracle8.7 b/mk/testcases/oracle8.7 new file mode 100644 index 0000000..a6cd218 --- /dev/null +++ b/mk/testcases/oracle8.7 @@ -0,0 +1 @@ +Oracle Linux Server release 8.7 diff --git a/mk/testcases/rhel-3u6 b/mk/testcases/rhel-3u6 deleted file mode 100644 index 97004ce..0000000 --- a/mk/testcases/rhel-3u6 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux AS release 3 (Taroon Update 6) diff --git a/mk/testcases/rhel-3u8 b/mk/testcases/rhel-3u8 deleted file mode 100644 index 0d75450..0000000 --- a/mk/testcases/rhel-3u8 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux AS release 3 (Taroon Update 8) diff --git a/mk/testcases/rhel-4 b/mk/testcases/rhel-4 deleted file mode 100644 index 62e7d40..0000000 --- a/mk/testcases/rhel-4 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux AS release 4 (Nahant) diff --git a/mk/testcases/rhel-4u1 b/mk/testcases/rhel-4u1 deleted file mode 100644 index cf62351..0000000 --- a/mk/testcases/rhel-4u1 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux AS release 4 (Nahant Update 1) diff --git a/mk/testcases/rhel-4u2 b/mk/testcases/rhel-4u2 deleted file mode 100644 index 76100de..0000000 --- a/mk/testcases/rhel-4u2 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux AS release 4 (Nahant Update 2) diff --git a/mk/testcases/rhel-4u3 b/mk/testcases/rhel-4u3 deleted file mode 100644 index a258c65..0000000 --- a/mk/testcases/rhel-4u3 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux AS release 4 (Nahant Update 3) diff --git a/mk/testcases/rhel-4u4 b/mk/testcases/rhel-4u4 deleted file mode 100644 index 50ace04..0000000 --- a/mk/testcases/rhel-4u4 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux AS release 4 (Nahant Update 4) diff --git a/mk/testcases/rhel-4u5 b/mk/testcases/rhel-4u5 deleted file mode 100644 index cf83112..0000000 --- a/mk/testcases/rhel-4u5 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux ES release 4 (Nahant Update 5) diff --git a/mk/testcases/rhel-4u6 b/mk/testcases/rhel-4u6 deleted file mode 100644 index 51ad006..0000000 --- a/mk/testcases/rhel-4u6 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux AS release 4 (Nahant Update 6) diff --git a/mk/testcases/rhel-5beta b/mk/testcases/rhel-5beta deleted file mode 100644 index 1cb8fcf..0000000 --- a/mk/testcases/rhel-5beta +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux Server release 4.92 (Tikanga) diff --git a/mk/testcases/rhel-5u1 b/mk/testcases/rhel-5u1 deleted file mode 100644 index 5b6c571..0000000 --- a/mk/testcases/rhel-5u1 +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux Server release 5.1 (Tikanga) diff --git a/mk/testcases/rhel-5u1beta b/mk/testcases/rhel-5u1beta deleted file mode 100644 index 65824b5..0000000 --- a/mk/testcases/rhel-5u1beta +++ /dev/null @@ -1 +0,0 @@ -Red Hat Enterprise Linux Server release 5.1 Beta (Tikanga) diff --git a/mk/testcases/rhel7.9 b/mk/testcases/rhel7.9 new file mode 100644 index 0000000..db5baab --- /dev/null +++ b/mk/testcases/rhel7.9 @@ -0,0 +1 @@ +Red Hat Enterprise Linux Server release 7.9 (Maipo) diff --git a/mk/testcases/rhel8.7 b/mk/testcases/rhel8.7 new file mode 100644 index 0000000..ee27316 --- /dev/null +++ b/mk/testcases/rhel8.7 @@ -0,0 +1 @@ +Red Hat Enterprise Linux release 8.7 (Ootpa) diff --git a/mk/testcases/rocky-8.3 b/mk/testcases/rocky-8.3 new file mode 100644 index 0000000..3e45eec --- /dev/null +++ b/mk/testcases/rocky-8.3 @@ -0,0 +1 @@ +Rocky Linux release 8.3 diff --git a/mk/testcases/rocky8.7 b/mk/testcases/rocky8.7 new file mode 100644 index 0000000..118e8fb --- /dev/null +++ b/mk/testcases/rocky8.7 @@ -0,0 +1 @@ +Rocky Linux release 8.7 (Green Obsidian) diff --git a/mk/testcases/scientific7.6 b/mk/testcases/scientific7.6 new file mode 100644 index 0000000..0ca5cd1 --- /dev/null +++ b/mk/testcases/scientific7.6 @@ -0,0 +1 @@ +Scientific Linux release 7.6 (Nitrogen) diff --git a/mk/testcases/slackware-15.0 b/mk/testcases/slackware-15.0 new file mode 100644 index 0000000..4cc0177 --- /dev/null +++ b/mk/testcases/slackware-15.0 @@ -0,0 +1,11 @@ +NAME=Slackware +VERSION="15.0" +ID=slackware +VERSION_ID=15.0 +PRETTY_NAME="Slackware 15.0 x86_64 (post 15.0 -current)" +ANSI_COLOR="0;34" +CPE_NAME="cpe:/o:slackware:slackware_linux:15.0" +HOME_URL="http://slackware.com/" +SUPPORT_URL="http://www.linuxquestions.org/questions/slackware-14/" +BUG_REPORT_URL="http://www.linuxquestions.org/questions/slackware-14/" +VERSION_CODENAME=current \ No newline at end of file diff --git a/mk/testcases/sles-10sp2 b/mk/testcases/sles-10sp2 deleted file mode 100644 index a01febe..0000000 --- a/mk/testcases/sles-10sp2 +++ /dev/null @@ -1,3 +0,0 @@ -SUSE Linux Enterprise Server 10 (i586) -VERSION = 10 -PATCHLEVEL = 2 diff --git a/mk/testcases/sles-11 b/mk/testcases/sles-11 deleted file mode 100644 index d2ec72d..0000000 --- a/mk/testcases/sles-11 +++ /dev/null @@ -1,3 +0,0 @@ -SUSE Linux Enterprise Server 11 (i586) -VERSION = 11 -PATCHLEVEL = 0 diff --git a/mk/testcases/sles-9sp3 b/mk/testcases/sles-9sp3 deleted file mode 100644 index 8f66b47..0000000 --- a/mk/testcases/sles-9sp3 +++ /dev/null @@ -1,3 +0,0 @@ -SUSE LINUX Enterprise Server 9 (i586) -VERSION = 9 -PATCHLEVEL = 3 diff --git a/mk/testcases/sles12sp4 b/mk/testcases/sles12sp4 new file mode 100644 index 0000000..bde50e8 --- /dev/null +++ b/mk/testcases/sles12sp4 @@ -0,0 +1,7 @@ +NAME="SLES" +VERSION="12-SP4" +VERSION_ID="12.4" +PRETTY_NAME="SUSE Linux Enterprise Server 12 SP4" +ID="sles" +ANSI_COLOR="0;32" +CPE_NAME="cpe:/o:suse:sles:12:sp4" diff --git a/mk/testcases/sles12sp5 b/mk/testcases/sles12sp5 new file mode 100644 index 0000000..2de3f28 --- /dev/null +++ b/mk/testcases/sles12sp5 @@ -0,0 +1,7 @@ +NAME="SLES" +VERSION="12-SP5" +VERSION_ID="12.5" +PRETTY_NAME="SUSE Linux Enterprise Server 12 SP5" +ID="sles" +ANSI_COLOR="0;32" +CPE_NAME="cpe:/o:suse:sles:12:sp5" diff --git a/mk/testcases/sles15sp2 b/mk/testcases/sles15sp2 new file mode 100644 index 0000000..54fafb5 --- /dev/null +++ b/mk/testcases/sles15sp2 @@ -0,0 +1,8 @@ +NAME="SLES" +VERSION="15-SP2" +VERSION_ID="15.2" +PRETTY_NAME="SUSE Linux Enterprise Server 15 SP2" +ID="sles" +ID_LIKE="suse" +ANSI_COLOR="0;32" +CPE_NAME="cpe:/o:suse:sles:15:sp2" diff --git a/mk/testcases/sles15sp4 b/mk/testcases/sles15sp4 new file mode 100644 index 0000000..022837e --- /dev/null +++ b/mk/testcases/sles15sp4 @@ -0,0 +1,9 @@ +NAME="SLES" +VERSION="15-SP4" +VERSION_ID="15.4" +PRETTY_NAME="SUSE Linux Enterprise Server 15 SP4" +ID="sles" +ID_LIKE="suse" +ANSI_COLOR="0;32" +CPE_NAME="cpe:/o:suse:sles:15:sp4" +DOCUMENTATION_URL="https://documentation.suse.com/" diff --git a/mk/xe-guest-utilities.spec.in b/mk/xe-guest-utilities.spec.in index 33392bc..009cf25 100644 --- a/mk/xe-guest-utilities.spec.in +++ b/mk/xe-guest-utilities.spec.in @@ -11,7 +11,6 @@ Vendor: @COMPANY_NAME_LEGAL@ Source0: xe-linux-distribution Source1: xe-linux-distribution.init Source3: xe-daemon -Source5: Citrix.repo Source6: xenstore Source8: LICENSE Source9: xen-vcpu-hotplug.rules @@ -42,6 +41,7 @@ mkdir -p %{buildroot}/usr/sbin/ mkdir -p %{buildroot}/usr/share/doc/%{name}-%{version}/examples/ mkdir -p %{buildroot}/etc/init.d mkdir -p %{buildroot}/etc/udev/rules.d +mkdir -p %{buildroot}/usr/lib/systemd/system cp %{SOURCE0} %{buildroot}/usr/sbin/xe-linux-distribution chmod 755 %{buildroot}/usr/sbin/xe-linux-distribution @@ -52,14 +52,21 @@ chmod 755 %{buildroot}/etc/init.d/xe-linux-distribution cp %{SOURCE3} %{buildroot}/usr/sbin/xe-daemon chmod 755 %{buildroot}/usr/sbin/xe-daemon +cp mk/xe-linux-distribution.service %{buildroot}/usr/lib/systemd/system/xe-linux-distribution.service +chmod 644 %{buildroot}/usr/lib/systemd/system/xe-linux-distribution.service + cp %{SOURCE5} %{buildroot}/usr/share/doc/%{name}-%{version}/examples/ install -d %{buildroot}/usr/bin/ install -m 755 %{SOURCE6} %{buildroot}/usr/bin/xenstore -ln -s /usr/bin/xenstore %{buildroot}/usr/bin/xenstore-read -ln -s /usr/bin/xenstore %{buildroot}/usr/bin/xenstore-write -ln -s /usr/bin/xenstore %{buildroot}/usr/bin/xenstore-exists -ln -s /usr/bin/xenstore %{buildroot}/usr/bin/xenstore-rm +ln -s xenstore %{buildroot}/usr/bin/xenstore-read +ln -s xenstore %{buildroot}/usr/bin/xenstore-write +ln -s xenstore %{buildroot}/usr/bin/xenstore-exists +ln -s xenstore %{buildroot}/usr/bin/xenstore-rm +ln -s xenstore %{buildroot}/usr/bin/xenstore-list +ln -s xenstore %{buildroot}/usr/bin/xenstore-ls +ln -s xenstore %{buildroot}/usr/bin/xenstore-chmod +ln -s xenstore %{buildroot}/usr/bin/xenstore-watch cp %{SOURCE9} %{buildroot}/etc/udev/rules.d/z10-xen-vcpu-hotplug.rules @@ -72,8 +79,16 @@ cp %{SOURCE8} %{buildroot}/usr/share/doc/%{name}-xenstore-%{version}/ rm -rf %{buildroot} %post -/sbin/chkconfig --add xe-linux-distribution >/dev/null -[ -n "${EXTERNAL_P2V}" ] || service xe-linux-distribution start >/dev/null 2>&1 +#!/bin/bash +if command -v systemctl >/dev/null 2>&1; then + xe_install_path=/usr/sbin + sed -i "s#/usr/share/oem/xs#$xe_install_path#g" /usr/lib/systemd/system/xe-linux-distribution.service + systemctl enable /usr/lib/systemd/system/xe-linux-distribution.service >/dev/null 2>&1 + systemctl start xe-linux-distribution.service >/dev/null 2>&1 +else + /sbin/chkconfig --add xe-linux-distribution >/dev/null + [ -n "${EXTERNAL_P2V}" ] || service xe-linux-distribution start >/dev/null 2>&1 +fi eval $(/usr/sbin/xe-linux-distribution) @@ -84,14 +99,6 @@ if [ -d /etc/yum.repos.d ] && [ -n "${os_distro}" ] && [ -n "${os_majorver}" ] ; if [ -f /etc/yum.repos.d/XenSource.repo ] ; then rm -f /etc/yum.repos.d/XenSource.repo # contains deprecated urls fi - sed -e "s/\^DISTRO\^/${distro}/g" \ - < /usr/share/doc/%{name}-%{version}/examples/Citrix.repo \ - > /etc/yum.repos.d/Citrix.repo - ;; - rhel3x|rhel5x|centos5x|oracle5x) # No vendor kernel any more. Remove Citrix.repo - if [ -f /etc/yum.repos.d/Citrix.repo ] ; then - rm -f /etc/yum.repos.d/Citrix.repo - fi ;; *) ;; esac @@ -99,9 +106,13 @@ fi %preun if [ $1 -eq 0 ] ; then - service xe-linux-distribution stop >/dev/null 2>&1 - /sbin/chkconfig --del xe-linux-distribution >/dev/null - rm -f /etc/yum.repos.d/Citrix.repo || /bin/true + if command -v systemctl >/dev/null 2>&1; then + systemctl stop xe-linux-distribution.service >/dev/null 2>&1 + systemctl disable xe-linux-distribution.service >/dev/null 2>&1 + else + service xe-linux-distribution stop >/dev/null 2>&1 + /sbin/chkconfig --del xe-linux-distribution >/dev/null + fi fi %files @@ -110,8 +121,8 @@ fi /etc/init.d/xe-linux-distribution /usr/sbin/xe-daemon /etc/udev/rules.d/z10-xen-vcpu-hotplug.rules -/usr/share/doc/%{name}-%{version}/examples/Citrix.repo /usr/share/doc/%{name}-%{version}/LICENSE +/usr/lib/systemd/system/xe-linux-distribution.service %files xenstore %defattr(-,root,root,-) diff --git a/mk/xe-linux-distribution b/mk/xe-linux-distribution index 097cc70..f8031d9 100755 --- a/mk/xe-linux-distribution +++ b/mk/xe-linux-distribution @@ -1,6 +1,6 @@ #! /bin/sh -# Copyright (c) 2015, Citrix Systems +# Copyright (c) 2022, Cloud Software Group Holdings, Inc. # All rights reserved. # Redistribution and use in source and binary forms, with or without modification, @@ -43,12 +43,12 @@ write_to_output() local uname=$(uname -r) if [ -n "${TEST_RESULT}" ] ; then - MAJOR=$major - MINOR=$minor - DISTRO=$distro - UNAME=$uname - NAME=$name - return 0 + MAJOR=$major + MINOR=$minor + DISTRO=$distro + UNAME=$uname + NAME=$name + return 0 fi echo "os_distro=\"${distro}\"" @@ -71,7 +71,7 @@ identify_debian() # Ignores testing and unstable which contain ".*/sid". if [ ! -f "${debian_version}" ] ; then - return 1 + return 1 fi eval $(awk -F. '/^[0-9]*\.[0-9]*/ \ @@ -79,7 +79,7 @@ identify_debian() "${debian_version}") if [ -z "${major}" ] && [ -z "${minor}" ] && ! grep -q /sid "${debian_version}" ; then - return 1 + return 1 fi write_to_output "debian" "${major}" "${minor}" "Debian $(head -n 1 $debian_version)" @@ -123,6 +123,10 @@ identify_redhat() # CentOS release 4.0 (Final) # CentOS release 5 (Final) # CentOS Linux release 7.0.1406 (Core) + # CentOS Stream release 8 + + # distro=rocky + # Rocky Linux release 8.3 # distro=cloudlinux # CloudLinux Server release 6.10 (Vladimir Lyakhov) @@ -137,8 +141,11 @@ identify_redhat() # Enterprise Linux Enterprise Linux Server release 5.5 (Carthage) # Oracle Linux Server release 5.6 + # distro=almalinux + # AlmaLinux release 8.3 (Purple Manul) + if [ ! -f "${redhat_release}" ] ; then - return 1 + return 1 fi eval $(sed -nr \ @@ -152,14 +159,17 @@ identify_redhat() -e 's/^Fedora.*release \([0-9]*\) (.*)$/distro=fedora;major=\1/gp;' \ -e 's/^CentOS release \([0-9]*\)\.\([0-9]*\) (.*)/distro=centos;major=\1;minor=\2/gp;' \ -e 's/^CentOS release \([0-9]*\) (.*)/distro=centos;major=\1/gp;' \ - -e 's/^CentOS Linux release \([0-9]*\)\.\([0-9]*\)\(\.[0-9]*\)\? (.*)/distro=centos;major=\1;minor=\2/gp;' \ - -e 's/^CloudLinux\( Linux|Server\)\? release \([0-9]*\)\.\([0-9]*\)\(\.[0-9]*\)\? (.*)/distro=cloudlinux;major=\2;minor=\1/gp;' \ - -e 's/^CloudLinux release \([0-9]*\)\.\([0-9]*\)\(\.[0-9]*\)\? (.*)/distro=cloudlinux;major=\1;minor=\2/gp;' \ + -e 's/^CentOS Linux release \([0-9]*\)\.\([0-9]*\).*$/distro=centos;major=\1;minor=\2/gp;' \ + -e 's/^CentOS Stream release \([0-9]*\).*$/distro=centos;major=\1/gp;' \ + -e 's/^CloudLinux\( Linux|Server\)\? release \([0-9]*\)\.\([0-9]*\)\(\.[0-9]*\)\? (.*)/distro=cloudlinux;major=\2;minor=\1/gp;' \ + -e 's/^CloudLinux release \([0-9]*\)\.\([0-9]*\)\(\.[0-9]*\)\? (.*)/distro=cloudlinux;major=\1;minor=\2/gp;' \ + -e 's/^Rocky Linux release \([0-9]*\)\.\([0-9]*\).*$/distro=rocky;major=\1;minor=\2/gp;' \ -e 's/^Enterprise Linux Enterprise Linux .* release \([0-9]*\)\.\([0-9]*\) (.*)$/distro=oracle;major=\1;minor=\2;/gp;' \ -e 's/^Enterprise Linux Enterprise Linux .* release \([0-9]*\) (.*)$/distro=oracle;major=\1/gp;' \ -e 's/^Oracle Linux Server release \([0-9]*\)\.\([0-9]*\)$/distro=oracle;major=\1;minor=\2/gp;' \ -e 's/^Scientific Linux SL release \([0-9]*\)\.\([0-9]*\) (.*)$/distro=scientific;major=\1;minor=\2;/gp;' \ -e 's/^Scientific Linux release \([0-9]*\)\.\([0-9]*\) (.*)$/distro=scientific;major=\1;minor=\2;/gp;' \ + -e 's/^AlmaLinux release \([0-9]*\)\.\([0-9]*\) (.*)$/distro=almalinux;major=\1;minor=\2;/gp;' \ "${redhat_release}") if [ -z "${major}" -o -z "${distro}" ] ; then @@ -172,13 +182,13 @@ identify_redhat() # HACK to handle RHEL betas if [ "${distro}" == "rhel" ] && [ ${minor} -gt 90 ] ; then - major=$(expr ${major} + 1 ) - minor=0 - beta=Beta + major=$(expr ${major} + 1 ) + minor=0 + beta=Beta fi if [ -n "${beta}" ] ; then - minor="${minor}beta" + minor="${minor}beta" fi write_to_output "${distro}" "${major}" "${minor}" "$(head -n 1 ${redhat_release})" @@ -229,12 +239,12 @@ identify_sles() fi eval $(sed -n \ - -e 's/^VERSION_ID="\([0-9]*\)\.\?\([0-9]*\)\?"$/major=\1;minor=\2;/gp' \ - -e 's/^PRETTY_NAME="SUSE L\(inux\|INUX\) Enterprise \([a-zA-Z0-9_]*\) \([0-9]*\)\( SP[0-9]*\)\?"/_major=\3;_pretty_name=\0;/gp' \ + -e 's/^VERSION_ID="\([0-9]*\)\.\?\([0-9]*\)\?"$/major=\1;minor=\2;/gp' \ + -e 's/^PRETTY_NAME="SUSE L\(inux\|INUX\) Enterprise \([a-zA-Z0-9_]*\) \([0-9]*\)\( SP[0-9]*\)\?"/_major=\3;_pretty_name=\0;/gp' \ -e 's/^SUSE L\(inux\|INUX\) Enterprise \([a-zA-Z0-9_]*\) \([0-9]*\) (.*)/_major=\3;_pretty_name="\0";/gp;' \ -e 's/^VERSION = \([0-9]*\)$/major=\1;/gp;' \ -e 's/^PATCHLEVEL = \([0-9]*\)$/minor=\1;/gp;' \ - "${suse_release}") + "${suse_release}") if [ -z "${major}" -o -z "${_major}" ] ; then return 1 @@ -245,7 +255,7 @@ identify_sles() fi if [ -z "${minor}" ] ; then - minor=0 + minor=0 fi write_to_output "sles" "${major}" "${minor}" "${_pretty_name##*=}" @@ -256,15 +266,15 @@ identify_lsb() lsb_release="$1" if [ ! -x "${lsb_release}" ] ; then - saved_IFS=$IFS - IFS=: - for i in $PATH ; do - if [ -x "${i}/${lsb_release}" ] ; then - lsb_release="${i}/${lsb_release}" - break - fi - done - IFS=$saved_IFS + saved_IFS=$IFS + IFS=: + for i in $PATH ; do + if [ -x "${i}/${lsb_release}" ] ; then + lsb_release="${i}/${lsb_release}" + break + fi + done + IFS=$saved_IFS fi if [ -x "${lsb_release}" ] ; then @@ -283,7 +293,7 @@ identify_lsb() fi if [ -z "${distro}" -o -z "${release}" ] ; then - return 1 + return 1 fi eval $(echo $release | awk -F. -- '{ subindex = index($0,"."); \ @@ -297,6 +307,37 @@ identify_lsb() write_to_output "${distro}" "${major}" "${minor}" "${description}" } +identify_os_release() +{ + os_release="$1" + local major + local minor + + # Use /etc/os-release to detect. + # NAME="SLES" + # VERSION="15" + # VERSION_ID="15" + # PRETTY_NAME="SUSE Linux Enterprise Server 15" + # ID="sles" + # ID_LIKE="suse" + # ANSI_COLOR="0;32" + # CPE_NAME="cpe:/o:suse:sles:15" + + if [ ! -f "${os_release}" ] ; then + return 1 + fi + + source "${os_release}" + + eval $(echo "$VERSION_ID" | \ + sed -n -e 's/^\([0-9]*\)\.\?\([0-9]*\).*$/major=\1;minor=\2;/gp') + + major="${major:-unknown}" + minor="${minor:-unknown}" + + write_to_output "${ID}" "${major}" "${minor}" "${PRETTY_NAME}" +} + identify_kylin() { kylin_release="$1" @@ -342,7 +383,7 @@ identify_asianux() # 'Asianux Server 4 (Hiranya SP4)' if [ ! -f "${asianux_release}" ] ; then - return 1 + return 1 fi eval $(sed -rn \ @@ -372,7 +413,7 @@ identify_turbo() # GreatTurbo Enterprise Server release 12.2 (Theseus) if [ ! -f "${turbo_release}" ] ; then - return 1 + return 1 fi eval $(sed -rn \ @@ -403,7 +444,7 @@ identify_linx() if [ ! -f "${linx_release}" ] ; then - return 1 + return 1 fi eval $(sed -rn \ @@ -433,7 +474,7 @@ identify_yinhe() # Kylin 4.0 if [ ! -f "${yinhe_release}" ] ; then - return 1 + return 1 fi eval $(sed -rn \ @@ -452,6 +493,38 @@ identify_yinhe() write_to_output "${distro}" "${major}" "${minor}" "${yinhe_osname}" } +identify_gooroom() +{ + gooroom_release="$1" + local distro + local major + local minor + local description + + if [ ! -f "${gooroom_release}" ] ; then + return 1 + fi + + eval $(sed -rn 's/^DISTRIB_ID=(.*)$/distro=\1;/gp;' ${gooroom_release}) + if [ ${distro} != "Gooroom" ] ; then + return 1 + fi + + eval $(sed -rn 's/^DISTRIB_RELEASE=([0-9]).([0-9])$/major=\1;minor=\2;/gp;' ${gooroom_release}) + + if [ -z "${major}" ] ; then + return 1 + fi + + if [ -z "${minor}" ] ; then + minor=0 + fi + + eval $(sed -rn 's/^DISTRIB_DESCRIPTION=(.*)$/description=\1;/gp;' ${gooroom_release}) + + write_to_output "${distro}" "${major}" "${minor}" "${description}" +} + identify_boot2docker() { boot2docker_release="$1" @@ -480,6 +553,9 @@ if [ -z "${TEST}" ] ; then identify_kylin /etc/neokylin-release && exit 0 identify_redhat /etc/oracle-release && exit 0 identify_redhat /etc/enterprise-release && exit 0 + #identify Rocky or AlmaLinux before CentOS and RHEL, as Rocky and AlmaLinux both have centos-release and redhat-release + identify_redhat /etc/rocky-release && exit 0 + identify_redhat /etc/almalinux-release && exit 0 identify_redhat /etc/centos-release && exit 0 identify_redhat /etc/redhat-release && exit 0 #identify SuSE-release before, as previous version of SUSE or other distros also have os-release @@ -488,13 +564,15 @@ if [ -z "${TEST}" ] ; then #identify Linx disto before debian, as Linx has both linx_release and debian_version. identify_yinhe /etc/kylin-build && exit 0 identify_linx /etc/linx-release && exit 0 + identify_gooroom /etc/lsb-release && exit 0 identify_lsb lsb_release && exit 0 identify_debian /etc/debian_version && exit 0 identify_boot2docker /etc/boot2docker && exit 0 + identify_os_release /etc/os-release && exit 0 if [ $# -eq 1 ] ; then - rm -f "$1" + rm -f "$1" fi exit 1 diff --git a/mk/xe-linux-distribution-test b/mk/xe-linux-distribution-test index 6bc26b8..1a46ab1 100755 --- a/mk/xe-linux-distribution-test +++ b/mk/xe-linux-distribution-test @@ -12,9 +12,11 @@ test_identify() { export TESTCASE=$1 identify_lsb testcases/lsb || \ + identify_gooroom "${1}" || \ identify_debian "${1}" || \ identify_redhat "${1}" || \ identify_sles "${1}" || \ + identify_os_release "${1}" || \ return 1 } @@ -23,61 +25,68 @@ do_test() TC=$1 ; shift TEST_RESULT=$@ if test_identify ${TC} ; then - if [ X"${TEST_RESULT}" = X"FAIL" ] ; then - echo "FAILED: ${TC}: should fail to parse" 1>&2 - else - set ${TEST_RESULT} - if [ "$1" != "${DISTRO}" ] ; then - echo "FAILED: ${TC}: $1 $2.$3: distro ${DISTRO} != $1" 1>&2 - exit 1 - fi - if [ "$2" != "${MAJOR}" ] ; then - echo "FAILED: ${TC}: $1 $2.$3: major ${MAJOR} != $2" 1>&2 - exit 1 - fi - if [ "$3" != "${MINOR}" ] ; then - echo "FAILED: ${TC} $1 $2.$3: minor ${MINOR} != $3" 1>&2 - exit 1 - fi - echo "PASSED: ${TC}: ${DISTRO} ${MAJOR} ${MINOR} ${NAME} correctly detected" 1>&2 - fi + if [ X"${TEST_RESULT}" = X"FAIL" ] ; then + echo "FAILED: ${TC}: should fail to parse" 1>&2 + else + set ${TEST_RESULT} + if [ "$1" != "${DISTRO}" ] ; then + echo "FAILED: ${TC}: $1 $2.$3: distro ${DISTRO} != $1" 1>&2 + exit 1 + fi + if [ "$2" != "${MAJOR}" ] ; then + echo "FAILED: ${TC}: $1 $2.$3: major ${MAJOR} != $2" 1>&2 + exit 1 + fi + if [ "$3" != "${MINOR}" ] ; then + echo "FAILED: ${TC} $1 $2.$3: minor ${MINOR} != $3" 1>&2 + exit 1 + fi + echo "PASSED: ${TC}: ${DISTRO} ${MAJOR} ${MINOR} ${NAME} correctly detected" 1>&2 + fi else - if [ X"${TEST_RESULT}" = X"FAIL" ] ; then - echo "PASSED: ${TC}: correctly failed to parse" 1>&2 - else - echo "FAILED: ${TC}: unable to parse" 1>&2 - fi + if [ X"${TEST_RESULT}" = X"FAIL" ] ; then + echo "PASSED: ${TC}: correctly failed to parse" 1>&2 + else + echo "FAILED: ${TC}: unable to parse" 1>&2 + fi fi } do_test "testcases/debian-sid" "debian" -do_test "testcases/rhel-3u6" "rhel 3 6" -do_test "testcases/rhel-3u8" "rhel 3 8" -do_test "testcases/rhel-4" "rhel 4 0" -do_test "testcases/rhel-4u1" "rhel 4 1" -do_test "testcases/rhel-4u2" "rhel 4 2" -do_test "testcases/rhel-4u3" "rhel 4 3" -do_test "testcases/rhel-4u4" "rhel 4 4" -do_test "testcases/rhel-4u5" "rhel 4 5" -do_test "testcases/rhel-4u6" "rhel 4 6" -do_test "testcases/rhel-5beta" "rhel 5 0beta" -do_test "testcases/rhel-5" "rhel 5 0" -do_test "testcases/rhel-5u1beta" "rhel 5 1beta" -do_test "testcases/rhel-5u1" "rhel 5 1" +do_test "testcases/debian-10.6" "debian 10 6" do_test "testcases/fc3" "fedora 3 0" -do_test "testcases/sles-9" "sles 9 0" -do_test "testcases/sles-9sp3" "sles 9 3" -do_test "testcases/sles-10sp2" "sles 10 2" -do_test "testcases/sles-11" "sles 11 0" do_test "testcases/ddk-0.5.6-2991c" "xe-ddk 0.5.6 2991c" do_test "testcases/sdk-0.5.6-2991c" "xe-sdk 0.5.6 2991c" -do_test "testcases/centos4" "centos 4 0" -do_test "testcases/centos5" "centos 5 0" -do_test "testcases/lsb-ubuntu-6.10" "ubuntu 6 10" -do_test "testcases/lsb-ubuntu-7.04" "ubuntu 7 04" -do_test "testcases/oracle-5" "oracle 5 0" -do_test "testcases/oracle-5u1" "oracle 5 1" -do_test "testcases/lsb-coreos-367.1.0" "coreos 367 1.0" do_test "testcases/sle-15" "sles 15 0" do_test "testcases/sle-15sp1" "sles 15 1" +do_test "testcases/centos7" "centos 7 0" +do_test "testcases/centos-stream-8" "centos 8 0" +do_test "testcases/rocky-8.3" "rocky 8 3" +do_test "testcases/almalinux-8.3" "almalinux 8 3" +do_test "testcases/slackware-15.0" "slackware 15 0" + +# Newly added test cases +do_test "testcases/centos7.9" "centos 7 9" +do_test "testcases/rhel7.9" "rhel 7 9" +do_test "testcases/rhel8.7" "rhel 8 7" +do_test "testcases/sles12sp4" "sles 12 4" +do_test "testcases/sles12sp5" "sles 12 5" +do_test "testcases/sles15sp2" "sles 15 2" +do_test "testcases/sles15sp4" "sles 15 4" +do_test "testcases/centos6.10" "centos 6 10" +do_test "testcases/oracle7.9" "oracle 7 9" +do_test "testcases/oracle8.7" "oracle 8 7" +do_test "testcases/scientific7.6" "scientific 7 6" +do_test "testcases/rocky8.7" "rocky 8 7" +do_test "testcases/debian10.13" "debian 10 13" +do_test "testcases/debian11.6" "debian 11 6" +do_test "testcases/gooroom2" "Gooroom 2 0" +do_test "testcases/lsb-ubuntu1804" "ubuntu 18 04" +do_test "testcases/lsb-ubuntu2004" "ubuntu 20 04" +do_test "testcases/lsb-ubuntu2204" "ubuntu 22 04" + +# EOL distributions test cases +do_test "testcases/centos4" "centos 4 0" +do_test "testcases/rhel-5" "rhel 5 0" +do_test "testcases/sles-9" "sles 9 0" exit 0 diff --git a/mk/xe-linux-distribution.init b/mk/xe-linux-distribution.init index 7c1bcf4..cfd5a1a 100644 --- a/mk/xe-linux-distribution.init +++ b/mk/xe-linux-distribution.init @@ -29,9 +29,9 @@ action() $cmd ret=$? if [ $ret -eq 0 ] ; then - echo "OK" + echo "OK" else - echo "Failed" + echo "Failed" fi return $ret } @@ -49,24 +49,24 @@ fi start() { if [ ! -e /proc/xen/xenbus ] ; then - if [ ! -d /proc/xen ] ; then - action $"Mounting xenfs on /proc/xen:" /bin/false - echo "Could not find /proc/xen directory." - echo "You need a post 2.6.29-rc1 kernel with CONFIG_XEN_COMPAT_XENFS=y and CONFIG_XENFS=y|m" - exit 1 - else - # This is needed post 2.6.29-rc1 when /proc/xen support was pushed upstream as a xen filesystem - action $"Mounting xenfs on /proc/xen:" mount -t xenfs none /proc/xen - fi + if [ ! -d /proc/xen ] ; then + action $"Mounting xenfs on /proc/xen:" /bin/false + echo "Could not find /proc/xen directory." + echo "You need a post 2.6.29-rc1 kernel with CONFIG_XEN_COMPAT_XENFS=y and CONFIG_XENFS=y|m" + exit 1 + else + # This is needed post 2.6.29-rc1 when /proc/xen support was pushed upstream as a xen filesystem + action $"Mounting xenfs on /proc/xen:" mount -t xenfs none /proc/xen + fi fi if [ -e /proc/xen/capabilities ] && grep -q control_d /proc/xen/capabilities ; then - # Do not want daemon in domain 0 - exit 0 + # Do not want daemon in domain 0 + exit 0 fi action $"Detecting Linux distribution version:" \ - ${XE_LINUX_DISTRIBUTION} ${XE_LINUX_DISTRIBUTION_CACHE} + ${XE_LINUX_DISTRIBUTION} ${XE_LINUX_DISTRIBUTION_CACHE} action $"Starting xe daemon: " /bin/true mkdir -p $(dirname ${XE_DAEMON_PIDFILE}) @@ -101,15 +101,15 @@ case "$1" in start ;; stop) - stop - ;; + stop + ;; status) - status - ;; + status + ;; force-reload|restart) - stop - start - ;; + stop + start + ;; *) # do not advertise unreasonable commands that there is no reason # to use with this device diff --git a/mk/xen-vcpu-hotplug.rules b/mk/xen-vcpu-hotplug.rules index a28f895..0e80111 100644 --- a/mk/xen-vcpu-hotplug.rules +++ b/mk/xen-vcpu-hotplug.rules @@ -1 +1 @@ -ACTION=="add", SUBSYSTEM=="cpu", RUN+="/bin/sh -c '( ! /usr/bin/xenstore-exists unique-domain-id 2>/dev/null ) || [ ! -e /sys$devpath/online ] || echo 1 > /sys$devpath/online'" +ACTION=="add", SUBSYSTEM=="cpu", RUN+="/bin/sh -c '[ -e /dev/xen/xenbus ] && [ -e /sys$devpath/online ] && echo 1 > /sys$devpath/online'" diff --git a/syslog/syslog.go b/syslog/syslog.go index 7acc87d..9b093da 100644 --- a/syslog/syslog.go +++ b/syslog/syslog.go @@ -19,8 +19,13 @@ type SysLoggerWriter struct { stdin io.WriteCloser } -func NewSyslogWriter(topic string) (io.Writer, error) { - cmd := exec.Command("logger", "-t", topic) +func NewSyslogWriter(topic string, debug bool) (io.Writer, error) { + // set lower priority by default + priority := "debug" + if debug { + priority = "notice" + } + cmd := exec.Command("logger", "-t", topic, "-p", priority) stdin, err := cmd.StdinPipe() if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt new file mode 100644 index 0000000..c77a673 --- /dev/null +++ b/vendor/modules.txt @@ -0,0 +1,4 @@ +# golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 +## explicit +golang.org/x/sys/internal/unsafeheader +golang.org/x/sys/unix diff --git a/xe-daemon/xe-daemon.go b/xe-daemon/xe-daemon.go index 7b07873..d6c6410 100644 --- a/xe-daemon/xe-daemon.go +++ b/xe-daemon/xe-daemon.go @@ -1,10 +1,6 @@ package main import ( - guestmetric "../guestmetric" - syslog "../syslog" - system "../system" - xenstoreclient "../xenstoreclient" "flag" "fmt" "io" @@ -15,6 +11,11 @@ import ( "strconv" "syscall" "time" + + guestmetric "github.com/xenserver/xe-guest-utilities/guestmetric" + syslog "github.com/xenserver/xe-guest-utilities/syslog" + system "github.com/xenserver/xe-guest-utilities/system" + xenstoreclient "github.com/xenserver/xe-guest-utilities/xenstoreclient" ) const ( @@ -28,7 +29,7 @@ func main() { var err error sleepInterval := flag.Int("i", 60, "Interval between updates (in seconds)") - debugFlag := flag.Bool("d", false, "Update to stdout rather than xenstore") + debugFlag := flag.Bool("d", false, "Update to log in addition to xenstore") balloonFlag := flag.Bool("B", true, "Do not report that ballooning is supported") pid := flag.String("p", "", "Write the PID to FILE") @@ -43,7 +44,7 @@ func main() { var loggerWriter io.Writer = os.Stderr var topic string = LoggerName - if w, err := syslog.NewSyslogWriter(topic); err == nil { + if w, err := syslog.NewSyslogWriter(topic, *debugFlag); err == nil { loggerWriter = w topic = "" } else { diff --git a/xenstore/xenstore.go b/xenstore/xenstore.go index 3c09537..7669af7 100644 --- a/xenstore/xenstore.go +++ b/xenstore/xenstore.go @@ -1,13 +1,14 @@ package main import ( - xenstoreclient "../xenstoreclient" "errors" "fmt" - "golang.org/x/sys/unix" "os" "strconv" "strings" + + xenstoreclient "github.com/xenserver/xe-guest-utilities/xenstoreclient" + "golang.org/x/sys/unix" ) func die(format string, a ...interface{}) {