Index: sbin/geom/class/part/gpart.8 =================================================================== --- sbin/geom/class/part/gpart.8 +++ sbin/geom/class/part/gpart.8 @@ -1146,6 +1146,36 @@ GEOM class. The default value is shown next to each variable. .Bl -tag -width indent +.It Va kern.phys2unit: +This variable add map which and how the disk should be renamed. +If this is recognized by CAM the mapping looks like: +.Li bNRtNRlNR=disk +where b is for a bus, t is for target and l is for lun. +All those values can be get from +.Xr camcontrol 8 +tool. +For example the +.Pa b0t1l0=12 +will means that disk on bus 0, target 0 and lun 0 should be renamed to disk12. +If the this is connected to the mfi the +.Pa ENR:SNR=disk +notation is used. +.Ar E +stands for enclosure and +.Ar S +stands for slot. +All those values can be get from +.Xr mfiutil 8 +tool. +Space should be used to separate multiple disks. +For +.Pa b0t1l0=0 b0t2l0=1 +two disk will be renamed. +Disk on bus 0, target 1 and lun 0 will be renamed to disk0, and disk on bus 0, +target 2 and lun 0 will be renamed to disk 1. +When this sysctl is in use the ad, ada or mfisyspd devices will not be created +if device is on the list. +.Pp .It Va kern.geom.part.auto_resize: No 1 This variable controls automatic resize behavior of .Nm Index: sys/cam/ata/ata_da.c =================================================================== --- sys/cam/ata/ata_da.c +++ sys/cam/ata/ata_da.c @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -1684,7 +1685,7 @@ char *announce_buf; caddr_t match; u_int maxio; - int quirks; + int quirks, unit; cgd = (struct ccb_getdev *)arg; if (cgd == NULL) { @@ -1778,7 +1779,6 @@ softc->disk->d_getattr = adagetattr; softc->disk->d_dump = adadump; softc->disk->d_gone = adadiskgonecb; - softc->disk->d_name = "ada"; softc->disk->d_drv1 = periph; maxio = cpi.maxio; /* Honor max I/O size of SIM */ if (maxio == 0) @@ -1790,7 +1790,18 @@ else /* 28bit ATA command limit */ maxio = min(maxio, 256 * softc->params.secsize); softc->disk->d_maxsize = maxio; - softc->disk->d_unit = periph->unit_number; + + unit = disk_unit_cam(periph->path->bus->path_id, + periph->path->target->target_id, periph->path->device->lun_id, + (off_t)softc->params.secsize * (off_t)softc->params.sectors); + if (unit >= 0) { + softc->disk->d_name = "disk"; + softc->disk->d_unit = unit; + } else { + softc->disk->d_name = "ada"; + softc->disk->d_unit = periph->unit_number; + } + softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE; if (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; @@ -1864,6 +1875,11 @@ sbuf_finish(&sb); sbuf_putbuf(&sb); + if (unit >= 0) { + printf("%s%d: Known in GEOM as disk%d\n", periph->periph_name, + periph->unit_number, unit); + } + /* * Create our sysctl variables, now that we know * we have successfully attached. Index: sys/cam/scsi/scsi_da.c =================================================================== --- sys/cam/scsi/scsi_da.c +++ sys/cam/scsi/scsi_da.c @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -2410,6 +2411,7 @@ struct ccb_getdev *cgd; char tmpstr[80]; caddr_t match; + int unit; cgd = (struct ccb_getdev *)arg; if (cgd == NULL) { @@ -2555,7 +2557,17 @@ softc->disk->d_dump = dadump; softc->disk->d_getattr = dagetattr; softc->disk->d_gone = dadiskgonecb; - softc->disk->d_name = "da"; + + unit = disk_unit_cam(periph->path->bus->path_id, + periph->path->target->target_id, periph->path->device->lun_id, 0); + if (unit >= 0) { + softc->disk->d_name = "disk"; + softc->disk->d_unit = unit; + } else { + softc->disk->d_name = "da"; + softc->disk->d_unit = periph->unit_number; + } + softc->disk->d_drv1 = periph; if (cpi.maxio == 0) softc->maxio = DFLTPHYS; /* traditional default */ @@ -2564,7 +2576,6 @@ else softc->maxio = cpi.maxio; softc->disk->d_maxsize = softc->maxio; - softc->disk->d_unit = periph->unit_number; softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE; if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; @@ -2629,6 +2640,11 @@ xpt_schedule(periph, CAM_PRIORITY_DEV); + if (unit >= 0) { + printf("%s%d: Known in GEOM as disk%d\n", periph->periph_name, + periph->unit_number, unit); + } + return(CAM_REQ_CMP); } Index: sys/conf/files =================================================================== --- sys/conf/files +++ sys/conf/files @@ -3451,6 +3451,7 @@ geom/geom_map.c optional geom_map geom/geom_mbr.c optional geom_mbr geom/geom_mbr_enc.c optional geom_mbr +geom/geom_phys2disk.c standard geom/geom_redboot.c optional geom_redboot geom/geom_slice.c standard geom/geom_subr.c standard Index: sys/dev/mfi/mfi_syspd.c =================================================================== --- sys/dev/mfi/mfi_syspd.c +++ sys/dev/mfi/mfi_syspd.c @@ -100,6 +100,7 @@ struct mfi_system_pending *syspd_pend; uint64_t sectors; uint32_t secsize; + int unit; sc = device_get_softc(dev); pd_info = device_get_ivars(dev); @@ -128,12 +129,20 @@ sc->pd_disk->d_drv1 = sc; sc->pd_disk->d_maxsize = min(sc->pd_controller->mfi_max_io * secsize, (sc->pd_controller->mfi_max_sge - 1) * PAGE_SIZE); - sc->pd_disk->d_name = "mfisyspd"; + + unit = disk_unit_mfi(pd_info->encl_index, pd_info->slot_number); + if (unit >= 0) { + sc->pd_disk->d_name = "disk"; + sc->pd_disk->d_unit = unit; + } else { + sc->pd_disk->d_name = "mfisyspd"; + sc->pd_disk->d_unit = sc->pd_unit; + } + sc->pd_disk->d_open = mfi_syspd_open; sc->pd_disk->d_close = mfi_syspd_close; sc->pd_disk->d_strategy = mfi_syspd_strategy; sc->pd_disk->d_dump = mfi_syspd_dump; - sc->pd_disk->d_unit = sc->pd_unit; sc->pd_disk->d_sectorsize = secsize; sc->pd_disk->d_mediasize = sectors * secsize; if (sc->pd_disk->d_mediasize >= (1 * 1024 * 1024)) { Index: sys/geom/geom_disk.h =================================================================== --- sys/geom/geom_disk.h +++ sys/geom/geom_disk.h @@ -44,6 +44,8 @@ #include #include +#include + #define G_DISK_CLASS_NAME "DISK" struct disk; Index: sys/geom/geom_phys2disk.h =================================================================== --- /dev/null +++ sys/geom/geom_phys2disk.h @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2017 Wheel Systems + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek and Mariusz Zaborski + * under sponsorship from Wheel Systems. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _PHYS2DISK_H_ +#define _PHYS2DISK_H_ + +int disk_unit_cam(u_int bus, u_int target, u_int lun, off_t mediasize); +int disk_unit_mfi(uint8_t enclindex, uint8_t slot); + +#endif Index: sys/geom/geom_phys2disk.c =================================================================== --- /dev/null +++ sys/geom/geom_phys2disk.c @@ -0,0 +1,89 @@ +/*- + * Copyright (c) 2017 Wheel Systems + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek and Mariusz Zaborski + * under sponsorship from Wheel Systems. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include + +static char disk_phys2unit[1024]; +SYSCTL_STRING(_kern, OID_AUTO, phys2unit, CTLFLAG_RDTUN, + disk_phys2unit, 0, "Disk connection to unit mapping"); + +static int +disk_unit(const char *phys) +{ + int unit; + char *ptr; + + ptr = strstr(disk_phys2unit, phys); + if (ptr == NULL) + return (-1); + ptr += strlen(phys); + if (ptr >= disk_phys2unit + sizeof(disk_phys2unit) - 1) { + printf("%s: Invalid kern.phys2unit value.\n", __func__); + return (-1); + } + if (*ptr < '0' || *ptr > '9') { + printf("%s: Invalid kern.phys2unit value.\n", __func__); + return (-1); + } + unit = 0; + for (; ptr <= disk_phys2unit + sizeof(disk_phys2unit) - 1; ptr++) { + if (*ptr < '0' || *ptr > '9') + break; + unit *= 10; + unit += *ptr - '0'; + } + return (unit); +} + +int +disk_unit_cam(u_int bus, u_int target, u_int lun, off_t mediasize) +{ + char phys[16]; + + (void)snprintf(phys, sizeof(phys), "b%ut%ul%u=", bus, target, lun); + return (disk_unit(phys)); +} + +int +disk_unit_mfi(uint8_t enclindex, uint8_t slot) +{ + char phys[32]; + + (void)snprintf(phys, sizeof(phys), "E%u:S%u=", enclindex, slot); + return (disk_unit(phys)); +}