Subject: Re: gpt on NetBSD_4.0BETA2
To: NetBSD current-users <current-users@netbsd.org>
From: Andreas Wrede <andreas@planix.com>
List: current-users
Date: 07/28/2007 10:11:47
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--Apple-Mail-10--981205915
Content-Type: multipart/mixed; boundary=Apple-Mail-9--981206056


--Apple-Mail-9--981206056
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	delsp=yes;
	format=flowed


On Jul 21, 2007, at 12:40 , Andreas Wrede wrote:

>
> On Jul 20, 2007, at 18:56 , Jonathan A. Kollasch wrote:
>
>> On Fri, Jul 20, 2007 at 05:23:19PM -0400, Andreas Wrede wrote:
>>>  I am trying to use gpt to create a GUID partition table on a 3TB  
>>> Xserve
>>>  RAID:
>>>
>>>  # gpt create /dev/sd0d
>>>  gpt: unable to open device 'sd0d': Invalid argument
>>>
>>>  I assume this because in sys/dev/scsipi/sd.c does not set the  
>>> properties.
>>>  In -current, rev 1.260 of sd.c adds sd_set_properties().   
>>> (4.0BETA's sd.c is
>>>  at rev 1.258).
>>>
>>>  Is that all that's needed to get gpt to work on sd(4) type  
>>> devices? If so,
>>>  maybe that change can be pulled up to the 4.0 branch?
>>
>> Yes, a backport is trivial, I've actually done it.  I don't see  
>> why it couldn't
>> go into netbsd-4.
>
> Thanks - I'll go ahead then..

For the record, with the patch below, gpt and dkctl work fine on  
NetBSD/i386 4.0_BETA2.  This is rev 1.260 of sd.c in -current.


>> Also, you may want the appropriate gpt stuff for dk in the kernel:
>>
>> options DKWEDGE_AUTODISCOVER
>> options DKWEDGE_METHOD_GPT
>
> Ok.  I guess, without it, I have to re-run the dkctl .. addwedge  
> commands?
>
> BTW, pseudo-device   drvctl is only present in the ALL kernel and  
> the DKWEDGE_... options are missing completely.  Should GENERIC not  
> have drvctl? And the commented-out options?
>
> Also missing is the drvctl(4) man page, which is referenced from  
> drvctl(8).

-- 
     aew


--Apple-Mail-9--981206056
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	x-mac-type=54455854;
	x-unix-mode=0755;
	x-mac-creator=74747874;
	name=sd-gpt.patch.txt
Content-Disposition: attachment;
	filename=sd-gpt.patch.txt

Index: sd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/scsipi/sd.c,v
retrieving revision 1.258
diff -u -u -r1.258 sd.c
--- sd.c	30 Nov 2006 17:59:35 -0000	1.258
+++ sd.c	28 Jul 2007 14:04:35 -0000
@@ -90,6 +90,8 @@
 #include <dev/scsipi/scsipi_base.h>
 #include <dev/scsipi/sdvar.h>
 
+#include <prop/proplib.h>
+
 #define	SDUNIT(dev)			DISKUNIT(dev)
 #define	SDPART(dev)			DISKPART(dev)
 #define	SDMINOR(unit, part)		DISKMINOR(unit, part)
@@ -131,6 +133,7 @@
 static void	sdattach(struct device *, struct device *, void *);
 static int	sdactivate(struct device *, enum devact);
 static int	sddetach(struct device *, int);
+static void	sd_set_properties(struct sd_softc *);
 
 CFATTACH_DECL(sd, sizeof(struct sd_softc), sdmatch, sdattach, sddetach,
     sdactivate);
@@ -327,6 +330,8 @@
 
 	/* Discover wedges on this disk. */
 	dkwedge_discover(&sd->sc_dk);
+
+	sd_set_properties(sd);
 }
 
 static int
@@ -2230,3 +2235,44 @@
 	    sizeof(struct scsi_mode_page_header) +
 	    pages->caching_params.pg_length, 0, big));
 }
+
+static void
+sd_set_properties(struct sd_softc *sd)
+{
+	prop_dictionary_t disk_info, odisk_info, geom;
+
+	disk_info = prop_dictionary_create();
+
+	geom = prop_dictionary_create();
+
+	prop_dictionary_set_uint64(geom, "sectors-per-unit",
+	    sd->params.disksize);
+
+	prop_dictionary_set_uint32(geom, "sector-size",
+	    sd->params.blksize);
+
+	prop_dictionary_set_uint16(geom, "sectors-per-track",
+	    sd->params.sectors);
+
+	prop_dictionary_set_uint16(geom, "tracks-per-cylinder",
+	    sd->params.heads);
+
+	prop_dictionary_set_uint64(geom, "cylinders-per-unit",
+	    sd->params.cyls);
+
+	prop_dictionary_set(disk_info, "geometry", geom);
+	prop_object_release(geom);
+
+	prop_dictionary_set(device_properties(&sd->sc_dev),
+	    "disk-info", disk_info);
+
+	/*
+	 * Don't release disk_info here; we keep a reference to it.
+	 * disk_detach() will release it when we go away.
+	 */
+
+	odisk_info = sd->sc_dk.dk_info;
+	sd->sc_dk.dk_info = disk_info;
+	if (odisk_info)
+		prop_object_release(odisk_info);
+}

--Apple-Mail-9--981206056--

--Apple-Mail-10--981205915
content-type: application/pgp-signature; x-mac-type=70674453;
	name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)

iD8DBQFGq06jEh/h9J/TQyERAmQJAJ9TFlkdinZWerw94LHio/AwWMsGPgCfZ3kX
hTTiubni4RrxhNvRwb8iy1c=
=TvBr
-----END PGP SIGNATURE-----

--Apple-Mail-10--981205915--