The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=5a656ef632de2f363f37484b0128aa60b688bf32

commit 5a656ef632de2f363f37484b0128aa60b688bf32
Author:     Warner Losh <i...@freebsd.org>
AuthorDate: 2025-07-10 15:56:20 +0000
Commit:     Warner Losh <i...@freebsd.org>
CommitDate: 2025-07-10 16:17:00 +0000

    cam: Add xpt_gdev_type() and use it instead of many copies of same
    
    Add a convenience wrapper to XPT_GDEV_TYPE in the same way we have one
    for XPT_PATH_INQ. The changes from PRIORITY_NORMAL to PRIORITY_NONE are
    intentional because this isn't a queued CCB. Please note: we have
    several places still that construct a XPT_GDEV_TYPE message by
    overwriting a CCB that happens to be laying around. I've not used this
    method, by and large, in those places since I didn't want to risk
    upsetting allocation flags that might be present (since we use a specail
    allocator for some CCB types in *_da.c).
    
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D51216
---
 sys/cam/ata/ata_da.c        |  5 +----
 sys/cam/cam_periph.c        | 16 +++-------------
 sys/cam/cam_xpt.c           |  5 +----
 sys/cam/cam_xpt.h           | 18 ++++++++++++++++--
 sys/cam/mmc/mmc_da.c        |  5 +----
 sys/cam/scsi/scsi_all.c     | 12 ++----------
 sys/cam/scsi/scsi_cd.c      |  8 +-------
 sys/cam/scsi/scsi_ch.c      |  6 +-----
 sys/cam/scsi/scsi_da.c      |  6 +-----
 sys/cam/scsi/scsi_enc_ses.c |  5 +----
 sys/cam/scsi/scsi_sa.c      |  7 +------
 11 files changed, 29 insertions(+), 64 deletions(-)

diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c
index ae7cf14c8f8e..1facab47473c 100644
--- a/sys/cam/ata/ata_da.c
+++ b/sys/cam/ata/ata_da.c
@@ -1359,10 +1359,7 @@ adaasync(void *callback_arg, uint32_t code,
        case AC_GETDEV_CHANGED:
        {
                softc = (struct ada_softc *)periph->softc;
-               memset(&cgd, 0, sizeof(cgd));
-               xpt_setup_ccb(&cgd.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
-               cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-               xpt_action((union ccb *)&cgd);
+               xpt_gdev_type(&cgd, periph->path);
 
                /*
                 * Update our information based on the new Identify data.
diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c
index 2cf1ef5f53ef..730656684e2a 100644
--- a/sys/cam/cam_periph.c
+++ b/sys/cam/cam_periph.c
@@ -771,10 +771,7 @@ camperiphfree(struct cam_periph *periph)
                case AC_FOUND_DEVICE: {
                        struct ccb_getdev cgd;
 
-                       memset(&cgd, 0, sizeof(cgd));
-                       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-                       xpt_setup_ccb(&cgd.ccb_h, periph->path, 
CAM_PRIORITY_NORMAL);
-                       xpt_action((union ccb *)&cgd);
+                       xpt_gdev_type(&cgd, periph->path);
                        periph->deferred_callback(NULL, periph->deferred_ac,
                            periph->path, &cgd);
                        break;
@@ -1686,10 +1683,7 @@ camperiphscsisenseerror(union ccb *ccb, union ccb **orig,
                /*
                 * Grab the inquiry data for this device.
                 */
-               memset(&cgd, 0, sizeof(cgd));
-               xpt_setup_ccb(&cgd.ccb_h, ccb->ccb_h.path, CAM_PRIORITY_NORMAL);
-               cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-               xpt_action((union ccb *)&cgd);
+               xpt_gdev_type(&cgd, ccb->ccb_h.path);
 
                err_action = scsi_error_action(&ccb->csio, &cgd.inq_data,
                    sense_flags);
@@ -2137,11 +2131,7 @@ cam_periph_devctl_notify(union ccb *ccb)
 
        sbuf_cat(&sb, "serial=\"");
        if ((cgd = (struct ccb_getdev *)xpt_alloc_ccb_nowait()) != NULL) {
-               xpt_setup_ccb(&cgd->ccb_h, ccb->ccb_h.path,
-                   CAM_PRIORITY_NORMAL);
-               cgd->ccb_h.func_code = XPT_GDEV_TYPE;
-               xpt_action((union ccb *)cgd);
-
+               xpt_gdev_type(cgd, ccb->ccb_h.path);
                if (cgd->ccb_h.status == CAM_REQ_CMP)
                        sbuf_bcat(&sb, cgd->serial_num, cgd->serial_num_len);
                xpt_free_ccb((union ccb *)cgd);
diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c
index 38bc82c69aad..2ec736e7f4ac 100644
--- a/sys/cam/cam_xpt.c
+++ b/sys/cam/cam_xpt.c
@@ -2471,15 +2471,12 @@ xptsetasyncfunc(struct cam_ed *device, void *arg)
        if ((device->flags & CAM_DEV_UNCONFIGURED) != 0)
                return (1);
 
-       memset(&cgd, 0, sizeof(cgd));
        xpt_compile_path(&path,
                         NULL,
                         device->target->bus->path_id,
                         device->target->target_id,
                         device->lun_id);
-       xpt_setup_ccb(&cgd.ccb_h, &path, CAM_PRIORITY_NORMAL);
-       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-       xpt_action((union ccb *)&cgd);
+       xpt_gdev_type(&cgd, &path);
        csa->callback(csa->callback_arg,
                            AC_FOUND_DEVICE,
                            &path, &cgd);
diff --git a/sys/cam/cam_xpt.h b/sys/cam/cam_xpt.h
index 57225a0ae92d..3815f42cba40 100644
--- a/sys/cam/cam_xpt.h
+++ b/sys/cam/cam_xpt.h
@@ -145,8 +145,8 @@ uint32_t            xpt_poll_setup(union ccb *start_ccb);
 void                   xpt_sim_poll(struct cam_sim *sim);
 
 /*
- * Perform a path inquiry at the request priority. bzero may be redundant for
- * allocated CCBs, but for the on-stack CCBs it's required.
+ * Perform a path inquiry. bzero may be redundant for allocated CCBs, but for
+ * the on-stack CCBs it's required.
  */
 static inline void
 xpt_path_inq(struct ccb_pathinq *cpi, struct cam_path *path)
@@ -158,6 +158,20 @@ xpt_path_inq(struct ccb_pathinq *cpi, struct cam_path 
*path)
        xpt_action((union ccb *)cpi);
 }
 
+/*
+ * Perform get device type. bzero may be redundant for allocated CCBs, but for
+ * the on-stack CCBs it's required.
+ */
+static inline void
+xpt_gdev_type(struct ccb_getdev *cgd, struct cam_path *path)
+{
+
+       bzero(cgd, sizeof(*cgd));
+       xpt_setup_ccb(&cgd->ccb_h, path, CAM_PRIORITY_NONE);
+       cgd->ccb_h.func_code = XPT_GDEV_TYPE;
+       xpt_action((union ccb *)cgd);
+}
+
 #endif /* _KERNEL */
 
 #endif /* _CAM_CAM_XPT_H */
diff --git a/sys/cam/mmc/mmc_da.c b/sys/cam/mmc/mmc_da.c
index f7c478076144..7f8bf3516804 100644
--- a/sys/cam/mmc/mmc_da.c
+++ b/sys/cam/mmc/mmc_da.c
@@ -692,10 +692,7 @@ sddaasync(void *callback_arg, uint32_t code,
        case AC_GETDEV_CHANGED:
        {
                CAM_DEBUG(path, CAM_DEBUG_TRACE, ("=> AC_GETDEV_CHANGED\n"));
-               memset(&cgd, 0, sizeof(cgd));
-               xpt_setup_ccb(&cgd.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
-               cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-               xpt_action((union ccb *)&cgd);
+               xpt_gdev_type(&cgd, periph->path);
                cam_periph_async(periph, code, path, arg);
                break;
        }
diff --git a/sys/cam/scsi/scsi_all.c b/sys/cam/scsi/scsi_all.c
index 13a376ebb6e3..b518f84454ad 100644
--- a/sys/cam/scsi/scsi_all.c
+++ b/sys/cam/scsi/scsi_all.c
@@ -3708,11 +3708,7 @@ scsi_command_string(struct cam_device *device, struct 
ccb_scsiio *csio,
        /*
         * Get the device information.
         */
-       xpt_setup_ccb(&cgd->ccb_h,
-                     csio->ccb_h.path,
-                     CAM_PRIORITY_NORMAL);
-       cgd->ccb_h.func_code = XPT_GDEV_TYPE;
-       xpt_action((union ccb *)cgd);
+       xpt_gdev_type(cgd, csio->ccb_h.path);
 
        /*
         * If the device is unconfigured, just pretend that it is a hard
@@ -5144,11 +5140,7 @@ scsi_sense_sbuf(struct cam_device *device, struct 
ccb_scsiio *csio,
        /*
         * Get the device information.
         */
-       xpt_setup_ccb(&cgd->ccb_h,
-                     csio->ccb_h.path,
-                     CAM_PRIORITY_NORMAL);
-       cgd->ccb_h.func_code = XPT_GDEV_TYPE;
-       xpt_action((union ccb *)cgd);
+       xpt_gdev_type(cgd, csio->ccb_h.path);
 
        /*
         * If the device is unconfigured, just pretend that it is a hard
diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c
index 00a417f65052..e622a96ec77e 100644
--- a/sys/cam/scsi/scsi_cd.c
+++ b/sys/cam/scsi/scsi_cd.c
@@ -1240,13 +1240,7 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
                                                 /*getcount_only*/0);
 
                                status = done_ccb->ccb_h.status;
-
-                               bzero(&cgd, sizeof(cgd));
-                               xpt_setup_ccb(&cgd.ccb_h,
-                                             done_ccb->ccb_h.path,
-                                             CAM_PRIORITY_NORMAL);
-                               cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-                               xpt_action((union ccb *)&cgd);
+                               xpt_gdev_type(&cgd, done_ccb->ccb_h.path);
 
                                if (scsi_extract_sense_ccb(done_ccb,
                                    &error_code, &sense_key, &asc, &ascq))
diff --git a/sys/cam/scsi/scsi_ch.c b/sys/cam/scsi/scsi_ch.c
index 89a817c1b488..3da22ba61392 100644
--- a/sys/cam/scsi/scsi_ch.c
+++ b/sys/cam/scsi/scsi_ch.c
@@ -1705,11 +1705,7 @@ chscsiversion(struct cam_periph *periph)
        /*
         * Get the device information.
         */
-       xpt_setup_ccb(&cgd->ccb_h,
-                     periph->path,
-                     CAM_PRIORITY_NORMAL);
-       cgd->ccb_h.func_code = XPT_GDEV_TYPE;
-       xpt_action((union ccb *)cgd);
+       xpt_gdev_type(cgd, periph->path);
 
        if (cgd->ccb_h.status != CAM_REQ_CMP) {
                xpt_free_ccb((union ccb *)cgd);
diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c
index 0a2389cd9b5d..9eda664ee7b0 100644
--- a/sys/cam/scsi/scsi_da.c
+++ b/sys/cam/scsi/scsi_da.c
@@ -5035,11 +5035,7 @@ dadone_proberc(struct cam_periph *periph, union ccb 
*done_ccb)
                                                 /*timeout*/0,
                                                 /*getcount_only*/0);
 
-                       memset(&cgd, 0, sizeof(cgd));
-                       xpt_setup_ccb(&cgd.ccb_h, done_ccb->ccb_h.path,
-                                     CAM_PRIORITY_NORMAL);
-                       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-                       xpt_action((union ccb *)&cgd);
+                       xpt_gdev_type(&cgd, done_ccb->ccb_h.path);
 
                        if (scsi_extract_sense_ccb(done_ccb,
                            &error_code, &sense_key, &asc, &ascq))
diff --git a/sys/cam/scsi/scsi_enc_ses.c b/sys/cam/scsi/scsi_enc_ses.c
index c429e820a1fd..435874a9874a 100644
--- a/sys/cam/scsi/scsi_enc_ses.c
+++ b/sys/cam/scsi/scsi_enc_ses.c
@@ -979,10 +979,7 @@ ses_paths_iter(enc_softc_t *enc, enc_element_t *elm,
                             != CAM_REQ_CMP)
                                return;
 
-                       memset(&cgd, 0, sizeof(cgd));
-                       xpt_setup_ccb(&cgd.ccb_h, path, CAM_PRIORITY_NORMAL);
-                       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-                       xpt_action((union ccb *)&cgd);
+                       xpt_gdev_type(&cgd, path);
                        if (cam_ccb_success((union ccb *)&cgd))
                                callback(enc, elm, path, callback_arg);
 
diff --git a/sys/cam/scsi/scsi_sa.c b/sys/cam/scsi/scsi_sa.c
index cfd48c98f30e..88147393192f 100644
--- a/sys/cam/scsi/scsi_sa.c
+++ b/sys/cam/scsi/scsi_sa.c
@@ -4731,12 +4731,7 @@ saextget(struct cdev *dev, struct cam_periph *periph, 
struct sbuf *sb,
        SASBADDVARSTR(sb, indent, periph->periph_name, %s, periph_name,
            strlen(periph->periph_name) + 1);
        SASBADDUINT(sb, indent, periph->unit_number, %u, unit_number);
-       memset(&cgd, 0, sizeof(cgd));
-       xpt_setup_ccb(&cgd.ccb_h,
-                     periph->path,
-                     CAM_PRIORITY_NORMAL);
-       cgd.ccb_h.func_code = XPT_GDEV_TYPE;
-       xpt_action((union ccb *)&cgd);
+       xpt_gdev_type(&cgd, periph->path);
        if ((cgd.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
                g->status = MT_EXT_GET_ERROR;
                snprintf(g->error_str, sizeof(g->error_str),

Reply via email to