Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/dm make dm aware of physical sector sizes.
details: https://anonhg.NetBSD.org/src/rev/07027bde2c52
branches: trunk
changeset: 759999:07027bde2c52
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Thu Dec 23 14:58:13 2010 +0000
description:
make dm aware of physical sector sizes.
For aggregates of multiple disks we use the largest sector size from
all disks. For standard power-of-2 sizes this is the same as the least
common multiple. We still require proper alignment of the targets in
the mapping table.
ok by haad@
diffstat:
sys/dev/dm/device-mapper.c | 21 ++++++++++++---------
sys/dev/dm/dm.h | 9 ++++++++-
sys/dev/dm/dm_pdev.c | 3 ++-
sys/dev/dm/dm_table.c | 37 ++++++++++++++++++++++++++++++++++++-
sys/dev/dm/dm_target.c | 4 +++-
sys/dev/dm/dm_target_linear.c | 22 +++++++++++++++++++++-
sys/dev/dm/dm_target_snapshot.c | 3 ++-
sys/dev/dm/dm_target_stripe.c | 29 ++++++++++++++++++++++++++++-
8 files changed, 112 insertions(+), 16 deletions(-)
diffs (truncated from 304 to 300 lines):
diff -r f41efd469b5f -r 07027bde2c52 sys/dev/dm/device-mapper.c
--- a/sys/dev/dm/device-mapper.c Thu Dec 23 14:46:25 2010 +0000
+++ b/sys/dev/dm/device-mapper.c Thu Dec 23 14:58:13 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: device-mapper.c,v 1.26 2010/12/06 09:12:23 haad Exp $ */
+/* $NetBSD: device-mapper.c,v 1.27 2010/12/23 14:58:13 mlelstv Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -440,6 +440,7 @@
case DIOCGWEDGEINFO:
{
struct dkwedge_info *dkw = (void *) data;
+ unsigned secsize;
if ((dmv = dm_dev_lookup(NULL, NULL, minor(dev))) == NULL)
return ENODEV;
@@ -451,7 +452,7 @@
strlcpy(dkw->dkw_parent, dmv->name, 16);
dkw->dkw_offset = 0;
- dkw->dkw_size = dm_table_size(&dmv->table_head);
+ dm_table_disksize(&dmv->table_head, &dkw->dkw_size, &secsize);
strcpy(dkw->dkw_ptype, DKW_PTYPE_FFS);
dm_dev_unbusy(dmv);
@@ -667,19 +668,19 @@
dmgetproperties(struct disk *disk, dm_table_head_t *head)
{
prop_dictionary_t disk_info, odisk_info, geom;
- int dmp_size;
+ uint64_t numsec;
+ unsigned secsize;
- dmp_size = dm_table_size(head);
+ dm_table_disksize(head, &numsec, &secsize);
disk_info = prop_dictionary_create();
geom = prop_dictionary_create();
prop_dictionary_set_cstring_nocopy(disk_info, "type", "ESDI");
- prop_dictionary_set_uint64(geom, "sectors-per-unit", dmp_size);
- prop_dictionary_set_uint32(geom, "sector-size",
- DEV_BSIZE /* XXX 512? */);
+ prop_dictionary_set_uint64(geom, "sectors-per-unit", numsec);
+ prop_dictionary_set_uint32(geom, "sector-size", secsize);
prop_dictionary_set_uint32(geom, "sectors-per-track", 32);
prop_dictionary_set_uint32(geom, "tracks-per-cylinder", 64);
- prop_dictionary_set_uint32(geom, "cylinders-per-unit", dmp_size / 2048);
+ prop_dictionary_set_uint32(geom, "cylinders-per-unit", numsec / 2048);
prop_dictionary_set(disk_info, "geometry", geom);
prop_object_release(geom);
@@ -688,4 +689,6 @@
if (odisk_info != NULL)
prop_object_release(odisk_info);
-}
+
+ disk_blocksize(disk, secsize);
+}
diff -r f41efd469b5f -r 07027bde2c52 sys/dev/dm/dm.h
--- a/sys/dev/dm/dm.h Thu Dec 23 14:46:25 2010 +0000
+++ b/sys/dev/dm/dm.h Thu Dec 23 14:58:13 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm.h,v 1.20 2010/12/06 08:54:49 haad Exp $ */
+/* $NetBSD: dm.h,v 1.21 2010/12/23 14:58:13 mlelstv Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -46,6 +46,7 @@
#include <sys/queue.h>
#include <sys/device.h>
+#include <sys/disk.h>
#include <sys/disklabel.h>
#include <prop/proplib.h>
@@ -108,6 +109,8 @@
char name[MAX_DEV_NAME];
struct vnode *pdev_vnode;
+ uint64_t pdev_numsec;
+ unsigned pdev_secsize;
int ref_cnt; /* reference counter for users ofthis pdev */
SLIST_ENTRY(dm_pdev) next_pdev;
@@ -241,6 +244,7 @@
int (*strategy)(dm_table_entry_t *, struct buf *);
int (*sync)(dm_table_entry_t *);
int (*upcall)(dm_table_entry_t *, struct buf *);
+ int (*secsize)(dm_table_entry_t *, unsigned *);
uint32_t version[3];
int ref_cnt;
@@ -306,6 +310,7 @@
int dm_target_linear_deps(dm_table_entry_t *, prop_array_t);
int dm_target_linear_destroy(dm_table_entry_t *);
int dm_target_linear_upcall(dm_table_entry_t *, struct buf *);
+int dm_target_linear_secsize(dm_table_entry_t *, unsigned *);
/* Generic function used to convert char to string */
uint64_t atoi(const char *);
@@ -318,6 +323,7 @@
int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t);
int dm_target_stripe_destroy(dm_table_entry_t *);
int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *);
+int dm_target_stripe_secsize(dm_table_entry_t *, unsigned *);
/* dm_table.c */
#define DM_TABLE_ACTIVE 0
@@ -325,6 +331,7 @@
int dm_table_destroy(dm_table_head_t *, uint8_t);
uint64_t dm_table_size(dm_table_head_t *);
+void dm_table_disksize(dm_table_head_t *, uint64_t *, unsigned *);
dm_table_t * dm_table_get_entry(dm_table_head_t *, uint8_t);
int dm_table_get_target_count(dm_table_head_t *, uint8_t);
void dm_table_release(dm_table_head_t *, uint8_t s);
diff -r f41efd469b5f -r 07027bde2c52 sys/dev/dm/dm_pdev.c
--- a/sys/dev/dm/dm_pdev.c Thu Dec 23 14:46:25 2010 +0000
+++ b/sys/dev/dm/dm_pdev.c Thu Dec 23 14:58:13 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_pdev.c,v 1.7 2010/11/19 06:44:40 dholland Exp $ */
+/* $NetBSD: dm_pdev.c,v 1.8 2010/12/23 14:58:13 mlelstv Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -119,6 +119,7 @@
kmem_free(dmp, sizeof(dm_pdev_t));
return NULL;
}
+ getdisksize(dmp->pdev_vnode, &dmp->pdev_numsec, &dmp->pdev_secsize);
dmp->ref_cnt = 1;
mutex_enter(&dm_pdev_mutex);
diff -r f41efd469b5f -r 07027bde2c52 sys/dev/dm/dm_table.c
--- a/sys/dev/dm/dm_table.c Thu Dec 23 14:46:25 2010 +0000
+++ b/sys/dev/dm/dm_table.c Thu Dec 23 14:58:13 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_table.c,v 1.5 2010/01/04 00:19:08 haad Exp $ */
+/* $NetBSD: dm_table.c,v 1.6 2010/12/23 14:58:13 mlelstv Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -203,6 +203,41 @@
return length;
}
/*
+ * Return combined disk geometry
+ */
+void
+dm_table_disksize(dm_table_head_t * head, uint64_t *numsecp, unsigned *secsizep)
+{
+ dm_table_t *tbl;
+ dm_table_entry_t *table_en;
+ uint64_t length;
+ unsigned secsize, tsecsize;
+ 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.
+ */
+ secsize = 0;
+ SLIST_FOREACH(table_en, tbl, next) {
+ length += table_en->length;
+ (void)table_en->target->secsize(table_en, &tsecsize);
+ if (secsize < tsecsize)
+ secsize = tsecsize;
+ }
+ *numsecp = secsize > 0 ? dbtob(length) / secsize : 0;
+ *secsizep = secsize;
+
+ dm_table_unbusy(head);
+}
+/*
* 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
* doesn't need to be true when userspace user receive it (after return
diff -r f41efd469b5f -r 07027bde2c52 sys/dev/dm/dm_target.c
--- a/sys/dev/dm/dm_target.c Thu Dec 23 14:46:25 2010 +0000
+++ b/sys/dev/dm/dm_target.c Thu Dec 23 14:58:13 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target.c,v 1.14 2010/08/21 13:19:41 pgoyette Exp $ */
+/* $NetBSD: dm_target.c,v 1.15 2010/12/23 14:58:13 mlelstv Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -291,6 +291,7 @@
dmt->deps = &dm_target_linear_deps;
dmt->destroy = &dm_target_linear_destroy;
dmt->upcall = &dm_target_linear_upcall;
+ dmt->secsize = &dm_target_linear_secsize;
r = dm_target_insert(dmt);
@@ -305,6 +306,7 @@
dmt3->deps = &dm_target_stripe_deps;
dmt3->destroy = &dm_target_stripe_destroy;
dmt3->upcall = &dm_target_stripe_upcall;
+ dmt3->secsize = &dm_target_stripe_secsize;
r = dm_target_insert(dmt3);
diff -r f41efd469b5f -r 07027bde2c52 sys/dev/dm/dm_target_linear.c
--- a/sys/dev/dm/dm_target_linear.c Thu Dec 23 14:46:25 2010 +0000
+++ b/sys/dev/dm/dm_target_linear.c Thu Dec 23 14:58:13 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target_linear.c,v 1.11 2010/11/15 05:53:29 uebayasi Exp $ */
+/* $NetBSD: dm_target_linear.c,v 1.12 2010/12/23 14:58:13 mlelstv Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -219,6 +219,26 @@
return 0;
}
/*
+ * Query physical block size of this target
+ * For a linear target this is just the sector size of the underlying device
+ */
+int
+dm_target_linear_secsize(dm_table_entry_t * table_en, unsigned *secsizep)
+{
+ dm_target_linear_config_t *tlc;
+ unsigned secsize;
+
+ secsize = 0;
+
+ tlc = table_en->target_config;
+ if (tlc != NULL)
+ secsize = tlc->pdev->pdev_secsize;
+
+ *secsizep = secsize;
+
+ return 0;
+}
+/*
* Transform char s to uint64_t offset number.
*/
uint64_t
diff -r f41efd469b5f -r 07027bde2c52 sys/dev/dm/dm_target_snapshot.c
--- a/sys/dev/dm/dm_target_snapshot.c Thu Dec 23 14:46:25 2010 +0000
+++ b/sys/dev/dm/dm_target_snapshot.c Thu Dec 23 14:58:13 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target_snapshot.c,v 1.13 2010/05/18 15:10:38 haad Exp $ */
+/* $NetBSD: dm_target_snapshot.c,v 1.14 2010/12/23 14:58:13 mlelstv Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -243,6 +243,7 @@
*target_config = tsc;
dmv->dev_type = DM_SNAPSHOT_DEV;
+ dmv->sec_size = dmp_snap->dmp_secsize;
return 0;
}
diff -r f41efd469b5f -r 07027bde2c52 sys/dev/dm/dm_target_stripe.c
--- a/sys/dev/dm/dm_target_stripe.c Thu Dec 23 14:46:25 2010 +0000
+++ b/sys/dev/dm/dm_target_stripe.c Thu Dec 23 14:58:13 2010 +0000
@@ -1,4 +1,4 @@
-/*$NetBSD: dm_target_stripe.c,v 1.12 2010/11/15 05:54:38 uebayasi Exp $*/
+/*$NetBSD: dm_target_stripe.c,v 1.13 2010/12/23 14:58:14 mlelstv Exp $*/
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -342,3 +342,30 @@
{
return 0;
}
+/*
+ * Compute physical block size
+ * For a stripe target we chose the maximum sector size of all
+ * stripe devices. For the supported power-of-2 sizes this is equivalent
+ * to the least common multiple.
+ */
+int
+dm_target_stripe_secsize(dm_table_entry_t * table_en, unsigned *secsizep)
+{
+ dm_target_linear_config_t *tlc;
+ dm_target_stripe_config_t *tsc;
+ unsigned secsize;
+
+ secsize = 0;
+
+ tsc = table_en->target_config;
+ if (tsc != NULL) {
+ TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) {
+ if (secsize < tlc->pdev->pdev_secsize)
+ secsize = tlc->pdev->pdev_secsize;
+ }
+ }
+
Home |
Main Index |
Thread Index |
Old Index