From 22e848f88e2cb9510e82fb4875c182240fff3303 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Fri, 29 Mar 2019 08:30:49 +0530 Subject: protocol: add an option to force using old-protocol As protocol implements every fop, and in general a large part of the codebase. Considering our regression is run mostly in 1 machine, there was no way of forcing the client to use old protocol (while new one is available). With this patch, a new 'testing' option is provided which forces client to use old protocol if found. This should help increase the code coverage by at least 10k lines overall. updates: bz#1693692 Change-Id: Ie45256f7dea250671b689c72b4b6f25037cef948 Signed-off-by: Amar Tumballi --- tests/basic/old-protocol.t | 31 ++++++++++++++++++++++++++ xlators/protocol/client/src/client-handshake.c | 13 ++++++++--- xlators/protocol/client/src/client.c | 12 ++++++++++ xlators/protocol/client/src/client.h | 2 ++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100755 tests/basic/old-protocol.t diff --git a/tests/basic/old-protocol.t b/tests/basic/old-protocol.t new file mode 100755 index 00000000000..27a688d3538 --- /dev/null +++ b/tests/basic/old-protocol.t @@ -0,0 +1,31 @@ +#!/bin/bash + +. $(dirname $0)/../include.rc +. $(dirname $0)/../volume.rc + +cleanup; + +TEST glusterd +TEST pidof glusterd +TEST $CLI volume info; + +TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{1,2,3,4,5,6}; + +EXPECT "$V0" volinfo_field $V0 'Volume Name'; +EXPECT 'Created' volinfo_field $V0 'Status'; +EXPECT '6' brick_count $V0 + +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; + +file="/var/lib/glusterd/vols/$V0/trusted-$V0.tcp-fuse.vol" +sed -i -e 's$send-gids true$send-gids true\n option testing.old-protocol true$g' $file + +## Mount FUSE +TEST $GFS -s $H0 --volfile-id $V0 $M1; + +## TODO: best way to increase coverage is to have a gfapi program +## which covers maximum fops +TEST $(dirname $0)/rpc-coverage.sh $M1 + +cleanup; diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c index c43756a3fec..01505587243 100644 --- a/xlators/protocol/client/src/client-handshake.c +++ b/xlators/protocol/client/src/client-handshake.c @@ -1338,11 +1338,15 @@ select_server_supported_programs(xlator_t *this, gf_prog_detail *prog) while (trav) { /* Select 'programs' */ if ((clnt3_3_fop_prog.prognum == trav->prognum) && - (clnt3_3_fop_prog.progver == trav->progver) && !conf->fops) { + (clnt3_3_fop_prog.progver == trav->progver)) { conf->fops = &clnt3_3_fop_prog; if (conf->rpc) conf->rpc->auth_value = AUTH_GLUSTERFS_v2; ret = 0; + /* In normal flow, we don't want to use old protocol type. + but if it is for testing, lets use it */ + if (conf->old_protocol) + goto done; } if ((clnt4_0_fop_prog.prognum == trav->prognum) && @@ -1351,8 +1355,10 @@ select_server_supported_programs(xlator_t *this, gf_prog_detail *prog) if (conf->rpc) conf->rpc->auth_value = AUTH_GLUSTERFS_v3; ret = 0; - /* this is latest program, lets use it */ - goto out; + /* this is latest program, lets use this program only */ + /* if we are testing for old-protocol, lets not break this */ + if (!conf->old_protocol) + goto done; } if (ret) { @@ -1362,6 +1368,7 @@ select_server_supported_programs(xlator_t *this, gf_prog_detail *prog) trav = trav->next; } +done: if (!ret) gf_msg(this->name, GF_LOG_INFO, 0, PC_MSG_VERSION_INFO, "Using Program %s," diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c index 1e9f47297ee..fffe22380b1 100644 --- a/xlators/protocol/client/src/client.c +++ b/xlators/protocol/client/src/client.c @@ -2508,6 +2508,8 @@ build_client_config(xlator_t *this, clnt_conf_t *conf) GF_OPTION_INIT("send-gids", conf->send_gids, bool, out); + GF_OPTION_INIT("testing.old-protocol", conf->old_protocol, bool, out); + conf->client_id = glusterfs_leaf_position(this); ret = client_check_remote_host(this, this->options); @@ -3048,6 +3050,16 @@ struct volume_options options[] = { " power. Range 1-32 threads.", .op_version = {GD_OP_VERSION_3_7_0}, .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, + + /* This option is required for running code-coverage tests with + old protocol */ + { + .key = {"testing.old-protocol"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .op_version = {GD_OP_VERSION_7_0}, + .flags = OPT_FLAG_SETTABLE, + }, {.key = {NULL}}, }; diff --git a/xlators/protocol/client/src/client.h b/xlators/protocol/client/src/client.h index f12fa61bb93..60efa9c264a 100644 --- a/xlators/protocol/client/src/client.h +++ b/xlators/protocol/client/src/client.h @@ -235,6 +235,8 @@ typedef struct clnt_conf { * up, disconnects can be * logged */ + + gf_boolean_t old_protocol; /* used only for old-protocol testing */ } clnt_conf_t; typedef struct _client_fd_ctx { -- cgit