[BACK]Return to dk.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / dev / dkwedge

Annotation of src/sys/dev/dkwedge/dk.c, Revision 1.72.2.3

1.72.2.3! martin      1: /*     $NetBSD: dk.c,v 1.72.2.2 2014/11/11 10:36:41 martin Exp $       */
1.1       thorpej     2:
                      3: /*-
1.27      ad          4:  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
1.1       thorpej     5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by Jason R. Thorpe.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     20:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     21:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     22:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     23:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     24:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     25:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     26:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     27:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     28:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     29:  * POSSIBILITY OF SUCH DAMAGE.
                     30:  */
                     31:
                     32: #include <sys/cdefs.h>
1.72.2.3! martin     33: __KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.72.2.2 2014/11/11 10:36:41 martin Exp $");
1.1       thorpej    34:
1.50      pooka      35: #ifdef _KERNEL_OPT
1.1       thorpej    36: #include "opt_dkwedge.h"
1.50      pooka      37: #endif
1.1       thorpej    38:
                     39: #include <sys/param.h>
                     40: #include <sys/systm.h>
                     41: #include <sys/proc.h>
                     42: #include <sys/errno.h>
                     43: #include <sys/pool.h>
                     44: #include <sys/ioctl.h>
                     45: #include <sys/disklabel.h>
                     46: #include <sys/disk.h>
                     47: #include <sys/fcntl.h>
1.5       yamt       48: #include <sys/buf.h>
                     49: #include <sys/bufq.h>
1.1       thorpej    50: #include <sys/vnode.h>
1.3       thorpej    51: #include <sys/stat.h>
1.1       thorpej    52: #include <sys/conf.h>
                     53: #include <sys/callout.h>
                     54: #include <sys/kernel.h>
                     55: #include <sys/malloc.h>
1.2       thorpej    56: #include <sys/device.h>
1.15      elad       57: #include <sys/kauth.h>
1.1       thorpej    58:
                     59: #include <miscfs/specfs/specdev.h>
                     60:
                     61: MALLOC_DEFINE(M_DKWEDGE, "dkwedge", "Disk wedge structures");
                     62:
                     63: typedef enum {
                     64:        DKW_STATE_LARVAL        = 0,
                     65:        DKW_STATE_RUNNING       = 1,
                     66:        DKW_STATE_DYING         = 2,
                     67:        DKW_STATE_DEAD          = 666
                     68: } dkwedge_state_t;
                     69:
                     70: struct dkwedge_softc {
1.65      chs        71:        device_t        sc_dev; /* pointer to our pseudo-device */
1.2       thorpej    72:        struct cfdata   sc_cfdata;      /* our cfdata structure */
1.1       thorpej    73:        uint8_t         sc_wname[128];  /* wedge name (Unicode, UTF-8) */
                     74:
                     75:        dkwedge_state_t sc_state;       /* state this wedge is in */
                     76:
                     77:        struct disk     *sc_parent;     /* parent disk */
                     78:        daddr_t         sc_offset;      /* LBA offset of wedge in parent */
                     79:        uint64_t        sc_size;        /* size of wedge in blocks */
                     80:        char            sc_ptype[32];   /* partition type */
                     81:        dev_t           sc_pdev;        /* cached parent's dev_t */
                     82:                                        /* link on parent's wedge list */
                     83:        LIST_ENTRY(dkwedge_softc) sc_plink;
                     84:
                     85:        struct disk     sc_dk;          /* our own disk structure */
1.9       yamt       86:        struct bufq_state *sc_bufq;     /* buffer queue */
1.1       thorpej    87:        struct callout  sc_restart_ch;  /* callout to restart I/O */
                     88:
                     89:        u_int           sc_iopend;      /* I/Os pending */
                     90:        int             sc_flags;       /* flags (splbio) */
                     91: };
                     92:
                     93: #define        DK_F_WAIT_DRAIN         0x0001  /* waiting for I/O to drain */
                     94:
                     95: static void    dkstart(struct dkwedge_softc *);
                     96: static void    dkiodone(struct buf *);
                     97: static void    dkrestart(void *);
1.52      jakllsch   98: static void    dkminphys(struct buf *);
1.1       thorpej    99:
1.46      dyoung    100: static int     dklastclose(struct dkwedge_softc *);
1.72.2.2  martin    101: static int     dkwedge_cleanup_parent(struct dkwedge_softc *, int);
1.47      dyoung    102: static int     dkwedge_detach(device_t, int);
1.72.2.2  martin    103: static void    dkwedge_delall1(struct disk *, bool);
                    104: static int     dkwedge_del1(struct dkwedge_info *, int);
1.46      dyoung    105:
1.1       thorpej   106: static dev_type_open(dkopen);
                    107: static dev_type_close(dkclose);
                    108: static dev_type_read(dkread);
                    109: static dev_type_write(dkwrite);
                    110: static dev_type_ioctl(dkioctl);
                    111: static dev_type_strategy(dkstrategy);
                    112: static dev_type_dump(dkdump);
                    113: static dev_type_size(dksize);
1.72      dholland  114: static dev_type_discard(dkdiscard);
1.1       thorpej   115:
                    116: const struct bdevsw dk_bdevsw = {
1.68      dholland  117:        .d_open = dkopen,
                    118:        .d_close = dkclose,
                    119:        .d_strategy = dkstrategy,
                    120:        .d_ioctl = dkioctl,
                    121:        .d_dump = dkdump,
                    122:        .d_psize = dksize,
1.72      dholland  123:        .d_discard = dkdiscard,
1.68      dholland  124:        .d_flag = D_DISK
1.1       thorpej   125: };
                    126:
                    127: const struct cdevsw dk_cdevsw = {
1.68      dholland  128:        .d_open = dkopen,
                    129:        .d_close = dkclose,
                    130:        .d_read = dkread,
                    131:        .d_write = dkwrite,
                    132:        .d_ioctl = dkioctl,
                    133:        .d_stop = nostop,
                    134:        .d_tty = notty,
                    135:        .d_poll = nopoll,
                    136:        .d_mmap = nommap,
                    137:        .d_kqfilter = nokqfilter,
1.72      dholland  138:        .d_discard = dkdiscard,
1.68      dholland  139:        .d_flag = D_DISK
1.1       thorpej   140: };
                    141:
                    142: static struct dkwedge_softc **dkwedges;
                    143: static u_int ndkwedges;
1.27      ad        144: static krwlock_t dkwedges_lock;
1.1       thorpej   145:
                    146: static LIST_HEAD(, dkwedge_discovery_method) dkwedge_discovery_methods;
1.27      ad        147: static krwlock_t dkwedge_discovery_methods_lock;
1.1       thorpej   148:
                    149: /*
1.2       thorpej   150:  * dkwedge_match:
                    151:  *
                    152:  *     Autoconfiguration match function for pseudo-device glue.
                    153:  */
                    154: static int
1.45      cegger    155: dkwedge_match(device_t parent, cfdata_t match,
1.20      christos  156:     void *aux)
1.2       thorpej   157: {
                    158:
                    159:        /* Pseudo-device; always present. */
                    160:        return (1);
                    161: }
                    162:
                    163: /*
                    164:  * dkwedge_attach:
                    165:  *
                    166:  *     Autoconfiguration attach function for pseudo-device glue.
                    167:  */
                    168: static void
1.45      cegger    169: dkwedge_attach(device_t parent, device_t self,
1.20      christos  170:     void *aux)
1.2       thorpej   171: {
                    172:
1.31      jmcneill  173:        if (!pmf_device_register(self, NULL, NULL))
                    174:                aprint_error_dev(self, "couldn't establish power handler\n");
1.2       thorpej   175: }
                    176:
                    177: CFDRIVER_DECL(dk, DV_DISK, NULL);
1.47      dyoung    178: CFATTACH_DECL3_NEW(dk, 0,
                    179:     dkwedge_match, dkwedge_attach, dkwedge_detach, NULL, NULL, NULL,
                    180:     DVF_DETACH_SHUTDOWN);
1.2       thorpej   181:
                    182: /*
1.1       thorpej   183:  * dkwedge_wait_drain:
                    184:  *
                    185:  *     Wait for I/O on the wedge to drain.
                    186:  *     NOTE: Must be called at splbio()!
                    187:  */
                    188: static void
                    189: dkwedge_wait_drain(struct dkwedge_softc *sc)
                    190: {
                    191:
                    192:        while (sc->sc_iopend != 0) {
                    193:                sc->sc_flags |= DK_F_WAIT_DRAIN;
                    194:                (void) tsleep(&sc->sc_iopend, PRIBIO, "dkdrn", 0);
                    195:        }
                    196: }
                    197:
                    198: /*
                    199:  * dkwedge_compute_pdev:
                    200:  *
                    201:  *     Compute the parent disk's dev_t.
                    202:  */
                    203: static int
1.72.2.2  martin    204: dkwedge_compute_pdev(const char *pname, dev_t *pdevp, enum vtype type)
1.1       thorpej   205: {
                    206:        const char *name, *cp;
1.63      drochner  207:        devmajor_t pmaj;
                    208:        int punit;
1.1       thorpej   209:        char devname[16];
                    210:
                    211:        name = pname;
1.72.2.2  martin    212:        switch (type) {
                    213:        case VBLK:
                    214:                pmaj = devsw_name2blk(name, devname, sizeof(devname));
                    215:                break;
                    216:        case VCHR:
                    217:                pmaj = devsw_name2chr(name, devname, sizeof(devname));
                    218:                break;
                    219:        default:
1.72.2.3! martin    220:                pmaj = NODEVMAJOR;
1.72.2.2  martin    221:                break;
                    222:        }
1.72.2.3! martin    223:        if (pmaj == NODEVMAJOR)
1.1       thorpej   224:                return (ENODEV);
1.6       perry     225:
1.1       thorpej   226:        name += strlen(devname);
                    227:        for (cp = name, punit = 0; *cp >= '0' && *cp <= '9'; cp++)
                    228:                punit = (punit * 10) + (*cp - '0');
                    229:        if (cp == name) {
                    230:                /* Invalid parent disk name. */
                    231:                return (ENODEV);
                    232:        }
                    233:
                    234:        *pdevp = MAKEDISKDEV(pmaj, punit, RAW_PART);
                    235:
                    236:        return (0);
                    237: }
                    238:
                    239: /*
                    240:  * dkwedge_array_expand:
                    241:  *
                    242:  *     Expand the dkwedges array.
                    243:  */
                    244: static void
                    245: dkwedge_array_expand(void)
                    246: {
                    247:        int newcnt = ndkwedges + 16;
                    248:        struct dkwedge_softc **newarray, **oldarray;
                    249:
                    250:        newarray = malloc(newcnt * sizeof(*newarray), M_DKWEDGE,
                    251:            M_WAITOK|M_ZERO);
                    252:        if ((oldarray = dkwedges) != NULL)
                    253:                memcpy(newarray, dkwedges, ndkwedges * sizeof(*newarray));
                    254:        dkwedges = newarray;
                    255:        ndkwedges = newcnt;
                    256:        if (oldarray != NULL)
                    257:                free(oldarray, M_DKWEDGE);
                    258: }
                    259:
1.48      haad      260: static void
1.72.2.3! martin    261: dk_set_geometry(struct dkwedge_softc *sc)
1.48      haad      262: {
1.72.2.3! martin    263:        struct disk *disk = &sc->sc_dk;
1.66      christos  264:        struct disk_geom *dg = &disk->dk_geom;
1.48      haad      265:
1.66      christos  266:        memset(dg, 0, sizeof(*dg));
1.48      haad      267:
1.72.2.3! martin    268:        dg->dg_secperunit = sc->sc_size >> disk->dk_blkshift;
1.66      christos  269:        dg->dg_secsize = DEV_BSIZE << disk->dk_blkshift;
1.72.2.3! martin    270:
        !           271:        /* fake numbers, 1 cylinder is 1 MB with default sector size */
1.66      christos  272:        dg->dg_nsectors = 32;
                    273:        dg->dg_ntracks = 64;
1.72.2.3! martin    274:        dg->dg_ncylinders = dg->dg_secperunit / (dg->dg_nsectors * dg->dg_ntracks);
1.48      haad      275:
1.72.2.3! martin    276:        disk_set_info(sc->sc_dev, disk, NULL);
1.48      haad      277: }
                    278:
1.1       thorpej   279: /*
                    280:  * dkwedge_add:                [exported function]
                    281:  *
                    282:  *     Add a disk wedge based on the provided information.
                    283:  *
                    284:  *     The incoming dkw_devname[] is ignored, instead being
                    285:  *     filled in and returned to the caller.
                    286:  */
                    287: int
                    288: dkwedge_add(struct dkwedge_info *dkw)
                    289: {
                    290:        struct dkwedge_softc *sc, *lsc;
                    291:        struct disk *pdk;
                    292:        u_int unit;
                    293:        int error;
                    294:        dev_t pdev;
                    295:
                    296:        dkw->dkw_parent[sizeof(dkw->dkw_parent) - 1] = '\0';
                    297:        pdk = disk_find(dkw->dkw_parent);
                    298:        if (pdk == NULL)
                    299:                return (ENODEV);
                    300:
1.72.2.2  martin    301:        error = dkwedge_compute_pdev(pdk->dk_name, &pdev, VBLK);
1.1       thorpej   302:        if (error)
                    303:                return (error);
                    304:
                    305:        if (dkw->dkw_offset < 0)
                    306:                return (EINVAL);
                    307:
                    308:        sc = malloc(sizeof(*sc), M_DKWEDGE, M_WAITOK|M_ZERO);
                    309:        sc->sc_state = DKW_STATE_LARVAL;
                    310:        sc->sc_parent = pdk;
                    311:        sc->sc_pdev = pdev;
                    312:        sc->sc_offset = dkw->dkw_offset;
                    313:        sc->sc_size = dkw->dkw_size;
                    314:
                    315:        memcpy(sc->sc_wname, dkw->dkw_wname, sizeof(sc->sc_wname));
                    316:        sc->sc_wname[sizeof(sc->sc_wname) - 1] = '\0';
                    317:
                    318:        memcpy(sc->sc_ptype, dkw->dkw_ptype, sizeof(sc->sc_ptype));
                    319:        sc->sc_ptype[sizeof(sc->sc_ptype) - 1] = '\0';
                    320:
1.9       yamt      321:        bufq_alloc(&sc->sc_bufq, "fcfs", 0);
1.1       thorpej   322:
1.26      ad        323:        callout_init(&sc->sc_restart_ch, 0);
1.1       thorpej   324:        callout_setfunc(&sc->sc_restart_ch, dkrestart, sc);
                    325:
                    326:        /*
                    327:         * Wedge will be added; increment the wedge count for the parent.
                    328:         * Only allow this to happend if RAW_PART is the only thing open.
                    329:         */
1.27      ad        330:        mutex_enter(&pdk->dk_openlock);
1.1       thorpej   331:        if (pdk->dk_openmask & ~(1 << RAW_PART))
                    332:                error = EBUSY;
                    333:        else {
                    334:                /* Check for wedge overlap. */
                    335:                LIST_FOREACH(lsc, &pdk->dk_wedges, sc_plink) {
                    336:                        daddr_t lastblk = sc->sc_offset + sc->sc_size - 1;
                    337:                        daddr_t llastblk = lsc->sc_offset + lsc->sc_size - 1;
                    338:
                    339:                        if (sc->sc_offset >= lsc->sc_offset &&
                    340:                            sc->sc_offset <= llastblk) {
1.63      drochner  341:                                /* Overlaps the tail of the existing wedge. */
1.1       thorpej   342:                                break;
                    343:                        }
                    344:                        if (lastblk >= lsc->sc_offset &&
                    345:                            lastblk <= llastblk) {
                    346:                                /* Overlaps the head of the existing wedge. */
                    347:                                break;
                    348:                        }
                    349:                }
1.72.2.2  martin    350:                if (lsc != NULL) {
                    351:                        if (sc->sc_offset == lsc->sc_offset &&
                    352:                            sc->sc_size == lsc->sc_size &&
                    353:                            strcmp(sc->sc_wname, lsc->sc_wname) == 0)
                    354:                                error = EEXIST;
                    355:                        else
                    356:                                error = EINVAL;
                    357:                } else {
1.1       thorpej   358:                        pdk->dk_nwedges++;
                    359:                        LIST_INSERT_HEAD(&pdk->dk_wedges, sc, sc_plink);
                    360:                }
                    361:        }
1.27      ad        362:        mutex_exit(&pdk->dk_openlock);
1.1       thorpej   363:        if (error) {
1.9       yamt      364:                bufq_free(sc->sc_bufq);
1.1       thorpej   365:                free(sc, M_DKWEDGE);
                    366:                return (error);
                    367:        }
                    368:
1.2       thorpej   369:        /* Fill in our cfdata for the pseudo-device glue. */
                    370:        sc->sc_cfdata.cf_name = dk_cd.cd_name;
                    371:        sc->sc_cfdata.cf_atname = dk_ca.ca_name;
                    372:        /* sc->sc_cfdata.cf_unit set below */
1.8       nathanw   373:        sc->sc_cfdata.cf_fstate = FSTATE_STAR;
1.2       thorpej   374:
1.1       thorpej   375:        /* Insert the larval wedge into the array. */
1.27      ad        376:        rw_enter(&dkwedges_lock, RW_WRITER);
1.1       thorpej   377:        for (error = 0;;) {
                    378:                struct dkwedge_softc **scpp;
                    379:
                    380:                /*
                    381:                 * Check for a duplicate wname while searching for
                    382:                 * a slot.
                    383:                 */
                    384:                for (scpp = NULL, unit = 0; unit < ndkwedges; unit++) {
                    385:                        if (dkwedges[unit] == NULL) {
                    386:                                if (scpp == NULL) {
                    387:                                        scpp = &dkwedges[unit];
1.2       thorpej   388:                                        sc->sc_cfdata.cf_unit = unit;
1.1       thorpej   389:                                }
                    390:                        } else {
                    391:                                /* XXX Unicode. */
                    392:                                if (strcmp(dkwedges[unit]->sc_wname,
                    393:                                           sc->sc_wname) == 0) {
                    394:                                        error = EEXIST;
                    395:                                        break;
                    396:                                }
                    397:                        }
                    398:                }
                    399:                if (error)
                    400:                        break;
                    401:                KASSERT(unit == ndkwedges);
                    402:                if (scpp == NULL)
                    403:                        dkwedge_array_expand();
                    404:                else {
1.2       thorpej   405:                        KASSERT(scpp == &dkwedges[sc->sc_cfdata.cf_unit]);
1.1       thorpej   406:                        *scpp = sc;
                    407:                        break;
                    408:                }
                    409:        }
1.27      ad        410:        rw_exit(&dkwedges_lock);
1.1       thorpej   411:        if (error) {
1.27      ad        412:                mutex_enter(&pdk->dk_openlock);
1.1       thorpej   413:                pdk->dk_nwedges--;
                    414:                LIST_REMOVE(sc, sc_plink);
1.27      ad        415:                mutex_exit(&pdk->dk_openlock);
1.1       thorpej   416:
1.9       yamt      417:                bufq_free(sc->sc_bufq);
1.1       thorpej   418:                free(sc, M_DKWEDGE);
                    419:                return (error);
                    420:        }
                    421:
1.2       thorpej   422:        /*
                    423:         * Now that we know the unit #, attach a pseudo-device for
                    424:         * this wedge instance.  This will provide us with the
1.65      chs       425:         * device_t necessary for glue to other parts of the system.
1.2       thorpej   426:         *
                    427:         * This should never fail, unless we're almost totally out of
                    428:         * memory.
                    429:         */
                    430:        if ((sc->sc_dev = config_attach_pseudo(&sc->sc_cfdata)) == NULL) {
                    431:                aprint_error("%s%u: unable to attach pseudo-device\n",
                    432:                    sc->sc_cfdata.cf_name, sc->sc_cfdata.cf_unit);
                    433:
1.27      ad        434:                rw_enter(&dkwedges_lock, RW_WRITER);
1.2       thorpej   435:                dkwedges[sc->sc_cfdata.cf_unit] = NULL;
1.27      ad        436:                rw_exit(&dkwedges_lock);
1.2       thorpej   437:
1.27      ad        438:                mutex_enter(&pdk->dk_openlock);
1.2       thorpej   439:                pdk->dk_nwedges--;
                    440:                LIST_REMOVE(sc, sc_plink);
1.27      ad        441:                mutex_exit(&pdk->dk_openlock);
1.2       thorpej   442:
1.9       yamt      443:                bufq_free(sc->sc_bufq);
1.2       thorpej   444:                free(sc, M_DKWEDGE);
                    445:                return (ENOMEM);
                    446:        }
1.1       thorpej   447:
                    448:        /* Return the devname to the caller. */
1.36      cegger    449:        strlcpy(dkw->dkw_devname, device_xname(sc->sc_dev),
                    450:                sizeof(dkw->dkw_devname));
1.1       thorpej   451:
                    452:        /*
                    453:         * XXX Really ought to make the disk_attach() and the changing
                    454:         * of state to RUNNING atomic.
                    455:         */
                    456:
1.36      cegger    457:        disk_init(&sc->sc_dk, device_xname(sc->sc_dev), NULL);
1.58      mlelstv   458:        disk_blocksize(&sc->sc_dk, DEV_BSIZE << pdk->dk_blkshift);
1.72.2.3! martin    459:        dk_set_geometry(sc);
1.1       thorpej   460:        disk_attach(&sc->sc_dk);
                    461:
                    462:        /* Disk wedge is ready for use! */
                    463:        sc->sc_state = DKW_STATE_RUNNING;
                    464:
                    465:        /* Announce our arrival. */
1.36      cegger    466:        aprint_normal("%s at %s: %s\n", device_xname(sc->sc_dev), pdk->dk_name,
1.1       thorpej   467:            sc->sc_wname);      /* XXX Unicode */
                    468:        aprint_normal("%s: %"PRIu64" blocks at %"PRId64", type: %s\n",
1.36      cegger    469:            device_xname(sc->sc_dev), sc->sc_size, sc->sc_offset, sc->sc_ptype);
1.1       thorpej   470:
                    471:        return (0);
                    472: }
                    473:
                    474: /*
1.47      dyoung    475:  * dkwedge_find:
1.1       thorpej   476:  *
1.47      dyoung    477:  *     Lookup a disk wedge based on the provided information.
1.1       thorpej   478:  *     NOTE: We look up the wedge based on the wedge devname,
                    479:  *     not wname.
1.47      dyoung    480:  *
                    481:  *     Return NULL if the wedge is not found, otherwise return
                    482:  *     the wedge's softc.  Assign the wedge's unit number to unitp
                    483:  *     if unitp is not NULL.
1.1       thorpej   484:  */
1.47      dyoung    485: static struct dkwedge_softc *
                    486: dkwedge_find(struct dkwedge_info *dkw, u_int *unitp)
1.1       thorpej   487: {
                    488:        struct dkwedge_softc *sc = NULL;
                    489:        u_int unit;
                    490:
                    491:        /* Find our softc. */
                    492:        dkw->dkw_devname[sizeof(dkw->dkw_devname) - 1] = '\0';
1.47      dyoung    493:        rw_enter(&dkwedges_lock, RW_READER);
1.1       thorpej   494:        for (unit = 0; unit < ndkwedges; unit++) {
                    495:                if ((sc = dkwedges[unit]) != NULL &&
1.36      cegger    496:                    strcmp(device_xname(sc->sc_dev), dkw->dkw_devname) == 0 &&
1.1       thorpej   497:                    strcmp(sc->sc_parent->dk_name, dkw->dkw_parent) == 0) {
                    498:                        break;
                    499:                }
                    500:        }
1.27      ad        501:        rw_exit(&dkwedges_lock);
1.1       thorpej   502:        if (unit == ndkwedges)
1.47      dyoung    503:                return NULL;
                    504:
                    505:        if (unitp != NULL)
                    506:                *unitp = unit;
                    507:
                    508:        return sc;
                    509: }
                    510:
                    511: /*
                    512:  * dkwedge_del:                [exported function]
                    513:  *
                    514:  *     Delete a disk wedge based on the provided information.
                    515:  *     NOTE: We look up the wedge based on the wedge devname,
                    516:  *     not wname.
                    517:  */
                    518: int
                    519: dkwedge_del(struct dkwedge_info *dkw)
                    520: {
1.72.2.2  martin    521:        return dkwedge_del1(dkw, 0);
                    522: }
                    523:
                    524: int
                    525: dkwedge_del1(struct dkwedge_info *dkw, int flags)
                    526: {
1.47      dyoung    527:        struct dkwedge_softc *sc = NULL;
                    528:
                    529:        /* Find our softc. */
                    530:        if ((sc = dkwedge_find(dkw, NULL)) == NULL)
1.1       thorpej   531:                return (ESRCH);
                    532:
1.72.2.2  martin    533:        return config_detach(sc->sc_dev, flags);
1.47      dyoung    534: }
                    535:
                    536: static int
1.72.2.2  martin    537: dkwedge_cleanup_parent(struct dkwedge_softc *sc, int flags)
1.47      dyoung    538: {
                    539:        struct disk *dk = &sc->sc_dk;
                    540:        int rc;
                    541:
                    542:        rc = 0;
                    543:        mutex_enter(&dk->dk_openlock);
                    544:        if (dk->dk_openmask == 0)
                    545:                ;       /* nothing to do */
                    546:        else if ((flags & DETACH_FORCE) == 0)
                    547:                rc = EBUSY;
1.57      bouyer    548:        else {
                    549:                mutex_enter(&sc->sc_parent->dk_rawlock);
                    550:                rc = dklastclose(sc); /* releases dk_rawlock */
                    551:        }
1.47      dyoung    552:        mutex_exit(&dk->dk_openlock);
                    553:
                    554:        return rc;
                    555: }
                    556:
                    557: /*
                    558:  * dkwedge_detach:
                    559:  *
                    560:  *     Autoconfiguration detach function for pseudo-device glue.
                    561:  */
                    562: static int
                    563: dkwedge_detach(device_t self, int flags)
                    564: {
                    565:        struct dkwedge_softc *sc = NULL;
                    566:        u_int unit;
                    567:        int bmaj, cmaj, rc, s;
                    568:
                    569:        rw_enter(&dkwedges_lock, RW_WRITER);
                    570:        for (unit = 0; unit < ndkwedges; unit++) {
                    571:                if ((sc = dkwedges[unit]) != NULL && sc->sc_dev == self)
                    572:                        break;
                    573:        }
                    574:        if (unit == ndkwedges)
                    575:                rc = ENXIO;
1.72.2.2  martin    576:        else if ((rc = dkwedge_cleanup_parent(sc, flags)) == 0) {
1.47      dyoung    577:                /* Mark the wedge as dying. */
                    578:                sc->sc_state = DKW_STATE_DYING;
                    579:        }
                    580:        rw_exit(&dkwedges_lock);
                    581:
                    582:        if (rc != 0)
                    583:                return rc;
                    584:
                    585:        pmf_device_deregister(self);
1.1       thorpej   586:
                    587:        /* Locate the wedge major numbers. */
                    588:        bmaj = bdevsw_lookup_major(&dk_bdevsw);
                    589:        cmaj = cdevsw_lookup_major(&dk_cdevsw);
                    590:
                    591:        /* Kill any pending restart. */
                    592:        callout_stop(&sc->sc_restart_ch);
                    593:
                    594:        /*
                    595:         * dkstart() will kill any queued buffers now that the
                    596:         * state of the wedge is not RUNNING.  Once we've done
                    597:         * that, wait for any other pending I/O to complete.
                    598:         */
                    599:        s = splbio();
                    600:        dkstart(sc);
                    601:        dkwedge_wait_drain(sc);
                    602:        splx(s);
                    603:
                    604:        /* Nuke the vnodes for any open instances. */
1.14      thorpej   605:        vdevgone(bmaj, unit, unit, VBLK);
                    606:        vdevgone(cmaj, unit, unit, VCHR);
1.1       thorpej   607:
                    608:        /* Clean up the parent. */
1.72.2.2  martin    609:        dkwedge_cleanup_parent(sc, flags | DETACH_FORCE);
1.1       thorpej   610:
                    611:        /* Announce our departure. */
1.36      cegger    612:        aprint_normal("%s at %s (%s) deleted\n", device_xname(sc->sc_dev),
1.1       thorpej   613:            sc->sc_parent->dk_name,
                    614:            sc->sc_wname);      /* XXX Unicode */
                    615:
1.27      ad        616:        mutex_enter(&sc->sc_parent->dk_openlock);
1.1       thorpej   617:        sc->sc_parent->dk_nwedges--;
                    618:        LIST_REMOVE(sc, sc_plink);
1.27      ad        619:        mutex_exit(&sc->sc_parent->dk_openlock);
1.1       thorpej   620:
                    621:        /* Delete our buffer queue. */
1.9       yamt      622:        bufq_free(sc->sc_bufq);
1.1       thorpej   623:
                    624:        /* Detach from the disk list. */
                    625:        disk_detach(&sc->sc_dk);
1.39      plunky    626:        disk_destroy(&sc->sc_dk);
1.1       thorpej   627:
                    628:        /* Poof. */
1.27      ad        629:        rw_enter(&dkwedges_lock, RW_WRITER);
1.1       thorpej   630:        dkwedges[unit] = NULL;
                    631:        sc->sc_state = DKW_STATE_DEAD;
1.27      ad        632:        rw_exit(&dkwedges_lock);
1.1       thorpej   633:
                    634:        free(sc, M_DKWEDGE);
                    635:
1.47      dyoung    636:        return 0;
1.1       thorpej   637: }
                    638:
                    639: /*
                    640:  * dkwedge_delall:     [exported function]
                    641:  *
                    642:  *     Delete all of the wedges on the specified disk.  Used when
                    643:  *     a disk is being detached.
                    644:  */
                    645: void
                    646: dkwedge_delall(struct disk *pdk)
                    647: {
1.72.2.2  martin    648:        dkwedge_delall1(pdk, false);
                    649: }
                    650:
                    651: static void
                    652: dkwedge_delall1(struct disk *pdk, bool idleonly)
                    653: {
1.1       thorpej   654:        struct dkwedge_info dkw;
                    655:        struct dkwedge_softc *sc;
1.72.2.2  martin    656:        int flags;
                    657:
                    658:        flags = DETACH_QUIET;
                    659:        if (!idleonly) flags |= DETACH_FORCE;
1.1       thorpej   660:
                    661:        for (;;) {
1.27      ad        662:                mutex_enter(&pdk->dk_openlock);
1.72.2.2  martin    663:                LIST_FOREACH(sc, &pdk->dk_wedges, sc_plink) {
                    664:                        if (!idleonly || sc->sc_dk.dk_openmask == 0)
                    665:                                break;
                    666:                }
                    667:                if (sc == NULL) {
                    668:                        KASSERT(idleonly || pdk->dk_nwedges == 0);
1.27      ad        669:                        mutex_exit(&pdk->dk_openlock);
1.1       thorpej   670:                        return;
                    671:                }
                    672:                strcpy(dkw.dkw_parent, pdk->dk_name);
1.36      cegger    673:                strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev),
                    674:                        sizeof(dkw.dkw_devname));
1.27      ad        675:                mutex_exit(&pdk->dk_openlock);
1.72.2.2  martin    676:                (void) dkwedge_del1(&dkw, flags);
1.1       thorpej   677:        }
                    678: }
                    679:
                    680: /*
                    681:  * dkwedge_list:       [exported function]
                    682:  *
                    683:  *     List all of the wedges on a particular disk.
                    684:  *     If p == NULL, the buffer is in kernel space.  Otherwise, it is
                    685:  *     in user space of the specified process.
                    686:  */
                    687: int
1.10      christos  688: dkwedge_list(struct disk *pdk, struct dkwedge_list *dkwl, struct lwp *l)
1.1       thorpej   689: {
                    690:        struct uio uio;
                    691:        struct iovec iov;
                    692:        struct dkwedge_softc *sc;
                    693:        struct dkwedge_info dkw;
                    694:        int error = 0;
                    695:
                    696:        iov.iov_base = dkwl->dkwl_buf;
                    697:        iov.iov_len = dkwl->dkwl_bufsize;
                    698:
                    699:        uio.uio_iov = &iov;
                    700:        uio.uio_iovcnt = 1;
                    701:        uio.uio_offset = 0;
                    702:        uio.uio_resid = dkwl->dkwl_bufsize;
                    703:        uio.uio_rw = UIO_READ;
1.51      pooka     704:        KASSERT(l == curlwp);
                    705:        uio.uio_vmspace = l->l_proc->p_vmspace;
1.1       thorpej   706:
                    707:        dkwl->dkwl_ncopied = 0;
                    708:
1.27      ad        709:        mutex_enter(&pdk->dk_openlock);
1.1       thorpej   710:        LIST_FOREACH(sc, &pdk->dk_wedges, sc_plink) {
                    711:                if (uio.uio_resid < sizeof(dkw))
                    712:                        break;
                    713:
                    714:                if (sc->sc_state != DKW_STATE_RUNNING)
                    715:                        continue;
                    716:
1.36      cegger    717:                strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev),
                    718:                        sizeof(dkw.dkw_devname));
1.1       thorpej   719:                memcpy(dkw.dkw_wname, sc->sc_wname, sizeof(dkw.dkw_wname));
                    720:                dkw.dkw_wname[sizeof(dkw.dkw_wname) - 1] = '\0';
                    721:                strcpy(dkw.dkw_parent, sc->sc_parent->dk_name);
                    722:                dkw.dkw_offset = sc->sc_offset;
                    723:                dkw.dkw_size = sc->sc_size;
                    724:                strcpy(dkw.dkw_ptype, sc->sc_ptype);
                    725:
                    726:                error = uiomove(&dkw, sizeof(dkw), &uio);
                    727:                if (error)
                    728:                        break;
                    729:                dkwl->dkwl_ncopied++;
                    730:        }
                    731:        dkwl->dkwl_nwedges = pdk->dk_nwedges;
1.27      ad        732:        mutex_exit(&pdk->dk_openlock);
1.1       thorpej   733:
                    734:        return (error);
                    735: }
                    736:
1.25      dyoung    737: device_t
                    738: dkwedge_find_by_wname(const char *wname)
                    739: {
                    740:        device_t dv = NULL;
                    741:        struct dkwedge_softc *sc;
                    742:        int i;
                    743:
1.27      ad        744:        rw_enter(&dkwedges_lock, RW_WRITER);
1.25      dyoung    745:        for (i = 0; i < ndkwedges; i++) {
                    746:                if ((sc = dkwedges[i]) == NULL)
                    747:                        continue;
                    748:                if (strcmp(sc->sc_wname, wname) == 0) {
                    749:                        if (dv != NULL) {
                    750:                                printf(
                    751:                                    "WARNING: double match for wedge name %s "
                    752:                                    "(%s, %s)\n", wname, device_xname(dv),
                    753:                                    device_xname(sc->sc_dev));
                    754:                                continue;
                    755:                        }
                    756:                        dv = sc->sc_dev;
                    757:                }
                    758:        }
1.27      ad        759:        rw_exit(&dkwedges_lock);
1.25      dyoung    760:        return dv;
                    761: }
                    762:
                    763: void
                    764: dkwedge_print_wnames(void)
                    765: {
                    766:        struct dkwedge_softc *sc;
                    767:        int i;
                    768:
1.27      ad        769:        rw_enter(&dkwedges_lock, RW_WRITER);
1.25      dyoung    770:        for (i = 0; i < ndkwedges; i++) {
                    771:                if ((sc = dkwedges[i]) == NULL)
                    772:                        continue;
                    773:                printf(" wedge:%s", sc->sc_wname);
                    774:        }
1.27      ad        775:        rw_exit(&dkwedges_lock);
1.25      dyoung    776: }
                    777:
1.1       thorpej   778: /*
1.18      uebayasi  779:  * We need a dummy object to stuff into the dkwedge discovery method link
1.1       thorpej   780:  * set to ensure that there is always at least one object in the set.
                    781:  */
                    782: static struct dkwedge_discovery_method dummy_discovery_method;
                    783: __link_set_add_bss(dkwedge_methods, dummy_discovery_method);
                    784:
                    785: /*
1.27      ad        786:  * dkwedge_init:
1.1       thorpej   787:  *
1.27      ad        788:  *     Initialize the disk wedge subsystem.
1.1       thorpej   789:  */
1.27      ad        790: void
                    791: dkwedge_init(void)
1.1       thorpej   792: {
                    793:        __link_set_decl(dkwedge_methods, struct dkwedge_discovery_method);
                    794:        struct dkwedge_discovery_method * const *ddmp;
                    795:        struct dkwedge_discovery_method *lddm, *ddm;
                    796:
1.27      ad        797:        rw_init(&dkwedges_lock);
                    798:        rw_init(&dkwedge_discovery_methods_lock);
                    799:
                    800:        if (config_cfdriver_attach(&dk_cd) != 0)
                    801:                panic("dkwedge: unable to attach cfdriver");
                    802:        if (config_cfattach_attach(dk_cd.cd_name, &dk_ca) != 0)
                    803:                panic("dkwedge: unable to attach cfattach");
1.1       thorpej   804:
1.27      ad        805:        rw_enter(&dkwedge_discovery_methods_lock, RW_WRITER);
1.1       thorpej   806:
                    807:        LIST_INIT(&dkwedge_discovery_methods);
                    808:
                    809:        __link_set_foreach(ddmp, dkwedge_methods) {
                    810:                ddm = *ddmp;
                    811:                if (ddm == &dummy_discovery_method)
                    812:                        continue;
                    813:                if (LIST_EMPTY(&dkwedge_discovery_methods)) {
                    814:                        LIST_INSERT_HEAD(&dkwedge_discovery_methods,
                    815:                                         ddm, ddm_list);
                    816:                        continue;
                    817:                }
                    818:                LIST_FOREACH(lddm, &dkwedge_discovery_methods, ddm_list) {
                    819:                        if (ddm->ddm_priority == lddm->ddm_priority) {
                    820:                                aprint_error("dk-method-%s: method \"%s\" "
                    821:                                    "already exists at priority %d\n",
                    822:                                    ddm->ddm_name, lddm->ddm_name,
                    823:                                    lddm->ddm_priority);
                    824:                                /* Not inserted. */
                    825:                                break;
                    826:                        }
                    827:                        if (ddm->ddm_priority < lddm->ddm_priority) {
                    828:                                /* Higher priority; insert before. */
                    829:                                LIST_INSERT_BEFORE(lddm, ddm, ddm_list);
                    830:                                break;
                    831:                        }
                    832:                        if (LIST_NEXT(lddm, ddm_list) == NULL) {
                    833:                                /* Last one; insert after. */
                    834:                                KASSERT(lddm->ddm_priority < ddm->ddm_priority);
                    835:                                LIST_INSERT_AFTER(lddm, ddm, ddm_list);
                    836:                                break;
                    837:                        }
                    838:                }
                    839:        }
                    840:
1.27      ad        841:        rw_exit(&dkwedge_discovery_methods_lock);
1.1       thorpej   842: }
                    843:
                    844: #ifdef DKWEDGE_AUTODISCOVER
                    845: int    dkwedge_autodiscover = 1;
                    846: #else
                    847: int    dkwedge_autodiscover = 0;
                    848: #endif
                    849:
                    850: /*
                    851:  * dkwedge_discover:   [exported function]
                    852:  *
                    853:  *     Discover the wedges on a newly attached disk.
1.72.2.2  martin    854:  *     Remove all unused wedges on the disk first.
1.1       thorpej   855:  */
                    856: void
                    857: dkwedge_discover(struct disk *pdk)
                    858: {
                    859:        struct dkwedge_discovery_method *ddm;
                    860:        struct vnode *vp;
                    861:        int error;
                    862:        dev_t pdev;
                    863:
                    864:        /*
                    865:         * Require people playing with wedges to enable this explicitly.
                    866:         */
                    867:        if (dkwedge_autodiscover == 0)
                    868:                return;
                    869:
1.27      ad        870:        rw_enter(&dkwedge_discovery_methods_lock, RW_READER);
1.1       thorpej   871:
1.72.2.2  martin    872:        /*
                    873:         * Use the character device for scanning, the block device
                    874:         * is busy if there are already wedges attached.
                    875:         */
                    876:        error = dkwedge_compute_pdev(pdk->dk_name, &pdev, VCHR);
1.1       thorpej   877:        if (error) {
                    878:                aprint_error("%s: unable to compute pdev, error = %d\n",
                    879:                    pdk->dk_name, error);
                    880:                goto out;
                    881:        }
                    882:
1.72.2.2  martin    883:        error = cdevvp(pdev, &vp);
1.1       thorpej   884:        if (error) {
                    885:                aprint_error("%s: unable to find vnode for pdev, error = %d\n",
                    886:                    pdk->dk_name, error);
                    887:                goto out;
                    888:        }
                    889:
                    890:        error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
                    891:        if (error) {
                    892:                aprint_error("%s: unable to lock vnode for pdev, error = %d\n",
                    893:                    pdk->dk_name, error);
                    894:                vrele(vp);
                    895:                goto out;
                    896:        }
                    897:
1.62      jmcneill  898:        error = VOP_OPEN(vp, FREAD | FSILENT, NOCRED);
1.1       thorpej   899:        if (error) {
1.67      soren     900:                if (error != ENODEV)
                    901:                        aprint_error("%s: unable to open device, error = %d\n",
                    902:                            pdk->dk_name, error);
1.1       thorpej   903:                vput(vp);
                    904:                goto out;
                    905:        }
1.56      hannken   906:        VOP_UNLOCK(vp);
1.1       thorpej   907:
                    908:        /*
1.72.2.2  martin    909:         * Remove unused wedges
                    910:         */
                    911:        dkwedge_delall1(pdk, true);
                    912:
                    913:        /*
1.1       thorpej   914:         * For each supported partition map type, look to see if
                    915:         * this map type exists.  If so, parse it and add the
                    916:         * corresponding wedges.
                    917:         */
                    918:        LIST_FOREACH(ddm, &dkwedge_discovery_methods, ddm_list) {
                    919:                error = (*ddm->ddm_discover)(pdk, vp);
                    920:                if (error == 0) {
                    921:                        /* Successfully created wedges; we're done. */
                    922:                        break;
                    923:                }
                    924:        }
                    925:
1.35      ad        926:        error = vn_close(vp, FREAD, NOCRED);
1.1       thorpej   927:        if (error) {
                    928:                aprint_error("%s: unable to close device, error = %d\n",
                    929:                    pdk->dk_name, error);
                    930:                /* We'll just assume the vnode has been cleaned up. */
                    931:        }
1.72.2.3! martin    932:
1.1       thorpej   933:  out:
1.27      ad        934:        rw_exit(&dkwedge_discovery_methods_lock);
1.1       thorpej   935: }
                    936:
                    937: /*
                    938:  * dkwedge_read:
                    939:  *
1.37      agc       940:  *     Read some data from the specified disk, used for
1.1       thorpej   941:  *     partition discovery.
                    942:  */
                    943: int
1.20      christos  944: dkwedge_read(struct disk *pdk, struct vnode *vp, daddr_t blkno,
1.19      christos  945:     void *tbuf, size_t len)
1.1       thorpej   946: {
1.72.2.2  martin    947:        buf_t *bp;
                    948:        int error;
1.1       thorpej   949:
1.72.2.2  martin    950:        /*
                    951:         * The kernel cannot read from a character device vnode
                    952:         * as physio() only handles user memory.
                    953:         *
                    954:         * Determine the corresponding block device and call into
                    955:         * the driver directly.
                    956:         */
1.41      ad        957:
1.72.2.2  martin    958:        bp = getiobuf(vp, true);
1.41      ad        959:        bp->b_flags = B_READ;
1.72.2.2  martin    960:        bp->b_cflags = BC_BUSY;
                    961:        bp->b_dev = devsw_chr2blk(vp->v_rdev);
1.41      ad        962:        bp->b_data = tbuf;
1.72.2.3! martin    963:        bp->b_bufsize = bp->b_bcount = len;
1.72.2.2  martin    964:        bp->b_blkno = blkno;
1.72.2.3! martin    965:        bp->b_cylinder = 0;
        !           966:        bp->b_error = 0;
1.72.2.2  martin    967:
                    968:        error = bdev_open(bp->b_dev, FREAD, S_IFBLK, curlwp);
                    969:        if (error)
                    970:                return error;
1.41      ad        971:
1.72.2.2  martin    972:        bdev_strategy(bp);
                    973:        error = biowait(bp);
1.41      ad        974:        putiobuf(bp);
1.1       thorpej   975:
1.72.2.2  martin    976:        bdev_close(bp->b_dev, FREAD, S_IFBLK, curlwp);
                    977:
                    978:        return error;
1.1       thorpej   979: }
                    980:
                    981: /*
                    982:  * dkwedge_lookup:
                    983:  *
                    984:  *     Look up a dkwedge_softc based on the provided dev_t.
                    985:  */
                    986: static struct dkwedge_softc *
                    987: dkwedge_lookup(dev_t dev)
                    988: {
1.3       thorpej   989:        int unit = minor(dev);
1.1       thorpej   990:
                    991:        if (unit >= ndkwedges)
                    992:                return (NULL);
                    993:
                    994:        KASSERT(dkwedges != NULL);
                    995:
                    996:        return (dkwedges[unit]);
                    997: }
                    998:
                    999: /*
                   1000:  * dkopen:             [devsw entry point]
                   1001:  *
                   1002:  *     Open a wedge.
                   1003:  */
                   1004: static int
1.20      christos 1005: dkopen(dev_t dev, int flags, int fmt, struct lwp *l)
1.1       thorpej  1006: {
                   1007:        struct dkwedge_softc *sc = dkwedge_lookup(dev);
                   1008:        struct vnode *vp;
1.14      thorpej  1009:        int error = 0;
1.1       thorpej  1010:
                   1011:        if (sc == NULL)
                   1012:                return (ENODEV);
                   1013:        if (sc->sc_state != DKW_STATE_RUNNING)
                   1014:                return (ENXIO);
                   1015:
                   1016:        /*
                   1017:         * We go through a complicated little dance to only open the parent
                   1018:         * vnode once per wedge, no matter how many times the wedge is
                   1019:         * opened.  The reason?  We see one dkopen() per open call, but
                   1020:         * only dkclose() on the last close.
                   1021:         */
1.27      ad       1022:        mutex_enter(&sc->sc_dk.dk_openlock);
                   1023:        mutex_enter(&sc->sc_parent->dk_rawlock);
1.3       thorpej  1024:        if (sc->sc_dk.dk_openmask == 0) {
1.23      dyoung   1025:                if (sc->sc_parent->dk_rawopens == 0) {
1.1       thorpej  1026:                        KASSERT(sc->sc_parent->dk_rawvp == NULL);
                   1027:                        error = bdevvp(sc->sc_pdev, &vp);
                   1028:                        if (error)
                   1029:                                goto popen_fail;
                   1030:                        error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
                   1031:                        if (error) {
                   1032:                                vrele(vp);
                   1033:                                goto popen_fail;
                   1034:                        }
1.30      pooka    1035:                        error = VOP_OPEN(vp, FREAD | FWRITE, NOCRED);
1.1       thorpej  1036:                        if (error) {
                   1037:                                vput(vp);
                   1038:                                goto popen_fail;
                   1039:                        }
                   1040:                        /* VOP_OPEN() doesn't do this for us. */
1.61      rmind    1041:                        mutex_enter(vp->v_interlock);
1.1       thorpej  1042:                        vp->v_writecount++;
1.61      rmind    1043:                        mutex_exit(vp->v_interlock);
1.56      hannken  1044:                        VOP_UNLOCK(vp);
1.1       thorpej  1045:                        sc->sc_parent->dk_rawvp = vp;
                   1046:                }
1.24      christos 1047:                sc->sc_parent->dk_rawopens++;
1.1       thorpej  1048:        }
1.17      dbj      1049:        if (fmt == S_IFCHR)
                   1050:                sc->sc_dk.dk_copenmask |= 1;
                   1051:        else
                   1052:                sc->sc_dk.dk_bopenmask |= 1;
                   1053:        sc->sc_dk.dk_openmask =
                   1054:            sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
1.1       thorpej  1055:
                   1056:  popen_fail:
1.27      ad       1057:        mutex_exit(&sc->sc_parent->dk_rawlock);
                   1058:        mutex_exit(&sc->sc_dk.dk_openlock);
1.1       thorpej  1059:        return (error);
                   1060: }
                   1061:
                   1062: /*
1.46      dyoung   1063:  * Caller must hold sc->sc_dk.dk_openlock and sc->sc_parent->dk_rawlock.
                   1064:  */
                   1065: static int
                   1066: dklastclose(struct dkwedge_softc *sc)
                   1067: {
1.72.2.2  martin   1068:        int error = 0, doclose;
1.46      dyoung   1069:
1.72.2.2  martin   1070:        doclose = 0;
                   1071:        if (sc->sc_parent->dk_rawopens > 0) {
                   1072:                if (--sc->sc_parent->dk_rawopens == 0)
                   1073:                        doclose = 1;
                   1074:        }
                   1075:
                   1076:        mutex_exit(&sc->sc_parent->dk_rawlock);
                   1077:
                   1078:        if (doclose) {
1.46      dyoung   1079:                KASSERT(sc->sc_parent->dk_rawvp != NULL);
                   1080:                error = vn_close(sc->sc_parent->dk_rawvp,
                   1081:                    FREAD | FWRITE, NOCRED);
                   1082:                sc->sc_parent->dk_rawvp = NULL;
1.72.2.2  martin   1083:        }
                   1084:
1.46      dyoung   1085:        return error;
                   1086: }
                   1087:
                   1088: /*
1.1       thorpej  1089:  * dkclose:            [devsw entry point]
                   1090:  *
                   1091:  *     Close a wedge.
                   1092:  */
                   1093: static int
1.20      christos 1094: dkclose(dev_t dev, int flags, int fmt, struct lwp *l)
1.1       thorpej  1095: {
                   1096:        struct dkwedge_softc *sc = dkwedge_lookup(dev);
                   1097:        int error = 0;
                   1098:
1.59      christos 1099:        if (sc == NULL)
                   1100:                return (ENODEV);
                   1101:        if (sc->sc_state != DKW_STATE_RUNNING)
                   1102:                return (ENXIO);
                   1103:
1.3       thorpej  1104:        KASSERT(sc->sc_dk.dk_openmask != 0);
1.1       thorpej  1105:
1.27      ad       1106:        mutex_enter(&sc->sc_dk.dk_openlock);
                   1107:        mutex_enter(&sc->sc_parent->dk_rawlock);
1.1       thorpej  1108:
1.3       thorpej  1109:        if (fmt == S_IFCHR)
                   1110:                sc->sc_dk.dk_copenmask &= ~1;
                   1111:        else
                   1112:                sc->sc_dk.dk_bopenmask &= ~1;
                   1113:        sc->sc_dk.dk_openmask =
                   1114:            sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
                   1115:
1.46      dyoung   1116:        if (sc->sc_dk.dk_openmask == 0)
1.57      bouyer   1117:                error = dklastclose(sc); /* releases dk_rawlock */
                   1118:        else
                   1119:                mutex_exit(&sc->sc_parent->dk_rawlock);
1.1       thorpej  1120:
1.27      ad       1121:        mutex_exit(&sc->sc_dk.dk_openlock);
1.1       thorpej  1122:
                   1123:        return (error);
                   1124: }
                   1125:
                   1126: /*
                   1127:  * dkstragegy:         [devsw entry point]
                   1128:  *
                   1129:  *     Perform I/O based on the wedge I/O strategy.
                   1130:  */
                   1131: static void
                   1132: dkstrategy(struct buf *bp)
                   1133: {
                   1134:        struct dkwedge_softc *sc = dkwedge_lookup(bp->b_dev);
1.54      mlelstv  1135:        uint64_t p_size, p_offset;
1.1       thorpej  1136:        int s;
                   1137:
1.59      christos 1138:        if (sc == NULL) {
                   1139:                bp->b_error = ENODEV;
                   1140:                goto done;
                   1141:        }
1.60      christos 1142:
                   1143:        if (sc->sc_state != DKW_STATE_RUNNING ||
                   1144:            sc->sc_parent->dk_rawvp == NULL) {
1.1       thorpej  1145:                bp->b_error = ENXIO;
                   1146:                goto done;
                   1147:        }
                   1148:
                   1149:        /* If it's an empty transfer, wake up the top half now. */
                   1150:        if (bp->b_bcount == 0)
                   1151:                goto done;
                   1152:
1.54      mlelstv  1153:        p_offset = sc->sc_offset << sc->sc_parent->dk_blkshift;
                   1154:        p_size   = sc->sc_size << sc->sc_parent->dk_blkshift;
                   1155:
1.1       thorpej  1156:        /* Make sure it's in-range. */
1.54      mlelstv  1157:        if (bounds_check_with_mediasize(bp, DEV_BSIZE, p_size) <= 0)
1.1       thorpej  1158:                goto done;
                   1159:
                   1160:        /* Translate it to the parent's raw LBA. */
1.54      mlelstv  1161:        bp->b_rawblkno = bp->b_blkno + p_offset;
1.1       thorpej  1162:
                   1163:        /* Place it in the queue and start I/O on the unit. */
                   1164:        s = splbio();
                   1165:        sc->sc_iopend++;
1.43      yamt     1166:        bufq_put(sc->sc_bufq, bp);
1.1       thorpej  1167:        dkstart(sc);
                   1168:        splx(s);
                   1169:        return;
                   1170:
                   1171:  done:
                   1172:        bp->b_resid = bp->b_bcount;
                   1173:        biodone(bp);
                   1174: }
                   1175:
                   1176: /*
                   1177:  * dkstart:
                   1178:  *
                   1179:  *     Start I/O that has been enqueued on the wedge.
                   1180:  *     NOTE: Must be called at splbio()!
                   1181:  */
                   1182: static void
                   1183: dkstart(struct dkwedge_softc *sc)
                   1184: {
1.32      ad       1185:        struct vnode *vp;
1.1       thorpej  1186:        struct buf *bp, *nbp;
                   1187:
                   1188:        /* Do as much work as has been enqueued. */
1.43      yamt     1189:        while ((bp = bufq_peek(sc->sc_bufq)) != NULL) {
1.1       thorpej  1190:                if (sc->sc_state != DKW_STATE_RUNNING) {
1.43      yamt     1191:                        (void) bufq_get(sc->sc_bufq);
1.1       thorpej  1192:                        if (sc->sc_iopend-- == 1 &&
                   1193:                            (sc->sc_flags & DK_F_WAIT_DRAIN) != 0) {
                   1194:                                sc->sc_flags &= ~DK_F_WAIT_DRAIN;
                   1195:                                wakeup(&sc->sc_iopend);
                   1196:                        }
                   1197:                        bp->b_error = ENXIO;
                   1198:                        bp->b_resid = bp->b_bcount;
                   1199:                        biodone(bp);
                   1200:                }
                   1201:
                   1202:                /* Instrumentation. */
                   1203:                disk_busy(&sc->sc_dk);
1.6       perry    1204:
1.32      ad       1205:                nbp = getiobuf(sc->sc_parent->dk_rawvp, false);
1.1       thorpej  1206:                if (nbp == NULL) {
                   1207:                        /*
                   1208:                         * No resources to run this request; leave the
                   1209:                         * buffer queued up, and schedule a timer to
                   1210:                         * restart the queue in 1/2 a second.
                   1211:                         */
                   1212:                        disk_unbusy(&sc->sc_dk, 0, bp->b_flags & B_READ);
                   1213:                        callout_schedule(&sc->sc_restart_ch, hz / 2);
                   1214:                        return;
                   1215:                }
                   1216:
1.43      yamt     1217:                (void) bufq_get(sc->sc_bufq);
1.1       thorpej  1218:
                   1219:                nbp->b_data = bp->b_data;
1.32      ad       1220:                nbp->b_flags = bp->b_flags;
                   1221:                nbp->b_oflags = bp->b_oflags;
                   1222:                nbp->b_cflags = bp->b_cflags;
1.1       thorpej  1223:                nbp->b_iodone = dkiodone;
                   1224:                nbp->b_proc = bp->b_proc;
                   1225:                nbp->b_blkno = bp->b_rawblkno;
                   1226:                nbp->b_dev = sc->sc_parent->dk_rawvp->v_rdev;
                   1227:                nbp->b_bcount = bp->b_bcount;
                   1228:                nbp->b_private = bp;
                   1229:                BIO_COPYPRIO(nbp, bp);
                   1230:
1.32      ad       1231:                vp = nbp->b_vp;
                   1232:                if ((nbp->b_flags & B_READ) == 0) {
1.61      rmind    1233:                        mutex_enter(vp->v_interlock);
1.32      ad       1234:                        vp->v_numoutput++;
1.61      rmind    1235:                        mutex_exit(vp->v_interlock);
1.32      ad       1236:                }
                   1237:                VOP_STRATEGY(vp, nbp);
1.1       thorpej  1238:        }
                   1239: }
                   1240:
                   1241: /*
                   1242:  * dkiodone:
                   1243:  *
                   1244:  *     I/O to a wedge has completed; alert the top half.
                   1245:  */
                   1246: static void
                   1247: dkiodone(struct buf *bp)
                   1248: {
                   1249:        struct buf *obp = bp->b_private;
                   1250:        struct dkwedge_softc *sc = dkwedge_lookup(obp->b_dev);
                   1251:
1.53      bouyer   1252:        int s = splbio();
                   1253:
1.28      ad       1254:        if (bp->b_error != 0)
1.1       thorpej  1255:                obp->b_error = bp->b_error;
                   1256:        obp->b_resid = bp->b_resid;
1.11      yamt     1257:        putiobuf(bp);
1.1       thorpej  1258:
                   1259:        if (sc->sc_iopend-- == 1 && (sc->sc_flags & DK_F_WAIT_DRAIN) != 0) {
                   1260:                sc->sc_flags &= ~DK_F_WAIT_DRAIN;
                   1261:                wakeup(&sc->sc_iopend);
                   1262:        }
                   1263:
                   1264:        disk_unbusy(&sc->sc_dk, obp->b_bcount - obp->b_resid,
                   1265:            obp->b_flags & B_READ);
                   1266:
                   1267:        biodone(obp);
                   1268:
                   1269:        /* Kick the queue in case there is more work we can do. */
                   1270:        dkstart(sc);
1.53      bouyer   1271:        splx(s);
1.1       thorpej  1272: }
                   1273:
                   1274: /*
                   1275:  * dkrestart:
                   1276:  *
                   1277:  *     Restart the work queue after it was stalled due to
                   1278:  *     a resource shortage.  Invoked via a callout.
                   1279:  */
                   1280: static void
                   1281: dkrestart(void *v)
                   1282: {
                   1283:        struct dkwedge_softc *sc = v;
                   1284:        int s;
                   1285:
                   1286:        s = splbio();
                   1287:        dkstart(sc);
                   1288:        splx(s);
                   1289: }
                   1290:
                   1291: /*
1.52      jakllsch 1292:  * dkminphys:
                   1293:  *
                   1294:  *     Call parent's minphys function.
                   1295:  */
                   1296: static void
                   1297: dkminphys(struct buf *bp)
                   1298: {
                   1299:        struct dkwedge_softc *sc = dkwedge_lookup(bp->b_dev);
                   1300:        dev_t dev;
                   1301:
                   1302:        dev = bp->b_dev;
                   1303:        bp->b_dev = sc->sc_pdev;
                   1304:        (*sc->sc_parent->dk_driver->d_minphys)(bp);
                   1305:        bp->b_dev = dev;
                   1306: }
                   1307:
                   1308: /*
1.1       thorpej  1309:  * dkread:             [devsw entry point]
                   1310:  *
                   1311:  *     Read from a wedge.
                   1312:  */
                   1313: static int
1.20      christos 1314: dkread(dev_t dev, struct uio *uio, int flags)
1.1       thorpej  1315: {
                   1316:        struct dkwedge_softc *sc = dkwedge_lookup(dev);
                   1317:
1.59      christos 1318:        if (sc == NULL)
                   1319:                return (ENODEV);
1.1       thorpej  1320:        if (sc->sc_state != DKW_STATE_RUNNING)
                   1321:                return (ENXIO);
1.6       perry    1322:
1.52      jakllsch 1323:        return (physio(dkstrategy, NULL, dev, B_READ, dkminphys, uio));
1.1       thorpej  1324: }
                   1325:
                   1326: /*
                   1327:  * dkwrite:            [devsw entry point]
                   1328:  *
                   1329:  *     Write to a wedge.
                   1330:  */
                   1331: static int
1.20      christos 1332: dkwrite(dev_t dev, struct uio *uio, int flags)
1.1       thorpej  1333: {
                   1334:        struct dkwedge_softc *sc = dkwedge_lookup(dev);
                   1335:
1.59      christos 1336:        if (sc == NULL)
                   1337:                return (ENODEV);
1.1       thorpej  1338:        if (sc->sc_state != DKW_STATE_RUNNING)
                   1339:                return (ENXIO);
1.6       perry    1340:
1.52      jakllsch 1341:        return (physio(dkstrategy, NULL, dev, B_WRITE, dkminphys, uio));
1.1       thorpej  1342: }
                   1343:
                   1344: /*
                   1345:  * dkioctl:            [devsw entry point]
                   1346:  *
                   1347:  *     Perform an ioctl request on a wedge.
                   1348:  */
                   1349: static int
1.22      christos 1350: dkioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
1.1       thorpej  1351: {
                   1352:        struct dkwedge_softc *sc = dkwedge_lookup(dev);
                   1353:        int error = 0;
                   1354:
1.59      christos 1355:        if (sc == NULL)
                   1356:                return (ENODEV);
1.1       thorpej  1357:        if (sc->sc_state != DKW_STATE_RUNNING)
                   1358:                return (ENXIO);
1.60      christos 1359:        if (sc->sc_parent->dk_rawvp == NULL)
                   1360:                return (ENXIO);
1.1       thorpej  1361:
1.48      haad     1362:        error = disk_ioctl(&sc->sc_dk, cmd, data, flag, l);
                   1363:        if (error != EPASSTHROUGH)
                   1364:                return (error);
                   1365:
                   1366:        error = 0;
                   1367:
1.1       thorpej  1368:        switch (cmd) {
1.4       thorpej  1369:        case DIOCCACHESYNC:
                   1370:                /*
                   1371:                 * XXX Do we really need to care about having a writable
                   1372:                 * file descriptor here?
                   1373:                 */
                   1374:                if ((flag & FWRITE) == 0)
                   1375:                        error = EBADF;
                   1376:                else
                   1377:                        error = VOP_IOCTL(sc->sc_parent->dk_rawvp,
                   1378:                                          cmd, data, flag,
1.30      pooka    1379:                                          l != NULL ? l->l_cred : NOCRED);
1.4       thorpej  1380:                break;
1.1       thorpej  1381:        case DIOCGWEDGEINFO:
                   1382:            {
1.48      haad     1383:                struct dkwedge_info *dkw = (void *) data;
1.1       thorpej  1384:
1.36      cegger   1385:                strlcpy(dkw->dkw_devname, device_xname(sc->sc_dev),
                   1386:                        sizeof(dkw->dkw_devname));
1.1       thorpej  1387:                memcpy(dkw->dkw_wname, sc->sc_wname, sizeof(dkw->dkw_wname));
                   1388:                dkw->dkw_wname[sizeof(dkw->dkw_wname) - 1] = '\0';
                   1389:                strcpy(dkw->dkw_parent, sc->sc_parent->dk_name);
                   1390:                dkw->dkw_offset = sc->sc_offset;
                   1391:                dkw->dkw_size = sc->sc_size;
                   1392:                strcpy(dkw->dkw_ptype, sc->sc_ptype);
                   1393:
                   1394:                break;
                   1395:            }
                   1396:
                   1397:        default:
                   1398:                error = ENOTTY;
                   1399:        }
                   1400:
                   1401:        return (error);
                   1402: }
                   1403:
                   1404: /*
1.72      dholland 1405:  * dkdiscard:          [devsw entry point]
                   1406:  *
                   1407:  *     Perform a discard-range request on a wedge.
                   1408:  */
                   1409: static int
                   1410: dkdiscard(dev_t dev, off_t pos, off_t len)
                   1411: {
                   1412:        struct dkwedge_softc *sc = dkwedge_lookup(dev);
1.72.2.1  martin   1413:        unsigned shift;
                   1414:        off_t offset, maxlen;
1.72      dholland 1415:
                   1416:        if (sc == NULL)
                   1417:                return (ENODEV);
                   1418:        if (sc->sc_state != DKW_STATE_RUNNING)
                   1419:                return (ENXIO);
                   1420:        if (sc->sc_parent->dk_rawvp == NULL)
                   1421:                return (ENXIO);
                   1422:
1.72.2.1  martin   1423:        shift = (sc->sc_parent->dk_blkshift + DEV_BSHIFT);
                   1424:        KASSERT(__type_fit(off_t, sc->sc_size));
                   1425:        KASSERT(__type_fit(off_t, sc->sc_offset));
                   1426:        KASSERT(0 <= sc->sc_offset);
                   1427:        KASSERT(sc->sc_size <= (__type_max(off_t) >> shift));
                   1428:        KASSERT(sc->sc_offset <= ((__type_max(off_t) >> shift) - sc->sc_size));
                   1429:        offset = ((off_t)sc->sc_offset << shift);
                   1430:        maxlen = ((off_t)sc->sc_size << shift);
                   1431:
                   1432:        if (len > maxlen)
                   1433:                return (EINVAL);
                   1434:        if (pos > (maxlen - len))
                   1435:                return (EINVAL);
                   1436:
                   1437:        pos += offset;
1.72      dholland 1438:        return VOP_FDISCARD(sc->sc_parent->dk_rawvp, pos, len);
                   1439: }
                   1440:
                   1441: /*
1.1       thorpej  1442:  * dksize:             [devsw entry point]
                   1443:  *
                   1444:  *     Query the size of a wedge for the purpose of performing a dump
                   1445:  *     or for swapping to.
                   1446:  */
                   1447: static int
                   1448: dksize(dev_t dev)
                   1449: {
1.13      thorpej  1450:        struct dkwedge_softc *sc = dkwedge_lookup(dev);
                   1451:        int rv = -1;
                   1452:
                   1453:        if (sc == NULL)
                   1454:                return (-1);
                   1455:        if (sc->sc_state != DKW_STATE_RUNNING)
1.55      mlelstv  1456:                return (-1);
1.13      thorpej  1457:
1.27      ad       1458:        mutex_enter(&sc->sc_dk.dk_openlock);
                   1459:        mutex_enter(&sc->sc_parent->dk_rawlock);
1.1       thorpej  1460:
1.13      thorpej  1461:        /* Our content type is static, no need to open the device. */
                   1462:
                   1463:        if (strcmp(sc->sc_ptype, DKW_PTYPE_SWAP) == 0) {
                   1464:                /* Saturate if we are larger than INT_MAX. */
                   1465:                if (sc->sc_size > INT_MAX)
                   1466:                        rv = INT_MAX;
                   1467:                else
                   1468:                        rv = (int) sc->sc_size;
                   1469:        }
                   1470:
1.27      ad       1471:        mutex_exit(&sc->sc_parent->dk_rawlock);
                   1472:        mutex_exit(&sc->sc_dk.dk_openlock);
1.13      thorpej  1473:
                   1474:        return (rv);
1.1       thorpej  1475: }
                   1476:
                   1477: /*
                   1478:  * dkdump:             [devsw entry point]
                   1479:  *
                   1480:  *     Perform a crash dump to a wedge.
                   1481:  */
                   1482: static int
1.23      dyoung   1483: dkdump(dev_t dev, daddr_t blkno, void *va, size_t size)
1.1       thorpej  1484: {
1.23      dyoung   1485:        struct dkwedge_softc *sc = dkwedge_lookup(dev);
                   1486:        const struct bdevsw *bdev;
                   1487:        int rv = 0;
                   1488:
                   1489:        if (sc == NULL)
1.59      christos 1490:                return (ENODEV);
1.23      dyoung   1491:        if (sc->sc_state != DKW_STATE_RUNNING)
                   1492:                return (ENXIO);
                   1493:
1.27      ad       1494:        mutex_enter(&sc->sc_dk.dk_openlock);
                   1495:        mutex_enter(&sc->sc_parent->dk_rawlock);
1.23      dyoung   1496:
                   1497:        /* Our content type is static, no need to open the device. */
                   1498:
                   1499:        if (strcmp(sc->sc_ptype, DKW_PTYPE_SWAP) != 0) {
                   1500:                rv = ENXIO;
                   1501:                goto out;
                   1502:        }
                   1503:        if (size % DEV_BSIZE != 0) {
                   1504:                rv = EINVAL;
                   1505:                goto out;
                   1506:        }
                   1507:        if (blkno + size / DEV_BSIZE > sc->sc_size) {
                   1508:                printf("%s: blkno (%" PRIu64 ") + size / DEV_BSIZE (%zu) > "
                   1509:                    "sc->sc_size (%" PRIu64 ")\n", __func__, blkno,
                   1510:                    size / DEV_BSIZE, sc->sc_size);
                   1511:                rv = EINVAL;
                   1512:                goto out;
                   1513:        }
                   1514:
                   1515:        bdev = bdevsw_lookup(sc->sc_pdev);
                   1516:        rv = (*bdev->d_dump)(sc->sc_pdev, blkno + sc->sc_offset, va, size);
                   1517:
                   1518: out:
1.27      ad       1519:        mutex_exit(&sc->sc_parent->dk_rawlock);
                   1520:        mutex_exit(&sc->sc_dk.dk_openlock);
1.1       thorpej  1521:
1.23      dyoung   1522:        return rv;
1.1       thorpej  1523: }
1.49      pooka    1524:
                   1525: /*
                   1526:  * config glue
                   1527:  */
                   1528:
1.64      mlelstv  1529: /*
                   1530:  * dkwedge_find_partition
                   1531:  *
                   1532:  *     Find wedge corresponding to the specified parent name
                   1533:  *     and offset/length.
                   1534:  */
                   1535: device_t
                   1536: dkwedge_find_partition(device_t parent, daddr_t startblk, uint64_t nblks)
1.49      pooka    1537: {
1.64      mlelstv  1538:        struct dkwedge_softc *sc;
                   1539:        int i;
                   1540:        device_t wedge = NULL;
1.49      pooka    1541:
1.64      mlelstv  1542:        rw_enter(&dkwedges_lock, RW_READER);
                   1543:        for (i = 0; i < ndkwedges; i++) {
                   1544:                if ((sc = dkwedges[i]) == NULL)
                   1545:                        continue;
                   1546:                if (strcmp(sc->sc_parent->dk_name, device_xname(parent)) == 0 &&
                   1547:                    sc->sc_offset == startblk &&
                   1548:                    sc->sc_size == nblks) {
                   1549:                        if (wedge) {
                   1550:                                printf("WARNING: double match for boot wedge "
                   1551:                                    "(%s, %s)\n",
                   1552:                                    device_xname(wedge),
                   1553:                                    device_xname(sc->sc_dev));
                   1554:                                continue;
                   1555:                        }
                   1556:                        wedge = sc->sc_dev;
                   1557:                }
1.49      pooka    1558:        }
1.64      mlelstv  1559:        rw_exit(&dkwedges_lock);
1.49      pooka    1560:
1.64      mlelstv  1561:        return wedge;
                   1562: }
1.49      pooka    1563:
1.69      christos 1564: const char *
                   1565: dkwedge_get_parent_name(dev_t dev)
                   1566: {
                   1567:        /* XXX: perhaps do this in lookup? */
                   1568:        int bmaj = bdevsw_lookup_major(&dk_bdevsw);
                   1569:        int cmaj = cdevsw_lookup_major(&dk_cdevsw);
                   1570:        if (major(dev) != bmaj && major(dev) != cmaj)
                   1571:                return NULL;
                   1572:        struct dkwedge_softc *sc = dkwedge_lookup(dev);
                   1573:        if (sc == NULL)
                   1574:                return NULL;
                   1575:        return sc->sc_parent->dk_name;
                   1576: }
1.72.2.3! martin   1577:

CVSweb <webmaster@jp.NetBSD.org>