ctdb-common: Extend srvid_exists() check to support optional private_data
authorAmitay Isaacs <amitay@gmail.com>
Wed, 30 Aug 2017 03:27:12 +0000 (13:27 +1000)
committerMartin Schwenke <martins@samba.org>
Thu, 21 Sep 2017 06:53:26 +0000 (08:53 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13042

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/common/srvid.c
ctdb/common/srvid.h
ctdb/tests/src/srvid_test.c

index f9cd49b4ea3d962c7713818f662ee9f6c5ce1f83..33049941e69b0c7e9afa6fb1bbbde8a6c7aaad90 100644 (file)
@@ -221,9 +221,10 @@ int srvid_deregister(struct srvid_context *srv, uint64_t srvid,
 /*
  * Check if a message handler exists
  */
-int srvid_exists(struct srvid_context *srv, uint64_t srvid)
+int srvid_exists(struct srvid_context *srv, uint64_t srvid, void *private_data)
 {
        struct srvid_handler_list *list;
+       struct srvid_handler *h;
        int ret;
 
        ret = srvid_fetch(srv, srvid, &list);
@@ -234,6 +235,16 @@ int srvid_exists(struct srvid_context *srv, uint64_t srvid)
                return ENOENT;
        }
 
+       if (private_data != NULL) {
+               for (h = list->h; h != NULL; h = h->next) {
+                       if (h->private_data == private_data) {
+                               return 0;
+                       }
+               }
+
+               return ENOENT;
+       }
+
        return 0;
 }
 
index f048b5c6cbfc8c58dbcaf9e0c78628240bee437d..702724ff93a79e932b2613625e0d6956c2201bb1 100644 (file)
@@ -91,11 +91,17 @@ int srvid_deregister(struct srvid_context *srv, uint64_t srvid,
 /**
  * @brief Check if any message handler is registered for srvid
  *
+ * If private_data is NULL, then check if there is any registration
+ * for * specified srvid.  If private_data is not NULL, then check for
+ * registration that matches the specified private data.
+ *
  * @param[in] srv The srvid message handler database context
  * @param[in] srvid The srvid
+ * @param[in] private_data Private data
  * @return 0 on success, errno on failure
  */
-int srvid_exists(struct srvid_context *srv, uint64_t srvid);
+int srvid_exists(struct srvid_context *srv, uint64_t srvid,
+                void *private_data);
 
 /**
  * @brief Call message handlers for given srvid
index b979c19c2f58b11f501130b3747104e9138907b7..2367c6c76911ef56a3f39bab4dca051f2b0173a0 100644 (file)
@@ -52,7 +52,10 @@ int main(void)
        ret = srvid_register(srv, tmp_ctx, TEST_SRVID, test_handler, &count);
        assert(ret == 0);
 
-       ret = srvid_exists(srv, TEST_SRVID);
+       ret = srvid_exists(srv, TEST_SRVID, NULL);
+       assert(ret == 0);
+
+       ret = srvid_exists(srv, TEST_SRVID, &count);
        assert(ret == 0);
 
        ret = srvid_dispatch(srv, TEST_SRVID, 0, tdb_null);
@@ -73,7 +76,7 @@ int main(void)
        assert(ret == 0);
 
        talloc_free(tmp_ctx);
-       ret = srvid_exists(srv, TEST_SRVID);
+       ret = srvid_exists(srv, TEST_SRVID, NULL);
        assert(ret == ENOENT);
 
        ret = srvid_dispatch(srv, TEST_SRVID, 0, tdb_null);
@@ -84,8 +87,13 @@ int main(void)
 
        ret = srvid_register(srv, tmp_ctx, TEST_SRVID, test_handler, NULL);
        assert(ret == 0);
+       ret = srvid_exists(srv, TEST_SRVID, &count);
+       assert(ret == ENOENT);
+
        ret = srvid_register(srv, tmp_ctx, TEST_SRVID, test_handler, &count);
        assert(ret == 0);
+       ret = srvid_exists(srv, TEST_SRVID, &count);
+       assert(ret == 0);
 
        talloc_free(srv);
        assert(talloc_get_size(mem_ctx) == 0);