summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-01-09 14:30:53 +0100
committerJeremy Allison <jra@samba.org>2012-01-12 23:59:22 +0100
commit9cf6d735d43f6f905b19f52d38c93aa30092333d (patch)
treefd75eba7dc698d61b3f8d5ef240c31fef068f28a
parent540e51f77e07cc65b6b097f8ff01cd10f04644d0 (diff)
downloadsamba-9cf6d735d43f6f905b19f52d38c93aa30092333d.tar.gz
samba-9cf6d735d43f6f905b19f52d38c93aa30092333d.tar.bz2
samba-9cf6d735d43f6f905b19f52d38c93aa30092333d.zip
s3: Introduce get_share_mode_lock_fresh()
This slightly simplifies the code path for all callers which assume that a share mode exists already. Only the callers in open_file_ntcreate and open_directory will ever create new share modes. Signed-off-by: Jeremy Allison <jra@samba.org>
-rw-r--r--source3/locking/locking.c30
-rw-r--r--source3/locking/proto.h11
-rw-r--r--source3/smbd/close.c10
-rw-r--r--source3/smbd/open.c15
-rw-r--r--source3/smbd/oplock.c9
-rw-r--r--source3/smbd/reply.c3
-rw-r--r--source3/smbd/trans2.c3
7 files changed, 40 insertions, 41 deletions
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 95710cdd75..2e400ac8ef 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -675,6 +675,11 @@ static struct share_mode_lock *fresh_share_mode_lock(
{
struct share_mode_lock *lck;
+ if ((servicepath == NULL) || (smb_fname == NULL) ||
+ (old_write_time == NULL)) {
+ return NULL;
+ }
+
lck = talloc_zero(mem_ctx, struct share_mode_lock);
if (lck == NULL) {
goto fail;
@@ -703,11 +708,11 @@ fail:
return NULL;
}
-struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
- const struct file_id id,
- const char *servicepath,
- const struct smb_filename *smb_fname,
- const struct timespec *old_write_time)
+struct share_mode_lock *get_share_mode_lock_fresh(TALLOC_CTX *mem_ctx,
+ const struct file_id id,
+ const char *servicepath,
+ const struct smb_filename *smb_fname,
+ const struct timespec *old_write_time)
{
struct share_mode_lock *lck;
struct file_id tmp;
@@ -735,14 +740,18 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
TALLOC_FREE(rec);
return NULL;
}
-
lck->id = id;
lck->record = talloc_move(lck, &rec);
talloc_set_destructor(lck, share_mode_lock_destructor);
-
return lck;
}
+struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
+ const struct file_id id)
+{
+ return get_share_mode_lock_fresh(mem_ctx, id, NULL, NULL, NULL);
+}
+
struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
const struct file_id id)
{
@@ -1260,8 +1269,7 @@ bool set_delete_on_close(files_struct *fsp, bool delete_on_close, const struct s
delete_on_close ? "Adding" : "Removing", fsp->fnum,
fsp_str_dbg(fsp)));
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
- NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
if (lck == NULL) {
return False;
}
@@ -1314,7 +1322,7 @@ bool set_sticky_write_time(struct file_id fileid, struct timespec write_time)
convert_timespec_to_time_t(write_time)),
file_id_string_tos(&fileid)));
- lck = get_share_mode_lock(talloc_tos(), fileid, NULL, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fileid);
if (lck == NULL) {
return False;
}
@@ -1337,7 +1345,7 @@ bool set_write_time(struct file_id fileid, struct timespec write_time)
convert_timespec_to_time_t(write_time)),
file_id_string_tos(&fileid)));
- lck = get_share_mode_lock(talloc_tos(), fileid, NULL, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fileid);
if (lck == NULL) {
return False;
}
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index d6f1c1bf4a..25f3d196b8 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -147,10 +147,13 @@ bool locking_init_readonly(void);
bool locking_end(void);
char *share_mode_str(TALLOC_CTX *ctx, int num, const struct share_mode_entry *e);
struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
- const struct file_id id,
- const char *servicepath,
- const struct smb_filename *smb_fname,
- const struct timespec *old_write_time);
+ const struct file_id id);
+struct share_mode_lock *get_share_mode_lock_fresh(
+ TALLOC_CTX *mem_ctx,
+ const struct file_id id,
+ const char *servicepath,
+ const struct smb_filename *smb_fname,
+ const struct timespec *old_write_time);
struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
const struct file_id id);
bool rename_share_filename(struct messaging_context *msg_ctx,
diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index 26656f47a2..a07ab4b42c 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -347,9 +347,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
* This prevents race conditions with the file being created. JRA.
*/
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
- NULL);
-
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
if (lck == NULL) {
DEBUG(0, ("close_remove_share_mode: Could not get share mode "
"lock for file %s\n", fsp_str_dbg(fsp)));
@@ -617,7 +615,7 @@ static NTSTATUS update_write_time_on_close(struct files_struct *fsp)
* must update it in the open file db too. */
(void)set_write_time(fsp->file_id, fsp->close_write_time);
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
if (lck) {
/* Close write times overwrite sticky write times
so we must replace any sticky write time here. */
@@ -1019,9 +1017,7 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp,
* reference to a directory also.
*/
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
- NULL);
-
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
if (lck == NULL) {
DEBUG(0, ("close_directory: Could not get share mode lock for "
"%s\n", fsp_str_dbg(fsp)));
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index dbc4dba448..46d5d28863 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1584,8 +1584,7 @@ NTSTATUS smbd_calculate_access_mask(connection_struct *conn,
void remove_deferred_open_entry(struct file_id id, uint64_t mid,
struct server_id pid)
{
- struct share_mode_lock *lck = get_share_mode_lock(talloc_tos(), id,
- NULL, NULL, NULL);
+ struct share_mode_lock *lck = get_share_mode_lock(talloc_tos(), id);
if (lck == NULL) {
DEBUG(0, ("could not get share mode lock\n"));
return;
@@ -1629,11 +1628,8 @@ static bool acquire_ordered_locks(TALLOC_CTX *mem_ctx,
lock on the brlock database. */
}
- *p_lck = get_share_mode_lock(mem_ctx,
- id,
- connectpath,
- smb_fname,
- p_old_write_time);
+ *p_lck = get_share_mode_lock_fresh(
+ mem_ctx, id, connectpath, smb_fname, p_old_write_time);
if (*p_lck == NULL) {
DEBUG(0, ("Could not get share mode lock\n"));
@@ -2928,8 +2924,9 @@ static NTSTATUS open_directory(connection_struct *conn,
return NT_STATUS_ACCESS_DENIED;
}
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id,
- conn->connectpath, smb_dname, &mtimespec);
+ lck = get_share_mode_lock_fresh(talloc_tos(), fsp->file_id,
+ conn->connectpath, smb_dname,
+ &mtimespec);
if (lck == NULL) {
DEBUG(0, ("open_directory: Could not get share mode lock for "
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 7a810d9a20..e1731f1e10 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -162,8 +162,7 @@ bool remove_oplock(files_struct *fsp)
struct share_mode_lock *lck;
/* Remove the oplock flag from the sharemode. */
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
- NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
if (lck == NULL) {
DEBUG(0,("remove_oplock: failed to lock share entry for "
"file %s\n", fsp_str_dbg(fsp)));
@@ -189,8 +188,7 @@ bool downgrade_oplock(files_struct *fsp)
bool ret;
struct share_mode_lock *lck;
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
- NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
if (lck == NULL) {
DEBUG(0,("downgrade_oplock: failed to lock share entry for "
"file %s\n", fsp_str_dbg(fsp)));
@@ -760,8 +758,7 @@ static void contend_level2_oplocks_begin_default(files_struct *fsp,
if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
return;
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
- NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
if (lck == NULL) {
DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
"share mode entry for file %s.\n", fsp_str_dbg(fsp)));
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 4954098de7..b8da33549c 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -6207,8 +6207,7 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
status = NT_STATUS_ACCESS_DENIED;
}
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
- NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
/*
* We have the file open ourselves, so not being able to get the
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index ec9901b99e..4e86fbfcdd 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -7572,8 +7572,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
* non-POSIX opens return SHARING_VIOLATION.
*/
- lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
- NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
if (lck == NULL) {
DEBUG(0, ("smb_posix_unlink: Could not get share mode "
"lock for file %s\n", fsp_str_dbg(fsp)));