[sheepdog] [PATCH 04/10] collie: fix 'node info'

Liu Yuan namei.unix at gmail.com
Sun May 26 15:40:38 CEST 2013


Always return the actual size instead of from sys->disk_space

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/md.c         |   25 +++++++++++++++++++------
 sheep/ops.c        |   23 +++++------------------
 sheep/sheep_priv.h |    1 +
 3 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/sheep/md.c b/sheep/md.c
index 291ffca..33f7ab3 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -234,7 +234,7 @@ static int for_each_object_in_path(char *path,
 	return ret;
 }
 
-static uint64_t get_path_size(char *path, uint64_t *used)
+static uint64_t get_path_free_size(char *path, uint64_t *used)
 {
 	struct statvfs fs;
 	uint64_t size;
@@ -286,7 +286,7 @@ static uint64_t init_path_space(char *path)
 
 	return size;
 create:
-	size = get_path_size(path, NULL);
+	size = get_path_free_size(path, NULL);
 	if (!size)
 		goto broken_path;
 	if (setxattr(path, MDNAME, &size, MDSIZE, 0) < 0) {
@@ -432,7 +432,7 @@ static void md_do_recover(struct work *work)
 		/* Just ignore the duplicate EIO of the same path */
 		goto out;
 	remove_disk(idx);
-	sys->disk_space = md_init_space();
+	md_init_space();
 	nr = md_nr_disks;
 out:
 	pthread_rwlock_unlock(&md_lock);
@@ -606,8 +606,8 @@ uint32_t md_get_info(struct sd_md_info *info)
 		info->disk[i].idx = i;
 		pstrcpy(info->disk[i].path, PATH_MAX, md_disks[i].path);
 		/* FIXME: better handling failure case. */
-		info->disk[i].size = get_path_size(info->disk[i].path,
-						   &info->disk[i].used);
+		info->disk[i].size = get_path_free_size(info->disk[i].path,
+							&info->disk[i].used);
 	}
 	info->nr = md_nr_disks;
 	pthread_rwlock_unlock(&md_lock);
@@ -646,7 +646,7 @@ static int do_plug_unplug(char *disks, bool plug)
 	if (old_nr == md_nr_disks)
 		goto out;
 
-	sys->disk_space = md_init_space();
+	md_init_space();
 	cur_nr = md_nr_disks;
 
 	ret = SD_RES_SUCCESS;
@@ -673,3 +673,16 @@ int md_unplug_disks(char *disks)
 {
 	return do_plug_unplug(disks, false);
 }
+
+uint64_t md_get_size(uint64_t *used)
+{
+	uint64_t fsize = 0;
+	*used = 0;
+
+	pthread_rwlock_rdlock(&md_lock);
+	for (int i = 0; i < md_nr_disks; i++)
+		fsize += get_path_free_size(md_disks[i].path, used);
+	pthread_rwlock_unlock(&md_lock);
+
+	return fsize + *used;
+}
diff --git a/sheep/ops.c b/sheep/ops.c
index 4c9cd3d..8f798f3 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -61,31 +61,18 @@ struct sd_op_template {
 	int (*process_main)(const struct sd_req *req, struct sd_rsp *rsp, void *data);
 };
 
-static int get_total_object_size(uint64_t oid, char *ignore, void *total)
-{
-	uint64_t *t = total;
-	*t += get_objsize(oid);
-
-	return SD_RES_SUCCESS;
-}
-
 static int stat_sheep(uint64_t *store_size, uint64_t *store_free,
 		      uint32_t epoch)
 {
-	uint64_t used = 0;
-	int ret;
+	uint64_t used;
 
-	ret = for_each_object_in_wd(get_total_object_size, false, &used);
-	if (ret != SD_RES_SUCCESS)
-		goto out;
-
-	*store_size = sys->disk_space;
+	*store_size = md_get_size(&used);
 	if (sys->gateway_only)
 		*store_free = 0;
 	else
-		*store_free = sys->disk_space - used;
-out:
-	return ret;
+		*store_free = *store_size - used;
+
+	return SD_RES_SUCCESS;
 }
 
 static int cluster_new_vdi(struct request *req)
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index f3fb09e..febc9b9 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -413,5 +413,6 @@ int md_get_stale_path(uint64_t oid, uint32_t epoch, char *path);
 uint32_t md_get_info(struct sd_md_info *info);
 int md_plug_disks(char *disks);
 int md_unplug_disks(char *disks);
+uint64_t md_get_size(uint64_t *used);
 
 #endif
-- 
1.7.9.5




More information about the sheepdog mailing list