PERFORCE change 109900 for review
Adam Martin
adamartin at FreeBSD.org
Tue Nov 14 02:08:16 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=109900
Change 109900 by adamartin at adamartin_hobbes on 2006/11/14 01:59:39
Adding autofs_subr.[ch] for using circular queue mechanisms. Importing
updated versions of macro headers, and adding more autofs_ctl device
support.
Affected files ...
.. //depot/projects/soc2006/adamartin_autofs/autofs/Makefile#4 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/README#3 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs.c#5 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs.h#5 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.c#4 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.h#3 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.c#4 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.h#2 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_pfsops.c#4 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_subr.c#1 add
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_subr.h#1 add
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_vfsops.c#5 delete
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_vnops.c#4 delete
.. //depot/projects/soc2006/adamartin_autofs/autofs/cleanup.h#5 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/protocol.c#4 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/protocol.h#4 edit
.. //depot/projects/soc2006/adamartin_autofs/pseudofs/pseudofs.h#2 edit
.. //depot/projects/soc2006/adamartin_autofs/pseudofs/pseudofs_vnops.c#3 edit
Differences ...
==== //depot/projects/soc2006/adamartin_autofs/autofs/Makefile#4 (text+ko) ====
==== //depot/projects/soc2006/adamartin_autofs/autofs/README#3 (text+ko) ====
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs.c#5 (text+ko) ====
@@ -50,13 +50,10 @@
#include "autofs.h"
#include "autofs_ctl.h"
-
-
+#include "debug.h"
-/** There's no more block devices, so all are cdevs, as c represents char
-in cdev **/
@@ -65,19 +62,20 @@
autofs_handle_loader( struct module *mod, int action, void *args )
{
int err= 0;
- switch (action) {
+ switch( action )
+ {
case MOD_LOAD:
- KPRINTF("Now loading AutoFS module: \n");
- autofs_ctl_dev = make_dev(&autofs_ctl_devops,
- 00,
- UID_ROOT,
- GID_WHEEL,
- 0600,
- AUTOFS_CTL_DEV_NAME);
- DEBUG KPRINTF(".");
+ EPRINTF( "Now loading AutoFS module: \n" );
+ autofs_ctl_dev = make_dev( &autofs_ctl_devops,
+ 00,
+ UID_ROOT,
+ GID_WHEEL,
+ 0600,
+ AUTOFS_CTL_DEV_NAME );
+ DEBUG EPRINTF( "." );
autofs_ctl_init();
- DEBUG KPRINTF(".");
- KPRINTF("AutoFS module successfully loaded.\n");
+ DEBUG EPRINTF( "." );
+ EPRINTF( "AutoFS module successfully loaded.\n" );
break;
case MOD_QUIESCE:
@@ -86,22 +84,23 @@
* Find out what we should do for QUIESCE option?
*
*/
- KPRINTF("AutoFS quiesced.\n");
+ EPRINTF( "AutoFS quiesced.\n" );
return 0;
+ break;
case MOD_UNLOAD:
- destroy_dev(autofs_ctl_dev);
- //free(autofs_ctl_state, M_AUTOFS_CTL_NODES);
- KPRINTF("AutoFS unloaded.\n");
+ destroy_dev( autofs_ctl_dev );
+ //free( autofs_ctl_state, M_AUTOFS_CTL_NODES );
+ EPRINTF( "AutoFS unloaded.\n" );
break;
default:
err= EINVAL;
- KPRINTF("Error -- action %d not supported!\n",
- action);
- KPRINTF("MOD_LOAD= %d, MOD_UNLOAD= %d\n",
- MOD_LOAD, MOD_UNLOAD);
+ EPRINTF( "Error -- action %d not supported!\n",
+ action );
+ EPRINTF( "MOD_LOAD= %d, MOD_UNLOAD= %d\n",
+ MOD_LOAD, MOD_UNLOAD );
break;
}
@@ -110,30 +109,36 @@
-int vn_iscdev(struct vnode *vp, int *errp);
+int vn_iscdev( struct vnode *vp, int *errp );
int
-vn_iscdev(struct vnode *vp, int *errp)
+vn_iscdev( struct vnode *vp, int *errp )
{
- int error = 0;
+ $cleanup_init_size( 8 );
+ int error= 0;
- dev_lock();
+ dev_lock();
+ $cleanup( dev_unlock(); );
+
- if (vp->v_type != VCHR)
+ 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;
+ else if( vp->v_rdev == NULL )
+ {
+ error= ENXIO;
+ }
+ else if( vp->v_rdev->si_devsw == NULL )
+ {
+ error= ENXIO;
+ }
#endif
- dev_unlock();
-
+ $do_cleanup;
if (errp != NULL)
- *errp = error;
- return (error == 0);
+ *errp= error;
+ $return ( error == 0 );
}
DEV_MODULE( AutoFS, autofs_handle_loader, NULL );
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs.h#5 (text+ko) ====
@@ -30,7 +30,13 @@
#ifndef __AUTOFS_MAIN_HEADER__
#define __AUTOFS_MAIN_HEADER__
+#define USE_SETJMP_CLEANUP
+#define NO_USE_SETJMP_INCLUDE
+#define NO_CLEANUP_WARNING
+#define FREEBSD_SYS
+#include "cleanup.h"
+
#define AUTOFS_VERSION ( 1 )
//#define MIN( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
@@ -41,34 +47,6 @@
//#define NO_CLEANUP_WARNING
-#define KPRINTF( a, ... ) \
- 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 DEBUG5
-
-#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 MNT_TARGET ( "fspath" )
#define MNT_DEVICE ( "from" )
@@ -76,8 +54,9 @@
#define entity( member, value )\
- .member = value
+ .member= value
+#define KPRINTF EPRINTF
#endif /*** __AUTOFS_MAIN_HEADER__ ***/
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.c#4 (text+ko) ====
@@ -50,7 +50,7 @@
static d_ioctl_t autofs_ctl_ioctl;
-struct cdevsw autofs_ctl_devops = {
+static struct cdevsw autofs_ctl_devops = {
.d_version= D_VERSION,
.d_open= NULL,
.d_close= NULL,
@@ -63,8 +63,48 @@
int
autofs_ctl_init()
{
- DEBUG KPRINTF("Initializing "
+ DEBUG KPRINTF( "Initializing " )
+}
+
+MALLOC_DECLARE( M_AUTOFS_DEV );
+MALLOC_DEFINE( M_AUTOFS_DEV, "autofs_dev", "autofs device structure" );
+
+MALLOC_DECLARE( M_AUTOFS_DEV_BUFFERS );
+MALLOC_DEFINE( M_AUTOFS_DEV_BUFFERS, "autofs_dev_buffers", "autofs device io buffers" );
+
+int create_autofs_node( int num )
+{
+ int error;
+ struct cdevsw *autofs_cdevsw;
+ struct cdev *autofs_cdev;
+ struct autofs_dev_data *autofs_dev_data;
+
+ autofs_cdevsw= malloc( sizeof( struct cdevsw ), M_AUTOFS_DEV, M_WAITOK );
+ autofs_dev_data= malloc( sizeof( struct autofs_dev_data ), M_AUTOFS_DEV_BUFFERS,
+ M_WAITOK );
+
+ autofs_dev_data.input= malloc( IOV_BUF_COUNT * sizeof( struct iovec * ), M_AUTOFS_DEV_BUFFERS, M_WAITOK );
+ autofs_dev_data.output= malloc( IOV_BUF_COUNT * sizeof( struct iovec * ), M_AUTOFS_DEV_BUFFERS, M_WAITOK );
+
+ autofs_cdevsw->d_open= autofs_dev_open;
+ autofs_cdevsw->d_close= autofs_dev_close;
+ autofs_cdevsw->d_read= autofs_dev_read;
+ autofs_cdevsw->d_write= autofs_dev_write;
+ autofs_cdevsw->d_poll= autofs_dev_poll;
+ autofs_cdevsw->d_version= D_VERSION;
+ autofs_cdevsw->d_name= "autofs_dev";
+
+ autofs_cdev= make_dev( autofs_cdevsw, num, UID_ROOT, GID_WHEEL, 0600, "autofs%d", num );
+ if( autofs_cdev == NULL )
+ {
+ panic( "Bad autofs_cdev\n" );
+ }
+ autofs_cdev->si_priv= (struct cdev_priv *) autofs_dev_data;
+
+ return 0;
+}
+
/*
* We only handle the IOCTLS for create and destroy autofs_dev instances.
@@ -78,8 +118,8 @@
static int
-autofs_ctl_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg_c, int mode,
- struct thread *td)
+autofs_ctl_ioctl( struct cdev *i_dev, u_long cmd, caddr_t arg_c, int mode,
+ struct thread *td )
{
$cleanup_init_size( 8 );
int error= 0;
@@ -89,17 +129,17 @@
arg= NULL;
$return EOPNOTSUPP;
- #if 0
+ #if 1
switch( cmd ) {
case AFSIOCREATDEV:
- mtx_lock(&autofs_ctl_state.lock);
+ /* mtx_lock(&autofs_ctl_state.lock);
$cleanup(
mtx_unlock(&autofs_ctl_state.lock);
)
-
+ */
arg= autofs_ctl_state.next_assignable_node++;
- error= create_autofs_node(arg);
+ error= create_autofs_node( arg );
$do_cleanup;
@@ -115,4 +155,5 @@
error= EIO;
#endif
+ return error;
}
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.h#3 (text+ko) ====
@@ -74,7 +74,10 @@
-
+struct autofs_dev_data {
+ struct uio input;
+ struct uio output
+};
/** Are we allowed to reuse group "a"? **/
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.c#4 (text+ko) ====
@@ -28,6 +28,7 @@
*/
#include "autofs.h"
+#include "protocol.h"
#include <sys/types.h>
#include <sys/module.h>
@@ -46,19 +47,19 @@
struct uio *in_buffer, *out_buffer;
-#define IOV_BUF_COUNT ( 16 )
-
int
write_buffer( struct uio *buf, void *data, int len )
{
$cleanup_init_size( 8 );
int error;
- error = 0;
+ error= 0;
if( buf->uio_iovcnt < IOV_BUF_COUNT )
{
buf->uio_iov[ buf->uio_iovcnt ].iov_base= data;
buf->uio_iov[ buf->uio_iovcnt ].iov_len= len;
buf->uio_iovcnt++;
+
+ parse_messages();
}
else
{
@@ -68,3 +69,10 @@
$return error;
}
+
+
+int autofs_dev_open( struct cdev *dev, int oflags, int devtype, struct thread *td )
+{
+ int error;
+ int i;
+}
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.h#2 (text+ko) ====
@@ -1,6 +1,16 @@
#include <sys/types.h>
#include <sys/uio.h>
+
+#define IOV_BUF_COUNT ( 16 )
+
extern struct uio *in_buffer, *out_buffer;
int write_buffer( struct uio *buf, void *data, int len );
+
+
+int autofs_dev_open( struct cdev *dev, int oflags, int devtype, struct thread *td );
+int autofs_dev_close( struct cdev *dev, int oflags, int devtype, struct thread *td );
+int autofs_dev_read( struct cdev *dev, struct uio *uio, int ioflag );
+int autofs_dev_write( struct cdev *dev, struct uio *uio, int ioflag );
+int autofs_dev_poll( struct cdev *dev, int events, struct thread *td );
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_pfsops.c#4 (text+ko) ====
@@ -56,6 +56,7 @@
#include <fs/pseudofs/pseudofs.h>
#include "protocol.h"
+#include "debug.h"
MALLOC_DEFINE(M_AUTOFS_MOUNTBUF, "AutoFS mntbuf", "AutoFS mountpoint data, to simulate filesystem contents.");
==== //depot/projects/soc2006/adamartin_autofs/autofs/cleanup.h#5 (text+ko) ====
@@ -1,7 +1,10 @@
-/*-
+/*
* Copyright (c) 2006 ADAM David Alan Martin
* LSD Kernel Project, All Rights Reserved.
*
+ * Copyright (c) 2006 ADAM David Alan Martin
+ * FreeBSD Project, All Rights Reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -20,7 +23,7 @@
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT, AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
@@ -37,6 +40,21 @@
#ifndef __CLEANUP_H__
#define __CLEANUP_H__
+#ifdef LSD
+
+#include <cdefs.h>
+
+__LSDHEADERID( cleanup, "$Id: cleanup.i 252 2006-10-31 23:54:52Z adam $" );
+#else
+static const char *__lsdid_cleanup_header__ __attribute__(( unused ))= "$Id: cleanup.i 252 2006-10-31 23:54:52Z adam $";
+#ifdef FREEBSD
+#include <sys/cdefs.h>
+
+/* __FBSDID( "$FreeBSD$" ); */
+#endif
+
+#endif /* LSD */
+
@@ -78,11 +96,11 @@
#define __VOLATILE_IMPLEMENTATION__ /** No volatile for nested functions **/
-#define LN __LINE__
+#define __CLN_LN__ __LINE__
#define ___cleanup_action_( a ) ___cleanup_action___ ## a
-#define REGISTER_ACTION( actions ) _REGISTER_ACTION( LN, actions )
+#define REGISTER_ACTION( actions ) _REGISTER_ACTION( __CLN_LN__, actions )
#define _REGISTER_ACTION( name, actions ) \
static void ___cleanup_action_( name ) ( void )\
@@ -115,8 +133,16 @@
/** The setjmp/longjmp implementation of the cleanup library.
This one is really nasty-ugly **/
-#ifndef NO_USE_SETJMP_INCLUDE
-#include <setjmp.h>
+
+#ifdef FREEBSD_SYS
+# include <machine/setjmp.h>
+
+#else
+
+# ifndef NO_USE_SETJMP_INCLUDE
+# include <setjmp.h>
+# endif
+
#endif
#ifndef NO_CLEANUP_WARNING
@@ -126,8 +152,13 @@
#define __VOLATILE_IMPLEMENTATION__ volatile
/** Yes we're volatile for this one **/
+#ifdef FREEBSD
+#ifdef KERNEL
typedef struct _jmp_buf *__cleanup_ptr;
-//#define __cleanup_ptr struct _jmp_buf *
+#endif
+#else
+typedef jmp_buf __cleanup_ptr;
+#endif
#define ___CLEANUP_STACK_EXTRAS___ \
__cleanup_ptr ___CLEANUP_STACK_DISPATCHER= NULL;\
@@ -168,16 +199,22 @@
#define CLEANUP_STACK\
___CLEANUP_STACK_EXTRAS___\
+ __VOLATILE_IMPLEMENTATION__ ___generic___ ___CLEANUP_LOCALS___ \
+ [ __CLEANUP_STACK_MAX__ ];\
__VOLATILE_IMPLEMENTATION__ __cleanup_ptr ___CLEANUP_STACK \
[ __CLEANUP_STACK_MAX__ ];\
- __VOLATILE_IMPLEMENTATION__ int __CLEANUP_STACK_POINTER__= 0
-
+ __VOLATILE_IMPLEMENTATION__ int __CLEANUP_STACK_POINTER__= 0;\
+ ___CLEANUP_LOCALS___[ 0 ]= 0
#define CLEANUP_STACK_SIZE( size )\
___CLEANUP_STACK_EXTRAS___\
+ __VOLATILE_IMPLEMENTATION__ ___generic___ ___CLEANUP_LOCALS___ \
+ [ size ];\
__VOLATILE_IMPLEMENTATION__ __cleanup_ptr ___CLEANUP_STACK \
[ size ];\
- __VOLATILE_IMPLEMENTATION__ int __CLEANUP_STACK_POINTER__= 0
+ __VOLATILE_IMPLEMENTATION__ int __CLEANUP_STACK_POINTER__= 0;\
+ ___CLEANUP_LOCALS___[ 0 ]= 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
@@ -190,6 +227,15 @@
#define GET_LOCAL()\
( ___CLEANUP_LOCALS___[ __CLEANUP_STACK_POINTER___ ] )
+#define POP_CLEANUP\
+ do\
+ {\
+ if( __CLEANUP_STACK_POINTER___ )\
+ {\
+ ( __CLEANUP_STACK_POINTER___-- );\
+ }\
+ } while( 0 );
+
/*** OOPC names: ***/
@@ -207,6 +253,8 @@
#define $reset_cleanup RESET_CLEANUP
+#define $pop_cleanup POP_CLEANUP
+
#endif /*** __CLEANUP_H__ ***/
==== //depot/projects/soc2006/adamartin_autofs/autofs/protocol.c#4 (text+ko) ====
==== //depot/projects/soc2006/adamartin_autofs/autofs/protocol.h#4 (text+ko) ====
@@ -224,4 +224,6 @@
int send_mount_request(struct message_header *req);
+int parse_user_message();
+
#endif /*** AUTOFS_PROTOCOL_HEADER ***/
==== //depot/projects/soc2006/adamartin_autofs/pseudofs/pseudofs.h#2 (text+ko) ====
@@ -43,6 +43,7 @@
struct uio;
struct vfsconf;
struct vnode;
+struct componentname;
/*
* Limits and constants
@@ -137,7 +138,7 @@
*/
#define PFS_LOOKUP_ARGS \
struct thread *td, struct proc *p, struct pfs_node *pn, \
- unsigned long cmd, void *data
+ struct componentname *cnp
#define PFS_LOOKUP_PROTO(name) \
int name(PFS_LOOKUP_ARGS);
typedef int (*pfs_lookup_t)(PFS_LOOKUP_ARGS);
==== //depot/projects/soc2006/adamartin_autofs/pseudofs/pseudofs_vnops.c#3 (text+ko) ====
More information about the p4-projects
mailing list