leases_db: Add share_mode_lease info to leases.tdb
authorVolker Lendecke <vl@samba.org>
Tue, 11 Sep 2018 14:13:24 +0000 (16:13 +0200)
committerChristof Schmitt <cs@samba.org>
Sun, 14 Apr 2019 04:01:30 +0000 (04:01 +0000)
This is the data stored in share_mode_lease inside the leases[] array in
locking.tdb. This and all the following patches move all leases array to
looking at the leases.tdb.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
source3/librpc/idl/leases_db.idl
source3/locking/leases_db.c
source3/locking/leases_db.h
source3/smbd/open.c

index d021875..ed9f276 100644 (file)
@@ -22,6 +22,32 @@ interface leases_db
        } leases_db_file;
 
        typedef [public] struct {
+               smb2_lease_state        current_state;
+               /*
+                * 'breaking' indicates that we're waiting
+                * for a lease break ack from the client
+                * and breaking_to_requested and breaking_to_required
+                * have a meaning.
+                *
+                * breaking_to_requested is the value already sent to
+                * the client, the client needs to ack to this (or less).
+                *
+                * breaking_to_required is the internal value that needs to
+                * be reached before we can reset breaking = false, this
+                * may requires multiple roundtrips to the client, e.g.
+                * when the lease broken to a more reduced value, while
+                * the lease break is still in progress.
+                *
+                * The following can be assumed (if breaking == true):
+                *
+                * current_state>breaking_to_requested>=breaking_to_required
+                */
+               boolean8                breaking;
+               smb2_lease_state        breaking_to_requested;
+               smb2_lease_state        breaking_to_required;
+               uint16                  lease_version;
+               uint16                  epoch;
+
                uint32 num_files;
                [size_is(num_files)] leases_db_file files[];
        } leases_db_value;
index 3893841..658d1ea 100644 (file)
@@ -196,6 +196,9 @@ static NTSTATUS leases_db_do_locked(
 
 struct leases_db_add_state {
        const struct file_id *id;
+       uint32_t current_state;
+       uint16_t lease_version;
+       uint16_t epoch;
        const char *servicepath;
        const char *base_name;
        const char *stream_name;
@@ -217,6 +220,13 @@ static void leases_db_add_fn(
                }
        }
 
+       if (value->num_files == 0) {
+               /* new record */
+               value->current_state = state->current_state;
+               value->lease_version = state->lease_version;
+               value->epoch = state->epoch;
+       }
+
        tmp = talloc_realloc(
                value,
                value->files,
@@ -242,12 +252,18 @@ static void leases_db_add_fn(
 NTSTATUS leases_db_add(const struct GUID *client_guid,
                       const struct smb2_lease_key *lease_key,
                       const struct file_id *id,
+                      uint32_t current_state,
+                      uint16_t lease_version,
+                      uint16_t epoch,
                       const char *servicepath,
                       const char *base_name,
                       const char *stream_name)
 {
        struct leases_db_add_state state = {
                .id = id,
+               .current_state = current_state,
+               .lease_version = lease_version,
+               .epoch = epoch,
                .servicepath = servicepath,
                .base_name = base_name,
                .stream_name = stream_name,
index 383575a..db08c61 100644 (file)
@@ -30,6 +30,9 @@ bool leases_db_init(bool read_only);
 NTSTATUS leases_db_add(const struct GUID *client_guid,
                       const struct smb2_lease_key *lease_key,
                       const struct file_id *id,
+                      uint32_t current_state,
+                      uint16_t lease_version,
+                      uint16_t epoch,
                       const char *servicepath,
                       const char *filename,
                       const char *stream_name);
index f8833df..3791df4 100644 (file)
@@ -2142,6 +2142,9 @@ static NTSTATUS grant_fsp_lease(struct files_struct *fsp,
        status = leases_db_add(client_guid,
                               &lease->lease_key,
                               &fsp->file_id,
+                              fsp->lease->lease.lease_state,
+                              fsp->lease->lease.lease_version,
+                              fsp->lease->lease.lease_epoch,
                               fsp->conn->connectpath,
                               fsp->fsp_name->base_name,
                               fsp->fsp_name->stream_name);