1 Star 0 Fork 101

huanglg/systemd

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
net-set-sriov-names 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
hexiaowen 提交于 2019-09-30 11:17 . Package init
#!/bin/bash -e
#
# This script is run to rename virtual interfaces
#
if [ -n "$UDEV_LOG" ]; then
if [ "$UDEV_LOG" -ge 7 ]; then
set -x
fi
fi
# according to dev_new_index(), ifindex is within [1, INT_MAX]
int_max=$(/usr/bin/getconf INT_MAX)
ifindex_before() {
a=$1
b=$2
((0 < (b - a) && (b - a) < int_max / 2 ||
-1 * int_max < (b - a) && (b - a) < -1 * int_max / 2))
}
rename_interface() {
local src_net=$1
local dest_net=$2
local err=0
/sbin/ip link set dev $src_net down
/sbin/ip link set dev $src_net name $dest_net
}
if [ -z "$INTERFACE" ]; then
echo "missing \$INTERFACE" >&2
exit 1
fi
if [ -e "/sys/class/net/$INTERFACE/device/physfn" ]; then
pf=$(ls -1 "/sys/class/net/$INTERFACE/device/physfn/net")
if [ $(echo "$pf" | wc -l) -ne 1 ]; then
echo "too many pf's" >&2
exit 1
fi
read vfindex < "/sys/class/net/$INTERFACE/ifindex"
read pfindex < "/sys/class/net/$pf/ifindex"
if ifindex_before $pfindex $vfindex; then
bus_info=$(basename $(readlink "/sys/class/net/$INTERFACE/device"))
for virtfn in "/sys/class/net/$pf/device/"virtfn*; do
if [ "$(basename $(readlink "$virtfn"))" = "$bus_info" ]; then
vfnum=$(basename "$virtfn")
vfnum=${vfnum#virtfn}
echo "INTERFACE_NEW=$pf.vf$vfnum"
exit 0
fi
done
fi
fi
read pfindex < "/sys/class/net/$INTERFACE/ifindex"
shopt -s nullglob
for virtfn in "/sys/class/net/$INTERFACE/device/"virtfn*; do
vf=$(ls -1 "$virtfn/net")
if [ $(echo "$vf" | wc -l) -ne 1 ]; then
echo "too many vf's" >&2
exit 1
fi
read vfindex < "/sys/class/net/$vf/ifindex"
if ifindex_before $vfindex $pfindex; then
vfnum=$(basename "$virtfn")
vfnum=${vfnum#virtfn}
if [ "$INTERFACE_NEW" ]; then
new_name=$INTERFACE_NEW
else
new_name=$INTERFACE
fi
new_name="$new_name.vf$vfnum"
if [ "$vf" != "$new_name" ]; then
rename_interface "$vf" "$new_name"
fi
fi
done
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huanglg2022/systemd.git
[email protected]:huanglg2022/systemd.git
huanglg2022
systemd
systemd
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385