The sysfs tip is certainly also simpler than parsing values out of the udev
configuration.
Only caveat to add is that:
# grep "^VM.*Name:" /proc/sysinfo
should be
# awk '/^VM00 Name:/{print $3}' /proc/sysinfo
...in order to pick out just the appropriate field, and avoid picking up a
second line for the "VM01" entry that appears when you're on a Linux running
under a second-level VM. Like this:
# grep "^VM.*Name:" /proc/sysinfo
VM00 Name: GUEST123
VM01 Name: VM321
vs.
# awk '/^VM00 Name:/{print $3}' /proc/sysinfo
GUEST123
...but I had also forgotten that the VSwitch name for an active NIC will
also show in the output of `vmcp q v nic`. So the script can work without
looking at the user directory entry. Like this:
#!/bin/bash
### BEGIN SCRIPT: getswitchname ###
function getVSwitch {
local iface=$1
local userid=$(awk '/^VM00 Name:/{print $3}' /proc/sysinfo)
local vdev=$(readlink -f /sys/class/net/${iface}/device)
vdev=${vdev##*.}
# Get the line after the line containing the appropriate
# vdev, and pull the vswitch name from the second field
# following the word "VSWITCH".
vmcp query virtual nic |
sed -n '/^Adapter '${vdev}'/{n;p;}' |
sed -rn 's/.*VSWITCH:\s+\S+\s+(\S*).*/\1/p'
}
getVSwitch $1
### END OF SCRIPT ###
...though whether the "live" or "in directory" configuration of that NIC is
desired would depend on the user's intentions in the fringe case that the
two differ.
On Thu, Jan 20, 2011 at 12:53 PM, Steffen Maier <[email protected]>wrote:
> Not encouraging to make procedures dependent on vswitch names,
> just sharing info on how to obtain base info within Linux itself.
>
>
> On 01/19/2011 09:02 PM, Christian Paro wrote:
>
>> #!/bin/bash
>> ### BEGIN SCRIPT: getswitchname ###
>> function getVSwitch {
>> local iface=$1
>> local userid=$(vmcp q userid)
>>
>
> # grep "^VM.*Name:" /proc/sysinfo
> VM00 Name: LNXUSR1
>
> might save a hypercall by not using vmcp
>
>
> local vdev=$(sed -rn
>> 's/^SUBSYSTEM.*KERNELS=="0.0.([0-9a-f]{4})",.*NAME="'${iface}'"$/\1/pI' \
>> /etc/udev/rules.d/70-persistent-net.rules)
>>
>
> This file might have been edited by an administrator meanwhile and no
> longer reflect the actual system configuration. You can get the latter
> directly from sysfs to obtain the mapping between network interface name and
> device bus IDs (devnos) on s390:
>
> local vdev=$(readlink -f /sys/class/net/eth0/device)
> vdev=${vdev##*.}
>
> Based on:
> # ll /sys/class/net/eth0/device
> lrwxrwxrwx. 1 root root 0 Jan 20 18:33 /sys/class/net/eth0/device ->
> ../../../0.0.f5f0
>
>
> catdirectoryentry --mergeprofile ${userid%% *} | sed -n
>> 's/^NICDEF\s'${vdev}'.*SYSTEM //p'
>> }
>>
>> getVSwitch $1
>>
>
> ...where `catdirectoryentry` is a script I wrote for a project I'm current
>> working on, which pulls the directory entry for a guest, expands all
>>
>
> Steffen
>
> Linux on System z Development
>
> IBM Deutschland Research & Development GmbH
> Vorsitzender des Aufsichtsrats: Martin Jetter
> Geschäftsführung: Dirk Wittkopp
> Sitz der Gesellschaft: Böblingen
> Registergericht: Amtsgericht Stuttgart, HRB 243294
>
>
> ----------------------------------------------------------------------
> For LINUX-390 subscribe / signoff / archive access instructions,
> send email to [email protected] with the message: INFO LINUX-390 or
> visit
> http://www.marist.edu/htbin/wlvindex?LINUX-390
> ----------------------------------------------------------------------
> For more information on Linux on System z, visit
> http://wiki.linuxvm.org/
>
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
----------------------------------------------------------------------
For more information on Linux on System z, visit
http://wiki.linuxvm.org/