Re: Change vnd disk name based on mode

Previous thread: Solvng the NVIDIA IDE/SATA/AHCI mess by Mark Kettenis on Tuesday, December 21, 2010 - 3:27 am. (4 messages)

Next thread: Combo Barriletes by TBX on Tuesday, December 21, 2010 - 7:02 am. (1 message)
From: Joel Sing
Date: Tuesday, December 21, 2010 - 5:30 am

When a vnd(4) device is configured the device name is always configured as
vndX, even when it is created as a "safe" vnd (or svndX). This device name
is also used as the name for the disk:

$ vnconfig -c svnd0 /tmp/test
$ sysctl hw.disknames
hw.disknames=sd0:19291b8cb83eb8b8,cd0:,vnd0:

When DUIDs are used we end up mapping back to a device node using the name
of the disk. This means that we always end up using /dev/vnd* even for svnd
disks. 

The following diff adds a separate disk name that is populated based on
the mode that the vnd(4) is created with. This means that if you created
a vnd disk then the disk name will be vndX and diskmap(4) will open the
/dev/vnd* devices. Whereas if you created a svnd disk then the disk name
will be svndX and diskmap(4) will open /dev/svnd* devices.

ok?

Index: vnd.c
===================================================================
RCS file: /cvs/src/sys/dev/vnd.c,v
retrieving revision 1.103
diff -u -p -r1.103 vnd.c
--- vnd.c	22 Sep 2010 01:18:57 -0000	1.103
+++ vnd.c	16 Nov 2010 14:37:41 -0000
@@ -125,6 +125,7 @@ struct pool     vndbufpl;
 struct vnd_softc {
 	struct device	 sc_dev;
 	struct disk	 sc_dk;
+	char		 sc_dk_name[16];
 
 	char		 sc_file[VNDNLEN];	/* file we're covering */
 	int		 sc_flags;		/* flags */
@@ -780,6 +781,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t 
 			return (error);
 		}
 
+		/* Set device name. */
 		bzero(vnd->sc_dev.dv_xname, sizeof(vnd->sc_dev.dv_xname));
 		if (snprintf(vnd->sc_dev.dv_xname, sizeof(vnd->sc_dev.dv_xname),
 		    "vnd%d", unit) >= sizeof(vnd->sc_dev.dv_xname)) {
@@ -788,6 +790,16 @@ vndioctl(dev_t dev, u_long cmd, caddr_t 
 			return(ENXIO);
 		}
 
+		/* Set disk name depending on how we were created. */
+		bzero(vnd->sc_dk_name, sizeof(vnd->sc_dk_name));
+		if (snprintf(vnd->sc_dk_name, sizeof(vnd->sc_dk_name),
+		    "%svnd%d", ((vnd->sc_flags & VNF_SIMPLE) ? "s" : ""),
+		    unit) >= sizeof(vnd->sc_dk_name)) {
+			printf("VNDIOCSET: disk name too ...
From: Todd T. Fries
Date: Tuesday, December 21, 2010 - 8:15 am

I've been successfully running with this since Nov 24th. Definately
changes the behavior as advertised and has no issues that I have
seen in my testing, using duid's on svnd(4) on i386.

Penned by Joel Sing on 20101221  6:30.49, we have:
| When a vnd(4) device is configured the device name is always configured as
| vndX, even when it is created as a "safe" vnd (or svndX). This device name
| is also used as the name for the disk:
| 
| $ vnconfig -c svnd0 /tmp/test
| $ sysctl hw.disknames
| hw.disknames=sd0:19291b8cb83eb8b8,cd0:,vnd0:
| 
| When DUIDs are used we end up mapping back to a device node using the name
| of the disk. This means that we always end up using /dev/vnd* even for svnd
| disks. 
| 
| The following diff adds a separate disk name that is populated based on
| the mode that the vnd(4) is created with. This means that if you created
| a vnd disk then the disk name will be vndX and diskmap(4) will open the
| /dev/vnd* devices. Whereas if you created a svnd disk then the disk name
| will be svndX and diskmap(4) will open /dev/svnd* devices.
| 
| ok?
| 
| Index: vnd.c
| ===================================================================
| RCS file: /cvs/src/sys/dev/vnd.c,v
| retrieving revision 1.103
| diff -u -p -r1.103 vnd.c
| --- vnd.c	22 Sep 2010 01:18:57 -0000	1.103
| +++ vnd.c	16 Nov 2010 14:37:41 -0000
| @@ -125,6 +125,7 @@ struct pool     vndbufpl;
|  struct vnd_softc {
|  	struct device	 sc_dev;
|  	struct disk	 sc_dk;
| +	char		 sc_dk_name[16];
|  
|  	char		 sc_file[VNDNLEN];	/* file we're covering */
|  	int		 sc_flags;		/* flags */
| @@ -780,6 +781,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t 
|  			return (error);
|  		}
|  
| +		/* Set device name. */
|  		bzero(vnd->sc_dev.dv_xname, sizeof(vnd->sc_dev.dv_xname));
|  		if (snprintf(vnd->sc_dev.dv_xname, sizeof(vnd->sc_dev.dv_xname),
|  		    "vnd%d", unit) >= sizeof(vnd->sc_dev.dv_xname)) {
| @@ -788,6 +790,16 @@ vndioctl(dev_t dev, u_long cmd, caddr_t 
|  			return(ENXIO);
|  		}
|  ...
Previous thread: Solvng the NVIDIA IDE/SATA/AHCI mess by Mark Kettenis on Tuesday, December 21, 2010 - 3:27 am. (4 messages)

Next thread: Combo Barriletes by TBX on Tuesday, December 21, 2010 - 7:02 am. (1 message)