Obtaining valid status about active connections

Asked by Bob Harvey

I have a file server, built to be solar powered. It is powered up by a WOL magic packet, and a little daemon I have written starts to count down. When it gets to zero it suspends. Every second the daemon monitors for valid activity and restarts the countdown if the server is in use. The indications of valid activity are : 'who' count > 0, number of rysnc running >0, and number of active samba connections open >0.

Details
---------
It is the samba connection that is causing me trouble. The test is actually `smbstatus | grep \: -c`. It ignores the various header lines in the default smbstatus output, and counts those with a time delimiter as active connections.

This works fine with a Windows client, and used to work fine with an Ubunutu client, but that second case is no longer true. I have two text files which tell the story: with a windows client closing the windows file explorer closes the last connection. In Ubuntu, closing the Natuilus file explorer leaves the last connection running. If go to look at /proc/<process no>/net/tcp it is not changing. So there is no traffic, but the connection is still open.

If I kill either the process listed in smbstatus at the server end, or the one listed as gvfsd-smb at the client end, then it all settles down and no harm is done: the countdown resumes because of my smbstatus | grep test, and if I try to open a new connection it opens normally.

I cannot differentiate when samba is in use or idle when the client is Ubuntu, only when it is Windows.

Question
-------------
So that is my question:
How, at the server end, do I reliably detect that a samba connection is in use?

Supplementary
------------------
Out of curiosity:
Why does samba lock directories when opened in a client windows file navigator, but not an ubuntu one?
Why does samba not lock a text file when opened with a text editor from either type of client?

========================================
I cannot attach files, so I will add them as subsequent comments
=======================================

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu samba Edit question
Assignee:
No assignee Edit question
Solved by:
Bob Harvey
Solved:
Last query:
Last reply:
Revision history for this message
Bob Harvey (bobharvey) said :
#1

This is the effect of using a windows client
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------Server login---------------------
login as: bob
bob@server01's password:
Linux server01 2.6.32-34-server #77-Ubuntu SMP Tue Sep 13 20:54:38 UTC 2011 x86_ 64 GNU/Linux
Ubuntu 10.04.3 LTS

Welcome to the Ubuntu Server!
 * Documentation: http://www.ubuntu.com/server/doc

  System information as of Mon Oct 24 21:22:33 BST 2011

  System load: 1.22 Memory usage: 5% Processes: 157
  Usage of /: 50.5% of 3.46GB Swap usage: 0% Users logged in: 0

  => There are 2 zombie processes.

  Graph this data and manage this system at https://landscape.canonical.com/

Last login: Mon Oct 24 16:22:15 2011 from 10.63.63.63

============================Server end, no client =========================
bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------

No locked files

==================Server end, Windows Client file navigator open=============================

bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 746 10.63.63.63 Mon Oct 24 21:23:06 2011

Locked files:
Pid Uid DenyMode Access R/W Oplock Share Path Name Time
-------------------------------------------------------------------------------- ------------------
746 501 DENY_NONE 0x100081 RDONLY NONE /srv/ share/samba . Mon Oct 24 21:23:07 2011

bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 746 10.63.63.63 Mon Oct 24 21:23:06 2011

Locked files:
Pid Uid DenyMode Access R/W Oplock SharePath Name Time
--------------------------------------------------------------------------------------------------
746 501 DENY_NONE 0x100081 RDONLY NONE /srv/share/samba . Mon Oct 24 21:23:07 2011

=====================Server end, Text file opened in Windows cllient text editor========================
=====================File /srv/share/samba/code/keep_alive.py opened with scite editor ==================
bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 746 10.63.63.63 Mon Oct 24 21:23:06 2011

Locked files:
Pid Uid DenyMode Access R/W Oplock SharePath Name Time
--------------------------------------------------------------------------------------------------
746 501 DENY_NONE 0x100081 RDONLY NONE /srv/share/samba . Mon Oct 24 21:23:07 2011

bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 746 10.63.63.63 Mon Oct 24 21:23:06 2011

Locked files:
Pid Uid DenyMode Access R/W Oplock SharePath Name Time
--------------------------------------------------------------------------------------------------
746 501 DENY_NONE 0x100081 RDONLY NONE /srv/share/samba code Mon Oct 24 21:26:13 2011
746 501 DENY_ALL 0x20089 RDONLY EXCLUSIVE+BATCH /srv/share/samba code/keep_alive.py Mon Oct 24 21:26:32 2011
746 501 DENY_NONE 0x100081 RDONLY NONE /srv/share/samba . Mon Oct 24 21:23:07 2011

bob@server01:~$

===================Server side, A few minutes later, text file still open in windows client editor=====================
===================Closing the editor has no effect. It looks the same as thisThe directories are still locked =======

bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 746 10.63.63.63 Mon Oct 24 21:23:06 2011

Locked files:
Pid Uid DenyMode Access R/W Oplock SharePath Name Time
--------------------------------------------------------------------------------------------------
746 501 DENY_NONE 0x100081 RDONLY NONE /srv/share/samba code Mon Oct 24 21:26:13 2011
746 501 DENY_NONE 0x100081 RDONLY NONE /srv/share/samba . Mon Oct 24 21:23:07 2011

bob@server01:~$

========================Server side, windows client file explorer navigated up one level=======
bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 746 10.63.63.63 Mon Oct 24 21:23:06 2011
IPC$ 746 10.63.63.63 Mon Oct 24 21:31:46 2011

Locked files:
Pid Uid DenyMode Access R/W Oplock SharePath Name Time
--------------------------------------------------------------------------------------------------
746 501 DENY_NONE 0x100081 RDONLY NONE /srv/share/samba . Mon Oct 24 21:23:07 2011

bob@server01:~$

=====================Server side, windows client file explorer closed altogehter =========================
bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 746 10.63.63.63 Mon Oct 24 21:23:06 2011

No locked files

bob@server01:~$

=====================Server side, a few minutes later. Nothing else opened or closed on windows client ========
bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------

No locked files

bob@server01:~$

Revision history for this message
Bob Harvey (bobharvey) said :
#2

This is the effect of using an ubuntu client
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----------------------------------Server login--------------------------------
bob@Harvey10:~$ ssh server01
bob@server01's password:
Linux server01 2.6.32-34-server #77-Ubuntu SMP Tue Sep 13 20:54:38 UTC 2011 x86_64 GNU/Linux
Ubuntu 10.04.3 LTS

Welcome to the Ubuntu Server!
 * Documentation: http://www.ubuntu.com/server/doc

  System information as of Mon Oct 24 21:42:59 BST 2011

  System load: 0.62 Memory usage: 5% Processes: 155
  Usage of /: 50.5% of 3.46GB Swap usage: 0% Users logged in: 0

  => There are 2 zombie processes.

  Graph this data and manage this system at https://landscape.canonical.com/

Last login: Mon Oct 24 21:22:34 2011 from 10.63.63.63
bob@server01:~$

=========================================================================
=====================Server side, no connection made=====================
bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------

No locked files

bob@server01:~$

=======================Client side, no connection made===================
bob@Harvey10:~$ ps aux | grep smb
root 1107 0.0 0.1 15316 3960 ? Ss 21:42 0:00 smbd -F
root 1405 0.0 0.0 15316 1192 ? S 21:42 0:00 smbd -F
bob 2208 0.0 0.0 3328 808 pts/1 S+ 21:45 0:00 grep smb
bob@Harvey10:~$

=========================================================================
=====================Server side, Nautilus navigator open================
bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 27703 10.63.63.63 Mon Oct 24 21:46:45 2011

No locked files

========================Client side, Nautilus navigator open===============
bob@Harvey10:~$ ps aux | grep smb
root 1107 0.0 0.1 15316 3960 ? Ss 21:42 0:00 smbd -F
root 1405 0.0 0.0 15316 1192 ? S 21:42 0:00 smbd -F
bob 2210 0.0 0.2 24184 4960 ? S 21:46 0:00 /usr/lib/gvfs/gvfsd-smb --spawner :1.8 /org/gtk/gvfs/exec_spaw/2
bob 2217 0.0 0.0 3328 812 pts/1 S+ 21:47 0:00 grep smb
bob@Harvey10:~$

=============================================================================
=======================Server side, text file opened in Ubuntu client text editor==========
=======================fiole /srv/share/samba/code/keep_alive.py opened in gedit===========
=======================Looked exactly the same a few minutes later with the editor open====
=======================Looked exactly the same with the editor closed======================
=======================Looked exactly the same a few minutse after the editor was closed.==
bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 27703 10.63.63.63 Mon Oct 24 21:46:45 2011

No locked files

======================Cient side, text file opened in ubuntu client text editor===============
=======================Looked exactly the same a few minutes later with the editor open====
=======================Looked exactly the same with the editor closed======================
=======================Looked exactly the same a few minutes after the editor was closed.==
bob@Harvey10:~$ ps aux | grep smb
root 1107 0.0 0.1 15316 3960 ? Ss 21:42 0:00 smbd -F
root 1405 0.0 0.0 15316 1192 ? S 21:42 0:00 smbd -F
bob 2210 0.0 0.2 24308 5156 ? S 21:46 0:00 /usr/lib/gvfs/gvfsd-smb --spawner :1.8 /org/gtk/gvfs/exec_spaw/2
bob 2237 0.0 0.0 3328 808 pts/1 S+ 21:48 0:00 grep smb
bob@Harvey10:~$

===========================================================================================
======================Server side with Ubuntu clien Nautilus file explorer closed==========
======================Looked exactly the same a few minutes later==========================
bob@server01:~$ smbstatus

Samba version 3.4.7
PID Username Group Machine
-------------------------------------------------------------------
 <processes do not show up in anonymous mode>

Service pid machine Connected at
-------------------------------------------------------
share 27703 10.63.63.63 Mon Oct 24 21:46:45 2011

No locked files

bob@server01:~$
===================Client side with Nautilus file explorer closed==========================
bob@Harvey10:~$ ps aux | grep smb
root 1107 0.0 0.1 15316 3960 ? Ss 21:42 0:00 smbd -F
root 1405 0.0 0.0 15316 1192 ? S 21:42 0:00 smbd -F
bob 2210 0.0 0.2 24308 5156 ? S 21:46 0:00 /usr/lib/gvfs/gvfsd-smb --spawner :1.8 /org/gtk/gvfs/exec_spaw/2
bob 2257 0.0 0.0 3328 804 pts/1 S+ 21:55 0:00 grep smb
bob@Harvey10:~$

=============================================================================================

Revision history for this message
Bob Harvey (bobharvey) said :
#3

smb.conf from the server
~~~~~~~~~~~~~~~~~~~~
#
#======================= Global Settings =======================

[global]
 log file = /var/log/samba/log.%m
 guest account = samba_user
 passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
 obey pam restrictions = yes
 map to guest = bad user
 encrypt passwords = true
 passwd program = /usr/bin/passwd %u
 passdb backend = tdbsam
 dns proxy = no
 netbios name = Solar
 server string = Solar Server
 unix password sync = yes
 workgroup = HARVEY
 os level = 20
 security = share
 syslog = 0
 panic action = /usr/share/samba/panic-action %d
 usershare allow guests = yes
 max log size = 1000
 pam password change = yes

# attempts to speed up
 socket options = TCP_NODELAY
# SO_RCVBUF = 8192
# SO_SNDBUF = 8192

## Browsing/Identification ###

   #server string = %h server (Samba, Ubuntu)

# This will prevent nmbd to search for NetBIOS names through DNS.

# This tells Samba to use a separate log file for each machine
# that connects

# Cap the size of the individual log files (in KiB).

# Do something sensible when Samba crashes: mail the admin a backtrace

####### Authentication #######

#======================= Share Definitions =======================

[share]
    # needed the directory mask setting 0770 because samba
    # appeared to be respecting the group rather than user
    # permissions when working in guest mode. Don't understand
    # why - samba_user is 501:501 and nothing else is in that group.
    comment = Server Share
    path = /srv/share/samba
    browsable = yes
    guest ok = yes
    guest only = yes
    read only = no
    create mask = 0770
    directory mask = 0770
# directory security mask = 0777
# force directory security mode = 0000
# force directory mode = 0777

[shadow]
    comment = Server shadow
    path = /srv/shadow/samba
    browsable = yes
    guest ok = yes
    guest only = yes
    read only = yes
    create mask = 775

Revision history for this message
Bob Harvey (bobharvey) said :
#4

Solution from https://bugzilla.samba.org/show_bug.cgi?id=8601
add deadtime parameter to global section