mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
smbXsrv_open: factor fetch-locking of global record into function
smbXsrv_open_global_fetch_locked() Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
f3ea162488
commit
7b8cfa1cbc
@ -151,6 +151,27 @@ static NTSTATUS smbXsrv_open_local_key_to_id(TDB_DATA key, uint32_t *id)
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
static struct db_record *smbXsrv_open_global_fetch_locked(
|
||||
struct db_context *db,
|
||||
uint32_t id,
|
||||
TALLOC_CTX *mem_ctx)
|
||||
{
|
||||
TDB_DATA key;
|
||||
uint8_t key_buf[SMBXSRV_OPEN_GLOBAL_TDB_KEY_SIZE];
|
||||
struct db_record *rec = NULL;
|
||||
|
||||
key = smbXsrv_open_global_id_to_key(id, key_buf);
|
||||
|
||||
rec = dbwrap_fetch_locked(db, mem_ctx, key);
|
||||
|
||||
if (rec == NULL) {
|
||||
DBG_DEBUG("Failed to lock global id 0x%08x, key '%s'\n", id,
|
||||
hex_encode_talloc(talloc_tos(), key.dptr, key.dsize));
|
||||
}
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
static NTSTATUS smbXsrv_open_table_init(struct smbXsrv_connection *conn,
|
||||
uint32_t lowest_id,
|
||||
uint32_t highest_id,
|
||||
@ -494,8 +515,6 @@ static NTSTATUS smbXsrv_open_global_allocate(struct db_context *db,
|
||||
bool is_free = false;
|
||||
bool was_free = false;
|
||||
uint32_t id;
|
||||
uint8_t key_buf[SMBXSRV_OPEN_GLOBAL_TDB_KEY_SIZE];
|
||||
TDB_DATA key;
|
||||
|
||||
if (i >= min_tries && last_free != 0) {
|
||||
id = last_free;
|
||||
@ -509,9 +528,7 @@ static NTSTATUS smbXsrv_open_global_allocate(struct db_context *db,
|
||||
id--;
|
||||
}
|
||||
|
||||
key = smbXsrv_open_global_id_to_key(id, key_buf);
|
||||
|
||||
global->db_rec = dbwrap_fetch_locked(db, mem_ctx, key);
|
||||
global->db_rec = smbXsrv_open_global_fetch_locked(db, id, mem_ctx);
|
||||
if (global->db_rec == NULL) {
|
||||
talloc_free(global);
|
||||
return NT_STATUS_INSUFFICIENT_RESOURCES;
|
||||
@ -717,8 +734,6 @@ static NTSTATUS smbXsrv_open_global_lookup(struct smbXsrv_open_table *table,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct smbXsrv_open_global0 **_global)
|
||||
{
|
||||
TDB_DATA key;
|
||||
uint8_t key_buf[SMBXSRV_OPEN_GLOBAL_TDB_KEY_SIZE];
|
||||
struct db_record *global_rec = NULL;
|
||||
bool is_free = false;
|
||||
|
||||
@ -728,15 +743,10 @@ static NTSTATUS smbXsrv_open_global_lookup(struct smbXsrv_open_table *table,
|
||||
return NT_STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
key = smbXsrv_open_global_id_to_key(open_global_id, key_buf);
|
||||
|
||||
global_rec = dbwrap_fetch_locked(table->global.db_ctx, mem_ctx, key);
|
||||
if (global_rec == NULL) {
|
||||
DEBUG(0, ("smbXsrv_open_global_lookup(0x%08x): "
|
||||
"Failed to lock global key '%s'\n",
|
||||
global_rec = smbXsrv_open_global_fetch_locked(table->global.db_ctx,
|
||||
open_global_id,
|
||||
hex_encode_talloc(talloc_tos(), key.dptr,
|
||||
key.dsize)));
|
||||
mem_ctx);
|
||||
if (global_rec == NULL) {
|
||||
return NT_STATUS_INTERNAL_DB_ERROR;
|
||||
}
|
||||
|
||||
@ -909,8 +919,6 @@ NTSTATUS smbXsrv_open_update(struct smbXsrv_open *op)
|
||||
{
|
||||
struct smbXsrv_open_table *table = op->table;
|
||||
NTSTATUS status;
|
||||
uint8_t key_buf[SMBXSRV_OPEN_GLOBAL_TDB_KEY_SIZE];
|
||||
TDB_DATA key;
|
||||
|
||||
if (op->global->db_rec != NULL) {
|
||||
DEBUG(0, ("smbXsrv_open_update(0x%08x): "
|
||||
@ -919,17 +927,11 @@ NTSTATUS smbXsrv_open_update(struct smbXsrv_open *op)
|
||||
return NT_STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
key = smbXsrv_open_global_id_to_key(op->global->open_global_id,
|
||||
key_buf);
|
||||
|
||||
op->global->db_rec = dbwrap_fetch_locked(table->global.db_ctx,
|
||||
op->global, key);
|
||||
if (op->global->db_rec == NULL) {
|
||||
DEBUG(0, ("smbXsrv_open_update(0x%08x): "
|
||||
"Failed to lock global key '%s'\n",
|
||||
op->global->db_rec = smbXsrv_open_global_fetch_locked(
|
||||
table->global.db_ctx,
|
||||
op->global->open_global_id,
|
||||
hex_encode_talloc(talloc_tos(), key.dptr,
|
||||
key.dsize)));
|
||||
op->global /* TALLOC_CTX */);
|
||||
if (op->global->db_rec == NULL) {
|
||||
return NT_STATUS_INTERNAL_DB_ERROR;
|
||||
}
|
||||
|
||||
@ -979,21 +981,11 @@ NTSTATUS smbXsrv_open_close(struct smbXsrv_open *op, NTTIME now)
|
||||
global_rec = op->global->db_rec;
|
||||
op->global->db_rec = NULL;
|
||||
if (global_rec == NULL) {
|
||||
uint8_t key_buf[SMBXSRV_OPEN_GLOBAL_TDB_KEY_SIZE];
|
||||
TDB_DATA key;
|
||||
|
||||
key = smbXsrv_open_global_id_to_key(
|
||||
global_rec = smbXsrv_open_global_fetch_locked(
|
||||
table->global.db_ctx,
|
||||
op->global->open_global_id,
|
||||
key_buf);
|
||||
|
||||
global_rec = dbwrap_fetch_locked(table->global.db_ctx,
|
||||
op->global, key);
|
||||
op->global /* TALLOC_CTX */);
|
||||
if (global_rec == NULL) {
|
||||
DEBUG(0, ("smbXsrv_open_close(0x%08x): "
|
||||
"Failed to lock global key '%s'\n",
|
||||
op->global->open_global_id,
|
||||
hex_encode_talloc(global_rec, key.dptr,
|
||||
key.dsize)));
|
||||
error = NT_STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
@ -1403,21 +1395,16 @@ NTSTATUS smbXsrv_open_cleanup(uint64_t persistent_id)
|
||||
NTSTATUS status = NT_STATUS_OK;
|
||||
TALLOC_CTX *frame = talloc_stackframe();
|
||||
struct smbXsrv_open_global0 *op = NULL;
|
||||
uint8_t key_buf[SMBXSRV_OPEN_GLOBAL_TDB_KEY_SIZE];
|
||||
TDB_DATA key;
|
||||
TDB_DATA val;
|
||||
struct db_record *rec;
|
||||
bool delete_open = false;
|
||||
uint32_t global_id = persistent_id & UINT32_MAX;
|
||||
|
||||
key = smbXsrv_open_global_id_to_key(global_id, key_buf);
|
||||
rec = dbwrap_fetch_locked(smbXsrv_open_global_db_ctx, frame, key);
|
||||
rec = smbXsrv_open_global_fetch_locked(smbXsrv_open_global_db_ctx,
|
||||
global_id,
|
||||
frame);
|
||||
if (rec == NULL) {
|
||||
status = NT_STATUS_NOT_FOUND;
|
||||
DEBUG(1, ("smbXsrv_open_cleanup[global: 0x%08x] "
|
||||
"failed to fetch record from %s - %s\n",
|
||||
global_id, dbwrap_name(smbXsrv_open_global_db_ctx),
|
||||
nt_errstr(status)));
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user