[sheepdog] [PATCH consolidate the MAX_EVENT_BUF_SIZE definitions
Christoph Hellwig
hch at infradead.org
Sun May 20 19:51:53 CEST 2012
The accord, local and zookeeper drivers all need an upper bound of the
message size the sheepdog might send for their communication queues.
Centralize the definition into a single place, and make sure we never
send larger messages from the core sheepdog code.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
sheep/cluster.h | 3 +++
sheep/cluster/accord.c | 4 +---
sheep/cluster/local.c | 3 +--
sheep/cluster/zookeeper.c | 3 +--
sheep/group.c | 2 ++
5 files changed, 8 insertions(+), 7 deletions(-)
Index: sheepdog/sheep/cluster.h
===================================================================
--- sheepdog.orig/sheep/cluster.h 2012-05-20 16:18:51.094558848 +0200
+++ sheepdog/sheep/cluster.h 2012-05-20 19:37:26.656020841 +0200
@@ -22,6 +22,9 @@
#include "sheep.h"
#include "logger.h"
+/* maximum payload size sent in ->notify and ->unblock */
+#define SD_MAX_EVENT_BUF_SIZE (64 * 1024)
+
enum cluster_join_result {
CJ_RES_SUCCESS, /* Success */
CJ_RES_FAIL, /* Fail to join. The joining node has an invalidepoch. */
Index: sheepdog/sheep/cluster/accord.c
===================================================================
--- sheepdog.orig/sheep/cluster/accord.c 2012-05-20 16:18:51.094558848 +0200
+++ sheepdog/sheep/cluster/accord.c 2012-05-20 19:36:44.304019756 +0200
@@ -23,8 +23,6 @@
#include "event.h"
#include "work.h"
-#define MAX_EVENT_BUF_SIZE (64 * 1024)
-
#define BASE_FILE "/sheepdog"
#define LOCK_FILE BASE_FILE "/lock"
#define QUEUE_FILE BASE_FILE "/queue"
@@ -40,7 +38,7 @@ struct acrd_event {
struct sd_node sender;
size_t buf_len;
- uint8_t buf[MAX_EVENT_BUF_SIZE];
+ uint8_t buf[SD_MAX_EVENT_BUF_SIZE];
size_t nr_nodes; /* the number of sheep */
struct sd_node nodes[SD_MAX_NODES];
Index: sheepdog/sheep/cluster/local.c
===================================================================
--- sheepdog.orig/sheep/cluster/local.c 2012-05-20 19:35:32.388017915 +0200
+++ sheepdog/sheep/cluster/local.c 2012-05-20 19:37:33.636021021 +0200
@@ -25,7 +25,6 @@
#include "work.h"
#define MAX_EVENTS 500
-#define MAX_EVENT_BUF_SIZE (64 * 1024)
const char *shmfile = "/tmp/sheepdog_shm";
static int shmfd;
@@ -46,7 +45,7 @@ struct local_event {
struct sd_node sender;
size_t buf_len;
- uint8_t buf[MAX_EVENT_BUF_SIZE];
+ uint8_t buf[SD_MAX_EVENT_BUF_SIZE];
size_t nr_nodes; /* the number of sheep processes */
struct sd_node nodes[SD_MAX_NODES];
Index: sheepdog/sheep/cluster/zookeeper.c
===================================================================
--- sheepdog.orig/sheep/cluster/zookeeper.c 2012-05-20 16:18:51.094558848 +0200
+++ sheepdog/sheep/cluster/zookeeper.c 2012-05-20 19:38:10.472021965 +0200
@@ -23,7 +23,6 @@
#include "event.h"
#include "work.h"
-#define MAX_EVENT_BUF_SIZE (64 * 1024)
#define SESSION_TIMEOUT 30000 /* millisecond */
#define MEMBER_CREATE_TIMEOUT SESSION_TIMEOUT
#define MEMBER_CREATE_INTERVAL 10 /* millisecond */
@@ -82,7 +81,7 @@ struct zk_event {
int callbacked; /* set non-zero after sd_block_handler() was called */
size_t buf_len;
- uint8_t buf[MAX_EVENT_BUF_SIZE];
+ uint8_t buf[SD_MAX_EVENT_BUF_SIZE];
};
static int zk_notify_blocked;
Index: sheepdog/sheep/group.c
===================================================================
--- sheepdog.orig/sheep/group.c 2012-05-20 16:18:51.098558849 +0200
+++ sheepdog/sheep/group.c 2012-05-20 19:38:56.260023135 +0200
@@ -247,6 +247,8 @@ static struct vdi_op_message *prepare_cl
else
size = sizeof(*msg);
+ assert(size <= SD_MAX_EVENT_BUF_SIZE);
+
msg = zalloc(size);
if (!msg) {
eprintf("failed to allocate memory\n");
More information about the sheepdog
mailing list