rpc: Decouple RPC config from instance ID

Instance ID is too overloaded and the uses are beginning
to conflict. Separate the RPC configuration out.

Change-Id: I712731130339fee4fc8de4dc2d0fea7040773c58
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2017-02-01 11:14:03 -07:00
parent 5c42f21870
commit dd16a7277d
5 changed files with 59 additions and 38 deletions

View File

@ -38,8 +38,6 @@
#include "spdk/jsonrpc.h"
#define SPDK_JSONRPC_PORT_BASE 5260
typedef void (*spdk_rpc_method_handler)(struct spdk_jsonrpc_server_conn *conn,
const struct spdk_json_val *params,
const struct spdk_json_val *id);

View File

@ -51,11 +51,13 @@
#include "spdk/env.h"
#include "spdk/conf.h"
#include "spdk/log.h"
#include "spdk/string.h"
#include "spdk_internal/event.h"
#define RPC_SELECT_INTERVAL 4000 /* 4ms */
#define RPC_DEFAULT_LISTEN_ADDR "127.0.0.1"
#define RPC_DEFAULT_LISTEN_ADDR "127.0.0.1:5260"
#define RPC_DEFAULT_PORT "5260"
static struct sockaddr_un g_rpc_listen_addr_unix = {};
@ -160,8 +162,6 @@ spdk_jsonrpc_handler(
static void
spdk_rpc_setup(void *arg)
{
uint16_t port;
char port_str[16];
struct addrinfo hints;
struct addrinfo *res;
const char *listen_addr;
@ -186,7 +186,7 @@ spdk_rpc_setup(void *arg)
g_rpc_listen_addr_unix.sun_family = AF_UNIX;
rc = snprintf(g_rpc_listen_addr_unix.sun_path,
sizeof(g_rpc_listen_addr_unix.sun_path),
"%s.%d", listen_addr, spdk_app_get_instance_id());
"%s", listen_addr);
if (rc < 0 || (size_t)rc >= sizeof(g_rpc_listen_addr_unix.sun_path)) {
SPDK_ERRLOG("RPC Listen address Unix socket path too long\n");
g_rpc_listen_addr_unix.sun_path[0] = '\0';
@ -200,15 +200,32 @@ spdk_rpc_setup(void *arg)
sizeof(g_rpc_listen_addr_unix),
spdk_jsonrpc_handler);
} else {
port = SPDK_JSONRPC_PORT_BASE + spdk_app_get_instance_id();
snprintf(port_str, sizeof(port_str), "%" PRIu16, port);
char *tmp;
char *host, *port;
tmp = strdup(listen_addr);
if (!tmp) {
SPDK_ERRLOG("Out of memory\n");
return;
}
if (spdk_parse_ip_addr(tmp, &host, &port) < 0) {
free(tmp);
SPDK_ERRLOG("Invalid listen address '%s'\n", listen_addr);
return;
}
if (port == NULL) {
port = RPC_DEFAULT_PORT;
}
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if (getaddrinfo(listen_addr, port_str, &hints, &res) != 0) {
if (getaddrinfo(host, port, &hints, &res) != 0) {
free(tmp);
SPDK_ERRLOG("Unable to look up RPC listen address '%s'\n", listen_addr);
return;
}
@ -218,6 +235,7 @@ spdk_rpc_setup(void *arg)
spdk_jsonrpc_handler);
freeaddrinfo(res);
free(tmp);
}
if (g_jsonrpc_server == NULL) {

View File

@ -9,8 +9,6 @@ try:
except ImportError:
from pipes import quote
SPDK_JSONRPC_PORT_BASE = 5260
def print_dict(d):
print json.dumps(d, indent=2)
@ -19,7 +17,7 @@ def print_array(a):
parser = argparse.ArgumentParser(description='SPDK RPC command line interface')
parser.add_argument('-s', dest='server_addr', help='RPC server address', default='127.0.0.1')
parser.add_argument('-p', dest='instance_id', help='RPC server instance ID', default=0, type=int)
parser.add_argument('-p', dest='port', help='RPC port number', default=5260, type=int)
subparsers = parser.add_subparsers(help='RPC methods')
@ -30,10 +28,10 @@ def int_arg(arg):
def jsonrpc_call(method, params={}):
if args.server_addr.startswith('/'):
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect("{}.{}".format(args.server_addr, args.instance_id))
s.connect(args.server_addr)
else:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((args.server_addr, SPDK_JSONRPC_PORT_BASE + args.instance_id))
s.connect((args.server_addr, args.port))
req = {}
req['jsonrpc'] = '2.0'
req['method'] = method

View File

@ -17,10 +17,16 @@ fi
rpc_py="python $rootdir/scripts/rpc.py"
fio_py="python $rootdir/scripts/fio.py"
PORT=3260
RPC_PORT=5260
NETMASK=127.0.0.0/24
MIGRATION_ADDRESS=127.0.0.2
function kill_all_iscsi_target() {
for ((i=0; i<${#pid[*]}; i++))
for ((i=0; i<2; i++))
do
$rpc_py -p $i kill_instance SIGTERM
port=$(($RPC_PORT + $i))
$rpc_py -p $port kill_instance SIGTERM
done
}
@ -38,34 +44,32 @@ timing_enter ip_migration
# iSCSI target configuration
PORT=3260
RPC_PORT=5260
NETMASK=127.0.0.0/24
MIGRATION_ADDRESS=127.0.0.2
#The iscsi target process parameter array
dpdk_file_prefix=(target1 target2)
instanceID=(0 1)
echo "Running ip migration tests"
exe=./app/iscsi_tgt/iscsi_tgt
for ((i=0; i<${#dpdk_file_prefix[*]}; i++))
for ((i=0; i<2; i++))
do
$exe -c $testdir/iscsi.conf -i ${instanceID[$i]} -s 1000 &
pid[$i]=$!
echo "Process pid: ${pid[$i]}"
cp $testdir/iscsi.conf $testdir/iscsi.conf.$i
port=$(($RPC_PORT + $i))
echo "Listen 127.0.0.1:$port" >> $testdir/iscsi.conf.$i
$exe -c $testdir/iscsi.conf.$i -i $i -s 1000 &
pid=$!
echo "Process pid: $pid"
trap "kill_all_iscsi_target; exit 1" SIGINT SIGTERM EXIT
waitforlisten ${pid[i]} $(expr $RPC_PORT + ${instanceID[$i]})
waitforlisten $pid $port
echo "iscsi_tgt is listening. Running tests..."
rpc_config ${instanceID[$i]} $NETMASK
rpc_config $port $NETMASK
trap "kill_all_iscsi_target; exit 1" \
SIGINT SIGTERM EXIT
rm -f $testdir/iscsi.conf.$i
done
rpc_add_ip ${instanceID[0]} $MIGRATION_ADDRESS
$rpc_py -p ${instanceID[0]} add_portal_group 1 $MIGRATION_ADDRESS:$PORT
$rpc_py -p ${instanceID[0]} construct_target_node ${dpdk_file_prefix[0]} ${dpdk_file_prefix[0]}_alias 'Malloc0:0' '1:1' 64 1 0 0 0
rpc_first_port=$(($RPC_PORT + 0))
rpc_add_ip $rpc_first_port $MIGRATION_ADDRESS
$rpc_py -p $rpc_first_port add_portal_group 1 $MIGRATION_ADDRESS:$PORT
$rpc_py -p $rpc_first_port construct_target_node target1 target1_alias 'Malloc0:0' '1:1' 64 1 0 0 0
sleep 1
iscsiadm -m discovery -t sendtargets -p $MIGRATION_ADDRESS:$PORT
@ -78,11 +82,12 @@ $fio_py 4096 32 randrw 10 &
fiopid=$!
sleep 5
$rpc_py -p 0 kill_instance SIGTERM
$rpc_py -p $rpc_first_port kill_instance SIGTERM
rpc_add_ip ${instanceID[1]} $MIGRATION_ADDRESS
$rpc_py -p ${instanceID[1]} add_portal_group 1 $MIGRATION_ADDRESS:$PORT
$rpc_py -p ${instanceID[1]} construct_target_node ${dpdk_file_prefix[0]} ${dpdk_file_prefix[0]}_alias 'Malloc0:0' '1:1' 64 1 0 0 0
rpc_second_port=$(($RPC_PORT + 1))
rpc_add_ip $rpc_second_port $MIGRATION_ADDRESS
$rpc_py -p $rpc_second_port add_portal_group 1 $MIGRATION_ADDRESS:$PORT
$rpc_py -p $rpc_second_port construct_target_node target1 target1_alias 'Malloc0:0' '1:1' 64 1 0 0 0
wait $fiopid
@ -90,5 +95,5 @@ trap - SIGINT SIGTERM EXIT
iscsicleanup
$rpc_py -p 1 kill_instance SIGTERM
$rpc_py -p $rpc_second_port kill_instance SIGTERM
timing_exit ip_migration

View File

@ -10,5 +10,7 @@
MaxSessions 64
ImmediateData Yes
ErrorRecoveryLevel 0
# The RPC section must be the last section in this file.
[Rpc]
Enable Yes