The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/geom/geom_disk.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2002 Poul-Henning Kamp
    3  * Copyright (c) 2002 Networks Associates Technology, Inc.
    4  * All rights reserved.
    5  *
    6  * This software was developed for the FreeBSD Project by Poul-Henning Kamp
    7  * and NAI Labs, the Security Research Division of Network Associates, Inc.
    8  * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
    9  * DARPA CHATS research program.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. The names of the authors may not be used to endorse or promote
   20  *    products derived from this software without specific prior written
   21  *    permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   33  * SUCH DAMAGE.
   34  */
   35 
   36 #include <sys/cdefs.h>
   37 __FBSDID("$FreeBSD: releng/8.3/sys/geom/geom_disk.c 223176 2011-06-17 06:23:58Z mav $");
   38 
   39 #include "opt_geom.h"
   40 
   41 #include <sys/param.h>
   42 #include <sys/systm.h>
   43 #include <sys/kernel.h>
   44 #include <sys/sysctl.h>
   45 #include <sys/bio.h>
   46 #include <sys/ctype.h>
   47 #include <sys/fcntl.h>
   48 #include <sys/malloc.h>
   49 #include <sys/sysctl.h>
   50 #include <sys/devicestat.h>
   51 #include <machine/md_var.h>
   52 
   53 #include <sys/lock.h>
   54 #include <sys/mutex.h>
   55 #include <geom/geom.h>
   56 #include <geom/geom_disk.h>
   57 #include <geom/geom_int.h>
   58 
   59 #include <dev/led/led.h>
   60 
   61 struct g_disk_softc {
   62         struct disk             *dp;
   63         struct sysctl_ctx_list  sysctl_ctx;
   64         struct sysctl_oid       *sysctl_tree;
   65         char                    led[64];
   66         uint32_t                state;
   67 };
   68 
   69 static struct mtx g_disk_done_mtx;
   70 
   71 static g_access_t g_disk_access;
   72 static g_init_t g_disk_init;
   73 static g_fini_t g_disk_fini;
   74 static g_start_t g_disk_start;
   75 static g_ioctl_t g_disk_ioctl;
   76 static g_dumpconf_t g_disk_dumpconf;
   77 
   78 static struct g_class g_disk_class = {
   79         .name = "DISK",
   80         .version = G_VERSION,
   81         .init = g_disk_init,
   82         .fini = g_disk_fini,
   83         .start = g_disk_start,
   84         .access = g_disk_access,
   85         .ioctl = g_disk_ioctl,
   86         .dumpconf = g_disk_dumpconf,
   87 };
   88 
   89 SYSCTL_DECL(_kern_geom);
   90 SYSCTL_NODE(_kern_geom, OID_AUTO, disk, CTLFLAG_RW, 0, "GEOM_DISK stuff");
   91 
   92 static void
   93 g_disk_init(struct g_class *mp __unused)
   94 {
   95 
   96         mtx_init(&g_disk_done_mtx, "g_disk_done", NULL, MTX_DEF);
   97 }
   98 
   99 static void
  100 g_disk_fini(struct g_class *mp __unused)
  101 {
  102 
  103         mtx_destroy(&g_disk_done_mtx);
  104 }
  105 
  106 DECLARE_GEOM_CLASS(g_disk_class, g_disk);
  107 
  108 static void __inline
  109 g_disk_lock_giant(struct disk *dp)
  110 {
  111         if (dp->d_flags & DISKFLAG_NEEDSGIANT)
  112                 mtx_lock(&Giant);
  113 }
  114 
  115 static void __inline
  116 g_disk_unlock_giant(struct disk *dp)
  117 {
  118         if (dp->d_flags & DISKFLAG_NEEDSGIANT)
  119                 mtx_unlock(&Giant);
  120 }
  121 
  122 static int
  123 g_disk_access(struct g_provider *pp, int r, int w, int e)
  124 {
  125         struct disk *dp;
  126         struct g_disk_softc *sc;
  127         int error;
  128 
  129         g_trace(G_T_ACCESS, "g_disk_access(%s, %d, %d, %d)",
  130             pp->name, r, w, e);
  131         g_topology_assert();
  132         sc = pp->geom->softc;
  133         if (sc == NULL || (dp = sc->dp) == NULL || dp->d_destroyed) {
  134                 /*
  135                  * Allow decreasing access count even if disk is not
  136                  * avaliable anymore.
  137                  */
  138                 if (r <= 0 && w <= 0 && e <= 0)
  139                         return (0);
  140                 return (ENXIO);
  141         }
  142         r += pp->acr;
  143         w += pp->acw;
  144         e += pp->ace;
  145         error = 0;
  146         if ((pp->acr + pp->acw + pp->ace) == 0 && (r + w + e) > 0) {
  147                 if (dp->d_open != NULL) {
  148                         g_disk_lock_giant(dp);
  149                         error = dp->d_open(dp);
  150                         if (bootverbose && error != 0)
  151                                 printf("Opened disk %s -> %d\n",
  152                                     pp->name, error);
  153                         g_disk_unlock_giant(dp);
  154                 }
  155                 pp->mediasize = dp->d_mediasize;
  156                 pp->sectorsize = dp->d_sectorsize;
  157                 if (dp->d_flags & DISKFLAG_CANDELETE)
  158                         pp->flags |= G_PF_CANDELETE;
  159                 else
  160                         pp->flags &= ~G_PF_CANDELETE;
  161                 pp->stripeoffset = dp->d_stripeoffset;
  162                 pp->stripesize = dp->d_stripesize;
  163                 dp->d_flags |= DISKFLAG_OPEN;
  164                 if (dp->d_maxsize == 0) {
  165                         printf("WARNING: Disk drive %s%d has no d_maxsize\n",
  166                             dp->d_name, dp->d_unit);
  167                         dp->d_maxsize = DFLTPHYS;
  168                 }
  169         } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) {
  170                 if (dp->d_close != NULL) {
  171                         g_disk_lock_giant(dp);
  172                         error = dp->d_close(dp);
  173                         if (error != 0)
  174                                 printf("Closed disk %s -> %d\n",
  175                                     pp->name, error);
  176                         g_disk_unlock_giant(dp);
  177                 }
  178                 sc->state = G_STATE_ACTIVE;
  179                 if (sc->led[0] != 0)
  180                         led_set(sc->led, "");
  181                 dp->d_flags &= ~DISKFLAG_OPEN;
  182         }
  183         return (error);
  184 }
  185 
  186 static void
  187 g_disk_kerneldump(struct bio *bp, struct disk *dp)
  188 {
  189         struct g_kerneldump *gkd;
  190         struct g_geom *gp;
  191 
  192         gkd = (struct g_kerneldump*)bp->bio_data;
  193         gp = bp->bio_to->geom;
  194         g_trace(G_T_TOPOLOGY, "g_disk_kernedump(%s, %jd, %jd)",
  195                 gp->name, (intmax_t)gkd->offset, (intmax_t)gkd->length);
  196         if (dp->d_dump == NULL) {
  197                 g_io_deliver(bp, ENODEV);
  198                 return;
  199         }
  200         gkd->di.dumper = dp->d_dump;
  201         gkd->di.priv = dp;
  202         gkd->di.blocksize = dp->d_sectorsize;
  203         gkd->di.maxiosize = dp->d_maxsize;
  204         gkd->di.mediaoffset = gkd->offset;
  205         if ((gkd->offset + gkd->length) > dp->d_mediasize)
  206                 gkd->length = dp->d_mediasize - gkd->offset;
  207         gkd->di.mediasize = gkd->length;
  208         g_io_deliver(bp, 0);
  209 }
  210 
  211 static void
  212 g_disk_setstate(struct bio *bp, struct g_disk_softc *sc)
  213 {
  214         const char *cmd;
  215 
  216         memcpy(&sc->state, bp->bio_data, sizeof(sc->state));
  217         if (sc->led[0] != 0) {
  218                 switch (sc->state) {
  219                 case G_STATE_FAILED:
  220                         cmd = "1";
  221                         break;
  222                 case G_STATE_REBUILD:
  223                         cmd = "f5";
  224                         break;
  225                 case G_STATE_RESYNC:
  226                         cmd = "f1";
  227                         break;
  228                 default:
  229                         cmd = "";
  230                         break;
  231                 }
  232                 led_set(sc->led, cmd);
  233         }
  234         g_io_deliver(bp, 0);
  235 }
  236 
  237 static void
  238 g_disk_done(struct bio *bp)
  239 {
  240         struct bio *bp2;
  241         struct disk *dp;
  242         struct g_disk_softc *sc;
  243 
  244         /* See "notes" for why we need a mutex here */
  245         /* XXX: will witness accept a mix of Giant/unGiant drivers here ? */
  246         mtx_lock(&g_disk_done_mtx);
  247         bp->bio_completed = bp->bio_length - bp->bio_resid;
  248 
  249         bp2 = bp->bio_parent;
  250         if (bp2->bio_error == 0)
  251                 bp2->bio_error = bp->bio_error;
  252         bp2->bio_completed += bp->bio_completed;
  253         if ((bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_DELETE)) &&
  254             (sc = bp2->bio_to->geom->softc) &&
  255             (dp = sc->dp)) {
  256                 devstat_end_transaction_bio(dp->d_devstat, bp);
  257         }
  258         g_destroy_bio(bp);
  259         bp2->bio_inbed++;
  260         if (bp2->bio_children == bp2->bio_inbed) {
  261                 bp2->bio_resid = bp2->bio_bcount - bp2->bio_completed;
  262                 g_io_deliver(bp2, bp2->bio_error);
  263         }
  264         mtx_unlock(&g_disk_done_mtx);
  265 }
  266 
  267 static int
  268 g_disk_ioctl(struct g_provider *pp, u_long cmd, void * data, int fflag, struct thread *td)
  269 {
  270         struct g_geom *gp;
  271         struct disk *dp;
  272         struct g_disk_softc *sc;
  273         int error;
  274 
  275         gp = pp->geom;
  276         sc = gp->softc;
  277         dp = sc->dp;
  278 
  279         if (dp->d_ioctl == NULL)
  280                 return (ENOIOCTL);
  281         g_disk_lock_giant(dp);
  282         error = dp->d_ioctl(dp, cmd, data, fflag, td);
  283         g_disk_unlock_giant(dp);
  284         return(error);
  285 }
  286 
  287 static void
  288 g_disk_start(struct bio *bp)
  289 {
  290         struct bio *bp2, *bp3;
  291         struct disk *dp;
  292         struct g_disk_softc *sc;
  293         int error;
  294         off_t off;
  295 
  296         sc = bp->bio_to->geom->softc;
  297         if (sc == NULL || (dp = sc->dp) == NULL || dp->d_destroyed) {
  298                 g_io_deliver(bp, ENXIO);
  299                 return;
  300         }
  301         error = EJUSTRETURN;
  302         switch(bp->bio_cmd) {
  303         case BIO_DELETE:
  304                 if (!(dp->d_flags & DISKFLAG_CANDELETE)) {
  305                         error = 0;
  306                         break;
  307                 }
  308                 /* fall-through */
  309         case BIO_READ:
  310         case BIO_WRITE:
  311                 off = 0;
  312                 bp3 = NULL;
  313                 bp2 = g_clone_bio(bp);
  314                 if (bp2 == NULL) {
  315                         error = ENOMEM;
  316                         break;
  317                 }
  318                 do {
  319                         bp2->bio_offset += off;
  320                         bp2->bio_length -= off;
  321                         bp2->bio_data += off;
  322                         if (bp2->bio_length > dp->d_maxsize) {
  323                                 /*
  324                                  * XXX: If we have a stripesize we should really
  325                                  * use it here.
  326                                  */
  327                                 bp2->bio_length = dp->d_maxsize;
  328                                 off += dp->d_maxsize;
  329                                 /*
  330                                  * To avoid a race, we need to grab the next bio
  331                                  * before we schedule this one.  See "notes".
  332                                  */
  333                                 bp3 = g_clone_bio(bp);
  334                                 if (bp3 == NULL)
  335                                         bp->bio_error = ENOMEM;
  336                         }
  337                         bp2->bio_done = g_disk_done;
  338                         bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize;
  339                         bp2->bio_bcount = bp2->bio_length;
  340                         bp2->bio_disk = dp;
  341                         devstat_start_transaction_bio(dp->d_devstat, bp2);
  342                         g_disk_lock_giant(dp);
  343                         dp->d_strategy(bp2);
  344                         g_disk_unlock_giant(dp);
  345                         bp2 = bp3;
  346                         bp3 = NULL;
  347                 } while (bp2 != NULL);
  348                 break;
  349         case BIO_GETATTR:
  350                 if (g_handleattr_int(bp, "GEOM::candelete",
  351                     (dp->d_flags & DISKFLAG_CANDELETE) != 0))
  352                         break;
  353                 else if (g_handleattr_int(bp, "GEOM::fwsectors",
  354                     dp->d_fwsectors))
  355                         break;
  356                 else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads))
  357                         break;
  358                 else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0))
  359                         break;
  360                 else if (g_handleattr_str(bp, "GEOM::ident", dp->d_ident))
  361                         break;
  362                 else if (!strcmp(bp->bio_attribute, "GEOM::kerneldump"))
  363                         g_disk_kerneldump(bp, dp);
  364                 else if (!strcmp(bp->bio_attribute, "GEOM::setstate"))
  365                         g_disk_setstate(bp, sc);
  366                 else 
  367                         error = ENOIOCTL;
  368                 break;
  369         case BIO_FLUSH:
  370                 g_trace(G_T_TOPOLOGY, "g_disk_flushcache(%s)",
  371                     bp->bio_to->name);
  372                 if (!(dp->d_flags & DISKFLAG_CANFLUSHCACHE)) {
  373                         g_io_deliver(bp, ENODEV);
  374                         return;
  375                 }
  376                 bp2 = g_clone_bio(bp);
  377                 if (bp2 == NULL) {
  378                         g_io_deliver(bp, ENOMEM);
  379                         return;
  380                 }
  381                 bp2->bio_done = g_disk_done;
  382                 bp2->bio_disk = dp;
  383                 g_disk_lock_giant(dp);
  384                 dp->d_strategy(bp2);
  385                 g_disk_unlock_giant(dp);
  386                 break;
  387         default:
  388                 error = EOPNOTSUPP;
  389                 break;
  390         }
  391         if (error != EJUSTRETURN)
  392                 g_io_deliver(bp, error);
  393         return;
  394 }
  395 
  396 static void
  397 g_disk_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp)
  398 {
  399         struct disk *dp;
  400         struct g_disk_softc *sc;
  401 
  402         sc = gp->softc;
  403         if (sc == NULL || (dp = sc->dp) == NULL)
  404                 return;
  405         if (indent == NULL) {
  406                 sbuf_printf(sb, " hd %u", dp->d_fwheads);
  407                 sbuf_printf(sb, " sc %u", dp->d_fwsectors);
  408                 return;
  409         }
  410         if (pp != NULL) {
  411                 sbuf_printf(sb, "%s<fwheads>%u</fwheads>\n",
  412                     indent, dp->d_fwheads);
  413                 sbuf_printf(sb, "%s<fwsectors>%u</fwsectors>\n",
  414                     indent, dp->d_fwsectors);
  415         }
  416 }
  417 
  418 static void
  419 g_disk_create(void *arg, int flag)
  420 {
  421         struct g_geom *gp;
  422         struct g_provider *pp;
  423         struct disk *dp;
  424         struct g_disk_softc *sc;
  425         char tmpstr[80];
  426 
  427         if (flag == EV_CANCEL)
  428                 return;
  429         g_topology_assert();
  430         dp = arg;
  431         sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
  432         sc->dp = dp;
  433         gp = g_new_geomf(&g_disk_class, "%s%d", dp->d_name, dp->d_unit);
  434         gp->softc = sc;
  435         pp = g_new_providerf(gp, "%s", gp->name);
  436         pp->mediasize = dp->d_mediasize;
  437         pp->sectorsize = dp->d_sectorsize;
  438         if (dp->d_flags & DISKFLAG_CANDELETE)
  439                 pp->flags |= G_PF_CANDELETE;
  440         pp->stripeoffset = dp->d_stripeoffset;
  441         pp->stripesize = dp->d_stripesize;
  442         if (bootverbose)
  443                 printf("GEOM: new disk %s\n", gp->name);
  444         sysctl_ctx_init(&sc->sysctl_ctx);
  445         snprintf(tmpstr, sizeof(tmpstr), "GEOM disk %s", gp->name);
  446         sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
  447                 SYSCTL_STATIC_CHILDREN(_kern_geom_disk), OID_AUTO, gp->name,
  448                 CTLFLAG_RD, 0, tmpstr);
  449         if (sc->sysctl_tree != NULL) {
  450                 snprintf(tmpstr, sizeof(tmpstr),
  451                     "kern.geom.disk.%s.led", gp->name);
  452                 TUNABLE_STR_FETCH(tmpstr, sc->led, sizeof(sc->led));
  453                 SYSCTL_ADD_STRING(&sc->sysctl_ctx,
  454                     SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO, "led",
  455                     CTLFLAG_RW | CTLFLAG_TUN, sc->led, sizeof(sc->led),
  456                     "LED name");
  457         }
  458         pp->private = sc;
  459         dp->d_geom = gp;
  460         g_error_provider(pp, 0);
  461 }
  462 
  463 static void
  464 g_disk_destroy(void *ptr, int flag)
  465 {
  466         struct disk *dp;
  467         struct g_geom *gp;
  468         struct g_disk_softc *sc;
  469 
  470         g_topology_assert();
  471         dp = ptr;
  472         gp = dp->d_geom;
  473         if (gp != NULL) {
  474                 sc = gp->softc;
  475                 if (sc->sysctl_tree != NULL) {
  476                         sysctl_ctx_free(&sc->sysctl_ctx);
  477                         sc->sysctl_tree = NULL;
  478                 }
  479                 if (sc->led[0] != 0) {
  480                         led_set(sc->led, "");
  481                         sc->led[0] = 0;
  482                 }
  483                 g_free(sc);
  484                 gp->softc = NULL;
  485                 g_wither_geom(gp, ENXIO);
  486         }
  487         g_free(dp);
  488 }
  489 
  490 /*
  491  * We only allow printable characters in disk ident,
  492  * the rest is converted to 'x<HH>'.
  493  */
  494 static void
  495 g_disk_ident_adjust(char *ident, size_t size)
  496 {
  497         char *p, tmp[4], newid[DISK_IDENT_SIZE];
  498 
  499         newid[0] = '\0';
  500         for (p = ident; *p != '\0'; p++) {
  501                 if (isprint(*p)) {
  502                         tmp[0] = *p;
  503                         tmp[1] = '\0';
  504                 } else {
  505                         snprintf(tmp, sizeof(tmp), "x%02hhx",
  506                             *(unsigned char *)p);
  507                 }
  508                 if (strlcat(newid, tmp, sizeof(newid)) >= sizeof(newid))
  509                         break;
  510         }
  511         bzero(ident, size);
  512         strlcpy(ident, newid, size);
  513 }
  514 
  515 struct disk *
  516 disk_alloc()
  517 {
  518         struct disk *dp;
  519 
  520         dp = g_malloc(sizeof *dp, M_WAITOK | M_ZERO);
  521         return (dp);
  522 }
  523 
  524 void
  525 disk_create(struct disk *dp, int version)
  526 {
  527         if (version != DISK_VERSION_00 && version != DISK_VERSION_01) {
  528                 printf("WARNING: Attempt to add disk %s%d %s",
  529                     dp->d_name, dp->d_unit,
  530                     " using incompatible ABI version of disk(9)\n");
  531                 printf("WARNING: Ignoring disk %s%d\n",
  532                     dp->d_name, dp->d_unit);
  533                 return;
  534         }
  535         KASSERT(dp->d_strategy != NULL, ("disk_create need d_strategy"));
  536         KASSERT(dp->d_name != NULL, ("disk_create need d_name"));
  537         KASSERT(*dp->d_name != 0, ("disk_create need d_name"));
  538         KASSERT(strlen(dp->d_name) < SPECNAMELEN - 4, ("disk name too long"));
  539         if (dp->d_devstat == NULL)
  540                 dp->d_devstat = devstat_new_entry(dp->d_name, dp->d_unit,
  541                     dp->d_sectorsize, DEVSTAT_ALL_SUPPORTED,
  542                     DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX);
  543         dp->d_geom = NULL;
  544         g_disk_ident_adjust(dp->d_ident, sizeof(dp->d_ident));
  545         g_post_event(g_disk_create, dp, M_WAITOK, dp, NULL);
  546 }
  547 
  548 void
  549 disk_destroy(struct disk *dp)
  550 {
  551 
  552         g_cancel_event(dp);
  553         dp->d_destroyed = 1;
  554         if (dp->d_devstat != NULL)
  555                 devstat_remove_entry(dp->d_devstat);
  556         g_post_event(g_disk_destroy, dp, M_WAITOK, NULL);
  557 }
  558 
  559 void
  560 disk_gone(struct disk *dp)
  561 {
  562         struct g_geom *gp;
  563         struct g_provider *pp;
  564 
  565         gp = dp->d_geom;
  566         if (gp != NULL)
  567                 LIST_FOREACH(pp, &gp->provider, provider)
  568                         g_wither_provider(pp, ENXIO);
  569 }
  570 
  571 static void
  572 g_kern_disks(void *p, int flag __unused)
  573 {
  574         struct sbuf *sb;
  575         struct g_geom *gp;
  576         char *sp;
  577 
  578         sb = p;
  579         sp = "";
  580         g_topology_assert();
  581         LIST_FOREACH(gp, &g_disk_class.geom, geom) {
  582                 sbuf_printf(sb, "%s%s", sp, gp->name);
  583                 sp = " ";
  584         }
  585         sbuf_finish(sb);
  586 }
  587 
  588 static int
  589 sysctl_disks(SYSCTL_HANDLER_ARGS)
  590 {
  591         int error;
  592         struct sbuf *sb;
  593 
  594         sb = sbuf_new_auto();
  595         g_waitfor_event(g_kern_disks, sb, M_WAITOK, NULL);
  596         error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1);
  597         sbuf_delete(sb);
  598         return error;
  599 }
  600  
  601 SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NOLOCK, 0, 0, 
  602     sysctl_disks, "A", "names of available disks");
  603 

Cache object: 7a53704d812f894898f00d170a2eb302


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.