From owner-p4-projects@FreeBSD.ORG Wed Aug 9 22:14:39 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 84A0A16A4E8; Wed, 9 Aug 2006 22:14:39 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5C89216A4DA for ; Wed, 9 Aug 2006 22:14:39 +0000 (UTC) (envelope-from adamartin@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id C0E4243D5F for ; Wed, 9 Aug 2006 22:14:32 +0000 (GMT) (envelope-from adamartin@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k79MEWjT015805 for ; Wed, 9 Aug 2006 22:14:32 GMT (envelope-from adamartin@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k79MEW2o015802 for perforce@freebsd.org; Wed, 9 Aug 2006 22:14:32 GMT (envelope-from adamartin@FreeBSD.org) Date: Wed, 9 Aug 2006 22:14:32 GMT Message-Id: <200608092214.k79MEW2o015802@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to adamartin@FreeBSD.org using -f From: Adam Martin To: Perforce Change Reviews Cc: Subject: PERFORCE change 103535 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Aug 2006 22:14:39 -0000 http://perforce.freebsd.org/chv.cgi?CH=103535 Change 103535 by adamartin@adamartin_hobbes on 2006/08/09 22:14:10 Implemented most of vfsops. Need to implement vfs_root, so that we do not get panics on "lost mount". Also need to implement a few vnops, and import my other work on the protocol handler. Affected files ... .. //depot/projects/soc2006/adamartin_autofs/autofs/Makefile#2 edit .. //depot/projects/soc2006/adamartin_autofs/autofs/README#2 edit .. //depot/projects/soc2006/adamartin_autofs/autofs/autofs.c#2 edit .. //depot/projects/soc2006/adamartin_autofs/autofs/autofs.h#2 edit .. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_vfsops.c#2 edit .. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_vnops.c#2 edit .. //depot/projects/soc2006/adamartin_autofs/autofs/cleanup.h#2 edit .. //depot/projects/soc2006/adamartin_autofs/mount_autofs/mount_autofs.c#2 edit Differences ... ==== //depot/projects/soc2006/adamartin_autofs/autofs/Makefile#2 (text+ko) ==== @@ -30,6 +30,16 @@ AUTOFS_FS_SOURCE=autofs_vnops.c autofs_vfsops.c vnode_if.h AUTOFS_CORE_SOURCE=autofs.c protocol.c SRCS=$(AUTOFS_CORE_SOURCE) $(AUTOFS_FS_SOURCE) $(AUTOFS_DEV_SOURCE) +HEADERS=autofs.h cleanup.h protocol.h KMOD=autofs +autofs.c: $(HEADERS) + +autofs_vfsops.c: $(HEADERS) + +autofs_vnops.c: $(HEADERS) + +autofs_ctl.c: $(HEADERS) + + .include ==== //depot/projects/soc2006/adamartin_autofs/autofs/README#2 (text+ko) ==== @@ -1,0 +1,2 @@ +FreeBSD Autofs is written by ADAM David Alan Martin, for Google +Summer of Code, 2006. ==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs.c#2 (text+ko) ==== @@ -44,7 +44,10 @@ #include #include "cleanup.h" +#include +#include + #define AUTOFS_CTL_DEV_NAME "autofs_ctl" @@ -108,4 +111,29 @@ return( err ); } + +int +vn_iscdev(struct vnode *vp, int *errp) +{ + int error = 0; + + dev_lock(); + + if (vp->v_type != VCHR) + error = ENODEV; + + #ifdef USE_EXTENDED_DEV_CHECK + else if (vp->v_rdev == NULL) + error = ENXIO; + else if (vp->v_rdev->si_devsw == NULL) + error = ENXIO; + #endif + dev_unlock(); + + + if (errp != NULL) + *errp = error; + return (error == 0); +} + DEV_MODULE( AutoFS, autofs_handle_loader, NULL ); ==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs.h#2 (text+ko) ==== @@ -31,25 +31,42 @@ #define __AUTOFS_MAIN_HEADER__ -#define USE_SETJMP_CLEANUP -#define NO_USE_SETJMP_INCLUDE -#define NO_CLEANUP_WARNING +//#define USE_SETJMP_CLEANUP +//#define NO_USE_SETJMP_INCLUDE +//#define NO_CLEANUP_WARNING #define KPRINTF( a, ... ) \ - printf( a, ## __VA_ARGS__ );\ - uprintf( a, ## __VA_ARGS__ ); + do {\ + printf( a, ## __VA_ARGS__ );\ + uprintf( a, ## __VA_ARGS__ );\ + } while( 0 ) + + + +#ifndef DEBUG_LEVEL +#define DEBUG_LEVEL 8 +#endif /** DEBUG_LEVEL **/ + +#define DEBUG_L( level ) if( DEBUG_LEVEL >= level ) +#define DEBUG DEBUG8 -#define DEBUGGING_ON 1 +#define DEBUG1 DEBUG_L( 1 ) +#define DEBUG2 DEBUG_L( 2 ) +#define DEBUG3 DEBUG_L( 3 ) +#define DEBUG4 DEBUG_L( 4 ) +#define DEBUG5 DEBUG_L( 5 ) +#define DEBUG6 DEBUG_L( 6 ) +#define DEBUG7 DEBUG_L( 7 ) +#define DEBUG8 DEBUG_L( 8 ) -#define DEBUG if( DEBUGGING_ON ) #define STOR_NAME_MAX 64 -#define MNT_TARGET ( "target" ) +#define MNT_TARGET ( "fspath" ) #define MNT_DEVICE ( "from" ) @@ -68,10 +85,15 @@ struct cdev *ctrl_dev; }; +#define entity( member, value )\ + .member = value + #define VFSTOAUTOFS(mp) ((struct autofs_mount *)((mp)->mnt_data)) +int vn_iscdev( struct vnode *vp, int *errp ); + //extern struct vop_vector autofs_vnodeops; ==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_vfsops.c#2 (text+ko) ==== @@ -55,55 +55,106 @@ -MALLOC_DEFINE( M_AUTOFS_MOUNTBUF, "AutoFS mntbuf", "AutoFS mountpoint data, to simulate filesystem contents." ); + + +MALLOC_DEFINE(M_AUTOFS_MOUNTBUF, "AutoFS mntbuf", "AutoFS mountpoint data, to simulate filesystem contents."); static int -autofs_mount( struct mount *mp, struct thread *td ) +autofs_mount(struct mount *mp, struct thread *td) { - $cleanup_init; + $cleanup_init_size(8); int error = 0; struct vnode *devvp; - //struct autofs_mount *a_mnt; + struct autofs_mount *a_mnt; struct nameidata ndp; /* Mount point path and length */ char *m_dev; + devvp= NULL; + DEBUG KPRINTF("Now mounting autofs...\n"); /* Update and rootfs are not allowed. */ - if ((mp->mnt_flag & (MNT_ROOTFS | MNT_UPDATE)) != 0) + if ((mp->mnt_flag & (MNT_UPDATE)) != 0) { + DEBUG KPRINTF("Failed update\n"); + $return (EOPNOTSUPP); + } + if ((mp->mnt_flag & (MNT_ROOTFS)) != 0) { + DEBUG KPRINTF("Failed autofs\n"); $return (EOPNOTSUPP); + } + /* Get the mount device (which is the autofs ctl point) */ m_dev = vfs_getopts(mp->mnt_optnew, MNT_DEVICE, &error); - if (error != 0) + if (error != 0) { + DEBUG KPRINTF("Failed in mount options\n"); $return (error); + } /* check that the device is a real device, and an autofs ctl point */ + DEBUG KPRINTF("Now going to lookup devvp...\n"); NDINIT(&ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, m_dev, td); - if ((error = namei(&ndp)) != 0) + DEBUG KPRINTF("NDINIT done...\n"); + if ((error = namei(&ndp)) != 0) { + DEBUG KPRINTF("namei failed\n"); $return (error); + } + + DEBUG KPRINTF("device mounting from %s\n", ndp.ni_dirp); + NDFREE(&ndp, NDF_ONLY_PNBUF); + DEBUG KPRINTF("NDFREE done...\n" ); + devvp = ndp.ni_vp; + DEBUG KPRINTF("Devvp path is looked up...\n"); - $cleanup( vrele(devvp); ); - + $cleanup( + DEBUG KPRINTF("running vrele...\n"); + vrele(devvp); + DEBUG KPRINTF("vrele done...\n"); + ); - if (vn_isdisk(devvp, &error)){ + DEBUG KPRINTF("Done looking up devvp...\n"); + + if (!vn_iscdev(devvp, &error)){ + DEBUG KPRINTF("Device type check failed...\n" + "error: %d\n", error ); $return (error); } + + DEBUG KPRINTF("Making autofs mount structure..."); + a_mnt = (struct autofs_mount *) malloc(sizeof(struct autofs_mount), + M_AUTOFS_MOUNTBUF, M_WAITOK); + DEBUG KPRINTF("Done\n"); + + DEBUG KPRINTF("Getting newfsid..."); + vfs_getnewfsid(mp); + DEBUG KPRINTF("Done\n"); + + DEBUG KPRINTF("Setting vfs_mountedfrom..."); + vfs_mountedfrom(mp, "autofs"); + DEBUG KPRINTF("Done\n"); + + + //DEBUG $return (EOPNOTSUPP); + + $cleanup( + DEBUG KPRINTF("Mount done -- error = %d...\n", error); + ); + DEBUG KPRINTF("Leaving mount, invoking cleanups -- error = %d...\n", + error); $return (error); - } static int autofs_unmount(struct mount *mp, int mntflags, struct thread *td) { $cleanup_init; - void *mntdata; + //void *mntdata; int error = 0; int flags = 0; @@ -114,10 +165,14 @@ if((error = vflush(mp, 0, flags, td))) $return (error); - vinvalbuf( mp->mnt_data-> + //vinvalbuf( mp->mnt_data-> + + $return (error); +} static struct vfsops autofs_vfsops = { - .vfs_mount = autofs_mount, + entity(vfs_mount, autofs_mount), + entity(vfs_unmount, autofs_unmount), }; VFS_SET(autofs_vfsops, autofs, 0); ==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_vnops.c#2 (text+ko) ==== @@ -26,3 +26,32 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "autofs.h" +#include "cleanup.h" +//#include "protocol.h" + + + +struct vop_vector autofs_vnodeops ={ + +}; ==== //depot/projects/soc2006/adamartin_autofs/autofs/cleanup.h#2 (text+ko) ==== @@ -70,7 +70,7 @@ #if defined( __GNUC__ ) && !defined( USE_SETJMP_CLEANUP ) -typedef void (*__cleanup_ptr)(); +typedef void (*__cleanup_ptr)( void ); typedef void *___generic___; @@ -85,7 +85,7 @@ #define REGISTER_ACTION( actions ) _REGISTER_ACTION( LN, actions ) #define _REGISTER_ACTION( name, actions ) \ - void ___cleanup_action_( name ) ()\ + static void ___cleanup_action_( name ) ( void )\ {\ actions\ }\ @@ -172,6 +172,13 @@ [ __CLEANUP_STACK_MAX__ ];\ __VOLATILE_IMPLEMENTATION__ int __CLEANUP_STACK_POINTER__= 0 + +#define CLEANUP_STACK_SIZE( size )\ + ___CLEANUP_STACK_EXTRAS___\ + __VOLATILE_IMPLEMENTATION__ __cleanup_ptr ___CLEANUP_STACK \ + [ size ];\ + __VOLATILE_IMPLEMENTATION__ int __CLEANUP_STACK_POINTER__= 0 + /** Use REGISTER_CLEANUP_LOCAL *** XXX BEFORE XXX *** you register an action to use that local with. It's just a void *. You must re-cast it to what is useful to you. **/ @@ -188,6 +195,7 @@ #define $cleanup_init CLEANUP_STACK +#define $cleanup_init_size( a ) CLEANUP_STACK_SIZE( a ) #define $cleanup( a ) REGISTER_ACTION( a ) #define $return leave ==== //depot/projects/soc2006/adamartin_autofs/mount_autofs/mount_autofs.c#2 (text+ko) ==== @@ -60,7 +60,7 @@ #define FSTYPE "autofs" #define FSTYPE_HANDLE "fstype" -#define SOURCE "source" +#define SOURCE "fspath" #define TARGET "from" @@ -82,40 +82,33 @@ char source[MAXPATHLEN]; char target[MAXPATHLEN]; - mntflags = 0; - while ((ch = getopt(argc, argv, "o:")) != -1) - switch(ch) { - case 'o': - getmntopts(optarg, mopts, &mntflags, 0); - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - if (argc != 2) + if (argc != 3) usage(); /* resolve target and source with realpath(3) */ - (void)checkpath(argv[0], target); - (void)checkpath(argv[1], source); + //(void)checkpath(argv[0], target); + fprintf(stderr, "argv[ 1 ]= %s, argv[ 2 ]= %s\n", + argv[ 1 ], argv[ 2 ] ); + strcpy(target, argv[1]); + (void)checkpath(argv[2], source); iov[0].iov_base = FSTYPE_HANDLE; - iov[0].iov_len = sizeof(FSTYPE_HANDLE); + iov[0].iov_len = strlen(FSTYPE_HANDLE) + 1; iov[1].iov_base = FSTYPE; iov[1].iov_len = strlen(iov[1].iov_base) + 1; + iov[2].iov_base = SOURCE; - iov[2].iov_len = sizeof(SOURCE); + iov[2].iov_len = strlen(SOURCE) + 1; iov[3].iov_base = source; iov[3].iov_len = strlen(source) + 1; + iov[4].iov_base = TARGET; - iov[4].iov_len = sizeof(TARGET); + iov[4].iov_len = strlen(TARGET) + 1; iov[5].iov_base = target; iov[5].iov_len = strlen(target) + 1; - if (nmount(iov, 6, mntflags)) + if (nmount(iov, 6, MNT_RDONLY)) err(1, NULL); exit(0); }