Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
frogstarr78 authored Jul 2, 2024
2 parents 402b73c + 1764ee8 commit 1608f45
Show file tree
Hide file tree
Showing 72 changed files with 520 additions and 240 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [email protected] [email protected]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
38 changes: 23 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 ; \
Expand All @@ -66,23 +72,25 @@ $(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" | \
sed -e "s/@PRODUCT_MINOR_VERSION@/$(PRODUCT_MINOR_VERSION)/g" | \
sed -e "s/@PRODUCT_MICRO_VERSION@/$(PRODUCT_MICRO_VERSION)/g" | \
sed -e "s/@NUMERIC_BUILD_NUMBER@/$(RELEASE)/g" \
> $@

152 changes: 146 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 [email protected]: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 [email protected]: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
12 changes: 6 additions & 6 deletions analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/xenserver/xe-guest-utilities

go 1.19

require golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
14 changes: 10 additions & 4 deletions guestmetric/guestmetric_linux.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package guestmetric

import (
xenstoreclient "../xenstoreclient"
"bufio"
"bytes"
"fmt"
xenstoreclient "github.com/xenserver/xe-guest-utilities/xenstoreclient"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -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]
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 0 additions & 7 deletions mk/Citrix.repo

This file was deleted.

Loading

0 comments on commit 1608f45

Please sign in to comment.