Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-9]: src/sys/sys Pull up following revision(s) (requested by riast...
details: https://anonhg.NetBSD.org/src/rev/3d62e7b63052
branches: netbsd-9
changeset: 963726:3d62e7b63052
user: martin <martin%NetBSD.org@localhost>
date: Sat Mar 21 15:18:57 2020 +0000
description:
Pull up following revision(s) (requested by riastradh in ticket #788):
sys/sys/dkio.h: revision 1.26
sys/dev/dkwedge/dk.c: revision 1.100
sys/sys/disk.h: revision 1.75
external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c: revision 1.14
external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c: revision 1.15
sys/dev/cgd.c: revision 1.121
sys/dev/ata/wdvar.h: revision 1.50
sys/kern/subr_disk_open.c: revision 1.15
sys/dev/ata/wd.c: revision 1.459
New ioctl DIOCGSECTORALIGN returns sector alignment parameters.
struct disk_sectoralign {
/* First aligned sector number. */
uint32_t dsa_firstaligned;
/* Number of sectors per aligned unit. */
uint32_t dsa_alignment;
};
- Teach wd(4) to get it from ATA.
- Teach cgd(4) to pass it through from the underlying disk.
- Teach dk(4) to pass it through with adjustments.
- Teach zpool (zfs) to take advantage of it.
=> XXX zpool doesn't seem to understand when the vdev's starting
sector is misaligned.
Missing:
- ccd(4) and raidframe(4) support -- these should support _using_
DIOCGSECTORALIGN to decide where to start putting ccd or raid
stripes on disk, and these should perhaps _implement_
DIOCGSECTORALIGN by reporting the stripe/interleave factor.
- sd(4) support -- I don't know any obvious way to get it from SCSI,
but if any SCSI wizards know better than I, please feel free to
teach sd(4) about it!
- any ld(4) attachments -- might be worth teaching the ld drivers for
nvme and various raid controllers to get the aligned sector size
There's some duplicate logic here for now. I'm doing it this way,
rather than gathering the logic into a new disklabel_sectoralign
function or something, so that this change is limited to adding a new
ioctl, without any new kernel symbols, in order to make it easy to
pull up to netbsd-9 without worrying about the module ABI.
Make getdiskinfo() compatible with a DIOCGWEDGEINFO.
dkw_parent is defined to hold the disk name as used by disk_find(), not
a partition (i.e. no partition letter appended).
Use utility functions to handle disk geometry.
diffstat:
external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c | 81 +++++++----------
sys/dev/ata/wd.c | 51 ++++++++++-
sys/dev/ata/wdvar.h | 3 +-
sys/dev/cgd.c | 31 ++++++-
sys/dev/dkwedge/dk.c | 21 ++++-
sys/kern/subr_disk_open.c | 7 +-
sys/sys/disk.h | 8 +-
sys/sys/dkio.h | 5 +-
8 files changed, 148 insertions(+), 59 deletions(-)
diffs (truncated from 391 to 300 lines):
diff -r 4e27087a38a5 -r 3d62e7b63052 external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c Thu Mar 19 19:47:39 2020 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c Sat Mar 21 15:18:57 2020 +0000
@@ -35,7 +35,6 @@
#include <sys/sunldi.h>
#include <sys/fm/fs/zfs.h>
#include <sys/disk.h>
-#include <sys/disklabel.h>
#include <sys/dkio.h>
#include <sys/workqueue.h>
@@ -147,10 +146,12 @@
spa_t *spa = vd->vdev_spa;
vdev_disk_t *dvd;
vnode_t *vp;
- struct dkwedge_info dkw;
+ int error, cmd;
+ uint64_t numsecs;
+ unsigned secsize;
struct disk *pdk;
- int error, cmd;
- struct partinfo pinfo;
+ struct dkwedge_info dkw;
+ struct disk_sectoralign dsa;
/*
* We must have a pathname, and it must be absolute.
@@ -219,33 +220,15 @@
return (SET_ERROR(EINVAL));
}
+ pdk = NULL;
+ if (getdiskinfo(vp, &dkw) == 0)
+ pdk = disk_find(dkw.dkw_parent);
+
/* XXXNETBSD Once tls-maxphys gets merged this block becomes:
- if (VOP_IOCTL(vp, DIOCGWEDGEINFO, &dkw, FREAD, NOCRED) == 0)
- pdk = disk_find(dkw.dkw_parent);
- else
- pdk = disk_find_blk(vp->v_rdev);
dvd->vd_maxphys = (pdk ? disk_maxphys(pdk) : MACHINE_MAXPHYS);
*/
{
struct buf buf = { .b_bcount = MAXPHYS };
-
- if (VOP_IOCTL(vp, DIOCGWEDGEINFO, &dkw, FREAD, NOCRED) == 0) {
- pdk = disk_find(dkw.dkw_parent);
- } else {
- const char *dev_name;
-
- dev_name = devsw_blk2name(major(vp->v_rdev));
- if (dev_name) {
- char disk_name[16];
-
- snprintf(disk_name, sizeof(disk_name), "%s%d",
- dev_name, DISKUNIT(vp->v_rdev));
- pdk = disk_find(disk_name);
- } else {
- pdk = NULL;
- }
- buf.b_dev = vp->v_rdev;
- }
if (pdk && pdk->dk_driver && pdk->dk_driver->d_minphys)
(*pdk->dk_driver->d_minphys)(&buf);
dvd->vd_maxphys = buf.b_bcount;
@@ -268,32 +251,38 @@
dvd->vd_vp = vp;
skip_open:
- /*
- * Determine the actual size of the device.
- * Try wedge info first as it supports larger disks.
- */
- error = VOP_IOCTL(vp, DIOCGWEDGEINFO, &dkw, FREAD, NOCRED);
- if (error == 0) {
- pdk = disk_find(dkw.dkw_parent);
- if (pdk) {
- pinfo.pi_secsize = (1 << pdk->dk_byteshift);
- pinfo.pi_size = dkw.dkw_size;
- pinfo.pi_offset = dkw.dkw_offset;
- } else
- error = ENODEV;
- }
- if (error)
- error = VOP_IOCTL(vp, DIOCGPARTINFO, &pinfo, FREAD, kcred);
+ error = getdisksize(vp, &numsecs, &secsize);
if (error != 0) {
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
return (SET_ERROR(error));
}
- *psize = pinfo.pi_size * pinfo.pi_secsize;
+
+ *psize = numsecs * secsize;
*max_psize = *psize;
- *ashift = highbit(MAX(pinfo.pi_secsize, SPA_MINBLOCKSIZE)) - 1;
- *pashift = *ashift;
- vd->vdev_wholedisk = (pinfo.pi_offset == 0); /* XXXNETBSD */
+ *ashift = highbit(MAX(secsize, SPA_MINBLOCKSIZE)) - 1;
+
+ /*
+ * Try to determine whether the disk has a preferred physical
+ * sector size even if it can emulate a smaller logical sector
+ * size with r/m/w cycles, e.g. a disk with 4096-byte sectors
+ * that for compatibility claims to support 512-byte ones.
+ */
+ if (VOP_IOCTL(vp, DIOCGSECTORALIGN, &dsa, FREAD, NOCRED) == 0) {
+ *pashift = highbit(dsa.dsa_alignment * secsize) - 1;
+ if (dsa.dsa_firstaligned % dsa.dsa_alignment)
+ printf("ZFS WARNING: vdev %s: sectors are misaligned"
+ " (alignment=%"PRIu32", firstaligned=%"PRIu32")\n",
+ vd->vdev_path,
+ dsa.dsa_alignment, dsa.dsa_firstaligned);
+ } else {
+ *pashift = *ashift;
+ }
+
+ vd->vdev_wholedisk = 0;
+ if (getdiskinfo(vp, &dkw) != 0 &&
+ dkw.dkw_offset == 0 && dkw.dkw_size == numsecs)
+ vd->vdev_wholedisk = 1,
/*
* Clear the nowritecache bit, so that on a vdev_reopen() we will
diff -r 4e27087a38a5 -r 3d62e7b63052 sys/dev/ata/wd.c
--- a/sys/dev/ata/wd.c Thu Mar 19 19:47:39 2020 +0000
+++ b/sys/dev/ata/wd.c Sat Mar 21 15:18:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wd.c,v 1.452 2019/06/06 20:55:43 mlelstv Exp $ */
+/* $NetBSD: wd.c,v 1.452.2.1 2020/03/21 15:18:57 martin Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved.
@@ -54,7 +54,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.452 2019/06/06 20:55:43 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.452.2.1 2020/03/21 15:18:57 martin Exp $");
#include "opt_ata.h"
#include "opt_wd.h"
@@ -430,16 +430,40 @@
} else {
wd->sc_blksize = 512;
}
+ wd->sc_sectoralign.dsa_firstaligned = 0;
+ wd->sc_sectoralign.dsa_alignment = 1;
+ if ((wd->sc_params.atap_secsz & ATA_SECSZ_VALID_MASK) == ATA_SECSZ_VALID
+ && ((wd->sc_params.atap_secsz & ATA_SECSZ_LPS) != 0)) {
+ wd->sc_sectoralign.dsa_alignment = 1 <<
+ (wd->sc_params.atap_secsz & ATA_SECSZ_LPS_SZMSK);
+ if ((wd->sc_params.atap_logical_align & ATA_LA_VALID_MASK) ==
+ ATA_LA_VALID) {
+ wd->sc_sectoralign.dsa_firstaligned =
+ (wd->sc_sectoralign.dsa_alignment -
+ (wd->sc_params.atap_logical_align &
+ ATA_LA_MASK));
+ }
+ }
wd->sc_capacity512 = (wd->sc_capacity * wd->sc_blksize) / DEV_BSIZE;
format_bytes(pbuf, sizeof(pbuf), wd->sc_capacity * wd->sc_blksize);
aprint_normal_dev(self, "%s, %d cyl, %d head, %d sec, "
- "%d bytes/sect x %llu sectors\n",
+ "%d bytes/sect x %llu sectors",
pbuf,
(wd->sc_flags & WDF_LBA) ? (int)(wd->sc_capacity /
(wd->sc_params.atap_heads * wd->sc_params.atap_sectors)) :
wd->sc_params.atap_cylinders,
wd->sc_params.atap_heads, wd->sc_params.atap_sectors,
wd->sc_blksize, (unsigned long long)wd->sc_capacity);
+ if (wd->sc_sectoralign.dsa_alignment != 1) {
+ aprint_normal(" (%d bytes/physsect",
+ wd->sc_sectoralign.dsa_alignment & wd->sc_blksize);
+ if (wd->sc_sectoralign.dsa_firstaligned != 0) {
+ aprint_normal("; first aligned sector: %jd",
+ (intmax_t)wd->sc_sectoralign.dsa_firstaligned);
+ }
+ aprint_normal(")");
+ }
+ aprint_normal("\n");
ATADEBUG_PRINT(("%s: atap_dmatiming_mimi=%d, atap_dmatiming_recom=%d\n",
device_xname(self), wd->sc_params.atap_dmatiming_mimi,
@@ -1409,6 +1433,27 @@
return(error1);
}
+ case DIOCGSECTORALIGN: {
+ struct disk_sectoralign *dsa = addr;
+ int part = WDPART(dev);
+
+ *dsa = wd->sc_sectoralign;
+ if (part != RAW_PART) {
+ struct disklabel *lp = dksc->sc_dkdev.dk_label;
+ daddr_t offset = lp->d_partitions[part].p_offset;
+ uint32_t r = offset % dsa->dsa_alignment;
+
+ if (r < dsa->dsa_firstaligned)
+ dsa->dsa_firstaligned = dsa->dsa_firstaligned
+ - r;
+ else
+ dsa->dsa_firstaligned = (dsa->dsa_firstaligned
+ + dsa->dsa_alignment) - r;
+ }
+
+ return 0;
+ }
+
default:
return dk_ioctl(dksc, dev, cmd, addr, flag, l);
}
diff -r 4e27087a38a5 -r 3d62e7b63052 sys/dev/ata/wdvar.h
--- a/sys/dev/ata/wdvar.h Thu Mar 19 19:47:39 2020 +0000
+++ b/sys/dev/ata/wdvar.h Sat Mar 21 15:18:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wdvar.h,v 1.49 2019/04/05 18:23:45 bouyer Exp $ */
+/* $NetBSD: wdvar.h,v 1.49.4.1 2020/03/21 15:18:57 martin Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -59,6 +59,7 @@
uint64_t sc_capacity512; /* ... in DEV_BSIZE blocks */
uint32_t sc_capacity28; /* capacity accessible with LBA28 commands */
uint32_t sc_blksize; /* logical block size, in bytes */
+ struct disk_sectoralign sc_sectoralign; /* sector alignment */
#ifdef WD_SOFTBADSECT
SLIST_HEAD(, disk_badsectors) sc_bslist;
diff -r 4e27087a38a5 -r 3d62e7b63052 sys/dev/cgd.c
--- a/sys/dev/cgd.c Thu Mar 19 19:47:39 2020 +0000
+++ b/sys/dev/cgd.c Sat Mar 21 15:18:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.116 2018/01/23 22:42:29 pgoyette Exp $ */
+/* $NetBSD: cgd.c,v 1.116.10.1 2020/03/21 15:18:57 martin Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.116 2018/01/23 22:42:29 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.116.10.1 2020/03/21 15:18:57 martin Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -722,6 +722,33 @@
* We pass this call down to the underlying disk.
*/
return VOP_IOCTL(cs->sc_tvn, cmd, data, flag, l->l_cred);
+ case DIOCGSECTORALIGN: {
+ struct disk_sectoralign *dsa = data;
+ int error;
+
+ if (!DK_ATTACHED(dksc))
+ return ENOENT;
+
+ /* Get the underlying disk's sector alignment. */
+ error = VOP_IOCTL(cs->sc_tvn, cmd, data, flag, l->l_cred);
+ if (error)
+ return error;
+
+ /* Adjust for the disklabel partition if necessary. */
+ if (part != RAW_PART) {
+ struct disklabel *lp = dksc->sc_dkdev.dk_label;
+ daddr_t offset = lp->d_partitions[part].p_offset;
+ uint32_t r = offset % dsa->dsa_alignment;
+
+ if (r < dsa->dsa_firstaligned)
+ dsa->dsa_firstaligned = dsa->dsa_firstaligned
+ - r;
+ else
+ dsa->dsa_firstaligned = (dsa->dsa_firstaligned
+ + dsa->dsa_alignment) - r;
+ }
+ return 0;
+ }
case DIOCGSTRATEGY:
case DIOCSSTRATEGY:
if (!DK_ATTACHED(dksc))
diff -r 4e27087a38a5 -r 3d62e7b63052 sys/dev/dkwedge/dk.c
--- a/sys/dev/dkwedge/dk.c Thu Mar 19 19:47:39 2020 +0000
+++ b/sys/dev/dkwedge/dk.c Sat Mar 21 15:18:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dk.c,v 1.97 2018/05/12 10:33:06 mlelstv Exp $ */
+/* $NetBSD: dk.c,v 1.97.8.1 2020/03/21 15:18:57 martin Exp $ */
/*-
* Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.97 2018/05/12 10:33:06 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.97.8.1 2020/03/21 15:18:57 martin Exp $");
#ifdef _KERNEL_OPT
#include "opt_dkwedge.h"
@@ -1501,7 +1501,24 @@
Home |
Main Index |
Thread Index |
Old Index