s3: Remove UNUSED_SHARE_MODE_ENTRY
authorVolker Lendecke <vl@samba.org>
Wed, 14 Dec 2011 09:35:56 +0000 (10:35 +0100)
committerVolker Lendecke <vl@samba.org>
Wed, 14 Dec 2011 16:34:21 +0000 (17:34 +0100)
source3/include/smb.h
source3/locking/locking.c
source3/locking/proto.h
source3/smbd/open.c

index 3451123dee190e4a4fd4c25d229db5790b456179..0724b7ce8266cd21359d4adcb07c46731acdadb9 100644 (file)
@@ -1070,11 +1070,11 @@ enum acl_compatibility {ACL_COMPAT_AUTO, ACL_COMPAT_WINNT, ACL_COMPAT_WIN2K};
                                 * inform potential level2 holders on
                                 * write. */
 #define DEFERRED_OPEN_ENTRY            0x20
-#define UNUSED_SHARE_MODE_ENTRY        0x40
+/* #define UNUSED_SHARE_MODE_ENTRY     0x40 */   /* Not used anymore */
 #define FORCE_OPLOCK_BREAK_TO_NONE     0x80
 
 /* None of the following should ever appear in fsp->oplock_request. */
-#define SAMBA_PRIVATE_OPLOCK_MASK (INTERNAL_OPEN_ONLY|DEFERRED_OPEN_ENTRY|UNUSED_SHARE_MODE_ENTRY|FORCE_OPLOCK_BREAK_TO_NONE)
+#define SAMBA_PRIVATE_OPLOCK_MASK (INTERNAL_OPEN_ONLY|DEFERRED_OPEN_ENTRY|FORCE_OPLOCK_BREAK_TO_NONE)
 
 #define EXCLUSIVE_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)EXCLUSIVE_OPLOCK|(unsigned int)BATCH_OPLOCK))
 #define BATCH_OPLOCK_TYPE(lck) ((lck) & (unsigned int)BATCH_OPLOCK)
index b0f719bb48b7ad16dbb8eed3dce724d52f4b1d53..39d3f28e26812d9cb9617dfc840947f0c76b72aa 100644 (file)
@@ -495,12 +495,11 @@ static TDB_DATA locking_key(const struct file_id *id, struct file_id *tmp)
 
 char *share_mode_str(TALLOC_CTX *ctx, int num, const struct share_mode_entry *e)
 {
-       return talloc_asprintf(ctx, "share_mode_entry[%d]: %s "
+       return talloc_asprintf(ctx, "share_mode_entry[%d]: "
                 "pid = %s, share_access = 0x%x, private_options = 0x%x, "
                 "access_mask = 0x%x, mid = 0x%llx, type= 0x%x, gen_id = %lu, "
                 "uid = %u, flags = %u, file_id %s, name_hash = 0x%x",
                 num,
-                e->op_type == UNUSED_SHARE_MODE_ENTRY ? "UNUSED" : "",
                 procid_str_static(&e->pid),
                 e->share_access, e->private_options,
                 e->access_mask, (unsigned long long)e->op_mid,
@@ -562,12 +561,16 @@ static bool parse_share_modes(const TDB_DATA dbuf, struct share_mode_lock *lck)
                smb_panic("parse_share_modes: serverids_exist failed");
        }
 
-       for (i = 0; i < lck->num_share_modes; i++) {
-               struct share_mode_entry *entry_p = &lck->share_modes[i];
+       i = 0;
+       while (i < lck->num_share_modes) {
+               struct share_mode_entry *e = &lck->share_modes[i];
                if (!pid_exists[i]) {
-                       entry_p->op_type = UNUSED_SHARE_MODE_ENTRY;
+                       *e = lck->share_modes[lck->num_share_modes-1];
+                       lck->num_share_modes -= 1;
                        lck->modified = True;
+                       continue;
                }
+               i += 1;
        }
        TALLOC_FREE(pid_exists);
        TALLOC_FREE(pids);
@@ -579,19 +582,13 @@ static TDB_DATA unparse_share_modes(struct share_mode_lock *lck)
 {
        DATA_BLOB blob;
        enum ndr_err_code ndr_err;
-       uint32_t i;
 
        if (DEBUGLEVEL >= 10) {
                DEBUG(10, ("unparse_share_modes:\n"));
                NDR_PRINT_DEBUG(share_mode_lock, lck);
        }
 
-       for (i=0; i<lck->num_share_modes; i++) {
-               if (!is_unused_share_mode_entry(&lck->share_modes[i])) {
-                       break;
-               }
-       }
-       if (i == lck->num_share_modes) {
+       if (lck->num_share_modes == 0) {
                DEBUG(10, ("No used share mode found\n"));
                return make_tdb_data(NULL, 0);
        }
@@ -773,6 +770,10 @@ struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
                TALLOC_FREE(lck);
                return NULL;
        }
+       if (data.dptr == NULL) {
+               TALLOC_FREE(lck);
+               return NULL;
+       }
 
        if (!fill_share_mode_lock(lck, id, NULL, NULL, data, NULL)) {
                DEBUG(10, ("fetch_share_mode_unlocked: no share_mode record "
@@ -936,14 +937,6 @@ bool is_valid_share_mode_entry(const struct share_mode_entry *e)
 {
        int num_props = 0;
 
-       if (e->op_type == UNUSED_SHARE_MODE_ENTRY) {
-               /* cope with dead entries from the process not
-                  existing. These should not be considered valid,
-                  otherwise we end up doing zero timeout sharing
-                  violation */
-               return False;
-       }
-
        num_props += ((e->op_type == NO_OPLOCK) ? 1 : 0);
        num_props += (EXCLUSIVE_OPLOCK_TYPE(e->op_type) ? 1 : 0);
        num_props += (LEVEL_II_OPLOCK_TYPE(e->op_type) ? 1 : 0);
@@ -957,11 +950,6 @@ bool is_deferred_open_entry(const struct share_mode_entry *e)
        return (e->op_type == DEFERRED_OPEN_ENTRY);
 }
 
-bool is_unused_share_mode_entry(const struct share_mode_entry *e)
-{
-       return (e->op_type == UNUSED_SHARE_MODE_ENTRY);
-}
-
 /*******************************************************************
  Fill a share mode entry.
 ********************************************************************/
@@ -1006,21 +994,8 @@ static void fill_deferred_open_entry(struct share_mode_entry *e,
 static void add_share_mode_entry(struct share_mode_lock *lck,
                                 const struct share_mode_entry *entry)
 {
-       int i;
-
-       for (i=0; i<lck->num_share_modes; i++) {
-               struct share_mode_entry *e = &lck->share_modes[i];
-               if (is_unused_share_mode_entry(e)) {
-                       *e = *entry;
-                       break;
-               }
-       }
-
-       if (i == lck->num_share_modes) {
-               /* No unused entry found */
-               ADD_TO_ARRAY(lck, struct share_mode_entry, *entry,
-                            &lck->share_modes, &lck->num_share_modes);
-       }
+       ADD_TO_ARRAY(lck, struct share_mode_entry, *entry,
+                    &lck->share_modes, &lck->num_share_modes);
        lck->modified = True;
 }
 
@@ -1105,8 +1080,8 @@ bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp)
        if (e == NULL) {
                return False;
        }
-
-       e->op_type = UNUSED_SHARE_MODE_ENTRY;
+       *e = lck->share_modes[lck->num_share_modes-1];
+       lck->num_share_modes -= 1;
        lck->modified = True;
        return True;
 }
@@ -1123,8 +1098,8 @@ void del_deferred_open_entry(struct share_mode_lock *lck, uint64_t mid,
        if (e == NULL) {
                return;
        }
-
-       e->op_type = UNUSED_SHARE_MODE_ENTRY;
+       *e = lck->share_modes[lck->num_share_modes-1];
+       lck->num_share_modes -= 1;
        lck->modified = True;
 }
 
index 2c01634d310e11d2e3f5c5c9ae7b1afba383baf5..d6f1c1bf4ae6c8925a5a9068f49c1974cc766759 100644 (file)
@@ -165,7 +165,6 @@ void get_file_infos(struct file_id id,
                    struct timespec *write_time);
 bool is_valid_share_mode_entry(const struct share_mode_entry *e);
 bool is_deferred_open_entry(const struct share_mode_entry *e);
-bool is_unused_share_mode_entry(const struct share_mode_entry *e);
 void set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
                    uid_t uid, uint64_t mid, uint16 op_type);
 void add_deferred_open(struct share_mode_lock *lck, uint64_t mid,
index 265de2718488f5ad7553cc436fc667f256863222..461206893be6a8601a019ad875605e2c41948b2e 100644 (file)
@@ -911,8 +911,7 @@ static void validate_my_share_entries(struct smbd_server_connection *sconn,
                          "share entry with an open file\n");
        }
 
-       if (is_deferred_open_entry(share_entry) ||
-           is_unused_share_mode_entry(share_entry)) {
+       if (is_deferred_open_entry(share_entry)) {
                goto panic;
        }