Module Name: src
Committed By: mlelstv
Date: Thu Dec 23 14:58:14 UTC 2010
Modified Files:
src/sys/dev/dm: device-mapper.c dm.h dm_pdev.c dm_table.c dm_target.c
dm_target_linear.c dm_target_snapshot.c dm_target_stripe.c
Log Message:
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@
To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/dm/device-mapper.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/dm/dm.h
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/dm/dm_pdev.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/dm/dm_table.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/dm/dm_target.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/dm/dm_target_linear.c
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/dm/dm_target_snapshot.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/dm/dm_target_stripe.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/dm/device-mapper.c
diff -u src/sys/dev/dm/device-mapper.c:1.26 src/sys/dev/dm/device-mapper.c:1.27
--- src/sys/dev/dm/device-mapper.c:1.26 Mon Dec 6 09:12:23 2010
+++ src/sys/dev/dm/device-mapper.c Thu Dec 23 14:58:13 2010
@@ -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);
+}
Index: src/sys/dev/dm/dm.h
diff -u src/sys/dev/dm/dm.h:1.20 src/sys/dev/dm/dm.h:1.21
--- src/sys/dev/dm/dm.h:1.20 Mon Dec 6 08:54:49 2010
+++ src/sys/dev/dm/dm.h Thu Dec 23 14:58:13 2010
@@ -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);
Index: src/sys/dev/dm/dm_pdev.c
diff -u src/sys/dev/dm/dm_pdev.c:1.7 src/sys/dev/dm/dm_pdev.c:1.8
--- src/sys/dev/dm/dm_pdev.c:1.7 Fri Nov 19 06:44:40 2010
+++ src/sys/dev/dm/dm_pdev.c Thu Dec 23 14:58:13 2010
@@ -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);
Index: src/sys/dev/dm/dm_table.c
diff -u src/sys/dev/dm/dm_table.c:1.5 src/sys/dev/dm/dm_table.c:1.6
--- src/sys/dev/dm/dm_table.c:1.5 Mon Jan 4 00:19:08 2010
+++ src/sys/dev/dm/dm_table.c Thu Dec 23 14:58:13 2010
@@ -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
Index: src/sys/dev/dm/dm_target.c
diff -u src/sys/dev/dm/dm_target.c:1.14 src/sys/dev/dm/dm_target.c:1.15
--- src/sys/dev/dm/dm_target.c:1.14 Sat Aug 21 13:19:41 2010
+++ src/sys/dev/dm/dm_target.c Thu Dec 23 14:58:13 2010
@@ -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);
Index: src/sys/dev/dm/dm_target_linear.c
diff -u src/sys/dev/dm/dm_target_linear.c:1.11 src/sys/dev/dm/dm_target_linear.c:1.12
--- src/sys/dev/dm/dm_target_linear.c:1.11 Mon Nov 15 05:53:29 2010
+++ src/sys/dev/dm/dm_target_linear.c Thu Dec 23 14:58:13 2010
@@ -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
Index: src/sys/dev/dm/dm_target_snapshot.c
diff -u src/sys/dev/dm/dm_target_snapshot.c:1.13 src/sys/dev/dm/dm_target_snapshot.c:1.14
--- src/sys/dev/dm/dm_target_snapshot.c:1.13 Tue May 18 15:10:41 2010
+++ src/sys/dev/dm/dm_target_snapshot.c Thu Dec 23 14:58:13 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target_snapshot.c,v 1.13 2010/05/18 15:10:41 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;
}
Index: src/sys/dev/dm/dm_target_stripe.c
diff -u src/sys/dev/dm/dm_target_stripe.c:1.12 src/sys/dev/dm/dm_target_stripe.c:1.13
--- src/sys/dev/dm/dm_target_stripe.c:1.12 Mon Nov 15 05:54:38 2010
+++ src/sys/dev/dm/dm_target_stripe.c Thu Dec 23 14:58:14 2010
@@ -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;
+ }
+ }
+
+ *secsizep = secsize;
+
+ return 0;
+}