fcntl cooperation with server side processes
Chris Green
cmg at dok.org
Tue Jul 20 21:35:14 GMT 2004
Good day,
This is a repost/recap of a question and asked on
samba at lists.samba.org. I'm using Samba 2.2.8a [1] on Slackware 9.1
with 2000/XP clients. I'm using the Linux 2.4.25 kernel.
I want to have a "drop box" that I have NT/2000 clients writing to
share and then have a unix process read and delete the file.
My problem is that samba isn't doing a lock that I can see from the
Linux side. My usage pattern is:
1) Copy cygwin.tar (250M) to share using Windows Explorer on W2K.
2) from the server's command line while the file is still copying, run
./lockview cygwin.tar
http://cmg.dok.org/code/lockview.c. This code uses fcntl(fd,F_GETLK,
&flockstruct) to see what kind of locks are on the file.
output/Testing# ~/lockview cygwin.tar
this file has no lock!
If I use ``strict locking = yes'', and I have a process use fcntl to
perform a fcntl(fd, F_SETLK, {F_WRLCK, ....}), I get a message on the
windows side instantly saying
``Cannot copy cygwin: The process cannot access the file because
another process has locked a portion of the file''
If I don't use strict locking, rather than aborting the copy, it appears
to unlink when the copy is complete.
As far as I've been able to trace it with debug level = 10, it seems
that there is no lock associated with file creation. I'm not able to
dig out what the values of share mode means. My lock fails even if I
turn oplocks = off.
[2004/07/20 13:21:37, 5] smbd/files.c:file_new(123)
allocated file structure 5634, fnum = 9730 (2 used)
[2004/07/20 13:21:37, 10] smbd/open.c:open_file_shared1(807)
open_file_shared: fname = output/Testing/cygwin.tar, share_mode = 11, ofun = 10, mode = 660, oplock request
= 3
I just noticed:
// F_SETLEASE
if(fcntl(fd, 1024, F_WRLCK) < 0)
perror("Unable to get F_WRLCK\n");
Will not work unless samba is done writing to the file. I think this
might be my linux specific answer.
Is there a better way to know when the copy is done from the linux
side?
Is there an option I can give samba at run time to force it to use
fcntl locks?
Footnotes:
[1] Samba is compiled:
--with-fhs \
--prefix=/usr \
--localstatedir=/var \
--bindir=/usr/bin \
--sbindir=/usr/sbin \
--with-lockdir=/var/cache/samba \
--sysconfdir=/etc \
--with-configdir=/etc/samba \
--with-privatedir=/etc/samba/private \
--with-codepagedir=/etc/codepages \
--with-smbmount \
--with-quotas \
--with-syslog \
--with-utmp \
--with-sambabook=/usr/share/swat/using_samba \
--with-ssl \
--with-sslinc=/usr/include/openssl \
--with-ssllib=/usr \
--with-msdfs \
--with-vfs \
--with-libsmbclient \
i386-slackware-linux
--
Chris Green <cmg at dok.org>
Chicken's thinkin'
More information about the samba-technical
mailing list