From nobody Fri Nov 05 15:25:40 2021 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 2316A18364A0; Fri, 5 Nov 2021 15:25:41 +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 4Hm48N51zqz4kmP; Fri, 5 Nov 2021 15:25:40 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5726119AF8; Fri, 5 Nov 2021 15:25:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A5FPee8073269; Fri, 5 Nov 2021 15:25:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A5FPepL073268; Fri, 5 Nov 2021 15:25:40 GMT (envelope-from git) Date: Fri, 5 Nov 2021 15:25:40 GMT Message-Id: <202111051525.1A5FPepL073268@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 577f9aa266e3 - main - cam_periph: Add ability to wire units to a serial number 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 577f9aa266e3407a2de9d6bd6d836a9ba984e944 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=577f9aa266e3407a2de9d6bd6d836a9ba984e944 commit 577f9aa266e3407a2de9d6bd6d836a9ba984e944 Author: Warner Losh AuthorDate: 2021-11-05 14:56:33 +0000 Commit: Warner Losh CommitDate: 2021-11-05 14:56:33 +0000 cam_periph: Add ability to wire units to a serial number For scsi, ata and nvme, at least, we read a serial number from the device (if the device supports it, some scsi drives do not) and record it during the *_xpt probe device state machine before it posts the AC_FOUND_DEVICE async event. For mmc, no serial number is ever retrieved, so it's always NULL. Add the ability to match this serial number during device wiring. This mechanism is competely optional, and often times using a label and/or some other attribute of the device is easier. However, other times wiring a unit to a serial number simplifies management as most monitoring tools require the *daX device and having it stable from boot to boot helps with data continuity. It can be especially helpful for nvme where no other means exists to reliably tie a ndaX device to an underlying nvme drive and namespace. A similar mechanism exists in Linux to mange device unit numbers with udev. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D32683 --- sys/cam/cam_periph.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c index 8fbc2e3926fa..bb4baaf0888f 100644 --- a/sys/cam/cam_periph.c +++ b/sys/cam/cam_periph.c @@ -69,7 +69,8 @@ static u_int camperiphnextunit(struct periph_driver *p_drv, lun_id_t lun); static u_int camperiphunit(struct periph_driver *p_drv, path_id_t pathid, target_id_t target, - lun_id_t lun); + lun_id_t lun, + const char *sn); static void camperiphdone(struct cam_periph *periph, union ccb *done_ccb); static void camperiphfree(struct cam_periph *periph); @@ -273,7 +274,8 @@ cam_periph_alloc(periph_ctor_t *periph_ctor, free(periph, M_CAMPERIPH); return (CAM_REQ_INVALID); } - periph->unit_number = camperiphunit(*p_drv, path_id, target_id, lun_id); + periph->unit_number = camperiphunit(*p_drv, path_id, target_id, lun_id, + path->device->serial_num); cur_periph = TAILQ_FIRST(&(*p_drv)->units); while (cur_periph != NULL && cur_periph->unit_number < periph->unit_number) @@ -582,7 +584,8 @@ camperiphnextunit(struct periph_driver *p_drv, u_int newunit, int wired, if (newunit != dunit) continue; - if (resource_int_value(dname, dunit, "lun", &val) == 0 || + if (resource_string_value(dname, dunit, "sn", &strval) == 0 || + resource_int_value(dname, dunit, "lun", &val) == 0 || resource_int_value(dname, dunit, "target", &val) == 0 || resource_string_value(dname, dunit, "at", &strval) == 0) break; @@ -595,7 +598,7 @@ camperiphnextunit(struct periph_driver *p_drv, u_int newunit, int wired, static u_int camperiphunit(struct periph_driver *p_drv, path_id_t pathid, - target_id_t target, lun_id_t lun) + target_id_t target, lun_id_t lun, const char *sn) { u_int unit; int wired, i, val, dunit; @@ -624,6 +627,11 @@ camperiphunit(struct periph_driver *p_drv, path_id_t pathid, continue; wired++; } + if (resource_string_value(dname, dunit, "sn", &strval) == 0) { + if (sn == NULL || strcmp(strval, sn) != 0) + continue; + wired++; + } if (wired != 0) { unit = dunit; break;