summaryrefslogtreecommitdiff
path: root/source3/locking
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2019-08-26 16:22:23 +0200
committerJeremy Allison <jra@samba.org>2019-09-10 23:14:32 +0000
commit5427f73af58252f6aabb044dac267c799ec26eb6 (patch)
tree4552625bcccdb0ed7b4df58d357f9faf683cf8e3 /source3/locking
parent4204ed2b82fd8e9f6faf6e05a009d0ad7742c649 (diff)
downloadsamba-5427f73af58252f6aabb044dac267c799ec26eb6.tar.gz
smbd: Use dbwrap_do_locked() in fd_close_posix()
We don't need to make a copy of the fd array Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/locking')
-rw-r--r--source3/locking/posix.c91
1 files changed, 21 insertions, 70 deletions
diff --git a/source3/locking/posix.c b/source3/locking/posix.c
index 5b5fc229d33..3b75cfe481a 100644
--- a/source3/locking/posix.c
+++ b/source3/locking/posix.c
@@ -550,53 +550,22 @@ static void add_fd_to_close_entry(const files_struct *fsp)
fsp_str_dbg(fsp));
}
-/****************************************************************************
- Remove all fd entries for a specific dev/inode pair from the tdb.
-****************************************************************************/
-
-static void delete_close_entries(const files_struct *fsp)
-{
- struct db_record *rec;
-
- rec = dbwrap_fetch_locked(
- posix_pending_close_db, talloc_tos(),
- fd_array_key_fsp(fsp));
-
- SMB_ASSERT(rec != NULL);
- dbwrap_record_delete(rec);
- TALLOC_FREE(rec);
-}
-
-/****************************************************************************
- Get the array of POSIX pending close records for an open fsp. Returns number
- of entries.
-****************************************************************************/
-
-static size_t get_posix_pending_close_entries(TALLOC_CTX *mem_ctx,
- const files_struct *fsp,
- int **entries)
+static void fd_close_posix_fn(
+ struct db_record *rec, void *private_data)
{
- TDB_DATA dbuf;
- NTSTATUS status;
-
- status = dbwrap_fetch(
- posix_pending_close_db, mem_ctx, fd_array_key_fsp(fsp),
- &dbuf);
+ TDB_DATA data = dbwrap_record_get_value(rec);
+ size_t num_fds, i;
- if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
- *entries = NULL;
- return 0;
- }
-
- SMB_ASSERT(NT_STATUS_IS_OK(status));
+ SMB_ASSERT((data.dsize % sizeof(int)) == 0);
+ num_fds = data.dsize / sizeof(int);
- if (dbuf.dsize == 0) {
- *entries = NULL;
- return 0;
+ for (i=0; i<num_fds; i++) {
+ int fd;
+ memcpy(&fd, data.dptr, sizeof(int));
+ close(fd);
+ data.dptr += sizeof(int);
}
-
- *entries = (int *)dbuf.dptr;
- return (size_t)(dbuf.dsize / sizeof(int));
+ dbwrap_record_delete(rec);
}
/****************************************************************************
@@ -609,8 +578,7 @@ int fd_close_posix(const struct files_struct *fsp)
{
int saved_errno = 0;
int ret;
- int *fd_array = NULL;
- size_t count, i;
+ NTSTATUS status;
if (!lp_locking(fsp->conn->params) ||
!lp_posix_locking(fsp->conn->params) ||
@@ -637,33 +605,16 @@ int fd_close_posix(const struct files_struct *fsp)
return 0;
}
- /*
- * No outstanding locks. Get the pending close fd's
- * from the db and close them all.
- */
-
- count = get_posix_pending_close_entries(talloc_tos(), fsp, &fd_array);
-
- if (count) {
- DEBUG(10,("fd_close_posix: doing close on %u fd's.\n",
- (unsigned int)count));
-
- for(i = 0; i < count; i++) {
- if (close(fd_array[i]) == -1) {
- saved_errno = errno;
- }
- }
-
- /*
- * Delete all fd's stored in the db
- * for this dev/inode pair.
- */
-
- delete_close_entries(fsp);
+ status = dbwrap_do_locked(
+ posix_pending_close_db,
+ fd_array_key_fsp(fsp),
+ fd_close_posix_fn,
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_WARNING("dbwrap_do_locked failed: %s\n",
+ nt_errstr(status));
}
- TALLOC_FREE(fd_array);
-
/* Don't need a lock ref count on this dev/ino anymore. */
delete_lock_ref_count(fsp);