smbd: Factor out fsps_lease_update()
authorVolker Lendecke <vl@samba.org>
Fri, 24 May 2019 14:50:30 +0000 (16:50 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 28 May 2019 20:27:15 +0000 (20:27 +0000)
Less lines of code, less .text bytes with -O3

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/oplock.c

index ba5db38daef5081d0de385aae2b2b1e22b6c8dfd..aad85fbb2d18d626a931cab551ecb6e41d896c52 100644 (file)
@@ -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)));