* some question about "/sys/class/net/<iface>/operstate"
@ 2020-11-11 4:31 杜英杰
2020-11-11 19:02 ` Cong Wang
0 siblings, 1 reply; 5+ messages in thread
From: 杜英杰 @ 2020-11-11 4:31 UTC (permalink / raw)
To: netdev
I want to use inotify to monitor /sys/class/net//operstate to detect status of a iface in real time.
when I ifdown && ifup eth3, the content of operstate changed, but the file's Modify time didn't change.
I don't know the reason, is there any file which can be monitored by inotify to get iface status in real time?
Much appreciation for any advice!
below are my terminal msg:
[root@yingjie-4-5-0-20201109195739-1 11:10:39 0000:00:0c.0]$stat /sys/class/net/eth3/operstate
File: ‘/sys/class/net/eth3/operstate’
Size: 4096 Blocks: 0 IO Block: 4096 regular file
Device: 14h/20d Inode: 25838 Links: 1
Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-11-10 20:42:18.592000969 +0800
Modify: 2020-11-10 20:42:18.592000969 +0800
Change: 2020-11-10 20:42:18.592000969 +0800
Birth: -
[root@yingjie-4-5-0-20201109195739-1 11:10:50 0000:00:0c.0]$cat /sys/class/net/eth3/operstate
up
You have new mail in /var/spool/mail/root
[root@yingjie-4-5-0-20201109195739-1 11:11:06 0000:00:0c.0]$ifdown eth3
[root@yingjie-4-5-0-20201109195739-1 11:11:13 0000:00:0c.0]$cat /sys/class/net/eth3/operstate
down
[root@yingjie-4-5-0-20201109195739-1 11:11:16 0000:00:0c.0]$stat /sys/class/net/eth3/operstate
File: ‘/sys/class/net/eth3/operstate’
Size: 4096 Blocks: 0 IO Block: 4096 regular file
Device: 14h/20d Inode: 25838 Links: 1
Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-11-10 20:42:18.592000969 +0800
Modify: 2020-11-10 20:42:18.592000969 +0800
Change: 2020-11-10 20:42:18.592000969 +0800
Birth: -
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: some question about "/sys/class/net/<iface>/operstate"
2020-11-11 4:31 some question about "/sys/class/net/<iface>/operstate" 杜英杰
@ 2020-11-11 19:02 ` Cong Wang
2020-11-11 19:55 ` Stephen Hemminger
0 siblings, 1 reply; 5+ messages in thread
From: Cong Wang @ 2020-11-11 19:02 UTC (permalink / raw)
To: 杜英杰; +Cc: Linux Kernel Network Developers
On Tue, Nov 10, 2020 at 8:32 PM 杜英杰 <leondyj@pku.edu.cn> wrote:
>
> I want to use inotify to monitor /sys/class/net//operstate to detect status of a iface in real time.
> when I ifdown && ifup eth3, the content of operstate changed, but the file's Modify time didn't change.
> I don't know the reason, is there any file which can be monitored by inotify to get iface status in real time?
> Much appreciation for any advice!
You need to listen to netdev netlink messages for changes like
this. These messages are generated in real-time.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: some question about "/sys/class/net/<iface>/operstate"
2020-11-11 19:02 ` Cong Wang
@ 2020-11-11 19:55 ` Stephen Hemminger
2020-11-11 20:34 ` Erik Kline
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2020-11-11 19:55 UTC (permalink / raw)
To: Cong Wang; +Cc: 杜英杰, Linux Kernel Network Developers
On Wed, 11 Nov 2020 11:02:14 -0800
Cong Wang <xiyou.wangcong@gmail.com> wrote:
> On Tue, Nov 10, 2020 at 8:32 PM 杜英杰 <leondyj@pku.edu.cn> wrote:
> >
> > I want to use inotify to monitor /sys/class/net//operstate to detect status of a iface in real time.
> > when I ifdown && ifup eth3, the content of operstate changed, but the file's Modify time didn't change.
> > I don't know the reason, is there any file which can be monitored by inotify to get iface status in real time?
> > Much appreciation for any advice!
>
> You need to listen to netdev netlink messages for changes like
> this. These messages are generated in real-time.
The /sys and /proc are pseudo-filesystems. The file modify time and inotify do not work
as expected on these files. Cong is right you need to use netlink for this.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: some question about "/sys/class/net/<iface>/operstate"
2020-11-11 19:55 ` Stephen Hemminger
@ 2020-11-11 20:34 ` Erik Kline
2020-11-11 21:17 ` Stephen Hemminger
0 siblings, 1 reply; 5+ messages in thread
From: Erik Kline @ 2020-11-11 20:34 UTC (permalink / raw)
To: Stephen Hemminger
Cc: Cong Wang, 杜英杰, Linux Kernel Network Developers
On Wed, Nov 11, 2020 at 11:55 AM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> On Wed, 11 Nov 2020 11:02:14 -0800
> Cong Wang <xiyou.wangcong@gmail.com> wrote:
>
> > On Tue, Nov 10, 2020 at 8:32 PM 杜英杰 <leondyj@pku.edu.cn> wrote:
> > >
> > > I want to use inotify to monitor /sys/class/net//operstate to detect status of a iface in real time.
> > > when I ifdown && ifup eth3, the content of operstate changed, but the file's Modify time didn't change.
> > > I don't know the reason, is there any file which can be monitored by inotify to get iface status in real time?
> > > Much appreciation for any advice!
> >
> > You need to listen to netdev netlink messages for changes like
> > this. These messages are generated in real-time.
>
> The /sys and /proc are pseudo-filesystems. The file modify time and inotify do not work
> as expected on these files. Cong is right you need to use netlink for this.
Related question: could/should modify time and/or inotify be made to
work? I genuinely don't know if that would even be possible (separate
from "desirable").
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: some question about "/sys/class/net/<iface>/operstate"
2020-11-11 20:34 ` Erik Kline
@ 2020-11-11 21:17 ` Stephen Hemminger
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2020-11-11 21:17 UTC (permalink / raw)
To: Erik Kline
Cc: Cong Wang, 杜英杰, Linux Kernel Network Developers
On Wed, 11 Nov 2020 12:34:51 -0800
Erik Kline <ek@loon.com> wrote:
> On Wed, Nov 11, 2020 at 11:55 AM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > On Wed, 11 Nov 2020 11:02:14 -0800
> > Cong Wang <xiyou.wangcong@gmail.com> wrote:
> >
> > > On Tue, Nov 10, 2020 at 8:32 PM 杜英杰 <leondyj@pku.edu.cn> wrote:
> > > >
> > > > I want to use inotify to monitor /sys/class/net//operstate to detect status of a iface in real time.
> > > > when I ifdown && ifup eth3, the content of operstate changed, but the file's Modify time didn't change.
> > > > I don't know the reason, is there any file which can be monitored by inotify to get iface status in real time?
> > > > Much appreciation for any advice!
> > >
> > > You need to listen to netdev netlink messages for changes like
> > > this. These messages are generated in real-time.
> >
> > The /sys and /proc are pseudo-filesystems. The file modify time and inotify do not work
> > as expected on these files. Cong is right you need to use netlink for this.
>
> Related question: could/should modify time and/or inotify be made to
> work? I genuinely don't know if that would even be possible (separate
> from "desirable").
The problem is lots of data changes in /proc and /sys all the time, like every counter
value. So having any kind of notification would be a major performance hit.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-11 21:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11 4:31 some question about "/sys/class/net/<iface>/operstate" 杜英杰
2020-11-11 19:02 ` Cong Wang
2020-11-11 19:55 ` Stephen Hemminger
2020-11-11 20:34 ` Erik Kline
2020-11-11 21:17 ` Stephen Hemminger
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.