/* * iscsiattach: * Only called when statically configured into a kernel */ void iscsiattach(int n) { int err; cfdata_t cf; err = config_cfattach_attach(iscsi_cd.cd_name, &iscsi_ca); if (err) { aprint_error("%s: couldn't register cfattach: %d\n", iscsi_cd.cd_name, err); config_cfdriver_detach(&iscsi_cd); return; } if (n > 1) aprint_error("%s: only one device supported\n", iscsi_cd.cd_name); cf = kmem_alloc(sizeof(struct cfdata), KM_NOSLEEP); if (cf == NULL) { aprint_error("%s: couldn't allocate cfdata\n", iscsi_cd.cd_name); return; } cf->cf_name = iscsi_cd.cd_name; cf->cf_atname = iscsi_cd.cd_name; cf->cf_unit = 0; cf->cf_fstate = FSTATE_NOTFOUND; (void)config_attach_pseudo(cf); return; }
int fss_open(dev_t dev, int flags, int mode, struct lwp *l) { int mflag; cfdata_t cf; struct fss_softc *sc; mflag = (mode == S_IFCHR ? FSS_CDEV_OPEN : FSS_BDEV_OPEN); mutex_enter(&fss_device_lock); sc = device_lookup_private(&fss_cd, minor(dev)); if (sc == NULL) { cf = malloc(sizeof(*cf), M_DEVBUF, M_WAITOK); cf->cf_name = fss_cd.cd_name; cf->cf_atname = fss_cd.cd_name; cf->cf_unit = minor(dev); cf->cf_fstate = FSTATE_STAR; sc = device_private(config_attach_pseudo(cf)); if (sc == NULL) { mutex_exit(&fss_device_lock); return ENOMEM; } } mutex_enter(&sc->sc_slock); sc->sc_flags |= mflag; mutex_exit(&sc->sc_slock); mutex_exit(&fss_device_lock); return 0; }
/* * This is called if we are configured as a pseudo-device */ void mdattach(int n) { int i; cfdata_t cf; if (config_cfattach_attach("md", &md_ca)) { printf("md: cfattach_attach failed\n"); return; } /* XXX: Are we supposed to provide a default? */ if (n <= 1) n = 1; /* Attach as if by autoconfig. */ for (i = 0; i < n; i++) { cf = malloc(sizeof(*cf), M_DEVBUF, M_WAITOK); cf->cf_name = "md"; cf->cf_atname = "md"; cf->cf_unit = i; cf->cf_fstate = FSTATE_NOTFOUND; (void)config_attach_pseudo(cf); } }
static struct cgd_softc * cgd_spawn(int unit) { cfdata_t cf; cf = malloc(sizeof(*cf), M_DEVBUF, M_WAITOK); cf->cf_name = cgd_cd.cd_name; cf->cf_atname = cgd_cd.cd_name; cf->cf_unit = unit; cf->cf_fstate = FSTATE_STAR; return device_private(config_attach_pseudo(cf)); }
/* * tap(4) can be cloned by two ways: * using 'ifconfig tap0 create', which will use the network * interface cloning API, and call tap_clone_create above. * opening the cloning device node, whose minor number is TAP_CLONER. * See below for an explanation on how this part work. */ static struct tap_softc * tap_clone_creator(int unit) { struct cfdata *cf; cf = malloc(sizeof(*cf), M_DEVBUF, M_WAITOK); cf->cf_name = tap_cd.cd_name; cf->cf_atname = tap_ca.ca_name; if (unit == -1) { /* let autoconf find the first free one */ cf->cf_unit = 0; cf->cf_fstate = FSTATE_STAR; } else { cf->cf_unit = unit; cf->cf_fstate = FSTATE_NOTFOUND; } return device_private(config_attach_pseudo(cf)); }
void cpu_rootconf(void) { findroot(); #if defined(MEMORY_DISK_HOOKS) /* * XXX * quick hacks for atari's traditional "auto-load from floppy on open" * installation md(4) ramdisk. * See sys/arch/atari/dev/md_root.c for details. */ #define RAMD_NDEV 3 /* XXX */ if ((boothowto & RB_ASKNAME) != 0) { int md_major, i; cfdata_t cf; struct md_softc *sc; md_major = devsw_name2blk("md", NULL, 0); if (md_major >= 0) { for (i = 0; i < RAMD_NDEV; i++) { cf = malloc(sizeof(*cf), M_DEVBUF, M_ZERO|M_WAITOK); if (cf == NULL) break; /* XXX */ cf->cf_name = md_cd.cd_name; cf->cf_atname = md_cd.cd_name; cf->cf_unit = i; cf->cf_fstate = FSTATE_STAR; /* XXX mutex */ sc = device_private(config_attach_pseudo(cf)); if (sc == NULL) break; /* XXX */ } } } #endif rootconf(); }
static int iscsi_modcmd(modcmd_t cmd, void *arg) { #ifdef _MODULE devmajor_t cmajor = NODEVMAJOR, bmajor = NODEVMAJOR; int error; #endif switch (cmd) { case MODULE_CMD_INIT: #ifdef _MODULE error = config_cfdriver_attach(&iscsi_cd); if (error) { return error; } error = config_cfattach_attach(iscsi_cd.cd_name, &iscsi_ca); if (error) { config_cfdriver_detach(&iscsi_cd); aprint_error("%s: unable to register cfattach\n", iscsi_cd.cd_name); return error; } error = config_cfdata_attach(iscsi_cfdata, 1); if (error) { aprint_error("%s: unable to attach cfdata\n", iscsi_cd.cd_name); config_cfattach_detach(iscsi_cd.cd_name, &iscsi_ca); config_cfdriver_detach(&iscsi_cd); return error; } error = devsw_attach(iscsi_cd.cd_name, NULL, &bmajor, &iscsi_cdevsw, &cmajor); if (error) { aprint_error("%s: unable to register devsw\n", iscsi_cd.cd_name); config_cfdata_detach(iscsi_cfdata); config_cfattach_detach(iscsi_cd.cd_name, &iscsi_ca); config_cfdriver_detach(&iscsi_cd); return error; } if (config_attach_pseudo(iscsi_cfdata) == NULL) { aprint_error("%s: config_attach_pseudo failed\n", iscsi_cd.cd_name); config_cfattach_detach(iscsi_cd.cd_name, &iscsi_ca); config_cfdriver_detach(&iscsi_cd); return ENXIO; } #endif return 0; break; case MODULE_CMD_FINI: #ifdef _MODULE error = config_cfdata_detach(iscsi_cfdata); if (error) return error; config_cfattach_detach(iscsi_cd.cd_name, &iscsi_ca); config_cfdriver_detach(&iscsi_cd); devsw_detach(NULL, &iscsi_cdevsw); #endif return 0; break; case MODULE_CMD_AUTOUNLOAD: return EBUSY; break; default: return ENOTTY; break; } }
/* * Create in-kernel entry for device. Device attributes such as name, uuid are * taken from proplib dictionary. * */ int dm_dev_create_ioctl(prop_dictionary_t dm_dict) { dm_dev_t *dmv; const char *name, *uuid; int r, flags; device_t devt; r = 0; flags = 0; name = NULL; uuid = NULL; /* Get needed values from dictionary. */ prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name); prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid); prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags); dm_dbg_print_flags(flags); /* Lookup name and uuid if device already exist quit. */ if ((dmv = dm_dev_lookup(name, uuid, -1)) != NULL) { DM_ADD_FLAG(flags, DM_EXISTS_FLAG); /* Device already exists */ dm_dev_unbusy(dmv); return EEXIST; } if ((devt = config_attach_pseudo(&dm_cfdata)) == NULL) { aprint_error("Unable to attach pseudo device dm/%s\n", name); return (ENOMEM); } if ((dmv = dm_dev_alloc()) == NULL) return ENOMEM; if (uuid) strncpy(dmv->uuid, uuid, DM_UUID_LEN); else dmv->uuid[0] = '\0'; if (name) strlcpy(dmv->name, name, DM_NAME_LEN); dmv->minor = (uint64_t)atomic_inc_32_nv(&sc_minor_num); dmv->flags = 0; /* device flags are set when needed */ dmv->ref_cnt = 0; dmv->event_nr = 0; dmv->dev_type = 0; dmv->devt = devt; dm_table_head_init(&dmv->table_head); mutex_init(&dmv->dev_mtx, MUTEX_DEFAULT, IPL_NONE); mutex_init(&dmv->diskp_mtx, MUTEX_DEFAULT, IPL_NONE); cv_init(&dmv->dev_cv, "dm_dev"); if (flags & DM_READONLY_FLAG) dmv->flags |= DM_READONLY_FLAG; prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor); disk_init(dmv->diskp, dmv->name, &dmdkdriver); disk_attach(dmv->diskp); dmv->diskp->dk_info = NULL; if ((r = dm_dev_insert(dmv)) != 0) dm_dev_free(dmv); DM_ADD_FLAG(flags, DM_EXISTS_FLAG); DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG); /* Increment device counter After creating device */ atomic_inc_32(&dm_dev_counter); return r; }