summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/dht/src/dht-common.c
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2010-10-06 05:23:44 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-10-27 00:47:59 -0700
commitc02cd37866ae22e3a433d737f3c80395bb72f002 (patch)
treef36b11adfec519aa6c938356522b8f93614469d2 /xlators/cluster/dht/src/dht-common.c
parent40dd9e9e18c5de009baf9e437d3222fa6b473237 (diff)
distribute: bring in statfs normalization
We had normalization of statvfs structure in 'cluster/unify' translator, with distribute, we had this section as 'TODO:'. Now, the same code is migrated to distribute. Thanks to <marty.rosenberg@gmail.com> for sending the patches Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1035 (The distribute translator does not handle differently sized block sizes and/or fragment sizes) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1035
Diffstat (limited to 'xlators/cluster/dht/src/dht-common.c')
-rw-r--r--xlators/cluster/dht/src/dht-common.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index 9caa3dc5b..d1e04b16a 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -2432,13 +2432,37 @@ err:
return 0;
}
+/*
+ * dht_normalize_stats -
+ */
+static void
+dht_normalize_stats (struct statvfs *buf, unsigned long bsize,
+ unsigned long frsize)
+{
+ double factor = 0;
+
+ if (buf->f_bsize != bsize) {
+ buf->f_bsize = bsize;
+ }
+
+ if (buf->f_frsize != frsize) {
+ factor = ((double) buf->f_frsize) / frsize;
+ buf->f_frsize = frsize;
+ buf->f_blocks = (fsblkcnt_t) (factor * buf->f_blocks);
+ buf->f_bfree = (fsblkcnt_t) (factor * buf->f_bfree);
+ buf->f_bavail = (fsblkcnt_t) (factor * buf->f_bavail);
+
+ }
+}
int
dht_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int op_ret, int op_errno, struct statvfs *statvfs)
{
- dht_local_t *local = NULL;
- int this_call_cnt = 0;
+ dht_local_t *local = NULL;
+ int this_call_cnt = 0;
+ int bsize = 0;
+ int frsize = 0;
local = frame->local;
@@ -2451,9 +2475,15 @@ dht_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
}
local->op_ret = 0;
- /* TODO: normalize sizes */
- local->statvfs.f_bsize = statvfs->f_bsize;
- local->statvfs.f_frsize = statvfs->f_frsize;
+ if (local->statvfs.f_bsize != 0) {
+ bsize = max(local->statvfs.f_bsize, statvfs->f_bsize);
+ frsize = max(local->statvfs.f_frsize, statvfs->f_frsize);
+ dht_normalize_stats(&local->statvfs, bsize, frsize);
+ dht_normalize_stats(statvfs, bsize, frsize);
+ } else {
+ local->statvfs.f_bsize = statvfs->f_bsize;
+ local->statvfs.f_frsize = statvfs->f_frsize;
+ }
local->statvfs.f_blocks += statvfs->f_blocks;
local->statvfs.f_bfree += statvfs->f_bfree;