From nobody Mon Jun 10 16:01:45 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 4Vyc4T4LnHz5M8y8; Mon, 10 Jun 2024 16:01:45 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vyc4T2nMdz4pWy; Mon, 10 Jun 2024 16:01:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718035305; 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=+gGCURNHyXgNtnm6cbe+d1MFAdv7+rScwceCtsiaWDQ=; b=iWXgxDKe5+E09buIPpzHAkgmoft0BWft5MOxVEt7JCcb1O/c8zOtxdkbZBZyjaP5NNQbyp CyqI5a9CEjxar+MlDWD31VVGyK/dNTSwRJ1nkVEQkQcM8hYdoV00kXVFYbUtOeEuUwaBEY NZahP5J84y0nCLJMFYFV8Blcyv4MgWzW4oLY6JB4kL95MW3X9xp17nSmIMi7b3B+qugEXj WtOSJWykXNhEDPnC0kOaNdXFmss8ArlkRBOTp4EtjvMALWrYih5m1CudAK4l6nT2RuNIKx vlm/V1tNGOCkaF0CNbPjqKmL+65EC+zj3+NYK5ibsaIsZt1/FMXdiy1Pm6v5GQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718035305; a=rsa-sha256; cv=none; b=akwtykSj2PUZ4F4oYEgokPkaLnjH2FGt+JOSy5zRmBNItVCIcKd6Q0S0DaM3b0QHnv0v5n Km5nj+cnhPRQtjBCgZWocVyHBzVd/DUBq7SVbG5YmCqm1I5OlbeaGoL8m9RWx4xAIq3vBZ e/E5hBCisUDZ7A+oLunVrclaV/lG/K+lxJufKb+gJE0hbZJ0VCt5/Yai899E+8wgzmjjqT IFT3ByqqhZ3vnhYNuZWLrmI92PwQjYnHeihMnJHK/JmXsEQ2k7k4wxBnaqPS48cXEB5Yv0 P7PbqZPKbTSJKelpMqE1542ypKl/e8j1JbuAlhKwBSS+Py24u169DoYbMXKjjQ== 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=1718035305; 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=+gGCURNHyXgNtnm6cbe+d1MFAdv7+rScwceCtsiaWDQ=; b=LncYoxTG93FtxBmZaId6/Bb9yC9nortz9PDhyyTEXqktOlU8vBFe4lp+FU/4Hi5894k/VR qvMN9WwvApsp4nJfuqHSOf9HBB6vWsr3DW1hk3E6uqo74YaX1VDptHazmjo1g2bkPS/BuL 2iGyUn0eAUPllxpnE/qdmCPTMDq8ufu5eULLf3L6GTNvS2Mg2mvfsB+K1IFXBwyOEaNFnj 6k1GaefSosQezHXSqUhRgh4aqsqPjbfyiDURh8FWX9rV4CbIgDsJRLaQIAqZMqmfQcgvHp mXNsC6/EYsuVvMfzrmyTN0rhGQykliBWp1VxE+OMPZJH25V7F8c3vDggD6lUDA== 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 4Vyc4T2Pv2zXqJ; Mon, 10 Jun 2024 16:01:45 +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 45AG1jVg001519; Mon, 10 Jun 2024 16:01:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45AG1jSb001516; Mon, 10 Jun 2024 16:01:45 GMT (envelope-from git) Date: Mon, 10 Jun 2024 16:01:45 GMT Message-Id: <202406101601.45AG1jSb001516@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: edbd489d09ba - main - ctladm: don't require the use of "-p" with "port -r" 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/main X-Git-Reftype: branch X-Git-Commit: edbd489d09babebdc6c03924a912013be584c409 Auto-Submitted: auto-generated The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=edbd489d09babebdc6c03924a912013be584c409 commit edbd489d09babebdc6c03924a912013be584c409 Author: Alan Somers AuthorDate: 2024-06-06 19:14:43 +0000 Commit: Alan Somers CommitDate: 2024-06-10 16:01:25 +0000 ctladm: don't require the use of "-p" with "port -r" When removing a port, the ioctl frontend requires the "-p" argument. But other frontends, like cfiscsi, do not. So don't require that argument in the ctladm command. The frontend driver will report an error if any required argument is missing. MFC after: 2 weeks Sponsored by: Axcient Reviewed by: mav Pull Request: https://github.com/freebsd/freebsd-src/pull/1279 --- sys/cam/ctl/ctl_frontend_ioctl.c | 2 +- usr.sbin/ctladm/ctladm.8 | 3 +-- usr.sbin/ctladm/ctladm.c | 10 +++------- usr.sbin/ctladm/tests/port.sh | 28 +++++++++++++++++++++++----- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/sys/cam/ctl/ctl_frontend_ioctl.c b/sys/cam/ctl/ctl_frontend_ioctl.c index 7fc8deac82b3..3449154afb38 100644 --- a/sys/cam/ctl/ctl_frontend_ioctl.c +++ b/sys/cam/ctl/ctl_frontend_ioctl.c @@ -267,7 +267,7 @@ cfi_ioctl_port_remove(struct ctl_req *req) if (port_id == -1) { req->status = CTL_LUN_ERROR; snprintf(req->error_str, sizeof(req->error_str), - "port_id not provided"); + "Missing required argument: port_id"); return; } diff --git a/usr.sbin/ctladm/ctladm.8 b/usr.sbin/ctladm/ctladm.8 index 5c6e4aa04c77..72f0162eed54 100644 --- a/usr.sbin/ctladm/ctladm.8 +++ b/usr.sbin/ctladm/ctladm.8 @@ -673,8 +673,7 @@ and Specify the frontend port number. The port numbers can be found in the frontend port list. .It Fl r -Remove port specified with -.Pq Fl p Ar targ_port . +Remove a port. .It Fl t Ar fe_type Specify the frontend type used by the .Pq Fl o , diff --git a/usr.sbin/ctladm/ctladm.c b/usr.sbin/ctladm/ctladm.c index 14951797ddf1..46b7b88547dd 100644 --- a/usr.sbin/ctladm/ctladm.c +++ b/usr.sbin/ctladm/ctladm.c @@ -580,11 +580,6 @@ cctl_port(int fd, int argc, char **argv, char *combinedopt) break; } case CCTL_PORT_MODE_REMOVE: - if (targ_port == -1) { - warnx("%s: -r requires -p", __func__); - retval = 1; - goto bailout; - } /* FALLTHROUGH */ case CCTL_PORT_MODE_CREATE: { bzero(&req, sizeof(req)); @@ -594,8 +589,9 @@ cctl_port(int fd, int argc, char **argv, char *combinedopt) if (port_mode == CCTL_PORT_MODE_REMOVE) { req.reqtype = CTL_REQ_REMOVE; - nvlist_add_stringf(option_list, "port_id", "%d", - targ_port); + if (targ_port != -1) + nvlist_add_stringf(option_list, "port_id", "%d", + targ_port); } else req.reqtype = CTL_REQ_CREATE; diff --git a/usr.sbin/ctladm/tests/port.sh b/usr.sbin/ctladm/tests/port.sh index 1f2c9aaed5c1..139e1a7d29a0 100644 --- a/usr.sbin/ctladm/tests/port.sh +++ b/usr.sbin/ctladm/tests/port.sh @@ -37,8 +37,6 @@ cleanup() { ;; "iscsi") TARGET=`awk '/target:/ {print $2}' port-create.txt` - # PORTNUM is ignored, but must be set - PORTNUM=9999 ctladm port -r -d $driver -p "$PORTNUM" -O cfiscsi_portal_group_tag=$PGTAG -O cfiscsi_target=$TARGET ;; esac @@ -68,6 +66,25 @@ create_ioctl_cleanup() cleanup ioctl } +atf_test_case remove_ioctl_without_required_args cleanup +remove_ioctl_without_required_args_head() +{ + atf_set "descr" "ctladm will gracefully fail to remove an ioctl target if required arguments are missing" + atf_set "require.user" "root" +} +remove_ioctl_without_required_args_body() +{ + skip_if_ctld + + atf_check -o save:port-create.txt ctladm port -c -d "ioctl" + atf_check egrep -q "Port created successfully" port-create.txt + atf_check -s exit:1 -e match:"Missing required argument: port_id" ctladm port -r -d "ioctl" +} +remove_ioctl_without_required_args_cleanup() +{ + cleanup ioctl +} + atf_test_case create_iscsi cleanup create_iscsi_head() { @@ -246,7 +263,7 @@ remove_iscsi_body() atf_check -o save:port-create.txt ctladm port -c -d "iscsi" -O cfiscsi_portal_group_tag=$PGTAG -O cfiscsi_target="$TARGET" portnum=`awk '/port:/ {print $2}' port-create.txt` atf_check -o save:portlist.txt ctladm portlist -qf iscsi - atf_check -o inline:"Port destroyed successfully\n" ctladm port -r -d iscsi -p 9999 -O cfiscsi_portal_group_tag=$PGTAG -O cfiscsi_target="$TARGET" + atf_check -o inline:"Port destroyed successfully\n" ctladm port -r -d iscsi -O cfiscsi_portal_group_tag=$PGTAG -O cfiscsi_target="$TARGET" # Check that the port was removed. A new port may have been added with # the same ID, so match against the target and tag, too. PGTAGHEX=0x7631 # PGTAG in hex @@ -270,8 +287,8 @@ remove_iscsi_without_required_args_body() TARGET=iqn.2018-10.myhost.remove_iscsi_without_required_args atf_check -o save:port-create.txt ctladm port -c -d "iscsi" -O cfiscsi_portal_group_tag=$PGTAG -O cfiscsi_target="$TARGET" echo "target: $TARGET" >> port-create.txt - atf_check -s exit:1 -e match:"Missing required argument: cfiscsi_portal_group_tag" ctladm port -r -d iscsi -p 9999 -O cfiscsi_target="$TARGET" - atf_check -s exit:1 -e match:"Missing required argument: cfiscsi_target" ctladm port -r -d iscsi -p 9999 -O cfiscsi_portal_group_tag=$PGTAG + atf_check -s exit:1 -e match:"Missing required argument: cfiscsi_portal_group_tag" ctladm port -r -d iscsi -O cfiscsi_target="$TARGET" + atf_check -s exit:1 -e match:"Missing required argument: cfiscsi_target" ctladm port -r -d iscsi -O cfiscsi_portal_group_tag=$PGTAG } remove_iscsi_without_required_args_cleanup() { @@ -288,6 +305,7 @@ atf_init_test_cases() atf_add_test_case disable_ioctl atf_add_test_case enable_ioctl atf_add_test_case remove_ioctl + atf_add_test_case remove_ioctl_without_required_args atf_add_test_case remove_iscsi atf_add_test_case remove_iscsi_without_required_args }