Bryan Kadzban wrote:
> Bruce Dubbs wrote:
>> I'm trying to write a script to be run in Section 7.2 to initialize
>> 70-persistent-net.rules.  I'm using, as a base, the udev-182 rule
>> 75-persistent-net-generator.rules.
>>
>> I have a problem in that this rule uses a variable SUBSYSTEMS.
>
> Uh oh, that's one thing I was afraid of.  :-(  Might be fixable, but it
> might also be hard.
>
> SUBSYSTEMS is "the SUBSYSTEM of the matching parent device", but the
> concept of a "parent device" is not exposed any obvious way in the sysfs
> tree.  The only way I know of to find it is to udevadm info
> --attribute-walk.
>
> The SUBSYSTEM value for a given device directory is definitely the
> basename of the target of the "subsystem" link; it's just that I don't
> know how to find the parent devices.
>
> Looking at the libudev source (from -180), it appears that the algorithm
> is simpler than I thought, though; it's as follows:
>
> 1. Start with the /sys path given, and resolve symlinks all the way down
> 2. Remove one directory from the end of the path
> 3. If the result of 2 is under /sys/devices, and the directory has a
> "uevent" file present, then finish.
> 4. If the result of 2 is under /sys/devices and the directory does not
> have a "uevent" file present, then goto 2.
> 5. If the result of 2 is not under /sys/devices, and the result is a
> directory, then finish.  (Would be hard for this to fail.)
> 6. If the result of 2 is not under /sys/devices, and the result is not a
> directory, then goto 2.
>
> The result after "finish" is then the next level in the tree.  The
> recursion stops when the code hits the /sys directory.
>
> So on my system, /sys/class/net/eth0 resolves to
> /sys/devices/pci0000:00/0000:00:06.0/0000:05:05.0/net/eth0.  That has a
> uevent file.  The first parent is the "net" directory, which does not
> have one, so the algorithm continues to the "0000:05:05.0" directory.
> That does have a uevent file, so that's next in line.  The 0000:00:06.0
> directory is next, then the pci0000:00 directory.  The "devices"
> directory doesn't have a uevent file, so the next loop iteration is the
> last one (hits /sys), which doesn't find a parent for the pci0000:00
> directory.

What I'm using right now is:

# Ignore Xen virtual interfaces
if [ -e /proc/xen ]; then
   msg="The rules file should not be created in the Xen environment"
   usage
fi

I'm not sure if that is right or not.  Someone with Xen needs to verify.

I also skipped the other SUBSYSTEMS values.  They are just contributing 
to a comment and I don't think that's required.

I did find

NIC=/sys/class/net/eth0
$ basename $(readlink -f $NIC/device/subsystem)
pci

but I'm not sure how robust that is.

I'm going to post a new tarball in a few minutes after I finish some 
testing.  Take a look at that.

   -- Bruce
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to