Bug 3327 - close_our_files erroneously closes FD for gencache.tdb
Summary: close_our_files erroneously closes FD for gencache.tdb
Status: RESOLVED FIXED
Alias: None
Product: Samba 3.0
Classification: Unclassified
Component: smbmount (unmaintained) (show other bugs)
Version: 3.0.7
Hardware: x86 Linux
: P3 normal
Target Milestone: none
Assignee: Samba Bugzilla Account
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-14 11:41 UTC by Tony Mountifield
Modified: 2008-01-04 14:51 UTC (History)
0 users

See Also:


Attachments
Proposed patch to fix the problem (568 bytes, patch)
2006-01-08 15:54 UTC, Tony Mountifield
no flags Details
Revised patch for client/smbmount.c and lib/gencache.c (1.06 KB, patch)
2006-01-10 15:41 UTC, Tony Mountifield
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tony Mountifield 2005-12-14 11:41:13 UTC
I've been investigating the frequent occurrence of the following error messages:

[2005/12/14 17:52:53, 5] tdb/tdbutil.c:tdb_log(725)
  tdb(/var/cache/samba/gencache.tdb): tdb_brlock failed (fd=3) at offset 244 rw_type=0 lck_type=14
[2005/12/14 17:52:53, 5] tdb/tdbutil.c:tdb_log(725)
  tdb(/var/cache/samba/gencache.tdb): tdb_brlock failed (fd=3) at offset 244 rw_type=0 lck_type=14: Bad file descriptor
[2005/12/14 17:52:53, 0] tdb/tdbutil.c:tdb_log(725)
  tdb(/var/cache/samba/gencache.tdb): tdb_lock failed on list 19 ltype=0 (Bad file descriptor)

I eventually discovered that it is caused by close_our_files() closing the fd for gencache.tdb in the tdb structure (usually fd 3).

An "lsof" of any mount.smbfs process will show only fds 0, 1 and 2 open, even though tdb->fd contains 3.

close_our_files() needs to avoid the inherited fd for gencache.tdb as it does for client_fd.
Comment 1 Gerald (Jerry) Carter (dead mail address) 2006-01-07 12:35:35 UTC
From IRC discussion:

original thread on samba-technical:
http://lists.samba.org/archive/samba-technical/2006-January/044654.html

....
<coffeedude> option #2 sounds best to me.  gencache.tdb is a generic 
string based cache which we frequently use for name caching.  But you 
are talking about smbmount and not smbclient.  Different programs.  If 
you post attach a patch to the bug report with enough etails to verify 
the fix (besides just reading code), i'll get it into the tree.
Comment 2 Tony Mountifield 2006-01-08 15:54:37 UTC
Created attachment 1657 [details]
Proposed patch to fix the problem

This patch adds a call to namecache_shutdown() within the condition that calls close_our_files(), so that the name cache gets closed properly before close_our_files() steals its file descriptor.

Tested on 3.0.7 on Fedora Core 1, but such a trivial change should apply easily to any version.
Comment 3 Tony Mountifield 2006-01-09 01:33:11 UTC
Hmmm, it looks like there's a problem if the remote server closes the connection due to no activity. When smbclient gets the 104 error (ECONNRESET) and retries, mount.smbfs dies.

I'll do some more testing.
Comment 4 Tony Mountifield 2006-01-09 01:34:20 UTC
(In reply to comment #3)
> Hmmm, it looks like there's a problem if the remote server closes the
> connection due to no activity. When smbclient gets the 104 error (ECONNRESET)
> and retries, mount.smbfs dies.
> I'll do some more testing.

I meant smbmount of course. I keep doing that :-(
Comment 5 Tony Mountifield 2006-01-10 15:41:36 UTC
Created attachment 1660 [details]
Revised patch for client/smbmount.c and lib/gencache.c

Found the problem: gencache_shutdown() was not clearing out the static pointer "cache". This meant that when gencache_init() was subsequently called, it thought the cache file was already set up and returned without opening it again. The attempt to access the actual cache then caused smbmount to crash.

This revised patch adds a correction to gencache_shutdown() to set cache to NULL before returning.
Comment 6 Gerald (Jerry) Carter (dead mail address) 2006-01-13 11:40:27 UTC
Looks good to me.  Applying for 3.0.21b (and to all branches).
Thanks for being patient and for the patch.
Comment 7 we3cares 2008-01-04 14:50:26 UTC
can you please give me the download link for the patch.
i'm using Linux 2.4.21-51.EL 
and also where to apply?

Comment 8 we3cares 2008-01-04 14:51:35 UTC
can you please give me the download link for the patch.
i'm using Linux 2.4.21-51.EL 
and also where to apply?

error 
Jan  4 14:22:39 greenapple mount.smbfs[17262]:   tdb(/var/cache/samba/gencache.tdb): tdb_lock failed on list 115 ltype=1 (Bad file descriptor)
Jan  4 14:22:39 greenapple mount.smbfs[17262]: [2008/01/04 14:22:39, 0] tdb/tdbutil.c:tdb_log(725)
Jan  4 14:22:39 greenapple mount.smbfs[17262]:   tdb(/var/cache/samba/gencache.tdb): tdb_lock failed on list 115 ltype=1 (Bad file descriptor)
Jan  4 14:22:39 greenapple kernel: smb_retry: successful, new pid=17262, generation=4