Index: conf/files =================================================================== --- conf/files (revision 220981) +++ conf/files (working copy) @@ -2134,6 +2134,7 @@ geom/label/g_label.c optional geom_label geom/label/g_label_ext2fs.c optional geom_label geom/label/g_label_iso9660.c optional geom_label +geom/label/g_label_legacy.c optional geom_label geom/label/g_label_msdosfs.c optional geom_label geom/label/g_label_ntfs.c optional geom_label geom/label/g_label_reiserfs.c optional geom_label Index: cam/cam_xpt.h =================================================================== --- cam/cam_xpt.h (revision 220981) +++ cam/cam_xpt.h (working copy) @@ -113,6 +113,7 @@ 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, Index: cam/ata/ata_da.c =================================================================== --- cam/ata/ata_da.c (revision 220981) +++ cam/ata/ata_da.c (working copy) @@ -125,6 +125,7 @@ ada_state state; ada_flags flags; ada_quirks quirks; + int legacy_id; int ordered_tag_count; int outstanding_cmds; int trim_max_ranges; @@ -163,6 +164,7 @@ }; static disk_strategy_t adastrategy; +static disk_ioctl_t adaioctl; static dumper_t adadump; static periph_init_t adainit; static void adaasync(void *callback_arg, u_int32_t code, @@ -183,6 +185,10 @@ static void adasuspend(void *arg); static void adaresume(void *arg); +#ifndef ADA_DEFAULT_LEGACY_ALIASES +#define ADA_DEFAULT_LEGACY_ALIASES 1 +#endif + #ifndef ADA_DEFAULT_TIMEOUT #define ADA_DEFAULT_TIMEOUT 30 /* Timeout in seconds */ #endif @@ -215,6 +221,7 @@ #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 +231,9 @@ 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); @@ -428,6 +438,34 @@ } static int +adaioctl(struct disk *disk, u_long cmd, void *data, int flag, struct thread *td) +{ + struct cam_periph *periph; + struct ada_softc *softc; + int error = 0; + + periph = (struct cam_periph *)disk->d_drv1; + if (periph == NULL) + return (ENXIO); + softc = (struct ada_softc *)periph->softc; + + cam_periph_lock(periph); + switch (cmd) { + case DIOCGLEGACYNAME: + if (softc->legacy_id >= 0) { + snprintf(data, MAXPATHLEN, "ad%d", softc->legacy_id); + } else + error = ENOTTY; + break; + default: + error = cam_periph_ioctl(periph, cmd, data, adaerror); + break; + } + cam_periph_unlock(periph); + return (error); +} + +static int adadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) { struct cam_periph *periph; @@ -816,6 +854,7 @@ softc->disk->d_open = adaopen; softc->disk->d_close = adaclose; softc->disk->d_strategy = adastrategy; + softc->disk->d_ioctl = adaioctl; softc->disk->d_dump = adadump; softc->disk->d_name = "ada"; softc->disk->d_drv1 = periph; @@ -861,6 +900,10 @@ softc->disk->d_fwheads = softc->params.heads; ata_disk_firmware_geom_adjust(softc->disk); + if (ada_legacy_aliases) { + softc->legacy_id = xpt_path_legacy_ata_id(periph->path); + } else + softc->legacy_id = -1; disk_create(softc->disk, DISK_VERSION); mtx_lock(periph->sim->mtx); cam_periph_unhold(periph); @@ -874,6 +917,10 @@ dp->secsize, dp->heads, dp->secs_per_track, dp->cylinders); xpt_announce_periph(periph, announce_buf); + if (softc->legacy_id >= 0) + printf("%s%d: Previously was known as ad%d\n", + periph->periph_name, periph->unit_number, + softc->legacy_id); /* * Create our sysctl variables, now that we know Index: cam/cam_xpt.c =================================================================== --- cam/cam_xpt.c (revision 220981) +++ cam/cam_xpt.c (working copy) @@ -3569,6 +3569,42 @@ 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' Index: modules/geom/geom_label/Makefile =================================================================== --- modules/geom/geom_label/Makefile (revision 220981) +++ modules/geom/geom_label/Makefile (working copy) @@ -7,6 +7,7 @@ SRCS+= g_label_ext2fs.c SRCS+= g_label_gpt.c SRCS+= g_label_iso9660.c +SRCS+= g_label_legacy.c SRCS+= g_label_msdosfs.c SRCS+= g_label_ntfs.c SRCS+= g_label_reiserfs.c Index: geom/label/g_label.c =================================================================== --- geom/label/g_label.c (revision 220981) +++ geom/label/g_label.c (working copy) @@ -78,6 +78,7 @@ * 6. Add your file system to manual page sbin/geom/class/label/glabel.8. */ const struct g_label_desc *g_labels[] = { + &g_label_legacy, &g_label_ufs_id, &g_label_ufs_volume, &g_label_iso9660, @@ -159,7 +160,10 @@ } gp = NULL; cp = NULL; - snprintf(name, sizeof(name), "%s/%s", dir, label); + if (dir[0] != 0) + snprintf(name, sizeof(name), "%s/%s", dir, label); + else + snprintf(name, sizeof(name), "%s", label); LIST_FOREACH(gp, &mp->geom, geom) { pp2 = LIST_FIRST(&gp->provider); if (pp2 == NULL) Index: geom/label/g_label_legacy.c =================================================================== --- geom/label/g_label_legacy.c (revision 0) +++ geom/label/g_label_legacy.c (revision 0) @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2011 Alexander Motin + * All rights reserved. + * + * 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 + +#include +#include + +#define G_LABEL_LEGACY_DIR "" + +static void +g_label_legacy_taste(struct g_consumer *cp, char *label, size_t size) +{ + struct g_provider *pp; + char buf[MAXPATHLEN]; + int res = 0; + + g_topology_assert_not(); + pp = cp->provider; + label[0] = '\0'; + if (pp->geom->ioctl != NULL && + (res = pp->geom->ioctl(pp, DIOCGLEGACYNAME, buf, + FREAD, curthread)) == 0) + snprintf(label, size, "%s", buf); +} + +struct g_label_desc g_label_legacy = { + .ld_taste = g_label_legacy_taste, + .ld_dir = G_LABEL_LEGACY_DIR, + .ld_enabled = 1 +}; + +G_LABEL_INIT(legacy, g_label_legacy, + "Create device nodes for legacy device names"); Property changes on: geom/label/g_label_legacy.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + FreeBSD=%H Added: svn:eol-style + native Index: geom/label/g_label.h =================================================================== --- geom/label/g_label.h (revision 220981) +++ geom/label/g_label.h (working copy) @@ -81,6 +81,7 @@ extern struct g_label_desc g_label_ufs_id; extern struct g_label_desc g_label_ufs_volume; extern struct g_label_desc g_label_iso9660; +extern struct g_label_desc g_label_legacy; extern struct g_label_desc g_label_msdosfs; extern struct g_label_desc g_label_ext2fs; extern struct g_label_desc g_label_reiserfs; Index: sys/disk.h =================================================================== --- sys/disk.h (revision 220981) +++ sys/disk.h (working copy) @@ -116,4 +116,9 @@ * This should be a multiple of the sector size. */ +#define DIOCGLEGACYNAME _IOR('d', 141, char[MAXPATHLEN]) + /* + * Get the legacy name under which this device wasn known before. + */ + #endif /* _SYS_DISK_H_ */