From nobody Fri Sep 11 05:32:38 2026 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 4hh38k5htDz6rdmg for ; Fri, 11 Sep 2026 05:32:38 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hh38k4F5kz4NsQ for ; Fri, 11 Sep 2026 05:32:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789104758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GHbhGX2dor30EgSnMJX3P/u17rWsrjQm4XSSwcMV33I=; b=HL53Eo/r9QadZ6UlX4JYELzC8panGcsiiaS/hgoEG/AOqP6BtuALU8QPKFVukl8HBzFMsu DsVA11zkRkeshXbr90lzlWG7hPo9ckIh7wFG+rEW2HEbqt+7PLIO9FMxTj7YP5eJh/YoKw thGuD9bsa+Ojy1v+9haORreDfBI48MMXG3Dv+KwdKlQLbKXFHfxd4NTASmVD+dh0Dd4p6a MKid4kfaJjfktlXN8877O3pixL2DlXWmo4fmPkVsPDJXBSG12cFSt/KlSLB8/QHHLjUKYB GMFdrEnVlpWjPid/9Ak2s9SFfmE7rl38zDV49pWqNAqgy5Pc3emZryXULxWhDA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789104758; b=GhKDbT7HfsPXNSHFJ0yqbiMSJOFqsYO0hl5rLcf8bMScd3wo3Cm9COy67iKtHIvXsXk8p/ PR2maMtPhHFovJHgrozWqS3cv8I3RAYknWAw5eHJUNNFssYBvthFtW6QwuhT2aqQpKVDgA 2IY7/NqwKs2UPH5yT56MIuIjqy+YBiQLQ2D9qlNF7t8IWvC+bB92nCpgWX5RruIhg3ZGlF bsiBkEqECgPSQkGnzfDw6Nz9WV4NTSNNo8ysEWGCogumvWFRxxv8d7whKJaXyYRTt0+Pp5 Kh7Z0zvKMb+HbhqTe/a5wr6N/J02VGVN4VWakh0DDOJ4HJwmQPkApcNWoMjwDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789104758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GHbhGX2dor30EgSnMJX3P/u17rWsrjQm4XSSwcMV33I=; b=mny3HPCoUYVZ3IetZsEtLQBSA4UtN+v3s4fQX1HlYE9csgJuChkJZlmOb8RnbWYiyVdgSg zuE6+wYn86o9SO4dKt+z6eeKZ4SUJMGyBo9suYkm73/cXqv3TLH2SN7czC26QsGZzt5wBh rTccUD5UQTPlGzv4jf1OMz3II8YeIlwa3A2C+avDOr8aV9L8h6nomdqzYkp2H6d0nCZunx 20vma2swCAe0WjdKqtFYgySO1YmMswoDAp8M6CMkPzOHbmcjS2XMGO30fBTUAq2YH8BAfj eUHjaRvAzVJK2HNnwN18I9yFyuQ6WILuojqGYNtt0eZcDKnfrZgFfJ+r/hayKg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hh38k36wQz11PZ for ; Fri, 11 Sep 2026 05:32:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3fa83 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 11 Sep 2026 05:32:38 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Warner Losh From: Warner Losh Subject: git: a67354f213f8 - main - cam: Refactor cam_periph_devctl_notify init/fini bits 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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: a67354f213f83327cc4357db02985985c9c8db27 Auto-Submitted: auto-generated Date: Fri, 11 Sep 2026 05:32:38 +0000 Message-Id: <6aa39276.3fa83.4d175d4b@gitrepo.freebsd.org> The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a67354f213f83327cc4357db02985985c9c8db27 commit a67354f213f83327cc4357db02985985c9c8db27 Author: Warner Losh AuthorDate: 2026-09-11 05:13:02 +0000 Commit: Warner Losh CommitDate: 2026-09-11 05:13:02 +0000 cam: Refactor cam_periph_devctl_notify init/fini bits To be able to create other kinds of devctl notifications that don't flow through cam_periph_devctl_notify, refactor out the header / trailers we do and the sbuf life cycle management. No functional change. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D58526 --- sys/cam/cam_periph.c | 68 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c index 6fa5fa4a60d6..e34971a8e4ff 100644 --- a/sys/cam/cam_periph.c +++ b/sys/cam/cam_periph.c @@ -91,6 +91,10 @@ static int camperiphscsisenseerror(union ccb *ccb, uint32_t *action, const char **action_string); static void cam_periph_devctl_notify(union ccb *ccb); +static char *cam_periph_devctl_sb_init(struct sbuf *sb, + struct cam_periph *periph); +static void cam_periph_devctl_sb_fini(struct sbuf *sb, char *sbmsg, + const char *type); static int nperiph_drivers; static int initialized = 0; @@ -2110,32 +2114,65 @@ cam_periph_error(union ccb *ccb, cam_flags camflags, #define CAM_PERIPH_DEVD_MSG_SIZE 1024 -static void -cam_periph_devctl_notify(union ccb *ccb) +/* + * Allocate and initialize an sbuf for a devctl notification, populating it + * with the device name and serial number. Returns the malloc'd backing + * buffer, or NULL on allocation failure. On success, the caller can append + * additional fields to sb before calling cam_periph_devctl_sb_fini(). + */ +static char * +cam_periph_devctl_sb_init(struct sbuf *sb, struct cam_periph *periph) { - struct cam_periph *periph; struct ccb_getdev *cgd; - struct sbuf sb; - char *sbmsg, *type; + char *sbmsg; sbmsg = malloc(CAM_PERIPH_DEVD_MSG_SIZE, M_CAMPERIPH, M_NOWAIT); if (sbmsg == NULL) - return; + return (NULL); - sbuf_new(&sb, sbmsg, CAM_PERIPH_DEVD_MSG_SIZE, SBUF_FIXEDLEN); + sbuf_new(sb, sbmsg, CAM_PERIPH_DEVD_MSG_SIZE, SBUF_FIXEDLEN); - periph = xpt_path_periph(ccb->ccb_h.path); - sbuf_printf(&sb, "device=%s%d ", periph->periph_name, + sbuf_printf(sb, "device=%s%d ", periph->periph_name, periph->unit_number); - sbuf_cat(&sb, "serial=\""); + sbuf_cat(sb, "serial=\""); if ((cgd = (struct ccb_getdev *)xpt_alloc_ccb_nowait()) != NULL) { - xpt_gdev_type(cgd, ccb->ccb_h.path); + xpt_gdev_type(cgd, periph->path); if (cgd->ccb_h.status == CAM_REQ_CMP) - sbuf_bcat(&sb, cgd->serial_num, cgd->serial_num_len); + sbuf_bcat(sb, cgd->serial_num, cgd->serial_num_len); xpt_free_ccb((union ccb *)cgd); } - sbuf_cat(&sb, "\" "); + sbuf_cat(sb, "\" "); + + return (sbmsg); +} + +/* + * Finish and send a devctl notification, then clean up the sbuf and its + * backing buffer. + */ +static void +cam_periph_devctl_sb_fini(struct sbuf *sb, char *sbmsg, const char *type) +{ + + if (sbuf_finish(sb) == 0) + devctl_notify("CAM", "periph", type, sbuf_data(sb)); + sbuf_delete(sb); + free(sbmsg, M_CAMPERIPH); +} + +static void +cam_periph_devctl_notify(union ccb *ccb) +{ + struct cam_periph *periph; + struct sbuf sb; + char *sbmsg, *type; + + periph = xpt_path_periph(ccb->ccb_h.path); + sbmsg = cam_periph_devctl_sb_init(&sb, periph); + if (sbmsg == NULL) + return; + sbuf_printf(&sb, "cam_status=\"0x%x\" ", ccb->ccb_h.status); switch (ccb->ccb_h.status & CAM_STATUS_MASK) { @@ -2199,10 +2236,7 @@ cam_periph_devctl_notify(union ccb *ccb) break; } - if (sbuf_finish(&sb) == 0) - devctl_notify("CAM", "periph", type, sbuf_data(&sb)); - sbuf_delete(&sb); - free(sbmsg, M_CAMPERIPH); + cam_periph_devctl_sb_fini(&sb, sbmsg, type); } /*