Compare commits

...

28 Commits

Author SHA1 Message Date
Jian Qiu
49bf6d876f fix: task remote notify (#23631)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-10-29 12:17:55 +08:00
Zexi Li
8cbf379f15 chore(ci): turn off goimports-check rule (#23608) 2025-10-24 15:49:03 +08:00
屈轩
630d999781 fix(region): server sku create with region id (#23600) 2025-10-24 12:21:59 +08:00
Jian Qiu
26531dc4e1 fix(host): host probe isoalted device return jsonarray (#23598)
Co-authored-by: wanyaoqi <d3lx.yq@gmail.com>
2025-10-23 17:32:58 +08:00
Jian Qiu
c623bd9e5d fix: rpm/deb support postinst/preinst/prerm/postrm hooks (#23597)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-10-23 01:03:03 +08:00
Jian Qiu
82a4244cc7 fix: suport bulding multi-arch rpm deb (#23593)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-10-23 00:35:56 +08:00
Jian Qiu
46489ba15d fix: network manager keyfile static routes (#23481)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-10-08 13:18:17 +08:00
Jian Qiu
51754c9578 fix: support network manager connection profiles (#23470)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-10-03 09:25:50 +08:00
Jian Qiu
a865bcf7cc fix: default cloud region init error (#23477)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-10-03 06:33:50 +08:00
Jian Qiu
83a25db7a2 fix: hostman master nic may be nil (#23451)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-30 11:19:15 +08:00
Jian Qiu
d455e0cc6f fix: disable password history unique check by default (#23440)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-29 15:46:42 +08:00
wanyaoqi
aa65788247 fix(region,baremetal): ipv6 baremetal register support (#23423) 2025-09-29 15:22:35 +08:00
Jian Qiu
46d351f008 fix: backup task worker count in host configmap (#23426)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-29 15:20:49 +08:00
Jian Qiu
c3db8a1bb1 fix: auto cleanup obsolete password records (#23373)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-24 18:35:27 +08:00
Jian Qiu
ba09171042 Automated cherry pick of #23363: fix: network filter by ip error for dameng (#23365)
* fix: network filter by ip error for dameng

* fix: update vendor 20250923

---------

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-24 18:17:38 +08:00
Jian Qiu
a015a96299 fix: host backup task worker limit (#23348)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-22 09:48:30 +08:00
Jian Qiu
9a5dce99b6 fix: check os_arch when server rebuilding root (#23340)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-19 23:44:55 +08:00
Jian Qiu
7b4256043d fix: ipv6 ra should be sent periodically (#23260)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-10 18:59:19 +08:00
wanyaoqi
4d1f22c892 fix(host): live migrate compat ipv6 (#23215) 2025-09-03 05:50:10 +08:00
Jian Qiu
6944609cea fix: image s3 direct download option (#23221)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-03 05:47:46 +08:00
Jian Qiu
c2d880b8ac fix: network filter by ipv6 address (#23224)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-09-03 05:46:58 +08:00
Zexi Li
1eab56366e feat(host): add SdnFetchDataFromComputeService option (#23208) 2025-09-01 23:15:50 +08:00
Jian Qiu
e181a5c564 fix: too many recursive locks when batch create (#23200)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-08-29 23:08:40 +08:00
Jian Qiu
aed4db1454 fix: guest ipv6 vip (#23186)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-08-28 02:33:33 +08:00
Jian Qiu
5ba5d78344 fix: dhcpv6 should nack confirm if addr changed (#23170)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-08-26 15:35:15 +08:00
wanyaoqi
d4840e0293 fix(region,host): ipv6 change addr (#23172) 2025-08-26 15:34:42 +08:00
Jian Qiu
dd72ff2c4b fix: deploy gai.conf if both v4 and v6 present (#23163)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
2025-08-25 18:19:55 +08:00
屈轩
84b0f1075a fix(region): optimized cached image list (#23155) 2025-08-22 15:44:44 +08:00
114 changed files with 8411 additions and 570 deletions

View File

@@ -250,7 +250,7 @@ hostdeployer-grpc-gen:
check: fmt-check
check: gendocgo-check
check: goimports-check
#check: goimports-check
#check: vet-check
#check: y18n-check
.PHONY: check
@@ -274,7 +274,7 @@ dep:
@echo "$$depDeprecated"
@$(MAKE) mod
RELEASE_BRANCH:=release/4.0
RELEASE_BRANCH:=release/4.0.1
GOPROXY ?= direct
mod:

View File

@@ -36,6 +36,12 @@ fi
. $ROOT/vars
BUILDROOT=$(mktemp -d 2>/dev/null || mktemp -d -t 'yunion')
function cleanup {
rm -rf "$BUILDROOT"
echo "Deleted temp working directory $BUILDROOT"
}
# register the cleanup function to be called on the EXIT signal
trap cleanup EXIT
echo "Build root ${BUILDROOT}"
@@ -104,41 +110,84 @@ if [ -d $ROOT/root ]; then
rsync -a $ROOT/root/ \$RPM_BUILD_ROOT
fi
%pre
%pre" > $SPEC_FILE
if [ -f $ROOT/preinst ]; then
cat $ROOT/preinst >> $SPEC_FILE
else
echo "
%if %{use_systemd}
getent group %{owner} >/dev/null || /usr/sbin/groupadd -r %{owner}
getent passwd %{owner} >/dev/null || /usr/sbin/useradd -r -s /sbin/nologin -d %{homedir} -M -g %{owner} %{owner}
%endif
" >> $SPEC_FILE
fi
%post
echo "
%post" >> $SPEC_FILE
if [ -f $ROOT/postinst ]; then
cat $ROOT/postinst >> $SPEC_FILE
else
echo "
%if %{use_systemd}
mkdir -p /var/run/%{owner}
chown -R %{owner}:%{owner} /var/run/%{owner}
/usr/bin/systemctl preset %{pkgname}.service >/dev/null 2>&1 ||:
%endif
" >> $SPEC_FILE
fi
%preun
echo "
%preun" >> $SPEC_FILE
if [ -f $ROOT/prerm ]; then
cat $ROOT/prerm >> $SPEC_FILE
else
echo "
%if %{use_systemd}
/usr/bin/systemctl --no-reload disable %{pkgname}.service >/dev/null 2>&1 || :
/usr/bin/systemctl stop %{pkgname}.service >/dev/null 2>&1 ||:
%endif
" >> $SPEC_FILE
fi
%postun
echo "
%postun" >> $SPEC_FILE
if [ -f $ROOT/postrm ]; then
cat $ROOT/postrm >> $SPEC_FILE
else
echo "
%if %{use_systemd}
/usr/bin/systemctl daemon-reload >/dev/null 2>&1 ||:
%endif
" >> $SPEC_FILE
fi
echo -n "
%files
%doc
$BIN_PATH/$PKG
$(for b in $EXTRA_BINS; do echo $BIN_PATH/$b; done)
" > $SPEC_FILE
" >> $SPEC_FILE
for b in $EXTRA_BINS; do
echo $BIN_PATH/$b >> $SPEC_FILE
done
if [ -d $ROOT/root/ ]; then
find $ROOT/root/ -type f | sed -e "s:$ROOT/root::g" >> $SPEC_FILE
fi
rpmbuild --define "_topdir $BUILDROOT" -bb $SPEC_FILE
TARGET=
case "$GOARCH" in
"arm64" | "aarch64" | "arm")
TARGET="--target aarch64-redhat-linux"
;;
"amd64" | "x86" | "i686" | "i386" | "x86_64")
TARGET="--target x86_64-redhat-linux"
;;
esac
rpmbuild --define "_topdir $BUILDROOT" -bb $SPEC_FILE $TARGET
find $RPM_DIR -type f | while read f; do
d="$(dirname "$f")"
@@ -146,5 +195,3 @@ find $RPM_DIR -type f | while read f; do
mkdir -p "$d"
cp $f $d
done
rm -fr $BUILDROOT

View File

@@ -35,26 +35,6 @@ fi
. $ROOT/vars
if [ -z "$VERSION" ]; then
TAG=$(git describe --abbrev=0 --tags || echo 000000)
VERSION=${TAG/\//-}
VERSION=${VERSION/v/}
fi
RELEASE=`date +"%y%m%d%H"`
FULL_VERSION=$VERSION-$RELEASE
BUILDROOT=$OUTPUT_DIR/yunion-$1-$FULL_VERSION
rm -rf $BUILDROOT
mkdir -p $BUILDROOT/DEBIAN
mkdir -p $BUILDROOT/$BIN_PATH
cp -rf $BIN $BUILDROOT/$BIN_PATH
if [ -d $ROOT/root ]; then
cp -rf $ROOT/root/* $BUILDROOT/
fi
echo "Build root ${BUILDROOT}"
case $(uname -m) in
x86_64)
CURRENT_ARCH=amd64
@@ -64,15 +44,123 @@ case $(uname -m) in
;;
esac
echo "Package: yunion-$1
if [[ -n "$GOARCH" ]]; then
case "$GOARCH" in
"arm64" | "arm" | "aarch64")
CURRENT_ARCH="arm64"
;;
"x86" | "x86_64" | "i686" | "i386" | "amd64")
CURRENT_ARCH="amd64"
;;
esac
fi
if [ -z "$VERSION" ]; then
TAG=$(git describe --abbrev=0 --tags || echo 000000)
VERSION=${TAG/\//-}
VERSION=${VERSION/v/}
VERSION=${VERSION/master-/}
fi
RELEASE=`date +"%y%m%d%H"`
FULL_VERSION=$VERSION-$RELEASE
BUILDROOT=$OUTPUT_DIR/yunion-${PKG}-${FULL_VERSION}_${CURRENT_ARCH}
function cleanup {
rm -rf "$BUILDROOT"
echo "Deleted temp working directory $BUILDROOT"
}
# register the cleanup function to be called on the EXIT signal
trap cleanup EXIT
rm -rf $BUILDROOT
mkdir -p $BUILDROOT/DEBIAN
mkdir -p $BUILDROOT/$BIN_PATH
cp -rf $BIN $BUILDROOT/$BIN_PATH
if [ -d $ROOT/root ]; then
cp -rf $ROOT/root/* $BUILDROOT/
fi
echo "Build root ${BUILDROOT}"
echo "Package: yunion-$PKG
Version: $FULL_VERSION
Section: base
Priority: optional
Architecture: $CURRENT_ARCH
Maintainer: wanyaoqi@yunionyun.com
Description: Yunion $1
" > $BUILDROOT/DEBIAN/control
Description: $DESCRIPTION" > $BUILDROOT/DEBIAN/control
if [ ${#REQUIRES[@]} -gt 0 ]; then
DEPS=$(IFS=, ; echo "${REQUIRES[*]}")
echo "Depends: $DEPS" >> $BUILDROOT/DEBIAN/control
fi
chmod 0755 $BUILDROOT/DEBIAN/control
cat $BUILDROOT/DEBIAN/control
dpkg-deb --build $BUILDROOT
echo "#!/bin/bash
" > $BUILDROOT/DEBIAN/preinst
if [ -f $ROOT/preinst ]; then
cat $ROOT/preinst >> $BUILDROOT/DEBIAN/preinst
else
if [ "$SERVICE" == "yes" ] && [ -n "$OWNER" ]; then
echo "
getent group ${OWNER} >/dev/null || /usr/sbin/groupadd -r ${OWNER}
getent passwd ${OWNER} >/dev/null || /usr/sbin/useradd -r -s /sbin/nologin -d /home/${OWNER} -M -g ${OWNER} ${OWNER}
" >> $BUILDROOT/DEBIAN/preinst
fi
fi
chmod 0755 $BUILDROOT/DEBIAN/preinst
echo "#!/bin/bash
" > $BUILDROOT/DEBIAN/postinst
if [ -f $ROOT/postinst ]; then
cat $ROOT/postinst >> $BUILDROOT/DEBIAN/postinst
else
if [ "$SERVICE" == "yes" ]; then
echo "
/usr/bin/systemctl preset yunion-${PKG}.service >/dev/null 2>&1 ||:
" >> $BUILDROOT/DEBIAN/postinst
fi
fi
chmod 0755 $BUILDROOT/DEBIAN/postinst
echo "#!/bin/bash
" > $BUILDROOT/DEBIAN/prerm
if [ -f $ROOT/prerm ]; then
cat $ROOT/prerm >> $BUILDROOT/DEBIAN/prerm
else
if [ "$SERVICE" == "yes" ]; then
echo "
/usr/bin/systemctl --no-reload disable yunion-${PKG}.service >/dev/null 2>&1 || :
/usr/bin/systemctl stop yunion-${PKG}.service >/dev/null 2>&1 ||:
" >> $BUILDROOT/DEBIAN/prerm
fi
fi
chmod 0755 $BUILDROOT/DEBIAN/prerm
echo "#!/bin/bash
" > $BUILDROOT/DEBIAN/postrm
if [ -f $ROOT/postrm ]; then
cat $ROOT/postrm >> $BUILDROOT/DEBIAN/postrm
else
if [ "$SERVICE" == "yes" ]; then
echo "
/usr/bin/systemctl daemon-reload >/dev/null 2>&1 ||:
" >> $BUILDROOT/DEBIAN/postrm
fi
fi
chmod 0755 $BUILDROOT/DEBIAN/postrm
dpkg-deb --build $BUILDROOT
case "$CURRENT_ARCH" in
"amd64")
DSTARCH="x86_64"
;;
"arm64")
DSTARCH="aarch64"
;;
esac
mkdir -p ${OUTPUT_DIR}/${DSTARCH}
mv ${BUILDROOT}.deb ${OUTPUT_DIR}/${DSTARCH}/

View File

@@ -1,5 +1,5 @@
DESCRIPTION="Yunion Cloud Image Service"
REQUIRES=(
yunion-qemu-2.12.1
yunion-qemu-4.2.0
)

View File

@@ -184,59 +184,6 @@ func init() {
return nil
})
/*R(&options.ServerBatchMetadataOptions{}, "server-batch-update-user-tag", "add tags for some server", func(s *mcclient.ClientSession, opts *options.ServerBatchMetadataOptions) error {
params, err := opts.Params()
if err != nil {
return err
}
result, err := modules.Servers.PerformClassAction(s, "batch-user-metadata", params)
if err != nil {
return err
}
printObject(result)
return nil
})
R(&options.ServerBatchMetadataOptions{}, "server-batch-replace-user-tag", "Set tags for some server", func(s *mcclient.ClientSession, opts *options.ServerBatchMetadataOptions) error {
params, err := opts.Params()
if err != nil {
return err
}
result, err := modules.Servers.PerformClassAction(s, "batch-set-user-metadata", params)
if err != nil {
return err
}
printObject(result)
return nil
})
R(&options.ResourceMetadataOptions{}, "server-update-user-tag", "Set tag of a server", func(s *mcclient.ClientSession, opts *options.ResourceMetadataOptions) error {
params, err := opts.Params()
if err != nil {
return err
}
result, err := modules.Servers.PerformAction(s, opts.ID, "user-metadata", params)
if err != nil {
return err
}
printObject(result)
return nil
})
R(&options.ResourceMetadataOptions{}, "server-update-user-tag", "Set tag of a server", func(s *mcclient.ClientSession, opts *options.ResourceMetadataOptions) error {
params, err := opts.Params()
if err != nil {
return err
}
result, err := modules.Servers.PerformAction(s, opts.ID, "set-user-metadata", params)
if err != nil {
return err
}
printObject(result)
return nil
})
*/
R(&baseoptions.ResourceMetadataOptions{}, "server-set-metadata", "Set raw metadata of a server", func(s *mcclient.ClientSession, opts *baseoptions.ResourceMetadataOptions) error {
params, err := opts.Params()
if err != nil {

8
go.mod
View File

@@ -72,6 +72,7 @@ require (
github.com/vishvananda/netns v0.0.5-0.20240412164733-9469873f4601
github.com/vmihailenco/msgpack v4.0.4+incompatible
github.com/xuri/excelize/v2 v2.7.1
github.com/zeebo/xxh3 v1.0.2
github.com/zexi/influxql-to-metricsql v0.1.1
go.etcd.io/etcd/api/v3 v3.5.0
go.etcd.io/etcd/client/v3 v3.5.0
@@ -96,14 +97,14 @@ require (
k8s.io/cri-api v0.22.17
k8s.io/klog/v2 v2.20.0
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250820024120-20f73c47b078
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250829114849-df4e5cb536d0
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
yunion.io/x/pkg v1.10.4-0.20250814065738-8df5d9d07297
yunion.io/x/pkg v1.10.4-0.20250820035218-6008459eb4f0
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1
yunion.io/x/sqlchemy v1.1.3-0.20250806073422-e37f5197cec0
yunion.io/x/sqlchemy v1.1.3-0.20250925091009-4ca0766fc8f0
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
)
@@ -224,6 +225,7 @@ require (
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/lestrrat-go/iter v0.0.0-20200422075355-fc1769541911 // indirect

18
go.sum
View File

@@ -560,6 +560,8 @@ github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1q
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c h1:N7A4JCA2G+j5fuFxCsJqjFU/sZe0mj8H0sSoSwbaikw=
github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c/go.mod h1:Nn5wlyECw3iJrzi0AhIWg+AJUb4PlRQVW4/3XHH1LZA=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -903,6 +905,10 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
github.com/zexi/influxql-to-metricsql v0.1.1 h1:dXnVzlxVLuo88zGkDca7erEnmvprGWjzsBcs8qIoQGQ=
github.com/zexi/influxql-to-metricsql v0.1.1/go.mod h1:JlC5FY+6De9ZPxG47G5DOgva8P9X1VaKS4ExzCmhSCc=
github.com/zexi/promql/v2 v2.12.1 h1:crHKpULdLLsBZ9b78Rg6qQkugzlk6BHeCj93tw/F5RU=
@@ -1408,8 +1414,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250820024120-20f73c47b078 h1:KaAEKjdAcpRrJlrJfOtcXCz5IUgPdv7dqeZnLswxLXE=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250820024120-20f73c47b078/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250829114849-df4e5cb536d0 h1:sA8sWG97QRHyf2pMFUl1rPtGL69H62q59TUhbUVzwUw=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250829114849-df4e5cb536d0/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU=
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
@@ -1423,11 +1429,11 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v1.10.4-0.20250814065738-8df5d9d07297 h1:rnU78gHJ+2nEgjpwWN+FclED/nFeuMkrrBWgnTz0ykc=
yunion.io/x/pkg v1.10.4-0.20250814065738-8df5d9d07297/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
yunion.io/x/pkg v1.10.4-0.20250820035218-6008459eb4f0 h1:/vHcYqzQInxqR1jjS+e7A0owRXj+/rvrIgES6uadUqs=
yunion.io/x/pkg v1.10.4-0.20250820035218-6008459eb4f0/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1 h1:1KJ3YYinydPHpDEQRXdr/T8SYcKZ5Er+m489H+PnaQ4=
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
yunion.io/x/sqlchemy v1.1.3-0.20250806073422-e37f5197cec0 h1:Eha/ywh4foMJm7VJ8ibFOi+WPHacuTWtosAGpOld5vo=
yunion.io/x/sqlchemy v1.1.3-0.20250806073422-e37f5197cec0/go.mod h1:vCIZpqhZ5Jzaq3tFyrti/vv8BijQKtkzSgNT/uH4H5A=
yunion.io/x/sqlchemy v1.1.3-0.20250925091009-4ca0766fc8f0 h1:L4zE6kTD1PEki1jQnLLBiYnEYFKWa/weoful0Sl4tKw=
yunion.io/x/sqlchemy v1.1.3-0.20250925091009-4ca0766fc8f0/go.mod h1:vCIZpqhZ5Jzaq3tFyrti/vv8BijQKtkzSgNT/uH4H5A=
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c h1:QuLab2kSRECZRxo4Lo2KcYn6XjQFDGaZ1+x0pYDVVwQ=
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=

View File

@@ -1202,9 +1202,11 @@ type ServerQgaGuestInfoTaskInput struct {
type ServerQgaSetNetworkInput struct {
ServerQgaTimeoutInput
Device string
Ipmask string
Gateway string
Device string
Ipmask string
Gateway string
Ip6mask string
Gateway6 string
}
type ServerQgaGetNetworkInput struct {

View File

@@ -175,6 +175,10 @@ func IsARM(osArch string) bool {
return utils.IsInStringArray(osArch, ARCH_ARM)
}
func IsX86(osArch string) bool {
return utils.IsInStringArray(osArch, ARCH_X86)
}
func IsIllegalSearchDomain(domain string) bool {
switch domain {
case "cloud.onecloud.io":
@@ -182,3 +186,16 @@ func IsIllegalSearchDomain(domain string) bool {
}
return false
}
func IsSameArch(arch1, arch2 string) bool {
if arch1 == arch2 {
return true
}
if IsARM(arch1) && IsARM(arch2) {
return true
}
if IsX86(arch1) && IsX86(arch2) {
return true
}
return false
}

View File

@@ -16,7 +16,9 @@ package handler
import (
"context"
"fmt"
"net/http"
"strings"
"time"
"yunion.io/x/jsonutils"
@@ -193,7 +195,12 @@ func handleBaremetalValidateIPMI() appsrv.FilterHandler {
if err := body.Unmarshal(input); err != nil {
return nil, errors.Wrapf(err, "unmarshal validate ipmi request: %s", body)
}
redfishCli := redfish.NewRedfishDriver(ctx, "https://"+input.Ip, input.Username, input.Password, false)
var endpoint = "https://" + input.Ip
if strings.Contains(input.Ip, ":") {
endpoint = fmt.Sprintf("https://[%s]", input.Ip)
}
redfishCli := redfish.NewRedfishDriver(ctx, endpoint, input.Username, input.Password, false)
resp := &baremetalapi.ValidateIPMIResponse{}
if redfishCli == nil {
resp.IsRedfishSupported = false

View File

@@ -321,7 +321,12 @@ func (m *SBaremetalManager) RegisterBaremetal(ctx context.Context, userCred mccl
return
}
input.IpAddr, err = m.fetchIpmiIp(sshCli)
isIpv6Addr := false
if strings.Contains(input.RemoteIp, ":") {
isIpv6Addr = true
}
input.IpAddr, err = m.fetchIpmiIp(sshCli, isIpv6Addr)
log.Infof("find ipmi addr %s", input.IpAddr)
if input.isTimeout() {
return
@@ -375,17 +380,48 @@ func (m *SBaremetalManager) RegisterBaremetal(ctx context.Context, userCred mccl
registerTask.DoPrepare(ctx, sshCli, registered)
}
func (m *SBaremetalManager) fetchIpmiIp(sshCli *ssh.Client) (string, error) {
res, err := sshCli.RawRun(`/usr/bin/ipmitool lan print | grep "IP Address "`)
if err != nil {
return "", err
}
if len(res) == 1 {
segs := strings.Fields(res[0])
if len(segs) == 4 {
return strings.TrimSpace(segs[3]), nil
func (m *SBaremetalManager) fetchIpmiIp(sshCli *ssh.Client, isIpv6Addr bool) (string, error) {
if !isIpv6Addr {
res, err := sshCli.RawRun(`/usr/bin/ipmitool lan print | grep "IP Address "`)
if err != nil {
return "", err
}
if len(res) == 1 {
segs := strings.Fields(res[0])
if len(segs) == 4 {
return strings.TrimSpace(segs[3]), nil
}
}
} else {
res, err := sshCli.Run(`/usr/bin/ipmitool lan6 print`)
if err != nil {
return "", err
}
for i, line := range res {
if strings.HasPrefix(line, "IPv6 Static Address") || strings.HasPrefix(line, "IPv6 Dynamic Address") {
if len(res)-i > 3 {
enabledSegs := strings.Fields(res[i+1])
log.Infof("enabled segs %#v", enabledSegs)
if len(enabledSegs) != 2 || enabledSegs[0] != "Enabled:" || enabledSegs[1] != "yes" {
continue
}
statusSegs := strings.Fields(res[i+3])
log.Infof("status segs %#v", statusSegs)
if len(enabledSegs) != 2 || statusSegs[0] != "Status:" || statusSegs[1] != "active" {
continue
}
addrSegs := strings.Fields(res[i+2])
if len(addrSegs) != 2 || addrSegs[0] != "Address:" {
continue
}
ipv6Addr := strings.Split(addrSegs[1], "/")
return ipv6Addr[0], nil
}
}
}
}
return "", fmt.Errorf("Failed to find ipmi ip address")
}
@@ -394,6 +430,11 @@ func (m *SBaremetalManager) checkNetworkFromIp(ip string) (string, error) {
params.Set("ip", jsonutils.NewString(ip))
params.Set("scope", jsonutils.NewString("system"))
params.Set("is_classic", jsonutils.JSONTrue)
params.Set("provider", jsonutils.NewString(api.CLOUD_PROVIDER_ONECLOUD))
params.Set("limit", jsonutils.NewInt(0))
// use default vpc
params.Set("vpc", jsonutils.NewString(api.DEFAULT_VPC_ID))
res, err := modules.Networks.List(m.GetClientSession(), params)
if err != nil {
return "", fmt.Errorf("Fetch network by ip %s failed: %s", ip, err)
@@ -1793,8 +1834,11 @@ func (b *SBaremetalInstance) GetRedfishCli(ctx context.Context) redfish.IRedfish
return nil
}
conf := b.GetIPMIConfig()
return redfish.NewRedfishDriver(ctx, "https://"+conf.IpAddr,
conf.Username, conf.Password, false)
var endpoint = "https://" + conf.IpAddr
if strings.Contains(conf.IpAddr, ":") {
endpoint = fmt.Sprintf("https://[%s]", conf.IpAddr)
}
return redfish.NewRedfishDriver(ctx, endpoint, conf.Username, conf.Password, false)
}
func (b *SBaremetalInstance) GetIPMILanChannel() uint8 {

View File

@@ -84,12 +84,20 @@ func (s *sBaremetalRegisterTask) getSession() *mcclient.ClientSession {
}
func (s *sBaremetalRegisterTask) getAccessDevMacAddr(ip string) (string, error) {
nicsRet, err := s.SshCli.Run("/sbin/ip -o -4 addr show")
if err != nil {
return "", fmt.Errorf("Failed get access nic %s", err)
}
var dev string
var nicsRet []string
var err error
if strings.Contains(ip, ":") { // ipv6
nicsRet, err = s.SshCli.Run("/sbin/ip -o -6 addr show")
if err != nil {
return "", fmt.Errorf("Failed get access nic %s", err)
}
} else { // ipv4
nicsRet, err = s.SshCli.Run("/sbin/ip -o -4 addr show")
if err != nil {
return "", fmt.Errorf("Failed get access nic %s", err)
}
}
for i := 0; i < len(nicsRet); i++ {
if strings.Contains(nicsRet[i], ip+"/") {
segs := strings.Split(nicsRet[i], " ")
@@ -102,6 +110,7 @@ func (s *sBaremetalRegisterTask) getAccessDevMacAddr(ip string) (string, error)
if len(dev) == 0 {
return "", fmt.Errorf("Can't get access dev")
}
log.Infof("Access dev is %s", dev)
macRet, err := s.SshCli.Run("/sbin/ip a show " + dev)
if err != nil || len(macRet) < 2 {
@@ -205,7 +214,11 @@ func (s *sBaremetalRegisterTask) UpdateBaremetal(ctx context.Context) (string, e
}
func (s *sBaremetalRegisterTask) doRedfishProbe(ctx context.Context) (redfishSupport bool, cdromBoot bool) {
redfishCli := redfish.NewRedfishDriver(ctx, "https://"+s.IpmiIpAddr, s.IpmiUsername, s.IpmiPassword, false)
var endpoint = "https://" + s.IpmiIpAddr
if strings.Contains(s.IpmiIpAddr, ":") {
endpoint = fmt.Sprintf("https://[%s]", s.IpmiIpAddr)
}
redfishCli := redfish.NewRedfishDriver(ctx, endpoint, s.IpmiUsername, s.IpmiPassword, false)
if redfishCli != nil {
_, cdInfo, _ := redfishCli.GetVirtualCdromInfo(ctx)
redfishSupport = true

View File

@@ -16,7 +16,9 @@ package tasks
import (
"context"
"fmt"
"path/filepath"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
@@ -78,7 +80,12 @@ func (self *SBaremetalCdromTask) getRedfishApi(ctx context.Context) (redfish.IRe
if !ipmiInfo.CdromBoot {
return nil, errors.Error("mount Virtual Cdrom not supported")
}
redfishCli := redfish.NewRedfishDriver(ctx, "https://"+ipmiInfo.IpAddr, ipmiInfo.Username, ipmiInfo.Password, false)
var endpoint = "https://" + ipmiInfo.IpAddr
if strings.Contains(ipmiInfo.IpAddr, ":") {
endpoint = fmt.Sprintf("https://[%s]", ipmiInfo.IpAddr)
}
redfishCli := redfish.NewRedfishDriver(ctx, endpoint, ipmiInfo.Username, ipmiInfo.Password, false)
if redfishCli != nil {
return redfishCli, nil
} else {

View File

@@ -17,6 +17,7 @@ package agent
import (
"fmt"
"net"
"strings"
"time"
"yunion.io/x/jsonutils"
@@ -82,7 +83,14 @@ func (agent *SBaseAgent) GetListenIPs() []net.IP {
func (agent *SBaseAgent) FindListenIP(listenAddr string) (net.IP, error) {
ips := agent.GetListenIPs()
if listenAddr == "" {
return ips[0], nil
for i := range ips {
ipstr := ips[i].String()
if strings.HasPrefix(ipstr, netutils2.SECRET_PREFIX) {
continue
}
return ips[i], nil
}
return nil, fmt.Errorf("Not Address on Interface %#v", agent.ListenInterface)
}
if listenAddr == "0.0.0.0" {
return net.ParseIP(listenAddr), nil
@@ -287,6 +295,9 @@ func (agent *SBaseAgent) GetManagerUri() string {
if agent.IAgent().GetEnableSsl() {
proto = "https"
}
if accessIP.To4() == nil { // ipv6 addr
return fmt.Sprintf("%s://[%s]:%d", proto, accessIP, agent.IAgent().GetPort())
}
return fmt.Sprintf("%s://%s:%d", proto, accessIP, agent.IAgent().GetPort())
}

View File

@@ -1572,17 +1572,20 @@ func (dispatcher *DBModelDispatcher) BatchCreate(ctx context.Context, query json
results := make([]printutils.SubmitResult, count)
models := make([]IModel, 0)
for i, res := range createResults {
for i := range createResults {
res := createResults[i]
result := printutils.SubmitResult{}
if res.err != nil {
jsonErr := httperrors.NewGeneralError(res.err)
result.Status = jsonErr.Code
result.Data = jsonutils.Marshal(jsonErr)
} else {
lockman.LockObject(ctx, res.model)
defer lockman.ReleaseObject(ctx, res.model)
func() {
lockman.LockObject(ctx, res.model)
defer lockman.ReleaseObject(ctx, res.model)
res.model.PostCreate(ctx, userCred, ownerId, query, data)
res.model.PostCreate(ctx, userCred, ownerId, query, data)
}()
models = append(models, res.model)
body, err := getItemDetails(manager, res.model, ctx, userCred, query)
@@ -1597,10 +1600,12 @@ func (dispatcher *DBModelDispatcher) BatchCreate(ctx context.Context, query json
results[i] = result
}
if len(models) > 0 {
lockman.LockClass(ctx, manager, GetLockClassKey(manager, ownerId))
defer lockman.ReleaseClass(ctx, manager, GetLockClassKey(manager, ownerId))
func() {
lockman.LockClass(ctx, manager, GetLockClassKey(manager, ownerId))
defer lockman.ReleaseClass(ctx, manager, GetLockClassKey(manager, ownerId))
manager.OnCreateComplete(ctx, models, userCred, ownerId, query, multiData)
manager.OnCreateComplete(ctx, models, userCred, ownerId, query, multiData)
}()
}
return results, nil
}

View File

@@ -785,9 +785,9 @@ func (task *STask) SetStageFailed(ctx context.Context, reason jsonutils.JSONObje
reason = reasonDict
prevFailed, _ := task.Params.Get("__failed_reason")
if prevFailed != nil {
switch prevFailed.(type) {
switch prevFailed2 := prevFailed.(type) {
case *jsonutils.JSONArray:
prevFailed.(*jsonutils.JSONArray).Add(reason)
prevFailed2.Add(reason)
reason = prevFailed
default:
reason = jsonutils.NewArray(prevFailed, reason)
@@ -815,36 +815,43 @@ func (task *STask) NotifyParentTaskComplete(ctx context.Context, body *jsonutils
pTask := TaskManager.fetchTask(parentTaskId)
if pTask == nil {
saveTaskUpCallStatus(task.GetId(), parentTaskId, false, errors.Wrap(errors.ErrNotFound, "Parent task not found").Error())
log.Errorf("Parent task %s not found", parentTaskId)
return
}
if pTask.IsCurrentStageComplete() {
pTask.ScheduleRun(body)
err := pTask.ScheduleRun(body)
if err != nil {
saveTaskUpCallStatus(task.GetId(), parentTaskId, false, err.Error())
} else {
saveTaskUpCallStatus(task.GetId(), parentTaskId, true, "")
}
}
}()
}
if len(parentTaskNotify) > 0 {
notifyRemoteTask(ctx, parentTaskNotify, parentTaskId, body, 0)
header := task.getTaskHeader()
go notifyRemoteTask(ctx, parentTaskNotify, task.GetId(), header, body, 0)
}
}
func notifyRemoteTask(ctx context.Context, notifyUrl string, taskid string, body jsonutils.JSONObject, tried int) {
func notifyRemoteTask(ctx context.Context, notifyUrl string, taskId string, header http.Header, body jsonutils.JSONObject, tried uint) {
client := httputils.GetDefaultClient()
header := http.Header{}
if len(taskid) > 0 {
header.Set("X-Task-Id", taskid)
}
_, body, err := httputils.JSONRequest(client, ctx, "POST", notifyUrl, header, body, true)
_, body, err := httputils.JSONRequest(client, ctx, "POST", notifyUrl, header, body, false)
if err != nil {
log.Errorf("notifyRemoteTask fail %s", err)
if tried > MAX_REMOTE_NOTIFY_TRIES {
log.Errorf("notifyRemoteTask max tried reached, give up...")
saveTaskUpCallStatus(taskId, notifyUrl, false, fmt.Sprintf("notifyRemoteTask max tried reached, give up... %s", err.Error()))
} else {
notifyRemoteTask(ctx, notifyUrl, taskid, body, tried+1)
time.Sleep(time.Second * time.Duration(1<<tried))
notifyRemoteTask(ctx, notifyUrl, taskId, header, body, tried+1)
}
return
} else {
log.Infof("Notify remote URL %s get acked: %s, taskId: %s", notifyUrl, body.String(), taskId)
saveTaskUpCallStatus(taskId, notifyUrl, true, body.String())
}
log.Infof("Notify remote URL %s(%s) get acked: %s!", notifyUrl, taskid, body.String())
}
func (task *STask) NotifyParentTaskFailure(ctx context.Context, reason jsonutils.JSONObject) {
@@ -937,13 +944,18 @@ func (task *STask) GetObjects() []db.IStandaloneModel {
return task.taskObjects
}
func (task *STask) GetTaskRequestHeader() http.Header {
func (task *STask) getTaskHeader() http.Header {
userCred := task.GetUserCred()
if !userCred.IsValid() {
userCred = auth.AdminCredential()
}
header := mcclient.GetTokenHeaders(userCred)
header.Set(mcclient.TASK_ID, task.GetTaskId())
return header
}
func (task *STask) GetTaskRequestHeader() http.Header {
header := task.getTaskHeader()
if len(serviceUrl) > 0 {
notifyUrl := fmt.Sprintf("%s/tasks/%s", serviceUrl, task.GetTaskId())
header.Set(mcclient.TASK_NOTIFY_URL, notifyUrl)

View File

@@ -0,0 +1,89 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package taskman
import (
"fmt"
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
)
var _saveTaskUpcallWorkMan *appsrv.SWorkerManager
func init() {
_saveTaskUpcallWorkMan = appsrv.NewWorkerManager("SaveTaskUpcallResultWorkerManager", 1, 1024, true)
}
type saveUpcallStatusTask struct {
taskId string
target string
success bool
errMsg string
tm time.Time
}
func (task *saveUpcallStatusTask) Run() {
err := task.runInternal()
if err != nil {
log.Errorf("Task %s save upcall status fail %s", task.Dump(), err)
}
}
func (task *saveUpcallStatusTask) Dump() string {
return fmt.Sprintf("taskId: %s, success: %t, errMsg: %s", task.taskId, task.success, task.errMsg)
}
func saveTaskUpCallStatus(taskId string, target string, success bool, errMsg string) {
_saveTaskUpcallWorkMan.Run(&saveUpcallStatusTask{
taskId: taskId,
target: target,
success: success,
errMsg: errMsg,
tm: time.Now(),
}, nil, nil)
}
func (t *saveUpcallStatusTask) runInternal() error {
task := TaskManager.FetchTaskById(t.taskId)
_, err := db.Update(task, func() error {
params := jsonutils.NewDict()
params.Update(task.Params)
upcalls, _ := params.Get("__upcalls")
if upcalls == nil {
upcalls = jsonutils.NewArray()
params.Add(upcalls, "__upcalls")
}
upcallsList := upcalls.(*jsonutils.JSONArray)
upcallData := jsonutils.NewDict()
upcallData.Add(jsonutils.NewString(t.target), "target")
upcallData.Add(jsonutils.NewBool(t.success), "result")
upcallData.Add(jsonutils.NewString(t.errMsg), "msg")
upcallData.Add(jsonutils.NewTimeString(t.tm), "complete_at")
upcallsList.Add(upcallData)
task.Params = params
return nil
})
if err != nil {
return errors.Wrapf(err, "Update %s", t.taskId)
}
return nil
}

View File

@@ -20,6 +20,7 @@ import (
"net"
"net/http"
"yunion.io/x/log"
"yunion.io/x/pkg/tristate"
"yunion.io/x/onecloud/pkg/apis/compute"
@@ -52,9 +53,10 @@ func getBmAgentUrl(ctx context.Context, w http.ResponseWriter, r *http.Request)
return
}
}
n, _ := models.NetworkManager.GetOnPremiseNetworkOfIP(ipAddr, "", tristate.None)
log.Infof("getBmAgentUrl request ipaddr %s", ipAddr)
n, err := models.NetworkManager.GetOnPremiseNetworkOfIP(ipAddr, "", tristate.None)
if n == nil {
log.Errorf("failed get network of ip %s: %s", ipAddr, err)
httperrors.NotFoundError(ctx, w, "Network not found")
return
}
@@ -67,7 +69,8 @@ func getBmAgentUrl(ctx context.Context, w http.ResponseWriter, r *http.Request)
return
}
fmt.Fprintf(w, bmAgent.ManagerUri)
ret := fmt.Sprintf("%s %s", bmAgent.ManagerUri, ipAddr)
fmt.Fprintf(w, "%s", ret)
}
func getBmPrepareScript(ctx context.Context, w http.ResponseWriter, r *http.Request) {

View File

@@ -44,7 +44,7 @@ type SBaremetalagent struct {
SZoneResourceBase `width:"128" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"`
Status string `width:"36" charset:"ascii" nullable:"false" default:"disable" create:"optional"`
AccessIp string `width:"16" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"`
AccessIp string `width:"64" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"`
ManagerUri string `width:"256" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_required"`
// ZoneId string `width:"128" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"`

View File

@@ -901,47 +901,45 @@ func (manager *SCachedimageManager) ListItemFilter(
}
{
var idFilter bool
storagecachedImages := StoragecachedimageManager.Query("cachedimage_id").Equals("status", api.CACHED_IMAGE_STATUS_ACTIVE).SubQuery()
storageCaches := StoragecacheManager.Query().SubQuery()
storagecachedImages := StoragecachedimageManager.Query("cachedimage_id").Equals("status", api.CACHED_IMAGE_STATUS_ACTIVE) // .SubQuery()
storagecachedImages = storagecachedImages.Snapshot()
storagesQ := StorageManager.Query()
storagesQ := StorageManager.Query("storagecache_id")
storagesQ = storagesQ.Snapshot()
if query.Valid {
idFilter = true
storagesQ = storagesQ.In("status", []string{api.STORAGE_ENABLED, api.STORAGE_ONLINE}).IsTrue("enabled")
}
if len(query.CloudproviderId) > 0 {
idFilter = true
storagesQ = storagesQ.In("manager_id", query.CloudproviderId)
}
storages := storagesQ.SubQuery()
zonesQ := ZoneManager.Query()
if len(query.HostSchedtagId) > 0 {
hostschedtags := HostschedtagManager.Query("host_id").Equals("schedtag_id", query.HostSchedtagId)
hoststorages := HoststorageManager.Query("storage_id").In("host_id", hostschedtags.Distinct().SubQuery())
storagesQ = storagesQ.In("id", hoststorages.Distinct().SubQuery())
}
zonesQ := ZoneManager.Query("id")
zonesQ = zonesQ.Snapshot()
if len(query.ZoneId) > 0 {
idFilter = true
zonesQ = zonesQ.Equals("id", query.ZoneId)
}
if len(query.CloudregionId) > 0 {
idFilter = true
zonesQ = zonesQ.In("cloudregion_id", query.CloudregionId)
}
zones := zonesQ.SubQuery()
subq := storagecachedImages.Query(storagecachedImages.Field("cachedimage_id"))
subq = subq.Join(storageCaches, sqlchemy.Equals(storagecachedImages.Field("storagecache_id"), storageCaches.Field("id")))
subq = subq.Join(storages, sqlchemy.Equals(storageCaches.Field("id"), storages.Field("storagecache_id")))
subq = subq.Join(zones, sqlchemy.Equals(storages.Field("zone_id"), zones.Field("id")))
if len(query.HostSchedtagId) > 0 {
idFilter = true
hoststorages := HoststorageManager.Query("host_id", "storage_id").SubQuery()
hostschedtags := HostschedtagManager.Query().Equals("schedtag_id", query.HostSchedtagId).SubQuery()
subq = subq.Join(hoststorages, sqlchemy.Equals(hoststorages.Field("storage_id"), storages.Field("id")))
subq = subq.Join(hostschedtags, sqlchemy.Equals(hostschedtags.Field("host_id"), hoststorages.Field("host_id")))
if zonesQ.IsAltered() {
storagesQ = storagesQ.Filter(
sqlchemy.In(storagesQ.Field("zone_id"), zonesQ.Distinct().SubQuery()),
)
}
if idFilter {
subQ := subq.Distinct().SubQuery()
q = q.Join(subQ, sqlchemy.Equals(q.Field("id"), subQ.Field("cachedimage_id")))
if storagesQ.IsAltered() {
storagecachedImages = storagecachedImages.Filter(
sqlchemy.In(storagecachedImages.Field("storagecache_id"), storagesQ.Distinct().SubQuery()),
)
}
if storagecachedImages.IsAltered() {
q = q.In("id", storagecachedImages.Distinct().SubQuery())
}
}

View File

@@ -709,6 +709,7 @@ func (manager *SCloudregionManager) InitializeData() error {
defRegion.Description = "Default Region"
defRegion.Status = api.CLOUD_REGION_STATUS_INSERVER
defRegion.Provider = api.CLOUD_PROVIDER_ONECLOUD
defRegion.SetModelManager(manager, &defRegion)
err := manager.TableSpec().Insert(context.TODO(), &defRegion)
if err != nil {
return errors.Wrap(err, "insert default region")

View File

@@ -1031,13 +1031,18 @@ func (self *SGuest) StartRestartNetworkTask(ctx context.Context, userCred mcclie
return nil
}
func (self *SGuest) StartQgaRestartNetworkTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string, device string, ipMask string, gateway string, prevIp string, inBlockStream bool) error {
func (self *SGuest) StartQgaRestartNetworkTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId, device, ipMask, gateway, ip6Mask, gateway6 string) error {
data := jsonutils.NewDict()
data.Set("device", jsonutils.NewString(device))
data.Set("ip_mask", jsonutils.NewString(ipMask))
data.Set("gateway", jsonutils.NewString(gateway))
data.Set("prev_ip", jsonutils.NewString(prevIp))
data.Set("in_block_stream", jsonutils.NewBool(inBlockStream))
if len(ipMask) > 0 {
data.Set("ip_mask", jsonutils.NewString(ipMask))
data.Set("gateway", jsonutils.NewString(gateway))
}
if len(ip6Mask) > 0 {
data.Set("ip6_mask", jsonutils.NewString(ip6Mask))
data.Set("gateway6", jsonutils.NewString(gateway6))
}
if task, err := taskman.TaskManager.NewTask(ctx, "GuestQgaRestartNetworkTask", self, userCred, data, parentTaskId, "", nil); err != nil {
log.Errorln(err)
return err
@@ -1790,9 +1795,11 @@ func (self *SGuest) PerformRebuildRoot(
}
// compare os arch
if len(self.InstanceType) > 0 {
if len(img.Properties["os_arch"]) > 0 && len(self.OsArch) > 0 && !apis.IsSameArch(self.OsArch, img.Properties["os_arch"]) {
return nil, httperrors.NewConflictError("root disk image(%s) and guest(%s) OsArch mismatch", img.Properties["os_arch"], self.OsArch)
} else if len(self.InstanceType) > 0 {
sku, _ := ServerSkuManager.FetchSkuByNameAndProvider(self.InstanceType, region.Provider, true)
if sku != nil && len(sku.CpuArch) > 0 && len(img.Properties["os_arch"]) > 0 && !strings.Contains(img.Properties["os_arch"], sku.CpuArch) {
if sku != nil && len(sku.CpuArch) > 0 && len(img.Properties["os_arch"]) > 0 && !apis.IsSameArch(img.Properties["os_arch"], sku.CpuArch) {
return nil, httperrors.NewConflictError("root disk image(%s) and sku(%s) architecture mismatch", img.Properties["os_arch"], sku.CpuArch)
}
}
@@ -2755,9 +2762,13 @@ func (self *SGuest) PerformChangeIpaddr(
newMacAddr := networkJsonDesc.Mac
newMaskLen := networkJsonDesc.Masklen
newGateway := networkJsonDesc.Gateway
ipMask := fmt.Sprintf("%s/%d", newIpAddr, newMaskLen)
if conf.StrictIPv6 {
ipMask = fmt.Sprintf("%s/%d", networkJsonDesc.Ip6, networkJsonDesc.Masklen6)
ipMask := ""
if networkJsonDesc.Ip != "" {
ipMask = fmt.Sprintf("%s/%d", newIpAddr, newMaskLen)
}
ip6Mask := ""
if networkJsonDesc.Ip6 != "" {
ip6Mask = fmt.Sprintf("%s/%d", networkJsonDesc.Ip6, networkJsonDesc.Masklen6)
}
notes := gn.GetShortDesc(ctx)
@@ -2781,8 +2792,15 @@ func (self *SGuest) PerformChangeIpaddr(
return nil, errors.Wrapf(err, "GetNetwork")
}
taskData.Set("is_vpc_network", jsonutils.NewBool(net.isOneCloudVpcNetwork()))
taskData.Set("ip_mask", jsonutils.NewString(ipMask))
taskData.Set("gateway", jsonutils.NewString(newGateway))
if len(ipMask) > 0 {
taskData.Set("ip_mask", jsonutils.NewString(ipMask))
taskData.Set("gateway", jsonutils.NewString(newGateway))
}
if len(ip6Mask) > 0 {
taskData.Set("ip6_mask", jsonutils.NewString(ip6Mask))
taskData.Set("gateway6", jsonutils.NewString(networkJsonDesc.Gateway6))
}
if self.Status == api.VM_BLOCK_STREAM {
taskData.Set("in_block_stream", jsonutils.JSONTrue)
}

View File

@@ -502,11 +502,12 @@ func fetchGuestIPs(guestIds []string, virtual tristate.TriState) map[string][]st
func fetchGuestVips(guestIds []string) map[string][]string {
groupguests := GroupguestManager.Query().SubQuery()
groupnetworks := GroupnetworkManager.Query().SubQuery()
q := groupnetworks.Query(groupnetworks.Field("ip_addr"), groupguests.Field("guest_id"))
q := groupnetworks.Query(groupnetworks.Field("ip_addr"), groupnetworks.Field("ip6_addr"), groupguests.Field("guest_id"))
q = q.Join(groupguests, sqlchemy.Equals(q.Field("group_id"), groupguests.Field("group_id")))
q = q.In("guest_id", guestIds)
type sGuestVip struct {
IpAddr string
Ip6Addr string
GuestId string
}
gvips := make([]sGuestVip, 0)
@@ -519,7 +520,12 @@ func fetchGuestVips(guestIds []string) map[string][]string {
if _, ok := ret[gvips[i].GuestId]; !ok {
ret[gvips[i].GuestId] = make([]string, 0)
}
ret[gvips[i].GuestId] = append(ret[gvips[i].GuestId], gvips[i].IpAddr)
if len(gvips[i].IpAddr) > 0 {
ret[gvips[i].GuestId] = append(ret[gvips[i].GuestId], gvips[i].IpAddr)
}
if len(gvips[i].Ip6Addr) > 0 {
ret[gvips[i].GuestId] = append(ret[gvips[i].GuestId], gvips[i].Ip6Addr)
}
}
return ret
}

View File

@@ -434,6 +434,10 @@ func (manager *SGuestnetworkManager) newGuestNetwork(
gn.IsDefault = isDefault
}
if len(gn.Ip6Addr) > 0 && len(gn.IpAddr) == 0 {
gn.NumQueues = 1
}
err = manager.TableSpec().Insert(ctx, &gn)
if err != nil {
return nil, err

View File

@@ -2953,9 +2953,11 @@ func (self *SGuest) GetRealIPs() []string {
func (self *SGuest) IsExitOnly() bool {
for _, ip := range self.GetRealIPs() {
addr, _ := netutils.NewIPV4Addr(ip)
if !netutils.IsExitAddress(addr) {
return false
if regutils.MatchIP4Addr(ip) {
addr, _ := netutils.NewIPV4Addr(ip)
if !netutils.IsExitAddress(addr) {
return false
}
}
}
return true
@@ -2970,7 +2972,12 @@ func (self *SGuest) getVirtualIPs() []string {
continue
}
for _, groupnetwork := range groupnets {
ips = append(ips, groupnetwork.IpAddr)
if len(groupnetwork.IpAddr) > 0 {
ips = append(ips, groupnetwork.IpAddr)
}
if len(groupnetwork.Ip6Addr) > 0 {
ips = append(ips, groupnetwork.Ip6Addr)
}
}
}
return ips
@@ -2979,13 +2986,15 @@ func (self *SGuest) getVirtualIPs() []string {
func (self *SGuest) GetPrivateIPs() []string {
ips := self.GetRealIPs()
for i := len(ips) - 1; i >= 0; i-- {
ipAddr, err := netutils.NewIPV4Addr(ips[i])
if err != nil {
log.Errorf("guest %s(%s) has bad ipv4 address (%s): %v", self.Name, self.Id, ips[i], err)
continue
}
if !netutils.IsPrivate(ipAddr) {
ips = append(ips[:i], ips[i+1:]...)
if regutils.MatchIP4Addr(ips[i]) {
ipAddr, err := netutils.NewIPV4Addr(ips[i])
if err != nil {
log.Errorf("guest %s(%s) has bad ipv4 address (%s): %v", self.Name, self.Id, ips[i], err)
continue
}
if !netutils.IsPrivate(ipAddr) {
ips = append(ips[:i], ips[i+1:]...)
}
}
}
return ips

View File

@@ -4838,9 +4838,9 @@ func fetchIpmiInfo(data api.HostIpmiAttributes, hostId string) (types.SIPMIInfo,
info.Password = data.IpmiPassword
}
}
if len(data.IpmiIpAddr) > 0 && !regutils.MatchIP4Addr(data.IpmiIpAddr) {
msg := fmt.Sprintf("ipmi_ip_addr: %s not valid ipv4 address", data.IpmiIpAddr)
log.Errorf(msg)
if len(data.IpmiIpAddr) > 0 && !regutils.MatchIP4Addr(data.IpmiIpAddr) && !regutils.MatchIP6Addr(data.IpmiIpAddr) {
msg := fmt.Sprintf("ipmi_ip_addr: %v not valid address", data.IpmiIpAddr)
log.Errorf("%s", msg)
return info, errors.Wrap(httperrors.ErrInvalidFormat, msg)
}
info.IpAddr = data.IpmiIpAddr
@@ -5535,6 +5535,7 @@ func (hh *SHost) PerformInitialize(
guest.ProjectId = userCred.GetProjectId()
guest.DomainId = userCred.GetProjectDomainId()
guest.Status = api.VM_RUNNING
guest.PowerStates = api.VM_POWER_STATES_ON
guest.OsType = "Linux"
guest.SetModelManager(GuestManager, guest)
err = GuestManager.TableSpec().Insert(ctx, guest)

View File

@@ -95,11 +95,11 @@ type SNetwork struct {
IfnameHint string `width:"9" charset:"ascii" nullable:"true" list:"user" create:"optional"`
// 起始IP地址
GuestIpStart string `width:"16" charset:"ascii" nullable:"false" list:"user" update:"user" create:"optional"`
GuestIpStart string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"`
// 结束IP地址
GuestIpEnd string `width:"16" charset:"ascii" nullable:"false" list:"user" update:"user" create:"optional"`
GuestIpEnd string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"`
// 掩码
GuestIpMask int8 `nullable:"false" list:"user" update:"user" create:"optional"`
GuestIpMask int8 `nullable:"true" list:"user" update:"user" create:"optional"`
// 网关地址
GuestGateway string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"`
// DNS, allow multiple dns, seperated by ","
@@ -921,17 +921,39 @@ func (manager *SNetworkManager) fetchAllOnpremiseNetworks(serverType string, isP
}
func (manager *SNetworkManager) GetOnPremiseNetworkOfIP(ipAddr string, serverType string, isPublic tristate.TriState) (*SNetwork, error) {
address, err := netutils.NewIPV4Addr(ipAddr)
if err != nil {
return nil, errors.Wrap(err, "NewIPV4Addr")
var addr4 netutils.IPV4Addr
var addr6 netutils.IPV6Addr
var isIpv6Addr = false
var err error
if strings.Contains(ipAddr, ":") {
isIpv6Addr = true
}
if isIpv6Addr {
addr6, err = netutils.NewIPV6Addr(ipAddr)
if err != nil {
return nil, errors.Wrap(err, "NewIPV6Addr")
}
} else {
addr4, err = netutils.NewIPV4Addr(ipAddr)
if err != nil {
return nil, errors.Wrap(err, "NewIPV4Addr")
}
}
nets, err := manager.fetchAllOnpremiseNetworks(serverType, isPublic)
if err != nil {
return nil, errors.Wrap(err, "fetchAllOnpremiseNetworks")
}
for _, n := range nets {
if n.IsAddressInRange(address) {
return &n, nil
if isIpv6Addr {
if n.IsAddress6InRange(addr6) {
return &n, nil
}
} else {
if n.IsAddressInRange(addr4) {
return &n, nil
}
}
}
return nil, sql.ErrNoRows
@@ -2738,9 +2760,15 @@ func (manager *SNetworkManager) ListItemFilter(
ipStart := sqlchemy.INET_ATON(q.Field("guest_ip_start"))
ipEnd := sqlchemy.INET_ATON(q.Field("guest_ip_end"))
ipConst := sqlchemy.INET_ATON(q.StringField(ip4Addr.String()))
ipCondtion = sqlchemy.AND(
sqlchemy.GE(ipEnd, uint32(ip4Addr)),
sqlchemy.LE(ipStart, uint32(ip4Addr)),
sqlchemy.IsNotNull(q.Field("guest_ip_start")),
sqlchemy.IsNotNull(q.Field("guest_ip_end")),
sqlchemy.IsNotEmpty(q.Field("guest_ip_start")),
sqlchemy.IsNotEmpty(q.Field("guest_ip_end")),
sqlchemy.GE(ipEnd, ipConst),
sqlchemy.LE(ipStart, ipConst),
)
if !exactIpMatch {
ipCondtion = sqlchemy.OR(
@@ -2751,18 +2779,24 @@ func (manager *SNetworkManager) ListItemFilter(
}
} else if ip6Addr, err := netutils.NewIPV6Addr(ipstr); err == nil {
// ipv6 address, exactly
ipStart := q.Field("guest_ip6_start")
ipEnd := q.Field("guest_ip6_end")
ipStart := sqlchemy.INET6_ATON(q.Field("guest_ip6_start"))
ipEnd := sqlchemy.INET6_ATON(q.Field("guest_ip6_end"))
ipConst := sqlchemy.INET6_ATON(q.StringField(ip6Addr.String()))
ipCondtion = sqlchemy.AND(
sqlchemy.GE(ipEnd, ip6Addr.String()),
sqlchemy.LE(ipStart, ip6Addr.String()),
sqlchemy.IsNotNull(q.Field("guest_ip6_start")),
sqlchemy.IsNotNull(q.Field("guest_ip6_end")),
sqlchemy.IsNotEmpty(q.Field("guest_ip6_start")),
sqlchemy.IsNotEmpty(q.Field("guest_ip6_end")),
sqlchemy.GE(ipEnd, ipConst),
sqlchemy.LE(ipStart, ipConst),
)
if !exactIpMatch {
ipCondtion = sqlchemy.OR(
ipCondtion,
sqlchemy.Contains(q.Field("guest_ip6_start"), ipstr),
sqlchemy.Contains(q.Field("guest_ip6_end"), ipstr),
sqlchemy.Contains(q.Field("guest_ip6_start"), ip6Addr.String()),
sqlchemy.Contains(q.Field("guest_ip6_end"), ip6Addr.String()),
)
}
} else {
@@ -2884,6 +2918,8 @@ func (manager *SNetworkManager) ListItemFilter(
q = q.In("wire_id", subq.SubQuery())
}
q.DebugQuery()
return q, nil
}

View File

@@ -354,6 +354,7 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context, userCred
input.Provider = region.Provider
}
if input.Provider == api.CLOUD_PROVIDER_ONECLOUD {
input.CloudregionId = api.DEFAULT_REGION_ID
} else if utils.IsInStringArray(input.Provider, api.PRIVATE_CLOUD_PROVIDERS) {
input.Status = api.SkuStatusCreating
}

View File

@@ -45,26 +45,28 @@ func (self *GuestQgaRestartNetworkTask) OnRestartNetwork(ctx context.Context, gu
device, _ := self.Params.GetString("device")
ipMask, _ := self.Params.GetString("ip_mask")
gateway, _ := self.Params.GetString("gateway")
prevIp, _ := self.Params.GetString("prev_ip")
inBlockStream, _ := self.Params.Bool("in_block_stream")
ip6Mask, _ := self.Params.GetString("ip6_mask")
gateway6, _ := self.Params.GetString("gateway6")
_, err := self.requestSetNetwork(ctx, guest, device, ipMask, gateway)
_, err := self.requestSetNetwork(ctx, guest, device, ipMask, gateway, ip6Mask, gateway6)
if err != nil {
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_RESTART_NETWORK, err, self.UserCred, false)
self.taskFailed(ctx, guest, prevIp, inBlockStream, err)
self.taskFailed(ctx, guest, err)
}
}
func (self *GuestQgaRestartNetworkTask) requestSetNetwork(ctx context.Context, guest *models.SGuest, device string, ipMask string, gateway string) (jsonutils.JSONObject, error) {
func (self *GuestQgaRestartNetworkTask) requestSetNetwork(ctx context.Context, guest *models.SGuest, device, ipMask, gateway, ip6Mask, gateway6 string) (jsonutils.JSONObject, error) {
host, err := guest.GetHost()
if err != nil {
self.taskFailed(ctx, guest, "", false, err)
self.taskFailed(ctx, guest, err)
return nil, err
}
inputQgaNet := &api.ServerQgaSetNetworkInput{
Device: device,
Ipmask: ipMask,
Gateway: gateway,
Device: device,
Ipmask: ipMask,
Gateway: gateway,
Ip6mask: ip6Mask,
Gateway6: gateway6,
}
// if success, log network related information
@@ -85,12 +87,10 @@ func (self *GuestQgaRestartNetworkTask) OnSetNetwork(ctx context.Context, guest
}
func (self *GuestQgaRestartNetworkTask) OnSetNetworkFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
prevIp, _ := self.Params.GetString("prev_ip")
inBlockStream, _ := self.Params.Bool("in_block_stream")
self.taskFailed(ctx, guest, prevIp, inBlockStream, errors.Errorf(data.String()))
self.taskFailed(ctx, guest, errors.Errorf(data.String()))
}
func (self *GuestQgaRestartNetworkTask) taskFailed(ctx context.Context, guest *models.SGuest, prevIp string, inBlockStream bool, err error) {
func (self *GuestQgaRestartNetworkTask) taskFailed(ctx context.Context, guest *models.SGuest, err error) {
guest.SetStatus(ctx, self.GetUserCred(), api.VM_QGA_SET_NETWORK_FAILED, err.Error())
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_RESTART_NETWORK, jsonutils.NewString(err.Error()), self.UserCred, false)
self.SetStageFailed(ctx, nil)

View File

@@ -75,24 +75,20 @@ func (self *GuestSyncConfTask) OnSyncComplete(ctx context.Context, obj db.IStand
func (self *GuestSyncConfTask) StartRestartNetworkTask(ctx context.Context, guest *models.SGuest) {
defer self.SetStageComplete(ctx, guest.GetShortDesc(ctx))
prevIp, err := self.Params.GetString("prev_ip")
if err != nil {
log.Errorf("unable to get prev_ip when restart_network is true when sync guest")
return
}
inBlockStream := jsonutils.QueryBoolean(self.Params, "in_block_stream", false)
preMac, err := self.Params.GetString("prev_mac")
if err != nil {
log.Errorf("unable to get prev_mac when restart_network is true when sync guest")
return
}
ipMask, err := self.Params.GetString("ip_mask")
if err != nil {
gateway, err := self.Params.GetString("gateway")
ip6Mask, err := self.Params.GetString("ip6_mask")
gateway6, err := self.Params.GetString("gateway6")
if ipMask == "" && ip6Mask == "" {
log.Errorf("unable to get ip_mask when restart_network is true when sync guest")
return
}
gateway, err := self.Params.GetString("gateway")
if err != nil {
if gateway == "" && gateway6 == "" {
log.Errorf("unable to get gateway when restart_network is true when sync guest")
return
}
@@ -128,8 +124,7 @@ func (self *GuestSyncConfTask) StartRestartNetworkTask(ctx context.Context, gues
// wait for vpcagent sync network topo
time.Sleep(10 * time.Second)
}
return guest.StartQgaRestartNetworkTask(
ctx, self.UserCred, "", ifnameDevice, ipMask, gateway, prevIp, inBlockStream)
return guest.StartQgaRestartNetworkTask(ctx, self.UserCred, "", ifnameDevice, ipMask, gateway, ip6Mask, gateway6)
}()
if err != nil {
log.Errorf("guest %s failed start qga restart network task: %s", guest.GetName(), err)

View File

@@ -53,7 +53,7 @@ func (self *SecurityGroupCreateTask) OnInit(ctx context.Context, obj db.IStandal
}
rules := api.SSecgroupRuleResourceSet{}
self.GetParams().Unmarshal(&rules)
self.GetParams().Unmarshal(&rules, "rules")
driver := region.GetDriver()
err = driver.RequestCreateSecurityGroup(ctx, self.GetUserCred(), secgroup, rules)

View File

@@ -458,6 +458,26 @@ func (l *sLinuxRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*ty
log.Errorf("rootFs.GenerateSshHostKeys fail %s", err)
}
}
{
// deploy /etc/gai.conf if both IPv4 and IPv6 are enabled
v4Enabled := false
v6Enabled := false
for _, nic := range nics {
if nic.Ip != "" {
v4Enabled = true
}
if nic.Ip6 != "" {
v6Enabled = true
}
if v4Enabled && v6Enabled {
// prefer IPv4 over IPv6 by default of /etc/gai.conf not present
if !rootFs.Exists("/etc/gai.conf", false) {
rootFs.FilePutContents("/etc/gai.conf", "precedence ::ffff:0:0/96 100\n", false, false)
}
break
}
}
}
return nil
}
@@ -990,7 +1010,7 @@ func (d *sDebianLikeRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics
cmds.WriteString(fmt.Sprintf(" up ip -6 route add %s/%d via %s || true\n", r.Prefix, r.PrefixLen, r.Gateway))
cmds.WriteString(fmt.Sprintf(" down ip -6 route del %s/%d via %s || true\n", r.Prefix, r.PrefixLen, r.Gateway))
}
dnslist := netutils2.GetNicDns(nicDesc)
dnslist, _ := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-nameservers %s\n", strings.Join(dnslist, " ")))
dnss = append(dnss, dnslist...)
@@ -1001,15 +1021,6 @@ func (d *sDebianLikeRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics
if nicDesc.Mtu > 0 {
cmds.WriteString(fmt.Sprintf(" mtu %d\n", nicDesc.Mtu))
}
dnslist := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-nameservers %s\n", strings.Join(dnslist, " ")))
dnss = append(dnss, dnslist...)
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-search %s\n", nicDesc.Domain))
domains = append(domains, nicDesc.Domain)
}
}
if len(nicDesc.TeamingSlaves) > 0 {
cmds.WriteString(getNicTeamingConfigCmds(nicDesc.TeamingSlaves))
}
@@ -1023,6 +1034,15 @@ func (d *sDebianLikeRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics
if len(nicDesc.Gateway6) > 0 && nicDesc.Ip == mainIp {
cmds.WriteString(fmt.Sprintf(" gateway %s\n", nicDesc.Gateway6))
}
_, dnslist := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-nameservers %s\n", strings.Join(dnslist, " ")))
dnss = append(dnss, dnslist...)
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-search %s\n", nicDesc.Domain))
domains = append(domains, nicDesc.Domain)
}
}
cmds.WriteString("\n")
}
} else {
@@ -1284,8 +1304,24 @@ func (r *sRedhatLikeRootFs) PrepareFsForTemplate(rootFs IDiskPartition) error {
return r.CleanNetworkScripts(rootFs)
}
func (r *sRedhatLikeRootFs) cleanNetworkManagerConfigurations(rootFs IDiskPartition) error {
networkPath := "/etc/NetworkManager/system-connections"
if !rootFs.Exists(networkPath, false) {
return nil
}
files := rootFs.ListDir(networkPath, false)
for _, f := range files {
rootFs.Remove(filepath.Join(networkPath, f), false)
}
return nil
}
func (r *sRedhatLikeRootFs) CleanNetworkScripts(rootFs IDiskPartition) error {
networkPath := "/etc/sysconfig/network-scripts"
if !rootFs.Exists(networkPath, false) {
return r.cleanNetworkManagerConfigurations(rootFs)
}
files := rootFs.ListDir(networkPath, false)
for i := 0; i < len(files); i++ {
if strings.HasPrefix(files[i], "ifcfg-") && files[i] != "ifcfg-lo" {
@@ -1301,16 +1337,18 @@ func (r *sRedhatLikeRootFs) CleanNetworkScripts(rootFs IDiskPartition) error {
func (r *sRedhatLikeRootFs) RootSignatures() []string {
sig := r.sLinuxRootFs.RootSignatures()
return append([]string{"/etc/sysconfig/network", "/etc/redhat-release"}, sig...)
return append([]string{"/etc/redhat-release"}, sig...)
}
func (r *sRedhatLikeRootFs) DeployHostname(rootFs IDiskPartition, hn, domain string) error {
var sPath = "/etc/sysconfig/network"
centosHn := ""
centosHn += "NETWORKING=yes\n"
centosHn += fmt.Sprintf("HOSTNAME=%s\n", getHostname(hn, domain))
if err := rootFs.FilePutContents(sPath, centosHn, false, false); err != nil {
return errors.Wrapf(err, "DeployHostname %s", sPath)
if r.rootFs.Exists(sPath, false) {
centosHn := ""
centosHn += "NETWORKING=yes\n"
centosHn += fmt.Sprintf("HOSTNAME=%s\n", getHostname(hn, domain))
if err := rootFs.FilePutContents(sPath, centosHn, false, false); err != nil {
return errors.Wrapf(err, "DeployHostname %s", sPath)
}
}
if err := rootFs.FilePutContents("/etc/hostname", hn, false, false); err != nil {
return errors.Wrapf(err, "DeployHostname %s", "/etc/hostname")
@@ -1379,17 +1417,51 @@ func (r *sRedhatLikeRootFs) isNetworkManagerEnabled(rootFs IDiskPartition) bool
return rootFs.Exists("/etc/systemd/system/multi-user.target.wants/NetworkManager.service", false)
}
func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic, relInfo *deployapi.ReleaseInfo) error {
// remove all ifcfg-*
const scriptPath = "/etc/sysconfig/network-scripts"
func (r *sRedhatLikeRootFs) deployNetworkManagerConfigurations(rootFs IDiskPartition, nics []*types.SServerNic, relInfo *deployapi.ReleaseInfo) error {
const scriptPath = "/etc/NetworkManager/system-connections"
if !rootFs.Exists(scriptPath, false) {
return errors.Wrap(errors.ErrNotSupported, "unsupported system, neither network-scripts nor NetworkManager")
}
// remove all connections profiles
files := rootFs.ListDir(scriptPath, false)
for _, f := range files {
if strings.HasPrefix(f, "ifcfg-") && f != "ifcfg-lo" {
log.Infof("remove %s in %s", f, scriptPath)
rootFs.Remove(filepath.Join(scriptPath, f), false)
log.Infof("remove %s in %s", f, scriptPath)
rootFs.Remove(filepath.Join(scriptPath, f), false)
}
allNics, bondNics := convertNicConfigs(nics)
if len(bondNics) > 0 {
err := r.enableBondingModule(rootFs, bondNics)
if err != nil {
return errors.Wrap(err, "enableBondingModule")
}
}
nicCnt := len(allNics) - len(bondNics)
mainNic := getMainNic(allNics)
var mainIp string
if mainNic != nil {
mainIp = mainNic.Ip
}
mainNic6 := getMainNic6(allNics)
var mainIp6 string
if mainNic6 != nil {
mainIp6 = mainNic6.Ip6
}
for i := range allNics {
nicDesc := allNics[i]
profile := nicDescToNetworkManager(nicDesc, mainIp, mainIp6, nicCnt)
var fn = fmt.Sprintf("%s/%s.nmconnection", scriptPath, nicDesc.Name)
if err := rootFs.FilePutContents(fn, profile, false, false); err != nil {
return err
}
}
return nil
}
func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic, relInfo *deployapi.ReleaseInfo) error {
ver := strings.Split(relInfo.Version, ".")
iv, err := strconv.ParseInt(ver[0], 10, 0)
if err == nil && iv < 6 {
@@ -1400,6 +1472,21 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
if err != nil {
return errors.Wrap(err, "DeployNetworkingScripts")
}
const scriptPath = "/etc/sysconfig/network-scripts"
if !rootFs.Exists(scriptPath, false) {
// NetworkManager is enabled, but no network-scripts directory, deploy NetworkManager configurations
return r.deployNetworkManagerConfigurations(rootFs, nics, relInfo)
}
// remove all ifcfg-*
files := rootFs.ListDir(scriptPath, false)
for _, f := range files {
if strings.HasPrefix(f, "ifcfg-") && f != "ifcfg-lo" {
log.Infof("remove %s in %s", f, scriptPath)
rootFs.Remove(filepath.Join(scriptPath, f), false)
}
}
// ToServerNics(nics)
allNics, bondNics := convertNicConfigs(nics)
if len(bondNics) > 0 {
@@ -1452,7 +1539,7 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
cmds.WriteString("\n")
}
if len(nicDesc.TeamingSlaves) > 0 {
// bonding
// bonding master
cmds.WriteString(`BONDING_OPTS="mode=4 miimon=100"`)
cmds.WriteString("\n")
}
@@ -1489,15 +1576,6 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
cmds.WriteString("\n")
}
}
if len(nicDesc.Ip6) > 0 {
cmds.WriteString("IPV6INIT=yes\n")
cmds.WriteString("DHCPV6C=no\n")
cmds.WriteString("IPV6_AUTOCONF=no\n")
cmds.WriteString(fmt.Sprintf("IPV6ADDR=%s/%d\n", nicDesc.Ip6, nicDesc.Masklen6))
if len(nicDesc.Gateway6) > 0 && nicDesc.Ip6 == mainIp6 {
cmds.WriteString(fmt.Sprintf("IPV6_DEFAULTGW=%s\n", nicDesc.Gateway6))
}
}
routes4 := make([]netutils2.SRouteInfo, 0)
routes6 := make([]netutils2.SRouteInfo, 0)
routes4, routes6 = netutils2.AddNicRoutes(routes4, routes6, nicDesc, mainIp, mainIp6, nicCnt)
@@ -1524,15 +1602,30 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
if err := rootFs.FilePutContents(fn, rtblStr, false, false); err != nil {
return err
}
dnslist := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
cmds.WriteString("PEERDNS=yes\n")
for i := 0; i < len(dnslist); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", i+1, dnslist[i]))
}
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf("DOMAIN=%s\n", nicDesc.Domain))
}
}
dns4list, dns6list := netutils2.GetNicDns(nicDesc)
if len(dns4list)+len(dns6list) > 0 {
cmds.WriteString("PEERDNS=yes\n")
dnsIdx := 1
for i := 0; i < len(dns4list); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", dnsIdx, dns4list[i]))
dnsIdx += 1
}
for i := 0; i < len(dns6list); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", dnsIdx, dns6list[i]))
dnsIdx += 1
}
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf("DOMAIN=%s\n", nicDesc.Domain))
}
}
if len(nicDesc.Ip6) > 0 {
cmds.WriteString("IPV6INIT=yes\n")
cmds.WriteString("DHCPV6C=no\n")
cmds.WriteString("IPV6_AUTOCONF=no\n")
cmds.WriteString(fmt.Sprintf("IPV6ADDR=%s/%d\n", nicDesc.Ip6, nicDesc.Masklen6))
if len(nicDesc.Gateway6) > 0 && nicDesc.Ip6 == mainIp6 {
cmds.WriteString(fmt.Sprintf("IPV6_DEFAULTGW=%s\n", nicDesc.Gateway6))
}
}
}
@@ -1624,11 +1717,17 @@ func (r *sRedhatLikeRootFs) deployVlanNetworkingScripts(rootFs IDiskPartition, s
return err
}
}
dnslist := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
dns4list, dns6list := netutils2.GetNicDns(nicDesc)
if len(dns4list)+len(dns6list) > 0 {
cmds.WriteString("PEERDNS=yes\n")
for i := 0; i < len(dnslist); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", i+1, dnslist[i]))
dnsIdx := 1
for i := 0; i < len(dns4list); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", dnsIdx, dns4list[i]))
dnsIdx += 1
}
for i := 0; i < len(dns6list); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", dnsIdx, dns6list[i]))
dnsIdx += 1
}
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf("DOMAIN=%s\n", nicDesc.Domain))

View File

@@ -144,10 +144,13 @@ func getNetplanEthernetConfig(nic *types.SServerNic, isBond bool, mainIp, mainIp
})
}
dns4list, dns6list := netutils2.GetNicDns(nic)
dnslist := append(dns4list, dns6list...)
nicConf = netplan.NewStaticEthernetConfig(
addr, addr6, gateway, gateway6,
[]string{nic.Domain},
netutils2.GetNicDns(nic),
dnslist,
routes,
)
nicConf.MacAddress = nic.Mac

View File

@@ -0,0 +1,144 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package fsdriver
import (
"fmt"
"strings"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/types"
"yunion.io/x/onecloud/pkg/util/netutils2"
"yunion.io/x/onecloud/pkg/util/stringutils2"
)
func nicDescToNetworkManager(nicDesc *types.SServerNic, mainIp string, mainIp6 string, nicCnt int) string {
var profile strings.Builder
profile.WriteString("[connection]\n")
profile.WriteString(fmt.Sprintf("id=%s\n", nicDesc.Name))
profile.WriteString(fmt.Sprintf("uuid=%s\n", stringutils2.GenUuid(nicDesc.Name, nicDesc.Mac)))
profile.WriteString(fmt.Sprintf("interface-name=%s\n", nicDesc.Name))
if len(nicDesc.TeamingSlaves) > 0 {
// bonding master
profile.WriteString("type=bond\n")
profile.WriteString("autoconnect=true\n")
} else {
profile.WriteString("type=ethernet\n")
if nicDesc.TeamingMaster != nil {
// bonding slave
profile.WriteString(fmt.Sprintf("master=%s\n", nicDesc.TeamingMaster.Name))
profile.WriteString("slave-type=bond\n")
} else {
// normal interface
profile.WriteString("autoconnect=true\n")
}
}
profile.WriteString("\n")
if len(nicDesc.TeamingSlaves) > 0 {
profile.WriteString("[bond]\n")
profile.WriteString("mode=802.3ad\n")
profile.WriteString("miimon=100\n")
profile.WriteString("\n")
}
if len(nicDesc.Mac) > 0 && nicDesc.NicType != api.NIC_TYPE_INFINIBAND {
profile.WriteString("[ethernet]\n")
profile.WriteString(fmt.Sprintf("mac-address=%s\n", nicDesc.Mac))
if nicDesc.Mtu > 0 {
profile.WriteString(fmt.Sprintf("mtu=%d\n", nicDesc.Mtu))
}
profile.WriteString("\n")
}
if nicDesc.TeamingMaster != nil {
// slave interface
profile.WriteString("[ipv4]\n")
profile.WriteString("method=disabled\n\n")
profile.WriteString("[ipv6]\n")
profile.WriteString("method=disabled\n\n")
} else if nicDesc.Virtual {
// virtual interface
profile.WriteString("[ipv4]\n")
profile.WriteString("method=manual\n")
profile.WriteString(fmt.Sprintf("address1=%s/32\n", netutils2.PSEUDO_VIP))
profile.WriteString("\n")
} else if nicDesc.Manual {
routes4 := make([]netutils2.SRouteInfo, 0)
routes6 := make([]netutils2.SRouteInfo, 0)
routes4, routes6 = netutils2.AddNicRoutes(routes4, routes6, nicDesc, mainIp, mainIp6, nicCnt)
// manual interface
if len(nicDesc.Ip) > 0 {
profile.WriteString("[ipv4]\n")
profile.WriteString("method=manual\n")
profile.WriteString(fmt.Sprintf("address1=%s/%d\n", nicDesc.Ip, nicDesc.Masklen))
if len(nicDesc.Gateway) > 0 && nicDesc.Ip == mainIp {
profile.WriteString(fmt.Sprintf("gateway=%s\n", nicDesc.Gateway))
}
// dns
dnslist, _ := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
profile.WriteString(fmt.Sprintf("dns=%s\n", strings.Join(dnslist, ",")))
}
// static routes
for i := range routes4 {
gwstr := routes4[i].Gateway.String()
if gwstr == "0.0.0.0" {
profile.WriteString(fmt.Sprintf("route%d=%s\n", i+1, routes4[i].SPrefixInfo.String()))
} else {
profile.WriteString(fmt.Sprintf("route%d=%s,%s\n", i+1, routes4[i].SPrefixInfo.String(), gwstr))
}
}
profile.WriteString("\n")
}
if len(nicDesc.Ip6) > 0 {
profile.WriteString("[ipv6]\n")
profile.WriteString("method=manual\n")
profile.WriteString(fmt.Sprintf("address1=%s/%d\n", nicDesc.Ip6, nicDesc.Masklen6))
if len(nicDesc.Gateway6) > 0 && nicDesc.Ip6 == mainIp6 {
profile.WriteString(fmt.Sprintf("gateway=%s\n", nicDesc.Gateway6))
}
// dns
_, dns6list := netutils2.GetNicDns(nicDesc)
if len(dns6list) > 0 {
profile.WriteString(fmt.Sprintf("dns=%s\n", strings.Join(dns6list, ",")))
}
// static routes
for i := range routes6 {
gwstr := routes6[i].Gateway.String()
if gwstr == "::" {
profile.WriteString(fmt.Sprintf("route%d=%s\n", i+1, routes6[i].SPrefixInfo.String()))
} else {
profile.WriteString(fmt.Sprintf("route%d=%s,%s\n", i+1, routes6[i].SPrefixInfo.String(), gwstr))
}
}
profile.WriteString("\n")
}
} else {
// dhcp interface
if len(nicDesc.Ip) > 0 {
profile.WriteString("[ipv4]\n")
profile.WriteString("method=auto\n\n")
}
if len(nicDesc.Ip6) > 0 {
profile.WriteString("[ipv6]\n")
profile.WriteString("method=auto\n\n")
}
}
return profile.String()
}

View File

@@ -0,0 +1,230 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package fsdriver
import (
"testing"
"yunion.io/x/onecloud/pkg/cloudcommon/types"
)
func TestNicDescToNetworkManager(t *testing.T) {
cases := []struct {
nicDesc *types.SServerNic
mainIp string
mainIp6 string
want string
}{
{
nicDesc: &types.SServerNic{
Name: "eth0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Manual: false,
Mtu: 1440,
},
mainIp: "192.168.1.100",
mainIp6: "2001:db8::1",
want: `[connection]
id=eth0
uuid=de05e375-af25-9477-66ca-d4f41fe5e750
interface-name=eth0
type=ethernet
autoconnect=true
[ethernet]
mac-address=00:22:0a:0b:0c:0d
mtu=1440
[ipv4]
method=auto
[ipv6]
method=auto
`,
},
{
nicDesc: &types.SServerNic{
Name: "eth0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Manual: true,
},
mainIp: "192.168.1.100",
mainIp6: "2001:db8::200",
want: `[connection]
id=eth0
uuid=de05e375-af25-9477-66ca-d4f41fe5e750
interface-name=eth0
type=ethernet
autoconnect=true
[ethernet]
mac-address=00:22:0a:0b:0c:0d
[ipv4]
method=manual
address1=192.168.1.100/24
gateway=192.168.1.1
route1=169.254.169.254/32
[ipv6]
method=manual
address1=2001:db8::200/64
gateway=2001:db8::1
route1=fd00:ec2::254/128
`,
},
{
nicDesc: &types.SServerNic{
Name: "eth0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Domain: "onecloud.io",
Dns: "192.168.1.1,192.168.1.2,fc00::3fe:1",
Manual: true,
},
mainIp: "192.168.2.100",
mainIp6: "2001:db7::100",
want: `[connection]
id=eth0
uuid=de05e375-af25-9477-66ca-d4f41fe5e750
interface-name=eth0
type=ethernet
autoconnect=true
[ethernet]
mac-address=00:22:0a:0b:0c:0d
[ipv4]
method=manual
address1=192.168.1.100/24
dns=192.168.1.1,192.168.1.2
[ipv6]
method=manual
address1=2001:db8::200/64
dns=fc00::3fe:1
`,
},
{
nicDesc: &types.SServerNic{
Name: "bond0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Domain: "onecloud.io",
Dns: "192.168.1.1,192.168.1.2,fc00::3fe:1",
TeamingSlaves: []*types.SServerNic{
{
Name: "eth0",
},
{
Name: "eth1",
},
},
},
mainIp: "192.168.2.100",
mainIp6: "2001:db7::100",
want: `[connection]
id=bond0
uuid=01bf7157-f43f-58f4-15b0-cfb6d6dfdb5b
interface-name=bond0
type=bond
autoconnect=true
[bond]
mode=802.3ad
miimon=100
[ethernet]
mac-address=00:22:0a:0b:0c:0d
[ipv4]
method=auto
[ipv6]
method=auto
`,
},
{
nicDesc: &types.SServerNic{
Name: "eth0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Domain: "onecloud.io",
Dns: "192.168.1.1,192.168.1.2,fc00::3fe:1",
TeamingMaster: &types.SServerNic{
Name: "bond0",
},
},
mainIp: "192.168.2.100",
mainIp6: "2001:db7::100",
want: `[connection]
id=eth0
uuid=de05e375-af25-9477-66ca-d4f41fe5e750
interface-name=eth0
type=ethernet
master=bond0
slave-type=bond
[ethernet]
mac-address=00:22:0a:0b:0c:0d
[ipv4]
method=disabled
[ipv6]
method=disabled
`,
},
}
for _, c := range cases {
got := nicDescToNetworkManager(c.nicDesc, c.mainIp, c.mainIp6, 1)
if got != c.want {
t.Errorf("[[got]]\n%s\n[[want]]\n%s\n[[end]]", got, c.want)
}
}
}

View File

@@ -41,7 +41,7 @@ func (d *SRockyRootFs) String() string {
func (d *SRockyRootFs) RootSignatures() []string {
sig := d.sLinuxRootFs.RootSignatures()
return append([]string{"/etc/sysconfig/network", "/etc/rocky-release"}, sig...)
return append([]string{"/etc/rocky-release"}, sig...)
}
func (d *SRockyRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.ReleaseInfo {

View File

@@ -152,10 +152,15 @@ func (r *sSuseLikeRootFs) deployVlanNetworkingScripts(rootFs IDiskPartition, scr
}
}
dnslist := netutils2.GetNicDns(nicDesc)
for i := 0; i < len(dnslist); i++ {
if !utils.IsInArray(dnslist[i], dnsSrv) {
dnsSrv = append(dnsSrv, dnslist[i])
dns4list, dns6list := netutils2.GetNicDns(nicDesc)
for i := 0; i < len(dns4list); i++ {
if !utils.IsInArray(dns4list[i], dnsSrv) {
dnsSrv = append(dnsSrv, dns4list[i])
}
}
for i := 0; i < len(dns6list); i++ {
if !utils.IsInArray(dns6list[i], dnsSrv) {
dnsSrv = append(dnsSrv, dns6list[i])
}
}
@@ -165,6 +170,25 @@ func (r *sSuseLikeRootFs) deployVlanNetworkingScripts(rootFs IDiskPartition, scr
return err
}
if len(dnsSrv) > 0 {
cont, err := rootFs.FileGetContents("/etc/sysconfig/network/config", false)
if err != nil {
return errors.Wrap(err, "FileGetContents config")
}
lines := strings.Split(string(cont), "\n")
for i := range lines {
line := strings.TrimSpace(lines[i])
if strings.HasPrefix(line, "NETCONFIG_DNS_STATIC_SERVERS=") {
lines[i] = fmt.Sprintf("NETCONFIG_DNS_STATIC_SERVERS=\"%s\"", strings.Join(dnsSrv, " "))
}
}
err = rootFs.FilePutContents("/etc/sysconfig/network/config", strings.Join(lines, "\n"), false, false)
if err != nil {
return errors.Wrap(err, "FilePutContents config")
}
}
return nil
}
@@ -286,12 +310,17 @@ func (r *sSuseLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics []
if err := rootFs.FilePutContents(fn, rtblStr, false, false); err != nil {
return err
}
}
dnslist := netutils2.GetNicDns(nicDesc)
for i := 0; i < len(dnslist); i++ {
if !utils.IsInArray(dnslist[i], dnsSrv) {
dnsSrv = append(dnsSrv, dnslist[i])
}
dns4list, dns6list := netutils2.GetNicDns(nicDesc)
for i := 0; i < len(dns4list); i++ {
if !utils.IsInArray(dns4list[i], dnsSrv) {
dnsSrv = append(dnsSrv, dns4list[i])
}
}
for i := 0; i < len(dns6list); i++ {
if !utils.IsInArray(dns6list[i], dnsSrv) {
dnsSrv = append(dnsSrv, dns6list[i])
}
}

View File

@@ -351,13 +351,22 @@ func (w *SWindowsRootFs) DeployNetworkingScripts(rootfs IDiskPartition, nics []*
for _, r := range routes6 {
lines = append(lines, fmt.Sprintf(` netsh interface ipv6 add route %s/%d %s "%%%%b"`, r.Prefix, r.PrefixLen, r.Gateway.String()))
}
dnslist := netutils2.GetNicDns(snic)
if len(dnslist) > 0 {
dns4list, dns6list := netutils2.GetNicDns(snic)
if len(dns4list) > 0 {
lines = append(lines, fmt.Sprintf(
` netsh interface ip set dns name="%%%%b" source=static addr=%s`, dnslist[0]))
if len(dnslist) > 1 {
for i := 1; i < len(dnslist); i++ {
lines = append(lines, fmt.Sprintf(` netsh interface ip add dns "%%%%b" %s index=%d`, dnslist[i], i+1))
` netsh interface ip set dns name="%%%%b" source=static addr=%s`, dns4list[0]))
if len(dns4list) > 1 {
for i := 1; i < len(dns4list); i++ {
lines = append(lines, fmt.Sprintf(` netsh interface ip add dns "%%%%b" %s index=%d`, dns4list[i], i+1))
}
}
}
if len(dns6list) > 0 {
lines = append(lines, fmt.Sprintf(
` netsh interface ipv6 set dns name="%%%%b" source=static addr=%s`, dns6list[0]))
if len(dns6list) > 1 {
for i := 1; i < len(dns6list); i++ {
lines = append(lines, fmt.Sprintf(` netsh interface ip add dns "%%%%b" %s index=%d`, dns6list[i], i+1))
}
}
}

View File

@@ -103,9 +103,11 @@ func (m *SGuestManager) QgaGuestInfoTask(sid string) (string, error) {
func (m *SGuestManager) QgaSetNetwork(ctx context.Context, params interface{}) (jsonutils.JSONObject, error) {
input := params.(*SQgaGuestSetNetwork)
netmod := &monitor.NetworkModify{
Device: input.Device,
Ipmask: input.Ipmask,
Gateway: input.Gateway,
Device: input.Device,
Ipmask: input.Ipmask,
Gateway: input.Gateway,
Ip6mask: input.Ip6mask,
Gateway6: input.Gateway6,
}
guest, err := m.checkAndInitGuestQga(input.Sid)

View File

@@ -995,18 +995,20 @@ func qgaSetNetwork(ctx context.Context, userCred mcclient.TokenCredential, sid s
if input.Device == "" {
return nil, httperrors.NewMissingParameterError("device")
}
if input.Ipmask == "" {
if input.Ipmask == "" && input.Ip6mask == "" {
return nil, httperrors.NewMissingParameterError("ipmask")
}
if input.Gateway == "" {
if input.Gateway == "" && input.Gateway6 == "" {
return nil, httperrors.NewMissingParameterError("gateway")
}
hostutils.DelayTask(ctx, guestman.GetGuestManager().QgaSetNetwork, &guestman.SQgaGuestSetNetwork{
Sid: sid,
Device: input.Device,
Ipmask: input.Ipmask,
Gateway: input.Gateway,
Sid: sid,
Device: input.Device,
Ipmask: input.Ipmask,
Gateway: input.Gateway,
Ip6mask: input.Ip6mask,
Gateway6: input.Gateway6,
})
return nil, nil

View File

@@ -214,11 +214,13 @@ type SQgaGuestSetPassword struct {
}
type SQgaGuestSetNetwork struct {
Timeout int
Sid string
Device string
Ipmask string
Gateway string
Timeout int
Sid string
Device string
Ipmask string
Gateway string
Ip6mask string
Gateway6 string
}
type CpuSetCounter struct {

View File

@@ -398,6 +398,8 @@ func (m *SGuestManager) Bootstrap() (chan struct{}, error) {
go m.cpufreqSimulateManager.StartSetCpuFreqSimulate()
}
m.host.OnGuestLoadingComplete()
return m.dirtyServersChan, nil
}
@@ -570,8 +572,12 @@ func (m *SGuestManager) CPUSetRemove(ctx context.Context, sid string) error {
return guest.CPUSetRemove(ctx)
}
func (m *SGuestManager) IsGuestDir(f os.FileInfo) bool {
return hostutils.IsGuestDir(f, m.ServersPath)
func (m *SGuestManager) IsGuestDir(f os.DirEntry) bool {
fi, err := f.Info()
if err != nil {
return false
}
return hostutils.IsGuestDir(fi, m.ServersPath)
}
func (m *SGuestManager) IsGuestExist(sid string) bool {
@@ -583,7 +589,7 @@ func (m *SGuestManager) IsGuestExist(sid string) bool {
}
func (m *SGuestManager) LoadExistingGuests() {
files, err := ioutil.ReadDir(m.ServersPath)
files, err := os.ReadDir(m.ServersPath)
if err != nil {
log.Errorf("List servers path %s error %s", m.ServersPath, err)
}
@@ -601,7 +607,7 @@ func (m *SGuestManager) GetServerDescFilePath(sid string) string {
func (m *SGuestManager) GetServerDesc(sid string) (*desc.SGuestDesc, error) {
descPath := m.GetServerDescFilePath(sid)
descStr, err := ioutil.ReadFile(descPath)
descStr, err := os.ReadFile(descPath)
if err != nil {
return nil, errors.Wrapf(err, "read file %s", descPath)
}
@@ -702,6 +708,19 @@ func (m *SGuestManager) GetGuestNicDesc(
return guestDesc, nic
}
func (m *SGuestManager) GetAllGuestIPv6Macs(bridge string) []string {
macs := []string{}
m.Servers.Range(func(k, v interface{}) bool {
guest := v.(GuestRuntimeInstance)
if guest.IsLoaded() {
nicMacs := guest.GetIpv6NicMacs(bridge)
macs = append(macs, nicMacs...)
}
return true
})
return macs
}
func (m *SGuestManager) getGuestNicDescInCandidate(
mac, ip, port, bridge string,
) (*desc.SGuestDesc, *desc.SGuestNetwork) {

View File

@@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math"
"net"
"os"
"path"
"regexp"
@@ -634,10 +635,15 @@ func (n *SGuestNetworkSyncTask) Start(callback func(...error)) {
addNicConfs := make([]*monitor.NetworkModify, 0)
for i := range n.addNics {
addNicMacs = append(addNicMacs, n.addNics[i].Mac)
addNicConfs = append(addNicConfs, &monitor.NetworkModify{
Ipmask: fmt.Sprintf("%s/%d", n.addNics[i].Ip, n.addNics[i].Masklen),
Gateway: n.addNics[i].Gateway,
})
netMod := &monitor.NetworkModify{}
if len(n.addNics[i].Ip) > 0 {
netMod.Ipmask = fmt.Sprintf("%s/%d", n.addNics[i].Ip, n.addNics[i].Masklen)
netMod.Gateway = n.addNics[i].Gateway
}
if len(n.addNics[i].Ip6) > 0 {
netMod.Ip6mask = fmt.Sprintf("%s/%d", n.addNics[i].Ip6, n.addNics[i].Masklen6)
}
addNicConfs = append(addNicConfs, netMod)
}
n.addNicMacs = addNicMacs
n.addNicConfs = addNicConfs
@@ -1257,7 +1263,7 @@ func (s *SGuestLiveMigrateTask) waitMirrorJobsReady() {
s.waitMirrorJobsReady()
return
}
s.Monitor.Migrate(fmt.Sprintf("tcp:%s:%d", s.params.DestIp, s.params.DestPort),
s.Monitor.Migrate(fmt.Sprintf("tcp:%s", net.JoinHostPort(s.params.DestIp, strconv.Itoa(s.params.DestPort))),
false, false, s.setMaxBandwidth)
}
s.Monitor.GetBlockJobs(cb)
@@ -1308,7 +1314,7 @@ func (s *SGuestLiveMigrateTask) doMigrate() {
// copy disk data
copyIncremental = true
}
s.Monitor.Migrate(fmt.Sprintf("tcp:%s:%d", s.params.DestIp, s.params.DestPort),
s.Monitor.Migrate(fmt.Sprintf("tcp:%s", net.JoinHostPort(s.params.DestIp, strconv.Itoa(s.params.DestPort))),
copyIncremental, false, s.setMaxBandwidth)
}
}

View File

@@ -641,10 +641,10 @@ func getMigrateOptions(drvOpt QemuOptions, input *GenerateStartOptionsInput) []s
if input.LiveMigrateUseTLS {
opts = append(opts, "-incoming defer")
} else {
opts = append(opts, fmt.Sprintf("-incoming tcp:0:%d", input.LiveMigratePort))
opts = append(opts, fmt.Sprintf("-incoming tcp:[::]:%d", input.LiveMigratePort))
}
} else if input.GuestDesc.IsSlave {
opts = append(opts, fmt.Sprintf("-incoming tcp:0:%d", input.LiveMigratePort))
opts = append(opts, fmt.Sprintf("-incoming tcp:[::]:%d", input.LiveMigratePort))
}
return opts
}

View File

@@ -56,6 +56,7 @@ type GuestRuntimeInstance interface {
IsSuspend() bool
IsLoaded() bool
GetNicDescMatch(mac, ip, port, bridge string) *desc.SGuestNetwork
GetIpv6NicMacs(bridge string) []string
CleanGuest(ctx context.Context, params interface{}) (jsonutils.JSONObject, error)
CleanDirtyGuest(ctx context.Context) error
ImportServer(pendingDelete bool)
@@ -172,6 +173,16 @@ func (s *sBaseGuestInstance) GetNicDescMatch(mac, ip, port, bridge string) *desc
return nil
}
func (s *sBaseGuestInstance) GetIpv6NicMacs(bridge string) []string {
macs := []string{}
for _, nic := range s.Desc.Nics {
if nic.Bridge == bridge && len(nic.Ip6) > 0 {
macs = append(macs, nic.Mac)
}
}
return macs
}
func LoadGuestCpuset(m *SGuestManager, s GuestRuntimeInstance) error {
guestDesc := s.GetDesc()
if s.IsRunning() {

View File

@@ -29,6 +29,7 @@ var HealthCheckReactor IHealthCheckReactor
type IGuestDescGetter interface {
GetGuestNicDesc(mac, ip, port, bridge string, isCandidate bool) (*desc.SGuestDesc, *desc.SGuestNetwork)
GetAllGuestIPv6Macs(bridge string) []string
}
var GuestDescGetter IGuestDescGetter

View File

@@ -103,6 +103,5 @@ func hostRestart(ctx context.Context, hostId string, body jsonutils.JSONObject)
}
func hostProbeIsolatedDevices(ctx context.Context, hostId string, body jsonutils.JSONObject) (interface{}, error) {
_, err := hostinfo.Instance().ProbeSyncIsolatedDevices(hostId, body)
return nil, err
return hostinfo.Instance().ProbeSyncIsolatedDevices(hostId, body)
}

View File

@@ -44,8 +44,8 @@ type SGuestDHCP6Server struct {
ifaceDev *netutils2.SNetInterface
raExitCh chan struct{}
raReqCh chan *sRARequest
raReqQueue []*sRARequest
raReqCh chan net.HardwareAddr
raReqQueue map[string]*sRARequest
gwMacCache *hashcache.Cache
}
@@ -76,8 +76,8 @@ func NewGuestDHCP6Server(iface string, port int, relay *SDHCPRelayUpstream) (*SG
}
guestdhcp.raExitCh = make(chan struct{})
guestdhcp.raReqCh = make(chan *sRARequest, 100)
guestdhcp.raReqQueue = make([]*sRARequest, 0)
guestdhcp.raReqCh = make(chan net.HardwareAddr, 1024)
guestdhcp.raReqQueue = make(map[string]*sRARequest)
guestdhcp.gwMacCache = hashcache.NewCache(1024, 5*time.Minute)
return guestdhcp, nil
@@ -169,3 +169,15 @@ func (s *SGuestDHCP6Server) serveDHCPInternal(pkt dhcp.Packet, cliMac net.Hardwa
}
return nil, nil
}
func (s *SGuestDHCP6Server) InitRAQueue() {
macs := guestman.GuestDescGetter.GetAllGuestIPv6Macs(s.ifaceDev.String())
for _, mac := range macs {
hw, err := net.ParseMAC(mac)
if err != nil {
log.Errorf("ParseMAC %s: %v", mac, err)
continue
}
s.requestRA(hw)
}
}

View File

@@ -29,28 +29,19 @@ import (
)
type sRARequest struct {
solicitation *icmp6.SRouterSolicitation
vmMac net.HardwareAddr
attempts int
succAttempts int
nextAttempt time.Time
}
func (s *SGuestDHCP6Server) requestRA(vmMac net.HardwareAddr) {
s.raReqCh <- vmMac
}
func (s *SGuestDHCP6Server) handleRouterSolicitation(msg *icmp6.SRouterSolicitation) error {
// solicitation request from guest
var conf = s.getConfig(msg.SrcMac)
if conf != nil && conf.ClientIP6 != nil && conf.Gateway6 != nil {
req := &sRARequest{
solicitation: msg,
attempts: 1,
}
succ, err := s.sendRouterAdvertisement(msg)
if err != nil {
return errors.Wrapf(err, "sendRouterAdvertisement")
}
if succ {
req.succAttempts++
}
s.raReqCh <- req
}
s.requestRA(msg.SrcMac)
return nil
}
@@ -100,8 +91,11 @@ func (s *SGuestDHCP6Server) requestGatewayMac(gwIP net.IP, vlanId uint16) {
}
}
func (s *SGuestDHCP6Server) sendRouterAdvertisement(solicitation *icmp6.SRouterSolicitation) (bool, error) {
var conf = s.getConfig(solicitation.SrcMac)
func (s *SGuestDHCP6Server) sendRouterAdvertisement(vmMac net.HardwareAddr) (bool, error) {
var conf = s.getConfig(vmMac)
if conf == nil {
return false, errors.Wrapf(errors.ErrNotFound, "getConfig %s", vmMac.String())
}
if conf != nil && conf.ClientIP6 != nil && conf.Gateway6 != nil {
gwMacObj := s.gwMacCache.AtomicGet(conf.Gateway6.String())
if gwMacObj == nil {
@@ -130,7 +124,7 @@ func (s *SGuestDHCP6Server) sendRouterAdvertisement(solicitation *icmp6.SRouterS
// https://www.rfc-editor.org/rfc/rfc4861.html#page-18
// !!! MUST be the link-local address assigned to the interface from which this message is sent.
SrcIP: gwLinkLocalIP,
DstMac: solicitation.SrcMac,
DstMac: vmMac,
DstIP: net.ParseIP("ff02::1"),
},
CurHopLimit: 64,
@@ -138,7 +132,7 @@ func (s *SGuestDHCP6Server) sendRouterAdvertisement(solicitation *icmp6.SRouterS
IsOther: true,
IsHomeAgent: false,
Preference: pref,
RouterLifetime: 9000,
RouterLifetime: uint16(options.HostOptions.Dhcp6RouterLifetimeSeconds),
ReachableTime: 0,
RetransTimer: 0,
MTU: uint32(conf.MTU),
@@ -148,8 +142,8 @@ func (s *SGuestDHCP6Server) sendRouterAdvertisement(solicitation *icmp6.SRouterS
IsAutoconf: false,
Prefix: ipnet.IP,
PrefixLen: conf.PrefixLen6,
ValidLifetime: 4500,
PreferredLifetime: 2250,
ValidLifetime: uint32(options.HostOptions.Dhcp6RouterLifetimeSeconds / 2),
PreferredLifetime: uint32(options.HostOptions.Dhcp6RouterLifetimeSeconds / 4),
},
},
}
@@ -162,13 +156,13 @@ func (s *SGuestDHCP6Server) sendRouterAdvertisement(solicitation *icmp6.SRouterS
IsAutoconf: false,
Prefix: route.Prefix,
PrefixLen: route.PrefixLen,
ValidLifetime: 4500,
PreferredLifetime: 2250,
ValidLifetime: uint32(options.HostOptions.Dhcp6RouterLifetimeSeconds / 2),
PreferredLifetime: uint32(options.HostOptions.Dhcp6RouterLifetimeSeconds / 4),
})
} else if route.Gateway.String() != conf.Gateway6.String() {
// routes forwarded by router
ra.RouteInfo = append(ra.RouteInfo, icmp6.SRouteInfoOption{
RouteLifetime: 9000,
RouteLifetime: uint32(options.HostOptions.Dhcp6RouterLifetimeSeconds),
Prefix: route.Prefix,
PrefixLen: route.PrefixLen,
Preference: pref,
@@ -182,7 +176,7 @@ func (s *SGuestDHCP6Server) sendRouterAdvertisement(solicitation *icmp6.SRouterS
return false, errors.Wrapf(err, "EncodePacket")
}
err = s.conn.SendRaw(bytes, solicitation.SrcMac)
err = s.conn.SendRaw(bytes, vmMac)
if err != nil {
log.Errorf("Send RouterAdvertisement error: %v", err)
}
@@ -195,6 +189,46 @@ func (s *SGuestDHCP6Server) stopRAServer() {
close(s.raReqCh)
}
func (s *SGuestDHCP6Server) handleRARequest(vmMac net.HardwareAddr) {
vmMacStr := vmMac.String()
raReq, ok := s.raReqQueue[vmMacStr]
if !ok {
raReq = &sRARequest{
vmMac: vmMac,
}
s.raReqQueue[vmMacStr] = raReq
} else {
raReq.nextAttempt = time.Time{}
}
// send RA immediately
raReq.attempts++
succ, err := s.sendRouterAdvertisement(vmMac)
if err != nil {
if errors.Cause(err) == errors.ErrNotFound {
// no such vm, giveup
delete(s.raReqQueue, vmMacStr)
return
}
log.Errorf("sendRouterAdvertisement error: %v", err)
}
if succ {
raReq.succAttempts++
}
if raReq.succAttempts < options.HostOptions.Dhcp6RouterAdvertisementAttempts {
if raReq.attempts > 2*options.HostOptions.Dhcp6RouterAdvertisementAttempts {
// giveup
delete(s.raReqQueue, vmMacStr)
} else {
// retry next round
}
} else {
// schedule RA when prefix router lifetime expires
raReq.attempts = 0
raReq.succAttempts = 0
raReq.nextAttempt = time.Now().Add(time.Second * time.Duration(options.HostOptions.Dhcp6RouterLifetimeSeconds/4))
}
}
func (s *SGuestDHCP6Server) startRAServer() {
// a tiny RA server
stop := false
@@ -204,29 +238,14 @@ func (s *SGuestDHCP6Server) startRAServer() {
stop = true
case raReq := <-s.raReqCh:
// handle RA request
s.raReqQueue = append(s.raReqQueue, raReq)
s.handleRARequest(raReq)
case <-time.After(time.Second * time.Duration(options.HostOptions.Dhcp6RouterAdvertisementIntervalSecs)):
// send RA
// log.Infof("timeout, to announce RA %d requests", len(s.raReqQueue))
if len(s.raReqQueue) > 0 {
raReqQueue := s.raReqQueue
s.raReqQueue = make([]*sRARequest, 0)
for i := range raReqQueue {
raReq := raReqQueue[i]
raReq.attempts++
succ, err := s.sendRouterAdvertisement(raReq.solicitation)
if err != nil {
log.Errorf("sendRouterAdvertisement error: %v", err)
continue
}
if succ {
raReq.succAttempts++
}
if raReq.succAttempts < options.HostOptions.Dhcp6RouterAdvertisementAttempts && raReq.attempts < 2*options.HostOptions.Dhcp6RouterAdvertisementAttempts {
s.raReqCh <- raReq
}
for _, raReq := range s.raReqQueue {
if !raReq.nextAttempt.IsZero() && raReq.nextAttempt.After(time.Now()) {
continue
}
s.handleRARequest(raReq.vmMac)
}
}
}

View File

@@ -1163,6 +1163,9 @@ func (h *SHostInfo) GetMasterNicIpAndMask() (string, int) {
}
func (h *SHostInfo) GetMasterIp() string {
if h.MasterNic == nil {
return ""
}
if h.MasterNic.Addr != "" {
return h.MasterNic.Addr
}
@@ -1568,7 +1571,11 @@ func (h *SHostInfo) fetchHostname() string {
hn = "host"
}
masterIp := h.GetMasterIp()
return hn + "-" + strings.Replace(masterIp, ".", "-", -1)
if len(masterIp) > 0 {
return hn + "-" + strings.Replace(masterIp, ".", "-", -1)
} else {
return hn
}
}
}
@@ -2801,6 +2808,14 @@ func (h *SHostInfo) startBindReservedCpus(processesPrefix []string) {
}
}
func (h *SHostInfo) OnGuestLoadingComplete() {
for _, nic := range h.Nics {
if nic.dhcpServer6 != nil {
nic.dhcpServer6.InitRAQueue()
}
}
}
func NewHostInfo() (*SHostInfo, error) {
var res = new(SHostInfo)
res.sysinfo = &SSysInfo{}

View File

@@ -109,6 +109,8 @@ type IHost interface {
SetIGuestManager(guestman IGuestManager)
GetIGuestManager() IGuestManager
OnGuestLoadingComplete()
}
func GetComputeSession(ctx context.Context) *mcclient.ClientSession {
@@ -310,7 +312,7 @@ func initImageCacheWorkerManager() {
}
func initBackupWorkerManager() {
backupW = workmanager.NewWorkManger("BackupDelayTaskWorkers", TaskFailed, TaskComplete, options.HostOptions.DefaultRequestWorkerCount)
backupW = workmanager.NewWorkManger("BackupDelayTaskWorkers", TaskFailed, TaskComplete, options.HostOptions.BackupTaskWorkerCount)
}
func InitWorkerManagerWithCount(count int) {

View File

@@ -523,6 +523,29 @@ func ParseIPAndSubnet(input string) (string, string, error) {
return ip, subnetMask, nil
}
func ParseIP6AndSubnet(input string) (string, string, error) {
//Converting IP/MASK format to IP and MASK
parts := strings.Split(input, "/")
if len(parts) != 2 {
return "", "", fmt.Errorf("Invalid input format")
}
ip := parts[0]
subnetSizeStr := parts[1]
subnetSize := 0
for _, c := range subnetSizeStr {
if c < '0' || c > '9' {
return "", "", fmt.Errorf("Invalid subnet size")
}
subnetSize = subnetSize*10 + int(c-'0')
}
mask := net.CIDRMask(subnetSize, 32)
subnetMask := net.IP(mask).To16().String()
return ip, subnetMask, nil
}
func (qga *QemuGuestAgent) QgaAddFileExec(filePath string) error {
//Adding execution permissions to file
shellAddAuth := "chmod +x " + filePath
@@ -545,15 +568,35 @@ func (qga *QemuGuestAgent) QgaAddFileExec(filePath string) error {
}
func (qga *QemuGuestAgent) QgaSetWindowsNetwork(qgaNetMod *monitor.NetworkModify) error {
ip, subnetMask, err := ParseIPAndSubnet(qgaNetMod.Ipmask)
if err != nil {
return err
var ip, ip6, mask, mask6 string
var err error
var networkCmd string
if len(qgaNetMod.Ipmask) > 0 {
ip, mask, err = ParseIPAndSubnet(qgaNetMod.Ipmask)
if err != nil {
return err
}
networkCmd += fmt.Sprintf(
"netsh interface ip set address name=\"%s\" source=static addr=%s mask=%s gateway=%s & "+
"netsh interface ip set address name=\"%s\" dhcp",
qgaNetMod.Device, ip, mask, qgaNetMod.Gateway, qgaNetMod.Device,
)
}
if len(qgaNetMod.Ip6mask) > 0 {
ip6, mask6, err = ParseIP6AndSubnet(qgaNetMod.Ip6mask)
if err != nil {
return err
}
if networkCmd != "" {
networkCmd += " & "
}
networkCmd += fmt.Sprintf("netsh interface ipv6 set address interface=\"%s\" address=%s/%s & "+
"netsh interface ipv6 add route ::/0 interface=\"%s\" %s & "+
"netsh interface ipv6 set address interface=\"%s\" source=dhcp",
qgaNetMod.Device, ip6, mask6, qgaNetMod.Device, qgaNetMod.Gateway6, qgaNetMod.Device,
)
}
networkCmd := fmt.Sprintf(
"netsh interface ip set address name=\"%s\" source=static addr=%s mask=%s gateway=%s & "+
"netsh interface ip set address name=\"%s\" dhcp",
qgaNetMod.Device, ip, subnetMask, qgaNetMod.Gateway, qgaNetMod.Device,
)
log.Infof("networkCmd: %s", networkCmd)
arg := []string{"/C", networkCmd}

View File

@@ -82,9 +82,11 @@ type Command struct {
}
type NetworkModify struct {
Device string `json:"device"`
Ipmask string `json:"ipmask"`
Gateway string `json:"gateway"`
Device string `json:"device"`
Ipmask string `json:"ipmask"`
Gateway string `json:"gateway"`
Ip6mask string `json:"ip6mask"`
Gateway6 string `json:"gateway6"`
}
type Version struct {

View File

@@ -50,6 +50,7 @@ type SHostBaseOptions struct {
Dhcp6RouterAdvertisementIntervalSecs int `default:"3" help:"DHCPv6 router advertisement interval in seconds, default 3 seconds"`
Dhcp6RouterAdvertisementAttempts int `default:"3" help:"DHCPv6 router advertisement attempts, default 3 attempts"`
Dhcp6RouterLifetimeSeconds int `default:"9000" help:"DHCPv6 router lifetime in seconds, default 9000 seconds"`
Ext4LargefileSizeGb int `default:"4096" help:"Use largefile options when the ext4 fs greater than this size"`
Ext4HugefileSizeGb int `default:"512" help:"Use huge options when the ext4 fs greater than this size"`
@@ -63,6 +64,8 @@ type SHostBaseOptions struct {
TelegrafKafkaOutputSaslUsername string `json:"telegraf_kafka_output_sasl_username" help:"telegraf kafka output sasl_username"`
TelegrafKafkaOutputSaslPassword string `json:"telegraf_kafka_output_sasl_password" help:"telegraf kafka output sasl_password"`
TelegrafKafkaOutputSaslMechanism string `json:"telegraf_kafka_output_sasl_mechanism" help:"telegraf kafka output sasl_mechanism"`
BackupTaskWorkerCount int `default:"3" help:"backup task worker count"`
}
type SHostOptions struct {
@@ -187,7 +190,8 @@ type SHostOptions struct {
SdnEnableTapMan bool `help:"enable tap service" default:"$SDN_ENABLE_TAP_MAN|true"`
TapBridgeName string `help:"bridge name for tap service" default:"brtap"`
SdnAllowConntrackInvalid bool `help:"allow packets marked by conntrack as INVALID to pass" default:"$SDN_ALLOW_CONNTRACK_INVALID|false"`
SdnAllowConntrackInvalid bool `help:"allow packets marked by conntrack as INVALID to pass" default:"$SDN_ALLOW_CONNTRACK_INVALID|false"`
SdnFetchDataFromComputeService bool `help:"fetch network releated data from compute service" default:"$SDN_FETCH_DATA_FROM_COMPUTE_SERVICE|true"`
ovnutils.SOvnOptions

View File

@@ -390,7 +390,7 @@ func (img *SImage) GetExtraDetailsHeaders(ctx context.Context, userCred mcclient
headers[fmt.Sprintf("%s%s", modules.IMAGE_META, "auto_delete_at")] = timeutils.FullIsoTime(pendingDeletedAt)
}
if strings.HasPrefix(img.Location, api.S3Prefix) {
if options.Options.S3DirectDownload && strings.HasPrefix(img.Location, api.S3Prefix) {
headers[fmt.Sprintf("%s%s", modules.IMAGE_META, "s3_info_url")] = s3.GetEndpoint(options.Options.S3Endpoint, options.Options.S3UseSSL)
headers[fmt.Sprintf("%s%s", modules.IMAGE_META, "s3_info_access_key")] = options.Options.S3AccessKey
headers[fmt.Sprintf("%s%s", modules.IMAGE_META, "s3_info_secret")] = options.Options.S3SecretKey

View File

@@ -57,6 +57,8 @@ type SImageOptions struct {
S3UploadPartSizeMb int64 `help:"s3 upload part size in MB, default to 50MB" default:"50"`
S3UploadParallel int `help:"s3 upload parallel count" default:"4"`
S3DirectDownload bool `help:"enable s3 direct download" default:"true"`
ImageStreamWorkerCount int `help:"Image stream worker count" default:"10"`
}

View File

@@ -42,6 +42,7 @@ func InitDB() error {
CredentialManager,
FernetKeyManager,
PasswordManager,
} {
err := manager.InitializeData()
if err != nil {

View File

@@ -57,6 +57,7 @@ func init() {
),
}
PasswordManager.SetVirtualObject(PasswordManager)
PasswordManager.TableSpec().AddIndex(false, "local_user_id", "created_at_int")
}
/*
@@ -112,6 +113,7 @@ func (manager *SPasswordManager) getFetchByLocaluserIdQuery(localUserId int) *sq
passwords := manager.Query().SubQuery()
q := passwords.Query().Equals("local_user_id", localUserId)
q = q.Desc(passwords.Field("created_at_int"))
q = q.Limit(options.Options.PasswordHistoryCount() + 1)
return q
}
@@ -121,7 +123,7 @@ func (manager *SPasswordManager) FetchByLocaluserIdNewestPassword(localUserId in
return nil, errors.Wrap(err, "new password object")
}
q := manager.getFetchByLocaluserIdQuery(localUserId).Limit(1)
q := manager.getFetchByLocaluserIdQuery(localUserId)
if err := q.First(obj); err != nil {
return nil, errors.Wrap(err, "get newest password object")
}
@@ -300,3 +302,91 @@ func (pwd *SPassword) EventNotify(ctx context.Context, userCred mcclient.TokenCr
AdvanceDays: advanceDays,
})
}
func (manager *SPasswordManager) InitializeData() error {
return nil
}
func (manager *SPasswordManager) cleanPasswords() error {
userIds, err := manager.findUserIdsNeedCleanPassword()
if err != nil {
return errors.Wrap(err, "manager.findUserIdsNeedCleanPassword")
}
for _, userId := range userIds {
err := manager.cleanPassword(userId)
if err != nil {
return errors.Wrap(err, "manager.cleanPassword")
}
}
return nil
}
func (manager *SPasswordManager) findUserIdsNeedCleanPassword() ([]int, error) {
q := manager.Query()
q = q.AppendField(q.Field("local_user_id"))
q = q.AppendField(sqlchemy.COUNT("count"))
q = q.GroupBy(q.Field("local_user_id"))
rows, err := q.Rows()
if err != nil {
return nil, errors.Wrap(err, "rows")
}
defer rows.Close()
userIds := []int{}
for rows.Next() {
var localUserId int
var count int
err := rows.Scan(&localUserId, &count)
if err != nil {
return userIds, errors.Wrap(err, "rows.Scan")
}
if count > options.Options.PasswordHistoryCount()+1 {
// need to clean passwords of this user
userIds = append(userIds, localUserId)
}
}
return userIds, nil
}
func (manager *SPasswordManager) findMinPasswordId(localUserId int) (int, error) {
subQ := manager.Query().Equals("local_user_id", localUserId).Desc("created_at_int").Limit(options.Options.PasswordHistoryCount() + 1).SubQuery()
q := subQ.Query().AppendField(sqlchemy.MIN("min_id", subQ.Field("id"))).GroupBy(subQ.Field("id"))
rows, err := q.Rows()
if err != nil {
return -1, errors.Wrap(err, "rows")
}
defer rows.Close()
minId := -1
for rows.Next() {
var id int
err := rows.Scan(&id)
if err != nil {
return -1, errors.Wrap(err, "rows.Scan")
}
minId = id
break
}
return minId, nil
}
func (manager *SPasswordManager) cleanPassword(localUserId int) error {
minId, err := manager.findMinPasswordId(localUserId)
if err != nil {
return errors.Wrap(err, "manager.findMinPasswordId")
}
_, err = manager.TableSpec().GetTableSpec().Database().Exec(fmt.Sprintf("DELETE FROM %s WHERE local_user_id = ? AND id < ?", manager.TableSpec().Name()), localUserId, minId)
if err != nil {
return errors.Wrap(err, "batch delete passwords")
}
return err
}
func (manager *SPasswordManager) CleanPasswordsJob(ctx context.Context, userCred mcclient.TokenCredential, startRun bool) {
err := manager.cleanPasswords()
if err != nil {
log.Errorln(errors.Wrap(err, "manager.cleanPasswords"))
}
}

View File

@@ -40,7 +40,7 @@ type SKeystoneOptions struct {
PasswordExpirationSeconds int `help:"password expires after the duration in seconds"`
PasswordMinimalLength int `help:"password minimal length" default:"6"`
PasswordUniqueHistoryCheck int `help:"password must be unique in last N passwords" default:"1"`
PasswordUniqueHistoryCheck int `help:"password must be unique in last N passwords, default is 0 means no check" default:"0"`
PasswordCharComplexity int `help:"password complexity policy" default:"0"`
PasswordErrorLockCount int `help:"lock user account if given number of failed auth"`
@@ -87,6 +87,13 @@ var (
Options SKeystoneOptions
)
func (o SKeystoneOptions) PasswordHistoryCount() int {
if o.PasswordUniqueHistoryCheck > 0 {
return o.PasswordUniqueHistoryCheck
}
return 10
}
func OnOptionsChange(oldOptions, newOptions interface{}) bool {
oldOpts := oldOptions.(*SKeystoneOptions)
newOpts := newOptions.(*SKeystoneOptions)

View File

@@ -122,6 +122,8 @@ func StartService() {
cron.AddJobAtIntervalsWithStartRun("TaskCleanupJob", time.Duration(options.Options.TaskArchiveIntervalMinutes)*time.Minute, taskman.TaskManager.TaskCleanupJob, true)
cron.AddJobEveryFewHour("CleanPasswordsJob", 4, 8, 0, models.PasswordManager.CleanPasswordsJob, true)
cron.Start()
defer cron.Stop()
}

View File

@@ -18,7 +18,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"regexp"
@@ -34,6 +33,7 @@ import (
"yunion.io/x/pkg/utils"
api "yunion.io/x/onecloud/pkg/apis/identity"
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
)
const (
@@ -101,16 +101,16 @@ func SplitVersionedURL(url string) (string, string) {
return base
}*/
func (this *ClientSession) GetEndpointType() string {
return this.endpointType
func (cliss *ClientSession) GetEndpointType() string {
return cliss.endpointType
}
func (this *ClientSession) GetClient() *Client {
return this.client
func (cliss *ClientSession) GetClient() *Client {
return cliss.client
}
func (this *ClientSession) SetZone(zone string) {
this.zone = zone
func (cliss *ClientSession) SetZone(zone string) {
cliss.zone = zone
}
func getApiVersionByServiceType(serviceType string) string {
@@ -121,7 +121,7 @@ func getApiVersionByServiceType(serviceType string) string {
return ""
}
func (this *ClientSession) GetServiceName(service string) string {
func (cliss *ClientSession) GetServiceName(service string) string {
apiVersion := getApiVersionByServiceType(service)
if len(apiVersion) > 0 && apiVersion != DEFAULT_API_VERSION {
service = fmt.Sprintf("%s_%s", service, apiVersion)
@@ -129,54 +129,54 @@ func (this *ClientSession) GetServiceName(service string) string {
return service
}
func (this *ClientSession) GetServiceURL(service, endpointType string) (string, error) {
return this.GetServiceVersionURL(service, endpointType)
func (cliss *ClientSession) GetServiceURL(service, endpointType string) (string, error) {
return cliss.GetServiceVersionURL(service, endpointType)
}
func (this *ClientSession) SetServiceCatalog(catalog IServiceCatalog) {
this.catalog = catalog
func (cliss *ClientSession) SetServiceCatalog(catalog IServiceCatalog) {
cliss.catalog = catalog
}
func (this *ClientSession) GetServiceCatalog() IServiceCatalog {
if this.catalog != nil {
return this.catalog
func (cliss *ClientSession) GetServiceCatalog() IServiceCatalog {
if cliss.catalog != nil {
return cliss.catalog
}
return this.client.GetServiceCatalog()
return cliss.client.GetServiceCatalog()
}
func (this *ClientSession) GetServiceVersionURL(service, endpointType string) (string, error) {
urls, err := this.GetServiceVersionURLs(service, endpointType)
func (cliss *ClientSession) GetServiceVersionURL(service, endpointType string) (string, error) {
urls, err := cliss.GetServiceVersionURLs(service, endpointType)
if err != nil {
return "", errors.Wrap(err, "GetServiceVersionURLs")
}
return urls[rand.Intn(len(urls))], nil
}
func (this *ClientSession) GetServiceURLs(service, endpointType string) ([]string, error) {
return this.GetServiceVersionURLs(service, endpointType)
func (cliss *ClientSession) GetServiceURLs(service, endpointType string) ([]string, error) {
return cliss.GetServiceVersionURLs(service, endpointType)
}
func (this *ClientSession) GetServiceVersionURLs(service, endpointType string) ([]string, error) {
if len(this.endpointType) > 0 {
func (cliss *ClientSession) GetServiceVersionURLs(service, endpointType string) ([]string, error) {
if len(cliss.endpointType) > 0 {
// session specific endpoint type should override the input endpointType, which is supplied by manager
endpointType = this.endpointType
endpointType = cliss.endpointType
}
service = this.GetServiceName(service)
service = cliss.GetServiceName(service)
if endpointType == api.EndpointInterfaceApigateway {
return this.getApigatewayServiceURLs(service, this.region, this.zone, endpointType)
return cliss.getApigatewayServiceURLs(service, cliss.region, cliss.zone, endpointType)
} else {
return this.getServiceVersionURLs(service, this.region, this.zone, endpointType)
return cliss.getServiceVersionURLs(service, cliss.region, cliss.zone, endpointType)
}
}
func (this *ClientSession) getApigatewayServiceURLs(service, region, zone, endpointType string) ([]string, error) {
urls, err := this.getServiceVersionURLs(service, region, zone, "")
func (cliss *ClientSession) getApigatewayServiceURLs(service, region, zone, endpointType string) ([]string, error) {
urls, err := cliss.getServiceVersionURLs(service, region, zone, "")
if err != nil {
return nil, errors.Wrap(err, "getServiceVersionURLs")
}
// replace URLs with authUrl prefix
// find the common prefix
prefix := this.client.authUrl
prefix := cliss.client.authUrl
lastSlashPos := strings.LastIndex(prefix, "/api/s/identity")
if lastSlashPos <= 0 {
return nil, errors.Wrapf(errors.ErrInvalidFormat, "invalue auth_url %s, should be url of apigateway endpoint, e.g. https://<apigateway-host>/api/s/identity/v3", prefix)
@@ -206,24 +206,24 @@ func (this *ClientSession) getApigatewayServiceURLs(service, region, zone, endpo
return rets, nil
}
func (this *ClientSession) getServiceVersionURLs(service, region, zone, endpointType string) ([]string, error) {
catalog := this.GetServiceCatalog()
func (cliss *ClientSession) getServiceVersionURLs(service, region, zone, endpointType string) ([]string, error) {
catalog := cliss.GetServiceCatalog()
if gotypes.IsNil(catalog) {
return []string{this.client.authUrl}, nil
return []string{cliss.client.authUrl}, nil
}
urls, err := catalog.getServiceURLs(service, region, zone, endpointType)
// HACK! in case of fail to get keystone url or schema of keystone changed, always trust authUrl
if service == api.SERVICE_TYPE && (err != nil || len(urls) == 0 || (len(this.client.authUrl) != 0 && this.client.authUrl[:5] != urls[0][:5])) {
if service == api.SERVICE_TYPE && (err != nil || len(urls) == 0 || (len(cliss.client.authUrl) != 0 && cliss.client.authUrl[:5] != urls[0][:5])) {
var msg string
if err != nil {
msg = fmt.Sprintf("fail to retrieve keystone urls: %s", err)
} else if len(urls) == 0 {
msg = "empty keystone url"
} else {
msg = fmt.Sprintf("Schema of keystone authUrl and endpoint mismatch: %s!=%s", this.client.authUrl, urls)
msg = fmt.Sprintf("Schema of keystone authUrl and endpoint mismatch: %s!=%s", cliss.client.authUrl, urls)
}
log.Warningln(msg)
return []string{this.client.authUrl}, nil
return []string{cliss.client.authUrl}, nil
}
if err != nil {
return nil, errors.Wrap(err, "catalog.GetServiceURLs")
@@ -231,27 +231,27 @@ func (this *ClientSession) getServiceVersionURLs(service, region, zone, endpoint
return urls, err
}
func (this *ClientSession) GetBaseUrl(service, endpointType string) (string, error) {
func (cliss *ClientSession) GetBaseUrl(service, endpointType string) (string, error) {
if len(service) > 0 {
if strings.HasPrefix(service, "http://") || strings.HasPrefix(service, "https://") {
return service, nil
} else if url, ok := this.customizeServiceUrl[service]; ok {
} else if url, ok := cliss.customizeServiceUrl[service]; ok {
return url, nil
} else {
return this.GetServiceVersionURL(service, endpointType)
return cliss.GetServiceVersionURL(service, endpointType)
}
} else {
return "", fmt.Errorf("Empty service type or baseURL")
}
}
func (this *ClientSession) RawBaseUrlRequest(
func (cliss *ClientSession) RawBaseUrlRequest(
service, endpointType string,
method httputils.THttpMethod, url string,
headers http.Header, body io.Reader,
baseurlFactory func(string) string,
) (*http.Response, error) {
baseurl, err := this.GetBaseUrl(service, endpointType)
baseurl, err := cliss.GetBaseUrl(service, endpointType)
if err != nil {
return nil, err
}
@@ -262,33 +262,33 @@ func (this *ClientSession) RawBaseUrlRequest(
if headers != nil {
populateHeader(&tmpHeader, headers)
}
populateHeader(&tmpHeader, this.Header)
appctx.SetHTTPLangHeader(this.ctx, tmpHeader)
ctx := this.ctx
if this.ctx == nil {
populateHeader(&tmpHeader, cliss.Header)
appctx.SetHTTPLangHeader(cliss.ctx, tmpHeader)
ctx := cliss.ctx
if cliss.ctx == nil {
ctx = context.Background()
}
return this.client.rawRequest(ctx, baseurl,
this.token.GetTokenString(),
return cliss.client.rawRequest(ctx, baseurl,
cliss.token.GetTokenString(),
method, url, tmpHeader, body)
}
func (this *ClientSession) RawVersionRequest(
func (cliss *ClientSession) RawVersionRequest(
service, endpointType string, method httputils.THttpMethod, url string,
headers http.Header, body io.Reader,
) (*http.Response, error) {
return this.RawBaseUrlRequest(service, endpointType, method, url, headers, body, nil)
return cliss.RawBaseUrlRequest(service, endpointType, method, url, headers, body, nil)
}
func (this *ClientSession) RawRequest(service, endpointType string, method httputils.THttpMethod, url string, headers http.Header, body io.Reader) (*http.Response, error) {
return this.RawVersionRequest(service, endpointType, method, url, headers, body)
func (cliss *ClientSession) RawRequest(service, endpointType string, method httputils.THttpMethod, url string, headers http.Header, body io.Reader) (*http.Response, error) {
return cliss.RawVersionRequest(service, endpointType, method, url, headers, body)
}
func (this *ClientSession) JSONVersionRequest(
func (cliss *ClientSession) JSONVersionRequest(
service, endpointType string, method httputils.THttpMethod, url string,
headers http.Header, body jsonutils.JSONObject,
) (http.Header, jsonutils.JSONObject, error) {
baseUrl, err := this.GetBaseUrl(service, endpointType)
baseUrl, err := cliss.GetBaseUrl(service, endpointType)
if err != nil {
return headers, nil, err
}
@@ -296,84 +296,108 @@ func (this *ClientSession) JSONVersionRequest(
if headers != nil {
populateHeader(&tmpHeader, headers)
}
populateHeader(&tmpHeader, this.Header)
appctx.SetHTTPLangHeader(this.ctx, tmpHeader)
ctx := this.ctx
if this.ctx == nil {
populateHeader(&tmpHeader, cliss.Header)
appctx.SetHTTPLangHeader(cliss.ctx, tmpHeader)
ctx := cliss.ctx
if cliss.ctx == nil {
ctx = context.Background()
}
return this.client.jsonRequest(ctx, baseUrl,
this.token.GetTokenString(),
return cliss.client.jsonRequest(ctx, baseUrl,
cliss.token.GetTokenString(),
method, url, tmpHeader, body)
}
func (this *ClientSession) JSONRequest(service, endpointType string, method httputils.THttpMethod, url string, headers http.Header, body jsonutils.JSONObject) (http.Header, jsonutils.JSONObject, error) {
return this.JSONVersionRequest(service, endpointType, method, url, headers, body)
func (cliss *ClientSession) JSONRequest(service, endpointType string, method httputils.THttpMethod, url string, headers http.Header, body jsonutils.JSONObject) (http.Header, jsonutils.JSONObject, error) {
return cliss.JSONVersionRequest(service, endpointType, method, url, headers, body)
}
func (this *ClientSession) ParseJSONResponse(reqBody string, resp *http.Response, err error) (http.Header, jsonutils.JSONObject, error) {
return httputils.ParseJSONResponse(reqBody, resp, err, this.client.debug)
func (cliss *ClientSession) ParseJSONResponse(reqBody string, resp *http.Response, err error) (http.Header, jsonutils.JSONObject, error) {
return httputils.ParseJSONResponse(reqBody, resp, err, cliss.client.debug)
}
func (this *ClientSession) HasSystemAdminPrivilege() bool {
return this.token.HasSystemAdminPrivilege()
func (cliss *ClientSession) HasSystemAdminPrivilege() bool {
return cliss.token.HasSystemAdminPrivilege()
}
func (this *ClientSession) GetRegion() string {
return this.region
func (cliss *ClientSession) GetRegion() string {
return cliss.region
}
func (this *ClientSession) GetUserId() string {
return this.token.GetUserId()
func (cliss *ClientSession) GetUserId() string {
return cliss.token.GetUserId()
}
func (this *ClientSession) GetTenantId() string {
return this.token.GetTenantId()
func (cliss *ClientSession) GetTenantId() string {
return cliss.token.GetTenantId()
}
func (this *ClientSession) GetTenantName() string {
return this.token.GetTenantName()
func (cliss *ClientSession) GetTenantName() string {
return cliss.token.GetTenantName()
}
func (this *ClientSession) GetProjectId() string {
return this.GetTenantId()
func (cliss *ClientSession) GetProjectId() string {
return cliss.GetTenantId()
}
func (this *ClientSession) GetProjectName() string {
return this.GetTenantName()
func (cliss *ClientSession) GetProjectName() string {
return cliss.GetTenantName()
}
func (this *ClientSession) GetProjectDomain() string {
return this.token.GetProjectDomain()
func (cliss *ClientSession) GetProjectDomain() string {
return cliss.token.GetProjectDomain()
}
func (this *ClientSession) GetProjectDomainId() string {
return this.token.GetProjectDomainId()
func (cliss *ClientSession) GetProjectDomainId() string {
return cliss.token.GetProjectDomainId()
}
func (this *ClientSession) GetDomainId() string {
return this.token.GetDomainId()
func (cliss *ClientSession) GetDomainId() string {
return cliss.token.GetDomainId()
}
func (this *ClientSession) GetDomainName() string {
return this.token.GetDomainName()
func (cliss *ClientSession) GetDomainName() string {
return cliss.token.GetDomainName()
}
func (this *ClientSession) SetTaskNotifyUrl(url string) {
this.Header.Add(TASK_NOTIFY_URL, url)
func (cliss *ClientSession) SetTaskNotifyUrl(url string) {
cliss.Header.Add(TASK_NOTIFY_URL, url)
}
func (this *ClientSession) RemoveTaskNotifyUrl() {
this.Header.Del(TASK_NOTIFY_URL)
func (cliss *ClientSession) RemoveTaskNotifyUrl() {
cliss.Header.Del(TASK_NOTIFY_URL)
}
func (this *ClientSession) SetServiceUrl(service, url string) {
this.customizeServiceUrl[service] = url
func (cliss *ClientSession) SetServiceUrl(service, url string) {
cliss.customizeServiceUrl[service] = url
}
func (this *ClientSession) PrepareTask() {
func (cliss *ClientSession) WithTaskCallback(taskId string, req func() error) error {
baseUrl, err := cliss.GetBaseUrl(consts.GetServiceType(), api.EndpointInterfacePublic)
if err != nil {
log.Errorf("GetServiceURLs error: %s", err)
return errors.Wrap(err, "GetServiceURLs")
}
if len(baseUrl) == 0 {
return errors.Wrap(errors.ErrInvalidFormat, "empty service url")
}
taskUrl := joinUrl(baseUrl, fmt.Sprintf("/tasks/%s", taskId))
log.Infof("SetTaskNotifyUrl: %s service: %s", taskUrl, consts.GetServiceType())
cliss.SetTaskNotifyUrl(taskUrl)
defer cliss.RemoveTaskNotifyUrl()
{
err := req()
if err != nil {
return errors.Wrap(err, "Request")
}
}
return nil
}
func (cliss *ClientSession) PrepareTask() {
// start a random htttp server
this.notifyChannel = make(chan string)
cliss.notifyChannel = make(chan string)
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
@@ -381,18 +405,18 @@ func (this *ClientSession) PrepareTask() {
ip := utils.GetOutboundIP()
addr := fmt.Sprintf("%s:%d", ip.String(), port)
url := fmt.Sprintf("http://%s", addr)
this.SetTaskNotifyUrl(url)
cliss.SetTaskNotifyUrl(url)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "ok")
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
var msg string
if err != nil {
msg = fmt.Sprintf("Read request data error: %s", err)
} else {
msg = string(body)
}
this.notifyChannel <- msg
cliss.notifyChannel <- msg
})
go func() {
@@ -403,42 +427,42 @@ func (this *ClientSession) PrepareTask() {
}()
}
func (this *ClientSession) WaitTaskNotify() {
if this.notifyChannel != nil {
msg := <-this.notifyChannel
func (cliss *ClientSession) WaitTaskNotify() {
if cliss.notifyChannel != nil {
msg := <-cliss.notifyChannel
fmt.Println("---------------Task complete -------------")
fmt.Println(msg)
}
}
/*func (this *ClientSession) SetApiVersion(version string) {
this.defaultApiVersion = version
/*func (cliss *ClientSession) SetApiVersion(version string) {
cliss.defaultApiVersion = version
}
func (this *ClientSession) GetApiVersion() string {
apiVersion := this.getApiVersion("")
func (cliss *ClientSession) GetApiVersion() string {
apiVersion := cliss.getApiVersion("")
if len(apiVersion) == 0 {
return DEFAULT_API_VERSION
}
return apiVersion
}*/
func (this *ClientSession) ToJson() jsonutils.JSONObject {
func (cliss *ClientSession) ToJson() jsonutils.JSONObject {
params := jsonutils.NewDict()
simpleToken := SimplifyToken(this.token)
simpleToken := SimplifyToken(cliss.token)
tokenJson := jsonutils.Marshal(simpleToken)
params.Update(tokenJson)
// params.Add(jsonutils.NewString(this.GetApiVersion()), "api_version")
if len(this.endpointType) > 0 {
params.Add(jsonutils.NewString(this.endpointType), "endpoint_type")
// params.Add(jsonutils.NewString(cliss.GetApiVersion()), "api_version")
if len(cliss.endpointType) > 0 {
params.Add(jsonutils.NewString(cliss.endpointType), "endpoint_type")
}
if len(this.region) > 0 {
params.Add(jsonutils.NewString(this.region), "region")
if len(cliss.region) > 0 {
params.Add(jsonutils.NewString(cliss.region), "region")
}
if len(this.zone) > 0 {
params.Add(jsonutils.NewString(this.zone), "zone")
if len(cliss.zone) > 0 {
params.Add(jsonutils.NewString(cliss.zone), "zone")
}
if tokenV3, ok := this.token.(*TokenCredentialV3); ok {
if tokenV3, ok := cliss.token.(*TokenCredentialV3); ok {
params.Add(jsonutils.NewStringArray(tokenV3.Token.Policies.Project), "project_policies")
params.Add(jsonutils.NewStringArray(tokenV3.Token.Policies.Domain), "domain_policies")
params.Add(jsonutils.NewStringArray(tokenV3.Token.Policies.System), "system_policies")
@@ -446,17 +470,17 @@ func (this *ClientSession) ToJson() jsonutils.JSONObject {
return params
}
func (cs *ClientSession) GetToken() TokenCredential {
return cs.token
func (cliss *ClientSession) GetToken() TokenCredential {
return cliss.token
}
func (cs *ClientSession) GetContext() context.Context {
if cs.ctx == nil {
func (cliss *ClientSession) GetContext() context.Context {
if cliss.ctx == nil {
return context.Background()
}
return cs.ctx
return cliss.ctx
}
func (cs *ClientSession) GetCommonEtcdEndpoint() (*api.EndpointDetails, error) {
return cs.GetClient().GetCommonEtcdEndpoint(cs.GetToken(), cs.region, cs.endpointType)
func (cliss *ClientSession) GetCommonEtcdEndpoint() (*api.EndpointDetails, error) {
return cliss.GetClient().GetCommonEtcdEndpoint(cliss.GetToken(), cliss.region, cliss.endpointType)
}

View File

@@ -313,11 +313,15 @@ func optionsToBytes(opts []Option6) []byte {
}
func (p Packet) GetOption6s() []Option6 {
options := make([]Option6, 0)
offset := 4
if p.IsRelayMsg() {
offset = 16*2 + 2
}
return decodeDHCP6Options(p, offset)
}
func decodeDHCP6Options(p []byte, offset int) []Option6 {
options := make([]Option6, 0)
i := offset
for i < len(p) {
code := binary.BigEndian.Uint16(p[i : i+2])
@@ -378,28 +382,137 @@ func makeIAAddr(ip net.IP, preferLT, validLT uint32, opts []Option6) []byte {
return buf
}
func responseIANA(buf []byte, opts []Option6) []byte {
func decodeIAAddr(buf []byte) (net.IP, uint32, uint32, []Option6) {
ipBuf := make([]byte, 16)
copy(ipBuf, buf[0:16])
ip := net.IP(ipBuf)
preferLT := binary.BigEndian.Uint32(buf[16:20])
validLT := binary.BigEndian.Uint32(buf[20:24])
opts := decodeDHCP6Options(buf, 24)
return ip, preferLT, validLT, opts
}
/*
+---------------+------+--------------------------------------------+
| Name | Code | Description |
+---------------+------+--------------------------------------------+
| Success | 0 | Success. |
| | | |
| UnspecFail | 1 | Failure, reason unspecified; this status |
| | | code is sent by either a client or a |
| | | server to indicate a failure not |
| | | explicitly specified in this document. |
| | | |
| NoAddrsAvail | 2 | The server has no addresses available to |
| | | assign to the IA(s). |
| | | |
| NoBinding | 3 | Client record (binding) unavailable. |
| | | |
| NotOnLink | 4 | The prefix for the address is not |
| | | appropriate for the link to which the |
| | | client is attached. |
| | | |
| UseMulticast | 5 | Sent by a server to a client to force the |
| | | client to send messages to the server |
| | | using the |
| | | All_DHCP_Relay_Agents_and_Servers |
| | | multicast address. |
| | | |
| NoPrefixAvail | 6 | The server has no prefixes available to |
| | | assign to the IA_PD(s). |
+---------------+------+--------------------------------------------+
*/
type DHCP6StatusCode uint16
const (
Dhcp6StatusSuccess DHCP6StatusCode = 0
Dhcp6StatusUnspecFail DHCP6StatusCode = 1
Dhcp6StatusNoAddrsAvail DHCP6StatusCode = 2
Dhcp6StatusNoBinding DHCP6StatusCode = 3
Dhcp6StatusNotOnLink DHCP6StatusCode = 4
Dhcp6StatusUseMulticast DHCP6StatusCode = 5
Dhcp6StatusNoPrefixAvail DHCP6StatusCode = 6
)
func (code DHCP6StatusCode) Encode() []byte {
var msg string
switch code {
case Dhcp6StatusSuccess:
msg = "Success"
case Dhcp6StatusUnspecFail:
msg = "UnspecFail"
case Dhcp6StatusNoAddrsAvail:
msg = "NoAddrsAvail"
case Dhcp6StatusNoBinding:
msg = "NoBinding"
case Dhcp6StatusNotOnLink:
msg = "NotOnLink"
case Dhcp6StatusUseMulticast:
msg = "UseMulticast"
case Dhcp6StatusNoPrefixAvail:
msg = "NoPrefixAvail"
}
buf := make([]byte, 2)
binary.BigEndian.PutUint16(buf, uint16(code))
buf = append(buf, []byte(msg)...)
return buf
}
func responseIANA(buf []byte, ip net.IP, preferLT, validLT uint32) ([]byte, DHCP6StatusCode) {
// IA_NA structure: IAID (4 bytes) + T1 (4 bytes) + T2 (4 bytes)
// Preserve the original IAID, T1, and T2 values from the client request
opts := make([]Option6, 0)
status := Dhcp6StatusSuccess
resp := make([]byte, 12)
if len(buf) < 12 {
copy(resp, buf)
// If buffer is too short, pad with zeros
padding := make([]byte, 12-len(buf))
buf = append(buf, padding...)
} else if len(buf) > 12 {
// If buffer is too long, truncate to 12 bytes (IAID + T1 + T2)
buf = buf[:12]
}
// Log the IA_NA parameters for debugging
if len(buf) >= 12 {
// padding := make([]byte, 12-len(buf))
// copy(resp[len(buf):], padding)
} else {
// Log the IA_NA parameters for debugging
iaID := binary.BigEndian.Uint32(buf[0:4])
t1 := binary.BigEndian.Uint32(buf[4:8])
t2 := binary.BigEndian.Uint32(buf[8:12])
log.Debugf("responseIANA IA_NA IAID %d t1 %d t2 %d", iaID, t1, t2)
if len(buf) > 12 {
iaOpts := decodeDHCP6Options(buf, 12)
for i := range iaOpts {
if iaOpts[i].Code == DHCPV6_OPTION_IAADDR {
oldIp, oldPreferLT, oldValidLT, _ := decodeIAAddr(iaOpts[i].Value)
if !oldIp.Equal(ip) {
// send NotOnLink
opts = append(opts, Option6{
Code: DHCPV6_OPTION_IAADDR,
Value: makeIAAddr(oldIp, oldPreferLT, oldValidLT, []Option6{
{
Code: DHCPV6_OPTION_STATUS_CODE,
Value: Dhcp6StatusNotOnLink.Encode(),
},
}),
})
if status == Dhcp6StatusSuccess {
status = Dhcp6StatusNotOnLink
}
}
}
}
}
copy(resp, buf[:12])
}
buf = append(buf, optionsToBytes(opts)...)
return buf
opts = append(opts, Option6{
Code: DHCPV6_OPTION_IAADDR,
Value: makeIAAddr(ip, preferLT, validLT, []Option6{
{
Code: DHCPV6_OPTION_STATUS_CODE,
Value: Dhcp6StatusSuccess.Encode(),
},
}),
})
resp = append(resp, optionsToBytes(opts)...)
return resp, status
}
func makeIPv6s(ips []net.IP) []byte {
@@ -473,19 +586,11 @@ func makeDHCPReplyPacket6(pkt Packet, conf *ResponseConfig, msgType MessageType)
validLifetime := uint32(conf.LeaseTime.Seconds()) // Valid lifetime should be longer than preferred
preferredLifetime := validLifetime / 2
ianaResp, status := responseIANA(ianaOpt.Value, conf.ClientIP6, preferredLifetime, validLifetime)
options = append(options, Option6{
Code: DHCPV6_OPTION_IA_NA,
Value: responseIANA(ianaOpt.Value, []Option6{
{
Code: DHCPV6_OPTION_IAADDR,
Value: makeIAAddr(conf.ClientIP6, preferredLifetime, validLifetime, []Option6{
{
Code: DHCPV6_OPTION_STATUS_CODE,
Value: []byte{0, 0, 'S', 'u', 'c', 'c', 'e', 's', 's'},
},
}),
},
}),
Code: DHCPV6_OPTION_IA_NA,
Value: ianaResp,
})
if len(conf.DNSServers6) > 0 {
@@ -514,6 +619,11 @@ func makeDHCPReplyPacket6(pkt Packet, conf *ResponseConfig, msgType MessageType)
}
}
options = append(options, Option6{
Code: DHCPV6_OPTION_STATUS_CODE,
Value: status.Encode(),
})
resp := NewPacket6(msgType, tid)
resp = append(resp, optionsToBytes(options)...)

View File

@@ -415,14 +415,19 @@ func AddNicRoutes(routes4 []SRouteInfo, routes6 []SRouteInfo, nicDesc *types.SSe
return routes4, routes6
}
func GetNicDns(nicdesc *types.SServerNic) []string {
dnslist := []string{}
func GetNicDns(nicdesc *types.SServerNic) ([]string, []string) {
dns4list := []string{}
dns6list := []string{}
if len(nicdesc.Dns) > 0 {
for _, dns := range strings.Split(nicdesc.Dns, ",") {
dnslist = append(dnslist, dns)
if regutils.MatchIP6Addr(dns) {
dns6list = append(dns6list, dns)
} else {
dns4list = append(dns4list, dns)
}
}
}
return dnslist
return dns4list, dns6list
}
func NetBytes2Mask(mask []byte) string {

View File

@@ -17,6 +17,10 @@ package stringutils2
import (
"crypto/sha256"
"fmt"
"strings"
"github.com/google/uuid"
"github.com/zeebo/xxh3"
)
func GenId(ids ...string) string {
@@ -26,3 +30,9 @@ func GenId(ids ...string) string {
}
return fmt.Sprintf("%x", h.Sum(nil))
}
func GenUuid(ids ...string) string {
h := xxh3.HashString128(strings.Join(ids, "")).Bytes()
guid, _ := uuid.FromBytes(h[:])
return guid.String()
}

24
vendor/github.com/klauspost/cpuid/v2/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,24 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof

74
vendor/github.com/klauspost/cpuid/v2/.goreleaser.yml generated vendored Normal file
View File

@@ -0,0 +1,74 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
builds:
-
id: "cpuid"
binary: cpuid
main: ./cmd/cpuid/main.go
env:
- CGO_ENABLED=0
flags:
- -ldflags=-s -w
goos:
- aix
- linux
- freebsd
- netbsd
- windows
- darwin
goarch:
- 386
- amd64
- arm64
goarm:
- 7
archives:
-
id: cpuid
name_template: "cpuid-{{ .Os }}_{{ .Arch }}_{{ .Version }}"
replacements:
aix: AIX
darwin: OSX
linux: Linux
windows: Windows
386: i386
amd64: x86_64
freebsd: FreeBSD
netbsd: NetBSD
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^doc:'
- '^docs:'
- '^test:'
- '^tests:'
- '^Update\sREADME.md'
nfpms:
-
file_name_template: "cpuid_package_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
vendor: Klaus Post
homepage: https://github.com/klauspost/cpuid
maintainer: Klaus Post <klauspost@gmail.com>
description: CPUID Tool
license: BSD 3-Clause
formats:
- deb
- rpm
replacements:
darwin: Darwin
linux: Linux
freebsd: FreeBSD
amd64: x86_64

35
vendor/github.com/klauspost/cpuid/v2/CONTRIBUTING.txt generated vendored Normal file
View File

@@ -0,0 +1,35 @@
Developer Certificate of Origin
Version 1.1
Copyright (C) 2015- Klaus Post & Contributors.
Email: klauspost@gmail.com
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

22
vendor/github.com/klauspost/cpuid/v2/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Klaus Post
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

137
vendor/github.com/klauspost/cpuid/v2/README.md generated vendored Normal file
View File

@@ -0,0 +1,137 @@
# cpuid
Package cpuid provides information about the CPU running the current program.
CPU features are detected on startup, and kept for fast access through the life of the application.
Currently x86 / x64 (AMD64/i386) and ARM (ARM64) is supported, and no external C (cgo) code is used, which should make the library very easy to use.
You can access the CPU information by accessing the shared CPU variable of the cpuid library.
Package home: https://github.com/klauspost/cpuid
[![PkgGoDev](https://pkg.go.dev/badge/github.com/klauspost/cpuid)](https://pkg.go.dev/github.com/klauspost/cpuid/v2)
[![Build Status][3]][4]
[3]: https://travis-ci.org/klauspost/cpuid.svg?branch=master
[4]: https://travis-ci.org/klauspost/cpuid
## installing
`go get -u github.com/klauspost/cpuid/v2` using modules.
Drop `v2` for others.
## example
```Go
package main
import (
"fmt"
"strings"
. "github.com/klauspost/cpuid/v2"
)
func main() {
// Print basic CPU information:
fmt.Println("Name:", CPU.BrandName)
fmt.Println("PhysicalCores:", CPU.PhysicalCores)
fmt.Println("ThreadsPerCore:", CPU.ThreadsPerCore)
fmt.Println("LogicalCores:", CPU.LogicalCores)
fmt.Println("Family", CPU.Family, "Model:", CPU.Model, "Vendor ID:", CPU.VendorID)
fmt.Println("Features:", fmt.Sprintf(strings.Join(CPU.FeatureSet(), ",")))
fmt.Println("Cacheline bytes:", CPU.CacheLine)
fmt.Println("L1 Data Cache:", CPU.Cache.L1D, "bytes")
fmt.Println("L1 Instruction Cache:", CPU.Cache.L1D, "bytes")
fmt.Println("L2 Cache:", CPU.Cache.L2, "bytes")
fmt.Println("L3 Cache:", CPU.Cache.L3, "bytes")
fmt.Println("Frequency", CPU.Hz, "hz")
// Test if we have these specific features:
if CPU.Supports(SSE, SSE2) {
fmt.Println("We have Streaming SIMD 2 Extensions")
}
}
```
Sample output:
```
>go run main.go
Name: AMD Ryzen 9 3950X 16-Core Processor
PhysicalCores: 16
ThreadsPerCore: 2
LogicalCores: 32
Family 23 Model: 113 Vendor ID: AMD
Features: ADX,AESNI,AVX,AVX2,BMI1,BMI2,CLMUL,CMOV,CX16,F16C,FMA3,HTT,HYPERVISOR,LZCNT,MMX,MMXEXT,NX,POPCNT,RDRAND,RDSEED,RDTSCP,SHA,SSE,SSE2,SSE3,SSE4,SSE42,SSE4A,SSSE3
Cacheline bytes: 64
L1 Data Cache: 32768 bytes
L1 Instruction Cache: 32768 bytes
L2 Cache: 524288 bytes
L3 Cache: 16777216 bytes
Frequency 0 hz
We have Streaming SIMD 2 Extensions
```
# usage
The `cpuid.CPU` provides access to CPU features. Use `cpuid.CPU.Supports()` to check for CPU features.
A faster `cpuid.CPU.Has()` is provided which will usually be inlined by the gc compiler.
Note that for some cpu/os combinations some features will not be detected.
`amd64` has rather good support and should work reliably on all platforms.
Note that hypervisors may not pass through all CPU features.
## arm64 feature detection
Not all operating systems provide ARM features directly
and there is no safe way to do so for the rest.
Currently `arm64/linux` and `arm64/freebsd` should be quite reliable.
`arm64/darwin` adds features expected from the M1 processor, but a lot remains undetected.
A `DetectARM()` can be used if you are able to control your deployment,
it will detect CPU features, but may crash if the OS doesn't intercept the calls.
A `-cpu.arm` flag for detecting unsafe ARM features can be added. See below.
Note that currently only features are detected on ARM,
no additional information is currently available.
## flags
It is possible to add flags that affects cpu detection.
For this the `Flags()` command is provided.
This must be called *before* `flag.Parse()` AND after the flags have been parsed `Detect()` must be called.
This means that any detection used in `init()` functions will not contain these flags.
Example:
```Go
package main
import (
"flag"
"fmt"
"strings"
"github.com/klauspost/cpuid/v2"
)
func main() {
cpuid.Flags()
flag.Parse()
cpuid.Detect()
// Test if we have these specific features:
if cpuid.CPU.Supports(cpuid.SSE, cpuid.SSE2) {
fmt.Println("We have Streaming SIMD 2 Extensions")
}
}
```
# license
This code is published under an MIT license. See LICENSE file for more information.

1070
vendor/github.com/klauspost/cpuid/v2/cpuid.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

47
vendor/github.com/klauspost/cpuid/v2/cpuid_386.s generated vendored Normal file
View File

@@ -0,0 +1,47 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build 386,!gccgo,!noasm,!appengine
// func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32)
TEXT ·asmCpuid(SB), 7, $0
XORL CX, CX
MOVL op+0(FP), AX
CPUID
MOVL AX, eax+4(FP)
MOVL BX, ebx+8(FP)
MOVL CX, ecx+12(FP)
MOVL DX, edx+16(FP)
RET
// func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32)
TEXT ·asmCpuidex(SB), 7, $0
MOVL op+0(FP), AX
MOVL op2+4(FP), CX
CPUID
MOVL AX, eax+8(FP)
MOVL BX, ebx+12(FP)
MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP)
RET
// func xgetbv(index uint32) (eax, edx uint32)
TEXT ·asmXgetbv(SB), 7, $0
MOVL index+0(FP), CX
BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV
MOVL AX, eax+4(FP)
MOVL DX, edx+8(FP)
RET
// func asmRdtscpAsm() (eax, ebx, ecx, edx uint32)
TEXT ·asmRdtscpAsm(SB), 7, $0
BYTE $0x0F; BYTE $0x01; BYTE $0xF9 // RDTSCP
MOVL AX, eax+0(FP)
MOVL BX, ebx+4(FP)
MOVL CX, ecx+8(FP)
MOVL DX, edx+12(FP)
RET
// func asmDarwinHasAVX512() bool
TEXT ·asmDarwinHasAVX512(SB), 7, $0
MOVL $0, eax+0(FP)
RET

72
vendor/github.com/klauspost/cpuid/v2/cpuid_amd64.s generated vendored Normal file
View File

@@ -0,0 +1,72 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build amd64,!gccgo,!noasm,!appengine
// func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32)
TEXT ·asmCpuid(SB), 7, $0
XORQ CX, CX
MOVL op+0(FP), AX
CPUID
MOVL AX, eax+8(FP)
MOVL BX, ebx+12(FP)
MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP)
RET
// func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32)
TEXT ·asmCpuidex(SB), 7, $0
MOVL op+0(FP), AX
MOVL op2+4(FP), CX
CPUID
MOVL AX, eax+8(FP)
MOVL BX, ebx+12(FP)
MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP)
RET
// func asmXgetbv(index uint32) (eax, edx uint32)
TEXT ·asmXgetbv(SB), 7, $0
MOVL index+0(FP), CX
BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV
MOVL AX, eax+8(FP)
MOVL DX, edx+12(FP)
RET
// func asmRdtscpAsm() (eax, ebx, ecx, edx uint32)
TEXT ·asmRdtscpAsm(SB), 7, $0
BYTE $0x0F; BYTE $0x01; BYTE $0xF9 // RDTSCP
MOVL AX, eax+0(FP)
MOVL BX, ebx+4(FP)
MOVL CX, ecx+8(FP)
MOVL DX, edx+12(FP)
RET
// From https://go-review.googlesource.com/c/sys/+/285572/
// func asmDarwinHasAVX512() bool
TEXT ·asmDarwinHasAVX512(SB), 7, $0-1
MOVB $0, ret+0(FP) // default to false
#ifdef GOOS_darwin // return if not darwin
#ifdef GOARCH_amd64 // return if not amd64
// These values from:
// https://github.com/apple/darwin-xnu/blob/xnu-4570.1.46/osfmk/i386/cpu_capabilities.h
#define commpage64_base_address 0x00007fffffe00000
#define commpage64_cpu_capabilities64 (commpage64_base_address+0x010)
#define commpage64_version (commpage64_base_address+0x01E)
#define hasAVX512F 0x0000004000000000
MOVQ $commpage64_version, BX
MOVW (BX), AX
CMPW AX, $13 // versions < 13 do not support AVX512
JL no_avx512
MOVQ $commpage64_cpu_capabilities64, BX
MOVQ (BX), AX
MOVQ $hasAVX512F, CX
ANDQ CX, AX
JZ no_avx512
MOVB $1, ret+0(FP)
no_avx512:
#endif
#endif
RET

26
vendor/github.com/klauspost/cpuid/v2/cpuid_arm64.s generated vendored Normal file
View File

@@ -0,0 +1,26 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build arm64,!gccgo,!noasm,!appengine
// See https://www.kernel.org/doc/Documentation/arm64/cpu-feature-registers.txt
// func getMidr
TEXT ·getMidr(SB), 7, $0
WORD $0xd5380000 // mrs x0, midr_el1 /* Main ID Register */
MOVD R0, midr+0(FP)
RET
// func getProcFeatures
TEXT ·getProcFeatures(SB), 7, $0
WORD $0xd5380400 // mrs x0, id_aa64pfr0_el1 /* Processor Feature Register 0 */
MOVD R0, procFeatures+0(FP)
RET
// func getInstAttributes
TEXT ·getInstAttributes(SB), 7, $0
WORD $0xd5380600 // mrs x0, id_aa64isar0_el1 /* Instruction Set Attribute Register 0 */
WORD $0xd5380621 // mrs x1, id_aa64isar1_el1 /* Instruction Set Attribute Register 1 */
MOVD R0, instAttrReg0+0(FP)
MOVD R1, instAttrReg1+8(FP)
RET

246
vendor/github.com/klauspost/cpuid/v2/detect_arm64.go generated vendored Normal file
View File

@@ -0,0 +1,246 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build arm64,!gccgo,!noasm,!appengine
package cpuid
import "runtime"
func getMidr() (midr uint64)
func getProcFeatures() (procFeatures uint64)
func getInstAttributes() (instAttrReg0, instAttrReg1 uint64)
func initCPU() {
cpuid = func(uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
cpuidex = func(x, y uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
xgetbv = func(uint32) (a, b uint32) { return 0, 0 }
rdtscpAsm = func() (a, b, c, d uint32) { return 0, 0, 0, 0 }
}
func addInfo(c *CPUInfo, safe bool) {
// Seems to be safe to assume on ARM64
c.CacheLine = 64
detectOS(c)
// ARM64 disabled since it may crash if interrupt is not intercepted by OS.
if safe && !c.Supports(ARMCPUID) && runtime.GOOS != "freebsd" {
return
}
midr := getMidr()
// MIDR_EL1 - Main ID Register
// https://developer.arm.com/docs/ddi0595/h/aarch64-system-registers/midr_el1
// x--------------------------------------------------x
// | Name | bits | visible |
// |--------------------------------------------------|
// | Implementer | [31-24] | y |
// |--------------------------------------------------|
// | Variant | [23-20] | y |
// |--------------------------------------------------|
// | Architecture | [19-16] | y |
// |--------------------------------------------------|
// | PartNum | [15-4] | y |
// |--------------------------------------------------|
// | Revision | [3-0] | y |
// x--------------------------------------------------x
switch (midr >> 24) & 0xff {
case 0xC0:
c.VendorString = "Ampere Computing"
c.VendorID = Ampere
case 0x41:
c.VendorString = "Arm Limited"
c.VendorID = ARM
case 0x42:
c.VendorString = "Broadcom Corporation"
c.VendorID = Broadcom
case 0x43:
c.VendorString = "Cavium Inc"
c.VendorID = Cavium
case 0x44:
c.VendorString = "Digital Equipment Corporation"
c.VendorID = DEC
case 0x46:
c.VendorString = "Fujitsu Ltd"
c.VendorID = Fujitsu
case 0x49:
c.VendorString = "Infineon Technologies AG"
c.VendorID = Infineon
case 0x4D:
c.VendorString = "Motorola or Freescale Semiconductor Inc"
c.VendorID = Motorola
case 0x4E:
c.VendorString = "NVIDIA Corporation"
c.VendorID = NVIDIA
case 0x50:
c.VendorString = "Applied Micro Circuits Corporation"
c.VendorID = AMCC
case 0x51:
c.VendorString = "Qualcomm Inc"
c.VendorID = Qualcomm
case 0x56:
c.VendorString = "Marvell International Ltd"
c.VendorID = Marvell
case 0x69:
c.VendorString = "Intel Corporation"
c.VendorID = Intel
}
// Lower 4 bits: Architecture
// Architecture Meaning
// 0b0001 Armv4.
// 0b0010 Armv4T.
// 0b0011 Armv5 (obsolete).
// 0b0100 Armv5T.
// 0b0101 Armv5TE.
// 0b0110 Armv5TEJ.
// 0b0111 Armv6.
// 0b1111 Architectural features are individually identified in the ID_* registers, see 'ID registers'.
// Upper 4 bit: Variant
// An IMPLEMENTATION DEFINED variant number.
// Typically, this field is used to distinguish between different product variants, or major revisions of a product.
c.Family = int(midr>>16) & 0xff
// PartNum, bits [15:4]
// An IMPLEMENTATION DEFINED primary part number for the device.
// On processors implemented by Arm, if the top four bits of the primary
// part number are 0x0 or 0x7, the variant and architecture are encoded differently.
// Revision, bits [3:0]
// An IMPLEMENTATION DEFINED revision number for the device.
c.Model = int(midr) & 0xffff
procFeatures := getProcFeatures()
// ID_AA64PFR0_EL1 - Processor Feature Register 0
// x--------------------------------------------------x
// | Name | bits | visible |
// |--------------------------------------------------|
// | DIT | [51-48] | y |
// |--------------------------------------------------|
// | SVE | [35-32] | y |
// |--------------------------------------------------|
// | GIC | [27-24] | n |
// |--------------------------------------------------|
// | AdvSIMD | [23-20] | y |
// |--------------------------------------------------|
// | FP | [19-16] | y |
// |--------------------------------------------------|
// | EL3 | [15-12] | n |
// |--------------------------------------------------|
// | EL2 | [11-8] | n |
// |--------------------------------------------------|
// | EL1 | [7-4] | n |
// |--------------------------------------------------|
// | EL0 | [3-0] | n |
// x--------------------------------------------------x
var f flagSet
// if procFeatures&(0xf<<48) != 0 {
// fmt.Println("DIT")
// }
f.setIf(procFeatures&(0xf<<32) != 0, SVE)
if procFeatures&(0xf<<20) != 15<<20 {
f.set(ASIMD)
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64pfr0_el1
// 0b0001 --> As for 0b0000, and also includes support for half-precision floating-point arithmetic.
f.setIf(procFeatures&(0xf<<20) == 1<<20, FPHP, ASIMDHP)
}
f.setIf(procFeatures&(0xf<<16) != 0, FP)
instAttrReg0, instAttrReg1 := getInstAttributes()
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64isar0_el1
//
// ID_AA64ISAR0_EL1 - Instruction Set Attribute Register 0
// x--------------------------------------------------x
// | Name | bits | visible |
// |--------------------------------------------------|
// | TS | [55-52] | y |
// |--------------------------------------------------|
// | FHM | [51-48] | y |
// |--------------------------------------------------|
// | DP | [47-44] | y |
// |--------------------------------------------------|
// | SM4 | [43-40] | y |
// |--------------------------------------------------|
// | SM3 | [39-36] | y |
// |--------------------------------------------------|
// | SHA3 | [35-32] | y |
// |--------------------------------------------------|
// | RDM | [31-28] | y |
// |--------------------------------------------------|
// | ATOMICS | [23-20] | y |
// |--------------------------------------------------|
// | CRC32 | [19-16] | y |
// |--------------------------------------------------|
// | SHA2 | [15-12] | y |
// |--------------------------------------------------|
// | SHA1 | [11-8] | y |
// |--------------------------------------------------|
// | AES | [7-4] | y |
// x--------------------------------------------------x
// if instAttrReg0&(0xf<<52) != 0 {
// fmt.Println("TS")
// }
// if instAttrReg0&(0xf<<48) != 0 {
// fmt.Println("FHM")
// }
f.setIf(instAttrReg0&(0xf<<44) != 0, ASIMDDP)
f.setIf(instAttrReg0&(0xf<<40) != 0, SM4)
f.setIf(instAttrReg0&(0xf<<36) != 0, SM3)
f.setIf(instAttrReg0&(0xf<<32) != 0, SHA3)
f.setIf(instAttrReg0&(0xf<<28) != 0, ASIMDRDM)
f.setIf(instAttrReg0&(0xf<<20) != 0, ATOMICS)
f.setIf(instAttrReg0&(0xf<<16) != 0, CRC32)
f.setIf(instAttrReg0&(0xf<<12) != 0, SHA2)
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64isar0_el1
// 0b0010 --> As 0b0001, plus SHA512H, SHA512H2, SHA512SU0, and SHA512SU1 instructions implemented.
f.setIf(instAttrReg0&(0xf<<12) == 2<<12, SHA512)
f.setIf(instAttrReg0&(0xf<<8) != 0, SHA1)
f.setIf(instAttrReg0&(0xf<<4) != 0, AESARM)
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64isar0_el1
// 0b0010 --> As for 0b0001, plus PMULL/PMULL2 instructions operating on 64-bit data quantities.
f.setIf(instAttrReg0&(0xf<<4) == 2<<4, PMULL)
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64isar1_el1
//
// ID_AA64ISAR1_EL1 - Instruction set attribute register 1
// x--------------------------------------------------x
// | Name | bits | visible |
// |--------------------------------------------------|
// | GPI | [31-28] | y |
// |--------------------------------------------------|
// | GPA | [27-24] | y |
// |--------------------------------------------------|
// | LRCPC | [23-20] | y |
// |--------------------------------------------------|
// | FCMA | [19-16] | y |
// |--------------------------------------------------|
// | JSCVT | [15-12] | y |
// |--------------------------------------------------|
// | API | [11-8] | y |
// |--------------------------------------------------|
// | APA | [7-4] | y |
// |--------------------------------------------------|
// | DPB | [3-0] | y |
// x--------------------------------------------------x
// if instAttrReg1&(0xf<<28) != 0 {
// fmt.Println("GPI")
// }
f.setIf(instAttrReg1&(0xf<<28) != 24, GPA)
f.setIf(instAttrReg1&(0xf<<20) != 0, LRCPC)
f.setIf(instAttrReg1&(0xf<<16) != 0, FCMA)
f.setIf(instAttrReg1&(0xf<<12) != 0, JSCVT)
// if instAttrReg1&(0xf<<8) != 0 {
// fmt.Println("API")
// }
// if instAttrReg1&(0xf<<4) != 0 {
// fmt.Println("APA")
// }
f.setIf(instAttrReg1&(0xf<<0) != 0, DCPOP)
// Store
c.featureSet.or(f)
}

14
vendor/github.com/klauspost/cpuid/v2/detect_ref.go generated vendored Normal file
View File

@@ -0,0 +1,14 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build !amd64,!386,!arm64 gccgo noasm appengine
package cpuid
func initCPU() {
cpuid = func(uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
cpuidex = func(x, y uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
xgetbv = func(uint32) (a, b uint32) { return 0, 0 }
rdtscpAsm = func() (a, b, c, d uint32) { return 0, 0, 0, 0 }
}
func addInfo(info *CPUInfo, safe bool) {}

35
vendor/github.com/klauspost/cpuid/v2/detect_x86.go generated vendored Normal file
View File

@@ -0,0 +1,35 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build 386,!gccgo,!noasm,!appengine amd64,!gccgo,!noasm,!appengine
package cpuid
func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32)
func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32)
func asmXgetbv(index uint32) (eax, edx uint32)
func asmRdtscpAsm() (eax, ebx, ecx, edx uint32)
func asmDarwinHasAVX512() bool
func initCPU() {
cpuid = asmCpuid
cpuidex = asmCpuidex
xgetbv = asmXgetbv
rdtscpAsm = asmRdtscpAsm
darwinHasAVX512 = asmDarwinHasAVX512
}
func addInfo(c *CPUInfo, safe bool) {
c.maxFunc = maxFunctionID()
c.maxExFunc = maxExtendedFunction()
c.BrandName = brandName()
c.CacheLine = cacheLine()
c.Family, c.Model = familyModel()
c.featureSet = support()
c.SGX = hasSGX(c.featureSet.inSet(SGX), c.featureSet.inSet(SGXLC))
c.ThreadsPerCore = threadsPerCore()
c.LogicalCores = logicalCores()
c.PhysicalCores = physicalCores()
c.VendorID, c.VendorString = vendorID()
c.cacheSize()
c.frequencies()
}

View File

@@ -0,0 +1,185 @@
// Code generated by "stringer -type=FeatureID,Vendor"; DO NOT EDIT.
package cpuid
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[ADX-1]
_ = x[AESNI-2]
_ = x[AMD3DNOW-3]
_ = x[AMD3DNOWEXT-4]
_ = x[AMXBF16-5]
_ = x[AMXINT8-6]
_ = x[AMXTILE-7]
_ = x[AVX-8]
_ = x[AVX2-9]
_ = x[AVX512BF16-10]
_ = x[AVX512BITALG-11]
_ = x[AVX512BW-12]
_ = x[AVX512CD-13]
_ = x[AVX512DQ-14]
_ = x[AVX512ER-15]
_ = x[AVX512F-16]
_ = x[AVX512FP16-17]
_ = x[AVX512IFMA-18]
_ = x[AVX512PF-19]
_ = x[AVX512VBMI-20]
_ = x[AVX512VBMI2-21]
_ = x[AVX512VL-22]
_ = x[AVX512VNNI-23]
_ = x[AVX512VP2INTERSECT-24]
_ = x[AVX512VPOPCNTDQ-25]
_ = x[AVXSLOW-26]
_ = x[BMI1-27]
_ = x[BMI2-28]
_ = x[CLDEMOTE-29]
_ = x[CLMUL-30]
_ = x[CLZERO-31]
_ = x[CMOV-32]
_ = x[CPBOOST-33]
_ = x[CX16-34]
_ = x[ENQCMD-35]
_ = x[ERMS-36]
_ = x[F16C-37]
_ = x[FMA3-38]
_ = x[FMA4-39]
_ = x[GFNI-40]
_ = x[HLE-41]
_ = x[HTT-42]
_ = x[HWA-43]
_ = x[HYPERVISOR-44]
_ = x[IBPB-45]
_ = x[IBS-46]
_ = x[IBSBRNTRGT-47]
_ = x[IBSFETCHSAM-48]
_ = x[IBSFFV-49]
_ = x[IBSOPCNT-50]
_ = x[IBSOPCNTEXT-51]
_ = x[IBSOPSAM-52]
_ = x[IBSRDWROPCNT-53]
_ = x[IBSRIPINVALIDCHK-54]
_ = x[INT_WBINVD-55]
_ = x[INVLPGB-56]
_ = x[LZCNT-57]
_ = x[MCAOVERFLOW-58]
_ = x[MCOMMIT-59]
_ = x[MMX-60]
_ = x[MMXEXT-61]
_ = x[MOVDIR64B-62]
_ = x[MOVDIRI-63]
_ = x[MPX-64]
_ = x[MSRIRC-65]
_ = x[NX-66]
_ = x[POPCNT-67]
_ = x[RDPRU-68]
_ = x[RDRAND-69]
_ = x[RDSEED-70]
_ = x[RDTSCP-71]
_ = x[RTM-72]
_ = x[RTM_ALWAYS_ABORT-73]
_ = x[SERIALIZE-74]
_ = x[SGX-75]
_ = x[SGXLC-76]
_ = x[SHA-77]
_ = x[SSE-78]
_ = x[SSE2-79]
_ = x[SSE3-80]
_ = x[SSE4-81]
_ = x[SSE42-82]
_ = x[SSE4A-83]
_ = x[SSSE3-84]
_ = x[STIBP-85]
_ = x[SUCCOR-86]
_ = x[TBM-87]
_ = x[TSXLDTRK-88]
_ = x[VAES-89]
_ = x[VMX-90]
_ = x[VPCLMULQDQ-91]
_ = x[WAITPKG-92]
_ = x[WBNOINVD-93]
_ = x[XOP-94]
_ = x[AESARM-95]
_ = x[ARMCPUID-96]
_ = x[ASIMD-97]
_ = x[ASIMDDP-98]
_ = x[ASIMDHP-99]
_ = x[ASIMDRDM-100]
_ = x[ATOMICS-101]
_ = x[CRC32-102]
_ = x[DCPOP-103]
_ = x[EVTSTRM-104]
_ = x[FCMA-105]
_ = x[FP-106]
_ = x[FPHP-107]
_ = x[GPA-108]
_ = x[JSCVT-109]
_ = x[LRCPC-110]
_ = x[PMULL-111]
_ = x[SHA1-112]
_ = x[SHA2-113]
_ = x[SHA3-114]
_ = x[SHA512-115]
_ = x[SM3-116]
_ = x[SM4-117]
_ = x[SVE-118]
_ = x[lastID-119]
_ = x[firstID-0]
}
const _FeatureID_name = "firstIDADXAESNIAMD3DNOWAMD3DNOWEXTAMXBF16AMXINT8AMXTILEAVXAVX2AVX512BF16AVX512BITALGAVX512BWAVX512CDAVX512DQAVX512ERAVX512FAVX512FP16AVX512IFMAAVX512PFAVX512VBMIAVX512VBMI2AVX512VLAVX512VNNIAVX512VP2INTERSECTAVX512VPOPCNTDQAVXSLOWBMI1BMI2CLDEMOTECLMULCLZEROCMOVCPBOOSTCX16ENQCMDERMSF16CFMA3FMA4GFNIHLEHTTHWAHYPERVISORIBPBIBSIBSBRNTRGTIBSFETCHSAMIBSFFVIBSOPCNTIBSOPCNTEXTIBSOPSAMIBSRDWROPCNTIBSRIPINVALIDCHKINT_WBINVDINVLPGBLZCNTMCAOVERFLOWMCOMMITMMXMMXEXTMOVDIR64BMOVDIRIMPXMSRIRCNXPOPCNTRDPRURDRANDRDSEEDRDTSCPRTMRTM_ALWAYS_ABORTSERIALIZESGXSGXLCSHASSESSE2SSE3SSE4SSE42SSE4ASSSE3STIBPSUCCORTBMTSXLDTRKVAESVMXVPCLMULQDQWAITPKGWBNOINVDXOPAESARMARMCPUIDASIMDASIMDDPASIMDHPASIMDRDMATOMICSCRC32DCPOPEVTSTRMFCMAFPFPHPGPAJSCVTLRCPCPMULLSHA1SHA2SHA3SHA512SM3SM4SVElastID"
var _FeatureID_index = [...]uint16{0, 7, 10, 15, 23, 34, 41, 48, 55, 58, 62, 72, 84, 92, 100, 108, 116, 123, 133, 143, 151, 161, 172, 180, 190, 208, 223, 230, 234, 238, 246, 251, 257, 261, 268, 272, 278, 282, 286, 290, 294, 298, 301, 304, 307, 317, 321, 324, 334, 345, 351, 359, 370, 378, 390, 406, 416, 423, 428, 439, 446, 449, 455, 464, 471, 474, 480, 482, 488, 493, 499, 505, 511, 514, 530, 539, 542, 547, 550, 553, 557, 561, 565, 570, 575, 580, 585, 591, 594, 602, 606, 609, 619, 626, 634, 637, 643, 651, 656, 663, 670, 678, 685, 690, 695, 702, 706, 708, 712, 715, 720, 725, 730, 734, 738, 742, 748, 751, 754, 757, 763}
func (i FeatureID) String() string {
if i < 0 || i >= FeatureID(len(_FeatureID_index)-1) {
return "FeatureID(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _FeatureID_name[_FeatureID_index[i]:_FeatureID_index[i+1]]
}
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[VendorUnknown-0]
_ = x[Intel-1]
_ = x[AMD-2]
_ = x[VIA-3]
_ = x[Transmeta-4]
_ = x[NSC-5]
_ = x[KVM-6]
_ = x[MSVM-7]
_ = x[VMware-8]
_ = x[XenHVM-9]
_ = x[Bhyve-10]
_ = x[Hygon-11]
_ = x[SiS-12]
_ = x[RDC-13]
_ = x[Ampere-14]
_ = x[ARM-15]
_ = x[Broadcom-16]
_ = x[Cavium-17]
_ = x[DEC-18]
_ = x[Fujitsu-19]
_ = x[Infineon-20]
_ = x[Motorola-21]
_ = x[NVIDIA-22]
_ = x[AMCC-23]
_ = x[Qualcomm-24]
_ = x[Marvell-25]
_ = x[lastVendor-26]
}
const _Vendor_name = "VendorUnknownIntelAMDVIATransmetaNSCKVMMSVMVMwareXenHVMBhyveHygonSiSRDCAmpereARMBroadcomCaviumDECFujitsuInfineonMotorolaNVIDIAAMCCQualcommMarvelllastVendor"
var _Vendor_index = [...]uint8{0, 13, 18, 21, 24, 33, 36, 39, 43, 49, 55, 60, 65, 68, 71, 77, 80, 88, 94, 97, 104, 112, 120, 126, 130, 138, 145, 155}
func (i Vendor) String() string {
if i < 0 || i >= Vendor(len(_Vendor_index)-1) {
return "Vendor(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Vendor_name[_Vendor_index[i]:_Vendor_index[i+1]]
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) 2020 Klaus Post, released under MIT License. See LICENSE file.
package cpuid
import "runtime"
func detectOS(c *CPUInfo) bool {
// There are no hw.optional sysctl values for the below features on Mac OS 11.0
// to detect their supported state dynamically. Assume the CPU features that
// Apple Silicon M1 supports to be available as a minimal set of features
// to all Go programs running on darwin/arm64.
// TODO: Add more if we know them.
c.featureSet.setIf(runtime.GOOS != "ios", AESARM, PMULL, SHA1, SHA2)
c.PhysicalCores = runtime.NumCPU()
// For now assuming 1 thread per core...
c.ThreadsPerCore = 1
c.LogicalCores = c.PhysicalCores
return true
}

130
vendor/github.com/klauspost/cpuid/v2/os_linux_arm64.go generated vendored Normal file
View File

@@ -0,0 +1,130 @@
// Copyright (c) 2020 Klaus Post, released under MIT License. See LICENSE file.
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file located
// here https://github.com/golang/sys/blob/master/LICENSE
package cpuid
import (
"encoding/binary"
"io/ioutil"
"runtime"
)
// HWCAP bits.
const (
hwcap_FP = 1 << 0
hwcap_ASIMD = 1 << 1
hwcap_EVTSTRM = 1 << 2
hwcap_AES = 1 << 3
hwcap_PMULL = 1 << 4
hwcap_SHA1 = 1 << 5
hwcap_SHA2 = 1 << 6
hwcap_CRC32 = 1 << 7
hwcap_ATOMICS = 1 << 8
hwcap_FPHP = 1 << 9
hwcap_ASIMDHP = 1 << 10
hwcap_CPUID = 1 << 11
hwcap_ASIMDRDM = 1 << 12
hwcap_JSCVT = 1 << 13
hwcap_FCMA = 1 << 14
hwcap_LRCPC = 1 << 15
hwcap_DCPOP = 1 << 16
hwcap_SHA3 = 1 << 17
hwcap_SM3 = 1 << 18
hwcap_SM4 = 1 << 19
hwcap_ASIMDDP = 1 << 20
hwcap_SHA512 = 1 << 21
hwcap_SVE = 1 << 22
hwcap_ASIMDFHM = 1 << 23
)
func detectOS(c *CPUInfo) bool {
// For now assuming no hyperthreading is reasonable.
c.LogicalCores = runtime.NumCPU()
c.PhysicalCores = c.LogicalCores
c.ThreadsPerCore = 1
if hwcap == 0 {
// We did not get values from the runtime.
// Try reading /proc/self/auxv
// From https://github.com/golang/sys
const (
_AT_HWCAP = 16
_AT_HWCAP2 = 26
uintSize = int(32 << (^uint(0) >> 63))
)
buf, err := ioutil.ReadFile("/proc/self/auxv")
if err != nil {
// e.g. on android /proc/self/auxv is not accessible, so silently
// ignore the error and leave Initialized = false. On some
// architectures (e.g. arm64) doinit() implements a fallback
// readout and will set Initialized = true again.
return false
}
bo := binary.LittleEndian
for len(buf) >= 2*(uintSize/8) {
var tag, val uint
switch uintSize {
case 32:
tag = uint(bo.Uint32(buf[0:]))
val = uint(bo.Uint32(buf[4:]))
buf = buf[8:]
case 64:
tag = uint(bo.Uint64(buf[0:]))
val = uint(bo.Uint64(buf[8:]))
buf = buf[16:]
}
switch tag {
case _AT_HWCAP:
hwcap = val
case _AT_HWCAP2:
// Not used
}
}
if hwcap == 0 {
return false
}
}
// HWCap was populated by the runtime from the auxiliary vector.
// Use HWCap information since reading aarch64 system registers
// is not supported in user space on older linux kernels.
c.featureSet.setIf(isSet(hwcap, hwcap_AES), AESARM)
c.featureSet.setIf(isSet(hwcap, hwcap_ASIMD), ASIMD)
c.featureSet.setIf(isSet(hwcap, hwcap_ASIMDDP), ASIMDDP)
c.featureSet.setIf(isSet(hwcap, hwcap_ASIMDHP), ASIMDHP)
c.featureSet.setIf(isSet(hwcap, hwcap_ASIMDRDM), ASIMDRDM)
c.featureSet.setIf(isSet(hwcap, hwcap_CPUID), ARMCPUID)
c.featureSet.setIf(isSet(hwcap, hwcap_CRC32), CRC32)
c.featureSet.setIf(isSet(hwcap, hwcap_DCPOP), DCPOP)
c.featureSet.setIf(isSet(hwcap, hwcap_EVTSTRM), EVTSTRM)
c.featureSet.setIf(isSet(hwcap, hwcap_FCMA), FCMA)
c.featureSet.setIf(isSet(hwcap, hwcap_FP), FP)
c.featureSet.setIf(isSet(hwcap, hwcap_FPHP), FPHP)
c.featureSet.setIf(isSet(hwcap, hwcap_JSCVT), JSCVT)
c.featureSet.setIf(isSet(hwcap, hwcap_LRCPC), LRCPC)
c.featureSet.setIf(isSet(hwcap, hwcap_PMULL), PMULL)
c.featureSet.setIf(isSet(hwcap, hwcap_SHA1), SHA1)
c.featureSet.setIf(isSet(hwcap, hwcap_SHA2), SHA2)
c.featureSet.setIf(isSet(hwcap, hwcap_SHA3), SHA3)
c.featureSet.setIf(isSet(hwcap, hwcap_SHA512), SHA512)
c.featureSet.setIf(isSet(hwcap, hwcap_SM3), SM3)
c.featureSet.setIf(isSet(hwcap, hwcap_SM4), SM4)
c.featureSet.setIf(isSet(hwcap, hwcap_SVE), SVE)
// The Samsung S9+ kernel reports support for atomics, but not all cores
// actually support them, resulting in SIGILL. See issue #28431.
// TODO(elias.naur): Only disable the optimization on bad chipsets on android.
c.featureSet.setIf(isSet(hwcap, hwcap_ATOMICS) && runtime.GOOS != "android", ATOMICS)
return true
}
func isSet(hwc uint, value uint) bool {
return hwc&value != 0
}

17
vendor/github.com/klauspost/cpuid/v2/os_other_arm64.go generated vendored Normal file
View File

@@ -0,0 +1,17 @@
// Copyright (c) 2020 Klaus Post, released under MIT License. See LICENSE file.
// +build arm64
// +build !linux
// +build !darwin
package cpuid
import "runtime"
func detectOS(c *CPUInfo) bool {
c.PhysicalCores = runtime.NumCPU()
// For now assuming 1 thread per core...
c.ThreadsPerCore = 1
c.LogicalCores = c.PhysicalCores
return false
}

View File

@@ -0,0 +1,7 @@
// Copyright (c) 2021 Klaus Post, released under MIT License. See LICENSE file.
//+build nounsafe
package cpuid
var hwcap uint

View File

@@ -0,0 +1,10 @@
// Copyright (c) 2021 Klaus Post, released under MIT License. See LICENSE file.
//+build !nounsafe
package cpuid
import _ "unsafe" // needed for go:linkname
//go:linkname hwcap internal/cpu.HWCap
var hwcap uint

View File

@@ -0,0 +1,15 @@
#!/bin/sh
set -e
go tool dist list | while IFS=/ read os arch; do
echo "Checking $os/$arch..."
echo " normal"
GOARCH=$arch GOOS=$os go build -o /dev/null .
echo " noasm"
GOARCH=$arch GOOS=$os go build -tags noasm -o /dev/null .
echo " appengine"
GOARCH=$arch GOOS=$os go build -tags appengine -o /dev/null .
echo " noasm,appengine"
GOARCH=$arch GOOS=$os go build -tags 'appengine noasm' -o /dev/null .
done

6
vendor/github.com/zeebo/xxh3/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,6 @@
upstream
*.pprof
xxh3.test
.vscode
*.txt
_compat

25
vendor/github.com/zeebo/xxh3/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,25 @@
xxHash Library
Copyright (c) 2012-2014, Yann Collet
Copyright (c) 2019, Jeff Wendling
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

27
vendor/github.com/zeebo/xxh3/Makefile generated vendored Normal file
View File

@@ -0,0 +1,27 @@
.PHONY: all vet
all: genasm _compat
genasm: avo/avx.go avo/sse.go
cd ./avo; go generate gen.go
clean:
rm accum_vector_avx_amd64.s
rm accum_vector_sse_amd64.s
rm _compat
upstream/xxhash.o: upstream/xxhash.h
( cd upstream && make )
_compat: _compat.c upstream/xxhash.o
gcc -o _compat _compat.c ./upstream/xxhash.o
vet:
GOOS=linux GOARCH=386 GO386=softfloat go vet ./...
GOOS=windows GOARCH=386 GO386=softfloat go vet ./...
GOOS=linux GOARCH=amd64 go vet ./...
GOOS=windows GOARCH=amd64 go vet ./...
GOOS=darwin GOARCH=amd64 go vet ./...
GOOS=linux GOARCH=arm go vet ./...
GOOS=linux GOARCH=arm64 go vet ./...
GOOS=windows GOARCH=arm64 go vet ./...
GOOS=darwin GOARCH=arm64 go vet ./...

38
vendor/github.com/zeebo/xxh3/README.md generated vendored Normal file
View File

@@ -0,0 +1,38 @@
# XXH3
[![GoDoc](https://godoc.org/github.com/zeebo/xxh3?status.svg)](https://godoc.org/github.com/zeebo/xxh3)
[![Sourcegraph](https://sourcegraph.com/github.com/zeebo/xxh3/-/badge.svg)](https://sourcegraph.com/github.com/zeebo/xxh3?badge)
[![Go Report Card](https://goreportcard.com/badge/github.com/zeebo/xxh3)](https://goreportcard.com/report/github.com/zeebo/xxh3)
This package is a port of the [xxh3](https://github.com/Cyan4973/xxHash) library to Go.
Upstream has fixed the output as of v0.8.0, and this package matches that.
---
# Benchmarks
Run on my `i7-8850H CPU @ 2.60GHz`
## Small Sizes
| Bytes | Rate |
|-----------|--------------------------------------|
|` 0 ` |` 0.74 ns/op ` |
|` 1-3 ` |` 4.19 ns/op (0.24 GB/s - 0.71 GB/s) `|
|` 4-8 ` |` 4.16 ns/op (0.97 GB/s - 1.98 GB/s) `|
|` 9-16 ` |` 4.46 ns/op (2.02 GB/s - 3.58 GB/s) `|
|` 17-32 ` |` 6.22 ns/op (2.76 GB/s - 5.15 GB/s) `|
|` 33-64 ` |` 8.00 ns/op (4.13 GB/s - 8.13 GB/s) `|
|` 65-96 ` |` 11.0 ns/op (5.91 GB/s - 8.84 GB/s) `|
|` 97-128 ` |` 12.8 ns/op (7.68 GB/s - 10.0 GB/s) `|
## Large Sizes
| Bytes | Rate | SSE2 Rate | AVX2 Rate |
|---------|--------------------------|--------------------------|--------------------------|
|` 129 ` |` 13.6 ns/op (9.45 GB/s) `| | |
|` 240 ` |` 23.8 ns/op (10.1 GB/s) `| | |
|` 241 ` |` 40.5 ns/op (5.97 GB/s) `|` 23.3 ns/op (10.4 GB/s) `|` 20.1 ns/op (12.0 GB/s) `|
|` 512 ` |` 69.8 ns/op (7.34 GB/s) `|` 30.4 ns/op (16.9 GB/s) `|` 24.7 ns/op (20.7 GB/s) `|
|` 1024 ` |` 132 ns/op (7.77 GB/s) `|` 48.9 ns/op (20.9 GB/s) `|` 37.7 ns/op (27.2 GB/s) `|
|` 100KB `|` 13.0 us/op (7.88 GB/s) `|` 4.05 us/op (25.3 GB/s) `|` 2.31 us/op (44.3 GB/s) `|

39
vendor/github.com/zeebo/xxh3/_compat.c generated vendored Normal file
View File

@@ -0,0 +1,39 @@
#include "upstream/xxhash.h"
#include <stdio.h>
int main() {
unsigned char buf[4096];
for (int i = 0; i < 4096; i++) {
buf[i] = (unsigned char)((i+1)%251);
}
printf("var testVecs64 = []uint64{\n");
for (int i = 0; i < 4096; i++) {
if (i % 4 == 0) {
printf("\t");
}
uint64_t h = XXH3_64bits(buf, (size_t)i);
printf("0x%lx, ", h);
if (i % 4 == 3) {
printf("\n\t");
}
}
printf("}\n\n");
printf("var testVecs128 = [][2]uint64{\n");
for (int i = 0; i < 4096; i++) {
if (i % 4 == 0) {
printf("\t");
}
XXH128_hash_t h = XXH3_128bits(buf, (size_t)i);
printf("{0x%lx, 0x%lx}, ", h.high64, h.low64);
if (i % 4 == 3) {
printf("\n");
}
}
printf("}\n\n");
}

542
vendor/github.com/zeebo/xxh3/accum_generic.go generated vendored Normal file
View File

@@ -0,0 +1,542 @@
package xxh3
// avx512Switch is the size at which the avx512 code is used.
// Bigger blocks benefit more.
const avx512Switch = 1 << 10
func accumScalar(accs *[8]u64, p, secret ptr, l u64) {
if secret != key {
accumScalarSeed(accs, p, secret, l)
return
}
for l > _block {
k := secret
// accs
for i := 0; i < 16; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(k, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(k, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(k, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(k, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(k, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(k, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(k, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(k, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
l -= _stripe
if l > 0 {
p, k = ptr(ui(p)+_stripe), ptr(ui(k)+8)
}
}
// scramble accs
accs[0] ^= accs[0] >> 47
accs[0] ^= key64_128
accs[0] *= prime32_1
accs[1] ^= accs[1] >> 47
accs[1] ^= key64_136
accs[1] *= prime32_1
accs[2] ^= accs[2] >> 47
accs[2] ^= key64_144
accs[2] *= prime32_1
accs[3] ^= accs[3] >> 47
accs[3] ^= key64_152
accs[3] *= prime32_1
accs[4] ^= accs[4] >> 47
accs[4] ^= key64_160
accs[4] *= prime32_1
accs[5] ^= accs[5] >> 47
accs[5] ^= key64_168
accs[5] *= prime32_1
accs[6] ^= accs[6] >> 47
accs[6] ^= key64_176
accs[6] *= prime32_1
accs[7] ^= accs[7] >> 47
accs[7] ^= key64_184
accs[7] *= prime32_1
}
if l > 0 {
t, k := (l-1)/_stripe, secret
for i := u64(0); i < t; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(k, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(k, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(k, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(k, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(k, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(k, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(k, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(k, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
l -= _stripe
if l > 0 {
p, k = ptr(ui(p)+_stripe), ptr(ui(k)+8)
}
}
if l > 0 {
p = ptr(ui(p) - uintptr(_stripe-l))
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ key64_121
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ key64_129
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ key64_137
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ key64_145
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ key64_153
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ key64_161
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ key64_169
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ key64_177
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
}
}
}
func accumBlockScalar(accs *[8]u64, p, secret ptr) {
if secret != key {
accumBlockScalarSeed(accs, p, secret)
return
}
// accs
for i := 0; i < 16; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(secret, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(secret, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(secret, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(secret, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(secret, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(secret, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(secret, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(secret, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
p, secret = ptr(ui(p)+_stripe), ptr(ui(secret)+8)
}
// scramble accs
accs[0] ^= accs[0] >> 47
accs[0] ^= key64_128
accs[0] *= prime32_1
accs[1] ^= accs[1] >> 47
accs[1] ^= key64_136
accs[1] *= prime32_1
accs[2] ^= accs[2] >> 47
accs[2] ^= key64_144
accs[2] *= prime32_1
accs[3] ^= accs[3] >> 47
accs[3] ^= key64_152
accs[3] *= prime32_1
accs[4] ^= accs[4] >> 47
accs[4] ^= key64_160
accs[4] *= prime32_1
accs[5] ^= accs[5] >> 47
accs[5] ^= key64_168
accs[5] *= prime32_1
accs[6] ^= accs[6] >> 47
accs[6] ^= key64_176
accs[6] *= prime32_1
accs[7] ^= accs[7] >> 47
accs[7] ^= key64_184
accs[7] *= prime32_1
}
// accumScalarSeed should be used with custom key.
func accumScalarSeed(accs *[8]u64, p, secret ptr, l u64) {
for l > _block {
k := secret
// accs
for i := 0; i < 16; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(k, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(k, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(k, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(k, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(k, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(k, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(k, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(k, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
l -= _stripe
if l > 0 {
p, k = ptr(ui(p)+_stripe), ptr(ui(k)+8)
}
}
// scramble accs
accs[0] ^= accs[0] >> 47
accs[0] ^= readU64(secret, 128)
accs[0] *= prime32_1
accs[1] ^= accs[1] >> 47
accs[1] ^= readU64(secret, 136)
accs[1] *= prime32_1
accs[2] ^= accs[2] >> 47
accs[2] ^= readU64(secret, 144)
accs[2] *= prime32_1
accs[3] ^= accs[3] >> 47
accs[3] ^= readU64(secret, 152)
accs[3] *= prime32_1
accs[4] ^= accs[4] >> 47
accs[4] ^= readU64(secret, 160)
accs[4] *= prime32_1
accs[5] ^= accs[5] >> 47
accs[5] ^= readU64(secret, 168)
accs[5] *= prime32_1
accs[6] ^= accs[6] >> 47
accs[6] ^= readU64(secret, 176)
accs[6] *= prime32_1
accs[7] ^= accs[7] >> 47
accs[7] ^= readU64(secret, 184)
accs[7] *= prime32_1
}
if l > 0 {
t, k := (l-1)/_stripe, secret
for i := u64(0); i < t; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(k, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(k, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(k, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(k, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(k, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(k, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(k, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(k, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
l -= _stripe
if l > 0 {
p, k = ptr(ui(p)+_stripe), ptr(ui(k)+8)
}
}
if l > 0 {
p = ptr(ui(p) - uintptr(_stripe-l))
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(secret, 121)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(secret, 129)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(secret, 137)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(secret, 145)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(secret, 153)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(secret, 161)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(secret, 169)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(secret, 177)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
}
}
}
// accumBlockScalarSeed should be used with custom key.
func accumBlockScalarSeed(accs *[8]u64, p, secret ptr) {
// accs
{
secret := secret
for i := 0; i < 16; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(secret, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(secret, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(secret, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(secret, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(secret, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(secret, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(secret, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(secret, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
p, secret = ptr(ui(p)+_stripe), ptr(ui(secret)+8)
}
}
// scramble accs
accs[0] ^= accs[0] >> 47
accs[0] ^= readU64(secret, 128)
accs[0] *= prime32_1
accs[1] ^= accs[1] >> 47
accs[1] ^= readU64(secret, 136)
accs[1] *= prime32_1
accs[2] ^= accs[2] >> 47
accs[2] ^= readU64(secret, 144)
accs[2] *= prime32_1
accs[3] ^= accs[3] >> 47
accs[3] ^= readU64(secret, 152)
accs[3] *= prime32_1
accs[4] ^= accs[4] >> 47
accs[4] ^= readU64(secret, 160)
accs[4] *= prime32_1
accs[5] ^= accs[5] >> 47
accs[5] ^= readU64(secret, 168)
accs[5] *= prime32_1
accs[6] ^= accs[6] >> 47
accs[6] ^= readU64(secret, 176)
accs[6] *= prime32_1
accs[7] ^= accs[7] >> 47
accs[7] ^= readU64(secret, 184)
accs[7] *= prime32_1
}

40
vendor/github.com/zeebo/xxh3/accum_stubs_amd64.go generated vendored Normal file
View File

@@ -0,0 +1,40 @@
package xxh3
import (
"unsafe"
"github.com/klauspost/cpuid/v2"
)
var (
hasAVX2 = cpuid.CPU.Has(cpuid.AVX2)
hasSSE2 = cpuid.CPU.Has(cpuid.SSE2) // Always true on amd64
hasAVX512 = cpuid.CPU.Has(cpuid.AVX512F)
)
//go:noescape
func accumAVX2(acc *[8]u64, data, key unsafe.Pointer, len u64)
//go:noescape
func accumAVX512(acc *[8]u64, data, key unsafe.Pointer, len u64)
//go:noescape
func accumSSE(acc *[8]u64, data, key unsafe.Pointer, len u64)
//go:noescape
func accumBlockAVX2(acc *[8]u64, data, key unsafe.Pointer)
//go:noescape
func accumBlockSSE(acc *[8]u64, data, key unsafe.Pointer)
func withOverrides(avx512, avx2, sse2 bool, cb func()) {
avx512Orig, avx2Orig, sse2Orig := hasAVX512, hasAVX2, hasSSE2
hasAVX512, hasAVX2, hasSSE2 = avx512, avx2, sse2
defer func() { hasAVX512, hasAVX2, hasSSE2 = avx512Orig, avx2Orig, sse2Orig }()
cb()
}
func withAVX512(cb func()) { withOverrides(hasAVX512, false, false, cb) }
func withAVX2(cb func()) { withOverrides(false, hasAVX2, false, cb) }
func withSSE2(cb func()) { withOverrides(false, false, hasSSE2, cb) }
func withGeneric(cb func()) { withOverrides(false, false, false, cb) }

25
vendor/github.com/zeebo/xxh3/accum_stubs_other.go generated vendored Normal file
View File

@@ -0,0 +1,25 @@
//go:build !amd64
// +build !amd64
package xxh3
import (
"unsafe"
)
const (
hasAVX2 = false
hasSSE2 = false
hasAVX512 = false
)
func accumAVX2(acc *[8]u64, data, key unsafe.Pointer, len u64) { panic("unreachable") }
func accumSSE(acc *[8]u64, data, key unsafe.Pointer, len u64) { panic("unreachable") }
func accumBlockAVX2(acc *[8]u64, data, key unsafe.Pointer) { panic("unreachable") }
func accumBlockSSE(acc *[8]u64, data, key unsafe.Pointer) { panic("unreachable") }
func accumAVX512(acc *[8]u64, data, key unsafe.Pointer, len u64) { panic("unreachable") }
func withAVX512(cb func()) { cb() }
func withAVX2(cb func()) { cb() }
func withSSE2(cb func()) { cb() }
func withGeneric(cb func()) { cb() }

View File

@@ -0,0 +1,379 @@
// Code generated by command: go run gen.go -avx512 -out ../accum_vector_avx512_amd64.s -pkg xxh3. DO NOT EDIT.
#include "textflag.h"
DATA prime_avx512<>+0(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+8(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+16(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+24(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+32(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+40(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+48(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+56(SB)/8, $0x000000009e3779b1
GLOBL prime_avx512<>(SB), RODATA|NOPTR, $64
// func accumAVX512(acc *[8]uint64, data *byte, key *byte, len uint64)
// Requires: AVX, AVX512F, MMX+
TEXT ·accumAVX512(SB), NOSPLIT, $0-32
MOVQ acc+0(FP), AX
MOVQ data+8(FP), CX
MOVQ key+16(FP), DX
MOVQ len+24(FP), BX
VMOVDQU64 (AX), Z1
VMOVDQU64 prime_avx512<>+0(SB), Z0
VMOVDQU64 (DX), Z2
VMOVDQU64 8(DX), Z3
VMOVDQU64 16(DX), Z4
VMOVDQU64 24(DX), Z5
VMOVDQU64 32(DX), Z6
VMOVDQU64 40(DX), Z7
VMOVDQU64 48(DX), Z8
VMOVDQU64 56(DX), Z9
VMOVDQU64 64(DX), Z10
VMOVDQU64 72(DX), Z11
VMOVDQU64 80(DX), Z12
VMOVDQU64 88(DX), Z13
VMOVDQU64 96(DX), Z14
VMOVDQU64 104(DX), Z15
VMOVDQU64 112(DX), Z16
VMOVDQU64 120(DX), Z17
VMOVDQU64 128(DX), Z18
VMOVDQU64 121(DX), Z19
accum_large:
CMPQ BX, $0x00000400
JLE accum
VMOVDQU64 (CX), Z20
PREFETCHT0 1024(CX)
VPXORD Z2, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 64(CX), Z20
PREFETCHT0 1088(CX)
VPXORD Z3, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 128(CX), Z20
PREFETCHT0 1152(CX)
VPXORD Z4, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 192(CX), Z20
PREFETCHT0 1216(CX)
VPXORD Z5, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 256(CX), Z20
PREFETCHT0 1280(CX)
VPXORD Z6, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 320(CX), Z20
PREFETCHT0 1344(CX)
VPXORD Z7, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 384(CX), Z20
PREFETCHT0 1408(CX)
VPXORD Z8, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 448(CX), Z20
PREFETCHT0 1472(CX)
VPXORD Z9, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 512(CX), Z20
PREFETCHT0 1536(CX)
VPXORD Z10, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 576(CX), Z20
PREFETCHT0 1600(CX)
VPXORD Z11, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 640(CX), Z20
PREFETCHT0 1664(CX)
VPXORD Z12, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 704(CX), Z20
PREFETCHT0 1728(CX)
VPXORD Z13, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 768(CX), Z20
PREFETCHT0 1792(CX)
VPXORD Z14, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 832(CX), Z20
PREFETCHT0 1856(CX)
VPXORD Z15, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 896(CX), Z20
PREFETCHT0 1920(CX)
VPXORD Z16, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 960(CX), Z20
PREFETCHT0 1984(CX)
VPXORD Z17, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
ADDQ $0x00000400, CX
SUBQ $0x00000400, BX
VPSRLQ $0x2f, Z1, Z20
VPTERNLOGD $0x96, Z1, Z18, Z20
VPMULUDQ Z0, Z20, Z1
VPSHUFD $0xf5, Z20, Z20
VPMULUDQ Z0, Z20, Z20
VPSLLQ $0x20, Z20, Z20
VPADDQ Z1, Z20, Z1
JMP accum_large
accum:
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z2, Z0, Z2
VPSHUFD $0x31, Z2, Z18
VPMULUDQ Z2, Z18, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z3, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z4, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z5, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z6, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z7, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z8, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z9, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z10, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z11, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z12, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z13, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z14, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z15, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z16, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z17, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
finalize:
CMPQ BX, $0x00
JE return
SUBQ $0x40, CX
ADDQ BX, CX
VMOVDQU64 (CX), Z0
VPXORD Z19, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
return:
VMOVDQU64 Z1, (AX)
VZEROUPPER
RET

586
vendor/github.com/zeebo/xxh3/accum_vector_avx_amd64.s generated vendored Normal file
View File

@@ -0,0 +1,586 @@
// Code generated by command: go run gen.go -avx -out ../accum_vector_avx_amd64.s -pkg xxh3. DO NOT EDIT.
#include "textflag.h"
DATA prime_avx<>+0(SB)/8, $0x000000009e3779b1
DATA prime_avx<>+8(SB)/8, $0x000000009e3779b1
DATA prime_avx<>+16(SB)/8, $0x000000009e3779b1
DATA prime_avx<>+24(SB)/8, $0x000000009e3779b1
GLOBL prime_avx<>(SB), RODATA|NOPTR, $32
// func accumAVX2(acc *[8]uint64, data *byte, key *byte, len uint64)
// Requires: AVX, AVX2, MMX+
TEXT ·accumAVX2(SB), NOSPLIT, $0-32
MOVQ acc+0(FP), AX
MOVQ data+8(FP), CX
MOVQ key+16(FP), DX
MOVQ key+16(FP), BX
MOVQ len+24(FP), SI
VMOVDQU (AX), Y1
VMOVDQU 32(AX), Y2
VMOVDQU prime_avx<>+0(SB), Y0
accum_large:
CMPQ SI, $0x00000400
JLE accum
VMOVDQU (CX), Y3
VMOVDQU 32(CX), Y6
PREFETCHT0 512(CX)
VPXOR (DX), Y3, Y4
VPXOR 32(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 64(CX), Y3
VMOVDQU 96(CX), Y6
PREFETCHT0 576(CX)
VPXOR 8(DX), Y3, Y4
VPXOR 40(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 128(CX), Y3
VMOVDQU 160(CX), Y6
PREFETCHT0 640(CX)
VPXOR 16(DX), Y3, Y4
VPXOR 48(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 192(CX), Y3
VMOVDQU 224(CX), Y6
PREFETCHT0 704(CX)
VPXOR 24(DX), Y3, Y4
VPXOR 56(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 256(CX), Y3
VMOVDQU 288(CX), Y6
PREFETCHT0 768(CX)
VPXOR 32(DX), Y3, Y4
VPXOR 64(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 320(CX), Y3
VMOVDQU 352(CX), Y6
PREFETCHT0 832(CX)
VPXOR 40(DX), Y3, Y4
VPXOR 72(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 384(CX), Y3
VMOVDQU 416(CX), Y6
PREFETCHT0 896(CX)
VPXOR 48(DX), Y3, Y4
VPXOR 80(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 448(CX), Y3
VMOVDQU 480(CX), Y6
PREFETCHT0 960(CX)
VPXOR 56(DX), Y3, Y4
VPXOR 88(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 512(CX), Y3
VMOVDQU 544(CX), Y6
PREFETCHT0 1024(CX)
VPXOR 64(DX), Y3, Y4
VPXOR 96(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 576(CX), Y3
VMOVDQU 608(CX), Y6
PREFETCHT0 1088(CX)
VPXOR 72(DX), Y3, Y4
VPXOR 104(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 640(CX), Y3
VMOVDQU 672(CX), Y6
PREFETCHT0 1152(CX)
VPXOR 80(DX), Y3, Y4
VPXOR 112(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 704(CX), Y3
VMOVDQU 736(CX), Y6
PREFETCHT0 1216(CX)
VPXOR 88(DX), Y3, Y4
VPXOR 120(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 768(CX), Y3
VMOVDQU 800(CX), Y6
PREFETCHT0 1280(CX)
VPXOR 96(DX), Y3, Y4
VPXOR 128(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 832(CX), Y3
VMOVDQU 864(CX), Y6
PREFETCHT0 1344(CX)
VPXOR 104(DX), Y3, Y4
VPXOR 136(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 896(CX), Y3
VMOVDQU 928(CX), Y6
PREFETCHT0 1408(CX)
VPXOR 112(DX), Y3, Y4
VPXOR 144(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 960(CX), Y3
VMOVDQU 992(CX), Y6
PREFETCHT0 1472(CX)
VPXOR 120(DX), Y3, Y4
VPXOR 152(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
ADDQ $0x00000400, CX
SUBQ $0x00000400, SI
VPSRLQ $0x2f, Y1, Y3
VPXOR Y1, Y3, Y3
VPXOR 128(DX), Y3, Y3
VPMULUDQ Y0, Y3, Y1
VPSHUFD $0xf5, Y3, Y3
VPMULUDQ Y0, Y3, Y3
VPSLLQ $0x20, Y3, Y3
VPADDQ Y1, Y3, Y1
VPSRLQ $0x2f, Y2, Y3
VPXOR Y2, Y3, Y3
VPXOR 160(DX), Y3, Y3
VPMULUDQ Y0, Y3, Y2
VPSHUFD $0xf5, Y3, Y3
VPMULUDQ Y0, Y3, Y3
VPSLLQ $0x20, Y3, Y3
VPADDQ Y2, Y3, Y2
JMP accum_large
accum:
CMPQ SI, $0x40
JLE finalize
VMOVDQU (CX), Y0
VMOVDQU 32(CX), Y5
VPXOR (BX), Y0, Y3
VPXOR 32(BX), Y5, Y6
VPSHUFD $0x31, Y3, Y4
VPSHUFD $0x31, Y6, Y7
VPMULUDQ Y3, Y4, Y3
VPMULUDQ Y6, Y7, Y6
VPSHUFD $0x4e, Y0, Y0
VPSHUFD $0x4e, Y5, Y5
VPADDQ Y1, Y0, Y1
VPADDQ Y1, Y3, Y1
VPADDQ Y2, Y5, Y2
VPADDQ Y2, Y6, Y2
ADDQ $0x00000040, CX
SUBQ $0x00000040, SI
ADDQ $0x00000008, BX
JMP accum
finalize:
CMPQ SI, $0x00
JE return
SUBQ $0x40, CX
ADDQ SI, CX
VMOVDQU (CX), Y0
VMOVDQU 32(CX), Y5
VPXOR 121(DX), Y0, Y3
VPXOR 153(DX), Y5, Y6
VPSHUFD $0x31, Y3, Y4
VPSHUFD $0x31, Y6, Y7
VPMULUDQ Y3, Y4, Y3
VPMULUDQ Y6, Y7, Y6
VPSHUFD $0x4e, Y0, Y0
VPSHUFD $0x4e, Y5, Y5
VPADDQ Y1, Y0, Y1
VPADDQ Y1, Y3, Y1
VPADDQ Y2, Y5, Y2
VPADDQ Y2, Y6, Y2
return:
VMOVDQU Y1, (AX)
VMOVDQU Y2, 32(AX)
VZEROUPPER
RET
// func accumBlockAVX2(acc *[8]uint64, data *byte, key *byte)
// Requires: AVX, AVX2
TEXT ·accumBlockAVX2(SB), NOSPLIT, $0-24
MOVQ acc+0(FP), AX
MOVQ data+8(FP), CX
MOVQ key+16(FP), DX
VMOVDQU (AX), Y1
VMOVDQU 32(AX), Y2
VMOVDQU prime_avx<>+0(SB), Y0
VMOVDQU (CX), Y3
VMOVDQU 32(CX), Y6
VPXOR (DX), Y3, Y4
VPXOR 32(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 64(CX), Y3
VMOVDQU 96(CX), Y6
VPXOR 8(DX), Y3, Y4
VPXOR 40(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 128(CX), Y3
VMOVDQU 160(CX), Y6
VPXOR 16(DX), Y3, Y4
VPXOR 48(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 192(CX), Y3
VMOVDQU 224(CX), Y6
VPXOR 24(DX), Y3, Y4
VPXOR 56(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 256(CX), Y3
VMOVDQU 288(CX), Y6
VPXOR 32(DX), Y3, Y4
VPXOR 64(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 320(CX), Y3
VMOVDQU 352(CX), Y6
VPXOR 40(DX), Y3, Y4
VPXOR 72(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 384(CX), Y3
VMOVDQU 416(CX), Y6
VPXOR 48(DX), Y3, Y4
VPXOR 80(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 448(CX), Y3
VMOVDQU 480(CX), Y6
VPXOR 56(DX), Y3, Y4
VPXOR 88(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 512(CX), Y3
VMOVDQU 544(CX), Y6
VPXOR 64(DX), Y3, Y4
VPXOR 96(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 576(CX), Y3
VMOVDQU 608(CX), Y6
VPXOR 72(DX), Y3, Y4
VPXOR 104(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 640(CX), Y3
VMOVDQU 672(CX), Y6
VPXOR 80(DX), Y3, Y4
VPXOR 112(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 704(CX), Y3
VMOVDQU 736(CX), Y6
VPXOR 88(DX), Y3, Y4
VPXOR 120(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 768(CX), Y3
VMOVDQU 800(CX), Y6
VPXOR 96(DX), Y3, Y4
VPXOR 128(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 832(CX), Y3
VMOVDQU 864(CX), Y6
VPXOR 104(DX), Y3, Y4
VPXOR 136(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 896(CX), Y3
VMOVDQU 928(CX), Y6
VPXOR 112(DX), Y3, Y4
VPXOR 144(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 960(CX), Y3
VMOVDQU 992(CX), Y6
VPXOR 120(DX), Y3, Y4
VPXOR 152(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VPSRLQ $0x2f, Y1, Y3
VPXOR Y1, Y3, Y3
VPXOR 128(DX), Y3, Y3
VPMULUDQ Y0, Y3, Y1
VPSHUFD $0xf5, Y3, Y3
VPMULUDQ Y0, Y3, Y3
VPSLLQ $0x20, Y3, Y3
VPADDQ Y1, Y3, Y1
VPSRLQ $0x2f, Y2, Y3
VPXOR Y2, Y3, Y3
VPXOR 160(DX), Y3, Y3
VPMULUDQ Y0, Y3, Y2
VPSHUFD $0xf5, Y3, Y3
VPMULUDQ Y0, Y3, Y3
VPSLLQ $0x20, Y3, Y3
VPADDQ Y2, Y3, Y2
VMOVDQU Y1, (AX)
VMOVDQU Y2, 32(AX)
VZEROUPPER
RET

1236
vendor/github.com/zeebo/xxh3/accum_vector_sse_amd64.s generated vendored Normal file

File diff suppressed because it is too large Load Diff

97
vendor/github.com/zeebo/xxh3/consts.go generated vendored Normal file
View File

@@ -0,0 +1,97 @@
package xxh3
const (
_stripe = 64
_block = 1024
prime32_1 = 2654435761
prime32_2 = 2246822519
prime32_3 = 3266489917
prime64_1 = 11400714785074694791
prime64_2 = 14029467366897019727
prime64_3 = 1609587929392839161
prime64_4 = 9650029242287828579
prime64_5 = 2870177450012600261
)
var key = ptr(&[...]u8{
0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe /* 8 */, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c, /* 16 */
0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb /* 24 */, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f, /* 32 */
0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78 /* 40 */, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21, /* 48 */
0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e /* 56 */, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c, /* 64 */
0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb /* 72 */, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3, /* 80 */
0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e /* 88 */, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8, /* 96 */
0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f /* 104 */, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d, /* 112 */
0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31 /* 120 */, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64, /* 128 */
0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3 /* 136 */, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb, /* 144 */
0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49 /* 152 */, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e, /* 160 */
0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc /* 168 */, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce, /* 176 */
0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28 /* 184 */, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e, /* 192 */
})
const (
key64_000 u64 = 0xbe4ba423396cfeb8
key64_008 u64 = 0x1cad21f72c81017c
key64_016 u64 = 0xdb979083e96dd4de
key64_024 u64 = 0x1f67b3b7a4a44072
key64_032 u64 = 0x78e5c0cc4ee679cb
key64_040 u64 = 0x2172ffcc7dd05a82
key64_048 u64 = 0x8e2443f7744608b8
key64_056 u64 = 0x4c263a81e69035e0
key64_064 u64 = 0xcb00c391bb52283c
key64_072 u64 = 0xa32e531b8b65d088
key64_080 u64 = 0x4ef90da297486471
key64_088 u64 = 0xd8acdea946ef1938
key64_096 u64 = 0x3f349ce33f76faa8
key64_104 u64 = 0x1d4f0bc7c7bbdcf9
key64_112 u64 = 0x3159b4cd4be0518a
key64_120 u64 = 0x647378d9c97e9fc8
key64_128 u64 = 0xc3ebd33483acc5ea
key64_136 u64 = 0xeb6313faffa081c5
key64_144 u64 = 0x49daf0b751dd0d17
key64_152 u64 = 0x9e68d429265516d3
key64_160 u64 = 0xfca1477d58be162b
key64_168 u64 = 0xce31d07ad1b8f88f
key64_176 u64 = 0x280416958f3acb45
key64_184 u64 = 0x7e404bbbcafbd7af
key64_103 u64 = 0x4f0bc7c7bbdcf93f
key64_111 u64 = 0x59b4cd4be0518a1d
key64_119 u64 = 0x7378d9c97e9fc831
key64_127 u64 = 0xebd33483acc5ea64
key64_121 u64 = 0xea647378d9c97e9f
key64_129 u64 = 0xc5c3ebd33483acc5
key64_137 u64 = 0x17eb6313faffa081
key64_145 u64 = 0xd349daf0b751dd0d
key64_153 u64 = 0x2b9e68d429265516
key64_161 u64 = 0x8ffca1477d58be16
key64_169 u64 = 0x45ce31d07ad1b8f8
key64_177 u64 = 0xaf280416958f3acb
key64_011 = 0x6dd4de1cad21f72c
key64_019 = 0xa44072db979083e9
key64_027 = 0xe679cb1f67b3b7a4
key64_035 = 0xd05a8278e5c0cc4e
key64_043 = 0x4608b82172ffcc7d
key64_051 = 0x9035e08e2443f774
key64_059 = 0x52283c4c263a81e6
key64_067 = 0x65d088cb00c391bb
key64_117 = 0xd9c97e9fc83159b4
key64_125 = 0x3483acc5ea647378
key64_133 = 0xfaffa081c5c3ebd3
key64_141 = 0xb751dd0d17eb6313
key64_149 = 0x29265516d349daf0
key64_157 = 0x7d58be162b9e68d4
key64_165 = 0x7ad1b8f88ffca147
key64_173 = 0x958f3acb45ce31d0
)
const (
key32_000 u32 = 0xbe4ba423
key32_004 u32 = 0x396cfeb8
key32_008 u32 = 0x1cad21f7
key32_012 u32 = 0x2c81017c
)

253
vendor/github.com/zeebo/xxh3/hash128.go generated vendored Normal file
View File

@@ -0,0 +1,253 @@
package xxh3
import (
"math/bits"
)
// Hash128 returns the 128-bit hash of the byte slice.
func Hash128(b []byte) Uint128 {
return hashAny128(*(*str)(ptr(&b)))
}
// HashString128 returns the 128-bit hash of the string slice.
func HashString128(s string) Uint128 {
return hashAny128(*(*str)(ptr(&s)))
}
func hashAny128(s str) (acc u128) {
p, l := s.p, s.l
switch {
case l <= 16:
switch {
case l > 8: // 9-16
const bitflipl = key64_032 ^ key64_040
const bitfliph = key64_048 ^ key64_056
input_lo := readU64(p, 0)
input_hi := readU64(p, ui(l)-8)
m128_h, m128_l := bits.Mul64(input_lo^input_hi^bitflipl, prime64_1)
m128_l += uint64(l-1) << 54
input_hi ^= bitfliph
m128_h += input_hi + uint64(uint32(input_hi))*(prime32_2-1)
m128_l ^= bits.ReverseBytes64(m128_h)
acc.Hi, acc.Lo = bits.Mul64(m128_l, prime64_2)
acc.Hi += m128_h * prime64_2
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
case l > 3: // 4-8
const bitflip = key64_016 ^ key64_024
input_lo := readU32(p, 0)
input_hi := readU32(p, ui(l)-4)
input_64 := u64(input_lo) + u64(input_hi)<<32
keyed := input_64 ^ bitflip
acc.Hi, acc.Lo = bits.Mul64(keyed, prime64_1+(uint64(l)<<2))
acc.Hi += acc.Lo << 1
acc.Lo ^= acc.Hi >> 3
acc.Lo ^= acc.Lo >> 35
acc.Lo *= 0x9fb21c651e98df25
acc.Lo ^= acc.Lo >> 28
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
case l == 3: // 3
c12 := u64(readU16(p, 0))
c3 := u64(readU8(p, 2))
acc.Lo = c12<<16 + c3 + 3<<8
case l > 1: // 2
c12 := u64(readU16(p, 0))
acc.Lo = c12*(1<<24+1)>>8 + 2<<8
case l == 1: // 1
c1 := u64(readU8(p, 0))
acc.Lo = c1*(1<<24+1<<16+1) + 1<<8
default: // 0
return u128{0x99aa06d3014798d8, 0x6001c324468d497f}
}
acc.Hi = uint64(bits.RotateLeft32(bits.ReverseBytes32(uint32(acc.Lo)), 13))
acc.Lo ^= uint64(key32_000 ^ key32_004)
acc.Hi ^= uint64(key32_008 ^ key32_012)
acc.Lo = xxh64AvalancheSmall(acc.Lo)
acc.Hi = xxh64AvalancheSmall(acc.Hi)
return acc
case l <= 128:
acc.Lo = u64(l) * prime64_1
if l > 32 {
if l > 64 {
if l > 96 {
in8, in7 := readU64(p, ui(l)-8*8), readU64(p, ui(l)-7*8)
i6, i7 := readU64(p, 6*8), readU64(p, 7*8)
acc.Hi += mulFold64(in8^key64_112, in7^key64_120)
acc.Hi ^= i6 + i7
acc.Lo += mulFold64(i6^key64_096, i7^key64_104)
acc.Lo ^= in8 + in7
} // 96
in6, in5 := readU64(p, ui(l)-6*8), readU64(p, ui(l)-5*8)
i4, i5 := readU64(p, 4*8), readU64(p, 5*8)
acc.Hi += mulFold64(in6^key64_080, in5^key64_088)
acc.Hi ^= i4 + i5
acc.Lo += mulFold64(i4^key64_064, i5^key64_072)
acc.Lo ^= in6 + in5
} // 64
in4, in3 := readU64(p, ui(l)-4*8), readU64(p, ui(l)-3*8)
i2, i3 := readU64(p, 2*8), readU64(p, 3*8)
acc.Hi += mulFold64(in4^key64_048, in3^key64_056)
acc.Hi ^= i2 + i3
acc.Lo += mulFold64(i2^key64_032, i3^key64_040)
acc.Lo ^= in4 + in3
} // 32
in2, in1 := readU64(p, ui(l)-2*8), readU64(p, ui(l)-1*8)
i0, i1 := readU64(p, 0*8), readU64(p, 1*8)
acc.Hi += mulFold64(in2^key64_016, in1^key64_024)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_000, i1^key64_008)
acc.Lo ^= in2 + in1
acc.Hi, acc.Lo = (acc.Lo*prime64_1)+(acc.Hi*prime64_4)+(u64(l)*prime64_2), acc.Hi+acc.Lo
acc.Hi = -xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
return acc
case l <= 240:
acc.Lo = u64(l) * prime64_1
{
i0, i1, i2, i3 := readU64(p, 0*8), readU64(p, 1*8), readU64(p, 2*8), readU64(p, 3*8)
acc.Hi += mulFold64(i2^key64_016, i3^key64_024)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_000, i1^key64_008)
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 4*8), readU64(p, 5*8), readU64(p, 6*8), readU64(p, 7*8)
acc.Hi += mulFold64(i2^key64_048, i3^key64_056)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_032, i1^key64_040)
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 8*8), readU64(p, 9*8), readU64(p, 10*8), readU64(p, 11*8)
acc.Hi += mulFold64(i2^key64_080, i3^key64_088)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_064, i1^key64_072)
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 12*8), readU64(p, 13*8), readU64(p, 14*8), readU64(p, 15*8)
acc.Hi += mulFold64(i2^key64_112, i3^key64_120)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_096, i1^key64_104)
acc.Lo ^= i2 + i3
}
// avalanche
acc.Hi = xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
// trailing groups after 128
top := ui(l) &^ 31
for i := ui(4 * 32); i < top; i += 32 {
i0, i1, i2, i3 := readU64(p, i+0), readU64(p, i+8), readU64(p, i+16), readU64(p, i+24)
k0, k1, k2, k3 := readU64(key, i-125), readU64(key, i-117), readU64(key, i-109), readU64(key, i-101)
acc.Hi += mulFold64(i2^k2, i3^k3)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^k0, i1^k1)
acc.Lo ^= i2 + i3
}
// last 32 bytes
{
i0, i1, i2, i3 := readU64(p, ui(l)-32), readU64(p, ui(l)-24), readU64(p, ui(l)-16), readU64(p, ui(l)-8)
acc.Hi += mulFold64(i0^key64_119, i1^key64_127)
acc.Hi ^= i2 + i3
acc.Lo += mulFold64(i2^key64_103, i3^key64_111)
acc.Lo ^= i0 + i1
}
acc.Hi, acc.Lo = (acc.Lo*prime64_1)+(acc.Hi*prime64_4)+(u64(l)*prime64_2), acc.Hi+acc.Lo
acc.Hi = -xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
return acc
default:
acc.Lo = u64(l) * prime64_1
acc.Hi = ^(u64(l) * prime64_2)
accs := [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
if hasAVX512 && l >= avx512Switch {
accumAVX512(&accs, p, key, u64(l))
} else if hasAVX2 {
accumAVX2(&accs, p, key, u64(l))
} else if hasSSE2 {
accumSSE(&accs, p, key, u64(l))
} else {
accumScalar(&accs, p, key, u64(l))
}
// merge accs
acc.Lo += mulFold64(accs[0]^key64_011, accs[1]^key64_019)
acc.Hi += mulFold64(accs[0]^key64_117, accs[1]^key64_125)
acc.Lo += mulFold64(accs[2]^key64_027, accs[3]^key64_035)
acc.Hi += mulFold64(accs[2]^key64_133, accs[3]^key64_141)
acc.Lo += mulFold64(accs[4]^key64_043, accs[5]^key64_051)
acc.Hi += mulFold64(accs[4]^key64_149, accs[5]^key64_157)
acc.Lo += mulFold64(accs[6]^key64_059, accs[7]^key64_067)
acc.Hi += mulFold64(accs[6]^key64_165, accs[7]^key64_173)
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
}
}

264
vendor/github.com/zeebo/xxh3/hash128_seed.go generated vendored Normal file
View File

@@ -0,0 +1,264 @@
package xxh3
import (
"math/bits"
)
// Hash128Seed returns the 128-bit hash of the byte slice.
func Hash128Seed(b []byte, seed uint64) Uint128 {
return hashAny128Seed(*(*str)(ptr(&b)), seed)
}
// HashString128Seed returns the 128-bit hash of the string slice.
func HashString128Seed(s string, seed uint64) Uint128 {
return hashAny128Seed(*(*str)(ptr(&s)), seed)
}
func hashAny128Seed(s str, seed uint64) (acc u128) {
p, l := s.p, s.l
switch {
case l <= 16:
switch {
case l > 8: // 9-16
bitflipl := (key64_032 ^ key64_040) - seed
bitfliph := (key64_048 ^ key64_056) + seed
input_lo := readU64(p, 0)
input_hi := readU64(p, ui(l)-8)
m128_h, m128_l := bits.Mul64(input_lo^input_hi^bitflipl, prime64_1)
m128_l += uint64(l-1) << 54
input_hi ^= bitfliph
m128_h += input_hi + uint64(uint32(input_hi))*(prime32_2-1)
m128_l ^= bits.ReverseBytes64(m128_h)
acc.Hi, acc.Lo = bits.Mul64(m128_l, prime64_2)
acc.Hi += m128_h * prime64_2
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
case l > 3: // 4-8
seed ^= u64(bits.ReverseBytes32(u32(seed))) << 32
bitflip := (key64_016 ^ key64_024) + seed
input_lo := readU32(p, 0)
input_hi := readU32(p, ui(l)-4)
input_64 := u64(input_lo) + u64(input_hi)<<32
keyed := input_64 ^ bitflip
acc.Hi, acc.Lo = bits.Mul64(keyed, prime64_1+(uint64(l)<<2))
acc.Hi += acc.Lo << 1
acc.Lo ^= acc.Hi >> 3
acc.Lo ^= acc.Lo >> 35
acc.Lo *= 0x9fb21c651e98df25
acc.Lo ^= acc.Lo >> 28
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
case l == 3: // 3
c12 := u64(readU16(p, 0))
c3 := u64(readU8(p, 2))
acc.Lo = c12<<16 + c3 + 3<<8
case l > 1: // 2
c12 := u64(readU16(p, 0))
acc.Lo = c12*(1<<24+1)>>8 + 2<<8
case l == 1: // 1
c1 := u64(readU8(p, 0))
acc.Lo = c1*(1<<24+1<<16+1) + 1<<8
default: // 0
bitflipl := key64_064 ^ key64_072 ^ seed
bitfliph := key64_080 ^ key64_088 ^ seed
return u128{Lo: xxh64AvalancheFull(bitflipl), Hi: xxh64AvalancheFull(bitfliph)}
}
acc.Hi = uint64(bits.RotateLeft32(bits.ReverseBytes32(uint32(acc.Lo)), 13))
acc.Lo ^= uint64(key32_000^key32_004) + seed
acc.Hi ^= uint64(key32_008^key32_012) - seed
acc.Lo = xxh64AvalancheFull(acc.Lo)
acc.Hi = xxh64AvalancheFull(acc.Hi)
return acc
case l <= 128:
acc.Lo = u64(l) * prime64_1
if l > 32 {
if l > 64 {
if l > 96 {
in8, in7 := readU64(p, ui(l)-8*8), readU64(p, ui(l)-7*8)
i6, i7 := readU64(p, 6*8), readU64(p, 7*8)
acc.Hi += mulFold64(in8^(key64_112+seed), in7^(key64_120-seed))
acc.Hi ^= i6 + i7
acc.Lo += mulFold64(i6^(key64_096+seed), i7^(key64_104-seed))
acc.Lo ^= in8 + in7
} // 96
in6, in5 := readU64(p, ui(l)-6*8), readU64(p, ui(l)-5*8)
i4, i5 := readU64(p, 4*8), readU64(p, 5*8)
acc.Hi += mulFold64(in6^(key64_080+seed), in5^(key64_088-seed))
acc.Hi ^= i4 + i5
acc.Lo += mulFold64(i4^(key64_064+seed), i5^(key64_072-seed))
acc.Lo ^= in6 + in5
} // 64
in4, in3 := readU64(p, ui(l)-4*8), readU64(p, ui(l)-3*8)
i2, i3 := readU64(p, 2*8), readU64(p, 3*8)
acc.Hi += mulFold64(in4^(key64_048+seed), in3^(key64_056-seed))
acc.Hi ^= i2 + i3
acc.Lo += mulFold64(i2^(key64_032+seed), i3^(key64_040-seed))
acc.Lo ^= in4 + in3
} // 32
in2, in1 := readU64(p, ui(l)-2*8), readU64(p, ui(l)-1*8)
i0, i1 := readU64(p, 0*8), readU64(p, 1*8)
acc.Hi += mulFold64(in2^(key64_016+seed), in1^(key64_024-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_000+seed), i1^(key64_008-seed))
acc.Lo ^= in2 + in1
acc.Hi, acc.Lo = (acc.Lo*prime64_1)+(acc.Hi*prime64_4)+((u64(l)-seed)*prime64_2), acc.Hi+acc.Lo
acc.Hi = -xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
return acc
case l <= 240:
acc.Lo = u64(l) * prime64_1
{
i0, i1, i2, i3 := readU64(p, 0*8), readU64(p, 1*8), readU64(p, 2*8), readU64(p, 3*8)
acc.Hi += mulFold64(i2^(key64_016+seed), i3^(key64_024-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_000+seed), i1^(key64_008-seed))
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 4*8), readU64(p, 5*8), readU64(p, 6*8), readU64(p, 7*8)
acc.Hi += mulFold64(i2^(key64_048+seed), i3^(key64_056-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_032+seed), i1^(key64_040-seed))
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 8*8), readU64(p, 9*8), readU64(p, 10*8), readU64(p, 11*8)
acc.Hi += mulFold64(i2^(key64_080+seed), i3^(key64_088-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_064+seed), i1^(key64_072-seed))
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 12*8), readU64(p, 13*8), readU64(p, 14*8), readU64(p, 15*8)
acc.Hi += mulFold64(i2^(key64_112+seed), i3^(key64_120-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_096+seed), i1^(key64_104-seed))
acc.Lo ^= i2 + i3
}
// avalanche
acc.Hi = xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
// trailing groups after 128
top := ui(l) &^ 31
for i := ui(4 * 32); i < top; i += 32 {
i0, i1, i2, i3 := readU64(p, i+0), readU64(p, i+8), readU64(p, i+16), readU64(p, i+24)
k0, k1, k2, k3 := readU64(key, i-125)+seed, readU64(key, i-117)-seed, readU64(key, i-109)+seed, readU64(key, i-101)-seed
acc.Hi += mulFold64(i2^k2, i3^k3)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^k0, i1^k1)
acc.Lo ^= i2 + i3
}
// last 32 bytes
{
i0, i1, i2, i3 := readU64(p, ui(l)-32), readU64(p, ui(l)-24), readU64(p, ui(l)-16), readU64(p, ui(l)-8)
seed := 0 - seed
acc.Hi += mulFold64(i0^(key64_119+seed), i1^(key64_127-seed))
acc.Hi ^= i2 + i3
acc.Lo += mulFold64(i2^(key64_103+seed), i3^(key64_111-seed))
acc.Lo ^= i0 + i1
}
acc.Hi, acc.Lo = (acc.Lo*prime64_1)+(acc.Hi*prime64_4)+((u64(l)-seed)*prime64_2), acc.Hi+acc.Lo
acc.Hi = -xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
return acc
default:
acc.Lo = u64(l) * prime64_1
acc.Hi = ^(u64(l) * prime64_2)
secret := key
if seed != 0 {
secret = ptr(&[secretSize]byte{})
initSecret(secret, seed)
}
accs := [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
if hasAVX512 && l >= avx512Switch {
accumAVX512(&accs, p, secret, u64(l))
} else if hasAVX2 {
accumAVX2(&accs, p, secret, u64(l))
} else if hasSSE2 {
accumSSE(&accs, p, secret, u64(l))
} else {
accumScalar(&accs, p, secret, u64(l))
}
// merge accs
const hi_off = 117 - 11
acc.Lo += mulFold64(accs[0]^readU64(secret, 11), accs[1]^readU64(secret, 19))
acc.Hi += mulFold64(accs[0]^readU64(secret, 11+hi_off), accs[1]^readU64(secret, 19+hi_off))
acc.Lo += mulFold64(accs[2]^readU64(secret, 27), accs[3]^readU64(secret, 35))
acc.Hi += mulFold64(accs[2]^readU64(secret, 27+hi_off), accs[3]^readU64(secret, 35+hi_off))
acc.Lo += mulFold64(accs[4]^readU64(secret, 43), accs[5]^readU64(secret, 51))
acc.Hi += mulFold64(accs[4]^readU64(secret, 43+hi_off), accs[5]^readU64(secret, 51+hi_off))
acc.Lo += mulFold64(accs[6]^readU64(secret, 59), accs[7]^readU64(secret, 67))
acc.Hi += mulFold64(accs[6]^readU64(secret, 59+hi_off), accs[7]^readU64(secret, 67+hi_off))
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
}
}

126
vendor/github.com/zeebo/xxh3/hash64.go generated vendored Normal file
View File

@@ -0,0 +1,126 @@
package xxh3
import "math/bits"
// Hash returns the hash of the byte slice.
func Hash(b []byte) uint64 {
return hashAny(*(*str)(ptr(&b)))
}
// Hash returns the hash of the string slice.
func HashString(s string) uint64 {
return hashAny(*(*str)(ptr(&s)))
}
func hashAny(s str) (acc u64) {
p, l := s.p, s.l
switch {
case l <= 16:
switch {
case l > 8: // 9-16
inputlo := readU64(p, 0) ^ (key64_024 ^ key64_032)
inputhi := readU64(p, ui(l)-8) ^ (key64_040 ^ key64_048)
folded := mulFold64(inputlo, inputhi)
return xxh3Avalanche(u64(l) + bits.ReverseBytes64(inputlo) + inputhi + folded)
case l > 3: // 4-8
input1 := readU32(p, 0)
input2 := readU32(p, ui(l)-4)
input64 := u64(input2) + u64(input1)<<32
keyed := input64 ^ (key64_008 ^ key64_016)
return rrmxmx(keyed, u64(l))
case l == 3: // 3
c12 := u64(readU16(p, 0))
c3 := u64(readU8(p, 2))
acc = c12<<16 + c3 + 3<<8
case l > 1: // 2
c12 := u64(readU16(p, 0))
acc = c12*(1<<24+1)>>8 + 2<<8
case l == 1: // 1
c1 := u64(readU8(p, 0))
acc = c1*(1<<24+1<<16+1) + 1<<8
default: // 0
return 0x2d06800538d394c2 // xxh_avalanche(key64_056 ^ key64_064)
}
acc ^= u64(key32_000 ^ key32_004)
return xxhAvalancheSmall(acc)
case l <= 128:
acc = u64(l) * prime64_1
if l > 32 {
if l > 64 {
if l > 96 {
acc += mulFold64(readU64(p, 6*8)^key64_096, readU64(p, 7*8)^key64_104)
acc += mulFold64(readU64(p, ui(l)-8*8)^key64_112, readU64(p, ui(l)-7*8)^key64_120)
} // 96
acc += mulFold64(readU64(p, 4*8)^key64_064, readU64(p, 5*8)^key64_072)
acc += mulFold64(readU64(p, ui(l)-6*8)^key64_080, readU64(p, ui(l)-5*8)^key64_088)
} // 64
acc += mulFold64(readU64(p, 2*8)^key64_032, readU64(p, 3*8)^key64_040)
acc += mulFold64(readU64(p, ui(l)-4*8)^key64_048, readU64(p, ui(l)-3*8)^key64_056)
} // 32
acc += mulFold64(readU64(p, 0*8)^key64_000, readU64(p, 1*8)^key64_008)
acc += mulFold64(readU64(p, ui(l)-2*8)^key64_016, readU64(p, ui(l)-1*8)^key64_024)
return xxh3Avalanche(acc)
case l <= 240:
acc = u64(l) * prime64_1
acc += mulFold64(readU64(p, 0*16+0)^key64_000, readU64(p, 0*16+8)^key64_008)
acc += mulFold64(readU64(p, 1*16+0)^key64_016, readU64(p, 1*16+8)^key64_024)
acc += mulFold64(readU64(p, 2*16+0)^key64_032, readU64(p, 2*16+8)^key64_040)
acc += mulFold64(readU64(p, 3*16+0)^key64_048, readU64(p, 3*16+8)^key64_056)
acc += mulFold64(readU64(p, 4*16+0)^key64_064, readU64(p, 4*16+8)^key64_072)
acc += mulFold64(readU64(p, 5*16+0)^key64_080, readU64(p, 5*16+8)^key64_088)
acc += mulFold64(readU64(p, 6*16+0)^key64_096, readU64(p, 6*16+8)^key64_104)
acc += mulFold64(readU64(p, 7*16+0)^key64_112, readU64(p, 7*16+8)^key64_120)
// avalanche
acc = xxh3Avalanche(acc)
// trailing groups after 128
top := ui(l) &^ 15
for i := ui(8 * 16); i < top; i += 16 {
acc += mulFold64(readU64(p, i+0)^readU64(key, i-125), readU64(p, i+8)^readU64(key, i-117))
}
// last 16 bytes
acc += mulFold64(readU64(p, ui(l)-16)^key64_119, readU64(p, ui(l)-8)^key64_127)
return xxh3Avalanche(acc)
default:
acc = u64(l) * prime64_1
accs := [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
if hasAVX512 && l >= avx512Switch {
accumAVX512(&accs, p, key, u64(l))
} else if hasAVX2 {
accumAVX2(&accs, p, key, u64(l))
} else if hasSSE2 {
accumSSE(&accs, p, key, u64(l))
} else {
accumScalar(&accs, p, key, u64(l))
}
// merge accs
acc += mulFold64(accs[0]^key64_011, accs[1]^key64_019)
acc += mulFold64(accs[2]^key64_027, accs[3]^key64_035)
acc += mulFold64(accs[4]^key64_043, accs[5]^key64_051)
acc += mulFold64(accs[6]^key64_059, accs[7]^key64_067)
return xxh3Avalanche(acc)
}
}

134
vendor/github.com/zeebo/xxh3/hash64_seed.go generated vendored Normal file
View File

@@ -0,0 +1,134 @@
package xxh3
import "math/bits"
// HashSeed returns the hash of the byte slice with given seed.
func HashSeed(b []byte, seed uint64) uint64 {
return hashAnySeed(*(*str)(ptr(&b)), seed)
}
// HashStringSeed returns the hash of the string slice with given seed.
func HashStringSeed(s string, seed uint64) uint64 {
return hashAnySeed(*(*str)(ptr(&s)), seed)
}
func hashAnySeed(s str, seed uint64) (acc u64) {
p, l := s.p, s.l
switch {
case l <= 16:
switch {
case l > 8:
inputlo := readU64(p, 0) ^ (key64_024 ^ key64_032 + seed)
inputhi := readU64(p, ui(l)-8) ^ (key64_040 ^ key64_048 - seed)
folded := mulFold64(inputlo, inputhi)
return xxh3Avalanche(u64(l) + bits.ReverseBytes64(inputlo) + inputhi + folded)
case l > 3:
seed ^= u64(bits.ReverseBytes32(u32(seed))) << 32
input1 := readU32(p, 0)
input2 := readU32(p, ui(l)-4)
input64 := u64(input2) + u64(input1)<<32
keyed := input64 ^ (key64_008 ^ key64_016 - seed)
return rrmxmx(keyed, u64(l))
case l == 3: // 3
c12 := u64(readU16(p, 0))
c3 := u64(readU8(p, 2))
acc = c12<<16 + c3 + 3<<8
case l > 1: // 2
c12 := u64(readU16(p, 0))
acc = c12*(1<<24+1)>>8 + 2<<8
case l == 1: // 1
c1 := u64(readU8(p, 0))
acc = c1*(1<<24+1<<16+1) + 1<<8
default:
return xxhAvalancheSmall(seed ^ key64_056 ^ key64_064)
}
acc ^= u64(key32_000^key32_004) + seed
return xxhAvalancheSmall(acc)
case l <= 128:
acc = u64(l) * prime64_1
if l > 32 {
if l > 64 {
if l > 96 {
acc += mulFold64(readU64(p, 6*8)^(key64_096+seed), readU64(p, 7*8)^(key64_104-seed))
acc += mulFold64(readU64(p, ui(l)-8*8)^(key64_112+seed), readU64(p, ui(l)-7*8)^(key64_120-seed))
} // 96
acc += mulFold64(readU64(p, 4*8)^(key64_064+seed), readU64(p, 5*8)^(key64_072-seed))
acc += mulFold64(readU64(p, ui(l)-6*8)^(key64_080+seed), readU64(p, ui(l)-5*8)^(key64_088-seed))
} // 64
acc += mulFold64(readU64(p, 2*8)^(key64_032+seed), readU64(p, 3*8)^(key64_040-seed))
acc += mulFold64(readU64(p, ui(l)-4*8)^(key64_048+seed), readU64(p, ui(l)-3*8)^(key64_056-seed))
} // 32
acc += mulFold64(readU64(p, 0*8)^(key64_000+seed), readU64(p, 1*8)^(key64_008-seed))
acc += mulFold64(readU64(p, ui(l)-2*8)^(key64_016+seed), readU64(p, ui(l)-1*8)^(key64_024-seed))
return xxh3Avalanche(acc)
case l <= 240:
acc = u64(l) * prime64_1
acc += mulFold64(readU64(p, 0*16+0)^(key64_000+seed), readU64(p, 0*16+8)^(key64_008-seed))
acc += mulFold64(readU64(p, 1*16+0)^(key64_016+seed), readU64(p, 1*16+8)^(key64_024-seed))
acc += mulFold64(readU64(p, 2*16+0)^(key64_032+seed), readU64(p, 2*16+8)^(key64_040-seed))
acc += mulFold64(readU64(p, 3*16+0)^(key64_048+seed), readU64(p, 3*16+8)^(key64_056-seed))
acc += mulFold64(readU64(p, 4*16+0)^(key64_064+seed), readU64(p, 4*16+8)^(key64_072-seed))
acc += mulFold64(readU64(p, 5*16+0)^(key64_080+seed), readU64(p, 5*16+8)^(key64_088-seed))
acc += mulFold64(readU64(p, 6*16+0)^(key64_096+seed), readU64(p, 6*16+8)^(key64_104-seed))
acc += mulFold64(readU64(p, 7*16+0)^(key64_112+seed), readU64(p, 7*16+8)^(key64_120-seed))
// avalanche
acc = xxh3Avalanche(acc)
// trailing groups after 128
top := ui(l) &^ 15
for i := ui(8 * 16); i < top; i += 16 {
acc += mulFold64(readU64(p, i+0)^(readU64(key, i-125)+seed), readU64(p, i+8)^(readU64(key, i-117)-seed))
}
// last 16 bytes
acc += mulFold64(readU64(p, ui(l)-16)^(key64_119+seed), readU64(p, ui(l)-8)^(key64_127-seed))
return xxh3Avalanche(acc)
default:
acc = u64(l) * prime64_1
secret := key
if seed != 0 {
secret = ptr(&[secretSize]byte{})
initSecret(secret, seed)
}
accs := [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
if hasAVX512 && l >= avx512Switch {
accumAVX512(&accs, p, secret, u64(l))
} else if hasAVX2 {
accumAVX2(&accs, p, secret, u64(l))
} else if hasSSE2 {
accumSSE(&accs, p, secret, u64(l))
} else {
accumScalarSeed(&accs, p, secret, u64(l))
}
// merge accs
acc += mulFold64(accs[0]^readU64(secret, 11), accs[1]^readU64(secret, 19))
acc += mulFold64(accs[2]^readU64(secret, 27), accs[3]^readU64(secret, 35))
acc += mulFold64(accs[4]^readU64(secret, 43), accs[5]^readU64(secret, 51))
acc += mulFold64(accs[6]^readU64(secret, 59), accs[7]^readU64(secret, 67))
return xxh3Avalanche(acc)
}
}

239
vendor/github.com/zeebo/xxh3/hasher.go generated vendored Normal file
View File

@@ -0,0 +1,239 @@
package xxh3
import (
"encoding/binary"
"hash"
)
// Hasher implements the hash.Hash interface
type Hasher struct {
acc [8]u64
blk u64
len u64
key ptr
buf [_block + _stripe]byte
seed u64
}
var (
_ hash.Hash = (*Hasher)(nil)
_ hash.Hash64 = (*Hasher)(nil)
)
// New returns a new Hasher that implements the hash.Hash interface.
func New() *Hasher {
return new(Hasher)
}
// NewSeed returns a new Hasher that implements the hash.Hash interface.
func NewSeed(seed uint64) *Hasher {
var h Hasher
h.Reset()
h.seed = seed
h.key = key
// Only initiate once, not on reset.
if seed != 0 {
h.key = ptr(&[secretSize]byte{})
initSecret(h.key, seed)
}
return &h
}
// Reset resets the Hash to its initial state.
func (h *Hasher) Reset() {
h.acc = [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
h.blk = 0
h.len = 0
}
// BlockSize returns the hash's underlying block size.
// The Write method will accept any amount of data, but
// it may operate more efficiently if all writes are a
// multiple of the block size.
func (h *Hasher) BlockSize() int { return _stripe }
// Size returns the number of bytes Sum will return.
func (h *Hasher) Size() int { return 8 }
// Sum appends the current hash to b and returns the resulting slice.
// It does not change the underlying hash state.
func (h *Hasher) Sum(b []byte) []byte {
var tmp [8]byte
binary.BigEndian.PutUint64(tmp[:], h.Sum64())
return append(b, tmp[:]...)
}
// Write adds more data to the running hash.
// It never returns an error.
func (h *Hasher) Write(buf []byte) (int, error) {
h.update(buf)
return len(buf), nil
}
// WriteString adds more data to the running hash.
// It never returns an error.
func (h *Hasher) WriteString(buf string) (int, error) {
h.updateString(buf)
return len(buf), nil
}
func (h *Hasher) update(buf []byte) {
// relies on the data pointer being the first word in the string header
h.updateString(*(*string)(ptr(&buf)))
}
func (h *Hasher) updateString(buf string) {
if h.key == nil {
h.key = key
h.Reset()
}
// On first write, if more than 1 block, process without copy.
for h.len == 0 && len(buf) > len(h.buf) {
if hasAVX2 {
accumBlockAVX2(&h.acc, *(*ptr)(ptr(&buf)), h.key)
} else if hasSSE2 {
accumBlockSSE(&h.acc, *(*ptr)(ptr(&buf)), h.key)
} else {
accumBlockScalar(&h.acc, *(*ptr)(ptr(&buf)), h.key)
}
buf = buf[_block:]
h.blk++
}
for len(buf) > 0 {
if h.len < u64(len(h.buf)) {
n := copy(h.buf[h.len:], buf)
h.len += u64(n)
buf = buf[n:]
continue
}
if hasAVX2 {
accumBlockAVX2(&h.acc, ptr(&h.buf), h.key)
} else if hasSSE2 {
accumBlockSSE(&h.acc, ptr(&h.buf), h.key)
} else {
accumBlockScalar(&h.acc, ptr(&h.buf), h.key)
}
h.blk++
h.len = _stripe
copy(h.buf[:_stripe], h.buf[_block:])
}
}
// Sum64 returns the 64-bit hash of the written data.
func (h *Hasher) Sum64() uint64 {
if h.key == nil {
h.key = key
h.Reset()
}
if h.blk == 0 {
if h.seed == 0 {
return Hash(h.buf[:h.len])
}
return HashSeed(h.buf[:h.len], h.seed)
}
l := h.blk*_block + h.len
acc := l * prime64_1
accs := h.acc
if h.len > 0 {
// We are only ever doing 1 block here, so no avx512.
if hasAVX2 {
accumAVX2(&accs, ptr(&h.buf[0]), h.key, h.len)
} else if hasSSE2 {
accumSSE(&accs, ptr(&h.buf[0]), h.key, h.len)
} else {
accumScalar(&accs, ptr(&h.buf[0]), h.key, h.len)
}
}
if h.seed == 0 {
acc += mulFold64(accs[0]^key64_011, accs[1]^key64_019)
acc += mulFold64(accs[2]^key64_027, accs[3]^key64_035)
acc += mulFold64(accs[4]^key64_043, accs[5]^key64_051)
acc += mulFold64(accs[6]^key64_059, accs[7]^key64_067)
} else {
secret := h.key
acc += mulFold64(accs[0]^readU64(secret, 11), accs[1]^readU64(secret, 19))
acc += mulFold64(accs[2]^readU64(secret, 27), accs[3]^readU64(secret, 35))
acc += mulFold64(accs[4]^readU64(secret, 43), accs[5]^readU64(secret, 51))
acc += mulFold64(accs[6]^readU64(secret, 59), accs[7]^readU64(secret, 67))
}
acc = xxh3Avalanche(acc)
return acc
}
// Sum128 returns the 128-bit hash of the written data.
func (h *Hasher) Sum128() Uint128 {
if h.key == nil {
h.key = key
h.Reset()
}
if h.blk == 0 {
if h.seed == 0 {
return Hash128(h.buf[:h.len])
}
return Hash128Seed(h.buf[:h.len], h.seed)
}
l := h.blk*_block + h.len
acc := Uint128{Lo: l * prime64_1, Hi: ^(l * prime64_2)}
accs := h.acc
if h.len > 0 {
// We are only ever doing 1 block here, so no avx512.
if hasAVX2 {
accumAVX2(&accs, ptr(&h.buf[0]), h.key, h.len)
} else if hasSSE2 {
accumSSE(&accs, ptr(&h.buf[0]), h.key, h.len)
} else {
accumScalar(&accs, ptr(&h.buf[0]), h.key, h.len)
}
}
if h.seed == 0 {
acc.Lo += mulFold64(accs[0]^key64_011, accs[1]^key64_019)
acc.Hi += mulFold64(accs[0]^key64_117, accs[1]^key64_125)
acc.Lo += mulFold64(accs[2]^key64_027, accs[3]^key64_035)
acc.Hi += mulFold64(accs[2]^key64_133, accs[3]^key64_141)
acc.Lo += mulFold64(accs[4]^key64_043, accs[5]^key64_051)
acc.Hi += mulFold64(accs[4]^key64_149, accs[5]^key64_157)
acc.Lo += mulFold64(accs[6]^key64_059, accs[7]^key64_067)
acc.Hi += mulFold64(accs[6]^key64_165, accs[7]^key64_173)
} else {
secret := h.key
const hi_off = 117 - 11
acc.Lo += mulFold64(accs[0]^readU64(secret, 11), accs[1]^readU64(secret, 19))
acc.Hi += mulFold64(accs[0]^readU64(secret, 11+hi_off), accs[1]^readU64(secret, 19+hi_off))
acc.Lo += mulFold64(accs[2]^readU64(secret, 27), accs[3]^readU64(secret, 35))
acc.Hi += mulFold64(accs[2]^readU64(secret, 27+hi_off), accs[3]^readU64(secret, 35+hi_off))
acc.Lo += mulFold64(accs[4]^readU64(secret, 43), accs[5]^readU64(secret, 51))
acc.Hi += mulFold64(accs[4]^readU64(secret, 43+hi_off), accs[5]^readU64(secret, 51+hi_off))
acc.Lo += mulFold64(accs[6]^readU64(secret, 59), accs[7]^readU64(secret, 67))
acc.Hi += mulFold64(accs[6]^readU64(secret, 59+hi_off), accs[7]^readU64(secret, 67+hi_off))
}
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
}

Some files were not shown because too many files have changed in this diff Show More