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 d0218756ade7caa116895ebbe87a48cd93cca08e..ed9f27643abb504ef587e25ce1f011933d366aa0 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 3893841b1721617c815e2fab88f182d9234ec73b..658d1ea4ffbededdb57a178f2a75821594fa85f8 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 383575a2d881dc2a092be338f981cca2ca0afe9d..db08c61c6098dad202130033c6b36e86a83e0524 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 f8833df5745092df894e4c2156dac8b741559486..3791df4d509caa1a1434d8d7715c37f6da6a58fd 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);