summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorhaad <haad@NetBSD.org>2010-01-04 00:12:22 +0000
committerhaad <haad@NetBSD.org>2010-01-04 00:12:22 +0000
commit293fc00622d830d19d388458bc8774c17cb97ef9 (patch)
treed0a8d7a6e9bdb93138f8759d71a314ca04874b36 /sys/dev
parent1ee1eb05c32ccacc20d4b0b1e218fb18ee8b3f4d (diff)
Indent files remove unnecessary blank lines, white spaces and KNFize code.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/dm/dm_dev.c209
-rw-r--r--sys/dev/dm/dm_ioctl.c332
-rw-r--r--sys/dev/dm/dm_pdev.c71
-rw-r--r--sys/dev/dm/dm_table.c78
-rw-r--r--sys/dev/dm/dm_target.c103
-rw-r--r--sys/dev/dm/dm_target_error.c36
-rw-r--r--sys/dev/dm/dm_target_linear.c74
-rw-r--r--sys/dev/dm/dm_target_mirror.c36
-rw-r--r--sys/dev/dm/dm_target_snapshot.c222
-rw-r--r--sys/dev/dm/dm_target_stripe.c85
-rw-r--r--sys/dev/dm/dm_target_zero.c44
11 files changed, 593 insertions, 697 deletions
diff --git a/sys/dev/dm/dm_dev.c b/sys/dev/dm/dm_dev.c
index dc1b50ce9f9..bf6f6465c7d 100644
--- a/sys/dev/dm/dm_dev.c
+++ b/sys/dev/dm/dm_dev.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_dev.c,v 1.7 2009/12/29 23:37:48 haad Exp $ */
+/* $NetBSD: dm_dev.c,v 1.8 2010/01/04 00:19:08 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -41,9 +41,9 @@
#include "netbsd-dm.h"
#include "dm.h"
-static dm_dev_t* dm_dev_lookup_name(const char *);
-static dm_dev_t* dm_dev_lookup_uuid(const char *);
-static dm_dev_t* dm_dev_lookup_minor(int);
+static dm_dev_t *dm_dev_lookup_name(const char *);
+static dm_dev_t *dm_dev_lookup_uuid(const char *);
+static dm_dev_t *dm_dev_lookup_minor(int);
static struct dm_dev_head dm_dev_list =
TAILQ_HEAD_INITIALIZER(dm_dev_list);
@@ -52,90 +52,88 @@ kmutex_t dm_dev_mutex;
/* dm_dev_mutex must be holdby caller before using disable_dev. */
__inline static void
-disable_dev(dm_dev_t *dmv)
+disable_dev(dm_dev_t * dmv)
{
- TAILQ_REMOVE(&dm_dev_list, dmv, next_devlist);
- mutex_enter(&dmv->dev_mtx);
- mutex_exit(&dm_dev_mutex);
- while(dmv->ref_cnt != 0)
- cv_wait(&dmv->dev_cv, &dmv->dev_mtx);
- mutex_exit(&dmv->dev_mtx);
-}
-
+ TAILQ_REMOVE(&dm_dev_list, dmv, next_devlist);
+ mutex_enter(&dmv->dev_mtx);
+ mutex_exit(&dm_dev_mutex);
+ while (dmv->ref_cnt != 0)
+ cv_wait(&dmv->dev_cv, &dmv->dev_mtx);
+ mutex_exit(&dmv->dev_mtx);
+}
/*
- * Generic function used to lookup dm_dev_t. Calling with dm_dev_name
+ * 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_t *
dm_dev_lookup(const char *dm_dev_name, const char *dm_dev_uuid,
- int dm_dev_minor)
+ int dm_dev_minor)
{
dm_dev_t *dmv;
-
+
dmv = NULL;
mutex_enter(&dm_dev_mutex);
-
- /* KASSERT(dm_dev_name != NULL && dm_dev_uuid != NULL && dm_dev_minor > 0); */
+
+ /* KASSERT(dm_dev_name != NULL && dm_dev_uuid != NULL && dm_dev_minor
+ * > 0); */
if (dm_dev_minor > 0)
- if ((dmv = dm_dev_lookup_minor(dm_dev_minor)) != NULL){
+ if ((dmv = dm_dev_lookup_minor(dm_dev_minor)) != NULL) {
dm_dev_busy(dmv);
mutex_exit(&dm_dev_mutex);
return dmv;
}
-
- if (dm_dev_name != NULL)
- if ((dmv = dm_dev_lookup_name(dm_dev_name)) != NULL){
+ if (dm_dev_name != NULL)
+ if ((dmv = dm_dev_lookup_name(dm_dev_name)) != NULL) {
dm_dev_busy(dmv);
mutex_exit(&dm_dev_mutex);
- return dmv;
+ return dmv;
}
-
if (dm_dev_uuid != NULL)
- if ((dmv = dm_dev_lookup_uuid(dm_dev_uuid)) != NULL){
+ if ((dmv = dm_dev_lookup_uuid(dm_dev_uuid)) != NULL) {
dm_dev_busy(dmv);
mutex_exit(&dm_dev_mutex);
return dmv;
}
- mutex_exit(&dm_dev_mutex);
- return NULL;
+ mutex_exit(&dm_dev_mutex);
+ return NULL;
}
-
+
/*
* Lookup device with its minor number.
*/
-static dm_dev_t*
+static dm_dev_t *
dm_dev_lookup_minor(int dm_dev_minor)
{
dm_dev_t *dmv;
-
- TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist){
+
+ TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist) {
if (dm_dev_minor == dmv->minor)
return dmv;
}
-
+
return NULL;
}
-
/*
* Lookup device with it's device name.
*/
-static dm_dev_t*
+static dm_dev_t *
dm_dev_lookup_name(const char *dm_dev_name)
{
dm_dev_t *dmv;
- int dlen; int slen;
+ int dlen;
+ int slen;
slen = strlen(dm_dev_name);
if (slen == 0)
return NULL;
-
- TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist){
+
+ TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist) {
dlen = strlen(dmv->name);
-
- if(slen != dlen)
+
+ if (slen != dlen)
continue;
if (strncmp(dm_dev_name, dmv->name, slen) == 0)
@@ -144,62 +142,59 @@ dm_dev_lookup_name(const char *dm_dev_name)
return NULL;
}
-
/*
* Lookup device with it's device uuid. Used mostly by LVM2tools.
*/
-static dm_dev_t*
+static dm_dev_t *
dm_dev_lookup_uuid(const char *dm_dev_uuid)
{
dm_dev_t *dmv;
size_t len;
-
+
len = 0;
len = strlen(dm_dev_uuid);
-
+
if (len == 0)
return NULL;
- TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist){
+ TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist) {
if (strlen(dmv->uuid) != len)
continue;
-
+
if (strncmp(dm_dev_uuid, dmv->uuid, strlen(dmv->uuid)) == 0)
return dmv;
}
return NULL;
}
-
/*
* Insert new device to the global list of devices.
*/
int
-dm_dev_insert(dm_dev_t *dev)
+dm_dev_insert(dm_dev_t * dev)
{
dm_dev_t *dmv;
int r;
dmv = NULL;
r = 0;
-
+
KASSERT(dev != NULL);
mutex_enter(&dm_dev_mutex);
if (((dmv = dm_dev_lookup_uuid(dev->uuid)) == NULL) &&
((dmv = dm_dev_lookup_name(dev->name)) == NULL) &&
- ((dmv = dm_dev_lookup_minor(dev->minor)) == NULL)){
+ ((dmv = dm_dev_lookup_minor(dev->minor)) == NULL)) {
TAILQ_INSERT_TAIL(&dm_dev_list, dev, next_devlist);
-
+
} else
r = EEXIST;
-
- mutex_exit(&dm_dev_mutex);
+
+ mutex_exit(&dm_dev_mutex);
return r;
}
-
-#ifdef notyet
+#ifdef notyet
/*
* Lookup device with its minor number.
*/
@@ -207,16 +202,16 @@ int
dm_dev_test_minor(int dm_dev_minor)
{
dm_dev_t *dmv;
-
+
mutex_enter(&dm_dev_mutex);
- TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist){
- if (dm_dev_minor == dmv->minor){
+ TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist) {
+ if (dm_dev_minor == dmv->minor) {
mutex_exit(&dm_dev_mutex);
return 1;
}
}
mutex_exit(&dm_dev_mutex);
-
+
return 0;
}
#endif
@@ -231,45 +226,42 @@ dm_dev_t *
dm_dev_detach(device_t devt)
{
dm_dev_t *dmv;
-
+
mutex_enter(&dm_dev_mutex);
- TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist){
- if (devt == dmv->devt){
+ TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist) {
+ if (devt == dmv->devt) {
disable_dev(dmv);
return dmv;
}
}
mutex_exit(&dm_dev_mutex);
-
+
return NULL;
}
-
-/*
- * Remove device selected with dm_dev from global list of devices.
+/*
+ * Remove device selected with dm_dev from global list of devices.
*/
-dm_dev_t*
+dm_dev_t *
dm_dev_rem(const char *dm_dev_name, const char *dm_dev_uuid,
- int dm_dev_minor)
-{
+ int dm_dev_minor)
+{
dm_dev_t *dmv;
dmv = NULL;
-
+
mutex_enter(&dm_dev_mutex);
-
+
if (dm_dev_minor > 0)
- if ((dmv = dm_dev_lookup_minor(dm_dev_minor)) != NULL){
+ 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){
+ 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){
+ if ((dmv = dm_dev_lookup_name(dm_dev_uuid)) != NULL) {
disable_dev(dmv);
return dmv;
}
@@ -277,10 +269,9 @@ dm_dev_rem(const char *dm_dev_name, const char *dm_dev_uuid,
return NULL;
}
-
/*
* Destroy all devices created in device-mapper. Remove all tables
- * free all allocated memmory.
+ * free all allocated memmory.
*/
int
dm_dev_destroy(void)
@@ -288,10 +279,10 @@ dm_dev_destroy(void)
dm_dev_t *dmv;
mutex_enter(&dm_dev_mutex);
- while (TAILQ_FIRST(&dm_dev_list) != NULL){
+ while (TAILQ_FIRST(&dm_dev_list) != NULL) {
dmv = TAILQ_FIRST(&dm_dev_list);
-
+
TAILQ_REMOVE(&dm_dev_list, TAILQ_FIRST(&dm_dev_list),
next_devlist);
@@ -299,7 +290,7 @@ dm_dev_destroy(void)
while (dmv->ref_cnt != 0)
cv_wait(&dmv->dev_cv, &dmv->dev_mtx);
-
+
/* Destroy active table first. */
dm_table_destroy(&dmv->table_head, DM_TABLE_ACTIVE);
@@ -311,36 +302,34 @@ dm_dev_destroy(void)
mutex_exit(&dmv->dev_mtx);
mutex_destroy(&dmv->dev_mtx);
cv_destroy(&dmv->dev_cv);
-
- (void)kmem_free(dmv, sizeof(dm_dev_t));
+
+ (void) kmem_free(dmv, sizeof(dm_dev_t));
}
mutex_exit(&dm_dev_mutex);
mutex_destroy(&dm_dev_mutex);
- return 0;
+ return 0;
}
-
/*
* Allocate new device entry.
*/
-dm_dev_t*
+dm_dev_t *
dm_dev_alloc(void)
{
dm_dev_t *dmv;
-
+
dmv = kmem_zalloc(sizeof(dm_dev_t), KM_SLEEP);
-
- if(dmv != NULL)
+
+ if (dmv != NULL)
dmv->diskp = kmem_zalloc(sizeof(struct disk), KM_SLEEP);
-
+
return dmv;
}
-
/*
* Freed device entry.
*/
int
-dm_dev_free(dm_dev_t *dmv)
+dm_dev_free(dm_dev_t * dmv)
{
KASSERT(dmv != NULL);
@@ -348,33 +337,32 @@ dm_dev_free(dm_dev_t *dmv)
mutex_destroy(&dmv->diskp_mtx);
cv_destroy(&dmv->dev_cv);
- if(dmv->diskp != NULL)
- (void)kmem_free(dmv->diskp, sizeof(struct disk));
-
- (void)kmem_free(dmv, sizeof(dm_dev_t));
-
+ if (dmv->diskp != NULL)
+ (void) kmem_free(dmv->diskp, sizeof(struct disk));
+
+ (void) kmem_free(dmv, sizeof(dm_dev_t));
+
return 0;
}
void
-dm_dev_busy(dm_dev_t *dmv)
+dm_dev_busy(dm_dev_t * dmv)
{
mutex_enter(&dmv->dev_mtx);
dmv->ref_cnt++;
mutex_exit(&dmv->dev_mtx);
-}
+}
void
-dm_dev_unbusy(dm_dev_t *dmv)
+dm_dev_unbusy(dm_dev_t * dmv)
{
KASSERT(dmv->ref_cnt != 0);
-
+
mutex_enter(&dmv->dev_mtx);
if (--dmv->ref_cnt == 0)
cv_broadcast(&dmv->dev_cv);
mutex_exit(&dmv->dev_mtx);
}
-
/*
* Return prop_array of dm_targer_list dictionaries.
*/
@@ -384,14 +372,14 @@ dm_dev_prop_list(void)
dm_dev_t *dmv;
prop_array_t dev_array;
prop_dictionary_t dev_dict;
-
+
dev_array = prop_array_create();
-
+
mutex_enter(&dm_dev_mutex);
-
+
TAILQ_FOREACH(dmv, &dm_dev_list, next_devlist) {
- dev_dict = prop_dictionary_create();
-
+ dev_dict = prop_dictionary_create();
+
prop_dictionary_set_cstring(dev_dict, DM_DEV_NAME, dmv->name);
prop_dictionary_set_uint32(dev_dict, DM_DEV_DEV, dmv->minor);
@@ -399,17 +387,16 @@ dm_dev_prop_list(void)
prop_object_release(dev_dict);
}
- mutex_exit(&dm_dev_mutex);
+ mutex_exit(&dm_dev_mutex);
return dev_array;
}
-
/*
* Initialize global device mutex.
*/
int
dm_dev_init(void)
{
- TAILQ_INIT(&dm_dev_list); /* initialize global dev list */
+ TAILQ_INIT(&dm_dev_list); /* initialize global dev list */
mutex_init(&dm_dev_mutex, MUTEX_DEFAULT, IPL_NONE);
return 0;
}
diff --git a/sys/dev/dm/dm_ioctl.c b/sys/dev/dm/dm_ioctl.c
index d79a7d83ab4..f053b4a46ef 100644
--- a/sys/dev/dm/dm_ioctl.c
+++ b/sys/dev/dm/dm_ioctl.c
@@ -1,5 +1,4 @@
-
-/* $NetBSD: dm_ioctl.c,v 1.19 2010/01/03 22:22:23 haad Exp $ */
+/* $NetBSD: dm_ioctl.c,v 1.20 2010/01/04 00:19:08 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -45,15 +44,15 @@
* up them.
*
* table_head locking:
- * To access table entries dm_table_* routines must be used.
+ * To access table entries dm_table_* routines must be used.
*
* dm_table_get_entry will increment table users reference
- * counter. It will return active or inactive table depedns
+ * counter. It will return active or inactive table depedns
* on uint8_t argument.
*
* dm_table_release must be called for every table_entry from
* dm_table_get_entry. Between these to calls tables can'tbe switched
- * or destroyed.
+ * or destroyed.
*
* dm_table_head_init initialize talbe_entries SLISTS and io_cv.
*
@@ -64,7 +63,7 @@
* dm_table_size etc. There is another user for table_head which wants
* to change table lists e.g. dm_dev_resume_ioctl, dm_dev_remove_ioctl,
* dm_table_clear_ioctl.
- *
+ *
* NOTE: It is not allowed to call dm_table_destroy, dm_table_switch_tables
* with hold table reference counter. Table reference counter is hold
* after calling dm_table_get_entry routine. After calling this
@@ -94,7 +93,7 @@
#include "netbsd-dm.h"
#include "dm.h"
-static uint64_t sc_minor_num;
+static uint64_t sc_minor_num;
extern const struct dkdriver dmdkdriver;
uint64_t dev_counter;
@@ -105,18 +104,17 @@ static struct cfdata dm_cfdata = {
.cf_fstate = FSTATE_STAR,
.cf_unit = 0
};
-
#define DM_REMOVE_FLAG(flag, name) do { \
prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
flag &= ~name; \
prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
- } while (/*CONSTCOND*/0)
+} while (/*CONSTCOND*/0)
#define DM_ADD_FLAG(flag, name) do { \
prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
flag |= name; \
prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
- } while (/*CONSTCOND*/0)
+} while (/*CONSTCOND*/0)
static int dm_dbg_print_flags(int);
@@ -126,8 +124,8 @@ static int dm_dbg_print_flags(int);
static int
dm_dbg_print_flags(int flags)
{
- aprint_debug("dbg_print --- %d\n",flags);
-
+ aprint_debug("dbg_print --- %d\n", flags);
+
if (flags & DM_READONLY_FLAG)
aprint_debug("dbg_flags: DM_READONLY_FLAG set In/Out\n");
@@ -157,10 +155,9 @@ dm_dbg_print_flags(int flags)
if (flags & DM_NOFLUSH_FLAG)
aprint_debug("dbg_flags: DM_NOFLUSH_FLAG set In\n");
-
+
return 0;
}
-
/*
* Get version ioctl call I do it as default therefore this
* function is unused now.
@@ -168,9 +165,9 @@ dm_dbg_print_flags(int flags)
int
dm_get_version_ioctl(prop_dictionary_t dm_dict)
{
+
return 0;
}
-
/*
* Get list of all available targets from global
* target list and sent them back to libdevmapper.
@@ -184,18 +181,15 @@ dm_list_versions_ioctl(prop_dictionary_t dm_dict)
flags = 0;
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
-
- dm_dbg_print_flags(flags);
+ dm_dbg_print_flags(flags);
target_list = dm_target_prop_list();
prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, target_list);
-
prop_object_release(target_list);
-
+
return 0;
}
-
/*
* Create in-kernel entry for device. Device attributes such as name, uuid are
* taken from proplib dictionary.
@@ -208,49 +202,47 @@ dm_dev_create_ioctl(prop_dictionary_t dm_dict)
const char *name, *uuid;
int r, flags;
device_t devt;
-
+
r = 0;
flags = 0;
- name = NULL;
+ 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_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
+ else
dmv->uuid[0] = '\0';
-
+
if (name)
strlcpy(dmv->name, name, DM_NAME_LEN);
dmv->minor = atomic_inc_64_nv(&sc_minor_num);
- dmv->flags = 0; /* device flags are set when needed */
+ 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);
@@ -266,19 +258,18 @@ dm_dev_create_ioctl(prop_dictionary_t dm_dict)
disk_attach(dmv->diskp);
dmv->diskp->dk_info = NULL;
-
- if ((r = dm_dev_insert(dmv)) != 0)
+
+ 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_64(&dev_counter);
-
+
return r;
}
-
/*
* Get list of created device-mapper devices fromglobal list and
* send it to kernel.
@@ -295,7 +286,7 @@ dm_dev_create_ioctl(prop_dictionary_t dm_dict)
* <integer>...</integer>
* </dict>
* </array>
- *
+ *
*/
int
dm_dev_list_ioctl(prop_dictionary_t dm_dict)
@@ -303,21 +294,20 @@ dm_dev_list_ioctl(prop_dictionary_t dm_dict)
prop_array_t dev_list;
uint32_t flags;
-
+
flags = 0;
-
+
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
-
+
dm_dbg_print_flags(flags);
-
+
dev_list = dm_dev_prop_list();
prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, dev_list);
prop_object_release(dev_list);
-
+
return 0;
}
-
/*
* Rename selected devices old name is in struct dm_ioctl.
* newname is taken from dictionary
@@ -332,14 +322,14 @@ dm_dev_rename_ioctl(prop_dictionary_t dm_dict)
{
prop_array_t cmd_array;
dm_dev_t *dmv;
-
+
const char *name, *uuid, *n_name;
uint32_t flags, minor;
name = NULL;
uuid = NULL;
minor = 0;
-
+
/* 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);
@@ -347,35 +337,34 @@ dm_dev_rename_ioctl(prop_dictionary_t dm_dict)
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
dm_dbg_print_flags(flags);
-
+
cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
prop_array_get_cstring_nocopy(cmd_array, 0, &n_name);
-
+
if (strlen(n_name) + 1 > DM_NAME_LEN)
return EINVAL;
-
+
if ((dmv = dm_dev_rem(name, uuid, minor)) == NULL) {
DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
return ENOENT;
}
-
/* change device name */
- /* XXX How to deal with this change, name only used in
- * dm_dev_routines, should I add dm_dev_change_name which will run under the
- * dm_dev_list mutex ?
+ /*
+ * XXX How to deal with this change, name only used in
+ * dm_dev_routines, should I add dm_dev_change_name which will run
+ * under the dm_dev_list mutex ?
*/
strlcpy(dmv->name, n_name, DM_NAME_LEN);
-
+
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
dm_dev_insert(dmv);
-
+
return 0;
}
-
/*
* Remove device from global list I have to remove active
* and inactive tables first.
@@ -387,34 +376,37 @@ dm_dev_remove_ioctl(prop_dictionary_t dm_dict)
const char *name, *uuid;
uint32_t flags, minor;
device_t devt;
-
+
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);
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
-
+
dm_dbg_print_flags(flags);
- /* This seems as hack to me, probably use routine dm_dev_get_devt to
- atomicaly get devt from device. */
+ /*
+ * This seems as hack to me, probably use routine dm_dev_get_devt to
+ * atomicaly get devt from device.
+ */
if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
return ENOENT;
}
-
devt = dmv->devt;
dm_dev_unbusy(dmv);
-
- /* This will call dm_detach routine which will actually removes device. */
+
+ /*
+ * This will call dm_detach routine which will actually removes
+ * device.
+ */
return config_detach(devt, DETACH_QUIET);
}
-
/*
* Return actual state of device to libdevmapper.
*/
@@ -424,24 +416,23 @@ dm_dev_status_ioctl(prop_dictionary_t dm_dict)
dm_dev_t *dmv;
const char *name, *uuid;
uint32_t flags, j, minor;
-
+
name = NULL;
uuid = NULL;
flags = 0;
j = 0;
-
+
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);
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
-
+
if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
return ENOENT;
}
-
dm_dbg_print_flags(dmv->flags);
-
+
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
@@ -449,25 +440,26 @@ dm_dev_status_ioctl(prop_dictionary_t dm_dict)
if (dmv->flags & DM_SUSPEND_FLAG)
DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
- /* Add status flags for tables I have to check both
- active and inactive tables. */
+ /*
+ * Add status flags for tables I have to check both active and
+ * inactive tables.
+ */
if ((j = dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))) {
DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
} else
DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
-
+
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_TARGET_COUNT, j);
-
+
if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
else
DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
dm_dev_unbusy(dmv);
-
+
return 0;
}
-
/*
* Set only flag to suggest that device is suspended. This call is
* not supported in NetBSD.
@@ -479,40 +471,38 @@ dm_dev_suspend_ioctl(prop_dictionary_t dm_dict)
dm_dev_t *dmv;
const char *name, *uuid;
uint32_t flags, minor;
-
+
name = NULL;
uuid = NULL;
flags = 0;
-
+
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);
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
-
- if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL){
+
+ if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
return ENOENT;
}
-
atomic_or_32(&dmv->flags, DM_SUSPEND_FLAG);
-
+
dm_dbg_print_flags(dmv->flags);
-
+
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, dmv->flags);
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
-
+
dm_dev_unbusy(dmv);
-
+
/* Add flags to dictionary flag after dmv -> dict copy */
- DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
-
+ DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
+
return 0;
}
-
/*
* Simulate Linux behaviour better and switch tables here and not in
- * dm_table_load_ioctl.
+ * dm_table_load_ioctl.
*/
int
dm_dev_resume_ioctl(prop_dictionary_t dm_dict)
@@ -524,31 +514,31 @@ dm_dev_resume_ioctl(prop_dictionary_t dm_dict)
name = NULL;
uuid = NULL;
flags = 0;
-
-/* char *xml;
- xml = prop_dictionary_externalize(dm_dict);
- printf("%s\n",xml);*/
-
+
+ /*
+ * char *xml; xml = prop_dictionary_externalize(dm_dict);
+ * printf("%s\n",xml);
+ */
+
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);
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
-
+
/* Remove device from global device list */
- if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL){
+ if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
return ENOENT;
}
-
atomic_and_32(&dmv->flags, ~(DM_SUSPEND_FLAG | DM_INACTIVE_PRESENT_FLAG));
atomic_or_32(&dmv->flags, DM_ACTIVE_PRESENT_FLAG);
-
+
dm_table_switch_tables(&dmv->table_head);
-
- DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
+
+ DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
dmgetproperties(dmv->diskp, &dmv->table_head);
-
+
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
@@ -557,10 +547,9 @@ dm_dev_resume_ioctl(prop_dictionary_t dm_dict)
/* Destroy inactive table after resume. */
dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
-
+
return 0;
}
-
/*
* Table management routines
* lvm2tools doens't send name/uuid to kernel with table
@@ -579,41 +568,39 @@ dm_table_clear_ioctl(prop_dictionary_t dm_dict)
const char *name, *uuid;
uint32_t flags, minor;
- dmv = NULL;
+ dmv = NULL;
name = NULL;
uuid = NULL;
flags = 0;
minor = 0;
-
+
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);
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
-
+
aprint_debug("Clearing inactive table from device: %s--%s\n",
name, uuid);
-
- if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL){
+
+ if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
return ENOENT;
}
-
/* Select unused table */
dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
atomic_and_32(&dmv->flags, ~DM_INACTIVE_PRESENT_FLAG);
dm_dev_unbusy(dmv);
-
+
return 0;
}
-
/*
* Get list of physical devices for active table.
* Get dev_t from pdev vnode and insert it into cmd_array.
*
* XXX. This function is called from lvm2tools to get information
- * about physical devices, too e.g. during vgcreate.
+ * about physical devices, too e.g. during vgcreate.
*/
int
dm_table_deps_ioctl(prop_dictionary_t dm_dict)
@@ -631,9 +618,9 @@ dm_table_deps_ioctl(prop_dictionary_t dm_dict)
name = NULL;
uuid = NULL;
- dmv = NULL;
+ dmv = NULL;
flags = 0;
-
+
i = 0;
prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
@@ -644,37 +631,38 @@ dm_table_deps_ioctl(prop_dictionary_t dm_dict)
/* create array for dev_t's */
cmd_array = prop_array_create();
- if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL){
+ if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
return ENOENT;
}
-
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
prop_dictionary_set_cstring(dm_dict, DM_IOCTL_NAME, dmv->name);
prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
-
+
aprint_debug("Getting table deps for device: %s\n", dmv->name);
- /* if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query INACTIVE TABLE */
+ /*
+ * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
+ * INACTIVE TABLE
+ */
if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
table_type = DM_TABLE_INACTIVE;
else
table_type = DM_TABLE_ACTIVE;
-
+
tbl = dm_table_get_entry(&dmv->table_head, table_type);
SLIST_FOREACH(table_en, tbl, next)
- table_en->target->deps(table_en, cmd_array);
+ table_en->target->deps(table_en, cmd_array);
dm_table_release(&dmv->table_head, table_type);
dm_dev_unbusy(dmv);
-
+
prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
prop_object_release(cmd_array);
-
+
return 0;
}
-
/*
* Load new table/tables to device.
* Call apropriate target init routine open all physical pdev's and
@@ -690,13 +678,13 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
{
dm_dev_t *dmv;
dm_table_entry_t *table_en, *last_table;
- dm_table_t *tbl;
+ dm_table_t *tbl;
dm_target_t *target;
prop_object_iterator_t iter;
prop_array_t cmd_array;
prop_dictionary_t target_dict;
-
+
const char *name, *uuid, *type;
uint32_t flags, ret, minor;
@@ -711,27 +699,27 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
last_table = NULL;
str = NULL;
- /* char *xml;
- xml = prop_dictionary_externalize(dm_dict);
- printf("%s\n",xml);*/
-
+ /*
+ * char *xml; xml = prop_dictionary_externalize(dm_dict);
+ * printf("%s\n",xml);
+ */
+
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);
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
-
+
cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
iter = prop_array_iterator(cmd_array);
- dm_dbg_print_flags(flags);
-
- if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL){
+ dm_dbg_print_flags(flags);
+
+ if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
return ENOENT;
}
-
aprint_debug("Loading table to device: %s--%d\n", name,
dmv->table_head.cur_active_table);
-
+
/*
* I have to check if this table slot is not used by another table list.
* if it is used I should free them.
@@ -741,12 +729,12 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
dm_dbg_print_flags(dmv->flags);
tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_INACTIVE);
-
+
aprint_debug("dmv->name = %s\n", dmv->name);
-
+
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
- while((target_dict = prop_object_iterator_next(iter)) != NULL){
+ while ((target_dict = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(target_dict,
DM_TABLE_TYPE, &type);
@@ -760,14 +748,12 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
dm_dev_unbusy(dmv);
return ENOENT;
}
-
if ((table_en = kmem_alloc(sizeof(dm_table_entry_t),
KM_SLEEP)) == NULL) {
dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
dm_dev_unbusy(dmv);
return ENOMEM;
}
-
prop_dictionary_get_uint64(target_dict, DM_TABLE_START,
&table_en->start);
prop_dictionary_get_uint64(target_dict, DM_TABLE_LENGTH,
@@ -776,7 +762,7 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
table_en->target = target;
table_en->dm_dev = dmv;
table_en->target_config = NULL;
-
+
/*
* There is a parameter string after dm_target_spec
* structure which points to /dev/wd0a 284 part of
@@ -785,20 +771,20 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
* use it.
*/
prop_dictionary_get_cstring(target_dict,
- DM_TABLE_PARAMS, (char**)&str);
-
+ DM_TABLE_PARAMS, (char **) &str);
+
if (SLIST_EMPTY(tbl))
/* insert this table to head */
SLIST_INSERT_HEAD(tbl, table_en, next);
else
SLIST_INSERT_AFTER(last_table, table_en, next);
-
+
/*
* Params string is different for every target,
* therfore I have to pass it to target init
* routine and parse parameters there.
*/
-
+
if ((ret = target->init(dmv, &table_en->target_config,
str)) != 0) {
@@ -813,15 +799,14 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
free(str, M_TEMP);
}
prop_object_iterator_release(iter);
-
+
DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
atomic_or_32(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
-
+
dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
dm_dev_unbusy(dmv);
return 0;
}
-
/*
* Get description of all tables loaded to device from kernel
* and send it to libdevmapper.
@@ -855,14 +840,14 @@ dm_table_status_ioctl(prop_dictionary_t dm_dict)
prop_array_t cmd_array;
prop_dictionary_t target_dict;
-
+
uint32_t rec_size, minor;
-
+
const char *name, *uuid;
char *params;
int flags;
int table_type;
-
+
dmv = NULL;
uuid = NULL;
name = NULL;
@@ -876,42 +861,43 @@ dm_table_status_ioctl(prop_dictionary_t dm_dict)
prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
cmd_array = prop_array_create();
-
- if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL){
+
+ if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
return ENOENT;
}
-
- /* if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query INACTIVE TABLE */
+ /*
+ * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
+ * INACTIVE TABLE
+ */
if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
table_type = DM_TABLE_INACTIVE;
else
table_type = DM_TABLE_ACTIVE;
-
+
if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))
DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
else {
DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
-
+
if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
else {
DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
}
}
-
+
if (dmv->flags & DM_SUSPEND_FLAG)
DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
-
+
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
-
+
aprint_debug("Status of device tables: %s--%d\n",
name, dmv->table_head.cur_active_table);
-
+
tbl = dm_table_get_entry(&dmv->table_head, table_type);
-
- SLIST_FOREACH(table_en, tbl, next)
- {
+
+ SLIST_FOREACH(table_en, tbl, next) {
target_dict = prop_dictionary_create();
aprint_debug("%016" PRIu64 ", length %016" PRIu64
", target %s\n", table_en->start, table_en->length,
@@ -933,14 +919,13 @@ dm_table_status_ioctl(prop_dictionary_t dm_dict)
params = table_en->target->status
(table_en->target_config);
- if(params != NULL){
+ if (params != NULL) {
prop_dictionary_set_cstring(target_dict,
DM_TABLE_PARAMS, params);
-
+
kmem_free(params, DM_MAX_PARAMS_SIZE);
}
}
-
prop_array_add(cmd_array, target_dict);
prop_object_release(target_dict);
}
@@ -951,7 +936,7 @@ dm_table_status_ioctl(prop_dictionary_t dm_dict)
prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
prop_object_release(cmd_array);
-
+
return 0;
}
@@ -959,7 +944,7 @@ dm_table_status_ioctl(prop_dictionary_t dm_dict)
/*
* For every call I have to set kernel driver version.
* Because I can have commands supported only in other
- * newer/later version. This routine is called for every
+ * newer/later version. This routine is called for every
* ioctl command.
*/
int
@@ -968,26 +953,25 @@ dm_check_version(prop_dictionary_t dm_dict)
size_t i;
int dm_version[3];
prop_array_t ver;
-
+
ver = prop_dictionary_get(dm_dict, DM_IOCTL_VERSION);
-
- for(i=0; i < 3; i++)
+
+ for (i = 0; i < 3; i++)
prop_array_get_uint32(ver, i, &dm_version[i]);
- if (DM_VERSION_MAJOR != dm_version[0] || DM_VERSION_MINOR < dm_version[1]){
+ if (DM_VERSION_MAJOR != dm_version[0] || DM_VERSION_MINOR < dm_version[1]) {
aprint_debug("libdevmapper/kernel version mismatch "
"kernel: %d.%d.%d libdevmapper: %d.%d.%d\n",
DM_VERSION_MAJOR, DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL,
dm_version[0], dm_version[1], dm_version[2]);
-
+
return EIO;
}
-
prop_array_set_uint32(ver, 0, DM_VERSION_MAJOR);
prop_array_set_uint32(ver, 1, DM_VERSION_MINOR);
prop_array_set_uint32(ver, 2, DM_VERSION_PATCHLEVEL);
prop_dictionary_set(dm_dict, DM_IOCTL_VERSION, ver);
-
+
return 0;
}
diff --git a/sys/dev/dm/dm_pdev.c b/sys/dev/dm/dm_pdev.c
index abb214bbcbf..250624898f2 100644
--- a/sys/dev/dm/dm_pdev.c
+++ b/sys/dev/dm/dm_pdev.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_pdev.c,v 1.5 2010/01/03 12:53:00 haad Exp $ */
+/* $NetBSD: dm_pdev.c,v 1.6 2010/01/04 00:19:08 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -44,20 +44,21 @@
SLIST_HEAD(dm_pdevs, dm_pdev) dm_pdev_list;
-kmutex_t dm_pdev_mutex;
+ kmutex_t dm_pdev_mutex;
-static dm_pdev_t *dm_pdev_alloc(const char *);
-static int dm_pdev_rem(dm_pdev_t *);
-static dm_pdev_t* dm_pdev_lookup_name(const char *);
+ static dm_pdev_t *dm_pdev_alloc(const char *);
+ static int dm_pdev_rem(dm_pdev_t *);
+ static dm_pdev_t *dm_pdev_lookup_name(const char *);
/*
* Find used pdev with name == dm_pdev_name.
*/
-dm_pdev_t*
-dm_pdev_lookup_name(const char *dm_pdev_name)
+ dm_pdev_t *
+ dm_pdev_lookup_name(const char *dm_pdev_name)
{
dm_pdev_t *dm_pdev;
- int dlen; int slen;
+ int dlen;
+ int slen;
KASSERT(dm_pdev_name != NULL);
@@ -68,38 +69,37 @@ dm_pdev_lookup_name(const char *dm_pdev_name)
if (slen != dlen)
continue;
-
+
if (strncmp(dm_pdev_name, dm_pdev->name, slen) == 0)
return dm_pdev;
}
return NULL;
}
-
/*
* 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_t *
dm_pdev_insert(const char *dev_name)
{
dm_pdev_t *dmp;
int error;
-
+
KASSERT(dev_name != NULL);
-
+
mutex_enter(&dm_pdev_mutex);
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);
+ aprint_debug("dmp_pdev_insert pdev %s already in tree\n", dev_name);
mutex_exit(&dm_pdev_mutex);
return dmp;
}
mutex_exit(&dm_pdev_mutex);
-
+
if ((dmp = dm_pdev_alloc(dev_name)) == NULL)
return NULL;
@@ -110,33 +110,30 @@ dm_pdev_insert(const char *dev_name)
kmem_free(dmp, sizeof(dm_pdev_t));
return NULL;
}
-
dmp->ref_cnt = 1;
-
+
mutex_enter(&dm_pdev_mutex);
SLIST_INSERT_HEAD(&dm_pdev_list, dmp, next_pdev);
mutex_exit(&dm_pdev_mutex);
return dmp;
}
-
/*
* Initialize pdev subsystem.
*/
int
dm_pdev_init(void)
{
- SLIST_INIT(&dm_pdev_list); /* initialize global pdev list */
+ SLIST_INIT(&dm_pdev_list); /* initialize global pdev list */
mutex_init(&dm_pdev_mutex, MUTEX_DEFAULT, IPL_NONE);
-
+
return 0;
}
-
/*
* Allocat new pdev structure if is not already present and
* set name.
*/
-static dm_pdev_t*
+static dm_pdev_t *
dm_pdev_alloc(const char *name)
{
dm_pdev_t *dmp;
@@ -145,35 +142,32 @@ dm_pdev_alloc(const char *name)
return NULL;
strlcpy(dmp->name, name, MAX_DEV_NAME);
-
+
dmp->ref_cnt = 0;
dmp->pdev_vnode = NULL;
-
+
return dmp;
}
-
/*
* Destroy allocated dm_pdev.
*/
static int
-dm_pdev_rem(dm_pdev_t *dmp)
+dm_pdev_rem(dm_pdev_t * dmp)
{
int err;
KASSERT(dmp != NULL);
-
+
if (dmp->pdev_vnode != NULL) {
err = vn_close(dmp->pdev_vnode, FREAD | FWRITE, FSCRED);
if (err != 0)
return err;
}
-
kmem_free(dmp, sizeof(*dmp));
dmp = NULL;
-
+
return 0;
}
-
/*
* Destroy all existing pdev's in device-mapper.
*/
@@ -183,10 +177,10 @@ dm_pdev_destroy(void)
dm_pdev_t *dm_pdev;
mutex_enter(&dm_pdev_mutex);
- while (!SLIST_EMPTY(&dm_pdev_list)) { /* List Deletion. */
-
+ while (!SLIST_EMPTY(&dm_pdev_list)) { /* List Deletion. */
+
dm_pdev = SLIST_FIRST(&dm_pdev_list);
-
+
SLIST_REMOVE_HEAD(&dm_pdev_list, next_pdev);
dm_pdev_rem(dm_pdev);
@@ -196,7 +190,6 @@ dm_pdev_destroy(void)
mutex_destroy(&dm_pdev_mutex);
return 0;
}
-
/*
* This funcion is called from dm_dev_remove_ioctl.
* When I'm removing device from list, I have to decrement
@@ -209,7 +202,7 @@ dm_pdev_destroy(void)
* Decrement pdev reference counter if 0 remove it.
*/
int
-dm_pdev_decr(dm_pdev_t *dmp)
+dm_pdev_decr(dm_pdev_t * dmp)
{
KASSERT(dmp != NULL);
/*
@@ -217,18 +210,16 @@ dm_pdev_decr(dm_pdev_t *dmp)
* global list also.
*/
mutex_enter(&dm_pdev_mutex);
-
+
if (--dmp->ref_cnt == 0) {
- SLIST_REMOVE(&dm_pdev_list, dmp, dm_pdev, next_pdev);
+ SLIST_REMOVE(&dm_pdev_list, dmp, dm_pdev, next_pdev);
mutex_exit(&dm_pdev_mutex);
dm_pdev_rem(dmp);
return 0;
}
-
mutex_exit(&dm_pdev_mutex);
return 0;
}
-
/*static int
dm_pdev_dump_list(void)
{
@@ -241,6 +232,6 @@ dm_pdev_decr(dm_pdev_t *dmp)
dmp->name, dmp->ref_cnt, dmp->list_ref_cnt);
}
- return 0;
+ return 0;
}*/
diff --git a/sys/dev/dm/dm_table.c b/sys/dev/dm/dm_table.c
index fdcbf97ad18..1196aba01e9 100644
--- a/sys/dev/dm/dm_table.c
+++ b/sys/dev/dm/dm_table.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_table.c,v 1.4 2009/10/23 20:41:11 joerg Exp $ */
+/* $NetBSD: dm_table.c,v 1.5 2010/01/04 00:19:08 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
/*
* There are two types of users of this interface:
- *
+ *
* a) Readers such as
* dmstrategy, dmgetdisklabel, dmsize, dm_dev_status_ioctl,
* dm_table_deps_ioctl, dm_table_status_ioctl, dm_table_reload_ioctl
@@ -51,7 +51,7 @@
*
*/
-static int dm_table_busy(dm_table_head_t *, uint8_t );
+static int dm_table_busy(dm_table_head_t *, uint8_t);
static void dm_table_unbusy(dm_table_head_t *);
/*
@@ -61,7 +61,7 @@ static void dm_table_unbusy(dm_table_head_t *);
* DM_TABLE_INACTIVE will return inactive table id.
*/
static int
-dm_table_busy(dm_table_head_t *head, uint8_t table_id)
+dm_table_busy(dm_table_head_t * head, uint8_t table_id)
{
uint8_t id;
@@ -79,50 +79,46 @@ dm_table_busy(dm_table_head_t *head, uint8_t table_id)
mutex_exit(&head->table_mtx);
return id;
}
-
/*
* Function release table lock and eventually wakeup all waiters.
*/
static void
-dm_table_unbusy(dm_table_head_t *head)
+dm_table_unbusy(dm_table_head_t * head)
{
KASSERT(head->io_cnt != 0);
mutex_enter(&head->table_mtx);
-
+
if (--head->io_cnt == 0)
cv_broadcast(&head->table_cv);
-
+
mutex_exit(&head->table_mtx);
}
-
/*
* Return current active table to caller, increment io_cnt reference counter.
*/
dm_table_t *
-dm_table_get_entry(dm_table_head_t *head, uint8_t table_id)
+dm_table_get_entry(dm_table_head_t * head, uint8_t table_id)
{
uint8_t id;
id = dm_table_busy(head, table_id);
-
+
return &head->tables[id];
}
-
/*
* Decrement io reference counter and wake up all callers, with table_head cv.
*/
void
-dm_table_release(dm_table_head_t *head, uint8_t table_id)
+dm_table_release(dm_table_head_t * head, uint8_t table_id)
{
dm_table_unbusy(head);
}
-
/*
* Switch table from inactive to active mode. Have to wait until io_cnt is 0.
*/
void
-dm_table_switch_tables(dm_table_head_t *head)
+dm_table_switch_tables(dm_table_head_t * head)
{
mutex_enter(&head->table_mtx);
@@ -133,7 +129,6 @@ dm_table_switch_tables(dm_table_head_t *head)
mutex_exit(&head->table_mtx);
}
-
/*
* Destroy all table data. This function can run when there are no
* readers on table lists.
@@ -141,9 +136,9 @@ dm_table_switch_tables(dm_table_head_t *head)
* XXX Is it ok to call kmem_free and potentialy VOP_CLOSE with held mutex ?xs
*/
int
-dm_table_destroy(dm_table_head_t *head, uint8_t table_id)
+dm_table_destroy(dm_table_head_t * head, uint8_t table_id)
{
- dm_table_t *tbl;
+ dm_table_t *tbl;
dm_table_entry_t *table_en;
uint8_t id;
@@ -158,45 +153,44 @@ dm_table_destroy(dm_table_head_t *head, uint8_t table_id)
id = head->cur_active_table;
else
id = 1 - head->cur_active_table;
-
+
tbl = &head->tables[id];
-
- while (!SLIST_EMPTY(tbl)) { /* List Deletion. */
+
+ while (!SLIST_EMPTY(tbl)) { /* List Deletion. */
table_en = SLIST_FIRST(tbl);
/*
* Remove target specific config data. After successfull
* call table_en->target_config must be set to NULL.
*/
- table_en->target->destroy(table_en);
-
+ table_en->target->destroy(table_en);
+
SLIST_REMOVE_HEAD(tbl, next);
kmem_free(table_en, sizeof(*table_en));
}
mutex_exit(&head->table_mtx);
-
+
return 0;
}
-
/*
* Return length of active table in device.
*/
uint64_t
-dm_table_size(dm_table_head_t *head)
+dm_table_size(dm_table_head_t * head)
{
- dm_table_t *tbl;
+ dm_table_t *tbl;
dm_table_entry_t *table_en;
uint64_t length;
uint8_t id;
-
+
length = 0;
id = dm_table_busy(head, DM_TABLE_ACTIVE);
-
+
/* Select active table */
tbl = &head->tables[id];
-
+
/*
* Find out what tables I want to select.
* if length => rawblkno then we should used that table.
@@ -205,10 +199,9 @@ dm_table_size(dm_table_head_t *head)
length += table_en->length;
dm_table_unbusy(head);
-
+
return length;
}
-
/*
* Return > 0 if table is at least one table entry (returns number of entries)
* and return 0 if there is not. Target count returned from this function
@@ -216,8 +209,8 @@ dm_table_size(dm_table_head_t *head)
* there can be dm_dev_resume_ioctl), therfore this isonly informative.
*/
int
-dm_table_get_target_count(dm_table_head_t *head, uint8_t table_id)
-{
+dm_table_get_target_count(dm_table_head_t * head, uint8_t table_id)
+{
dm_table_entry_t *table_en;
dm_table_t *tbl;
uint32_t target_count;
@@ -233,7 +226,7 @@ dm_table_get_target_count(dm_table_head_t *head, uint8_t table_id)
target_count++;
dm_table_unbusy(head);
-
+
return target_count;
}
@@ -243,11 +236,11 @@ dm_table_get_target_count(dm_table_head_t *head, uint8_t table_id)
* opaque as possible.
*/
void
-dm_table_head_init(dm_table_head_t *head)
+dm_table_head_init(dm_table_head_t * head)
{
head->cur_active_table = 0;
head->io_cnt = 0;
-
+
/* Initialize tables. */
SLIST_INIT(&head->tables[0]);
SLIST_INIT(&head->tables[1]);
@@ -255,19 +248,18 @@ dm_table_head_init(dm_table_head_t *head)
mutex_init(&head->table_mtx, MUTEX_DEFAULT, IPL_NONE);
cv_init(&head->table_cv, "dm_io");
}
-
/*
* Destroy all variables in table_head
*/
void
-dm_table_head_destroy(dm_table_head_t *head)
+dm_table_head_destroy(dm_table_head_t * head)
{
KASSERT(!mutex_owned(&head->table_mtx));
KASSERT(!cv_has_waiters(&head->table_cv));
- /* tables doens't exists when I call this routine, therefore
- it doesn't make sense to have io_cnt != 0 */
- KASSERT(head->io_cnt == 0);
-
+ /* tables doens't exists when I call this routine, therefore it
+ * doesn't make sense to have io_cnt != 0 */
+ KASSERT(head->io_cnt == 0);
+
cv_destroy(&head->table_cv);
mutex_destroy(&head->table_mtx);
}
diff --git a/sys/dev/dm/dm_target.c b/sys/dev/dm/dm_target.c
index 9ab0bceb95c..a46b28cfd29 100644
--- a/sys/dev/dm/dm_target.c
+++ b/sys/dev/dm/dm_target.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target.c,v 1.11 2009/09/09 22:38:49 haad Exp $ */
+/* $NetBSD: dm_target.c,v 1.12 2010/01/04 00:14:41 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
#include "netbsd-dm.h"
#include "dm.h"
-static dm_target_t* dm_target_lookup_name(const char *);
+static dm_target_t *dm_target_lookup_name(const char *);
TAILQ_HEAD(dm_target_head, dm_target);
@@ -52,21 +52,19 @@ kmutex_t dm_target_mutex;
* Called indirectly from dm_table_load_ioctl to mark target as used.
*/
void
-dm_target_busy(dm_target_t *target)
+dm_target_busy(dm_target_t * target)
{
atomic_inc_32(&target->ref_cnt);
}
-
/*
* Release reference counter on target.
*/
void
-dm_target_unbusy(dm_target_t *target)
+dm_target_unbusy(dm_target_t * target)
{
KASSERT(target->ref_cnt > 0);
atomic_dec_32(&target->ref_cnt);
}
-
/*
* Try to autoload target module if it was not found in current
* target list.
@@ -79,26 +77,25 @@ dm_target_autoload(const char *dm_target_name)
dm_target_t *dmt;
snprintf(name, sizeof(name), "dm_target_%s", dm_target_name);
- name[29]='\0';
-
+ name[29] = '\0';
+
do {
gen = module_gen;
-
+
/* Try to autoload target module */
mutex_enter(&module_lock);
(void) module_autoload(name, MODULE_CLASS_MISC);
mutex_exit(&module_lock);
- } while (gen != module_gen);
+ } while (gen != module_gen);
mutex_enter(&dm_target_mutex);
dmt = dm_target_lookup_name(dm_target_name);
if (dmt != NULL)
dm_target_busy(dmt);
mutex_exit(&dm_target_mutex);
-
+
return dmt;
}
-
/*
* Lookup for target in global target list.
*/
@@ -117,20 +114,20 @@ dm_target_lookup(const char *dm_target_name)
dmt = dm_target_lookup_name(dm_target_name);
if (dmt != NULL)
dm_target_busy(dmt);
-
+
mutex_exit(&dm_target_mutex);
-
- return dmt;
+
+ return dmt;
}
-
/*
* Search for name in TAIL and return apropriate pointer.
*/
-static dm_target_t*
+static dm_target_t *
dm_target_lookup_name(const char *dm_target_name)
{
dm_target_t *dm_target;
- int dlen; int slen;
+ int dlen;
+ int slen;
slen = strlen(dm_target_name) + 1;
@@ -138,24 +135,23 @@ dm_target_lookup_name(const char *dm_target_name)
dlen = strlen(dm_target->name) + 1;
if (dlen != slen)
continue;
-
+
if (strncmp(dm_target_name, dm_target->name, slen) == 0)
return dm_target;
}
return NULL;
}
-
/*
* Insert new target struct into the TAIL.
* dm_target
* contains name, version, function pointer to specifif target functions.
*/
int
-dm_target_insert(dm_target_t *dm_target)
+dm_target_insert(dm_target_t * dm_target)
{
dm_target_t *dmt;
-
+
mutex_enter(&dm_target_mutex);
dmt = dm_target_lookup_name(dm_target->name);
@@ -163,11 +159,10 @@ dm_target_insert(dm_target_t *dm_target)
mutex_exit(&dm_target_mutex);
return EEXIST;
}
-
TAILQ_INSERT_TAIL(&dm_target_list, dm_target, dm_target_next);
mutex_exit(&dm_target_mutex);
-
+
return 0;
}
@@ -179,32 +174,29 @@ int
dm_target_rem(char *dm_target_name)
{
dm_target_t *dmt;
-
+
KASSERT(dm_target_name != NULL);
mutex_enter(&dm_target_mutex);
-
+
dmt = dm_target_lookup_name(dm_target_name);
if (dmt == NULL) {
mutex_exit(&dm_target_mutex);
return ENOENT;
}
-
if (dmt->ref_cnt > 0) {
mutex_exit(&dm_target_mutex);
return EBUSY;
}
-
TAILQ_REMOVE(&dm_target_list,
dmt, dm_target_next);
mutex_exit(&dm_target_mutex);
-
- (void)kmem_free(dmt, sizeof(dm_target_t));
+
+ (void) kmem_free(dmt, sizeof(dm_target_t));
return 0;
}
-
/*
* Destroy all targets and remove them from queue.
* This routine is called from dm_detach, before module
@@ -216,38 +208,36 @@ dm_target_destroy(void)
dm_target_t *dm_target;
mutex_enter(&dm_target_mutex);
- while (TAILQ_FIRST(&dm_target_list) != NULL){
+ while (TAILQ_FIRST(&dm_target_list) != NULL) {
dm_target = TAILQ_FIRST(&dm_target_list);
-
+
TAILQ_REMOVE(&dm_target_list, TAILQ_FIRST(&dm_target_list),
- dm_target_next);
-
- (void)kmem_free(dm_target, sizeof(dm_target_t));
+ dm_target_next);
+
+ (void) kmem_free(dm_target, sizeof(dm_target_t));
}
mutex_exit(&dm_target_mutex);
-
+
mutex_destroy(&dm_target_mutex);
-
+
return 0;
}
-
/*
* Allocate new target entry.
*/
-dm_target_t*
+dm_target_t *
dm_target_alloc(const char *name)
{
return kmem_zalloc(sizeof(dm_target_t), KM_SLEEP);
}
-
/*
* Return prop_array of dm_target dictionaries.
*/
prop_array_t
dm_target_prop_list(void)
{
- prop_array_t target_array,ver;
+ prop_array_t target_array, ver;
prop_dictionary_t target_dict;
dm_target_t *dm_target;
@@ -256,10 +246,10 @@ dm_target_prop_list(void)
target_array = prop_array_create();
mutex_enter(&dm_target_mutex);
-
- TAILQ_FOREACH (dm_target, &dm_target_list, dm_target_next){
- target_dict = prop_dictionary_create();
+ TAILQ_FOREACH(dm_target, &dm_target_list, dm_target_next) {
+
+ target_dict = prop_dictionary_create();
ver = prop_array_create();
prop_dictionary_set_cstring(target_dict, DM_TARGETS_NAME,
dm_target->name);
@@ -275,24 +265,23 @@ dm_target_prop_list(void)
}
mutex_exit(&dm_target_mutex);
-
+
return target_array;
}
-
/* Initialize dm_target subsystem. */
int
dm_target_init(void)
{
- dm_target_t *dmt,*dmt3;
+ dm_target_t *dmt, *dmt3;
int r;
r = 0;
mutex_init(&dm_target_mutex, MUTEX_DEFAULT, IPL_NONE);
-
+
dmt = dm_target_alloc("linear");
dmt3 = dm_target_alloc("striped");
-
+
dmt->version[0] = 1;
dmt->version[1] = 0;
dmt->version[2] = 2;
@@ -303,9 +292,9 @@ dm_target_init(void)
dmt->deps = &dm_target_linear_deps;
dmt->destroy = &dm_target_linear_destroy;
dmt->upcall = &dm_target_linear_upcall;
-
+
r = dm_target_insert(dmt);
-
+
dmt3->version[0] = 1;
dmt3->version[1] = 0;
dmt3->version[2] = 3;
@@ -316,10 +305,10 @@ dm_target_init(void)
dmt3->deps = &dm_target_stripe_deps;
dmt3->destroy = &dm_target_stripe_destroy;
dmt3->upcall = &dm_target_stripe_upcall;
-
+
r = dm_target_insert(dmt3);
-#ifdef notyet
+#ifdef notyet
dmt5->version[0] = 1;
dmt5->version[1] = 0;
dmt5->version[2] = 5;
@@ -330,9 +319,9 @@ dm_target_init(void)
dmt5->deps = &dm_target_snapshot_deps;
dmt5->destroy = &dm_target_snapshot_destroy;
dmt5->upcall = &dm_target_snapshot_upcall;
-
+
r = dm_target_insert(dmt5);
-
+
dmt6->version[0] = 1;
dmt6->version[1] = 0;
dmt6->version[2] = 5;
@@ -346,6 +335,6 @@ dm_target_init(void)
r = dm_target_insert(dmt6);
#endif
-
+
return r;
}
diff --git a/sys/dev/dm/dm_target_error.c b/sys/dev/dm/dm_target_error.c
index f2ac12ae271..e93509a78ff 100644
--- a/sys/dev/dm/dm_target_error.c
+++ b/sys/dev/dm/dm_target_error.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target_error.c,v 1.9 2009/12/01 23:12:10 haad Exp $ */
+/* $NetBSD: dm_target_error.c,v 1.10 2010/01/04 00:12:22 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,15 +58,15 @@ dm_target_error_modcmd(modcmd_t cmd, void *arg)
dm_target_t *dmt;
int r;
dmt = NULL;
-
+
switch (cmd) {
case MODULE_CMD_INIT:
- if ((dmt = dm_target_lookup("error")) != NULL){
+ if ((dmt = dm_target_lookup("error")) != NULL) {
dm_target_unbusy(dmt);
return EEXIST;
}
dmt = dm_target_alloc("error");
-
+
dmt->version[0] = 1;
dmt->version[1] = 0;
dmt->version[2] = 0;
@@ -79,7 +79,7 @@ dm_target_error_modcmd(modcmd_t cmd, void *arg)
dmt->upcall = &dm_target_error_upcall;
r = dm_target_insert(dmt);
-
+
break;
case MODULE_CMD_FINI:
@@ -95,12 +95,11 @@ dm_target_error_modcmd(modcmd_t cmd, void *arg)
return r;
}
-
#endif
/* Init function called from dm_table_load_ioctl. */
int
-dm_target_error_init(dm_dev_t *dmv, void **target_config, char *argv)
+dm_target_error_init(dm_dev_t * dmv, void **target_config, char *argv)
{
printf("Error target init function called!!\n");
@@ -108,20 +107,18 @@ dm_target_error_init(dm_dev_t *dmv, void **target_config, char *argv)
*target_config = NULL;
dmv->dev_type = DM_ERROR_DEV;
-
+
return 0;
}
-
/* Status routine called to get params string. */
char *
dm_target_error_status(void *target_config)
{
return NULL;
-}
-
+}
/* Strategy routine called from dm_strategy. */
int
-dm_target_error_strategy(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_error_strategy(dm_table_entry_t * table_en, struct buf * bp)
{
printf("Error target read function called!!\n");
@@ -130,32 +127,29 @@ dm_target_error_strategy(dm_table_entry_t *table_en, struct buf *bp)
bp->b_resid = 0;
biodone(bp);
-
+
return 0;
}
-
/* Doesn't do anything here. */
int
-dm_target_error_destroy(dm_table_entry_t *table_en)
+dm_target_error_destroy(dm_table_entry_t * table_en)
{
table_en->target_config = NULL;
/* Unbusy target so we can unload it */
dm_target_unbusy(table_en->target);
-
+
return 0;
}
-
/* Doesn't not need to do anything here. */
int
-dm_target_error_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
-{
+dm_target_error_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
+{
return 0;
}
-
/* Unsupported for this target. */
int
-dm_target_error_upcall(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_error_upcall(dm_table_entry_t * table_en, struct buf * bp)
{
return 0;
}
diff --git a/sys/dev/dm/dm_target_linear.c b/sys/dev/dm/dm_target_linear.c
index 62429a94843..a6a93611e2d 100644
--- a/sys/dev/dm/dm_target_linear.c
+++ b/sys/dev/dm/dm_target_linear.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target_linear.c,v 1.8 2009/12/01 23:12:10 haad Exp $ */
+/* $NetBSD: dm_target_linear.c,v 1.9 2010/01/04 00:14:41 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -48,56 +48,55 @@
/*
* Allocate target specific config data, and link them to table.
* This function is called only when, flags is not READONLY and
- * therefore we can add things to pdev list. This should not a
+ * therefore we can add things to pdev list. This should not a
* problem because this routine is called only from dm_table_load_ioctl.
* @argv[0] is name,
* @argv[1] is physical data offset.
*/
int
-dm_target_linear_init(dm_dev_t *dmv, void **target_config, char *params)
+dm_target_linear_init(dm_dev_t * dmv, void **target_config, char *params)
{
dm_target_linear_config_t *tlc;
dm_pdev_t *dmp;
char **ap, *argv[3];
- if(params == NULL)
+ if (params == NULL)
return EINVAL;
-
+
/*
* Parse a string, containing tokens delimited by white space,
* into an argument vector
*/
for (ap = argv; ap < &argv[2] &&
- (*ap = strsep(&params, " \t")) != NULL;) {
+ (*ap = strsep(&params, " \t")) != NULL;) {
if (**ap != '\0')
ap++;
}
aprint_debug("Linear target init function called %s--%s!!\n",
argv[0], argv[1]);
-
+
/* Insert dmp to global pdev list */
if ((dmp = dm_pdev_insert(argv[0])) == NULL)
return ENOENT;
-
+
if ((tlc = kmem_alloc(sizeof(dm_target_linear_config_t), KM_SLEEP))
== NULL)
return ENOMEM;
tlc->pdev = dmp;
- tlc->offset = 0; /* default settings */
-
+ tlc->offset = 0; /* default settings */
+
/* Check user input if it is not leave offset as 0. */
tlc->offset = atoi(argv[1]);
- *target_config = tlc;
+ *target_config = tlc;
dmv->dev_type = DM_LINEAR_DEV;
-
+
return 0;
}
-
/*
* Status routine is called to get params string, which is target
* specific. When dm_table_status_ioctl is called with flag
@@ -115,39 +114,37 @@ dm_target_linear_status(void *target_config)
if ((params = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_NOSLEEP)) == NULL)
return NULL;
- aprint_normal("%s %"PRIu64, tlc->pdev->name, tlc->offset);
- snprintf(params, DM_MAX_PARAMS_SIZE,"%s %"PRIu64,
+ aprint_normal("%s %" PRIu64, tlc->pdev->name, tlc->offset);
+ snprintf(params, DM_MAX_PARAMS_SIZE, "%s %" PRIu64,
tlc->pdev->name, tlc->offset);
return params;
}
-
/*
* Do IO operation, called from dmstrategy routine.
*/
int
-dm_target_linear_strategy(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_linear_strategy(dm_table_entry_t * table_en, struct buf * bp)
{
dm_target_linear_config_t *tlc;
tlc = table_en->target_config;
-
+
/* printf("Linear target read function called %" PRIu64 "!!\n",
tlc->offset);*/
bp->b_blkno += tlc->offset;
-
+
VOP_STRATEGY(tlc->pdev->pdev_vnode, bp);
-
+
return 0;
}
-
/*
* Destroy target specific data. Decrement table pdevs.
*/
int
-dm_target_linear_destroy(dm_table_entry_t *table_en)
+dm_target_linear_destroy(dm_table_entry_t * table_en)
{
dm_target_linear_config_t *tlc;
@@ -155,58 +152,55 @@ dm_target_linear_destroy(dm_table_entry_t *table_en)
* Destroy function is called for every target even if it
* doesn't have target_config.
*/
-
+
if (table_en->target_config == NULL)
return 0;
-
+
tlc = table_en->target_config;
-
+
/* Decrement pdev ref counter if 0 remove it */
dm_pdev_decr(tlc->pdev);
-
+
/* Unbusy target so we can unload it */
dm_target_unbusy(table_en->target);
-
+
kmem_free(table_en->target_config, sizeof(dm_target_linear_config_t));
table_en->target_config = NULL;
-
+
return 0;
}
-
/* Add this target pdev dependiences to prop_array_t */
int
-dm_target_linear_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
+dm_target_linear_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
{
dm_target_linear_config_t *tlc;
struct vattr va;
-
+
int error;
-
+
if (table_en->target_config == NULL)
return ENOENT;
-
+
tlc = table_en->target_config;
-
+
if ((error = VOP_GETATTR(tlc->pdev->pdev_vnode, &va, curlwp->l_cred)) != 0)
return error;
-
- prop_array_add_uint64(prop_array, (uint64_t)va.va_rdev);
-
+
+ prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
+
return 0;
}
-
/*
* Register upcall device.
* Linear target doesn't need any upcall devices but other targets like
* mirror, snapshot, multipath, stripe will use this functionality.
*/
int
-dm_target_linear_upcall(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_linear_upcall(dm_table_entry_t * table_en, struct buf * bp)
{
return 0;
}
-
/*
* Transform char s to uint64_t offset number.
*/
diff --git a/sys/dev/dm/dm_target_mirror.c b/sys/dev/dm/dm_target_mirror.c
index f04a6490f3b..65a7a5badbb 100644
--- a/sys/dev/dm/dm_target_mirror.c
+++ b/sys/dev/dm/dm_target_mirror.c
@@ -1,4 +1,4 @@
-/*$NetBSD: dm_target_mirror.c,v 1.7 2009/12/01 23:12:10 haad Exp $*/
+/*$NetBSD: dm_target_mirror.c,v 1.8 2010/01/04 00:12:22 haad Exp $*/
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -58,15 +58,15 @@ dm_target_mirror_modcmd(modcmd_t cmd, void *arg)
dm_target_t *dmt;
int r;
dmt = NULL;
-
+
switch (cmd) {
case MODULE_CMD_INIT:
- if ((dmt = dm_target_lookup("mirror")) != NULL){
+ if ((dmt = dm_target_lookup("mirror")) != NULL) {
dm_target_unbusy(dmt);
return EEXIST;
}
dmt = dm_target_alloc("mirror");
-
+
dmt->version[0] = 1;
dmt->version[1] = 0;
dmt->version[2] = 0;
@@ -79,7 +79,7 @@ dm_target_mirror_modcmd(modcmd_t cmd, void *arg)
dmt->upcall = &dm_target_mirror_upcall;
r = dm_target_insert(dmt);
-
+
break;
case MODULE_CMD_FINI:
@@ -95,7 +95,6 @@ dm_target_mirror_modcmd(modcmd_t cmd, void *arg)
return r;
}
-
#endif
/*
@@ -104,7 +103,7 @@ dm_target_mirror_modcmd(modcmd_t cmd, void *arg)
* 0 52428800 mirror clustered_disk 4 253:2 1024 UUID block_on_error 3 253:3 0 253:4 0 253:5 0
*/
int
-dm_target_mirror_init(dm_dev_t *dmv, void **target_config, char *argv)
+dm_target_mirror_init(dm_dev_t * dmv, void **target_config, char *argv)
{
printf("Mirror target init function called!!\n");
@@ -112,20 +111,18 @@ dm_target_mirror_init(dm_dev_t *dmv, void **target_config, char *argv)
*target_config = NULL;
dmv->dev_type = DM_MIRROR_DEV;
-
+
return ENOSYS;
}
-
/* Status routine called to get params string. */
char *
dm_target_mirror_status(void *target_config)
{
return NULL;
-}
-
+}
/* Strategy routine called from dm_strategy. */
int
-dm_target_mirror_strategy(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_mirror_strategy(dm_table_entry_t * table_en, struct buf * bp)
{
printf("Mirror target read function called!!\n");
@@ -134,32 +131,29 @@ dm_target_mirror_strategy(dm_table_entry_t *table_en, struct buf *bp)
bp->b_resid = 0;
biodone(bp);
-
+
return 0;
}
-
/* Doesn't do anything here. */
int
-dm_target_mirror_destroy(dm_table_entry_t *table_en)
+dm_target_mirror_destroy(dm_table_entry_t * table_en)
{
table_en->target_config = NULL;
/* Unbusy target so we can unload it */
dm_target_unbusy(table_en->target);
-
+
return 0;
}
-
/* Doesn't not need to do anything here. */
int
-dm_target_mirror_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
-{
+dm_target_mirror_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
+{
return 0;
}
-
/* Unsupported for this target. */
int
-dm_target_mirror_upcall(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_mirror_upcall(dm_table_entry_t * table_en, struct buf * bp)
{
return 0;
}
diff --git a/sys/dev/dm/dm_target_snapshot.c b/sys/dev/dm/dm_target_snapshot.c
index 8f710790ebb..3a7709e8072 100644
--- a/sys/dev/dm/dm_target_snapshot.c
+++ b/sys/dev/dm/dm_target_snapshot.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target_snapshot.c,v 1.11 2009/12/01 23:12:10 haad Exp $ */
+/* $NetBSD: dm_target_snapshot.c,v 1.12 2010/01/04 00:12:22 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
*
* After snapshot creation
* |my_data_org;0 1024 linear /dev/sd1a 384|
- * /
+ * /
* |my_data; 0 1024 snapshot-origin /dev/vg00/my_data_org|
* /
* |my_data_snap; 0 1024 snapshot /dev/vg00/my_data /dev/mapper/my_data_cow P 8
@@ -106,19 +106,17 @@ dm_target_snapshot_modcmd(modcmd_t cmd, void *arg)
dmt = NULL;
dmt1 = NULL;
-
+
switch (cmd) {
case MODULE_CMD_INIT:
if (((dmt = dm_target_lookup("snapshot")) != NULL)) {
dm_target_unbusy(dmt);
return EEXIST;
}
-
- if (((dmt = dm_target_lookup("snapshot-origin")) != NULL)){
+ if (((dmt = dm_target_lookup("snapshot-origin")) != NULL)) {
dm_target_unbusy(dmt);
return EEXIST;
}
-
dmt = dm_target_alloc("snapshot");
dmt1 = dm_target_alloc("snapshot-origin");
@@ -169,16 +167,15 @@ dm_target_snapshot_modcmd(modcmd_t cmd, void *arg)
return r;
}
-
#endif
/*
* Init function called from dm_table_load_ioctl.
- * argv: /dev/mapper/my_data_org /dev/mapper/tsc_cow_dev p 64
+ * argv: /dev/mapper/my_data_org /dev/mapper/tsc_cow_dev p 64
* snapshot_origin device, cow device, persistent flag, chunk size
*/
int
-dm_target_snapshot_init(dm_dev_t *dmv, void **target_config, char *params)
+dm_target_snapshot_init(dm_dev_t * dmv, void **target_config, char *params)
{
dm_target_snapshot_config_t *tsc;
dm_pdev_t *dmp_snap, *dmp_cow;
@@ -193,46 +190,44 @@ dm_target_snapshot_init(dm_dev_t *dmv, void **target_config, char *params)
* into an argument vector
*/
for (ap = argv; ap < &argv[4] &&
- (*ap = strsep(&params, " \t")) != NULL;) {
+ (*ap = strsep(&params, " \t")) != NULL;) {
if (**ap != '\0')
ap++;
}
-
+
printf("Snapshot target init function called!!\n");
printf("Snapshotted device: %s, cow device %s,\n\t persistent flag: %s, "
"chunk size: %s\n", argv[0], argv[1], argv[2], argv[3]);
-
+
/* Insert snap device to global pdev list */
if ((dmp_snap = dm_pdev_insert(argv[0])) == NULL)
return ENOENT;
-
+
if ((tsc = kmem_alloc(sizeof(dm_target_snapshot_config_t), KM_NOSLEEP))
== NULL)
return 1;
-
+
tsc->tsc_persistent_dev = 0;
-
+
/* There is now cow device for nonpersistent snapshot devices */
if (strcmp(argv[2], "p") == 0) {
tsc->tsc_persistent_dev = 1;
-
+
/* Insert cow device to global pdev list */
if ((dmp_cow = dm_pdev_insert(argv[1])) == NULL)
- return ENOENT;
+ return ENOENT;
}
-
tsc->tsc_chunk_size = atoi(argv[3]);
-
+
tsc->tsc_snap_dev = dmp_snap;
tsc->tsc_cow_dev = dmp_cow;
-
+
*target_config = tsc;
-
+
dmv->dev_type = DM_SNAPSHOT_DEV;
-
+
return 0;
}
-
/*
* Status routine is called to get params string, which is target
* specific. When dm_table_status_ioctl is called with flag
@@ -242,14 +237,14 @@ char *
dm_target_snapshot_status(void *target_config)
{
dm_target_snapshot_config_t *tsc;
-
+
uint32_t i;
uint32_t count;
size_t prm_len, cow_len;
char *params, *cow_name;
-
+
tsc = target_config;
-
+
prm_len = 0;
cow_len = 0;
count = 0;
@@ -258,33 +253,32 @@ dm_target_snapshot_status(void *target_config)
printf("Snapshot target status function called\n");
/* count number of chars in offset */
- for(i = tsc->tsc_chunk_size; i != 0; i /= 10)
+ for (i = tsc->tsc_chunk_size; i != 0; i /= 10)
count++;
-
- if(tsc->tsc_persistent_dev)
+
+ if (tsc->tsc_persistent_dev)
cow_len = strlen(tsc->tsc_cow_dev->name);
-
+
/* length of names + count of chars + spaces and null char */
prm_len = strlen(tsc->tsc_snap_dev->name) + cow_len + count + 5;
-
+
if ((params = kmem_alloc(prm_len, KM_NOSLEEP)) == NULL)
return NULL;
- printf("%s %s %s %"PRIu64"\n", tsc->tsc_snap_dev->name,
- tsc->tsc_cow_dev->name, tsc->tsc_persistent_dev ? "p":"n",
- tsc->tsc_chunk_size);
-
- snprintf(params, prm_len, "%s %s %s %"PRIu64, tsc->tsc_snap_dev->name,
- tsc->tsc_persistent_dev ? tsc->tsc_cow_dev->name : "",
- tsc->tsc_persistent_dev ? "p":"n",
- tsc->tsc_chunk_size);
-
+ printf("%s %s %s %" PRIu64 "\n", tsc->tsc_snap_dev->name,
+ tsc->tsc_cow_dev->name, tsc->tsc_persistent_dev ? "p" : "n",
+ tsc->tsc_chunk_size);
+
+ snprintf(params, prm_len, "%s %s %s %" PRIu64, tsc->tsc_snap_dev->name,
+ tsc->tsc_persistent_dev ? tsc->tsc_cow_dev->name : "",
+ tsc->tsc_persistent_dev ? "p" : "n",
+ tsc->tsc_chunk_size);
+
return params;
}
-
/* Strategy routine called from dm_strategy. */
int
-dm_target_snapshot_strategy(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_snapshot_strategy(dm_table_entry_t * table_en, struct buf * bp)
{
printf("Snapshot target read function called!!\n");
@@ -293,90 +287,85 @@ dm_target_snapshot_strategy(dm_table_entry_t *table_en, struct buf *bp)
bp->b_resid = 0;
biodone(bp);
-
+
return 0;
}
-
/* Doesn't do anything here. */
int
-dm_target_snapshot_destroy(dm_table_entry_t *table_en)
+dm_target_snapshot_destroy(dm_table_entry_t * table_en)
{
dm_target_snapshot_config_t *tsc;
-
+
/*
* Destroy function is called for every target even if it
* doesn't have target_config.
*/
-
+
if (table_en->target_config == NULL)
return 0;
-
+
printf("Snapshot target destroy function called\n");
-
+
tsc = table_en->target_config;
-
+
/* Decrement pdev ref counter if 0 remove it */
dm_pdev_decr(tsc->tsc_snap_dev);
-
+
if (tsc->tsc_persistent_dev)
dm_pdev_decr(tsc->tsc_cow_dev);
- /* Unbusy target so we can unload it */
+ /* Unbusy target so we can unload it */
dm_target_unbusy(table_en->target);
-
+
kmem_free(table_en->target_config, sizeof(dm_target_snapshot_config_t));
table_en->target_config = NULL;
return 0;
}
-
/* Add this target dependiences to prop_array_t */
int
-dm_target_snapshot_deps(dm_table_entry_t *table_en,
- prop_array_t prop_array)
+dm_target_snapshot_deps(dm_table_entry_t * table_en,
+ prop_array_t prop_array)
{
dm_target_snapshot_config_t *tsc;
struct vattr va;
-
+
int error;
-
+
if (table_en->target_config == NULL)
return 0;
tsc = table_en->target_config;
-
+
if ((error = VOP_GETATTR(tsc->tsc_snap_dev->pdev_vnode, &va, curlwp->l_cred)) != 0)
return error;
-
- prop_array_add_uint64(prop_array, (uint64_t)va.va_rdev);
-
+
+ prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
+
if (tsc->tsc_persistent_dev) {
-
- if ((error = VOP_GETATTR(tsc->tsc_cow_dev->pdev_vnode, &va,
- curlwp->l_cred)) != 0)
+
+ if ((error = VOP_GETATTR(tsc->tsc_cow_dev->pdev_vnode, &va,
+ curlwp->l_cred)) != 0)
return error;
- prop_array_add_uint64(prop_array, (uint64_t)va.va_rdev);
-
+ prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
+
}
-
return 0;
}
-
/* Upcall is used to inform other depended devices about IO. */
int
-dm_target_snapshot_upcall(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_snapshot_upcall(dm_table_entry_t * table_en, struct buf * bp)
{
printf("dm_target_snapshot_upcall called\n");
-
- printf("upcall buf flags %s %s\n",
- (bp->b_flags & B_WRITE) ? "B_WRITE":"",
- (bp->b_flags & B_READ) ? "B_READ":"");
-
+
+ printf("upcall buf flags %s %s\n",
+ (bp->b_flags & B_WRITE) ? "B_WRITE" : "",
+ (bp->b_flags & B_READ) ? "B_READ" : "");
+
return 0;
}
-
/*
* dm target snapshot origin routines.
*
@@ -386,41 +375,40 @@ dm_target_snapshot_upcall(dm_table_entry_t *table_en, struct buf *bp)
* snapshot device when write is done on master device.
*/
-/*
- * Init function called from dm_table_load_ioctl.
- *
+/*
+ * Init function called from dm_table_load_ioctl.
+ *
* argv: /dev/mapper/my_data_real
*/
int
-dm_target_snapshot_orig_init(dm_dev_t *dmv, void **target_config,
- prop_dictionary_t dict)
+dm_target_snapshot_orig_init(dm_dev_t * dmv, void **target_config,
+ prop_dictionary_t dict)
{
dm_target_snapshot_origin_config_t *tsoc;
dm_pdev_t *dmp_real;
if (params == NULL)
return EINVAL;
-
+
printf("Snapshot origin target init function called!!\n");
printf("Parent device: %s\n", params);
/* Insert snap device to global pdev list */
if ((dmp_real = dm_pdev_insert(params)) == NULL)
return ENOENT;
-
+
if ((tsoc = kmem_alloc(sizeof(dm_target_snapshot_origin_config_t), KM_NOSLEEP))
== NULL)
return 1;
tsoc->tsoc_real_dev = dmp_real;
-
+
dmv->dev_type = DM_SNAPSHOT_ORIG_DEV;
-
+
*target_config = tsoc;
-
+
return 0;
}
-
/*
* Status routine is called to get params string, which is target
* specific. When dm_table_status_ioctl is called with flag
@@ -433,31 +421,30 @@ dm_target_snapshot_orig_status(void *target_config)
size_t prm_len;
char *params;
-
+
tsoc = target_config;
-
+
prm_len = 0;
-
+
printf("Snapshot origin target status function called\n");
-
+
/* length of names + count of chars + spaces and null char */
prm_len = strlen(tsoc->tsoc_real_dev->name) + 1;
-
- printf("real_dev name %s\n",tsoc->tsoc_real_dev->name);
-
+
+ printf("real_dev name %s\n", tsoc->tsoc_real_dev->name);
+
if ((params = kmem_alloc(prm_len, KM_NOSLEEP)) == NULL)
return NULL;
printf("%s\n", tsoc->tsoc_real_dev->name);
-
+
snprintf(params, prm_len, "%s", tsoc->tsoc_real_dev->name);
-
+
return params;
}
-
/* Strategy routine called from dm_strategy. */
int
-dm_target_snapshot_orig_strategy(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_snapshot_orig_strategy(dm_table_entry_t * table_en, struct buf * bp)
{
printf("Snapshot_Orig target read function called!!\n");
@@ -466,68 +453,65 @@ dm_target_snapshot_orig_strategy(dm_table_entry_t *table_en, struct buf *bp)
bp->b_resid = 0;
biodone(bp);
-
+
return 0;
}
-
/* Decrement pdev and free allocated space. */
int
-dm_target_snapshot_orig_destroy(dm_table_entry_t *table_en)
+dm_target_snapshot_orig_destroy(dm_table_entry_t * table_en)
{
dm_target_snapshot_origin_config_t *tsoc;
-
+
/*
* Destroy function is called for every target even if it
* doesn't have target_config.
*/
-
+
if (table_en->target_config == NULL)
return 0;
-
+
tsoc = table_en->target_config;
-
+
/* Decrement pdev ref counter if 0 remove it */
dm_pdev_decr(tsoc->tsoc_real_dev);
/* Unbusy target so we can unload it */
dm_target_unbusy(table_en->target);
-
+
kmem_free(table_en->target_config, sizeof(dm_target_snapshot_origin_config_t));
table_en->target_config = NULL;
return 0;
}
-
/*
* Get target deps and add them to prop_array_t.
*/
int
-dm_target_snapshot_orig_deps(dm_table_entry_t *table_en,
- prop_array_t prop_array)
+dm_target_snapshot_orig_deps(dm_table_entry_t * table_en,
+ prop_array_t prop_array)
{
dm_target_snapshot_origin_config_t *tsoc;
struct vattr va;
-
+
int error;
-
+
if (table_en->target_config == NULL)
return 0;
tsoc = table_en->target_config;
-
- if ((error = VOP_GETATTR(tsoc->tsoc_real_dev->pdev_vnode, &va,
- curlwp->l_cred)) != 0)
+
+ if ((error = VOP_GETATTR(tsoc->tsoc_real_dev->pdev_vnode, &va,
+ curlwp->l_cred)) != 0)
return error;
-
- prop_array_add_uint64(prop_array, (uint64_t)va.va_rdev);
-
+
+ prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
+
return 0;
}
-
/* Unsupported for this target. */
int
-dm_target_snapshot_orig_upcall(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_snapshot_orig_upcall(dm_table_entry_t * table_en, struct buf * bp)
{
return 0;
}
diff --git a/sys/dev/dm/dm_target_stripe.c b/sys/dev/dm/dm_target_stripe.c
index 38352dba752..06fdf3b9234 100644
--- a/sys/dev/dm/dm_target_stripe.c
+++ b/sys/dev/dm/dm_target_stripe.c
@@ -1,4 +1,4 @@
-/*$NetBSD: dm_target_stripe.c,v 1.8 2009/12/01 23:12:10 haad Exp $*/
+/*$NetBSD: dm_target_stripe.c,v 1.9 2010/01/04 00:14:41 haad Exp $*/
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -60,16 +60,15 @@ dm_target_stripe_modcmd(modcmd_t cmd, void *arg)
dm_target_t *dmt;
int r;
dmt = NULL;
-
+
switch (cmd) {
case MODULE_CMD_INIT:
if ((dmt = dm_target_lookup("stripe")) != NULL) {
dm_target_unbusy(dmt);
return EEXIST;
}
-
dmt = dm_target_alloc("stripe");
-
+
dmt->version[0] = 1;
dmt->version[1] = 0;
dmt->version[2] = 0;
@@ -82,7 +81,7 @@ dm_target_stripe_modcmd(modcmd_t cmd, void *arg)
dmt->upcall = &dm_target_stripe_upcall;
r = dm_target_insert(dmt);
-
+
break;
case MODULE_CMD_FINI:
@@ -98,7 +97,6 @@ dm_target_stripe_modcmd(modcmd_t cmd, void *arg)
return r;
}
-
#endif
/*
@@ -108,27 +106,27 @@ dm_target_stripe_modcmd(modcmd_t cmd, void *arg)
* 0 65536 striped 2 512 /dev/hda 0 /dev/hdb 0
*/
int
-dm_target_stripe_init(dm_dev_t *dmv, void **target_config, char *params)
+dm_target_stripe_init(dm_dev_t * dmv, void **target_config, char *params)
{
dm_target_stripe_config_t *tsc;
size_t len;
char **ap, *argv[10];
- if(params == NULL)
+ if (params == NULL)
return EINVAL;
len = strlen(params) + 1;
-
+
/*
* Parse a string, containing tokens delimited by white space,
* into an argument vector
*/
for (ap = argv; ap < &argv[9] &&
- (*ap = strsep(&params, " \t")) != NULL;) {
+ (*ap = strsep(&params, " \t")) != NULL;) {
if (**ap != '\0')
ap++;
}
-
+
printf("Stripe target init function called!!\n");
printf("Stripe target chunk size %s number of stripes %s\n", argv[1], argv[0]);
@@ -141,7 +139,7 @@ dm_target_stripe_init(dm_dev_t *dmv, void **target_config, char *params)
if ((tsc = kmem_alloc(sizeof(dm_target_stripe_config_t), KM_NOSLEEP))
== NULL)
return ENOMEM;
-
+
/* Insert dmp to global pdev list */
if ((tsc->stripe_devs[0].pdev = dm_pdev_insert(argv[2])) == NULL)
return ENOENT;
@@ -156,15 +154,14 @@ dm_target_stripe_init(dm_dev_t *dmv, void **target_config, char *params)
/* Save length of param string */
tsc->params_len = len;
tsc->stripe_chunksize = atoi(argv[1]);
- tsc->stripe_num = (uint8_t)atoi(argv[0]);
-
+ tsc->stripe_num = (uint8_t) atoi(argv[0]);
+
*target_config = tsc;
dmv->dev_type = DM_STRIPE_DEV;
-
+
return 0;
}
-
/* Status routine called to get params string. */
char *
dm_target_stripe_status(void *target_config)
@@ -173,21 +170,20 @@ dm_target_stripe_status(void *target_config)
char *params;
tsc = target_config;
-
+
if ((params = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_SLEEP)) == NULL)
return NULL;
- snprintf(params, DM_MAX_PARAMS_SIZE, "%d %"PRIu64" %s %"PRIu64" %s %"PRIu64,
+ snprintf(params, DM_MAX_PARAMS_SIZE, "%d %" PRIu64 " %s %" PRIu64 " %s %" PRIu64,
tsc->stripe_num, tsc->stripe_chunksize,
tsc->stripe_devs[0].pdev->name, tsc->stripe_devs[0].offset,
tsc->stripe_devs[1].pdev->name, tsc->stripe_devs[1].offset);
-
- return params;
-}
+ return params;
+}
/* Strategy routine called from dm_strategy. */
int
-dm_target_stripe_strategy(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_stripe_strategy(dm_table_entry_t * table_en, struct buf * bp)
{
dm_target_stripe_config_t *tsc;
struct buf *nestbuf;
@@ -206,12 +202,12 @@ dm_target_stripe_strategy(dm_table_entry_t *table_en, struct buf *bp)
/* calculate extent of request */
KASSERT(bp->b_resid % DEV_BSIZE == 0);
- blkno = bp->b_blkno;
+ blkno = bp->b_blkno;
blkoff = 0;
num_blks = bp->b_resid / DEV_BSIZE;
for (;;) {
/* blockno to strip piece nr */
- stripe = blkno / tsc->stripe_chunksize;
+ stripe = blkno / tsc->stripe_chunksize;
stripe_off = blkno % tsc->stripe_chunksize;
/* where we are inside the strip */
@@ -231,8 +227,8 @@ dm_target_stripe_strategy(dm_table_entry_t *table_en, struct buf *bp)
VOP_STRATEGY(tsc->stripe_devs[stripe_devnr].pdev->pdev_vnode, nestbuf);
- blkno += issue_blks;
- blkoff += issue_blks * DEV_BSIZE;
+ blkno += issue_blks;
+ blkoff += issue_blks * DEV_BSIZE;
num_blks -= issue_blks;
if (num_blks <= 0)
@@ -241,61 +237,58 @@ dm_target_stripe_strategy(dm_table_entry_t *table_en, struct buf *bp)
return 0;
}
-
/* Doesn't do anything here. */
int
-dm_target_stripe_destroy(dm_table_entry_t *table_en)
+dm_target_stripe_destroy(dm_table_entry_t * table_en)
{
dm_target_stripe_config_t *tsc;
-
+
tsc = table_en->target_config;
if (tsc == NULL)
return 0;
-
+
dm_pdev_decr(tsc->stripe_devs[0].pdev);
dm_pdev_decr(tsc->stripe_devs[1].pdev);
/* Unbusy target so we can unload it */
dm_target_unbusy(table_en->target);
-
+
kmem_free(tsc, sizeof(dm_target_stripe_config_t));
-
+
table_en->target_config = NULL;
return 0;
}
-
/* Doesn't not need to do anything here. */
int
-dm_target_stripe_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
-{
+dm_target_stripe_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
+{
dm_target_stripe_config_t *tsc;
struct vattr va;
-
+
int error;
-
+
if (table_en->target_config == NULL)
return ENOENT;
-
+
tsc = table_en->target_config;
-
+
if ((error = VOP_GETATTR(tsc->stripe_devs[0].pdev->pdev_vnode, &va, curlwp->l_cred)) != 0)
return error;
- prop_array_add_uint64(prop_array, (uint64_t)va.va_rdev);
-
+ prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
+
if ((error = VOP_GETATTR(tsc->stripe_devs[1].pdev->pdev_vnode, &va, curlwp->l_cred)) != 0)
return error;
-
- prop_array_add_uint64(prop_array, (uint64_t)va.va_rdev);
-
+
+ prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
+
return 0;
}
-
/* Unsupported for this target. */
int
-dm_target_stripe_upcall(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_stripe_upcall(dm_table_entry_t * table_en, struct buf * bp)
{
return 0;
}
diff --git a/sys/dev/dm/dm_target_zero.c b/sys/dev/dm/dm_target_zero.c
index b92c88b1709..494988fb785 100644
--- a/sys/dev/dm/dm_target_zero.c
+++ b/sys/dev/dm/dm_target_zero.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target_zero.c,v 1.9 2009/12/01 23:12:10 haad Exp $ */
+/* $NetBSD: dm_target_zero.c,v 1.10 2010/01/04 00:12:22 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,15 +59,15 @@ dm_target_zero_modcmd(modcmd_t cmd, void *arg)
dm_target_t *dmt;
int r;
dmt = NULL;
-
+
switch (cmd) {
case MODULE_CMD_INIT:
- if ((dmt = dm_target_lookup("zero")) != NULL){
+ if ((dmt = dm_target_lookup("zero")) != NULL) {
dm_target_unbusy(dmt);
return EEXIST;
}
dmt = dm_target_alloc("zero");
-
+
dmt->version[0] = 1;
dmt->version[1] = 0;
dmt->version[2] = 0;
@@ -96,7 +96,6 @@ dm_target_zero_modcmd(modcmd_t cmd, void *arg)
return r;
}
-
#endif
/*
@@ -104,67 +103,62 @@ dm_target_zero_modcmd(modcmd_t cmd, void *arg)
* target specific config area.
*/
int
-dm_target_zero_init(dm_dev_t *dmv, void **target_config, char *argv)
+dm_target_zero_init(dm_dev_t * dmv, void **target_config, char *argv)
{
printf("Zero target init function called!!\n");
dmv->dev_type = DM_ZERO_DEV;
-
+
*target_config = NULL;
-
+
return 0;
}
-
/* Status routine called to get params string. */
char *
dm_target_zero_status(void *target_config)
{
return NULL;
-}
-
+}
+
/*
* This routine does IO operations.
*/
int
-dm_target_zero_strategy(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_zero_strategy(dm_table_entry_t * table_en, struct buf * bp)
{
/* printf("Zero target read function called %d!!\n", bp->b_bcount); */
- memset(bp->b_data, 0, bp->b_bcount);
- bp->b_resid = 0; /* nestiobuf_done wants b_resid = 0 to be sure
- that there is no other io to done */
-
+ memset(bp->b_data, 0, bp->b_bcount);
+ bp->b_resid = 0; /* nestiobuf_done wants b_resid = 0 to be sure
+ * that there is no other io to done */
+
biodone(bp);
return 0;
}
-
/* Doesn't not need to do anything here. */
int
-dm_target_zero_destroy(dm_table_entry_t *table_en)
+dm_target_zero_destroy(dm_table_entry_t * table_en)
{
table_en->target_config = NULL;
/* Unbusy target so we can unload it */
dm_target_unbusy(table_en->target);
-
+
return 0;
}
-
/* Doesn't not need to do anything here. */
int
-dm_target_zero_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
-{
+dm_target_zero_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
+{
return 0;
}
-
/* Unsuported for this target. */
int
-dm_target_zero_upcall(dm_table_entry_t *table_en, struct buf *bp)
+dm_target_zero_upcall(dm_table_entry_t * table_en, struct buf * bp)
{
return 0;
}
-