PERFORCE change 118076 for review
Adam Martin
adamartin at FreeBSD.org
Sat Apr 14 04:20:12 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=118076
Change 118076 by adamartin at adamartin_hobbes on 2007/04/14 04:19:21
Checkin of changes before scheduled outage.
(fixes to many crash conditions.)
Affected files ...
.. //depot/projects/soc2006/adamartin_autofs/autofs/Makefile#9 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs.c#10 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.c#11 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.c#10 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.h#8 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_tfsinit.c#2 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_tfsops.c#5 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/debug.h#2 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/protocol.c#10 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/protocol.h#9 edit
.. //depot/projects/soc2006/adamartin_autofs/templatefs/templatefs.h#4 edit
.. //depot/projects/soc2006/adamartin_autofs/templatefs/templatefs_vnops.c#3 edit
Differences ...
==== //depot/projects/soc2006/adamartin_autofs/autofs/Makefile#9 (text+ko) ====
@@ -28,9 +28,11 @@
AUTOFS_DEV_SOURCE=autofs_ctl.c autofs_dev.c
AUTOFS_FS_SOURCE=autofs_tfsops.c autofs_tfsinit.c vnode_if.h
-AUTOFS_CORE_SOURCE=autofs.c protocol.c
+AUTOFS_CORE_SOURCE=autofs.c
+AUTOFS_PROTOCOL_SOURCE=protocol.c
AUTOFS_SUPPORT_SOURCE=autofs_subr.c
-SRCS=$(AUTOFS_CORE_SOURCE) $(AUTOFS_FS_SOURCE) $(AUTOFS_DEV_SOURCE) $(AUTOFS_SUPPORT_SOURCE)
+SRCS=$(AUTOFS_CORE_SOURCE) $(AUTOFS_FS_SOURCE) $(AUTOFS_DEV_SOURCE) $(AUTOFS_SUPPORT_SOURCE) $(AUTOFS_PROTOCOL_SOURCE)
+#SRCS=$(AUTOFS_CORE_SOURCE) $(AUTOFS_PROTOCOL_SOURCE) $(AUTOFS_SUPPORT_SOURCE) $(AUTOFS_DEV_SOURCE)
HEADERS=autofs.h cleanup.h protocol.h autofs_subr.h autofs_ctl.h autofs_dev.h debug.h
KMOD=autofs
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs.c#10 (text+ko) ====
@@ -53,10 +53,13 @@
#include "debug.h"
+#define PUBLIC_LOADER static
+PUBLIC_LOADER int autofs_handle_loader(
+ struct module *mod, int action, void *args );
-static int
+PUBLIC_LOADER int
autofs_handle_loader( struct module *mod, int action, void *args )
{
int err;
@@ -73,6 +76,8 @@
GID_WHEEL,
0600,
AUTOFS_CTL_DEV_NAME );
+
+ dev_depends( autofs_ctl_dev, autofs_ctl_dev );
DEBUG EPRINTF( "." );
autofs_ctl_init();
DEBUG EPRINTF( "." );
@@ -85,16 +90,17 @@
* Find out what we should do for QUIESCE option?
*
*/
+
+ //cleanup_autofs();
+ //free( autofs_ctl_state, M_AUTOFS_CTL_NODES );
+ destroy_dev( autofs_ctl_dev );
EPRINTF( "AutoFS quiesced.\n" );
return 0;
break;
case MOD_UNLOAD:
- //cleanup_autofs();
- destroy_dev( autofs_ctl_dev );
- //free( autofs_ctl_state, M_AUTOFS_CTL_NODES );
- EPRINTF( "AutoFS unloaded.\n" );
+ printf( "AutoFS unloaded.\n" );
break;
default:
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.c#11 (text+ko) ====
@@ -40,6 +40,8 @@
#include <sys/lock.h>
#include <sys/mutex.h>
+#include <sys/stat.h>
+
//#include <machine/setjmp.h>
//#include "cleanup.h">
@@ -53,6 +55,14 @@
#define AUTOFS_NAME "autofs_dev"
+
+#define AUTOFS_DEV_PERMS ( \
+ ( ( S_IRUSR ) | ( S_IWUSR ) ) \
+ | \
+ ( ( S_IRGRP ) | ( S_IWGRP ) ) \
+ )
+
+
struct cdev *autofs_ctl_dev;
struct autofs_ctl_state autofs_ctl_state;
@@ -76,7 +86,7 @@
.d_close= autofs_dev_close,
.d_read= autofs_dev_read,
.d_write= autofs_dev_write,
- .d_poll= autofs_dev_poll,
+ //.d_poll= autofs_dev_poll,
.d_version= D_VERSION,
.d_name= AUTOFS_NAME,
};
@@ -121,7 +131,7 @@
{
$cleanup_init;
- int error;
+ int error;
struct cdevsw *devsw;
struct cdev *device;
struct autofs_dev_bufs *buffers;
@@ -129,9 +139,15 @@
struct tfs_info *ti;
struct autofs_protocol_state *prot_state;
- error= 0;
+ error= 0;
+
+ ti= NULL;
+
- instance_p= NULL;
+ /*
+ * TODO: return instance via instance_p. For now we leak...
+ */
+ instance_p= NULL;
/*
* Allocate all autofs buffers, and setup a new TemplateFS instance.
@@ -157,9 +173,7 @@
{
$return ( error );
}
-# if 0
- $cleanup( tfs_destroy_instance( ti ););
-# endif
+ // $cleanup( tfs_destroy_instance( ti ); );
/*
* Associate TemplateFS data structures together
@@ -167,20 +181,20 @@
- prot_state->message= NULL;
- prot_state->current_state= PROTOCOL_WAITING;
- prot_state->bytes_read= 0;
+ prot_state->message= NULL;
+ prot_state->current_state= PROTOCOL_WAITING;
+ prot_state->bytes_read= 0;
- buffers->input= autofs_queue_init();
- buffers->output= autofs_queue_init();
- buffers->instances= 0;
+ buffers->input= autofs_queue_init();
+ buffers->output= autofs_queue_init();
+ buffers->instances= 0;
/*
* Make the device, and lock it.
*/
- device= make_dev( devsw, num, UID_ROOT, GID_WHEEL, 0600,
+ device= make_dev( devsw, num, UID_ROOT, GID_WHEEL, AUTOFS_DEV_PERMS,
AUTOFS_DEV_FORMAT"%d", num );
/* Possible race? Locking the device? */
@@ -192,11 +206,12 @@
{
panic( "Bad device in %s:%d\n", __FILE__, __LINE__ );
}
- prot_state->instance= instance;
- buffers->this_instance= instance;
- ti->ti_priv= (void *) instance;
- device->si_priv= (struct cdev_priv *) instance;
- instance->templatefs_info= ti;
+ prot_state->instance= instance;
+ buffers->this_instance= instance;
+ ti->ti_priv= (void *) instance;
+ device->si_priv= (struct cdev_priv *) instance;
+ instance->templatefs_info= ti;
+ instance->dev_buffers= buffers;
/*
* Don't deallocate the resources --
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.c#10 (text+ko) ====
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2006
+ * Copyright (c) 2006,2007
* Adam Martin, Erez Zadok. All rights reserved.
*
* This code is derived from software in FreeBSD, and 4.4BSD.
@@ -48,8 +48,21 @@
#include "autofs_dev.h"
#include "autofs_subr.h"
+#include <sys/time.h>
+
#define AUTOFS_IO_BUF_SIZE ( 4096 )
+#define LONG_TIMEOUT_SECONDS ( 10 )
+#define TIMEOUT_MICROSECONDS ( 50000 )
+
+static struct timeval __LONG_TIMEOUT_SECONDS=
+{
+ .tv_sec= 0,
+ .tv_usec= TIMEOUT_MICROSECONDS,
+};
+
+#define LONG_TIMEOUT ( tvtohz( &__LONG_TIMEOUT_SECONDS ) )
+
struct uio *in_buffer, *out_buffer;
@@ -72,15 +85,19 @@
error= 0;
+ DEBUG printf( "Trying to open AutoFS device...\n" );
+
instance= AUTOFS_GET_INSTANCE( DEV, dev );
buffers= AUTOFS_GET_BUFFERS( DEV, dev );
inst_p= &( buffers->instances );
+ DEBUG printf( "AutoFS Device instances: %d\n", *inst_p );
+
if( *inst_p == 0 )
{
( *inst_p )++;
} else {
- DEBUG EPRINTF( "Tried to open the autofs device \"%s\" "
+ DEBUG printf( "Tried to open the autofs device \"%s\" "
"multiple times!\n", dev->si_devsw->d_name );
error= ENXIO;
}
@@ -105,7 +122,7 @@
if( *inst_p == 0 )
{
- DEBUG EPRINTF( "Tried to close device: \"%s\", beyond natural "
+ DEBUG printf( "Tried to close device: \"%s\", beyond natural "
"close minimum!\n", dev->si_devsw->d_name );
error= EDOOFUS;
}
@@ -131,6 +148,9 @@
int amt;
int error;
unsigned char out_buf[ AUTOFS_IO_BUF_SIZE ]; /* No more than a page! */
+ int sleepstat;
+
+ DEBUG7 printf( "Entered autofs_dev_read\n" );
error= 0;
amt= MIN( uio->uio_resid, AUTOFS_IO_BUF_SIZE );
@@ -142,11 +162,42 @@
do
{
remains= autofs_queue_remaining( q );
+ DEBUG7 printf( "Got %d remaining bytes...\n", remains );
/*
* We really should do SOME kind of sleep. This is
* more a spinlock
* right now.
*/
+
+ if( remains != 0 ) break;
+ sleepstat= tsleep( q, PCATCH, "BAFS", LONG_TIMEOUT );
+
+ switch( sleepstat )
+ {
+ case EWOULDBLOCK:
+ SKIP DEBUG printf( "Blocking more.\n" );
+ break;
+
+
+ case ERESTART:
+ DEBUG_L(17) printf( "restart system call?\n" );
+
+ return ERESTART;
+ break;
+
+ case EINTR:
+ DEBUG_L(17) printf( "Interrupted... die?\n" );
+
+ return EINTR;
+ break;
+
+
+ default:
+ /** NOTREACHED **/
+ DEBUG0 printf( "Unknown sleepstatus!\n" );
+ break;
+ }
+
}
while( remains == 0 ); /** FIXME: Shouldn't this be == **/
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.h#8 (text+ko) ====
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_tfsinit.c#2 (text+ko) ====
@@ -27,6 +27,8 @@
*
*/
+#define FIXED_VFS_SET_BUG
+
#include "autofs.h"
#include <sys/cdefs.h>
#include <sys/types.h>
@@ -72,6 +74,8 @@
struct tfs_node *foo;
+void null_wrapper______( void );
+
static struct tfs_info *
autofs_mount_handler( TFS_MOUNT_HANDLER_ARGS )
@@ -130,12 +134,16 @@
ti->ti_priv= AUTOFS_GET_INSTANCE( DEV, dev );
+ strlcpy( ti->ti_name, dev_name, TFS_FSNAMELEN );
+
DEBUG3 EPRINTF( "Making a fake node: %p is the parent (root) node",
ti->ti_root );
foo= tfs_create_dir( ti->ti_root, "foo", autofs_attr, autofs_vis, 0 );
foo->tn_lookup= autofs_lookup;
+ vput( devvp );
+
DEBUG3 EPRINTF( "leaving autofs_mount\n" );
return ti;
}
@@ -180,8 +188,8 @@
/** Make some fake files... Could be that these are killing us? **/
- foo= tfs_create_dir( ti->ti_root, "foo", autofs_attr, autofs_vis, 0 );
- foo->tn_lookup= autofs_lookup;
+ //foo= tfs_create_dir( ti->ti_root, "foo", autofs_attr, autofs_vis, 0 );
+ //foo->tn_lookup= autofs_lookup;
return 0;
}
@@ -192,5 +200,19 @@
return 0;
}
+#ifndef FIXED_VFS_SET_BUG
+#undef VFS_SET
+#define VFS_SET( a, b, c )
+#endif
TEMPLATEFS( autofs, AUTOFS_VERSION, autofs_mount_handler );
+
+#ifndef FIXED_VFS_SET_BUG
+void null_wrapper______()
+{
+ autofs_mount_handler( NULL, NULL, NULL );
+ autofs_init( NULL, NULL );
+ autofs_uninit( NULL, NULL );
+ autofs_vfsops= autofs_vfsops;
+}
+#endif
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_tfsops.c#5 (text+ko) ====
@@ -68,6 +68,9 @@
#include "autofs_templatefs.h"
+#define DOTDOT_CHECKER_SHORTCUT SKIP
+
+
int
autofs_vis( TFS_VIS_ARGS )
{
@@ -118,6 +121,11 @@
instance= AUTOFS_GET_INSTANCE( ROOT, ti );
buffers= AUTOFS_GET_BUFFERS( ROOT, ti );
+ if( buffers == NULL )
+ {
+ panic( "Buffers shouldn't be null!" );
+ }
+
DEBUG7 EPRINTF( "cn_nameptr= %s, cn_pnbuf= %s\n", c.cn_nameptr,
c.cn_pnbuf );
DEBUG7 EPRINTF( "cn_namelen= %ld, cn_consume= %ld\n", c.cn_namelen,
@@ -126,14 +134,15 @@
/* Prepare a mount message */
msg.flags= 0;
msg.transaction_id= generate_tid();
+ msg.reserved= 0;
msg.message_type= COMMAND_MOUNT_REQUEST;
- msg.message_data= (char *) &mr;
+ //msg.message_data= (char *) &mr;
mr.action= ACTION_MOUNT;
mr.mountpoint_len= c.cn_namelen;
strlcpy( mr.mountpoint, c.cn_nameptr, c.cn_namelen );
- if( strcmp( mr.mountpoint, ".." ) )
+ DOTDOT_CHECKER_SHORTCUT if( strcmp( mr.mountpoint, ".." ) )
{
return 0;
}
@@ -142,6 +151,7 @@
//if( take_autofs_lock( instance, node ) )
//{
+ DEBUG7 EPRINTF( "Passing protocol message: %p\n", &msg );
send_mount_request( &msg, buffers );
//}
==== //depot/projects/soc2006/adamartin_autofs/autofs/debug.h#2 (text+ko) ====
@@ -125,12 +125,24 @@
#else /*** FREEBSD_SYS ***/
-#define EPRINTF( a, ... ) \
- do\
- {\
- printf( a, ## __VA_ARGS__ );\
- uprintf( a, ## __VA_ARGS__ );\
- } while( 0 )
+
+#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+
+
+#define EPRINTF( a, ... ) \
+ \
+ do \
+ { \
+ printf( a, ## __VA_ARGS__ ); \
+ SKIP if( mtx_trylock( &Giant ) ) \
+ { \
+ mtx_unlock( &Giant ); \
+ uprintf( a, ## __VA_ARGS__ ); \
+ } \
+ } while( 0 ) \
+
#endif /*** FREEBSD_SYS ***/
==== //depot/projects/soc2006/adamartin_autofs/autofs/protocol.c#10 (text+ko) ====
@@ -106,7 +106,7 @@
int cnt;
error= 0;
- cnt=0;
+ cnt= 0;
instance= AUTOFS_GET_INSTANCE( PROTOCOL, protocol );
@@ -261,8 +261,18 @@
struct mount_request *mb;
queue *out_buffer;
+ DEBUG7 EPRINTF( "Sending Mount request...\n" );
+ DEBUG7 EPRINTF( "Given request buffer pointer: %p\n", req );
out_buffer= buffers->output;
- mb= (struct mount_request *) req->message_data;
+ mb= (struct mount_request *) ( *(
+ (struct mount_request **)
+ ( ( (unsigned char *) &req ) + sizeof(
+ struct message_header ) ) ) ) ;
+
+ DEBUG7 EPRINTF( "Mount output buffer %p, request buffer %p\n",
+ out_buffer, mb );
+
+ return 0;
write_buffer( out_buffer, (void *) req,
sizeof( struct message_header ) );
@@ -271,6 +281,7 @@
write_buffer( out_buffer, (void *) mb->mountpoint,
mb->mountpoint_len );
+ DEBUG7 EPRINTF( "Done with mount request write\n" );
return 0;
}
==== //depot/projects/soc2006/adamartin_autofs/autofs/protocol.h#9 (text+ko) ====
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2006
+ * Copyright (c) 2006,2007
* Adam Martin, Erez Zadok. All rights reserved.
*
* This code is derived from software in FreeBSD, and 4.4BSD.
@@ -47,10 +47,17 @@
uint64_t flags; /* flags, for some usage, yet to be determined. */
uint64_t transaction_id; /* Used to identify which transaction
the message pertains to. */
+
+ uint32_t reserved; /* Reserved for future use (Padding for now,
+ keep at 0) */
uint32_t message_type; /* Used to identify which command is issued in
this packet. COMMAND_* constants are used to fill these */
+
+# ifdef AUTOFS_USE_VARIABLE_LENGTH_TERMINATORS
void *message_data; /* The rest of the message data, as an
indeterminate length. */
+
+# endif /*** AUTOFS_USE_VARIABLE_LENGTH_TERMINATORS ***/
};
==== //depot/projects/soc2006/adamartin_autofs/templatefs/templatefs.h#4 (text+ko) ====
@@ -315,6 +315,7 @@
\
static int \
_##name##_init(struct vfsconf *vfc) { \
+ printf( "Initing Templatefs..." ); \
/*return tfs_init(&name##_info, vfc);*/ \
return 0; \
} \
@@ -332,9 +333,9 @@
.vfs_uninit = _##name##_uninit, \
.vfs_unmount = tfs_unmount, \
}; \
-VFS_SET(name##_vfsops, name, VFCF_SYNTHETIC); \
-MODULE_VERSION(name, version); \
-MODULE_DEPEND(name, templatefs, 1, 1, 1);
+VFS_SET(name##_vfsops, name, VFCF_SYNTHETIC | VFCF_READONLY); \
+
+//MODULE_DEPEND(name, templatefs, 1, 1, 1);
#endif
==== //depot/projects/soc2006/adamartin_autofs/templatefs/templatefs_vnops.c#3 (text+ko) ====
@@ -459,6 +459,7 @@
TFS_RETURN (td->tn_lookup(curthread, pfind(pid), td, cnp));
#else
td->tn_lookup(curthread, pfind(pid), td, cnp);
+ printf( "tn_lookup returned\n" );
#endif
}
/**/
More information about the p4-projects
mailing list