2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2002 Poul-Henning Kamp
5 * Copyright (c) 2002 Networks Associates Technology, Inc.
8 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
9 * and NAI Labs, the Security Research Division of Network Associates, Inc.
10 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
11 * DARPA CHATS research program.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. The names of the authors may not be used to endorse or promote
22 * products derived from this software without specific prior written
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/malloc.h>
41 #include <sys/kernel.h>
43 #include <sys/ctype.h>
45 #include <sys/devctl.h>
47 #include <sys/mutex.h>
49 #include <sys/errno.h>
52 #include <sys/fcntl.h>
53 #include <sys/limits.h>
54 #include <sys/selinfo.h>
55 #include <sys/sysctl.h>
56 #include <geom/geom.h>
57 #include <geom/geom_int.h>
58 #include <machine/stdarg.h>
63 struct cdev *sc_alias;
66 struct selinfo sc_selinfo;
67 #define SC_A_DESTROY (1 << 31)
68 #define SC_A_OPEN (1 << 30)
69 #define SC_A_ACTIVE (SC_A_OPEN - 1)
72 static d_open_t g_dev_open;
73 static d_close_t g_dev_close;
74 static d_strategy_t g_dev_strategy;
75 static d_ioctl_t g_dev_ioctl;
76 static d_kqfilter_t g_dev_kqfilter;
78 static void gdev_filter_detach(struct knote *kn);
79 static int gdev_filter_vnode(struct knote *kn, long hint);
81 static struct filterops gdev_filterops_vnode = {
83 .f_detach = gdev_filter_detach,
84 .f_event = gdev_filter_vnode,
87 static struct cdevsw g_dev_cdevsw = {
88 .d_version = D_VERSION,
90 .d_close = g_dev_close,
93 .d_ioctl = g_dev_ioctl,
94 .d_strategy = g_dev_strategy,
96 .d_flags = D_DISK | D_TRACKCLOSE,
97 .d_kqfilter = g_dev_kqfilter,
100 static g_init_t g_dev_init;
101 static g_fini_t g_dev_fini;
102 static g_taste_t g_dev_taste;
103 static g_orphan_t g_dev_orphan;
104 static g_attrchanged_t g_dev_attrchanged;
105 static g_resize_t g_dev_resize;
107 static struct g_class g_dev_class = {
109 .version = G_VERSION,
112 .taste = g_dev_taste,
113 .orphan = g_dev_orphan,
114 .attrchanged = g_dev_attrchanged,
115 .resize = g_dev_resize
119 * We target 262144 (8 x 32768) sectors by default as this significantly
120 * increases the throughput on commonly used SSD's with a marginal
121 * increase in non-interruptible request latency.
123 static uint64_t g_dev_del_max_sectors = 262144;
124 SYSCTL_DECL(_kern_geom);
125 SYSCTL_NODE(_kern_geom, OID_AUTO, dev, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
127 SYSCTL_QUAD(_kern_geom_dev, OID_AUTO, delete_max_sectors, CTLFLAG_RW,
128 &g_dev_del_max_sectors, 0, "Maximum number of sectors in a single "
129 "delete request sent to the provider. Larger requests are chunked "
130 "so they can be interrupted. (0 = disable chunking)");
132 static char *dumpdev = NULL;
134 g_dev_init(struct g_class *mp)
137 dumpdev = kern_getenv("dumpdev");
141 g_dev_fini(struct g_class *mp)
149 g_dev_setdumpdev(struct cdev *dev, struct diocskerneldump_arg *kda)
151 struct g_kerneldump kd;
152 struct g_consumer *cp;
155 MPASS(dev != NULL && kda != NULL);
156 MPASS(kda->kda_index != KDA_REMOVE);
163 error = g_io_getattr("GEOM::kerneldump", cp, &len, &kd);
167 error = dumper_insert(&kd.di, devtoname(dev), kda);
169 dev->si_flags |= SI_DUMPDEV;
175 init_dumpdev(struct cdev *dev)
177 struct diocskerneldump_arg kda;
178 struct g_consumer *cp;
179 const char *devprefix = _PATH_DEV, *devname;
183 bzero(&kda, sizeof(kda));
184 kda.kda_index = KDA_APPEND;
189 len = strlen(devprefix);
190 devname = devtoname(dev);
191 if (strcmp(devname, dumpdev) != 0 &&
192 (strncmp(dumpdev, devprefix, len) != 0 ||
193 strcmp(devname, dumpdev + len) != 0))
196 cp = (struct g_consumer *)dev->si_drv2;
197 error = g_access(cp, 1, 0, 0);
201 error = g_dev_setdumpdev(dev, &kda);
207 (void)g_access(cp, -1, 0, 0);
213 g_dev_destroy(void *arg, int flags __unused)
215 struct g_consumer *cp;
217 struct g_dev_softc *sc;
218 char buf[SPECNAMELEN + 6];
224 g_trace(G_T_TOPOLOGY, "g_dev_destroy(%p(%s))", cp, gp->name);
225 snprintf(buf, sizeof(buf), "cdev=%s", gp->name);
226 devctl_notify("GEOM", "DEV", "DESTROY", buf);
227 knlist_clear(&sc->sc_selinfo.si_note, 0);
228 knlist_destroy(&sc->sc_selinfo.si_note);
229 if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0)
230 g_access(cp, -cp->acr, -cp->acw, -cp->ace);
232 g_destroy_consumer(cp);
234 mtx_destroy(&sc->sc_mtx);
244 LIST_FOREACH(gp, &g_dev_class.geom, geom) {
245 printf("%s%s", p, gp->name);
252 g_dev_set_physpath(struct g_consumer *cp)
254 struct g_dev_softc *sc;
256 int error, physpath_len;
258 if (g_access(cp, 1, 0, 0) != 0)
262 physpath_len = MAXPATHLEN;
263 physpath = g_malloc(physpath_len, M_WAITOK|M_ZERO);
264 error = g_io_getattr("GEOM::physpath", cp, &physpath_len, physpath);
265 g_access(cp, -1, 0, 0);
266 if (error == 0 && strlen(physpath) != 0) {
267 struct cdev *dev, *old_alias_dev;
268 struct cdev **alias_devp;
271 old_alias_dev = sc->sc_alias;
272 alias_devp = (struct cdev **)&sc->sc_alias;
273 make_dev_physpath_alias(MAKEDEV_WAITOK | MAKEDEV_CHECKNAME,
274 alias_devp, dev, old_alias_dev, physpath);
275 } else if (sc->sc_alias) {
276 destroy_dev((struct cdev *)sc->sc_alias);
283 g_dev_set_media(struct g_consumer *cp)
285 struct g_dev_softc *sc;
287 char buf[SPECNAMELEN + 6];
291 snprintf(buf, sizeof(buf), "cdev=%s", dev->si_name);
292 devctl_notify("DEVFS", "CDEV", "MEDIACHANGE", buf);
293 devctl_notify("GEOM", "DEV", "MEDIACHANGE", buf);
296 snprintf(buf, sizeof(buf), "cdev=%s", dev->si_name);
297 devctl_notify("DEVFS", "CDEV", "MEDIACHANGE", buf);
298 devctl_notify("GEOM", "DEV", "MEDIACHANGE", buf);
303 g_dev_attrchanged(struct g_consumer *cp, const char *attr)
306 if (strcmp(attr, "GEOM::media") == 0) {
311 if (strcmp(attr, "GEOM::physpath") == 0) {
312 g_dev_set_physpath(cp);
318 g_dev_resize(struct g_consumer *cp)
320 struct g_dev_softc *sc;
321 char buf[SPECNAMELEN + 6];
324 KNOTE_UNLOCKED(&sc->sc_selinfo.si_note, NOTE_ATTRIB);
326 snprintf(buf, sizeof(buf), "cdev=%s", cp->provider->name);
327 devctl_notify("GEOM", "DEV", "SIZECHANGE", buf);
331 g_dev_getprovider(struct cdev *dev)
333 struct g_consumer *cp;
338 if (dev->si_devsw != &g_dev_cdevsw)
341 return (cp->provider);
344 static struct g_geom *
345 g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
348 struct g_geom_alias *gap;
349 struct g_consumer *cp;
350 struct g_dev_softc *sc;
352 struct cdev *dev, *adev;
353 char buf[SPECNAMELEN + 6];
354 struct make_dev_args args;
356 g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name);
358 gp = g_new_geomf(mp, "%s", pp->name);
359 sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
360 mtx_init(&sc->sc_mtx, "g_dev", NULL, MTX_DEF);
361 cp = g_new_consumer(gp);
363 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
364 error = g_attach(cp, pp);
366 printf("%s: g_dev_taste(%s) failed to g_attach, error=%d\n",
367 __func__, pp->name, error);
368 g_destroy_consumer(cp);
370 mtx_destroy(&sc->sc_mtx);
374 make_dev_args_init(&args);
375 args.mda_flags = MAKEDEV_CHECKNAME | MAKEDEV_WAITOK;
376 args.mda_devsw = &g_dev_cdevsw;
378 args.mda_uid = UID_ROOT;
379 args.mda_gid = GID_OPERATOR;
380 args.mda_mode = 0640;
381 args.mda_si_drv1 = sc;
382 args.mda_si_drv2 = cp;
383 error = make_dev_s(&args, &sc->sc_dev, "%s", gp->name);
385 printf("%s: make_dev_p() failed (gp->name=%s, error=%d)\n",
386 __func__, gp->name, error);
388 g_destroy_consumer(cp);
390 mtx_destroy(&sc->sc_mtx);
395 dev->si_flags |= SI_UNMAPPED;
396 dev->si_iosize_max = maxphys;
397 knlist_init_mtx(&sc->sc_selinfo.si_note, &sc->sc_mtx);
398 error = init_dumpdev(dev);
400 printf("%s: init_dumpdev() failed (gp->name=%s, error=%d)\n",
401 __func__, gp->name, error);
403 g_dev_attrchanged(cp, "GEOM::physpath");
404 snprintf(buf, sizeof(buf), "cdev=%s", gp->name);
405 devctl_notify("GEOM", "DEV", "CREATE", buf);
407 * Now add all the aliases for this drive
409 LIST_FOREACH(gap, &pp->aliases, ga_next) {
410 error = make_dev_alias_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK, &adev, dev,
411 "%s", gap->ga_alias);
413 printf("%s: make_dev_alias_p() failed (name=%s, error=%d)\n",
414 __func__, gap->ga_alias, error);
417 snprintf(buf, sizeof(buf), "cdev=%s", gap->ga_alias);
418 devctl_notify("GEOM", "DEV", "CREATE", buf);
425 g_dev_open(struct cdev *dev, int flags, int fmt, struct thread *td)
427 struct g_consumer *cp;
428 struct g_dev_softc *sc;
432 g_trace(G_T_ACCESS, "g_dev_open(%s, %d, %d, %p)",
433 cp->geom->name, flags, fmt, td);
435 r = flags & FREAD ? 1 : 0;
436 w = flags & FWRITE ? 1 : 0;
438 e = flags & O_EXCL ? 1 : 0;
444 * This happens on attempt to open a device node with O_EXEC.
451 * When running in very secure mode, do not allow
452 * opens for writing of any disks.
454 error = securelevel_ge(td->td_ucred, 2);
459 error = g_access(cp, r, w, e);
463 mtx_lock(&sc->sc_mtx);
464 if (sc->sc_open == 0 && (sc->sc_active & SC_A_ACTIVE) != 0)
465 wakeup(&sc->sc_active);
466 sc->sc_open += r + w + e;
467 if (sc->sc_open == 0)
468 atomic_clear_int(&sc->sc_active, SC_A_OPEN);
470 atomic_set_int(&sc->sc_active, SC_A_OPEN);
471 KNOTE_LOCKED(&sc->sc_selinfo.si_note, NOTE_OPEN);
472 mtx_unlock(&sc->sc_mtx);
478 g_dev_close(struct cdev *dev, int flags, int fmt, struct thread *td)
480 struct g_consumer *cp;
481 struct g_dev_softc *sc;
485 g_trace(G_T_ACCESS, "g_dev_close(%s, %d, %d, %p)",
486 cp->geom->name, flags, fmt, td);
488 r = flags & FREAD ? -1 : 0;
489 w = flags & FWRITE ? -1 : 0;
491 e = flags & O_EXCL ? -1 : 0;
497 * The vgonel(9) - caused by eg. forced unmount of devfs - calls
498 * VOP_CLOSE(9) on devfs vnode without any FREAD or FWRITE flags,
499 * which would result in zero deltas, which in turn would cause
500 * panic in g_access(9).
502 * Note that we cannot zero the counters (ie. do "r = cp->acr"
503 * etc) instead, because the consumer might be opened in another
510 mtx_lock(&sc->sc_mtx);
511 sc->sc_open += r + w + e;
512 if (sc->sc_open == 0)
513 atomic_clear_int(&sc->sc_active, SC_A_OPEN);
515 atomic_set_int(&sc->sc_active, SC_A_OPEN);
516 while (sc->sc_open == 0 && (sc->sc_active & SC_A_ACTIVE) != 0)
517 msleep(&sc->sc_active, &sc->sc_mtx, 0, "g_dev_close", hz / 10);
518 KNOTE_LOCKED(&sc->sc_selinfo.si_note, NOTE_CLOSE | (w ? NOTE_CLOSE_WRITE : 0));
519 mtx_unlock(&sc->sc_mtx);
521 error = g_access(cp, r, w, e);
527 g_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
529 struct g_consumer *cp;
530 struct g_provider *pp;
531 off_t offset, length, chunk, odd;
537 /* If consumer or provider is dying, don't disturb. */
538 if (cp->flags & G_CF_ORPHAN)
544 KASSERT(cp->acr || cp->acw,
545 ("Consumer with zero access count in g_dev_ioctl"));
547 i = IOCPARM_LEN(cmd);
549 case DIOCGSECTORSIZE:
550 *(u_int *)data = pp->sectorsize;
551 if (*(u_int *)data == 0)
555 *(off_t *)data = pp->mediasize;
556 if (*(off_t *)data == 0)
560 error = g_io_getattr("GEOM::fwsectors", cp, &i, data);
561 if (error == 0 && *(u_int *)data == 0)
565 error = g_io_getattr("GEOM::fwheads", cp, &i, data);
566 if (error == 0 && *(u_int *)data == 0)
569 case DIOCSKERNELDUMP:
571 struct diocskerneldump_arg *kda;
572 uint8_t *encryptedkey;
574 kda = (struct diocskerneldump_arg *)data;
575 if (kda->kda_index == KDA_REMOVE_ALL ||
576 kda->kda_index == KDA_REMOVE_DEV ||
577 kda->kda_index == KDA_REMOVE) {
578 error = dumper_remove(devtoname(dev), kda);
579 explicit_bzero(kda, sizeof(*kda));
583 if (kda->kda_encryption != KERNELDUMP_ENC_NONE) {
584 if (kda->kda_encryptedkeysize == 0 ||
585 kda->kda_encryptedkeysize >
586 KERNELDUMP_ENCKEY_MAX_SIZE) {
587 explicit_bzero(kda, sizeof(*kda));
590 encryptedkey = malloc(kda->kda_encryptedkeysize, M_TEMP,
592 error = copyin(kda->kda_encryptedkey, encryptedkey,
593 kda->kda_encryptedkeysize);
598 kda->kda_encryptedkey = encryptedkey;
599 error = g_dev_setdumpdev(dev, kda);
601 zfree(encryptedkey, M_TEMP);
602 explicit_bzero(kda, sizeof(*kda));
606 error = g_io_flush(cp);
609 offset = ((off_t *)data)[0];
610 length = ((off_t *)data)[1];
611 if ((offset % pp->sectorsize) != 0 ||
612 (length % pp->sectorsize) != 0 || length <= 0) {
613 printf("%s: offset=%jd length=%jd\n", __func__, offset,
620 if (g_dev_del_max_sectors != 0 &&
621 chunk > g_dev_del_max_sectors * pp->sectorsize) {
622 chunk = g_dev_del_max_sectors * pp->sectorsize;
623 if (pp->stripesize > 0) {
624 odd = (offset + chunk +
625 pp->stripeoffset) % pp->stripesize;
630 error = g_delete_data(cp, offset, chunk);
636 * Since the request size can be large, the service
637 * time can be is likewise. We make this ioctl
638 * interruptible by checking for signals for each bio.
645 error = g_io_getattr("GEOM::ident", cp, &i, data);
647 case DIOCGPROVIDERNAME:
648 strlcpy(data, pp->name, i);
650 case DIOCGSTRIPESIZE:
651 *(off_t *)data = pp->stripesize;
653 case DIOCGSTRIPEOFFSET:
654 *(off_t *)data = pp->stripeoffset;
657 error = g_io_getattr("GEOM::physpath", cp, &i, data);
658 if (error == 0 && *(char *)data == '\0')
662 struct diocgattr_arg *arg = (struct diocgattr_arg *)data;
664 if (arg->len > sizeof(arg->value)) {
668 error = g_io_getattr(arg->name, cp, &arg->len, &arg->value);
672 struct disk_zone_args *zone_args =(struct disk_zone_args *)data;
673 struct disk_zone_rep_entry *new_entries, *old_entries;
674 struct disk_zone_report *rep;
682 if (zone_args->zone_cmd == DISK_ZONE_REPORT_ZONES) {
683 rep = &zone_args->zone_params.report;
684 #define MAXENTRIES (maxphys / sizeof(struct disk_zone_rep_entry))
685 if (rep->entries_allocated > MAXENTRIES)
686 rep->entries_allocated = MAXENTRIES;
687 alloc_size = rep->entries_allocated *
688 sizeof(struct disk_zone_rep_entry);
690 new_entries = g_malloc(alloc_size,
692 old_entries = rep->entries;
693 rep->entries = new_entries;
695 error = g_io_zonecmd(zone_args, cp);
696 if (zone_args->zone_cmd == DISK_ZONE_REPORT_ZONES &&
697 alloc_size != 0 && error == 0)
698 error = copyout(new_entries, old_entries, alloc_size);
699 if (old_entries != NULL && rep != NULL)
700 rep->entries = old_entries;
705 if (pp->geom->ioctl != NULL) {
706 error = pp->geom->ioctl(pp, cmd, data, fflag, td);
716 g_dev_done(struct bio *bp2)
718 struct g_consumer *cp;
719 struct g_dev_softc *sc;
725 bp = bp2->bio_parent;
726 bp->bio_error = bp2->bio_error;
727 bp->bio_completed = bp2->bio_completed;
728 bp->bio_resid = bp->bio_length - bp2->bio_completed;
729 if (bp2->bio_cmd == BIO_ZONE)
730 bcopy(&bp2->bio_zone, &bp->bio_zone, sizeof(bp->bio_zone));
732 if (bp2->bio_error != 0) {
733 g_trace(G_T_BIO, "g_dev_done(%p) had error %d",
734 bp2, bp2->bio_error);
735 bp->bio_flags |= BIO_ERROR;
737 if (bp->bio_cmd == BIO_READ)
738 KNOTE_UNLOCKED(&sc->sc_selinfo.si_note, NOTE_READ);
739 if (bp->bio_cmd == BIO_WRITE)
740 KNOTE_UNLOCKED(&sc->sc_selinfo.si_note, NOTE_WRITE);
741 g_trace(G_T_BIO, "g_dev_done(%p/%p) resid %ld completed %jd",
742 bp2, bp, bp2->bio_resid, (intmax_t)bp2->bio_completed);
745 active = atomic_fetchadd_int(&sc->sc_active, -1) - 1;
746 if ((active & SC_A_ACTIVE) == 0) {
747 if ((active & SC_A_OPEN) == 0)
748 wakeup(&sc->sc_active);
749 if (active & SC_A_DESTROY)
750 g_post_event(g_dev_destroy, cp, M_NOWAIT, NULL);
756 g_dev_strategy(struct bio *bp)
758 struct g_consumer *cp;
761 struct g_dev_softc *sc;
763 KASSERT(bp->bio_cmd == BIO_READ ||
764 bp->bio_cmd == BIO_WRITE ||
765 bp->bio_cmd == BIO_DELETE ||
766 bp->bio_cmd == BIO_FLUSH ||
767 bp->bio_cmd == BIO_ZONE,
768 ("Wrong bio_cmd bio=%p cmd=%d", bp, bp->bio_cmd));
771 KASSERT(cp->acr || cp->acw,
772 ("Consumer with zero access count in g_dev_strategy"));
773 biotrack(bp, __func__);
775 if ((bp->bio_offset % cp->provider->sectorsize) != 0 ||
776 (bp->bio_bcount % cp->provider->sectorsize) != 0) {
777 bp->bio_resid = bp->bio_bcount;
778 biofinish(bp, NULL, EINVAL);
783 KASSERT(sc->sc_open > 0, ("Closed device in g_dev_strategy"));
784 atomic_add_int(&sc->sc_active, 1);
788 * XXX: This is not an ideal solution, but I believe it to
789 * XXX: deadlock safely, all things considered.
791 bp2 = g_clone_bio(bp);
794 pause("gdstrat", hz / 10);
796 KASSERT(bp2 != NULL, ("XXX: ENOMEM in a bad place"));
797 bp2->bio_done = g_dev_done;
799 "g_dev_strategy(%p/%p) offset %jd length %jd data %p cmd %d",
800 bp, bp2, (intmax_t)bp->bio_offset, (intmax_t)bp2->bio_length,
801 bp2->bio_data, bp2->bio_cmd);
802 g_io_request(bp2, cp);
803 KASSERT(cp->acr || cp->acw,
804 ("g_dev_strategy raced with g_dev_close and lost"));
811 * Called by devfs when asynchronous device destruction is completed.
812 * - Mark that we have no attached device any more.
813 * - If there are no outstanding requests, schedule geom destruction.
814 * Otherwise destruction will be scheduled later by g_dev_done().
818 g_dev_callback(void *arg)
820 struct g_consumer *cp;
821 struct g_dev_softc *sc;
826 g_trace(G_T_TOPOLOGY, "g_dev_callback(%p(%s))", cp, cp->geom->name);
830 active = atomic_fetchadd_int(&sc->sc_active, SC_A_DESTROY);
831 if ((active & SC_A_ACTIVE) == 0)
832 g_post_event(g_dev_destroy, cp, M_WAITOK, NULL);
838 * Called from below when the provider orphaned us.
839 * - Clear any dump settings.
840 * - Request asynchronous device destruction to prevent any more requests
841 * from coming in. The provider is already marked with an error, so
842 * anything which comes in the interim will be returned immediately.
846 g_dev_orphan(struct g_consumer *cp)
849 struct g_dev_softc *sc;
854 g_trace(G_T_TOPOLOGY, "g_dev_orphan(%p(%s))", cp, cp->geom->name);
856 /* Reset any dump-area set on this device */
857 if (dev->si_flags & SI_DUMPDEV) {
858 struct diocskerneldump_arg kda;
860 bzero(&kda, sizeof(kda));
861 kda.kda_index = KDA_REMOVE_DEV;
862 (void)dumper_remove(devtoname(dev), &kda);
865 /* Destroy the struct cdev *so we get no more requests */
867 destroy_dev_sched_cb(dev, g_dev_callback, cp);
871 gdev_filter_detach(struct knote *kn)
873 struct g_dev_softc *sc;
877 knlist_remove(&sc->sc_selinfo.si_note, kn, 0);
881 gdev_filter_vnode(struct knote *kn, long hint)
883 kn->kn_fflags |= kn->kn_sfflags & hint;
885 return (kn->kn_fflags != 0);
889 g_dev_kqfilter(struct cdev *dev, struct knote *kn)
891 struct g_dev_softc *sc;
895 if (kn->kn_filter != EVFILT_VNODE)
898 #define SUPPORTED_EVENTS (NOTE_ATTRIB | NOTE_OPEN | NOTE_CLOSE | \
899 NOTE_CLOSE_WRITE | NOTE_READ | NOTE_WRITE)
900 if (kn->kn_sfflags & ~SUPPORTED_EVENTS)
903 kn->kn_fop = &gdev_filterops_vnode;
905 knlist_add(&sc->sc_selinfo.si_note, kn, 0);
910 DECLARE_GEOM_CLASS(g_dev_class, g_dev);