From: Volker Lendecke Date: Fri, 23 Aug 2019 16:11:57 +0000 (+0200) Subject: smbd: Use dbwrap_do_locked() in add_fd_to_close_entry() X-Git-Tag: talloc-2.3.1~914 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4204ed2b82fd8e9f6faf6e05a009d0ad7742c649;p=thirdparty%2Fsamba.git smbd: Use dbwrap_do_locked() in add_fd_to_close_entry() Less explicit talloc. Right now dbwrap_rbt behind the scenes does a dbwrap_fetch_locked(), but that will eventually change. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/locking/posix.c b/source3/locking/posix.c index a7bb5519bb4..5b5fc229d33 100644 --- a/source3/locking/posix.c +++ b/source3/locking/posix.c @@ -508,44 +508,46 @@ static void delete_lock_ref_count(const files_struct *fsp) ref count is non zero. ****************************************************************************/ -/**************************************************************************** - Add an fd to the pending close db. -****************************************************************************/ +struct add_fd_to_close_entry_state { + const struct files_struct *fsp; +}; -static void add_fd_to_close_entry(const files_struct *fsp) +static void add_fd_to_close_entry_fn( + struct db_record *rec, void *private_data) { - struct db_record *rec; - int *fds; - size_t num_fds; + struct add_fd_to_close_entry_state *state = private_data; + TDB_DATA values[] = { + dbwrap_record_get_value(rec), + { .dptr = (uint8_t *)&(state->fsp->fh->fd), + .dsize = sizeof(state->fsp->fh->fd) }, + }; NTSTATUS status; - TDB_DATA value; - - rec = dbwrap_fetch_locked( - posix_pending_close_db, talloc_tos(), - fd_array_key_fsp(fsp)); - - SMB_ASSERT(rec != NULL); - value = dbwrap_record_get_value(rec); - SMB_ASSERT((value.dsize % sizeof(int)) == 0); + SMB_ASSERT((values[0].dsize % sizeof(int)) == 0); - num_fds = value.dsize / sizeof(int); - fds = talloc_array(rec, int, num_fds+1); - - SMB_ASSERT(fds != NULL); + status = dbwrap_record_storev(rec, values, ARRAY_SIZE(values), 0); + SMB_ASSERT(NT_STATUS_IS_OK(status)); +} - memcpy(fds, value.dptr, value.dsize); - fds[num_fds] = fsp->fh->fd; +/**************************************************************************** + Add an fd to the pending close db. +****************************************************************************/ - status = dbwrap_record_store( - rec, make_tdb_data((uint8_t *)fds, talloc_get_size(fds)), 0); +static void add_fd_to_close_entry(const files_struct *fsp) +{ + struct add_fd_to_close_entry_state state = { .fsp = fsp }; + NTSTATUS status; + status = dbwrap_do_locked( + posix_pending_close_db, + fd_array_key_fsp(fsp), + add_fd_to_close_entry_fn, + &state); SMB_ASSERT(NT_STATUS_IS_OK(status)); - TALLOC_FREE(rec); - - DEBUG(10,("add_fd_to_close_entry: added fd %d file %s\n", - fsp->fh->fd, fsp_str_dbg(fsp))); + DBG_DEBUG("added fd %d file %s\n", + fsp->fh->fd, + fsp_str_dbg(fsp)); } /****************************************************************************