From 5427f73af58252f6aabb044dac267c799ec26eb6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 26 Aug 2019 16:22:23 +0200 Subject: [PATCH] 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 Reviewed-by: Jeremy Allison --- source3/locking/posix.c | 91 ++++++++++++------------------------------------- 1 file 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; iconn->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); -- 2.11.4.GIT