From 519a30551e314539bf947c982c6407ccfa2a1fc7 Mon Sep 17 00:00:00 2001 From: mav Date: Tue, 26 Apr 2011 17:01:49 +0000 Subject: - Add shim to simplify migration to the CAM-based ATA. For each new adaX device in /dev/ create symbolic link with adY name, trying to mimic old ATA numbering. Imitation is not complete, but should be enough in most cases to mount file systems without touching /etc/fstab. - To know what behavior to mimic, restore ATA_STATIC_ID option in cases where it was present before. - Add some more details to UPDATING. --- UPDATING | 13 +++++++++++-- sys/amd64/conf/GENERIC | 1 + sys/arm/conf/CRB | 1 + sys/arm/conf/EP80219 | 1 + sys/arm/conf/IQ31244 | 1 + sys/cam/ata/ata_da.c | 35 ++++++++++++++++++++++++++++++++++- sys/cam/cam_xpt.c | 36 ++++++++++++++++++++++++++++++++++++ sys/cam/cam_xpt.h | 1 + sys/conf/NOTES | 2 +- sys/geom/geom_dev.c | 28 ++++++++++++++++++++++++++-- sys/i386/conf/GENERIC | 1 + sys/i386/conf/XBOX | 1 + sys/mips/conf/OCTEON1 | 1 + sys/mips/conf/std.SWARM | 1 + sys/modules/cam/Makefile | 1 + sys/pc98/conf/GENERIC | 1 + 16 files changed, 119 insertions(+), 6 deletions(-) diff --git a/UPDATING b/UPDATING index 217d141..d7901f8 100644 --- a/UPDATING +++ b/UPDATING @@ -30,7 +30,17 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 9.x IS SLOW: them respectively (adX -> adaY, acdX -> cdY, afdX -> daY, astX -> saY, where 'Y's are the sequential numbers starting from zero for each type in order of detection, unless configured otherwise with tunables, - see cam(4)). + see cam(4)). There will be symbolic links created in /dev/ to map + old adX devices to the respective adaY. They should provide basic + compatibility for file systems mounting in most cases, but they do + not support old user-level APIs and do not have respective providers + in GEOM. Consider using updated management tools with new device names. + + It is possible to load devices ahci, ata, siis and mvs as modules, + but option ATA_CAM should remain in kernel configuration to make ata + module work as CAM driver supporting legacy ATA controllers. Device ata + still can be used in modular fashion (atacore + ...). Modules atadisk + and atapi* are not used and won't affect operation in ATA_CAM mode. ataraid(4) functionality is now supported by the RAID GEOM class. To use it you can load geom_raid kernel module and use graid(8) tool @@ -49,7 +59,6 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 9.x IS SLOW: device atapicd # ATAPI CDROM drives device atapifd # ATAPI floppy drives device atapist # ATAPI tape drives - options ATA_STATIC_ID # Static device numbering 20110423: The default NFS server has been changed to the new server, which diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC index 6769c79..f9396e8 100644 --- a/sys/amd64/conf/GENERIC +++ b/sys/amd64/conf/GENERIC @@ -93,6 +93,7 @@ device fdc device ahci # AHCI-compatible SATA controllers device ata # Legacy ATA/SATA controllers options ATA_CAM # Handle legacy controllers with CAM +options ATA_STATIC_ID # Static device numbering device mvs # Marvell 88SX50XX/88SX60XX/88SX70XX/SoC SATA device siis # SiliconImage SiI3124/SiI3132/SiI3531 SATA diff --git a/sys/arm/conf/CRB b/sys/arm/conf/CRB index eebdcbd..45f19e0 100644 --- a/sys/arm/conf/CRB +++ b/sys/arm/conf/CRB @@ -74,6 +74,7 @@ device pci device ata options ATA_CAM +options ATA_STATIC_ID # Static device numbering device scbus # SCSI bus (required for ATA/SCSI) device cd # CD diff --git a/sys/arm/conf/EP80219 b/sys/arm/conf/EP80219 index c47f79e..23717df 100644 --- a/sys/arm/conf/EP80219 +++ b/sys/arm/conf/EP80219 @@ -74,6 +74,7 @@ device pci device ata options ATA_CAM +options ATA_STATIC_ID # Static device numbering device scbus # SCSI bus (required for ATA/SCSI) device cd # CD diff --git a/sys/arm/conf/IQ31244 b/sys/arm/conf/IQ31244 index dd90e4b..5679811 100644 --- a/sys/arm/conf/IQ31244 +++ b/sys/arm/conf/IQ31244 @@ -73,6 +73,7 @@ device pci device ata options ATA_CAM +options ATA_STATIC_ID # Static device numbering device scbus # SCSI bus (required for ATA/SCSI) device cd # CD diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c index 0e8b273..128bb8b 100644 --- a/sys/cam/ata/ata_da.c +++ b/sys/cam/ata/ata_da.c @@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$"); #include "opt_ada.h" +#include "opt_ata.h" #include @@ -183,6 +184,14 @@ static void adashutdown(void *arg, int howto); static void adasuspend(void *arg); static void adaresume(void *arg); +#ifndef ADA_DEFAULT_LEGACY_ALIASES +#ifdef ATA_CAM +#define ADA_DEFAULT_LEGACY_ALIASES 1 +#else +#define ADA_DEFAULT_LEGACY_ALIASES 0 +#endif +#endif + #ifndef ADA_DEFAULT_TIMEOUT #define ADA_DEFAULT_TIMEOUT 30 /* Timeout in seconds */ #endif @@ -215,6 +224,7 @@ static void adaresume(void *arg); #define ata_disk_firmware_geom_adjust(disk) #endif +static int ada_legacy_aliases = ADA_DEFAULT_LEGACY_ALIASES; static int ada_retry_count = ADA_DEFAULT_RETRY; static int ada_default_timeout = ADA_DEFAULT_TIMEOUT; static int ada_send_ordered = ADA_DEFAULT_SEND_ORDERED; @@ -224,6 +234,9 @@ static int ada_write_cache = ADA_DEFAULT_WRITE_CACHE; SYSCTL_NODE(_kern_cam, OID_AUTO, ada, CTLFLAG_RD, 0, "CAM Direct Access Disk driver"); +SYSCTL_INT(_kern_cam_ada, OID_AUTO, legacy_aliases, CTLFLAG_RW, + &ada_legacy_aliases, 0, "Create legacy-like device aliases"); +TUNABLE_INT("kern.cam.ada.legacy_aliases", &ada_legacy_aliases); SYSCTL_INT(_kern_cam_ada, OID_AUTO, retry_count, CTLFLAG_RW, &ada_retry_count, 0, "Normal I/O retry count"); TUNABLE_INT("kern.cam.ada.retry_count", &ada_retry_count); @@ -723,10 +736,11 @@ adaregister(struct cam_periph *periph, void *arg) struct ada_softc *softc; struct ccb_pathinq cpi; struct ccb_getdev *cgd; - char announce_buf[80]; + char announce_buf[80], buf1[32]; struct disk_params *dp; caddr_t match; u_int maxio; + int legacy_id; cgd = (struct ccb_getdev *)arg; if (periph == NULL) { @@ -861,6 +875,22 @@ adaregister(struct cam_periph *periph, void *arg) softc->disk->d_fwheads = softc->params.heads; ata_disk_firmware_geom_adjust(softc->disk); + if (ada_legacy_aliases) { +#ifdef ATA_STATIC_ID + legacy_id = xpt_path_legacy_ata_id(periph->path); +#else + legacy_id = softc->disk->d_unit; +#endif + if (legacy_id >= 0) { + snprintf(announce_buf, sizeof(announce_buf), + "kern.devalias.%s%d", + softc->disk->d_name, softc->disk->d_unit); + snprintf(buf1, sizeof(buf1), + "ad%d", legacy_id); + setenv(announce_buf, buf1); + } + } else + legacy_id = -1; disk_create(softc->disk, DISK_VERSION); mtx_lock(periph->sim->mtx); cam_periph_unhold(periph); @@ -874,6 +904,9 @@ adaregister(struct cam_periph *periph, void *arg) dp->secsize, dp->heads, dp->secs_per_track, dp->cylinders); xpt_announce_periph(periph, announce_buf); + if (legacy_id >= 0) + printf("%s%d: Previously was known as ad%d\n", + periph->periph_name, periph->unit_number, legacy_id); /* * Create our sysctl variables, now that we know diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c index a348800..0c7576d 100644 --- a/sys/cam/cam_xpt.c +++ b/sys/cam/cam_xpt.c @@ -3569,6 +3569,42 @@ xpt_path_periph(struct cam_path *path) return (path->periph); } +int +xpt_path_legacy_ata_id(struct cam_path *path) +{ + struct cam_eb *bus; + int bus_id; + + if ((strcmp(path->bus->sim->sim_name, "ata") != 0) && + strcmp(path->bus->sim->sim_name, "ahcich") != 0 && + strcmp(path->bus->sim->sim_name, "mvsch") != 0 && + strcmp(path->bus->sim->sim_name, "siisch") != 0) + return (-1); + + if (strcmp(path->bus->sim->sim_name, "ata") == 0 && + path->bus->sim->unit_number < 2) { + bus_id = path->bus->sim->unit_number; + } else { + bus_id = 2; + xpt_lock_buses(); + TAILQ_FOREACH(bus, &xsoftc.xpt_busses, links) { + if (bus == path->bus) + break; + if ((strcmp(bus->sim->sim_name, "ata") == 0 && + bus->sim->unit_number >= 2) || + strcmp(bus->sim->sim_name, "ahcich") == 0 || + strcmp(bus->sim->sim_name, "mvsch") == 0 || + strcmp(bus->sim->sim_name, "siisch") == 0) + bus_id++; + } + xpt_unlock_buses(); + } + if (path->target != NULL) + return (bus_id * 2 + path->target->target_id); + else + return (bus_id * 2); +} + /* * Release a CAM control block for the caller. Remit the cost of the structure * to the device referenced by the path. If the this device had no 'credits' diff --git a/sys/cam/cam_xpt.h b/sys/cam/cam_xpt.h index 61a7f3f..9355be4 100644 --- a/sys/cam/cam_xpt.h +++ b/sys/cam/cam_xpt.h @@ -113,6 +113,7 @@ int xpt_path_string(struct cam_path *path, char *str, path_id_t xpt_path_path_id(struct cam_path *path); target_id_t xpt_path_target_id(struct cam_path *path); lun_id_t xpt_path_lun_id(struct cam_path *path); +int xpt_path_legacy_ata_id(struct cam_path *path); struct cam_sim *xpt_path_sim(struct cam_path *path); struct cam_periph *xpt_path_periph(struct cam_path *path); void xpt_async(u_int32_t async_code, struct cam_path *path, diff --git a/sys/conf/NOTES b/sys/conf/NOTES index 610d336..ecaa077 100644 --- a/sys/conf/NOTES +++ b/sys/conf/NOTES @@ -1754,7 +1754,7 @@ hint.ata.1.irq="15" # atapifd, atapist, atapicam) and all user-level APIs. # cam(4) drivers and APIs will be connected instead. -#options ATA_STATIC_ID +options ATA_STATIC_ID #options ATA_REQUEST_TIMEOUT=10 options ATA_CAM diff --git a/sys/geom/geom_dev.c b/sys/geom/geom_dev.c index 6ae4201..909cb91 100644 --- a/sys/geom/geom_dev.c +++ b/sys/geom/geom_dev.c @@ -113,8 +113,9 @@ g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) { struct g_geom *gp; struct g_consumer *cp; - int error; - struct cdev *dev; + int error, len; + struct cdev *dev, *adev; + char buf[64], *val; g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name); g_topology_assert(); @@ -136,12 +137,35 @@ g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) g_destroy_geom(gp); return (NULL); } + + /* Search for device alias name and create it if found. */ + adev = NULL; + for (len = MIN(strlen(gp->name), sizeof(buf) - 15); len > 0; len--) { + snprintf(buf, sizeof(buf), "kern.devalias.%s", gp->name); + buf[14 + len] = 0; + val = getenv(buf); + if (val != NULL) { + snprintf(buf, sizeof(buf), "%s%s", + val, gp->name + len); + freeenv(val); + adev = make_dev_alias(dev, buf); + break; + } + } + if (pp->flags & G_PF_CANDELETE) dev->si_flags |= SI_CANDELETE; dev->si_iosize_max = MAXPHYS; gp->softc = dev; dev->si_drv1 = gp; dev->si_drv2 = cp; + if (adev != NULL) { + if (pp->flags & G_PF_CANDELETE) + adev->si_flags |= SI_CANDELETE; + adev->si_iosize_max = MAXPHYS; + adev->si_drv1 = gp; + adev->si_drv2 = cp; + } return (gp); } diff --git a/sys/i386/conf/GENERIC b/sys/i386/conf/GENERIC index 75281ae..1652211 100644 --- a/sys/i386/conf/GENERIC +++ b/sys/i386/conf/GENERIC @@ -95,6 +95,7 @@ device fdc device ahci # AHCI-compatible SATA controllers device ata # Legacy ATA/SATA controllers options ATA_CAM # Handle legacy controllers with CAM +options ATA_STATIC_ID # Static device numbering device mvs # Marvell 88SX50XX/88SX60XX/88SX70XX/SoC SATA device siis # SiliconImage SiI3124/SiI3132/SiI3531 SATA diff --git a/sys/i386/conf/XBOX b/sys/i386/conf/XBOX index 0b507c5..a3e8a6b 100644 --- a/sys/i386/conf/XBOX +++ b/sys/i386/conf/XBOX @@ -52,6 +52,7 @@ device pci # ATA and ATAPI devices device ata options ATA_CAM +options ATA_STATIC_ID # Static device numbering # ATA/SCSI peripherals device scbus # SCSI bus (required for ATA/SCSI) diff --git a/sys/mips/conf/OCTEON1 b/sys/mips/conf/OCTEON1 index 6d435d4..003b171 100644 --- a/sys/mips/conf/OCTEON1 +++ b/sys/mips/conf/OCTEON1 @@ -99,6 +99,7 @@ device pci device ahci # AHCI-compatible SATA controllers device ata # Legacy ATA/SATA controllers options ATA_CAM # Handle legacy controllers with CAM +options ATA_STATIC_ID # Static device numbering device mvs # Marvell 88SX50XX/88SX60XX/88SX70XX/SoC SATA device siis # SiliconImage SiI3124/SiI3132/SiI3531 SATA diff --git a/sys/mips/conf/std.SWARM b/sys/mips/conf/std.SWARM index a6a6197..37223b7 100644 --- a/sys/mips/conf/std.SWARM +++ b/sys/mips/conf/std.SWARM @@ -58,3 +58,4 @@ device pass device ata options ATA_CAM +options ATA_STATIC_ID # Static device numbering diff --git a/sys/modules/cam/Makefile b/sys/modules/cam/Makefile index 0f99465..f1bfdb9 100644 --- a/sys/modules/cam/Makefile +++ b/sys/modules/cam/Makefile @@ -9,6 +9,7 @@ KMOD= cam # See sys/conf/options for the flags that go into the different opt_*.h files. SRCS= opt_cam.h SRCS+= opt_ada.h +SRCS+= opt_ata.h SRCS+= opt_scsi.h SRCS+= opt_cd.h SRCS+= opt_pt.h diff --git a/sys/pc98/conf/GENERIC b/sys/pc98/conf/GENERIC index afe5173..0eacbcc 100644 --- a/sys/pc98/conf/GENERIC +++ b/sys/pc98/conf/GENERIC @@ -91,6 +91,7 @@ device fdc device ahci # AHCI-compatible SATA controllers device ata # Legacy ATA/SATA controllers options ATA_CAM # Handle legacy controllers with CAM +options ATA_STATIC_ID # Static device numbering device mvs # Marvell 88SX50XX/88SX60XX/88SX70XX/SoC SATA device siis # SiliconImage SiI3124/SiI3132/SiI3531 SATA -- cgit v1.1