s3: Add "share_mode_stale_pid"
authorVolker Lendecke <vl@samba.org>
Mon, 7 May 2012 10:57:07 +0000 (12:57 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 25 May 2012 16:19:37 +0000 (09:19 -0700)
This is a helper routine that prunes a dead share mode entry on demand. This
prepares for removing the serverids_exist call in parse_share_modes.

Signed-off-by: Jeremy Allison <jra@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/locking/locking.c
source3/locking/proto.h

index b9afd2392c46f973581e4d930cf8316837179b7c..df211040285ae30db396409962eef02472cb3c11 100644 (file)
@@ -625,6 +625,38 @@ bool is_deferred_open_entry(const struct share_mode_entry *e)
        return (e->op_type == DEFERRED_OPEN_ENTRY);
 }
 
+/*
+ * In case d->share_modes[i] conflicts with something or otherwise is
+ * being used, we need to make sure the corresponding process still
+ * exists. This routine checks it and potentially removes the entry
+ * from d->share_modes. Modifies d->num_share_modes, watch out in
+ * routines iterating over that array.
+ */
+bool share_mode_stale_pid(struct share_mode_data *d, unsigned i)
+{
+       struct share_mode_entry *e;
+
+       if (i > d->num_share_modes) {
+               DEBUG(1, ("Asking for index %u, only %u around\n",
+                         i, (unsigned)d->num_share_modes));
+               return false;
+       }
+       e = &d->share_modes[i];
+       if (serverid_exists(&e->pid)) {
+               DEBUG(10, ("PID %s (index %u out of %u) still exists\n",
+                          procid_str_static(&e->pid), i,
+                          (unsigned)d->num_share_modes));
+               return false;
+       }
+       DEBUG(10, ("PID %s (index %u out of %u) does not exist anymore\n",
+                  procid_str_static(&e->pid), i,
+                  (unsigned)d->num_share_modes));
+       *e = d->share_modes[d->num_share_modes-1];
+       d->num_share_modes -= 1;
+       d->modified = true;
+       return true;
+}
+
 /*******************************************************************
  Fill a share mode entry.
 ********************************************************************/
index 54badd91498c3b188811e7a207f69cbb7305dd65..f6a6f2ee12d94155b9cbe119e51613c6b77b1905 100644 (file)
@@ -168,6 +168,7 @@ 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 share_mode_stale_pid(struct share_mode_data *d, unsigned i);
 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,