From 953f9f7b6d21c4cb2cea6033af240b0bac1cabeb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 24 May 2019 16:50:30 +0200 Subject: [PATCH] smbd: Factor out fsps_lease_update() Less lines of code, less .text bytes with -O3 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/smbd/oplock.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c index ba5db38daef5..aad85fbb2d18 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -523,17 +523,16 @@ static void downgrade_lease_additional_trigger(struct tevent_context *ev, } } -struct downgrade_lease_fsps_state { - struct file_id id; - struct share_mode_lock *lck; +struct fsps_lease_update_state { + const struct file_id *id; const struct smb2_lease_key *key; }; -static struct files_struct *downgrade_lease_fsps(struct files_struct *fsp, - void *private_data) +static struct files_struct *fsps_lease_update_fn( + struct files_struct *fsp, void *private_data) { - struct downgrade_lease_fsps_state *state = - (struct downgrade_lease_fsps_state *)private_data; + struct fsps_lease_update_state *state = + (struct fsps_lease_update_state *)private_data; if (fsp->oplock_type != LEASE_OPLOCK) { return NULL; @@ -541,7 +540,7 @@ static struct files_struct *downgrade_lease_fsps(struct files_struct *fsp, if (!smb2_lease_key_equal(&fsp->lease->lease.lease_key, state->key)) { return NULL; } - if (!file_id_equal(&fsp->file_id, &state->id)) { + if (!file_id_equal(&fsp->file_id, state->id)) { return NULL; } @@ -550,6 +549,14 @@ static struct files_struct *downgrade_lease_fsps(struct files_struct *fsp, return NULL; } +static void fsps_lease_update(struct smbd_server_connection *sconn, + const struct file_id *id, + const struct smb2_lease_key *key) +{ + struct fsps_lease_update_state state = { .id = id, .key = key }; + files_forall(sconn, fsps_lease_update_fn, &state); +} + NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn, uint32_t num_file_ids, const struct file_id *ids, @@ -748,13 +755,7 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn, */ lck->data->modified = true; - { - struct downgrade_lease_fsps_state state = { - .id = id, .lck = lck, .key = key, - }; - - files_forall(sconn, downgrade_lease_fsps, &state); - } + fsps_lease_update(sconn, &id, key); TALLOC_FREE(lck); DEBUG(10, ("%s: Downgrading %s to %x => %s\n", __func__, @@ -771,13 +772,7 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn, return NT_STATUS_OBJECT_NAME_NOT_FOUND; } - { - struct downgrade_lease_fsps_state state = { - .id = ids[i], .lck = lck, .key = key, - }; - - files_forall(sconn, downgrade_lease_fsps, &state); - } + fsps_lease_update(sconn, &ids[i], key); DEBUG(10, ("%s: Downgrading %s to %x => %s\n", __func__, file_id_string_tos(&ids[i]), (unsigned)lease_state, nt_errstr(status))); -- 2.34.1