From nobody Fri Jun 28 19:36:12 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4W9lzc1vZNz5PCDC; Fri, 28 Jun 2024 19:36:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4W9lzc1HYFz40tc; Fri, 28 Jun 2024 19:36:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719603372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zF1gPpoa30emELgxB6crDYDsq4GjM26TAZtX6lqAK0I=; b=XhrR8cgsweKZDi3qkqytiu8kSsdC0ns68O4K65nXy+fAENY9rlWtcpwlpTvH+80Vciec5A Bl0iPvBLGIn35Jbx48eEOxoU3Pxv/khSfgh29py8GTKcb3sC+aX2xXKJU16TqZfHGpLAZY a0N6uDDDz9QvUGhRwli/cOwzOyatAEMei3/w5hj/nEmTNKCYz3gGtyJ890Ka3hqci1i3Zy R4g1ljhsmADEtFv7400yajN7redJ9sZ05pfJ3RsO9zEDugkXhv2mHZAnUYJy2nH9hQcsbg /lNQLkk9AA5m1HFEaSr1lwtr6Oeq3uHCwbSWi73l2qkGAGaTU37VMm0VeW8q+w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1719603372; a=rsa-sha256; cv=none; b=D4jwyKEwVloKY4LR8JF/Gcut3SfeA615MBSCrTrCYP4PUh7M+4JeY5Aj9s9u920bsZ05Ng BMQ7CqFPIw5bsMCfDyXN8gEcWVhExTbJz6xCEM+Sje+k/J+GP0IUC91W1cC4TrLBRUUSlY 8VKpbNlD/pnT/ZKemBiy797uNaQ1MzrmzyEB1CiRuneIie3jg5zdp/n32nCo+kDp3WgLXi MYuvMvQRrCPUI29jccaVPKZ2fFuBbr5AuEpFLLe43YO8gsNkCHJUow3iz7yTtPIoApe1nD AX+z2kVauJxqqJ80jPIcH4cv0HTi8y0aloB0sacRqirKSG/rzGjDAch/6dy33g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719603372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zF1gPpoa30emELgxB6crDYDsq4GjM26TAZtX6lqAK0I=; b=Awrg2Igk+TGgGU55uVKTerzaVlY7OceDmy4iDWKHvBs1JAL7EUwGsEv8fG29qAWeHUChaI iNDe5iVZ02ZKQpHol/ZtH6rCn8zf8GTGb/abqvDb2Bog3B/WvcEc/dxYAf0Qo5jnV8x+Xs 7KVUUblTCO9YH9RF0kWm+TmdkGZVVwTUqSgSckPM9JVo9dPmLhJGq1/O2ODOPM7BwqmRPe 7BuR3Tx/eh6cH+Q846JJwkG1o+Zh8DW6/7NnmGzwUT3LHTlNSWEHeIZW06vrnt9pLetEbe l8foDR7S8bFVRzrlG/b36y1vNQz4tWf3FI6fOaHPxpMJtwiPQMzcjHeMvz+O+Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4W9lzc0twMz17Z6; Fri, 28 Jun 2024 19:36:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45SJaCtT021052; Fri, 28 Jun 2024 19:36:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45SJaCdQ021049; Fri, 28 Jun 2024 19:36:12 GMT (envelope-from git) Date: Fri, 28 Jun 2024 19:36:12 GMT Message-Id: <202406281936.45SJaCdQ021049@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: 1dc90424b26f - stable/13 - ctladm: print port number with a succesful "port -c" command List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1dc90424b26f80e4a9475a722f46e754fe7aba76 Auto-Submitted: auto-generated The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=1dc90424b26f80e4a9475a722f46e754fe7aba76 commit 1dc90424b26f80e4a9475a722f46e754fe7aba76 Author: Alan Somers AuthorDate: 2024-06-05 23:54:46 +0000 Commit: Alan Somers CommitDate: 2024-06-28 19:25:54 +0000 ctladm: print port number with a succesful "port -c" command Make "ctladm port -c" print the port number of the newly successful port. This way it won't have to be guessed by a subsequent "ctladm portlist" command. That means it's safe to use it concurrently with other ctladm processes. In particular, this allows the tests to be run in parallel. Sponsored by: Axcient Reviewed by: mav Pull Request: https://github.com/freebsd/freebsd-src/pull/1279 (cherry picked from commit 591de7534fb3acb2e6eef94a1e5e92000d2cf83d) --- usr.sbin/ctladm/ctladm.c | 18 +++++++++++ usr.sbin/ctladm/tests/Makefile | 4 --- usr.sbin/ctladm/tests/port.sh | 70 ++++++++++++++++++++---------------------- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/usr.sbin/ctladm/ctladm.c b/usr.sbin/ctladm/ctladm.c index 1cf42aa5933b..6af25ed28925 100644 --- a/usr.sbin/ctladm/ctladm.c +++ b/usr.sbin/ctladm/ctladm.c @@ -392,7 +392,9 @@ static struct ctladm_opts cctl_fe_table[] = { static int cctl_port(int fd, int argc, char **argv, char *combinedopt) { + char result_buf[1024]; int c; + uint64_t created_port = -1; int32_t targ_port = -1; int retval = 0; int wwnn_set = 0, wwpn_set = 0; @@ -582,6 +584,8 @@ cctl_port(int fd, int argc, char **argv, char *combinedopt) case CCTL_PORT_MODE_CREATE: { bzero(&req, sizeof(req)); strlcpy(req.driver, driver, sizeof(req.driver)); + req.result = result_buf; + req.result_len = sizeof(result_buf); if (port_mode == CCTL_PORT_MODE_REMOVE) { req.reqtype = CTL_REQ_REMOVE; @@ -614,6 +618,20 @@ cctl_port(int fd, int argc, char **argv, char *combinedopt) warnx("warning: %s", req.error_str); break; case CTL_LUN_OK: + if (port_mode == CCTL_PORT_MODE_CREATE) { + req.result_nvl = nvlist_unpack(result_buf, req.result_len, 0); + if (req.result_nvl == NULL) { + warnx("error unpacking result nvlist"); + break; + } + created_port = nvlist_get_number(req.result_nvl, "port_id"); + printf("Port created successfully\n" + "frontend: %s\n" + "port: %ju\n", driver, + (uintmax_t) created_port); + nvlist_destroy(req.result_nvl); + } else + printf("Port destroyed successfully\n"); break; default: warnx("unknown status: %d", req.status); diff --git a/usr.sbin/ctladm/tests/Makefile b/usr.sbin/ctladm/tests/Makefile index 73ac94d77d21..825e38e6c6e3 100644 --- a/usr.sbin/ctladm/tests/Makefile +++ b/usr.sbin/ctladm/tests/Makefile @@ -3,8 +3,4 @@ PACKAGE= tests ATF_TESTS_SH= port -# "ctladm port" does not report the name of the port just created, so we can't -# cleanup unless we assume that no other test created a port too. -TEST_METADATA+= is_exclusive="true" - .include diff --git a/usr.sbin/ctladm/tests/port.sh b/usr.sbin/ctladm/tests/port.sh index 110b89bd965b..782a8ee5b6c1 100644 --- a/usr.sbin/ctladm/tests/port.sh +++ b/usr.sbin/ctladm/tests/port.sh @@ -45,8 +45,9 @@ skip_if_ctld() { cleanup() { driver=$1 - if [ -e after-ports ]; then - diff before-ports after-ports | awk "/$driver/ {print \$2}" | xargs -n1 ctladm port -r -d ioctl -p + if [ -e port-create.txt ]; then + portnum=`awk '/port:/ {print $2}' port-create.txt` + ctladm port -r -d $driver -p $portnum fi } @@ -60,12 +61,13 @@ create_ioctl_body() { skip_if_ctld - atf_check -o save:before-ports ctladm portlist -qf ioctl - atf_check ctladm port -c -d "ioctl" - atf_check -o save:after-ports ctladm portlist -qf ioctl - if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then - atf_fail "Did not create a new ioctl port" - fi + atf_check -o save:port-create.txt ctladm port -c -d "ioctl" + atf_check egrep -q "Port created successfully" port-create.txt + atf_check egrep -q "frontend: *ioctl" port-create.txt + atf_check egrep -q "port: *[0-9]+" port-create.txt + portnum=`awk '/port:/ {print $2}' port-create.txt` + atf_check -o save:portlist.txt ctladm portlist -qf ioctl + atf_check egrep -q "$portnum *YES *ioctl *ioctl" portlist.txt } create_ioctl_cleanup() { @@ -82,13 +84,13 @@ create_ioctl_options_body() { skip_if_ctld - atf_check -o save:before-ports ctladm portlist -qf ioctl - atf_check ctladm port -c -d "ioctl" -O pp=101 -O vp=102 - atf_check -o save:after-ports ctladm portlist -qf ioctl - if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then - atf_fail "Did not create a new ioctl port" - fi - if ! egrep -q '101[[:space:]]+102' after-ports; then + atf_check -o save:port-create.txt ctladm port -c -d "ioctl" -O pp=101 -O vp=102 + atf_check egrep -q "Port created successfully" port-create.txt + atf_check egrep -q "frontend: *ioctl" port-create.txt + atf_check egrep -q "port: *[0-9]+" port-create.txt + portnum=`awk '/port:/ {print $2}' port-create.txt` + atf_check -o save:portlist.txt ctladm portlist -qf ioctl + if ! egrep -q '101[[:space:]]+102' portlist.txt; then ctladm portlist atf_fail "Did not create the port with the specified options" fi @@ -109,13 +111,9 @@ disable_ioctl_body() { skip_if_ctld - atf_check -o save:before-ports ctladm portlist -qf ioctl - atf_check ctladm port -c -d "ioctl" - atf_check -o save:after-ports ctladm portlist -qf ioctl - if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then - atf_fail "Did not create a new ioctl port" - fi - portnum=`diff before-ports after-ports | awk '/ioctl/ {print $2}'`; + atf_check -o save:port-create.txt ctladm port -c -d "ioctl" + portnum=`awk '/port:/ {print $2}' port-create.txt` + atf_check -o save:portlist.txt ctladm portlist -qf ioctl atf_check -o ignore ctladm port -o off -p $portnum atf_check -o match:"^$portnum *NO" ctladm portlist -qf ioctl } @@ -134,13 +132,9 @@ enable_ioctl_body() { skip_if_ctld - atf_check -o save:before-ports ctladm portlist -qf ioctl - atf_check ctladm port -c -d "ioctl" - atf_check -o save:after-ports ctladm portlist -qf ioctl - if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then - atf_fail "Did not create a new ioctl port" - fi - portnum=`diff before-ports after-ports | awk '/ioctl/ {print $2}'`; + atf_check -o save:port-create.txt ctladm port -c -d "ioctl" + portnum=`awk '/port:/ {print $2}' port-create.txt` + atf_check -o save:portlist.txt ctladm portlist -qf ioctl atf_check -o ignore ctladm port -o off -p $portnum atf_check -o ignore ctladm port -o on -p $portnum atf_check -o match:"^$portnum *YES" ctladm portlist -qf ioctl @@ -160,14 +154,18 @@ remove_ioctl_body() { skip_if_ctld - atf_check -o save:before-ports ctladm portlist -qf ioctl - atf_check ctladm port -c -d "ioctl" - atf_check -o save:after-ports ctladm portlist -qf ioctl - if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then - atf_fail "Did not create a new ioctl port" + # Specify exact pp and vp to make the post-removal portlist check + # unambiguous + atf_check -o save:port-create.txt ctladm port -c -d "ioctl" -O pp=10001 -O vp=10002 + portnum=`awk '/port:/ {print $2}' port-create.txt` + atf_check -o save:portlist.txt ctladm portlist -qf ioctl + atf_check -o inline:"Port destroyed successfully\n" ctladm port -r -d ioctl -p $portnum + # Check that the port was removed. A new port may have been added with + # the same ID, so match against the pp and vp numbers, too. + if ctladm portlist -qf ioctl | egrep -q "^${portnum} .*10001 *10002"; then + ctladm portlist -qf ioctl + atf_fail "port was not removed" fi - portnum=`diff before-ports after-ports | awk '/ioctl/ {print $2}'`; - atf_check ctladm port -r -d ioctl -p $portnum } atf_init_test_cases()