/****************************************************************************
Deal with pending closes needed by POSIX locking support.
+ Note that posix_locking_close_file() is expected to have been called
+ to delete all locks on this fsp before this function is called.
****************************************************************************/
int fd_close_posix(struct connection_struct *conn, files_struct *fsp)
size_t count, i;
struct posix_lock *entries = NULL;
int *fd_array = NULL;
+ BOOL locks_on_other_fds = False;
if (!lp_posix_locking(SNUM(conn))) {
/*
*/
count = get_posix_lock_entries(fsp, &entries);
-
- if (count) {
+
+ /*
+ * Check if there are any outstanding locks belonging to
+ * other fd's. This should never be the case if posix_locking_close_file()
+ * has been called first, but it never hurts to be *sure*.
+ */
+
+ for (i = 0; i < count; i++) {
+ if (entries[i].fd != fsp->fd) {
+ locks_on_other_fds = True;
+ break;
+ }
+ }
+
+ if (locks_on_other_fds) {
/*
* There are outstanding locks on this dev/inode pair on other fds.
num_records--; /* We're deleting one. */
- DEBUG(10,("delete_posix_lock_entry: type = %s: start=%.0f size=%.0f, num_records = %d\n",
- posix_lock_type_name(pl->lock_type), (double)pl->start, (double)pl->size,
- (unsigned int)num_records ));
-
/* Make a copy if requested. */
if (pl)
*pl = *entry;
+ DEBUG(10,("delete_posix_lock_entry: type = %s: start=%.0f size=%.0f, num_records = %d\n",
+ posix_lock_type_name(pl->lock_type), (double)pl->start, (double)pl->size,
+ (unsigned int)num_records ));
+
/* Found it - delete it. */
if (count == 1) {
tdb_delete(posix_lock_tdb, kbuf);
for (i = 0; i < count; i++) {
struct posix_lock *pl = &entries[i];
- release_posix_lock(fsp, (SMB_BIG_UINT)pl->start, (SMB_BIG_UINT)pl->size );
+ if (pl->fd == fsp->fd)
+ release_posix_lock(fsp, (SMB_BIG_UINT)pl->start, (SMB_BIG_UINT)pl->size );
}
free((char *)entries);
}