[sheepdog] [PATCH 1/6] sheep: avoid atomic operations against uint64_t/int64_t variables

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Wed Sep 19 06:25:40 CEST 2012


On 32 bit architectures, atomic operations against 64 bit integers are
not allowed.  This patch uses more proper types for them.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/node.c        |    3 ++-
 sheep/object_cache.c |    6 +++---
 sheep/ops.c          |    2 +-
 sheep/sheep.c        |    9 +++++----
 sheep/sheep_priv.h   |    2 +-
 sheep/work.c         |    2 +-
 6 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/collie/node.c b/collie/node.c
index e86e4da..b5aeec1 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -143,7 +143,8 @@ static int node_recovery(int argc, char **argv)
 static int node_cache(int argc, char **argv)
 {
 	char *p;
-	int fd, ret, cache_size;
+	int fd, ret;
+	uint32_t cache_size;
 	unsigned int wlen, rlen = 0;
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 959ca15..79c56cb 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -48,7 +48,7 @@
 
 
 struct global_cache {
-	uint64_t cache_size;
+	uint32_t cache_size;
 	int in_reclaim;
 	struct cds_list_head cache_lru_list;
 };
@@ -515,8 +515,8 @@ static int do_reclaim_object(struct object_cache_entry *entry)
 		goto out;
 	}
 
-	dprintf("oid %"PRIx64" reclaimed successfully, cache_size: %ld\n", oid,
-		uatomic_read(&sys_cache.cache_size));
+	dprintf("oid %"PRIx64" reclaimed successfully, cache_size: %"PRId32"\n",
+		oid, uatomic_read(&sys_cache.cache_size));
 	del_from_object_tree_and_list(entry, &oc->object_tree);
 out:
 	pthread_rwlock_unlock(&oc->lock);
diff --git a/sheep/ops.c b/sheep/ops.c
index 02f43b1..ac02683 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -614,7 +614,7 @@ static int cluster_recovery_completion(const struct sd_req *req,
 static int local_set_cache_size(const struct sd_req *req, struct sd_rsp *rsp,
 				  void *data)
 {
-	int cache_size = *(int *)data;
+	uint32_t cache_size = *(uint32_t *)data;
 
 	uatomic_set(&sys->object_cache_size, cache_size);
 	dprintf("Max cache size set to %dM\n", cache_size);
diff --git a/sheep/sheep.c b/sheep/sheep.c
index cdf447d..e3d079e 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -193,13 +193,14 @@ static void object_cache_size_set(char *s)
 	const char *header = "size=";
 	int len = strlen(header);
 	char *size, *p;
-	int64_t cache_size;
+	uint32_t cache_size;
+	uint32_t max_cache_size = UINT32_MAX / 1024 / 1024;
 
 	assert(!strncmp(s, header, len));
 
 	size = s + len;
 	cache_size = strtol(size, &p, 10);
-	if (size == p || cache_size < 0 || UINT64_MAX < cache_size)
+	if (size == p || cache_size < 0 || max_cache_size < cache_size)
 		goto err;
 
 	sys->object_cache_size = cache_size * 1024 * 1024;
@@ -207,8 +208,8 @@ static void object_cache_size_set(char *s)
 
 err:
 	fprintf(stderr, "Invalid object cache option '%s': "
-		"size must be an integer between 0 and %lu\n",
-		s, UINT64_MAX);
+		"size must be an integer between 0 and %"PRIu32"\n",
+		s, max_cache_size);
 	exit(1);
 }
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 66f2863..cad25ce 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -120,7 +120,7 @@ struct cluster_info {
 #define CACHE_TYPE_DISK   0x2
 	int enabled_cache_type;
 
-	uint64_t object_cache_size;
+	uint32_t object_cache_size;
 	bool object_cache_directio;
 
 	bool use_journal;
diff --git a/sheep/work.c b/sheep/work.c
index d96026d..4240db9 100644
--- a/sheep/work.c
+++ b/sheep/work.c
@@ -62,7 +62,7 @@ static void *run_short_thread(void *arg)
 {
 	struct short_work *sw = arg;
 	eventfd_t value = 1;
-	static uint64_t idx = 0;
+	static unsigned long idx = 0;
 	int err;
 
 	/* Tell runtime to release resources after termination */
-- 
1.7.2.5




More information about the sheepdog mailing list