Browse Source

fix multiple sessions...

This fixes a bug where ggatessh was consuming 100% cpu because the
error from sftp_open wasn't being checked, now ggatessh will exit
if this fails (and log the failure)...

Add a test to make sure that a second session is launched and
works..  This discovered that the sftp_open wasn't passing in the
correct file name...

Now that there will be multiple IOs in flight, this should improve
performance a bit...
remotes/client/ssh-main
John-Mark Gurney 3 years ago
parent
commit
b7d400fabc
2 changed files with 107 additions and 4 deletions
  1. +24
    -1
      ggatessh/ggatessh.c
  2. +83
    -3
      tests/ggatessh_test.sh

+ 24
- 1
ggatessh/ggatessh.c View File

@@ -130,6 +130,21 @@ usage(void)
exit(EXIT_FAILURE);
}

#if 0
static void
libssh2_debug_error(LIBSSH2_SESSION *session, const char *info)
{
char *errmsg;
int error;
int rc;

error = libssh2_session_last_errno(session);
rc = libssh2_session_last_error(session, &errmsg, NULL, 0);

g_gate_log(LOG_DEBUG, "%s: %s(%d)", info, errmsg, error);
}
#endif

static void
libssh2_errorx(LIBSSH2_SESSION *session, const char *info)
{
@@ -825,8 +840,16 @@ procreq:
if (gsc_pending->sc_session != NULL) {
*didworkp = 1;
gsc_pending->sc_handle = libssh2_sftp_open(
gsc_pending->sc_session, "fstest/data.img",
gsc_pending->sc_session, imgpath,
get_open_flags(), 0);

if (gsc_pending->sc_handle == NULL) {
error = libssh2_session_last_errno(
session);
if (error != LIBSSH2_ERROR_EAGAIN)
libssh2_errorx(session,
"sftp_open");
}
}

g_gate_log(LOG_DEBUG,


+ 83
- 3
tests/ggatessh_test.sh View File

@@ -43,7 +43,7 @@ ggatessh_body()

wait_for_ggate_device ${ggate_dev}

# make sure it has correct size and sector sizekj
# make sure it has correct size and sector size
read _dev _secsize _size _nsecs _stripesize _stripeoff <<EOF
$(diskinfo /dev/ggate$us)
EOF
@@ -109,7 +109,7 @@ ggatessh_resize_body()

wait_for_ggate_device ${ggate_dev}

# make sure it has correct size and sector sizekj
# make sure it has correct size and sector size
read _dev _secsize _size _nsecs _stripesize _stripeoff <<EOF
$(diskinfo /dev/ggate$us)
EOF
@@ -153,6 +153,85 @@ ggatessh_resize_cleanup()
common_cleanup
}

atf_test_case ggatessh_multises cleanup
ggatessh_multises_head()
{
atf_set "descr" "ggatessh will handle multiple sessions w/o looping"
atf_set "require.progs" "ggatessh"
atf_set "require.user" "root"
atf_set "timeout" 20
}

ggatessh_multises_body()
{

n1mchunks=1
secsize=4096
us=$(alloc_ggate_dev)

startup_sshd

set -x
truncate -s ${n1mchunks}m "$TESTIMG"
# sshd authenticates and switches to USER
chown "$USER" "$TESTIMG"

echo 'WARNING: ggatessh error messages goes to syslog' \
'(aka /var/log/messages)'

ggatessh create -i "$(pwd)/id_rsa" -p "$PORT" -F "$PIDFILE" \
-u $us -l "$USER" 127.0.0.1 "$(pwd)/$TESTIMG"

ggate_dev=/dev/ggate${us}

wait_for_ggate_device ${ggate_dev}

# kill off ggate so we can schedule I/O
pkill -F "$PIDFILE"

# schedule some IO, to create a second session
dd if=/dev/ggate$us of=/dev/null bs=1m &
dd1pid="$!"
dd if=/dev/ggate$us of=/dev/null bs=1m &
dd2pid="$!"

# restart ggate
ggatessh rescue -v -i "$(pwd)/id_rsa" -p "$PORT" \
-u $us -l "$USER" 127.0.0.1 "$(pwd)/$TESTIMG" > ggatessh.log &
ggatepid="$!"

# This test will timeout if ggatessh exits before dd does, dump
# the log to find out why

# wait for IO to complete
wait "$dd1pid"
echo "dd exit:" $?

wait "$dd2pid"
echo "dd exit:" $?

# kill off ggate
kill "$ggatepid"
wait "$ggatepid"

#echo 'log:'
#cat ggatessh.log
#echo 'end of log'

# make sure the second session was successfully created
cnt=$(grep "new session created" ggatessh.log | wc -l)
if [ "$cnt" -ne 1 ]; then
echo "not the correct number of new sessions: $cnt"
return 1
fi
}

ggatessh_multises_cleanup()
{

common_cleanup
}

atf_test_case ggatessh_rowotest cleanup
ggatessh_rowotest_head()
{
@@ -192,7 +271,7 @@ ggatessh_rowotest_body()

wait_for_ggate_device ${ggate_dev}

# make sure it has correct size and sector sizekj
# make sure it has correct size and sector size
read _dev _secsize _size _nsecs _stripesize _stripeoff <<EOF
$(diskinfo /dev/ggate$us)
EOF
@@ -250,6 +329,7 @@ atf_init_test_cases()
{
atf_add_test_case ggatessh
atf_add_test_case ggatessh_resize
atf_add_test_case ggatessh_multises
atf_add_test_case ggatessh_rowotest
}



Loading…
Cancel
Save