sys/dev/disk/dm/dm_pdev.c
dm_pdev_t *
dm_pdev_insert(const char *dev_name)
{
	dm_pdev_t *dmp;
	int error;

	KKASSERT(dev_name != NULL);

	lockmgr(&dm_pdev_mutex, LK_EXCLUSIVE);
	dmp = dm_pdev_lookup_name(dev_name);

	if (dmp != NULL) {
		dmp->ref_cnt++;
		aprint_debug("dmp_pdev_insert pdev %s already in tree\n", dev_name);
		lockmgr(&dm_pdev_mutex, LK_RELEASE);
		return dmp;
	}
	lockmgr(&dm_pdev_mutex, LK_RELEASE);

	if ((dmp = dm_pdev_alloc(dev_name)) == NULL)
		return NULL;

	error = dm_dk_lookup(dev_name, &dmp->pdev_vnode);
	if (error) {
		aprint_debug("dk_lookup on device: %s failed with error %d!\n",
		    dev_name, error);
		kfree(dmp, M_DM);
		return NULL;
	}
	dmp->ref_cnt = 1;

	/*
	 * Get us the partinfo from the underlying device, it's needed for
	 * dumps.
	 */
	bzero(&dmp->pdev_pinfo, sizeof(dmp->pdev_pinfo));
	error = dev_dioctl(dmp->pdev_vnode->v_rdev, DIOCGPART,
	    (void *)&dmp->pdev_pinfo, 0, proc0.p_ucred, NULL);

	lockmgr(&dm_pdev_mutex, LK_EXCLUSIVE);
	SLIST_INSERT_HEAD(&dm_pdev_list, dmp, next_pdev);
	lockmgr(&dm_pdev_mutex, LK_RELEASE);

	return dmp;
}
/*
 * Create entry for device with name dev_name and open vnode for it.
 * If entry already exists in global SLIST I will only increment
 * reference counter.
 */
Create entry for device with name dev_name and open vnode for it.
If entry already exists in global SLIST I will only increment
reference counter.
Create entry for device with name dev_name and open vnode for it . If entry already exists in global SLIST I will only increment reference counter .
dm_pdev_t *
dm_pdev_insert(const char *dev_name)
{
	dm_pdev_t *dmp;
	int error;
	KKASSERT(dev_name != NULL);
	lockmgr(&dm_pdev_mutex, LK_EXCLUSIVE);
	dmp = dm_pdev_lookup_name(dev_name);
	if (dmp != NULL) {
		dmp->ref_cnt++;
		aprint_debug("dmp_pdev_insert pdev %s already in tree\n", dev_name);
		lockmgr(&dm_pdev_mutex, LK_RELEASE);
		return dmp;
	}
	lockmgr(&dm_pdev_mutex, LK_RELEASE);
	if ((dmp = dm_pdev_alloc(dev_name)) == NULL)
		return NULL;
	error = dm_dk_lookup(dev_name, &dmp->pdev_vnode);
	if (error) {
		aprint_debug("dk_lookup on device: %s failed with error %d!\n",
		    dev_name, error);
		kfree(dmp, M_DM);
		return NULL;
	}
	dmp->ref_cnt = 1;
	bzero(&dmp->pdev_pinfo, sizeof(dmp->pdev_pinfo));
	error = dev_dioctl(dmp->pdev_vnode->v_rdev, DIOCGPART,
	    (void *)&dmp->pdev_pinfo, 0, proc0.p_ucred, NULL);
	lockmgr(&dm_pdev_mutex, LK_EXCLUSIVE);
	SLIST_INSERT_HEAD(&dm_pdev_list, dmp, next_pdev);
	lockmgr(&dm_pdev_mutex, LK_RELEASE);
	return dmp;
}
dm_pdev_t * dm_pdev_insert ( const char * dev_name ) { dm_pdev_t * dmp ; int error ; KKASSERT ( dev_name != NULL ) ; lockmgr ( & dm_pdev_mutex , LK_EXCLUSIVE ) ; dmp = dm_pdev_lookup_name ( dev_name ) ; if ( dmp != NULL ) { dmp -> ref_cnt ++ ; aprint_debug ( " \n " , dev_name ) ; lockmgr ( & dm_pdev_mutex , LK_RELEASE ) ; return dmp ; } lockmgr ( & dm_pdev_mutex , LK_RELEASE ) ; if ( ( dmp = dm_pdev_alloc ( dev_name ) ) == NULL ) return NULL ; error = dm_dk_lookup ( dev_name , & dmp -> pdev_vnode ) ; if ( error ) { aprint_debug ( " \n " , dev_name , error ) ; kfree ( dmp , M_DM ) ; return NULL ; } dmp -> ref_cnt = 1 ; bzero ( & dmp -> pdev_pinfo , sizeof ( dmp -> pdev_pinfo ) ) ; error = dev_dioctl ( dmp -> pdev_vnode -> v_rdev , DIOCGPART , ( void * ) & dmp -> pdev_pinfo , 0 , proc0 . p_ucred , NULL ) ; lockmgr ( & dm_pdev_mutex , LK_EXCLUSIVE ) ; SLIST_INSERT_HEAD ( & dm_pdev_list , dmp , next_pdev ) ; lockmgr ( & dm_pdev_mutex , LK_RELEASE ) ; return dmp ; }
Create entry for device with name dev_name and open vnode for it.
Create entry for device with name dev_name and open vnode for it .
/*
	 * Get us the partinfo from the underlying device, it's needed for
	 * dumps.
	 */