summaryrefslogtreecommitdiff
path: root/source3/locking/locking.c
AgeCommit message (Collapse)AuthorFilesLines
2001-12-18Removed unused function, delete_fn()Tim Potter1-57/+0
(This used to be commit f26e8205cff63967b9c1659b8e6ad71cbe36dace)
2001-11-30After conversations with Andrew, improved the robustness of theJeremy Allison1-26/+53
sharemode db in the following way. Originally, on startup and shutdown, smbd would scan the share mode db to ensure it was correct. This lead to scalability issues as scans lock the db for quite a long time. Andrew had the brainstorm that we only care about the record we're about to read. This new code (small change really, but quite significant) causes get_share_modes() to do a process_exists() call against each pid in each record, and to delete any that don't and re-write the entry if any dead records were detected. This allowed me to remove the startup/shutdown scans of the db (they can be added into smbstatus if anyone really cares to have them back). This will please the vfs author who was worried about the time taken on open() calls, and will lead to much greater robustness and scalability in the share mode db. We need much testing of this, and also netbench tests to ensure the extra process_exists() calls don't hurt performance (they shouldn't it's a very simple system call). Jeremy. (This used to be commit 4098d442030e66601450baeb09ae06b39a1ab571)
2001-11-21Don't scan locking db on closedown.Jeremy Allison1-0/+4
Jeremy. (This used to be commit 59cfcd8a6c510204ac059a0d2fddc2fa17199f82)
2001-10-20Move from timestamp to gen count file id's for finding oplocked filesJeremy Allison1-6/+19
in a tdb. Jeremy. (This used to be commit 058ae6b58f61ef46013dd076af3a84de5fbaaab1)
2001-10-19Ensure we mask off deny modes correctly on being set (this shouldn't haveJeremy Allison1-2/+2
caused problems but is tidier). Fix debug statement in locking.c Jeremy. (This used to be commit eac6bbd24ebf00b35e50953bc11186111dc39059)
2001-10-02Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header.Tim Potter1-1/+0
(This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e)
2001-09-19Removed test code that got added by accident.Jeremy Allison1-22/+0
Jeremy. (This used to be commit fc91ecc236e0d27f5836e9820332ababd762f1a7)
2001-09-18Correct fix for unaligned memcpy - malloc'ed memory incremented by ↵Jeremy Allison1-18/+20
sizeof(struct locking_data) was not forced to be 8 byte aligned. Use union to force it to be correctly aligned for memcpy and use void *, to tell compiler not to optimize aligned copy (this last fix suggested by Trond @ RedHat). The first fix should be sufficient, but this provides a "belt and braces" fix. Jeremy. (This used to be commit 22c5915bb466529ac1bcb5c2574888b360a9775b)
2001-09-18Use structure copy to fix unaligned accesses on 64bit architectures onJeremy Allison1-1/+1
Linux. Jeremy. (This used to be commit b4b891279b6292237113456f1bb0d4393f1f9af1)
2001-09-17move to SAFE_FREE()Simo Sorce1-8/+8
(This used to be commit e61aec84edaf55b9ee087b076d2f1311033dc839)
2001-09-06got rid of USE_TDB_MMAP_FLAG as its not needed any moreAndrew Tridgell1-1/+1
(This used to be commit c26e0d3f27a05ecc8bd2390f9aab7f9451524e47)
2001-09-06use NTSTATUS not BOOL in do_lock()Andrew Tridgell1-12/+9
(This used to be commit b1b2a5fa5d084dad8ae47777419ab75db1e51eff)
2001-09-052nd DELETE_ON_CLOSE_FLAG fix ...Andrew Tridgell1-3/+3
we set the DELETE_ON_CLOSE_FLAG on all share modes on the file, which means the share mode in the fsp will not match the one in the tdb when we come to close for other file handles, which means we end up with share modes on files after all handles are closed fixed by making the comparison function that says if two shares modes are equal ignore the DELETE_ON_CLOSE_FLAG (This used to be commit 7b39c4c59897669106d7129bad8af3d592d25838)
2001-09-04the next stage in the NTSTATUS/WERROR change. smbd and nmbd now compile, but ↵Andrew Tridgell1-6/+6
the client code still needs some work (This used to be commit dcd6e735f709a9231860ceb9682db40ff26c9a66)
2001-08-27converted another bunch of stuff to NTSTATUSAndrew Tridgell1-1/+1
(This used to be commit 1d36250e338ae0ff9fbbf86019809205dd97d05e)
2001-08-27started converting NTSTATUS to be a structure on systems with gcc in order ↵Andrew Tridgell1-6/+6
to make it type incompatible with BOOL so we catch errors sooner. This has already found a number of bugs (This used to be commit 1b778bc7d22efff3f90dc450eb12baa1241cf68f)
2001-08-27converted smbd to use NTSTATUS by defaultAndrew Tridgell1-22/+13
major changes include: - added NSTATUS type - added automatic mapping between dos and nt error codes - changed all ERROR() calls to ERROR_DOS() and many to ERROR_NT() these calls auto-translate to the client error code system - got rid of the cached error code and the writebmpx code We eventually will need to also: - get rid of BOOL, so we don't lose error info - replace all ERROR_DOS() calls with ERROR_NT() calls but that is too much for one night (This used to be commit 83d9896c1ea8be796192b51a4678c2a3b87f7518)
2001-08-240 byte lock ranges ARE validAndrew Tridgell1-6/+3
(This used to be commit 5498da6664a457e4d64502d37fa887dabd9baaa0)
2001-08-22Tidyup fixes for fcntl spin problem.Jeremy Allison1-11/+30
Jeremy. (This used to be commit 27d3dd0e7cb777ef6b21d6966c07045c2940fd37)
2001-08-22Fixed the (incorrect) paranioa fix I put in for the fcntl lock spin.Jeremy Allison1-17/+35
Don't delete a share mode that failed to remove the oplock (doh!), just set the oplock entry to zero.... Jeremy. (This used to be commit fe4aa720181a43f7a636ca029680fab0c836b968)
2001-08-21Missed uninitialized variable return for del_share_mode().Jeremy Allison1-1/+1
Jeremy. (This used to be commit e4a57fb45660b82eaec751f1b41f657a64d963fd)
2001-08-21This is Jeremy pretending to be Volker, 'cos theVolker Lendecke1-64/+136
link from Seattle is having problems. I've added 3 things here to work on the fcntl spin problem. 1). Check *all* tdb return codes... :-). 2). If we're asking ourselves to break an oplock, and we can't find a fsp pointer that matches the entry, this is a *logic bug* and we should abort and panic so someone with gdb can pick up the pieces. 3). After we've broken an oplock, ensure that the entry itself has been removed, and if not remove it ourselves. This should not be neccessary in a correctly working environmen,t, but will provide an added layer of robustness in error situations. 4). I hate german keyboards :-) :-). Jeremy. (This used to be commit 1c94fa80646f9e31377fbb41332fe4780f550cab)
2001-08-20Ensure we are very explicit about what we're comparing whenJeremy Allison1-4/+4
we're comparing structures (ie. don't just do a memcmp). I don't think this will fix the fcntl spin issue, but it's a "just in case" change. Jeremy. (This used to be commit 41066208ad8ca20d35a32bdf9ad934e11465c8f1)
2001-07-30Added "use mmap" for HPUX.Jeremy Allison1-1/+1
Jeremy. (This used to be commit 840802f10677cb0009cb4df4c37c7d01aa5edacd)
2001-07-02Fixed the nastiest locking bug to track down.... smb_pids are sent in theJeremy Allison1-6/+6
lockingX calls - use that instead of smb_pid in the packet. Jeremy. (This used to be commit a3925cb9c6303ce24e5fecad6c8f3a0ba78b9ee0)
2001-06-30Ensure we return correct error on trying to unlock a region not locked.Jeremy Allison1-2/+2
Jeremy. (This used to be commit 015a077acc49e59179dc10256fd32166ee4623e2)
2001-06-30Fixed the first locking error (test #8 found by locktest code fromJeremy Allison1-3/+15
Clarion locktest. Jeremy. (This used to be commit 5c42845b5bb6fafd0ebf93fbdd23d9bf861da865)
2001-06-04use LDSHFLAGS not -shared in several placesAndrew Tridgell1-1/+1
(This used to be commit 8ec9c87b5d1a7dae17d5b1a30f58effaf5e69e4b)
2001-05-22Defensive brlock and locking database cleaning code.Jeremy Allison1-2/+81
Jeremy. (This used to be commit d7aa42e4593b02ee6e487f7a4633bd7e7620ef2f)
2001-03-30This is a big, rather ugly patch. Whilst investigating the files not truncatedJeremy Allison1-32/+39
when copying to a full disk problem, I discovered that we were not allowing the delete on close flag to be set properly, this led to other things, and after investigation of the proper delete on close semantics and their relationship to the file_share_delete flag I discovered there were some cases where we weren't doing the deny modes properly. And this after only 5 years working on them..... :-) :-). So here's the latest attempt. I realised the delete on close flag needs to be set across all smbds with a dev/ino pair open - in addition, the delete on close flag, allow share delete and delete access requested all need to be stored in the share mode tdb. The "delete_on_close" entry in the fsp struct is now redundant and should really be removed. This may also mean we can get rid of the "iterate_fsp" calls that I didn't like adding in the first place. Whilst doing this patch, I also discovered we needed to do the se_map_generic() call for file opens and POSIX ACL mapping, so I added that also. This code, although ugly, now passes the deny mode torture tests plus the delete on close tests I added. I do need to add one more multiple connection delete on close test to make sure I got the semantics exactly right, plus we should also (as Andrew suggested) move to random testing here. The good news is that NT should now correctly delete the file on disk full error when copying to a disk :-). Jeremy. (This used to be commit 51987684bd231c744da2e5f3705fd236d5616173)
2001-03-11Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMRJeremy Allison1-7/+4
RPC code to merge with new passdb code. Currently rpcclient doesn't compile. I'm working on it... Jeremy. (This used to be commit 0be41d5158ea4e645e93e8cd30617c038416e549)
2000-12-06tdb_unlockchain() no longer returns a valueTim Potter1-4/+4
(This used to be commit aee52c7acf138f8fd651aeb3d9bef79f99d1a2a9)
2000-12-06Changed to sourceforge tdb code. This includes spinlocks (so we now haveJeremy Allison1-4/+4
a --with-spinlocks option to configure, this does mean the on-disk tdb format has changed, so 2.2alphaX sites will need to re-create their tdb's. The upside is no more tdb fragmentation and a +5% on netbench. Swings and roundabouts.... Jeremy. (This used to be commit 9dea7b7c257db487f8ced7dad3fce92fba03ea91)
2000-09-11the first cut of the internal messaging system.Andrew Tridgell1-1/+1
The motivation for this system is to replace the UDP message for oplocks, but this commit only does the "set debug level" message. (This used to be commit 2a34ee95f3929cff131db6c5a2b4820194c05b2d)
2000-06-13allow posix locking database to be opened read-only (for smbstatus)Andrew Tridgell1-1/+1
(This used to be commit b9d78738bb30da3d989dfacc95cfde529f2afca5)
2000-05-10Using a structure for a tdb key can lead to insideous, hardHerb Lewis1-0/+2
to find bugs. On 64 bit IRIX, structure packing means that a struct { SMB_DEV_T dev /* 4 bytes */ SMB_INO_T ino /* 8 bytes */ } has 4 bytes of padding between the two members. If you don't null the memory before using it as a tdb key, you randomly can't find keys depending on what is in the padding. This caused me immense pain and was hard to track down.... :-) Jeremy. (This used to be commit f2a5ba3f0939f59097f0ef6a25f1cf9b5574f157)
2000-05-05Fix for uninitialized memory read in brlock code. brl_locktest now needsJeremy Allison1-1/+1
to correctly set the fnum, as the brl_conflict code looks at it. Jeremy. (This used to be commit df87259a356b91989604a10b3691480dcd16cf3f)
2000-05-02Added sys_fork() and sys_getpid() functions to stop the overheadJeremy Allison1-8/+8
of doing a system call every time we want to just get our pid. Jeremy. (This used to be commit 148628b616b5c29ba6340d65fc3ddbcabba6e67a)
2000-04-28Ok - this is the *third* implementation of this (third time's the charm :-).Jeremy Allison1-628/+13
This implementation keeps all POSIX lock records in a separate in memory tdb database only known about in locking/posix.c. In addition, the pending close fd's are also held in a tdb which has an array of fd's indexed by device and inode. The walk-split code uglyness has been moved to posix.c from brlock.c, which is the only place that needs to know about it, and the extra functions hacked into brlock to expose internal state have been removed. This implementation passes smbtorture locktest4, the only thing I need to check now for completeness is what to do about lock upgrade/downgrades which Win32 allows under some *very* strange circumstances. Jeremy. (This used to be commit 3f655de1c764b9ee1472a111621d4317f19f624d)
2000-04-28Forgot to close when "posix locking" is set to False.Jeremy Allison1-2/+5
Jeremy. (This used to be commit b812f09ba8ef074c9ff0747ea03a1e33f1ebbe71)
2000-04-28Added optimization where we are single opener (don't free POSIX locks).Jeremy Allison1-1/+21
Jeremy. (This used to be commit a2deb91128d59ad04f4ec858ffe4e30f2afb0edd)
2000-04-28Made changes suggested by Andrew review.Jeremy Allison1-37/+52
fd_close now calls fd_close_posix() directly. set_posix_lock/release_posix_lock() now handle the reference counting. More changes due when this gets moved to the file locking/posix.c Jeremy. (This used to be commit 239abd48f049c6a8d2bbc0636eacf347ab77588c)
2000-04-27Ok - this is more subtle than it looks :-).Jeremy Allison1-7/+13
When a file is being closed, once it passes the fnum and tid tests then the locking context should be ignored when removing all locks. This is what is done in the brl close case, but when you have outstanding POSIX locks, then you cannot remove all the brl locks in one go, you have to get the lock list and call do_unlock individually. As this uses global_smbpid as the locking context, you need to make sure that this is set correctly for the specific lock being removed. I now do this by storing the smbpid in each entry in the unlock list returned from the query call. I removed the smbpid from fsp (not needed) and things seem ok (even with the stupid smbpid tricks that smbtorture plays :-). Jeremy. (This used to be commit 6baa96bb466915cc17e8cbad50254d6bd47b967b)
2000-04-27Fixed subtle unlocking bug when a file is closed. We need to store theJeremy Allison1-6/+5
smbpid used when a file was opened in the files_struct. Else we use the wrong global_smbpid when we are closing the file and trying to remove the brl locks - this causes the brl locks to be left when the file is closed as the samba_context check fails. Jeremy. (This used to be commit 2746e5602e493e5b022764b4b839eb4d2f14363b)
2000-04-27Did the rewrite Andrew wanted where all knowledge of POSIX locking isJeremy Allison1-5/+179
removed from the smbd/open.c code. We now use a dlink list of structures indexed by dev/inode to store all pending fd's for close. This could be rewritten to use lib/hash.c if this is discovered to be too slow in use. Andrew, please take a look and let me know if this is what you had in mind. Jeremy. (This used to be commit 0487841120a7584da9a2b83b9574562c415d7024)
2000-04-27Fixed crash bugs Andrew pointed out with LOCK4 smbtortureJeremy Allison1-10/+7
test. Was miscounting posix locks, plus was not taking into account the case where other_fsp == fsp in the 'move locks' case. DOH ! This code will be re-written anyway :-). Jeremy. (This used to be commit 5278ec016cb24d8263fe6e7c1d389f466270ef24)
2000-04-25Added the hard code :-).Jeremy Allison1-50/+121
HEAD should now map brl locks correctly into POSIX locks, including the really nasty case of large range unlock. There is a lot of pretty ASCII art in locking/brlock.c explaining exactly how this code works. If it is unclear, please ask me. Jeremy. (This used to be commit 135855dbd3b8934a49229b81646cd4469acba926)
2000-04-24Added the code that keeps fd's open across a close if there are other fsp'sJeremy Allison1-36/+23
open on the same dev/inode pair with existing POSIX locks. This is done at the smbd/open layer, so smbd just calls fd_close() and the transfer of any open fd's is done under the covers of fd_close(). When an fsp is closed and no other fsp's open on the same dev/inode pair have existing POSIX locks then all fd's associated with this fsp are closed. Now only the hard part of doing the POSIX range unlock code when read locks overlap remains for full POSIX/SMB lock integration.... Jeremy. (This used to be commit 1df48ed55ee303b6d84d7277fd79761cfe5f7052)
2000-04-23fixed a locking database bug - it was actually harmless except thatAndrew Tridgell1-2/+10
smbstatus could display the wrong filename when files change dev/inum after a rename (This used to be commit 990b16fcf7af74f376db157a3e5de7bb68c1a4a1)
2000-04-22This is a *big* checkin that may break some things, but implements theJeremy Allison1-1/+2
new open mechanism Andrew & I discussed. config.sub: configure: Included the QNX patch. include/vfs.h: smbd/vfs-wrap.c: smbd/vfs.c: Added ftruncate vfs call (needed). Note that we will also need locking calls in the vfs (to be added). lib/util_unistr.c: nmbd/nmbd_processlogon.c: Fix for NT domain logons causing nmbd to core dump. Also fix for sidsize DOS bug. locking/locking.c: Check value of ret before using it for memdup. printing/printing.c: Convert print_fsp_open to return an allocated fsp. rpc_server/srv_lsa.c: Fix for NT domain logons. I have removed all use of lp_share_modes() from the code (although I left the parameter in the table for backwards compatibility). It no longer makes sense for this to exist. smbd/close.c: Removed lp_share_modes(). smbd/fileio.c: Fixed parameters to unlock_share_entry call in panic code. smbd/files.c: Correctly set the unix_ERR_code to ERRnofids on fsp allocation fail. smbd/nttrans.c: smbd/reply.c: smbd/trans2.c: Changed all occurrences of open_file_shared/open_directory/ open_file_stat to return an fsp from the call. smbd/open.c: Changed all occurrences of open_file_shared/open_directory/ open_file_stat to return an fsp from the call. In addition I have fixed a long standing race condition in the deny mode processing w.r.t. two smbd's creating a file. Andrew, please note that your original idea of using open with O_EXCL in this case would not work (I went over the races very carefully) and so we must re-check deny modes *after* the open() call returns. This is because there is a race between the open with O_EXCL and the lock of the share mode entry. Imagine the case where the first smbd does the open with O_EXCL and a deny mode of DENY_ALL, but is pre-empted before it locks the share modes and creates the deny mode entry for DENY_ALL. A second smbd could then come in with O_RDONLY and a deny mode of DENY_NONE and the two opens would be allowed. The *only* way to fix this race is to lock the share modes after the open and then do the deny mode checks *after* this lock in the case where the file did not originally exist. This code will need extensive testing but seems to initially work. Jeremy. (This used to be commit ab0ecc39d688f16b9692fe90b991f0b89287070a)