From cd24be007c64bd10d8c28e8e9b1c988478a32c8c Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Wed, 14 Dec 2011 10:36:27 +0530 Subject: debug/error-gen: add option to generate errors at random percentage Currently error-gen has a option where the percentage of the errors generated can be specified. This patch adds a new option, which if given errors are generated at random percentage. If both the random failure option and the specific percentage of the errors are provided, then random error generation is given preference. Change-Id: I43fffcd7da8935761ed7d30e2a9677895d6a31fb BUG: 767192 Signed-off-by: Raghavendra Bhat Reviewed-on: http://review.gluster.com/786 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy Reviewed-by: Vijay Bellur --- xlators/debug/error-gen/src/error-gen.c | 11 ++++++++++- xlators/debug/error-gen/src/error-gen.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'xlators/debug') diff --git a/xlators/debug/error-gen/src/error-gen.c b/xlators/debug/error-gen/src/error-gen.c index 6d6c5f24a..909dc681e 100644 --- a/xlators/debug/error-gen/src/error-gen.c +++ b/xlators/debug/error-gen/src/error-gen.c @@ -362,7 +362,8 @@ error_gen (xlator_t *this, int op_no) rand_no = 0; ret = error_no_list[op_no].error_no[rand_no]; } - egp->failure_iter_no = 3 + (rand () % GF_UNIVERSAL_ANSWER); + if (egp->random_failure == _gf_true) + egp->failure_iter_no = 3 + (rand () % GF_UNIVERSAL_ANSWER); } return ret; } @@ -1871,6 +1872,7 @@ init (xlator_t *this) data_t *error_no = NULL; data_t *failure_percent = NULL; data_t *enable = NULL; + gf_boolean_t random_failure = _gf_false; int32_t ret = 0; char *error_enable_fops = NULL; char *op_no_str = NULL; @@ -1953,6 +1955,11 @@ init (xlator_t *this) } } } + + random_failure = dict_get_str_boolean (this->options, "random-failure", + _gf_false); + pvt->random_failure = random_failure; + this->private = pvt; /* Give some seed value here */ @@ -2036,6 +2043,8 @@ struct volume_options options[] = { "ENODEV","EXDEV","EMFILE","ENFILE","ENOSYS","EINTR", "EFBIG","EAGAIN"}, .type = GF_OPTION_TYPE_STR }, + { .key = {"random-failure"}, + .type = GF_OPTION_TYPE_BOOL}, { .key = {"enable"}, .type = GF_OPTION_TYPE_STR }, { .key = {NULL} } diff --git a/xlators/debug/error-gen/src/error-gen.h b/xlators/debug/error-gen/src/error-gen.h index bd92aad6a..bb3adb2ab 100644 --- a/xlators/debug/error-gen/src/error-gen.h +++ b/xlators/debug/error-gen/src/error-gen.h @@ -34,6 +34,7 @@ typedef struct { int op_count; int failure_iter_no; char *error_no; + gf_boolean_t random_failure; gf_lock_t lock; } eg_t; -- cgit