s3:locking:brlock: use serverids_exist to validate_lock_entries
authorGregor Beck <gbeck@sernet.de>
Tue, 5 Mar 2013 13:02:10 +0000 (14:02 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 18 Apr 2013 11:15:12 +0000 (13:15 +0200)
...instead of checking each server-id separately which can
be expensive in a cluster.

Signed-off-by: Gregor Beck <gbeck@sernet.de>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/locking/brlock.c

index c5bbcd181c47f59fcf64697f7030b335c93674ce..3f23961ec27ca6dda18643ff203046ab1de85b2b 100644 (file)
@@ -1655,17 +1655,48 @@ static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct
        unsigned int i;
        unsigned int num_valid_entries = 0;
        struct lock_struct *locks = *pplocks;
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct server_id *ids;
+       bool *exists;
+
+       ids = talloc_array(frame, struct server_id, *pnum_entries);
+       if (ids == NULL) {
+               DEBUG(0, ("validate_lock_entries: "
+                         "talloc_array(struct server_id, %u) failed\n",
+                         *pnum_entries));
+               talloc_free(frame);
+               return false;
+       }
+
+       exists = talloc_array(frame, bool, *pnum_entries);
+       if (exists == NULL) {
+               DEBUG(0, ("validate_lock_entries: "
+                         "talloc_array(bool, %u) failed\n",
+                         *pnum_entries));
+               talloc_free(frame);
+               return false;
+       }
+
+       for (i = 0; i < *pnum_entries; i++) {
+               ids[i] = locks[i].context.pid;
+       }
+
+       if (!serverids_exist(ids, *pnum_entries, exists)) {
+               DEBUG(3, ("validate_lock_entries: serverids_exists failed\n"));
+               talloc_free(frame);
+               return false;
+       }
 
        for (i = 0; i < *pnum_entries; i++) {
-               struct lock_struct *lock_data = &locks[i];
-               if (!serverid_exists(&lock_data->context.pid)) {
+               if (!exists[i]) {
                        /* This process no longer exists - mark this
                           entry as invalid by zeroing it. */
-                       ZERO_STRUCTP(lock_data);
+                       ZERO_STRUCTP(&locks[i]);
                } else {
                        num_valid_entries++;
                }
        }
+       TALLOC_FREE(frame);
 
        if (num_valid_entries != *pnum_entries) {
                struct lock_struct *new_lock_data = NULL;