From: Stefan Metzmacher Date: Fri, 26 Aug 2022 07:42:45 +0000 (+0200) Subject: s3:locking: move from uint8_t share_mode_lock_key_data[] to struct file_id X-Git-Tag: talloc-2.4.0~864 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca9014d0378e1da8c30da4aae99a05005fe89b10;p=thirdparty%2Fsamba.git s3:locking: move from uint8_t share_mode_lock_key_data[] to struct file_id This will allow us to have better debug messages and will also make further changes easier. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125 Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c index 9d88f7766b2..6354ae00ed8 100644 --- a/source3/locking/share_mode_lock.c +++ b/source3/locking/share_mode_lock.c @@ -725,10 +725,10 @@ fail: /* * Key that's locked with g_lock */ -static uint8_t share_mode_lock_key_data[sizeof(struct file_id)]; +static struct file_id share_mode_lock_key_id = {}; static TDB_DATA share_mode_lock_key = { - .dptr = share_mode_lock_key_data, - .dsize = sizeof(share_mode_lock_key_data), + .dptr = (uint8_t *)&share_mode_lock_key_id, + .dsize = sizeof(share_mode_lock_key_id), }; static size_t share_mode_lock_key_refcount = 0; @@ -878,7 +878,6 @@ struct share_mode_lock *get_share_mode_lock( TDB_DATA key = locking_key(&id); struct share_mode_lock *lck = NULL; NTSTATUS status; - int cmp; lck = talloc(mem_ctx, struct share_mode_lock); if (lck == NULL) { @@ -914,12 +913,17 @@ struct share_mode_lock *get_share_mode_lock( nt_errstr(status)); goto fail; } - memcpy(share_mode_lock_key_data, key.dptr, key.dsize); + share_mode_lock_key_id = id; } - cmp = tdb_data_cmp(share_mode_lock_key, key); - if (cmp != 0) { - DBG_WARNING("Can not lock two share modes simultaneously\n"); + if (!file_id_equal(&share_mode_lock_key_id, &id)) { + struct file_id_buf existing; + struct file_id_buf requested; + + DBG_ERR("Can not lock two share modes " + "simultaneously: existing %s requested %s\n", + file_id_str_buf(share_mode_lock_key_id, &existing), + file_id_str_buf(id, &requested)); smb_panic(__location__); goto fail; }