Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/dm Add old file describing locking schema used in dm...
details: https://anonhg.NetBSD.org/src/rev/646ca08a986c
branches: trunk
changeset: 758162:646ca08a986c
user: haad <haad%NetBSD.org@localhost>
date: Sat Oct 23 21:18:54 2010 +0000
description:
Add old file describing locking schema used in dm driver.
diffstat:
sys/dev/dm/device-mapper.c | 3 +-
sys/dev/dm/dm.h | 17 ++-
sys/dev/dm/dm_target_stripe.c | 109 ++++++++++------
sys/dev/dm/doc/locking.txt | 263 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 346 insertions(+), 46 deletions(-)
diffs (truncated from 548 to 300 lines):
diff -r 1d1e237038c1 -r 646ca08a986c sys/dev/dm/device-mapper.c
--- a/sys/dev/dm/device-mapper.c Sat Oct 23 15:27:50 2010 +0000
+++ b/sys/dev/dm/device-mapper.c Sat Oct 23 21:18:54 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: device-mapper.c,v 1.24 2010/10/09 12:56:06 haad Exp $ */
+/* $NetBSD: device-mapper.c,v 1.25 2010/10/23 21:18:54 haad Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -350,7 +350,6 @@
r = 0;
aprint_debug("dmioctl called\n");
-
KASSERT(data != NULL);
if (( r = disk_ioctl_switch(dev, cmd, data)) == ENOTTY) {
diff -r 1d1e237038c1 -r 646ca08a986c sys/dev/dm/dm.h
--- a/sys/dev/dm/dm.h Sat Oct 23 15:27:50 2010 +0000
+++ b/sys/dev/dm/dm.h Sat Oct 23 21:18:54 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm.h,v 1.18 2010/05/18 15:10:41 haad Exp $ */
+/* $NetBSD: dm.h,v 1.19 2010/10/23 21:18:54 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -170,12 +170,23 @@
typedef struct target_linear_config {
dm_pdev_t *pdev;
uint64_t offset;
+ TAILQ_ENTRY(target_linear_config) entries;
} dm_target_linear_config_t;
+/*
+ * Striping devices are stored in a linked list, this might be inefficient
+ * for more than 8 striping devices and can be changed to something more
+ * scalable.
+ * TODO: look for other options than linked list.
+ */
+TAILQ_HEAD(target_linear_devs, target_linear_config);
+
+typedef struct target_linear_devs dm_target_linear_devs_t;
+
/* for stripe : */
typedef struct target_stripe_config {
-#define MAX_STRIPES 2
- struct target_linear_config stripe_devs[MAX_STRIPES];
+#define DM_STRIPE_DEV_OFFSET 2
+ struct target_linear_devs stripe_devs;
uint8_t stripe_num;
uint64_t stripe_chunksize;
size_t params_len;
diff -r 1d1e237038c1 -r 646ca08a986c sys/dev/dm/dm_target_stripe.c
--- a/sys/dev/dm/dm_target_stripe.c Sat Oct 23 15:27:50 2010 +0000
+++ b/sys/dev/dm/dm_target_stripe.c Sat Oct 23 21:18:54 2010 +0000
@@ -1,4 +1,4 @@
-/*$NetBSD: dm_target_stripe.c,v 1.10 2010/05/18 15:10:41 haad Exp $*/
+/*$NetBSD: dm_target_stripe.c,v 1.11 2010/10/23 21:18:54 haad Exp $*/
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -102,6 +102,8 @@
/*
* Init function called from dm_table_load_ioctl.
+ * DM_STRIPE_DEV_OFFSET should always hold the index of the first device-offset
+ * pair in the parameters.
* Example line sent to dm from lvm tools when using striped target.
* start length striped #stripes chunk_size device1 offset1 ... deviceN offsetN
* 0 65536 striped 2 512 /dev/hda 0 /dev/hdb 0
@@ -109,9 +111,11 @@
int
dm_target_stripe_init(dm_dev_t * dmv, void **target_config, char *params)
{
+ dm_target_linear_config_t *tlc;
dm_target_stripe_config_t *tsc;
size_t len;
char **ap, *argv[10];
+ int strpc, strpi;
if (params == NULL)
return EINVAL;
@@ -130,33 +134,34 @@
printf("Stripe target init function called!!\n");
- printf("Stripe target chunk size %s number of stripes %s\n", argv[1], argv[0]);
- printf("Stripe target device name %s -- offset %s\n", argv[2], argv[3]);
- printf("Stripe target device name %s -- offset %s\n", argv[4], argv[5]);
+ printf("Stripe target chunk size %s number of stripes %s\n",
+ argv[1], argv[0]);
- if (atoi(argv[0]) > MAX_STRIPES)
- return ENOTSUP;
-
- if ((tsc = kmem_alloc(sizeof(dm_target_stripe_config_t), KM_NOSLEEP))
- == NULL)
+ if ((tsc = kmem_alloc(sizeof(*tsc), 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;
-
- /* Insert dmp to global pdev list */
- if ((tsc->stripe_devs[1].pdev = dm_pdev_insert(argv[4])) == NULL)
- return ENOENT;
-
- tsc->stripe_devs[0].offset = atoi(argv[3]);
- tsc->stripe_devs[1].offset = atoi(argv[5]);
+ /* Initialize linked list for striping devices */
+ TAILQ_INIT(&tsc->stripe_devs);
/* Save length of param string */
tsc->params_len = len;
tsc->stripe_chunksize = atoi(argv[1]);
tsc->stripe_num = (uint8_t) atoi(argv[0]);
+ strpc = DM_STRIPE_DEV_OFFSET + (tsc->stripe_num * 2);
+ for (strpi = DM_STRIPE_DEV_OFFSET; strpi < strpc; strpi += 2) {
+ printf("Stripe target device name %s -- offset %s\n",
+ argv[strpi], argv[strpi+1]);
+
+ tlc = kmem_alloc(sizeof(*tlc), KM_NOSLEEP);
+ if ((tlc->pdev = dm_pdev_insert(argv[strpi])) == NULL)
+ return ENOENT;
+ tlc->offset = atoi(argv[strpi+1]);
+
+ /* Insert striping device to linked list. */
+ TAILQ_INSERT_TAIL(&tsc->stripe_devs, tlc, entries);
+ }
+
*target_config = tsc;
dmv->dev_type = DM_STRIPE_DEV;
@@ -167,18 +172,28 @@
char *
dm_target_stripe_status(void *target_config)
{
+ dm_target_linear_config_t *tlc;
dm_target_stripe_config_t *tsc;
- char *params;
+ char *params, *tmp;
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,
- 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);
+ if ((tmp = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_SLEEP)) == NULL)
+ return NULL;
+
+ snprintf(params, DM_MAX_PARAMS_SIZE, "%d %" PRIu64,
+ tsc->stripe_num, tsc->stripe_chunksize);
+
+ TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) {
+ snprintf(tmp, DM_MAX_PARAMS_SIZE, " %s %" PRIu64,
+ tlc->pdev->name, tlc->offset);
+ strcat(params, tmp);
+ }
+
+ kmem_free(tmp, DM_MAX_PARAMS_SIZE);
return params;
}
@@ -186,12 +201,13 @@
int
dm_target_stripe_strategy(dm_table_entry_t * table_en, struct buf * bp)
{
+ dm_target_linear_config_t *tlc;
dm_target_stripe_config_t *tsc;
struct buf *nestbuf;
uint64_t blkno, blkoff;
uint64_t stripe, stripe_blknr;
uint32_t stripe_off, stripe_rest, num_blks, issue_blks;
- int stripe_devnr;
+ int i, stripe_devnr;
tsc = table_en->target_config;
if (tsc == NULL)
@@ -224,9 +240,17 @@
nestiobuf_setup(bp, nestbuf, blkoff, issue_blks * DEV_BSIZE);
nestbuf->b_blkno = stripe_blknr * tsc->stripe_chunksize + stripe_off;
- nestbuf->b_blkno += tsc->stripe_devs[stripe_devnr].offset;
+
+ tlc = TAILQ_FIRST(&tsc->stripe_devs);
+ for (i = 0; i < stripe_devnr && tlc == NULL; i++)
+ tlc = TAILQ_NEXT(tlc, entries);
- VOP_STRATEGY(tsc->stripe_devs[stripe_devnr].pdev->pdev_vnode, nestbuf);
+ /* by this point we should have an tlc */
+ KASSERT(tlc == NULL);
+
+ nestbuf->b_blkno += tlc->offset;
+
+ VOP_STRATEGY(tlc->pdev->pdev_vnode, nestbuf);
blkno += issue_blks;
blkoff += issue_blks * DEV_BSIZE;
@@ -242,16 +266,17 @@
int
dm_target_stripe_sync(dm_table_entry_t * table_en)
{
- int cmd, err, i;
+ int cmd, err;
dm_target_stripe_config_t *tsc;
+ dm_target_linear_config_t *tlc;
tsc = table_en->target_config;
err = 0;
cmd = 1;
- for (i = 0; i < tsc->stripe_num; i++) {
- if ((err = VOP_IOCTL(tsc->stripe_devs[i].pdev->pdev_vnode, DIOCCACHESYNC,
+ TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) {
+ if ((err = VOP_IOCTL(tlc->pdev->pdev_vnode, DIOCCACHESYNC,
&cmd, FREAD|FWRITE, kauth_cred_get())) != 0)
return err;
}
@@ -264,19 +289,23 @@
dm_target_stripe_destroy(dm_table_entry_t * table_en)
{
dm_target_stripe_config_t *tsc;
+ dm_target_linear_config_t *tlc;
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);
+ while ((tlc = TAILQ_FIRST(&tsc->stripe_devs)) != NULL) {
+ TAILQ_REMOVE(&tsc->stripe_devs, tlc, entries);
+ dm_pdev_decr(tlc->pdev);
+ kmem_free(tlc, sizeof(*tlc));
+ }
/* Unbusy target so we can unload it */
dm_target_unbusy(table_en->target);
- kmem_free(tsc, sizeof(dm_target_stripe_config_t));
+ kmem_free(tsc, sizeof(*tsc));
table_en->target_config = NULL;
@@ -287,6 +316,7 @@
dm_target_stripe_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
{
dm_target_stripe_config_t *tsc;
+ dm_target_linear_config_t *tlc;
struct vattr va;
int error;
@@ -296,15 +326,12 @@
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);
+ TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) {
+ if ((error = VOP_GETATTR(tlc->pdev->pdev_vnode, &va, curlwp->l_cred)) != 0)
+ return error;
- 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;
}
diff -r 1d1e237038c1 -r 646ca08a986c sys/dev/dm/doc/locking.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/dm/doc/locking.txt Sat Oct 23 21:18:54 2010 +0000
@@ -0,0 +1,263 @@
+
+ Device-mapper Locking architecture
+
+Overview
+
+There are 2 users in device-mapper driver
+ a) Users who uses disk drives
+ b) Users who uses ioctl management interface
+
+Management is done by dm_dev_*_ioctl and dm_table_*_ioctl routines. There are
+two major structures used in these routines/device-mapper.
+
+Table entry:
+
+typedef struct dm_table_entry {
Home |
Main Index |
Thread Index |
Old Index