diff --git a/SOURCES/bondvf.sh b/SOURCES/bondvf.sh new file mode 100644 index 0000000..4aa5369 --- /dev/null +++ b/SOURCES/bondvf.sh @@ -0,0 +1,193 @@ +#!/bin/bash + +# This example script creates bonding network devices based on synthetic NIC +# (the virtual network adapter usually provided by Hyper-V) and the matching +# VF NIC (SRIOV virtual function). So the synthetic NIC and VF NIC can +# function as one network device, and fail over to the synthetic NIC if VF is +# down. +# +# Usage: +# - After configured vSwitch and vNIC with SRIOV, start Linux virtual +# machine (VM) +# - Run this scripts on the VM. It will create configuration files in +# distro specific directory. +# - Reboot the VM, so that the bonding config are enabled. +# +# The config files are DHCP by default. You may edit them if you need to change +# to Static IP or change other settings. +# + +sysdir=/sys/class/net +netvsc_cls={f8615163-df3e-46c5-913f-f2d2f965ed0e} +bondcnt=0 + +# Detect Distro +if [ -f /etc/redhat-release ]; +then + cfgdir=/etc/sysconfig/network-scripts + distro=redhat +elif grep -q 'Ubuntu' /etc/issue +then + cfgdir=/etc/network + distro=ubuntu +elif grep -q 'SUSE' /etc/issue +then + cfgdir=/etc/sysconfig/network + distro=suse +else + echo "Unsupported Distro" + exit 1 +fi + +echo Detected Distro: $distro, or compatible + +# Get a list of ethernet names +list_eth=(`cd $sysdir && ls -d */ | cut -d/ -f1 | grep -v bond`) +eth_cnt=${#list_eth[@]} + +echo List of net devices: + +# Get the MAC addresses +for (( i=0; i < $eth_cnt; i++ )) +do + list_mac[$i]=`cat $sysdir/${list_eth[$i]}/address` + echo ${list_eth[$i]}, ${list_mac[$i]} +done + +# Find NIC with matching MAC +for (( i=0; i < $eth_cnt-1; i++ )) +do + for (( j=i+1; j < $eth_cnt; j++ )) + do + if [ "${list_mac[$i]}" = "${list_mac[$j]}" ] + then + list_match[$i]=${list_eth[$j]} + break + fi + done +done + +function create_eth_cfg_redhat { + local fn=$cfgdir/ifcfg-$1 + + rm -f $fn + echo DEVICE=$1 >>$fn + echo TYPE=Ethernet >>$fn + echo BOOTPROTO=none >>$fn + echo UUID=`uuidgen` >>$fn + echo ONBOOT=yes >>$fn + echo PEERDNS=yes >>$fn + echo IPV6INIT=yes >>$fn + echo MASTER=$2 >>$fn + echo SLAVE=yes >>$fn +} + +function create_eth_cfg_pri_redhat { + create_eth_cfg_redhat $1 $2 +} + +function create_bond_cfg_redhat { + local fn=$cfgdir/ifcfg-$1 + + rm -f $fn + echo DEVICE=$1 >>$fn + echo TYPE=Bond >>$fn + echo BOOTPROTO=dhcp >>$fn + echo UUID=`uuidgen` >>$fn + echo ONBOOT=yes >>$fn + echo PEERDNS=yes >>$fn + echo IPV6INIT=yes >>$fn + echo BONDING_MASTER=yes >>$fn + echo BONDING_OPTS=\"mode=active-backup miimon=100 primary=$2\" >>$fn +} + +function create_eth_cfg_ubuntu { + local fn=$cfgdir/interfaces + + echo $'\n'auto $1 >>$fn + echo iface $1 inet manual >>$fn + echo bond-master $2 >>$fn +} + +function create_eth_cfg_pri_ubuntu { + local fn=$cfgdir/interfaces + + create_eth_cfg_ubuntu $1 $2 + echo bond-primary $1 >>$fn +} + +function create_bond_cfg_ubuntu { + local fn=$cfgdir/interfaces + + echo $'\n'auto $1 >>$fn + echo iface $1 inet dhcp >>$fn + echo bond-mode active-backup >>$fn + echo bond-miimon 100 >>$fn + echo bond-slaves none >>$fn +} + +function create_eth_cfg_suse { + local fn=$cfgdir/ifcfg-$1 + + rm -f $fn + echo BOOTPROTO=none >>$fn + echo STARTMODE=auto >>$fn +} + +function create_eth_cfg_pri_suse { + create_eth_cfg_suse $1 +} + +function create_bond_cfg_suse { + local fn=$cfgdir/ifcfg-$1 + + rm -f $fn + echo BOOTPROTO=dhcp >>$fn + echo STARTMODE=auto >>$fn + echo BONDING_MASTER=yes >>$fn + echo BONDING_SLAVE_0=$2 >>$fn + echo BONDING_SLAVE_1=$3 >>$fn + echo BONDING_MODULE_OPTS=\'mode=active-backup miimon=100 primary=$2\' >>$fn +} + +function create_bond { + local bondname=bond$bondcnt + local primary + local secondary + + local class_id1=`cat $sysdir/$1/device/class_id 2>/dev/null` + local class_id2=`cat $sysdir/$2/device/class_id 2>/dev/null` + + if [ "$class_id1" = "$netvsc_cls" ] + then + primary=$2 + secondary=$1 + elif [ "$class_id2" = "$netvsc_cls" ] + then + primary=$1 + secondary=$2 + else + return 0 + fi + + echo $'\nBond name:' $bondname + + echo configuring $primary + create_eth_cfg_pri_$distro $primary $bondname + + echo configuring $secondary + create_eth_cfg_$distro $secondary $bondname + + echo creating: $bondname with primary slave: $primary + create_bond_cfg_$distro $bondname $primary $secondary + + let bondcnt=bondcnt+1 +} + +for (( i=0; i < $eth_cnt-1; i++ )) +do + if [ -n "${list_match[$i]}" ] + then + create_bond ${list_eth[$i]} ${list_match[$i]} + fi +done diff --git a/SOURCES/hv_kvp_daemon.c b/SOURCES/hv_kvp_daemon.c index 0d9f48e..bc7adb8 100644 --- a/SOURCES/hv_kvp_daemon.c +++ b/SOURCES/hv_kvp_daemon.c @@ -1433,7 +1433,7 @@ int main(int argc, char *argv[]) openlog("KVP", 0, LOG_USER); syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); - kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR); + kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC); if (kvp_fd < 0) { syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s", diff --git a/SOURCES/hv_vss_daemon.c b/SOURCES/hv_vss_daemon.c index 5d51d6f..e082980 100644 --- a/SOURCES/hv_vss_daemon.c +++ b/SOURCES/hv_vss_daemon.c @@ -250,6 +250,9 @@ int main(int argc, char *argv[]) syslog(LOG_ERR, "/etc/fstab and /proc/mounts"); } break; + case VSS_OP_HOT_BACKUP: + syslog(LOG_INFO, "VSS: op=CHECK HOT BACKUP\n"); + break; default: syslog(LOG_ERR, "Illegal op:%d\n", op); } diff --git a/SOURCES/hypervkvpd-0-cloexec_device_file.patch b/SOURCES/hypervkvpd-0-cloexec_device_file.patch deleted file mode 100644 index e10b0d5..0000000 --- a/SOURCES/hypervkvpd-0-cloexec_device_file.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/hv_kvp_daemon.c b/hv_kvp_daemon.c -index 82fb565..123265d 100755 ---- a/hv_kvp_daemon.c -+++ b/hv_kvp_daemon.c -@@ -1430,7 +1430,7 @@ int main(int argc, char *argv[]) - openlog("KVP", 0, LOG_USER); - syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); - -- kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR); -+ kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC); - - if (kvp_fd < 0) { - syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s", diff --git a/SOURCES/lsvmbus b/SOURCES/lsvmbus new file mode 100644 index 0000000..e8fecd6 --- /dev/null +++ b/SOURCES/lsvmbus @@ -0,0 +1,102 @@ +#!/usr/bin/env python + +import os +from optparse import OptionParser + +parser = OptionParser() +parser.add_option("-v", "--verbose", dest="verbose", + help="print verbose messages. Try -vv, -vvv for \ + more verbose messages", action="count") + +(options, args) = parser.parse_args() + +verbose = 0 +if options.verbose is not None: + verbose = options.verbose + +vmbus_sys_path = '/sys/bus/vmbus/devices' +if not os.path.isdir(vmbus_sys_path): + print "%s doesn't exist: exiting..." % vmbus_sys_path + exit(-1) + +vmbus_dev_dict = { + '{0e0b6031-5213-4934-818b-38d90ced39db}' : '[Operating system shutdown]', + '{9527e630-d0ae-497b-adce-e80ab0175caf}' : '[Time Synchronization]', + '{57164f39-9115-4e78-ab55-382f3bd5422d}' : '[Heartbeat]', + '{a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}' : '[Data Exchange]', + '{35fa2e29-ea23-4236-96ae-3a6ebacba440}' : '[Backup (volume checkpoint)]', + '{34d14be3-dee4-41c8-9ae7-6b174977c192}' : '[Guest services]', + '{525074dc-8985-46e2-8057-a307dc18a502}' : '[Dynamic Memory]', + '{cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}' : 'Synthetic mouse', + '{f912ad6d-2b17-48ea-bd65-f927a61c7684}' : 'Synthetic keyboard', + '{da0a7802-e377-4aac-8e77-0558eb1073f8}' : 'Synthetic framebuffer adapter', + '{f8615163-df3e-46c5-913f-f2d2f965ed0e}' : 'Synthetic network adapter', + '{32412632-86cb-44a2-9b5c-50d1417354f5}' : 'Synthetic IDE Controller', + '{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}' : 'Synthetic SCSI Controller', + '{2f9bcc4a-0069-4af3-b76b-6fd0be528cda}' : 'Synthetic fiber channel adapter', + '{8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}' : 'Synthetic RDMA adapter', + '{44c4f61d-4444-4400-9d52-802e27ede19f}' : 'PCI Express pass-through', + '{276aacf4-ac15-426c-98dd-7521ad3f01fe}' : '[Reserved system device]', + '{f8e65716-3cb3-4a06-9a60-1889c5cccab5}' : '[Reserved system device]', + '{3375baf4-9e15-4b30-b765-67acb10d607b}' : '[Reserved system device]', +} + +def get_vmbus_dev_attr(dev_name, attr): + try: + f = open('%s/%s/%s' % (vmbus_sys_path, dev_name, attr), 'r') + lines = f.readlines() + f.close() + except IOError: + lines = [] + + return lines + +class VMBus_Dev: + pass + + +vmbus_dev_list = [] + +for f in os.listdir(vmbus_sys_path): + vmbus_id = get_vmbus_dev_attr(f, 'id')[0].strip() + class_id = get_vmbus_dev_attr(f, 'class_id')[0].strip() + device_id = get_vmbus_dev_attr(f, 'device_id')[0].strip() + dev_desc = vmbus_dev_dict.get(class_id, 'Unknown') + + chn_vp_mapping = get_vmbus_dev_attr(f, 'channel_vp_mapping') + chn_vp_mapping = [c.strip() for c in chn_vp_mapping] + chn_vp_mapping = sorted(chn_vp_mapping, + key = lambda c : int(c.split(':')[0])) + + chn_vp_mapping = ['\tRel_ID=%s, target_cpu=%s' % + (c.split(':')[0], c.split(':')[1]) + for c in chn_vp_mapping] + d = VMBus_Dev() + d.sysfs_path = '%s/%s' % (vmbus_sys_path, f) + d.vmbus_id = vmbus_id + d.class_id = class_id + d.device_id = device_id + d.dev_desc = dev_desc + d.chn_vp_mapping = '\n'.join(chn_vp_mapping) + if d.chn_vp_mapping: + d.chn_vp_mapping += '\n' + + vmbus_dev_list.append(d) + + +vmbus_dev_list = sorted(vmbus_dev_list, key = lambda d : int(d.vmbus_id)) + +format0 = '%2s: %s' +format1 = '%2s: Class_ID = %s - %s\n%s' +format2 = '%2s: Class_ID = %s - %s\n\tDevice_ID = %s\n\tSysfs path: %s\n%s' + +for d in vmbus_dev_list: + if verbose == 0: + print ('VMBUS ID ' + format0) % (d.vmbus_id, d.dev_desc) + elif verbose == 1: + print ('VMBUS ID ' + format1) % \ + (d.vmbus_id, d.class_id, d.dev_desc, d.chn_vp_mapping) + else: + print ('VMBUS ID ' + format2) % \ + (d.vmbus_id, d.class_id, d.dev_desc, \ + d.device_id, d.sysfs_path, d.chn_vp_mapping) diff --git a/SPECS/hyperv-daemons.spec b/SPECS/hyperv-daemons.spec index e9b276b..7167541 100644 --- a/SPECS/hyperv-daemons.spec +++ b/SPECS/hyperv-daemons.spec @@ -5,7 +5,7 @@ # HyperV FCOPY daemon binary name %global hv_fcopy_daemon hypervfcopyd # snapshot version -%global snapver .20160216git +%global snapver .20161211git # use hardened build %global _hardened_build 1 # udev rules prefix @@ -13,50 +13,45 @@ Name: hyperv-daemons Version: 0 -Release: 0.29%{?snapver}%{?dist} +Release: 0.30%{?snapver}%{?dist} Summary: HyperV daemons suite Group: System Environment/Daemons License: GPLv2 URL: http://www.kernel.org -# Source files obtained from kernel upstream 2016-02-16. -# git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git +# Source files obtained from kernel upstream v4.9. +# git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git # The daemon and scripts are located in "master branch - /tools/hv" -# COPYING -> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/plain/COPYING?id=next-20150402 Source0: COPYING # HYPERV KVP DAEMON -# hv_kvp_daemon.c -> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/tools/hv/hv_kvp_daemon.c?id=next-20150402 Source1: hv_kvp_daemon.c -# hv_get_dhcp_info.sh -> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/plain/tools/hv/hv_get_dhcp_info.sh?id=next-20150402 Source2: hv_get_dhcp_info.sh -# hv_get_dns_info.sh -> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/plain/tools/hv/hv_get_dns_info.sh?id=next-20150402 Source3: hv_get_dns_info.sh -# hv_set_ifconfig.sh -> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/plain/tools/hv/hv_set_ifconfig.sh?id=next-20150402 Source4: hv_set_ifconfig.sh Source5: hypervkvpd.service Source6: hypervkvp.rules # HYPERV VSS DAEMON -# hv_vss_daemon.c -> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/plain/tools/hv/hv_vss_daemon.c?id=next-20150402 Source100: hv_vss_daemon.c Source101: hypervvssd.service Source102: hypervvss.rules # HYPERV FCOPY DAEMON -# hv_fcopy_daemon.c -> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/plain/tools/hv/hv_fcopy_daemon.c?id=next-20150402 Source200: hv_fcopy_daemon.c Source201: hypervfcopyd.service Source202: hypervfcopy.rules +# HYPERV TOOLS +Source301: lsvmbus +Source302: bondvf.sh + # HYPERV KVP DAEMON # Correct paths to external scripts ("/usr/libexec/hypervkvpd"). Patch0: hypervkvpd-0-corrected_paths_to_external_scripts.patch # rhbz#872566 Patch1: hypervkvpd-0-long_file_names_from_readdir.patch -# rhbz#1347659 -Patch2: hypervkvpd-0-cloexec_device_file.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) # HyperV is available only on x86 architectures @@ -133,6 +128,13 @@ BuildArch: noarch %description license Contains license of the HyperV daemons suite. +%package -n hyperv-tools +Summary: Tools for Hyper-V guests +Group: Applications/System +BuildArch: noarch + +%description -n hyperv-tools +Contains tools and scripts useful for Hyper-V guests. %prep %setup -Tc @@ -152,7 +154,6 @@ cp -pvL %{SOURCE201} hypervfcopyd.service %patch0 -p1 -b .external_scripts %patch1 -p1 -b .long_names -%patch2 -p1 -b .close_exec %build # HYPERV KVP DAEMON @@ -211,9 +212,14 @@ install -p -m 0755 %{SOURCE4} %{buildroot}%{_libexecdir}/%{hv_kvp_daemon}/hv_set # Directory for pool files mkdir -p %{buildroot}%{_sharedstatedir}/hyperv +# Tools +install -p -m 0755 %{SOURCE301} %{buildroot}%{_sbindir}/ + +mkdir -p %{buildroot}%{_datarootdir}/hyperv-tools/ +install -p -m 0755 %{SOURCE302} %{buildroot}%{_datarootdir}/hyperv-tools/ %post -n hypervkvpd -if [ $1 > 1 ] ; then +if [ $1 -gt 1 ] ; then # Upgrade systemctl --no-reload disable hypervkvpd.service >/dev/null 2>&1 || : fi @@ -231,7 +237,7 @@ fi %post -n hypervvssd -if [ $1 > 1 ] ; then +if [ $1 -gt 1 ] ; then # Upgrade systemctl --no-reload disable hypervvssd.service >/dev/null 2>&1 || : fi @@ -244,7 +250,7 @@ fi %post -n hypervfcopyd -if [ $1 > 1 ] ; then +if [ $1 -gt 1 ] ; then # Upgrade systemctl --no-reload disable hypervfcopyd.service >/dev/null 2>&1 || : fi @@ -280,7 +286,16 @@ fi %files license %doc COPYING +%files -n hyperv-tools +%{_sbindir}/lsvmbus +%{_datarootdir}/hyperv-tools + %changelog +* Thu Jan 19 2017 Vitaly Kuznetsov - 0-0.30.20161211git +- Use '-gt' instead of '>' to do the right comparison (#1414822) +- hyperv-tools subpackage added (#1378710) +- Update to upstream v4.9 (#1406397) + * Tue Aug 16 2016 Vitaly Kuznetsov - 0-0.29.20150216git - Switch units to udev-only activation (#1367240)