Bug 286433 - On Sleep, KNetworkManager disables interfaces before pm-utils starts
Summary: On Sleep, KNetworkManager disables interfaces before pm-utils starts
Status: RESOLVED UPSTREAM
Alias: None
Product: knetworkmanager
Classification: Miscellaneous
Component: general (show other bugs)
Version: 0.9
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Will Stephenson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-12 17:54 UTC by Simon Blakely
Modified: 2011-11-15 21:15 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Blakely 2011-11-12 17:54:56 UTC
Version:           0.9 (using KDE 4.7.2) 
OS:                Linux

When Sleep is initiated, KNetworkManager immediately disables all interfaces, before org.freedesktop.nm_dispatcher is enabled (so dispatcher.d scripts do not run) and before pm-utils scripts start. This means that it is impossible to initiate an action such as dismounting CIFS/NFS mounts before sleeping (which will not happen with mounted CIFS shares). 

Reproducible: Always

Steps to Reproduce:
Mount CIFS folder
Use Powerdevil to issue a Sleep command
Examine syslog

Actual Results:  
Nov 12 15:01:49 simon-laptop dbus[988]: [system] Successfully activated service 'org.kde.powerdevil.backlighthelper'
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> sleep requested (sleeping: no  enabled: yes)
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> sleeping or disabling...
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (eth0): now unmanaged
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (eth0): device state change: unavailable -> unmanaged (reason 'sleeping') [20 10 37]
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (eth0): cleaning up...
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (eth0): taking down device.
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (ath0): now unmanaged
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (ath0): device state change: activated -> unmanaged (reason 'sleeping') [100 10 37]
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (ath0): deactivating device (reason 'sleeping') [37]
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (ath0): canceled DHCP transaction, DHCP client pid 17258
Nov 12 15:01:51 simon-laptop avahi-daemon[1015]: Withdrawing address record for 10.0.0.184 on ath0.
Nov 12 15:01:51 simon-laptop avahi-daemon[1015]: Leaving mDNS multicast group on interface ath0.IPv4 with address 10.0.0.184.
Nov 12 15:01:51 simon-laptop avahi-daemon[1015]: Interface ath0.IPv4 no longer relevant for mDNS.
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (ath0): cleaning up...
Nov 12 15:01:51 simon-laptop NetworkManager[1013]: <info> (ath0): taking down device.
Nov 12 15:01:51 simon-laptop dbus[988]: [system] Activating service name='org.freedesktop.nm_dispatcher' (using servicehelper)
Nov 12 15:01:52 simon-laptop dbus[988]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
...
Scripts in /etc/NetworkManager/dispatcher.d do not execute as all interfaces are down.
Scripts in /etc/pm/sleep.d execute, but all network interfaces are now disabled, and CIFS shares cannot now be unmounted.


Expected Results:  
org.freedesktop.nm_dispatcher starts before interfaces are disabled
Scripts in /etc/NetworkManager/dispatcher.d do execute as interfaces are set to down
or
Scripts in /etc/pm/sleep.d execute, but all network interfaces enabled, until 55NetworkManager executes and CIFS shares can be unmounted prior to this.
Comment 1 Lamarque V. Souza 2011-11-12 20:16:23 UTC
Plasma NM does not trigger any action during suspend, only during resuming and none of then affects NM.

Try running pm-suspend. If your problem still persists then it has nothing to do with Plasma NM or any other KDE program.

By what I see in your log NM is going to sleep before triggering the dispatch scripts, that is an error in NM my oppinion.

Anyway, as far as I know NM always run the dispatch scripts AFTER the event (connect or disconnect), so using /etc/NetworkManager/dispatcher.d/ does not solve your problem since you need to umount the devices BEFORE the event.

PS: I think you should use a script called /etc/pm/sleep.d/54Umount, for example, for it to be executed before /usr/lib64/pm-utils/sleep.d/55NetworkManager.
Comment 2 Simon Blakely 2011-11-13 08:43:35 UTC
my pm script is 00cifs and contains

#!/bin/bash
case $1 in
    hibernate|suspend)
        echo "Dismounting CIFS mounts"
	mount
	ifconfig
	umount -f -a -t cifs 
        ;;
    thaw|resume)
        echo "Remounting CIFS"
        ;;
    *)  echo "Error State"
        ;;
esac

When I tried pm-suspend this script worked correctly, as shown in the pm-suspend.log

Running hook /etc/pm/sleep.d/00cifs suspend suspend:
Dismounting CIFS mounts
/dev/sda10 on / type ext3 (rw,errors=remount-ro,commit=0)
...
//HOME/iso on /home/simon/smb4k/HOME/iso type cifs (rw)
//HOME/nntp on /home/simon/smb4k/HOME/nntp type cifs (rw)
//HOME/photos on /home/simon/smb4k/HOME/photos type cifs (rw)
ath0      Link encap:Ethernet  HWaddr 00:19:7d:4b:37:ed  
          inet addr:10.0.0.184  Bcast:10.0.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:15746 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6299 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:11982042 (11.9 MB)  TX bytes:884537 (884.5 KB)

eth0      Link encap:Ethernet  HWaddr 00:16:d4:ad:37:c1  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:21 Base address:0xa000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:500 (500.0 B)  TX bytes:500 (500.0 B)

wifi0     Link encap:UNSPEC  HWaddr 00-19-7D-4B-37-ED-00-00-00-00-00-00-00-00-00-00  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13289 errors:0 dropped:0 overruns:0 frame:548
          TX packets:6502 errors:3 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:280 
          RX bytes:6983925 (6.9 MB)  TX bytes:1136210 (1.1 MB)
          Interrupt:22 
/etc/pm/sleep.d/00cifs suspend suspend: success.

This clearly shows the mounted CIFS and all interfaces enabled. If I repeat the exercise using the PowerDevil panel or KDE menu I get 

Running hook /etc/pm/sleep.d/00cifs suspend suspend:
Dismounting CIFS mounts
/dev/sda10 on / type ext3 (rw,errors=remount-ro,commit=0)
...
//HOME/iso on /home/simon/smb4k/HOME/iso type cifs (rw)
//HOME/nntp on /home/simon/smb4k/HOME/nntp type cifs (rw)
//HOME/photos on /home/simon/smb4k/HOME/photos type cifs (rw)
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:470 errors:0 dropped:0 overruns:0 frame:0
          TX packets:470 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:38924 (38.9 KB)  TX bytes:38924 (38.9 KB)

umount2: Invalid argument
umount: /home/simon/smb4k/HOME/photos: not mounted

No enabled interfaces, umount fails, and pm-suspend will time out on the mount points and fail the suspend after 20 seconds.

KDE/PowerDevil/KNetworkManager/DBus is doing something to cause this.
Comment 3 Lamarque V. Souza 2011-11-13 19:00:47 UTC
If you use:

qdbus --system org.freedesktop.UPower /org/freedesktop/UPower \
org.freedesktop.UPower.Suspend

does the problem still happen?

I guess it does and the answer is because NetworkManager listens for UPower events. PowerDevil triggers the UPower sleep event, but it is NM responsability to do the right thing and it does not. I still think this is an upstream bug in NM. NM should run the dispatch scripts before sleeping.

I will try to contact the NM developers about this problem.
Comment 5 Simon Blakely 2011-11-15 20:49:30 UTC
I tried 
qdbus --system org.freedesktop.UPower /org/freedesktop/UPower \
org.freedesktop.UPower.Suspend

As you expected, this does not work (it times out while trying to unmount the drives)
Comment 6 Lamarque V. Souza 2011-11-15 21:15:02 UTC
One solution for your problem is bypassing Powerdevil's button events and allow acpid to handle them:

. install and set acpid to start at boot.
. edit the file /etc/acpi/default.sh to run pm-hibernate (suspend to disk) or pm-suspend (suspend to ram) on power button pressing. You can also set a command for lid closing event.
. in Powerdevil disable all button events for all your profiles.