Subject: Re: Upgrade of `struct vnd_ioctl'
To: Quentin Garnier <cube@cubidou.net>
From: Arnaud Lacombe <arnaud.lacombe.1@ulaval.ca>
List: tech-kern
Date: 02/12/2007 00:46:52
--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Sun, Feb 11, 2007 at 11:46:39PM +0100, Quentin Garnier wrote:
> On Sun, Feb 11, 2007 at 02:27:22PM -0500, Arnaud Lacombe wrote:
> > I'd like to change the size of the `vnd_size' member of struct vnd_ioctl
> > from `int' to `u_quad_t' (or any other unsigned 64bits type, but
> > u_quad_t is used by `struct vattr->va_size').
>
> uint64_t should be preferred for new code.
ok, done
> > Does the change needs any compatibility layer to be added ?
>
> The process is quite simple: keep a copy of the current structure with
> a different name (e.g., oldvnd_ioctl), and create new ioctl commands
> referencing that structure with the name OXXX.
>
> E.g.:
>
> #define OVNDIOCSET _IOWR('F', 0, struct oldvnd_ioctl)
>
> Then you add an entry in ioctl handler for those commands that do what
> they're supposed to do (i.e., in that case convert the value), and put
> those specific parts under COMPAT_40.
>
does the attached patch looks good ?
- Arnaud
--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="vnd_ioctl.diff"
Index: src/sys/dev/vndvar.h
===================================================================
RCS file: /data/netbsd/cvsroot/src/sys/dev/vndvar.h,v
retrieving revision 1.20
diff -u -r1.20 vndvar.h
--- src/sys/dev/vndvar.h 14 May 2006 21:42:26 -0000 1.20
+++ src/sys/dev/vndvar.h 12 Feb 2007 05:41:33 -0000
@@ -128,11 +128,22 @@
/*
* Ioctl definitions for file (vnode) disk pseudo-device.
*/
+#ifdef COMPAT_40
+struct vnd_oioctl {
+ char *vnd_file; /* pathname of file to mount */
+ int vnd_flags; /* flags; see below */
+ struct vndgeom vnd_geom; /* geometry to emulate */
+ int vnd_size; /* (returned) size of disk */
+};
+#define VNDIOOCSET _IOWR('F', 0, struct vnd_oioctl)/* enable disk */
+#define VNDIOOCCLR _IOW('F', 1, struct vnd_oioctl) /* disable disk */
+#endif
+
struct vnd_ioctl {
char *vnd_file; /* pathname of file to mount */
int vnd_flags; /* flags; see below */
struct vndgeom vnd_geom; /* geometry to emulate */
- int vnd_size; /* (returned) size of disk */
+ uint64_t vnd_size; /* (returned) size of disk */
};
/* vnd_flags */
Index: src/sys/dev/vnd.c
===================================================================
RCS file: /data/netbsd/cvsroot/src/sys/dev/vnd.c,v
retrieving revision 1.161
diff -u -r1.161 vnd.c
--- src/sys/dev/vnd.c 28 Jan 2007 21:33:24 -0000 1.161
+++ src/sys/dev/vnd.c 12 Feb 2007 05:42:32 -0000
@@ -948,6 +948,10 @@
/* Must be open for writes for these commands... */
switch (cmd) {
+#ifdef COMPAT_40
+ case VNDIOOCSET:
+ case VNDIOOCCLR:
+#endif
case VNDIOCSET:
case VNDIOCCLR:
case DIOCSDINFO:
@@ -964,6 +968,9 @@
/* Must be initialized for these... */
switch (cmd) {
+#ifdef COMPAT_40
+ case VNDIOOCCLR:
+#endif
case VNDIOCCLR:
case DIOCGDINFO:
case DIOCSDINFO:
@@ -983,6 +990,9 @@
}
switch (cmd) {
+#ifdef COMPAT_40
+ case VNDIOOCSET:
+#endif
case VNDIOCSET:
if (vnd->sc_flags & VNF_INITED)
return (EBUSY);
@@ -1182,7 +1192,12 @@
goto close_and_exit;
vndthrottle(vnd, vnd->sc_vp);
- vio->vnd_size = dbtob(vnd->sc_size);
+#ifdef COMPAT_40
+ if (cmd == VNDIOOCSET)
+ vio->vnd_size = dbtob(vnd->sc_size);
+ else
+#endif
+ vio->vnd_size = vattr.va_size;
vnd->sc_flags |= VNF_INITED;
/* create the kernel thread, wait for it to be up */
@@ -1239,6 +1254,9 @@
vndunlock(vnd);
return (error);
+#ifdef COMPAT_40
+ case OVNDIOCCLR:
+#endif
case VNDIOCCLR:
if ((error = vndlock(vnd)) != 0)
return (error);
Index: src/usr.sbin/vnconfig/vnconfig.c
===================================================================
RCS file: /data/netbsd/cvsroot/src/usr.sbin/vnconfig/vnconfig.c,v
retrieving revision 1.34
diff -u -r1.34 vnconfig.c
--- src/usr.sbin/vnconfig/vnconfig.c 19 Aug 2005 02:09:50 -0000 1.34
+++ src/usr.sbin/vnconfig/vnconfig.c 11 Feb 2007 19:08:23 -0000
@@ -353,7 +353,7 @@
if (rv)
warn("%s: VNDIOCSET", rdev);
else if (verbose) {
- printf("%s: %d bytes on %s", rdev,
+ printf("%s: %" PRIu64 " bytes on %s", rdev,
vndio.vnd_size, file);
if (vndio.vnd_flags & VNDIOF_HASGEOM)
printf(" using geometry %d/%d/%d/%d",
--wRRV7LY7NUeQGEoC--