/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Adam Hamsik.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: dm_dev.c,v 1.19 2021/08/21 22:23:33 andvar Exp $");
/*
* Generic function used to lookup dm_dev_t. Calling with dm_dev_name
* and dm_dev_uuid NULL is allowed.
*/
dm_dev_t *
dm_dev_lookup(const char *dm_dev_name, const char *dm_dev_uuid,
int dm_dev_minor)
{
dm_dev_t *dmv;
/*
* dm_dev_lookup_devt look for selected device_t. We keep this routine
* outside of dm_dev_lookup because it is a temporally solution.
*
* TODO: This is a hack autoconf should be more flexible.
*/
dm_dev_t *
dm_dev_detach(device_t devt)
{
dm_dev_t *dmv;
/*
* Remove device selected with dm_dev from global list of devices.
*/
dm_dev_t *
dm_dev_rem(const char *dm_dev_name, const char *dm_dev_uuid,
int dm_dev_minor)
{
dm_dev_t *dmv;
mutex_enter(&dm_dev_mutex);
if (dm_dev_minor > 0)
if ((dmv = dm_dev_lookup_minor(dm_dev_minor)) != NULL) {
disable_dev(dmv);
return dmv;
}
if (dm_dev_name != NULL)
if ((dmv = dm_dev_lookup_name(dm_dev_name)) != NULL) {
disable_dev(dmv);
return dmv;
}
if (dm_dev_uuid != NULL)
if ((dmv = dm_dev_lookup_name(dm_dev_uuid)) != NULL) {
disable_dev(dmv);
return dmv;
}
mutex_exit(&dm_dev_mutex);
return NULL;
}
/*
* Destroy all devices created in device-mapper. Remove all tables
* free all allocated memory.
*/
int
dm_dev_destroy(void)
{
dm_dev_t *dmv;
mutex_enter(&dm_dev_mutex);
while (TAILQ_FIRST(&dm_dev_list) != NULL) {
dmv = TAILQ_FIRST(&dm_dev_list);