File:  [DragonFly] / src / sys / vfs / coda / Attic / coda_fbsd.c
Revision 1.7: download - view: text, annotated - select for diffs
Wed May 19 22:53:03 2004 UTC (10 years, 4 months ago) by dillon
Branches: MAIN
CVS tags: HEAD, DragonFly_Snap29Sep2004, DragonFly_Snap13Sep2004, DragonFly_1_0_REL, DragonFly_1_0_RC1, DragonFly_1_0A_REL
Device layer rollup commit.

* cdevsw_add() is now required.  cdevsw_add() and cdevsw_remove() may specify
  a mask/match indicating the range of supported minor numbers.  Multiple
  cdevsw_add()'s using the same major number, but distinctly different
  ranges, may be issued.  All devices that failed to call cdevsw_add() before
  now do.

* cdevsw_remove() now automatically marks all devices within its supported
  range as being destroyed.

* vnode->v_rdev is no longer resolved when the vnode is created.  Instead,
  only v_udev (a newly added field) is resolved.  v_rdev is resolved when
  the vnode is opened and cleared on the last close.

* A great deal of code was making rather dubious assumptions with regards
  to the validity of devices associated with vnodes, primarily due to
  the persistence of a device structure due to being indexed by (major, minor)
  instead of by (cdevsw, major, minor).  In particular, if you run a program
  which connects to a USB device and then you pull the USB device and plug
  it back in, the vnode subsystem will continue to believe that the device
  is open when, in fact, it isn't (because it was destroyed and recreated).

  In particular, note that all the VFS mount procedures now check devices
  via v_udev instead of v_rdev prior to calling VOP_OPEN(), since v_rdev
  is NULL prior to the first open.

* The disk layer's device interaction has been rewritten.  The disk layer
  (i.e. the slice and disklabel management layer) no longer overloads
  its data onto the device structure representing the underlying physical
  disk.  Instead, the disk layer uses the new cdevsw_add() functionality
  to register its own cdevsw using the underlying device's major number,
  and simply does NOT register the underlying device's cdevsw.  No
  confusion is created because the device hash is now based on
  (cdevsw,major,minor) rather then (major,minor).

  NOTE: This also means that underlying raw disk devices may use the entire
  device minor number instead of having to reserve the bits used by the disk
  layer, and also means that can we (theoretically) stack a fully
  disklabel-supported 'disk' on top of any block device.

* The new reference counting scheme prevents this by associating a device
  with a cdevsw and disconnecting the device from its cdevsw when the cdevsw
  is removed.  Additionally, all udev2dev() lookups run through the cdevsw
  mask/match and only successfully find devices still associated with an
  active cdevsw.

* Major work on MFS:  MFS no longer shortcuts vnode and device creation.  It
  now creates a real vnode and a real device and implements real open and
  close VOPs.  Additionally, due to the disk layer changes, MFS is no longer
  limited to 255 mounts.  The new limit is 16 million.  Since MFS creates a
  real device node, mount_mfs will now create a real /dev/mfs<PID> device
  that can be read from userland (e.g. so you can dump an MFS filesystem).

* BUF AND DEVICE STRATEGY changes.  The struct buf contains a b_dev field.
  In order to properly handle stacked devices we now require that the b_dev
  field be initialized before the device strategy routine is called.  This
  required some additional work in various VFS implementations.  To enforce
  this requirement, biodone() now sets b_dev to NODEV.  The new disk layer
  will adjust b_dev before forwarding a request to the actual physical
  device.

* A bug in the ISO CD boot sequence which resulted in a panic has been fixed.

Testing by: lots of people, but David Rhodus found the most aggregious bugs.

    1: /*
    2:  * 
    3:  *             Coda: an Experimental Distributed File System
    4:  *                              Release 3.1
    5:  * 
    6:  *           Copyright (c) 1987-1998 Carnegie Mellon University
    7:  *                          All Rights Reserved
    8:  * 
    9:  * Permission  to  use, copy, modify and distribute this software and its
   10:  * documentation is hereby granted,  provided  that  both  the  copyright
   11:  * notice  and  this  permission  notice  appear  in  all  copies  of the
   12:  * software, derivative works or  modified  versions,  and  any  portions
   13:  * thereof, and that both notices appear in supporting documentation, and
   14:  * that credit is given to Carnegie Mellon University  in  all  documents
   15:  * and publicity pertaining to direct or indirect use of this code or its
   16:  * derivatives.
   17:  * 
   18:  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
   19:  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
   20:  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
   21:  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
   22:  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
   23:  * ANY DERIVATIVE WORK.
   24:  * 
   25:  * Carnegie  Mellon  encourages  users  of  this  software  to return any
   26:  * improvements or extensions that  they  make,  and  to  grant  Carnegie
   27:  * Mellon the rights to redistribute these changes without encumbrance.
   28:  * 
   29:  * 	@(#) src/sys/coda/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
   30:  * $FreeBSD: src/sys/coda/coda_fbsd.c,v 1.18 1999/09/25 18:23:43 phk Exp $
   31:  * $DragonFly: src/sys/vfs/coda/coda_fbsd.c,v 1.7 2004/05/19 22:53:03 dillon Exp $
   32:  * 
   33:  */
   34: 
   35: #include "use_vcoda.h"
   36: 
   37: #include <sys/param.h>
   38: #include <sys/systm.h>
   39: #include <sys/kernel.h>
   40: #include <sys/proc.h>
   41: #include <sys/malloc.h>
   42: #include <sys/fcntl.h>
   43: #include <sys/ucred.h>
   44: #include <sys/vnode.h>
   45: #include <sys/conf.h>
   46: 
   47: #include <vm/vm.h>
   48: #include <vm/vnode_pager.h>
   49: 
   50: #include "coda.h"
   51: #include "cnode.h"
   52: #include "coda_vnops.h"
   53: #include "coda_psdev.h"
   54: 
   55: /* 
   56:    From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
   57:    Subject: Re: New 3.0 SNAPshot CDROM about ready for production.. 
   58:    To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
   59:    Date: Fri, 20 Feb 1998 15:57:01 -0800
   60: 
   61:    > Also I need a character device major number. (and might want to reserve
   62:    > a block of 10 syscalls.)
   63: 
   64:    Just one char device number?  No block devices?  Very well, cdev 93 is yours!
   65: */
   66: 
   67: #define VC_DEV_NO      93
   68: 
   69: static struct cdevsw codadevsw = {
   70: 	/* name */	"Coda",
   71: 	/* maj */	VC_DEV_NO,
   72: 	/* flags */	0,
   73: 	/* port */      NULL,
   74: 	/* clone */	NULL,
   75: 
   76: 	/* open */	vc_nb_open,
   77: 	/* close */	vc_nb_close,
   78: 	/* read */	vc_nb_read,
   79: 	/* write */	vc_nb_write,
   80: 	/* ioctl */	vc_nb_ioctl,
   81: 	/* poll */	vc_nb_poll,
   82: 	/* mmap */	nommap,
   83: 	/* strategy */	nostrategy,
   84: 	/* dump */	nodump,
   85: 	/* psize */	nopsize
   86: };
   87: 
   88: int     vcdebug = 1;
   89: #define VCDEBUG if (vcdebug) printf
   90: 
   91: static int
   92: codadev_modevent(module_t mod, int type, void *data)
   93: {
   94: 	switch (type) {
   95: 	case MOD_LOAD:
   96: 		cdevsw_add(&codadevsw, 0, 0);
   97: 		break;
   98: 	case MOD_UNLOAD:
   99: 		cdevsw_remove(&codadevsw, 0, 0);
  100: 		break;
  101: 	default:
  102: 		break;
  103: 	}
  104: 	return 0;
  105: }
  106: static moduledata_t codadev_mod = {
  107: 	"codadev",
  108: 	codadev_modevent,
  109: 	NULL
  110: };
  111: DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
  112: 
  113: int
  114: coda_fbsd_getpages(void *v)
  115: {
  116:     struct vop_getpages_args *ap = v;
  117:     int ret = 0;
  118: 
  119: #if	1
  120: 	/* ??? a_offset */
  121: 	ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
  122: 		ap->a_reqpage);
  123: 	return ret;
  124: #else
  125:   {
  126:     struct vnode *vp = ap->a_vp;
  127:     struct cnode *cp = VTOC(vp);
  128:     struct vnode *cfvp = cp->c_ovp;
  129:     int opened_internally = 0;
  130:     struct ucred *cred = (struct ucred *) 0;
  131:     struct proc *p = curproc;
  132:     int error = 0;
  133: 	
  134:     if (IS_CTL_VP(vp)) {
  135: 	return(EINVAL);
  136:     }
  137: 
  138:     /* Redirect the request to UFS. */
  139: 
  140:     if (cfvp == NULL) {
  141: 	opened_internally = 1;
  142: 
  143: 	error = VOP_OPEN(vp, FREAD,  cred, p);
  144: printf("coda_getp: Internally Opening %p\n", vp);
  145: 
  146: 	if (error) {
  147: 	    printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
  148: 		return (error);
  149: 	}
  150: 	if (vp->v_type == VREG) {
  151: 	    error = vfs_object_create(vp, p, cred);
  152: 	    if (error != 0) {
  153: 		printf("coda_getpage: vfs_object_create() returns %d\n", error);
  154: 		vput(vp);
  155: 		return(error);
  156: 	    }
  157: 	}
  158: 
  159: 	cfvp = cp->c_ovp;
  160:     } else {
  161: printf("coda_getp: has container %p\n", cfvp);
  162:     }
  163: 
  164: printf("coda_fbsd_getpages: using container ");
  165: /*
  166:     error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
  167: 	ap->a_reqpage);
  168: */
  169:     error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
  170: 	ap->a_reqpage, ap->a_offset);
  171: printf("error = %d\n", error);
  172: 
  173:     /* Do an internal close if necessary. */
  174:     if (opened_internally) {
  175: 	(void)VOP_CLOSE(vp, FREAD, cred, p);
  176:     }
  177: 
  178:     return(error);
  179:   }
  180: #endif
  181: }
  182: 
  183: int
  184: coda_fbsd_putpages(void *v)
  185: {
  186: 	struct vop_putpages_args *ap = v;
  187: 
  188: 	/*??? a_offset */
  189: 	return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
  190: 		ap->a_sync, ap->a_rtvals);
  191: }