[sheepdog] [PATCH 2/7] sheep: fix stat_sheep()

Liu Yuan namei.unix at gmail.com
Mon Aug 13 10:13:59 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

- use sys->disk_space instead of a duplicate sys call
- use bytes internally for disk space calculation

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/ops.c   |   11 ++---------
 sheep/sheep.c |    2 +-
 sheep/store.c |    8 ++++----
 3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/sheep/ops.c b/sheep/ops.c
index 0cddf66..8ca8748 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -63,7 +63,6 @@ struct sd_op_template {
 
 static int stat_sheep(uint64_t *store_size, uint64_t *store_free, uint32_t epoch)
 {
-	struct statvfs vs;
 	int ret;
 	DIR *dir;
 	struct dirent *d;
@@ -72,12 +71,6 @@ static int stat_sheep(uint64_t *store_size, uint64_t *store_free, uint32_t epoch
 	char path[1024];
 	struct strbuf store_dir = STRBUF_INIT;
 
-	ret = statvfs(mnt_path, &vs);
-	if (ret) {
-		ret = SD_RES_EIO;
-		goto out;
-	}
-
 	strbuf_addf(&store_dir, "%s", obj_path);
 	dir = opendir(store_dir.buf);
 	if (!dir) {
@@ -101,8 +94,8 @@ static int stat_sheep(uint64_t *store_size, uint64_t *store_free, uint32_t epoch
 	closedir(dir);
 	ret = SD_RES_SUCCESS;
 
-	*store_size = (uint64_t)vs.f_frsize * vs.f_bfree + used;
-	*store_free = (uint64_t)vs.f_frsize * vs.f_bfree;
+	*store_size = sys->disk_space;
+	*store_free = sys->disk_space - used;
 out:
 	strbuf_release(&store_dir);
 	return ret;
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 1800178..c743184 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -294,7 +294,7 @@ int main(int argc, char **argv)
 					optarg, UINT64_MAX);
 				exit(1);
 			}
-			sys->disk_space = free_space;
+			sys->disk_space = free_space * 1024 * 1024;
 			break;
 		case 'c':
 			sys->cdrv = find_cdrv(optarg);
diff --git a/sheep/store.c b/sheep/store.c
index b093916..542804a 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -449,7 +449,7 @@ static int init_disk_space(const char *base_path)
 {
 	int ret = SD_RES_SUCCESS;
 	uint64_t space_size = 0;
-	struct statfs sf;
+	struct statvfs fs;
 
 	if (sys->gateway_only)
 		goto out;
@@ -465,17 +465,17 @@ static int init_disk_space(const char *base_path)
 		goto out;
 	}
 
-	ret = statfs(base_path, &sf);
+	ret = statvfs(base_path, &fs);
 	if (ret < 0) {
 		dprintf("get disk space failed %m\n");
 		ret = SD_RES_EIO;
 		goto out;
 	}
 
-	sys->disk_space = sf.f_bfree * 4 / 1024;
+	sys->disk_space = (uint64_t)fs.f_frsize * fs.f_bfree;
 	ret = set_cluster_space(sys->disk_space);
 out:
-	dprintf("disk free space is %" PRIu64 "M\n", sys->disk_space);
+	dprintf("disk free space is %" PRIu64 "\n", sys->disk_space);
 	return ret;
 }
 
-- 
1.7.10.2




More information about the sheepdog mailing list