From nobody Tue Oct 05 19:04:07 2021 X-Original-To: dev-commits-src-main@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 5CC1117EE3E3; Tue, 5 Oct 2021 19:04:07 +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 4HP6Sl28KCz4l8F; Tue, 5 Oct 2021 19:04:07 +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 2B233121D3; Tue, 5 Oct 2021 19:04:07 +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 195J47P4062168; Tue, 5 Oct 2021 19:04:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 195J479l062167; Tue, 5 Oct 2021 19:04:07 GMT (envelope-from git) Date: Tue, 5 Oct 2021 19:04:07 GMT Message-Id: <202110051904.195J479l062167@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: 8f9be1eed11c - main - cam(4): Improve XPT_DEV_MATCH List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8f9be1eed11c27c66386c3d72cd6c6aef597fa0d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=8f9be1eed11c27c66386c3d72cd6c6aef597fa0d commit 8f9be1eed11c27c66386c3d72cd6c6aef597fa0d Author: Alexander Motin AuthorDate: 2021-10-05 18:54:03 +0000 Commit: Alexander Motin CommitDate: 2021-10-05 18:54:03 +0000 cam(4): Improve XPT_DEV_MATCH Remove *_MATCH_NONE enums, making no sense and so never used. Make *_MATCH_ANY enums 0 (no any match flags set), previously used by *_MATCH_NONE. Bump CAM_VERSION to 0x1a reflecting those changes and add compat shims. When traversing through buses and devices do not descend if we can already see that requested pattern does not match the bus or device. It allows to save significant amount of time on system with thousands of disks when doing limited searches. Reviewed by: imp MFC after: 2 weeks Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D32304 --- sys/cam/cam_ccb.h | 11 +++----- sys/cam/cam_compat.c | 50 ++++++++++++++++++++++++++++++++-- sys/cam/cam_compat.h | 7 +++++ sys/cam/cam_xpt.c | 76 +++++++++++++--------------------------------------- 4 files changed, 78 insertions(+), 66 deletions(-) diff --git a/sys/cam/cam_ccb.h b/sys/cam/cam_ccb.h index 5b5e24904996..1ae310d399b7 100644 --- a/sys/cam/cam_ccb.h +++ b/sys/cam/cam_ccb.h @@ -422,13 +422,12 @@ struct ccb_getdevlist { }; typedef enum { - PERIPH_MATCH_NONE = 0x000, + PERIPH_MATCH_ANY = 0x000, PERIPH_MATCH_PATH = 0x001, PERIPH_MATCH_TARGET = 0x002, PERIPH_MATCH_LUN = 0x004, PERIPH_MATCH_NAME = 0x008, PERIPH_MATCH_UNIT = 0x010, - PERIPH_MATCH_ANY = 0x01f } periph_pattern_flags; struct periph_match_pattern { @@ -441,13 +440,12 @@ struct periph_match_pattern { }; typedef enum { - DEV_MATCH_NONE = 0x000, + DEV_MATCH_ANY = 0x000, DEV_MATCH_PATH = 0x001, DEV_MATCH_TARGET = 0x002, DEV_MATCH_LUN = 0x004, DEV_MATCH_INQUIRY = 0x008, DEV_MATCH_DEVID = 0x010, - DEV_MATCH_ANY = 0x00f } dev_pattern_flags; struct device_id_match_pattern { @@ -467,12 +465,11 @@ struct device_match_pattern { }; typedef enum { - BUS_MATCH_NONE = 0x000, + BUS_MATCH_ANY = 0x000, BUS_MATCH_PATH = 0x001, BUS_MATCH_NAME = 0x002, BUS_MATCH_UNIT = 0x004, BUS_MATCH_BUS_ID = 0x008, - BUS_MATCH_ANY = 0x00f } bus_pattern_flags; struct bus_match_pattern { @@ -594,7 +591,7 @@ struct ccb_dev_match { /* * Definitions for the path inquiry CCB fields. */ -#define CAM_VERSION 0x19 /* Hex value for current version */ +#define CAM_VERSION 0x1a /* Hex value for current version */ typedef enum { PI_MDP_ABLE = 0x80, /* Supports MDP message */ diff --git a/sys/cam/cam_compat.c b/sys/cam/cam_compat.c index 4c89072fa389..6893402a3d9c 100644 --- a/sys/cam/cam_compat.c +++ b/sys/cam/cam_compat.c @@ -58,6 +58,8 @@ static int cam_compat_handle_0x17(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td, d_ioctl_t *cbfnp); static int cam_compat_handle_0x18(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td, d_ioctl_t *cbfnp); +static int cam_compat_handle_0x19(struct cdev *dev, u_long cmd, caddr_t addr, + int flag, struct thread *td, d_ioctl_t *cbfnp); static int cam_compat_translate_dev_match_0x18(union ccb *ccb); int @@ -108,6 +110,22 @@ cam_compat_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, cmd = CAMGETPASSTHRU; error = cam_compat_handle_0x18(dev, cmd, addr, flag, td, cbfnp); break; + case CAMIOCOMMAND_0x19: + cmd = CAMIOCOMMAND; + error = cam_compat_handle_0x19(dev, cmd, addr, flag, td, cbfnp); + break; + case CAMGETPASSTHRU_0x19: + cmd = CAMGETPASSTHRU; + error = cam_compat_handle_0x19(dev, cmd, addr, flag, td, cbfnp); + break; + case CAMIOQUEUE_0x19: + cmd = CAMIOQUEUE; + error = cam_compat_handle_0x19(dev, cmd, addr, flag, td, cbfnp); + break; + case CAMIOGET_0x19: + cmd = CAMIOGET; + error = cam_compat_handle_0x19(dev, cmd, addr, flag, td, cbfnp); + break; default: error = ENOTTY; } @@ -170,7 +188,7 @@ cam_compat_handle_0x17(struct cdev *dev, u_long cmd, caddr_t addr, int flag, bcopy(ccbb17, ccbb, CAM_0X17_DATA_LEN); } - error = (cbfnp)(dev, cmd, (caddr_t)ccb, flag, td); + error = cam_compat_handle_0x19(dev, cmd, (caddr_t)ccb, flag, td, cbfnp); hdr17->pinfo = hdr->pinfo; hdr17->xpt_links = hdr->xpt_links; @@ -310,7 +328,7 @@ cam_compat_handle_0x18(struct cdev *dev, u_long cmd, caddr_t addr, int flag, bcopy(ccbb18, ccbb, CAM_0X18_DATA_LEN); } - error = (cbfnp)(dev, cmd, (caddr_t)ccb, flag, td); + error = cam_compat_handle_0x19(dev, cmd, (caddr_t)ccb, flag, td, cbfnp); hdr18->pinfo = hdr->pinfo; hdr18->xpt_links = hdr->xpt_links; @@ -420,3 +438,31 @@ cam_compat_translate_dev_match_0x18(union ccb *ccb) return (0); } + +static int +cam_compat_handle_0x19(struct cdev *dev, u_long cmd, caddr_t addr, int flag, + struct thread *td, d_ioctl_t *cbfnp) +{ + union ccb *ccb = (union ccb *)addr; + struct cam_periph_map_info mapinfo; + + if (cmd == CAMIOCOMMAND && ccb->ccb_h.func_code == XPT_DEV_MATCH) { + bzero(&mapinfo, sizeof(mapinfo)); + cam_periph_mapmem(ccb, &mapinfo, maxphys); + for (int i = 0; i < ccb->cdm.num_patterns; i++) { + struct dev_match_pattern *p = &ccb->cdm.patterns[i]; + + if (p->type == DEV_MATCH_BUS && + p->pattern.bus_pattern.flags == 0x00f) + p->pattern.bus_pattern.flags = BUS_MATCH_ANY; + if (p->type == DEV_MATCH_DEVICE && + p->pattern.device_pattern.flags == 0x00f) + p->pattern.device_pattern.flags = DEV_MATCH_ANY; + if (p->type == DEV_MATCH_PERIPH && + p->pattern.periph_pattern.flags == 0x01f) + p->pattern.periph_pattern.flags = PERIPH_MATCH_ANY; + } + cam_periph_unmapmem(ccb, &mapinfo); + } + return ((cbfnp)(dev, cmd, addr, flag, td)); +} diff --git a/sys/cam/cam_compat.h b/sys/cam/cam_compat.h index dd728d86839e..9a1996d230ce 100644 --- a/sys/cam/cam_compat.h +++ b/sys/cam/cam_compat.h @@ -220,5 +220,12 @@ struct dev_match_result_0x18 { #define CAMIOCOMMAND_0x18 _IOC(IOC_INOUT, CAM_VERSION_0x18, 2, CAM_0X18_LEN) #define CAMGETPASSTHRU_0x18 _IOC(IOC_INOUT, CAM_VERSION_0x18, 3, CAM_0X18_LEN) +/* Version 0x19 compatibility */ +#define CAM_VERSION_0x19 0x19 +#define CAMIOCOMMAND_0x19 _IOWR(CAM_VERSION_0x19, 2, union ccb) +#define CAMGETPASSTHRU_0x19 _IOWR(CAM_VERSION_0x19, 3, union ccb) +#define CAMIOQUEUE_0x19 _IO(CAM_VERSION_0x19, 4) +#define CAMIOGET_0x19 _IO(CAM_VERSION_0x19, 5) + #endif #endif diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c index e228f0967f0e..d9ecabefe044 100644 --- a/sys/cam/cam_xpt.c +++ b/sys/cam/cam_xpt.c @@ -1386,6 +1386,8 @@ xptbusmatch(struct dev_match_pattern *patterns, u_int num_patterns, for (i = 0; i < num_patterns; i++) { struct bus_match_pattern *cur_pattern; + struct device_match_pattern *dp = &patterns[i].pattern.device_pattern; + struct periph_match_pattern *pp = &patterns[i].pattern.periph_pattern; /* * If the pattern in question isn't for a bus node, we @@ -1394,6 +1396,14 @@ xptbusmatch(struct dev_match_pattern *patterns, u_int num_patterns, * tree, since the user wants to match against lower-level * EDT elements. */ + if (patterns[i].type == DEV_MATCH_DEVICE && + (dp->flags & DEV_MATCH_PATH) != 0 && + dp->path_id != bus->path_id) + continue; + if (patterns[i].type == DEV_MATCH_PERIPH && + (pp->flags & PERIPH_MATCH_PATH) != 0 && + pp->path_id != bus->path_id) + continue; if (patterns[i].type != DEV_MATCH_BUS) { if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE) retval |= DM_RET_DESCEND; @@ -1402,28 +1412,6 @@ xptbusmatch(struct dev_match_pattern *patterns, u_int num_patterns, cur_pattern = &patterns[i].pattern.bus_pattern; - /* - * If they want to match any bus node, we give them any - * device node. - */ - if (cur_pattern->flags == BUS_MATCH_ANY) { - /* set the copy flag */ - retval |= DM_RET_COPY; - - /* - * If we've already decided on an action, go ahead - * and return. - */ - if ((retval & DM_RET_ACTION_MASK) != DM_RET_NONE) - return(retval); - } - - /* - * Not sure why someone would do this... - */ - if (cur_pattern->flags == BUS_MATCH_NONE) - continue; - if (((cur_pattern->flags & BUS_MATCH_PATH) != 0) && (cur_pattern->path_id != bus->path_id)) continue; @@ -1499,11 +1487,20 @@ xptdevicematch(struct dev_match_pattern *patterns, u_int num_patterns, for (i = 0; i < num_patterns; i++) { struct device_match_pattern *cur_pattern; struct scsi_vpd_device_id *device_id_page; + struct periph_match_pattern *pp = &patterns[i].pattern.periph_pattern; /* * If the pattern in question isn't for a device node, we * aren't interested. */ + if (patterns[i].type == DEV_MATCH_PERIPH && + (pp->flags & PERIPH_MATCH_TARGET) != 0 && + pp->target_id != device->target->target_id) + continue; + if (patterns[i].type == DEV_MATCH_PERIPH && + (pp->flags & PERIPH_MATCH_LUN) != 0 && + pp->target_lun != device->lun_id) + continue; if (patterns[i].type != DEV_MATCH_DEVICE) { if ((patterns[i].type == DEV_MATCH_PERIPH) && ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)) @@ -1518,19 +1515,6 @@ xptdevicematch(struct dev_match_pattern *patterns, u_int num_patterns, == (DEV_MATCH_INQUIRY|DEV_MATCH_DEVID)) return(DM_RET_ERROR); - /* - * If they want to match any device node, we give them any - * device node. - */ - if (cur_pattern->flags == DEV_MATCH_ANY) - goto copy_dev_node; - - /* - * Not sure why someone would do this... - */ - if (cur_pattern->flags == DEV_MATCH_NONE) - continue; - if (((cur_pattern->flags & DEV_MATCH_PATH) != 0) && (cur_pattern->path_id != device->target->bus->path_id)) continue; @@ -1560,7 +1544,6 @@ xptdevicematch(struct dev_match_pattern *patterns, u_int num_patterns, cur_pattern->data.devid_pat.id_len) != 0)) continue; -copy_dev_node: /* * If we get to this point, the user definitely wants * information on this device. So tell the caller to copy @@ -1635,27 +1618,6 @@ xptperiphmatch(struct dev_match_pattern *patterns, u_int num_patterns, cur_pattern = &patterns[i].pattern.periph_pattern; - /* - * If they want to match on anything, then we will do so. - */ - if (cur_pattern->flags == PERIPH_MATCH_ANY) { - /* set the copy flag */ - retval |= DM_RET_COPY; - - /* - * We've already set the return action to stop, - * since there are no nodes below peripherals in - * the tree. - */ - return(retval); - } - - /* - * Not sure why someone would do this... - */ - if (cur_pattern->flags == PERIPH_MATCH_NONE) - continue; - if (((cur_pattern->flags & PERIPH_MATCH_PATH) != 0) && (cur_pattern->path_id != periph->path->bus->path_id)) continue;