From 365558571c59dd42cf0934e6c31c7b4bf2c65026 Mon Sep 17 00:00:00 2001 From: liuchang0812 Date: Wed, 6 Sep 2017 11:50:17 +0800 Subject: [PATCH] mon: incorrect MAX AVAIL in "ceph df" Fixes: http://tracker.ceph.com/issues/21243 Signed-off-by: liuchang0812 --- qa/standalone/mon/osd-pool-df.sh | 75 ++++++++++++++++++++++++++++ qa/standalone/mon/test_pool_quota.sh | 2 +- src/mon/PGMap.cc | 4 +- src/test/mon/PGMap.cc | 6 +-- 4 files changed, 81 insertions(+), 6 deletions(-) create mode 100755 qa/standalone/mon/osd-pool-df.sh diff --git a/qa/standalone/mon/osd-pool-df.sh b/qa/standalone/mon/osd-pool-df.sh new file mode 100755 index 00000000000..3ed169d8c04 --- /dev/null +++ b/qa/standalone/mon/osd-pool-df.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2017 Tencent +# +# Author: Chang Liu +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library Public License for more details. +# +source $CEPH_ROOT/qa/standalone/ceph-helpers.sh + +function run() { + local dir=$1 + shift + + export CEPH_MON="127.0.0.1:7113" # git grep '\<7113\>' : there must be only one + export CEPH_ARGS + CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none " + CEPH_ARGS+="--mon-host=$CEPH_MON " + + local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')} + for func in $funcs ; do + setup $dir || return 1 + $func $dir || return 1 + teardown $dir || return 1 + done +} + +function TEST_ceph_df() { + local dir=$1 + setup $dir || return 1 + + run_mon $dir a || return 1 + run_osd $dir 0 || return 1 + run_osd $dir 1 || return 1 + run_osd $dir 2 || return 1 + run_osd $dir 3 || return 1 + run_osd $dir 4 || return 1 + run_osd $dir 5 || return 1 + run_mgr $dir x || return 1 + + profile+=" plugin=jerasure" + profile+=" technique=reed_sol_van" + profile+=" k=4" + profile+=" m=2" + profile+=" crush-failure-domain=osd" + + ceph osd erasure-code-profile set ec42profile ${profile} + + local rep_poolname=testcephdf_replicate + local ec_poolname=testcephdf_erasurecode + create_pool $rep_poolname 6 6 replicated + create_pool $ec_poolname 6 6 erasure ec42profile + + local global_avail=`ceph df -f json | jq '.stats.total_avail_bytes'` + local rep_avail=`ceph df -f json | jq '.pools | map(select(.name == "$rep_poolname"))[0].stats.max_avail'` + local ec_avail=`ceph df -f json | jq '.pools | map(select(.name == "$ec_poolname"))[0].stats.max_avail'` + + echo "${global_avail} >= ${rep_avail}*3" | bc || return 1 + echo "${global_avail} >= ${ec_avail}*1.5" | bc || return 1 + + ceph osd pool delete $rep_poolname $rep_poolname --yes-i-really-really-mean-it + ceph osd pool delete $ec_poolname $ec_poolname --yes-i-really-really-mean-it + ceph osd erasure-code-profile rm ec42profile + teardown $dir || return 1 +} + +main osd-pool-df "$@" diff --git a/qa/standalone/mon/test_pool_quota.sh b/qa/standalone/mon/test_pool_quota.sh index 2f0b99d5a73..b87ec22328c 100755 --- a/qa/standalone/mon/test_pool_quota.sh +++ b/qa/standalone/mon/test_pool_quota.sh @@ -33,7 +33,7 @@ function TEST_pool_quota() { run_osd $dir 1 || return 1 run_osd $dir 2 || return 1 - local poolname=testquoa + local poolname=testquota create_pool $poolname 20 local objects=`ceph df detail | grep -w $poolname|awk '{print $3}'` local bytes=`ceph df detail | grep -w $poolname|awk '{print $4}'` diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc index 0268bc78267..934c4c81487 100644 --- a/src/mon/PGMap.cc +++ b/src/mon/PGMap.cc @@ -835,7 +835,7 @@ void PGMapDigest::dump_object_stat_sum( f->dump_int("kb_used", SHIFT_ROUND_UP(sum.num_bytes, 10)); f->dump_int("bytes_used", sum.num_bytes); f->dump_format_unquoted("percent_used", "%.2f", (used*100)); - f->dump_unsigned("max_avail", avail); + f->dump_unsigned("max_avail", avail / raw_used_rate); f->dump_int("objects", sum.num_objects); if (verbose) { f->dump_int("quota_objects", pool->quota_max_objects); @@ -850,7 +850,7 @@ void PGMapDigest::dump_object_stat_sum( } else { tbl << stringify(si_t(sum.num_bytes)); tbl << percentify(used*100); - tbl << si_t(avail); + tbl << si_t(avail / raw_used_rate); tbl << sum.num_objects; if (verbose) { tbl << stringify(si_t(sum.num_objects_dirty)) diff --git a/src/test/mon/PGMap.cc b/src/test/mon/PGMap.cc index 60de6b7ddae..d7e8a18fe41 100644 --- a/src/test/mon/PGMap.cc +++ b/src/test/mon/PGMap.cc @@ -180,7 +180,7 @@ TEST(pgmap, dump_object_stat_sum_0) unsigned col = 0; ASSERT_EQ(stringify(si_t(sum.num_bytes)), tbl.get(0, col++)); ASSERT_EQ(percentify(used_percent), tbl.get(0, col++)); - ASSERT_EQ(stringify(si_t(avail)), tbl.get(0, col++)); + ASSERT_EQ(stringify(si_t(avail/pool.size)), tbl.get(0, col++)); ASSERT_EQ(stringify(sum.num_objects), tbl.get(0, col++)); ASSERT_EQ(stringify(si_t(sum.num_objects_dirty)), tbl.get(0, col++)); ASSERT_EQ(stringify(si_t(sum.num_rd)), tbl.get(0, col++)); @@ -210,7 +210,7 @@ TEST(pgmap, dump_object_stat_sum_1) unsigned col = 0; ASSERT_EQ(stringify(si_t(0)), tbl.get(0, col++)); ASSERT_EQ(percentify(0), tbl.get(0, col++)); - ASSERT_EQ(stringify(si_t(avail)), tbl.get(0, col++)); + ASSERT_EQ(stringify(si_t(avail/pool.size)), tbl.get(0, col++)); ASSERT_EQ(stringify(0), tbl.get(0, col++)); ASSERT_EQ(stringify(si_t(0)), tbl.get(0, col++)); ASSERT_EQ(stringify(si_t(0)), tbl.get(0, col++)); @@ -239,6 +239,6 @@ TEST(pgmap, dump_object_stat_sum_2) unsigned col = 0; ASSERT_EQ(stringify(si_t(0)), tbl.get(0, col++)); ASSERT_EQ(percentify(0), tbl.get(0, col++)); - ASSERT_EQ(stringify(si_t(avail)), tbl.get(0, col++)); + ASSERT_EQ(stringify(si_t(avail/pool.size)), tbl.get(0, col++)); ASSERT_EQ(stringify(0), tbl.get(0, col++)); } -- 2.39.5