Re: [systemd-devel] udev rules environment variable

2013-12-18 Thread Robert Milasan
On Tue, 17 Dec 2013 23:14:12 +0400
Andrey Borzenkov arvidj...@gmail.com wrote:

 В Tue, 17 Dec 2013 19:59:47 +0100
 Kay Sievers k...@vrfy.org пишет:
 
  
  Works just fine here as expected, it's probably something in your
  setup.
  
 
 No, it *your* default interface renaming :)
 
  Kay
  
  # head -2 /etc/udev/rules.d/10-local.rules
  ACTION==add, SUBSYSTEM==net, ENV{test_device}=1
  ACTION==remove, SUBSYSTEM==net, ENV{test_device}==1,
  RUN+=/bin/logger $env{test_device}
  
  # udevadm monitor -p -u 
  
  # modprobe dummy
 
 dummy is not renamed.
 
 KERNEL[80247.266050]
 add  /devices/pci:00/:00:03.0/net/eth0 (net) ACTION=add
 DEVPATH=/devices/pci:00/:00:03.0/net/eth0
 IFINDEX=8
 INTERFACE=eth0
 SEQNUM=1448
 SUBSYSTEM=net
 
 KERNEL[80247.295702]
 move /devices/pci:00/:00:03.0/net/ens3 (net) ACTION=move
 DEVPATH=/devices/pci:00/:00:03.0/net/ens3
 DEVPATH_OLD=/devices/pci:00/:00:03.0/net/eth0
 IFINDEX=8
 INTERFACE=ens3
 SEQNUM=1452
 SUBSYSTEM=net
 
 UDEV  [80256.247824]
 add  /devices/pci:00/:00:03.0/net/ens3 (net) ACTION=add
 DEVPATH=/devices/pci:00/:00:03.0/net/ens3
 ID_BUS=pci
 ...
 INTERFACE=ens3
 INTERFACE_OLD=eth0
 SEQNUM=1448
 ...
 test_device=1
 
 UDEV  [80256.274447]
 move /devices/pci:00/:00:03.0/net/ens3 (net) ACTION=move
 ...
 INTERFACE=ens3
 SEQNUM=1452
 ...
 TAGS=:systemd:
 UDEV_LOG=7
 
 Oops. test_device is lost. 
 

So basically it doesn't really work ?!

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmila...@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-18 Thread Robert Milasan
On Wed, 18 Dec 2013 02:52:01 +0100
Kay Sievers k...@vrfy.org wrote:

 On Tue, Dec 17, 2013 at 8:14 PM, Andrey Borzenkov
 arvidj...@gmail.com wrote:
  В Tue, 17 Dec 2013 19:59:47 +0100 Kay Sievers k...@vrfy.org пишет:
 
  # modprobe dummy
 
  dummy is not renamed.
 
  UDEV  [80256.274447]
  move /devices/pci:00/:00:03.0/net/ens3 (net) ACTION=move
  ...
  INTERFACE=ens3
  SEQNUM=1452
  ...
  TAGS=:systemd:
  UDEV_LOG=7
 
  Oops. test_device is lost.
 
 Adding something like:
   ACTION!=add|remove, IMPORT{db}=test_device
 
 might make it work.
 
 Kay
 

One more question: Where exactly is 'test_device' variable saved, I
mean physically? I suppose it should be in /run/udev/data or something
similar no?

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmila...@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-18 Thread Kay Sievers
On Wed, Dec 18, 2013 at 2:07 PM, Robert Milasan rmila...@suse.com wrote:

 One more question: Where exactly is 'test_device' variable saved, I
 mean physically? I suppose it should be in /run/udev/data or something
 similar no?

Yes, in the udev database at /run/udev/data/device ID.

It's plain text, just look into it. The file names start with b ==
block, c == char, n == network devices, ...

Kay
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-18 Thread Robert Milasan
On Wed, 18 Dec 2013 14:39:57 +0100
Kay Sievers k...@vrfy.org wrote:

 On Wed, Dec 18, 2013 at 2:07 PM, Robert Milasan rmila...@suse.com
 wrote:
 
  One more question: Where exactly is 'test_device' variable saved, I
  mean physically? I suppose it should be in /run/udev/data or
  something similar no?
 
 Yes, in the udev database at /run/udev/data/device ID.
 
 It's plain text, just look into it. The file names start with b ==
 block, c == char, n == network devices, ...
 
 Kay
 

Good to know coz that means it doesn't work :)

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmila...@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-18 Thread Andrey Borzenkov
В Wed, 18 Dec 2013 13:36:52 +0100
Robert Milasan rmila...@suse.com пишет:

 
 So basically it doesn't really work ?!
 

It does not always work for net device as it looks like.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-18 Thread Andrey Borzenkov
В Wed, 18 Dec 2013 02:52:01 +0100
Kay Sievers k...@vrfy.org пишет:

 On Tue, Dec 17, 2013 at 8:14 PM, Andrey Borzenkov arvidj...@gmail.com wrote:
  В Tue, 17 Dec 2013 19:59:47 +0100 Kay Sievers k...@vrfy.org пишет:
 
  # modprobe dummy
 
  dummy is not renamed.
 
  UDEV  [80256.274447] move /devices/pci:00/:00:03.0/net/ens3 
  (net)
  ACTION=move
  ...
  INTERFACE=ens3
  SEQNUM=1452
  ...
  TAGS=:systemd:
  UDEV_LOG=7
 
  Oops. test_device is lost.
 
 Adding something like:
   ACTION!=add|remove, IMPORT{db}=test_device
 
 might make it work.
 

But it does not really scale. It needs to be done individually for every
single prperty. E.g. INTERFACE_OLD added by udev itself is lost as well.

And if even you did not remember this behavior what chances are that
others will?

For move event the only thing that changes is interface name. From
the udev pov not even path to database is changed (IFINDEX is the
same). So I think udev should import all existing properties by default
because this is really the same device with the same properties (as
opposed to change even where properties are not known in advance).
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Kay Sievers
On Tue, Dec 17, 2013 at 8:56 AM, Hannes Reinecke h...@suse.de wrote:
 On 12/17/2013 08:52 AM, Robert Milasan wrote:
 Hello,
   got a small question about creating a rule, like this:

 ACTION==add, , ENV{test_device}=1

 ACTION==remove, , ENV{test_device}==1,
 RUN+=/path/to/some/script

 Does udev save test_device variable someplace and then it can be used
 later on, when have ACTION==remove ?

 Typically not.

There is a standard REMOVE_CMD in 95-udev-late.rules to use for this

All variables are stored in the database and are contained in the
remove event, without the need to be added or queried. Sysfs though
is not available, all of it is gone at remove.

 I would be using external tools for that, like 'collect'

That is needed to sync stuff across multiple devices, not for a single
one, right?

 Might be biased, though, what with me having written it ...

 And the alternative of querying the udev database from within an
 udev event is just plain ugly and prone to races.

That happens automatically, it's just part of the remove environment.

Kay
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Hannes Reinecke
On 12/17/2013 11:52 AM, Kay Sievers wrote:
 On Tue, Dec 17, 2013 at 8:56 AM, Hannes Reinecke h...@suse.de wrote:
 On 12/17/2013 08:52 AM, Robert Milasan wrote:
 Hello,
   got a small question about creating a rule, like this:

 ACTION==add, , ENV{test_device}=1

 ACTION==remove, , ENV{test_device}==1,
 RUN+=/path/to/some/script

 Does udev save test_device variable someplace and then it can be used
 later on, when have ACTION==remove ?
 
 Typically not.
 
 There is a standard REMOVE_CMD in 95-udev-late.rules to use for this
 
 All variables are stored in the database and are contained in the
 remove event, without the need to be added or queried. Sysfs though
 is not available, all of it is gone at remove.
 
Ah.

Curious.

So 'remove' contains the environment variables set from the 'add' event?

What about the 'change' event?

I would have thought the same rule applies to this one, but
experience shows that 'change' events have to generate the same
environment variables as the 'add' event.
Otherwise unexpected results happen ...

So why are the environment variables / db entries not merged
into the 'change' environment?

Cheers,

Hannes
-- 
Dr. Hannes Reinecke   zSeries  Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Kay Sievers
On Tue, Dec 17, 2013 at 11:58 AM, Hannes Reinecke h...@suse.de wrote:
 On 12/17/2013 11:52 AM, Kay Sievers wrote:
 On Tue, Dec 17, 2013 at 8:56 AM, Hannes Reinecke h...@suse.de wrote:
 On 12/17/2013 08:52 AM, Robert Milasan wrote:
 Hello,
   got a small question about creating a rule, like this:

 ACTION==add, , ENV{test_device}=1

 ACTION==remove, , ENV{test_device}==1,
 RUN+=/path/to/some/script

 Does udev save test_device variable someplace and then it can be used
 later on, when have ACTION==remove ?

 Typically not.

 There is a standard REMOVE_CMD in 95-udev-late.rules to use for this

 All variables are stored in the database and are contained in the
 remove event, without the need to be added or queried. Sysfs though
 is not available, all of it is gone at remove.

 So 'remove' contains the environment variables set from the 'add' event?

Yes.

 What about the 'change' event?

No.

 I would have thought the same rule applies to this one, but
 experience shows that 'change' events have to generate the same
 environment variables as the 'add' event.
 Otherwise unexpected results happen ...

 So why are the environment variables / db entries not merged
 into the 'change' environment?

First of all, the logic at remove is older than change events even
existed in the kernel. :)

But it actually makes some sense that way. Remove is the death of
the device the last event in this life-cycle, so we can add everything
we know and it will not cause any harm or will leak. Also there is no
other data accessible anymore, sysfs is gone, so we need something to
match against.

Change on the other hand would leak the old state into the new
device representation and things like symlinks would never be removed
unless the variable is explicitly unset. Also sysfs is there as it was
at add, we can (and should) just do the same stuff again.

There is IMPORT{db} for change events to explicitly carry specific
variables forward from the old device to the new one during change,
by default all is gone.

Kay
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Robert Milasan
On Tue, 17 Dec 2013 11:52:15 +0100
Kay Sievers k...@vrfy.org wrote:

 On Tue, Dec 17, 2013 at 8:56 AM, Hannes Reinecke h...@suse.de wrote:
  On 12/17/2013 08:52 AM, Robert Milasan wrote:
  Hello,
got a small question about creating a rule, like this:
 
  ACTION==add, , ENV{test_device}=1
 
  ACTION==remove, , ENV{test_device}==1,
  RUN+=/path/to/some/script
 
  Does udev save test_device variable someplace and then it can be
  used later on, when have ACTION==remove ?
 
  Typically not.
 
 There is a standard REMOVE_CMD in 95-udev-late.rules to use for this
 
 All variables are stored in the database and are contained in the
 remove event, without the need to be added or queried. Sysfs though
 is not available, all of it is gone at remove.
 
  I would be using external tools for that, like 'collect'
 
 That is needed to sync stuff across multiple devices, not for a single
 one, right?
 
  Might be biased, though, what with me having written it ...
 
  And the alternative of querying the udev database from within an
  udev event is just plain ugly and prone to races.
 
 That happens automatically, it's just part of the remove
 environment.
 
 Kay
 ___
 systemd-devel mailing list
 systemd-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/systemd-devel
 

I have this rule as a test, but doesn't do squat (meaning it doesnt
work) :)

ACTION==add, SUBSYSTEM==net, KERNEL==?*, ENV{test_device}=1

ACTION==remove, SUBSYSTEM==net, KERNEL==?*, ENV{test_device}==1, 
RUN+=/bin/sh -c 'echo test_device  /tmp/test_device.log'


-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmila...@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Martin Pitt
Robert Milasan [2013-12-17 12:44 +0100]:
 I have this rule as a test, but doesn't do squat (meaning it doesnt
 work) :)
 
 ACTION==add, SUBSYSTEM==net, KERNEL==?*, ENV{test_device}=1
 
 ACTION==remove, SUBSYSTEM==net, KERNEL==?*, ENV{test_device}==1, 
 RUN+=/bin/sh -c 'echo test_device  /tmp/test_device.log'

Drop the KERNEL== bits. Network devices don't have a /dev/... device
node in Linux, so KERNEL will never be set for those.

Martin
-- 
Martin Pitt| http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Robert Milasan
On Tue, 17 Dec 2013 13:54:34 +0100
Martin Pitt martin.p...@ubuntu.com wrote:

 Robert Milasan [2013-12-17 12:44 +0100]:
  I have this rule as a test, but doesn't do squat (meaning it doesnt
  work) :)
  
  ACTION==add, SUBSYSTEM==net, KERNEL==?*, ENV{test_device}=1
  
  ACTION==remove, SUBSYSTEM==net, KERNEL==?*,
  ENV{test_device}==1, RUN+=/bin/sh -c 'echo test_device
   /tmp/test_device.log'
 
 Drop the KERNEL== bits. Network devices don't have a /dev/... device
 node in Linux, so KERNEL will never be set for those.
 
 Martin

Even without the KERNEL== doesn't seem to work:

I'm testing this by first removing the network device (ex. rmmod
e1000), so I can have first an ADD event and then a REMOVE event, by
removing again the module, so:

rmmod e1000 (remove first)
modprobe e1000 (ADD event, set the test_device var to 1)
rmmod e1000 (REMOVE event, get the test_device value)

This doesn't seem to work, or at least it looks like that.

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmila...@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Kay Sievers
On Tue, Dec 17, 2013 at 2:05 PM, Robert Milasan rmila...@suse.com wrote:
 On Tue, 17 Dec 2013 13:54:34 +0100
 Martin Pitt martin.p...@ubuntu.com wrote:

 Robert Milasan [2013-12-17 12:44 +0100]:
  I have this rule as a test, but doesn't do squat (meaning it doesnt
  work) :)
 
  ACTION==add, SUBSYSTEM==net, KERNEL==?*, ENV{test_device}=1
 
  ACTION==remove, SUBSYSTEM==net, KERNEL==?*,
  ENV{test_device}==1, RUN+=/bin/sh -c 'echo test_device
   /tmp/test_device.log'

 Drop the KERNEL== bits. Network devices don't have a /dev/... device
 node in Linux, so KERNEL will never be set for those.

KERNEL is the device name in /sys, without the leading path. It is in
almost all cases also the name in /dev, but there are some
differences. And right, it is always set, there is never a point to do
such a match.

 Even without the KERNEL== doesn't seem to work:

It's pointless to match that, so it should not make a difference.

 I'm testing this by first removing the network device (ex. rmmod
 e1000), so I can have first an ADD event and then a REMOVE event, by
 removing again the module, so:

 rmmod e1000 (remove first)
 modprobe e1000 (ADD event, set the test_device var to 1)
 rmmod e1000 (REMOVE event, get the test_device value)

 This doesn't seem to work, or at least it looks like that.

How old is your udev? You are not possibly talking about years old
versions, right?

Kay
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Andrey Borzenkov
В Tue, 17 Dec 2013 14:05:56 +0100
Robert Milasan rmila...@suse.com пишет:

 On Tue, 17 Dec 2013 13:54:34 +0100
 Martin Pitt martin.p...@ubuntu.com wrote:
 
  Robert Milasan [2013-12-17 12:44 +0100]:
   I have this rule as a test, but doesn't do squat (meaning it doesnt
   work) :)
   
   ACTION==add, SUBSYSTEM==net, KERNEL==?*, ENV{test_device}=1
   
   ACTION==remove, SUBSYSTEM==net, KERNEL==?*,
   ENV{test_device}==1, RUN+=/bin/sh -c 'echo test_device
/tmp/test_device.log'
  
  Drop the KERNEL== bits. Network devices don't have a /dev/... device
  node in Linux, so KERNEL will never be set for those.
  
  Martin
 
 Even without the KERNEL== doesn't seem to work:
 
 I'm testing this by first removing the network device (ex. rmmod
 e1000), so I can have first an ADD event and then a REMOVE event, by
 removing again the module, so:
 
 rmmod e1000 (remove first)
 modprobe e1000 (ADD event, set the test_device var to 1)

You miss MOVE event ... as was explained it does not import existing
environment by default ...

 rmmod e1000 (REMOVE event, get the test_device value)
 
 This doesn't seem to work, or at least it looks like that.
 

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Robert Milasan
On Tue, 17 Dec 2013 17:36:21 +0100
Kay Sievers k...@vrfy.org wrote:

 On Tue, Dec 17, 2013 at 2:05 PM, Robert Milasan rmila...@suse.com
 wrote:
  On Tue, 17 Dec 2013 13:54:34 +0100
  Martin Pitt martin.p...@ubuntu.com wrote:
 
  Robert Milasan [2013-12-17 12:44 +0100]:
   I have this rule as a test, but doesn't do squat (meaning it
   doesnt work) :)
  
   ACTION==add, SUBSYSTEM==net, KERNEL==?*,
   ENV{test_device}=1
  
   ACTION==remove, SUBSYSTEM==net, KERNEL==?*,
   ENV{test_device}==1, RUN+=/bin/sh -c 'echo test_device
/tmp/test_device.log'
 
  Drop the KERNEL== bits. Network devices don't have a /dev/...
  device node in Linux, so KERNEL will never be set for those.
 
 KERNEL is the device name in /sys, without the leading path. It is in
 almost all cases also the name in /dev, but there are some
 differences. And right, it is always set, there is never a point to do
 such a match.
 
  Even without the KERNEL== doesn't seem to work:
 
 It's pointless to match that, so it should not make a difference.
 
  I'm testing this by first removing the network device (ex. rmmod
  e1000), so I can have first an ADD event and then a REMOVE event, by
  removing again the module, so:
 
  rmmod e1000 (remove first)
  modprobe e1000 (ADD event, set the test_device var to 1)
  rmmod e1000 (REMOVE event, get the test_device value)
 
  This doesn't seem to work, or at least it looks like that.
 
 How old is your udev? You are not possibly talking about years old
 versions, right?
 
 Kay
 

The tests are run using udev 208 (systemd 208).

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmila...@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Andrey Borzenkov
В Tue, 17 Dec 2013 19:59:47 +0100
Kay Sievers k...@vrfy.org пишет:

 
 Works just fine here as expected, it's probably something in your setup.
 

No, it *your* default interface renaming :)

 Kay
 
 # head -2 /etc/udev/rules.d/10-local.rules
 ACTION==add, SUBSYSTEM==net, ENV{test_device}=1
 ACTION==remove, SUBSYSTEM==net, ENV{test_device}==1,
 RUN+=/bin/logger $env{test_device}
 
 # udevadm monitor -p -u 
 
 # modprobe dummy

dummy is not renamed.

KERNEL[80247.266050] add  /devices/pci:00/:00:03.0/net/eth0 (net)
ACTION=add
DEVPATH=/devices/pci:00/:00:03.0/net/eth0
IFINDEX=8
INTERFACE=eth0
SEQNUM=1448
SUBSYSTEM=net

KERNEL[80247.295702] move /devices/pci:00/:00:03.0/net/ens3 (net)
ACTION=move
DEVPATH=/devices/pci:00/:00:03.0/net/ens3
DEVPATH_OLD=/devices/pci:00/:00:03.0/net/eth0
IFINDEX=8
INTERFACE=ens3
SEQNUM=1452
SUBSYSTEM=net

UDEV  [80256.247824] add  /devices/pci:00/:00:03.0/net/ens3 (net)
ACTION=add
DEVPATH=/devices/pci:00/:00:03.0/net/ens3
ID_BUS=pci
...
INTERFACE=ens3
INTERFACE_OLD=eth0
SEQNUM=1448
...
test_device=1

UDEV  [80256.274447] move /devices/pci:00/:00:03.0/net/ens3 (net)
ACTION=move
...
INTERFACE=ens3
SEQNUM=1452
...
TAGS=:systemd:
UDEV_LOG=7

Oops. test_device is lost. 
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Kay Sievers
On Tue, Dec 17, 2013 at 6:57 PM, Robert Milasan rmila...@suse.com wrote:
 On Tue, 17 Dec 2013 17:36:21 +0100
 Kay Sievers k...@vrfy.org wrote:

 On Tue, Dec 17, 2013 at 2:05 PM, Robert Milasan rmila...@suse.com
 wrote:
  On Tue, 17 Dec 2013 13:54:34 +0100
  Martin Pitt martin.p...@ubuntu.com wrote:
 
  Robert Milasan [2013-12-17 12:44 +0100]:
   I have this rule as a test, but doesn't do squat (meaning it
   doesnt work) :)
  
   ACTION==add, SUBSYSTEM==net, KERNEL==?*,
   ENV{test_device}=1
  
   ACTION==remove, SUBSYSTEM==net, KERNEL==?*,
   ENV{test_device}==1, RUN+=/bin/sh -c 'echo test_device
/tmp/test_device.log'
 
  Drop the KERNEL== bits. Network devices don't have a /dev/...
  device node in Linux, so KERNEL will never be set for those.

 KERNEL is the device name in /sys, without the leading path. It is in
 almost all cases also the name in /dev, but there are some
 differences. And right, it is always set, there is never a point to do
 such a match.

  Even without the KERNEL== doesn't seem to work:

 It's pointless to match that, so it should not make a difference.

  I'm testing this by first removing the network device (ex. rmmod
  e1000), so I can have first an ADD event and then a REMOVE event, by
  removing again the module, so:
 
  rmmod e1000 (remove first)
  modprobe e1000 (ADD event, set the test_device var to 1)
  rmmod e1000 (REMOVE event, get the test_device value)
 
  This doesn't seem to work, or at least it looks like that.

 How old is your udev? You are not possibly talking about years old
 versions, right?

 Kay


 The tests are run using udev 208 (systemd 208).

Works just fine here as expected, it's probably something in your setup.

Kay

# head -2 /etc/udev/rules.d/10-local.rules
ACTION==add, SUBSYSTEM==net, ENV{test_device}=1
ACTION==remove, SUBSYSTEM==net, ENV{test_device}==1,
RUN+=/bin/logger $env{test_device}

# udevadm monitor -p -u 

# modprobe dummy
UDEV  [58102.666415] add  /devices/virtual/net/dummy0 (net)
ACTION=add
DEVPATH=/devices/virtual/net/dummy0
IFINDEX=5
INTERFACE=dummy0
SEQNUM=2591
SUBSYSTEM=net
SYSTEMD_ALIAS=/sys/subsystem/net/devices/dummy0
TAGS=:systemd:
USEC_INITIALIZED=102664557
test_device=1

[root@lon systemd]# rmmod dummy
UDEV  [58110.298302] remove   /devices/virtual/net/dummy0 (net)
ACTION=remove
DEVPATH=/devices/virtual/net/dummy0
IFINDEX=5
INTERFACE=dummy0
SEQNUM=2596
SUBSYSTEM=net
SYSTEMD_ALIAS=/sys/subsystem/net/devices/dummy0
TAGS=:systemd:
USEC_INITIALIZED=102664557
test_device=1

# journalctl -n 2
-- Logs begin at Sat 2013-12-14 03:17:23 CET, end at Tue 2013-12-17
19:55:28 CET. --
Dec 17 19:55:28 lon gnome-session[442]: Gjs-Message: JS LOG: Removing
a network device that was not added
Dec 17 19:55:28 lon logger[20316]: 1
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-17 Thread Kay Sievers
On Tue, Dec 17, 2013 at 8:14 PM, Andrey Borzenkov arvidj...@gmail.com wrote:
 В Tue, 17 Dec 2013 19:59:47 +0100 Kay Sievers k...@vrfy.org пишет:

 # modprobe dummy

 dummy is not renamed.

 UDEV  [80256.274447] move /devices/pci:00/:00:03.0/net/ens3 (net)
 ACTION=move
 ...
 INTERFACE=ens3
 SEQNUM=1452
 ...
 TAGS=:systemd:
 UDEV_LOG=7

 Oops. test_device is lost.

Adding something like:
  ACTION!=add|remove, IMPORT{db}=test_device

might make it work.

Kay
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udev rules environment variable

2013-12-16 Thread Hannes Reinecke
On 12/17/2013 08:52 AM, Robert Milasan wrote:
 Hello,
   got a small question about creating a rule, like this:
 
 ACTION==add, , ENV{test_device}=1
 
 ACTION==remove, , ENV{test_device}==1,
 RUN+=/path/to/some/script
 
 Does udev save test_device variable someplace and then it can be used
 later on, when have ACTION==remove ?
 

Typically not.
I would be using external tools for that, like 'collect'

Might be biased, though, what with me having written it ...

And the alternative of querying the udev database from within an
udev event is just plain ugly and prone to races.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke   zSeries  Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel