Просмотр исходного кода

Qnetd: Implement cluster algorithm data

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Jan Friesse 9 лет назад
Родитель
Сommit
77680a3cf6

+ 15 - 0
qdevices/node-list.c

@@ -194,3 +194,18 @@ return_res:
 
 
 	return (res);
 	return (res);
 }
 }
+
+size_t
+node_list_size(const struct node_list *nlist)
+{
+	struct node_list_entry *node_entry;
+	size_t res;
+
+	res = 0;
+
+	TAILQ_FOREACH(node_entry, nlist, entries) {
+		res++;
+	}
+
+	return (res);
+}

+ 2 - 0
qdevices/node-list.h

@@ -82,6 +82,8 @@ extern struct node_list_entry *		 node_list_find_node_id(const struct node_list
 extern int				 node_list_eq(const struct node_list *list1,
 extern int				 node_list_eq(const struct node_list *list1,
     const struct node_list *list2);
     const struct node_list *list2);
 
 
+extern size_t				 node_list_size(const struct node_list *nlist);
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 26 - 1
qdevices/qnetd-algo-test.c

@@ -53,7 +53,8 @@
  * - client->decision_algorithm
  * - client->decision_algorithm
  * - client->cluster
  * - client->cluster
  *
  *
- * Callback is designed mainly for allocating client->algorithm_data.
+ * Callback is designed mainly for allocating client->algorithm_data. It's also already
+ * part of the cluster, so can access (alloc) client->cluster->algorithm_data.
  *
  *
  * client is initialized qnetd_client structure.
  * client is initialized qnetd_client structure.
  *
  *
@@ -80,6 +81,21 @@ qnetd_algo_test_client_init(struct qnetd_client *client)
 	algo_data = client->algorithm_data;
 	algo_data = client->algorithm_data;
 	*algo_data = 42;
 	*algo_data = 42;
 
 
+	if (qnetd_cluster_size(client->cluster) == 1) {
+		/*
+		 * First client in the cluster
+		 */
+		qnetd_log(LOG_INFO, "algo-test: Initializing cluster->algorithm data");
+
+		client->cluster->algorithm_data = malloc(sizeof(int));
+		if (client->cluster->algorithm_data == NULL) {
+			return (-1);
+		}
+
+		algo_data = client->cluster->algorithm_data;
+		*algo_data = 42;
+	}
+
 	return (TLV_REPLY_ERROR_CODE_NO_ERROR);
 	return (TLV_REPLY_ERROR_CODE_NO_ERROR);
 }
 }
 
 
@@ -172,6 +188,15 @@ qnetd_algo_test_client_disconnect(struct qnetd_client *client, int server_going_
 	qnetd_log(LOG_INFO, "algo-test: client_disconnect");
 	qnetd_log(LOG_INFO, "algo-test: client_disconnect");
 
 
 	free(client->algorithm_data);
 	free(client->algorithm_data);
+
+	if (qnetd_cluster_size(client->cluster) == 1) {
+		/*
+		 * Last client in the cluster
+		 */
+		qnetd_log(LOG_INFO, "algo-test: Finalizing cluster->algorithm data");
+
+		free(client->cluster->algorithm_data);
+	}
 }
 }
 
 
 /*
 /*

+ 1 - 1
qdevices/qnetd-cluster-list.c

@@ -124,7 +124,7 @@ qnetd_cluster_list_free(struct qnetd_cluster_list *list)
 }
 }
 
 
 size_t
 size_t
-qnetd_cluster_list_size(struct qnetd_cluster_list *list)
+qnetd_cluster_list_size(const struct qnetd_cluster_list *list)
 {
 {
 	size_t res;
 	size_t res;
 	struct qnetd_cluster *cluster;
 	struct qnetd_cluster *cluster;

+ 1 - 1
qdevices/qnetd-cluster-list.h

@@ -63,7 +63,7 @@ extern void				 qnetd_cluster_list_del_client(
 extern void				 qnetd_cluster_list_free(struct qnetd_cluster_list *list);
 extern void				 qnetd_cluster_list_free(struct qnetd_cluster_list *list);
 
 
 extern size_t				 qnetd_cluster_list_size(
 extern size_t				 qnetd_cluster_list_size(
-    struct qnetd_cluster_list *list);
+    const struct qnetd_cluster_list *list);
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }

+ 1 - 1
qdevices/qnetd-cluster.c

@@ -66,7 +66,7 @@ qnetd_cluster_destroy(struct qnetd_cluster *cluster)
 }
 }
 
 
 size_t
 size_t
-qnetd_cluster_size(struct qnetd_cluster *cluster)
+qnetd_cluster_size(const struct qnetd_cluster *cluster)
 {
 {
 	size_t res;
 	size_t res;
 	struct qnetd_client *client;
 	struct qnetd_client *client;

+ 1 - 1
qdevices/qnetd-cluster.h

@@ -60,7 +60,7 @@ extern int		qnetd_cluster_init(struct qnetd_cluster *cluster,
 
 
 extern void		qnetd_cluster_destroy(struct qnetd_cluster *cluster);
 extern void		qnetd_cluster_destroy(struct qnetd_cluster *cluster);
 
 
-extern size_t		qnetd_cluster_size(struct qnetd_cluster *cluster);
+extern size_t		qnetd_cluster_size(const struct qnetd_cluster *cluster);
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }