From nobody Fri May 03 00:16:13 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 4VVrv15d5Xz5KKHg; Fri, 3 May 2024 00:16:13 +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 4VVrv14fCRz4RM1; Fri, 3 May 2024 00:16:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714695373; 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=5P2GZieahd97sknY+lsLpItDW/f3L7OSaysAVLRmCS0=; b=R4I3OOf8dtwMZofsirURg0RwrIhUAwKr9hLpI2M7hyCJYIFfe8yTl2svvRvDieJbWIo+7j yhqna4jIDuz87bvfVkvhC07QSsJrQtx5I8D27vsRB5IoXpf/bdPXY0m4jXtqiCZnytPwAe ppRxDiL24P9ZquTdUXO7V/WFF7MWb4De4okE13TwphNtVzmpyn82dhcOjLVOhxCCosf2hV ssXYa4msY8siCWW5InRVpoEhv2tQj97HHEmkuPiH1k0FBJOaQCvKsoJZ8v65J+lUU9YHPr rWBmMWwaJ9JIGnd0Eutjc6E4GUqg4qV+7GJBFMzilU/pakg0DW9RoS7kScK/Cg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714695373; a=rsa-sha256; cv=none; b=yqi9RCAJsLF1vXAXu5eLyW3R0468sEhUcLfg7UZDoBnwwBvegsks2oit2DvEO8pGlB4mLA IyjEoXvnaLm7WF3PnHqA6auzf8ShiihlXxN65fa4JAE1P5vaalFf872CoaYrPu4LbGUUIh j0xSk7ASVGRw5vJash6AMJaFSWFbHiThyfHk+GydMVZJsNfSssF0946Jd2Mv+91r6B/3xi XwIKd8aJeKR7ifsv9smeMR4aThET7H5kYVHhdpWySolNLGHHaHVmKGY3zZzg97N6sukUIl a5dewo6yFjrH4mphdptMNTafvzhDq2z5QXXLpL2S1rP/YfiHv2PJBpv6ojn08Q== 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=1714695373; 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=5P2GZieahd97sknY+lsLpItDW/f3L7OSaysAVLRmCS0=; b=foouSj4xQitEfXKFUsi58d9mrJZWHtZ/Y5i8enYlsHSBLf2o+Hk6d9I2K9J0A0xEENp03w lsnWnGBcOeZEpUbWngULhHDp6efXtBIaEuS/tTXMXZ+AumonG5a1+OBIG4j1CKkWb61yHM pFTRrcnXaq5fbYZmwnRmjNzGl/G0VM7ZN9H3l5pUebnyLkFlGn08dwF+n/eTg8m0kK5FCX hdbUrxxc6aVZszicFSMMRsc1b7HS76gN+kercoDul+5iSAajoUin+NLVy+6/IjezSIZK8k fn0e85KeVDWHbQRgmO396WrYOSkUGyeHMul7YzJL61z3XQmWrWDVHpbRP2jT1Q== 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 4VVrv14GfqzP3G; Fri, 3 May 2024 00:16:13 +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 4430GDhJ080316; Fri, 3 May 2024 00:16:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4430GDfG080313; Fri, 3 May 2024 00:16:13 GMT (envelope-from git) Date: Fri, 3 May 2024 00:16:13 GMT Message-Id: <202405030016.4430GDfG080313@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 17c907dd7acf - main - ctladm: Add nvterminate command to drop active NVMeoF associations 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 17c907dd7acf15cb54d6eca53fcc9eb7401f95ba Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=17c907dd7acf15cb54d6eca53fcc9eb7401f95ba commit 17c907dd7acf15cb54d6eca53fcc9eb7401f95ba Author: John Baldwin AuthorDate: 2024-05-02 23:35:20 +0000 Commit: John Baldwin CommitDate: 2024-05-02 23:38:39 +0000 ctladm: Add nvterminate command to drop active NVMeoF associations Reviewed by: imp Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D44729 --- usr.sbin/ctladm/ctladm.8 | 13 +++++++++ usr.sbin/ctladm/ctladm.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/usr.sbin/ctladm/ctladm.8 b/usr.sbin/ctladm/ctladm.8 index 6e084c30de36..2c90e12ef924 100644 --- a/usr.sbin/ctladm/ctladm.8 +++ b/usr.sbin/ctladm/ctladm.8 @@ -202,6 +202,9 @@ .Op Fl v .Op Fl x .Nm +.Ic nvterminate +.Aq Fl a | Fl c Ar controller-id | Fl h Ar name +.Nm .Ic help .Sh DESCRIPTION The @@ -876,6 +879,16 @@ Dump the raw XML. The sessions list information from the kernel comes in XML format, and this option allows the display of the raw XML data. .El +.It Ic nvterminate +Forcibly terminate NVMeoF associations matching criteria. +.Bl -tag -width 11n +.It Fl a +Terminate all associations. +.It Fl c +Specify controller ID. +.It Fl h +Specify host name. +.El .It Ic help Display .Nm diff --git a/usr.sbin/ctladm/ctladm.c b/usr.sbin/ctladm/ctladm.c index d0456986fd12..0b034b21b2b1 100644 --- a/usr.sbin/ctladm/ctladm.c +++ b/usr.sbin/ctladm/ctladm.c @@ -115,7 +115,8 @@ typedef enum { CTLADM_CMD_ISLOGOUT, CTLADM_CMD_ISTERMINATE, CTLADM_CMD_LUNMAP, - CTLADM_CMD_NVLIST + CTLADM_CMD_NVLIST, + CTLADM_CMD_NVTERMINATE } ctladm_cmdfunction; typedef enum { @@ -182,6 +183,7 @@ static struct ctladm_opts option_table[] = { {"modesense", CTLADM_CMD_MODESENSE, CTLADM_ARG_NEED_TL, "P:S:dlm:c:"}, {"modify", CTLADM_CMD_MODIFY, CTLADM_ARG_NONE, "b:l:o:s:"}, {"nvlist", CTLADM_CMD_NVLIST, CTLADM_ARG_NONE, "vx"}, + {"nvterminate", CTLADM_CMD_NVTERMINATE, CTLADM_ARG_NONE, "ac:h:"}, {"port", CTLADM_CMD_PORT, CTLADM_ARG_NONE, "lo:O:d:crp:qt:w:W:x"}, {"portlist", CTLADM_CMD_PORTLIST, CTLADM_ARG_NONE, "f:ilp:qvx"}, {"prin", CTLADM_CMD_PRES_IN, CTLADM_ARG_NEED_TL, "a:"}, @@ -4066,6 +4068,70 @@ bailout: return (retval); } +static int +cctl_nvterminate(int fd, int argc, char **argv, char *combinedopt) +{ + struct ctl_nvmf req; + int retval = 0, c; + int all = 0, cntlid = -1, nargs = 0; + char *hostnqn = NULL; + + while ((c = getopt(argc, argv, combinedopt)) != -1) { + switch (c) { + case 'a': + all = 1; + nargs++; + break; + case 'c': + cntlid = strtoul(optarg, NULL, 0); + nargs++; + break; + case 'h': + hostnqn = strdup(optarg); + if (hostnqn == NULL) + err(1, "%s: strdup", __func__); + nargs++; + break; + default: + break; + } + } + + if (nargs == 0) + errx(1, "%s: either -a, -c, or -h must be specified", + __func__); + if (nargs > 1) + errx(1, "%s: only one of -a, -c, or -h may be specified", + __func__); + + bzero(&req, sizeof(req)); + req.type = CTL_NVMF_TERMINATE; + req.data.terminate.cntlid = cntlid; + if (hostnqn != NULL) + strlcpy(req.data.terminate.hostnqn, + hostnqn, sizeof(req.data.terminate.hostnqn)); + if (all != 0) + req.data.terminate.all = 1; + + if (ioctl(fd, CTL_NVMF, &req) == -1) { + warn("%s: error issuing CTL_NVMF ioctl", __func__); + retval = 1; + goto bailout; + } + + if (req.status != CTL_NVMF_OK) { + warnx("%s: error returned from CTL NVMeoF connection " + "termination request:\n%s", __func__, req.error_str); + retval = 1; + goto bailout; + } + + printf("NVMeoF connections terminated\n"); + +bailout: + return (retval); +} + void usage(int error) { @@ -4113,11 +4179,12 @@ usage(int error) " ctladm islogout <-a | -c connection-id | -i name | -p portal>\n" " ctladm isterminate <-a | -c connection-id | -i name | -p portal>\n" " ctladm nvlist [-v | -x]\n" +" ctladm nvterminate <-a | -c controller-id | -h name>\n" " ctladm dumpooa\n" " ctladm dumpstructs\n" " ctladm help\n" "General Options:\n" -"-I intiator_id : defaults to 7, used to change the initiator id\n" +"-I initiator_id : defaults to 7, used to change the initiator id\n" "-C retries : specify the number of times to retry this command\n" "-D devicename : specify the device to operate on\n" " : (default is %s)\n" @@ -4512,6 +4579,9 @@ main(int argc, char **argv) case CTLADM_CMD_NVLIST: retval = cctl_nvlist(fd, argc, argv, combinedopt); break; + case CTLADM_CMD_NVTERMINATE: + retval = cctl_nvterminate(fd, argc, argv, combinedopt); + break; case CTLADM_CMD_HELP: default: usage(retval);