PERFORCE change 110310 for review
Adam Martin
adamartin at FreeBSD.org
Tue Nov 21 16:21:08 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=110310
Change 110310 by adamartin at adamartin_hobbes on 2006/11/20 17:30:15
Autofs Device functions now mostly implemented. Also some improved
'queue' functions. Lastly, autofs config program, afsconfig, added
to enable creation (and soon deletion) of /dev/autofs0...N devices.
Affected files ...
.. //depot/projects/soc2006/adamartin_autofs/afsconfig/Makefile#1 add
.. //depot/projects/soc2006/adamartin_autofs/afsconfig/afsconfig.c#1 add
.. //depot/projects/soc2006/adamartin_autofs/autofs/Makefile#6 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs.c#7 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs.h#7 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.c#6 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.h#5 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.c#6 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.h#4 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_pfsops.c#6 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_subr.c#3 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_types.h#1 add
Differences ...
==== //depot/projects/soc2006/adamartin_autofs/autofs/Makefile#6 (text+ko) ====
@@ -28,14 +28,21 @@
AUTOFS_DEV_SOURCE=autofs_ctl.c autofs_dev.c
AUTOFS_FS_SOURCE=autofs_pfsops.c vnode_if.h
-AUTOFS_CORE_SOURCE=autofs.c protocol.c autofs_subr.c
-SRCS=$(AUTOFS_CORE_SOURCE) $(AUTOFS_FS_SOURCE) $(AUTOFS_DEV_SOURCE)
+AUTOFS_CORE_SOURCE=autofs.c protocol.c
+AUTOFS_SUPPORT_SOURCE=autofs_subr.c
+SRCS=$(AUTOFS_CORE_SOURCE) $(AUTOFS_FS_SOURCE) $(AUTOFS_DEV_SOURCE) $(AUTOFS_SUPPORT_SOURCE)
HEADERS=autofs.h cleanup.h protocol.h autofs_subr.h autofs_ctl.h autofs_dev.h debug.h
KMOD=autofs
autofs.c: $(HEADERS)
-autofs_vfsops.c: $(HEADERS)
+autofs_pfsops.c: $(HEADERS)
+
+protocol.c: $(HEADERS)
+
+autofs_subr.c: $(HEADERS)
+
+autofs_dev.c: $(HEADERS)
autofs_vnops.c: $(HEADERS)
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs.c#7 (text+ko) ====
@@ -109,9 +109,7 @@
-int vn_iscdev( struct vnode *vp, int *errp );
-
-int
+static int
vn_iscdev( struct vnode *vp, int *errp )
{
$cleanup_init_size( 8 );
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs.h#7 (text+ko) ====
@@ -40,6 +40,7 @@
#include "cleanup.h"
+#include <sys/kthread.h>
#define AUTOFS_VERSION ( 1 )
@@ -63,4 +64,46 @@
#define KPRINTF EPRINTF
+/**************** FORWARD DEFINITIONS ******************/
+struct autofs_instance;
+struct autofs_dev_bufs;
+struct autofs_mounts;
+struct vnode;
+struct pfs_node;
+
+struct proc;
+
+
+typedef struct proc kthread_t;
+typedef struct autofs_instance autofs_instance_t;
+typedef struct autofs_mounts autofs_mounts_t;
+
+/************** END FORWARD DEFINITIONS *****************/
+
+
+//typedef struct autofs_dev_bufs autofs_dev_bufs_t;
+
+
+struct autofs_instance
+{
+ struct autofs_dev_bufs *device;
+ kthread_t *controller_thread;
+
+ autofs_mounts_t *mount_list;
+
+ void *extensions;
+};
+
+
+struct autofs_mounts
+{
+ autofs_mounts_t *next;
+ autofs_instance_t *instance_p;
+ char *mountpoint;
+ struct pfs_node *mount_file; /**The pn_data field points to the autofs mount
+ structure **/
+ int timeout; /* Timeout in seconds */
+ int time_remaining; /* Time remaining until next timeout event */
+};
+
#endif /*** __AUTOFS_MAIN_HEADER__ ***/
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.c#6 (text+ko) ====
@@ -67,7 +67,7 @@
int
autofs_ctl_init()
{
- DEBUG KPRINTF( "Initializing " );
+ DEBUG KPRINTF( "Initializing autofs ctl device...\n" );
return 0;
}
@@ -78,7 +78,22 @@
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 )
+MALLOC_DEFINE( M_AUTOFS_DEV_LOCKS, "autofs_dev_lock", "Autofs mutex locks for individual devices..." );
+
+
+static int
+destroy_autofs_node( int num )
+{
+ int error;
+
+ error= 0;
+
+
+ return ENOSYS;
+}
+
+static int
+create_autofs_node( int num )
{
int error;
struct cdevsw *autofs_cdevsw;
@@ -88,11 +103,13 @@
error= 0;
autofs_cdevsw= malloc( sizeof( struct cdevsw ), M_AUTOFS_DEV, M_WAITOK );
- autofs_dev_data= malloc( sizeof( struct autofs_dev_bufs ), M_AUTOFS_DEV_BUFFERS,
- M_WAITOK );
+ autofs_dev_data= malloc( sizeof( struct autofs_dev_bufs ),
+ M_AUTOFS_DEV_BUFFERS, M_WAITOK );
+
autofs_dev_data->input= autofs_queue_init();
autofs_dev_data->output= autofs_queue_init();
+ autofs_dev_data->instances= 0;
autofs_cdevsw->d_open= autofs_dev_open;
autofs_cdevsw->d_close= autofs_dev_close;
@@ -131,10 +148,12 @@
{
$cleanup_init_size( 8 );
int error= 0;
- int *argp= (int *) arg_c;
+ int *argp;
int arg;
- argp= NULL;
+ //argp= NULL;
+ argp= (int *) arg_c;
+ arg= *argp;
error= EOPNOTSUPP;
//$return EOPNOTSUPP;
@@ -156,6 +175,13 @@
break;
+ case AFSIODESTROYDEV:
+ error= destroy_autofs_node( arg );
+
+ $do_cleanup;
+
+ break;
+
default:
/* NOTREACHED */
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.h#5 (text+ko) ====
@@ -30,9 +30,12 @@
#ifndef __AUTOFS_CTL_H__
#define __AUTOFS_CTL_H__
+#include <sys/types.h>
+#include <sys/ioccom.h>
+#ifdef _KERNEL
#include "autofs.h"
#include "autofs_subr.h"
-#include <sys/types.h>
+
#include <sys/module.h>
#include <sys/systm.h> /* uprintf */
#include <sys/errno.h>
@@ -45,9 +48,7 @@
#include <sys/param.h>
#include <sys/vnode.h>
-#include <sys/ioccom.h>
-#define AUTOFS_CTL_DEV_NAME "autofs_ctl"
@@ -55,7 +56,6 @@
extern struct cdevsw autofs_ctl_devops;
-typedef int *_int_p;
struct autofs_ctl_state {
@@ -67,7 +67,9 @@
extern struct autofs_ctl_state autofs_ctl_state;
extern int autofs_ctl_init( void );
-int create_autofs_node( int num );
+
+//int destroy_autofs_node( int num );
+//int create_autofs_node( int num );
#define MAX_NODE_COUNT ( 32 )
@@ -76,21 +78,18 @@
-struct autofs_dev_bufs {
- queue *input;
- queue *output;
-};
+
+#endif
+
+typedef int *_int_p;
/** Are we allowed to reuse group "a"? **/
+#define AFSIOCREATDEV _IOR('a', 1, _int_p) /* 1 - create autofs node */
+#define AFSIODESTROYDEV _IOR('a', 2, _int_p) /* 2 - destroy autofs node */
-#define AFSIOCREATDEV _IOR('a', 1, _int_p) /* 1 - create autofs node */
+#define AUTOFS_CTL_DEV_NAME "autofs_ctl"
-#define AUTOFS_GET_BUFFERS( p_info )\
- ( (struct autofs_dev_bufs *) ( AUTOFS_GET_DEV( ( p_info ) )->si_priv ) )
-
-#define AUTOFS_GET_DEV( p_info )\
- ( (struct cdev *) ( ( p_info )->pi_priv ) )
#endif /** __AUTOFS_CTL_H__ **/
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.c#6 (text+ko) ====
@@ -36,15 +36,21 @@
#include <sys/errno.h>
#include <sys/param.h> /* defines used in kernel.h */
#include <sys/kernel.h> /* types used in module initialization */
+#include <sys/param.h> /* used for devsw function */
#include <sys/conf.h>
#include <sys/uio.h>
#include <sys/malloc.h>
#include <machine/setjmp.h>
+#include "debug.h"
#include "cleanup.h"
+#include "autofs_ctl.h"
#include "autofs_dev.h"
+#include "autofs_subr.h"
+#define AUTOFS_IO_BUF_SIZE ( 4096 )
+
struct uio *in_buffer, *out_buffer;
int
@@ -62,12 +68,134 @@
-int autofs_dev_open( struct cdev *dev, int oflags, int devtype, struct thread *td )
+int
+autofs_dev_open( struct cdev *dev, int oflags, int devtype,
+ struct thread *td )
+{
+ int error;
+ int *inst_p;
+ error= 0;
+
+ inst_p= & ( AUTOFS_DEV_GET_PRIVATE( dev )->instances );
+
+ if( *inst_p == 0 )
+ {
+ ( *inst_p )++;
+ } else {
+ DEBUG EPRINTF( "Tried to open the autofs device \"%s\" "
+ "multiple times!\n", dev->si_devsw->d_name );
+ error= ENXIO;
+ }
+
+ return error;
+}
+
+int
+autofs_dev_close( struct cdev *dev, int oflags, int devtype,
+ struct thread *td )
+{
+ int error;
+ int *inst_p;
+ error= 0;
+
+ inst_p= &( AUTOFS_DEV_GET_PRIVATE( dev )->instances );
+
+ if( *inst_p == 0 )
+ {
+ DEBUG EPRINTF( "Tried to close device: \"%s\", beyond natural "
+ "close minimum!\n", dev->si_devsw->d_name );
+ error= EDOOFUS;
+ }
+ else
+ {
+ ( *inst_p )--;
+ }
+
+
+ return error;
+}
+
+MALLOC_DECLARE( M_AUTOFS_DEV_OUT );
+MALLOC_DEFINE( M_AUTOFS_DEV_OUT, "autofs read", "Autofs read bounce buffer" );
+
+
+int
+autofs_dev_read( struct cdev *dev, struct uio *uio, int ioflag )
+{
+ int remains;
+ struct autofs_dev_bufs *bufs;
+ queue *q;
+ int amt;
+ int error;
+ unsigned char out_buf[ AUTOFS_IO_BUF_SIZE ]; /* No more than a page! */
+
+ error= 0;
+ amt= MIN( uio->uio_resid, AUTOFS_IO_BUF_SIZE );
+
+ bufs= AUTOFS_DEV_GET_BUFFERS( dev );
+ q= bufs->output;
+
+
+ do
+ {
+ remains= autofs_queue_remaining( q );
+ /*
+ * We really should do SOME kind of sleep. This is more a spinlock
+ * right now.
+ */
+ }
+ while( remains > 0 );
+
+ amt= MIN( remains, amt );
+ autofs_queue_read( q, out_buf, amt );
+
+ error= uiomove( out_buf, amt, uio );
+
+
+ return error;
+}
+
+int
+autofs_dev_write( struct cdev *dev, struct uio *uio, int ioflag )
{
+ struct autofs_dev_bufs *bufs;
+ queue *q;
+ int amt;
int error;
- int i;
+ unsigned char in_buf[ AUTOFS_IO_BUF_SIZE ]; /* No more than a page! */
+
error= 0;
- i= minor( dev );
+ amt= MIN( uio->uio_resid, AUTOFS_IO_BUF_SIZE );
+
+ bufs= AUTOFS_DEV_GET_BUFFERS( dev );
+ q= bufs->input;
+
+
+ error= uiomove( in_buf, amt, uio );
+ if( error )
+ {
+ return error;
+ }
+
+
+ autofs_queue_write( q, in_buf, amt );
+
return error;
}
+
+int
+autofs_dev_poll( struct cdev *dev, int events, struct thread *td )
+{
+ int rv= 0;
+ struct autofs_dev_bufs *bufs;
+ queue *q;
+
+ bufs= AUTOFS_DEV_GET_BUFFERS( dev );
+ q= bufs->output;
+
+
+ rv= autofs_queue_remaining( q );
+
+ return rv;
+}
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.h#4 (text+ko) ====
@@ -1,3 +1,35 @@
+/*-
+ * Copyright (c) 2006
+ * Adam Martin, Erez Zadok. All rights reserved.
+ *
+ * This code is derived from software in FreeBSD, and 4.4BSD.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The authors' names may not be used to endorse or promote products
+ * derived from this software without specific written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __AUTOFS_DEVICE_HEADER__
+#define __AUTOFS_DEVICE_HEADER__
+
#include <sys/types.h>
#include <sys/uio.h>
@@ -14,3 +46,32 @@
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 );
+
+
+struct autofs_dev_bufs;
+typedef struct autofs_dev_bufs autofs_dev_bufs_t;
+
+struct autofs_dev_bufs
+{
+ queue *input;
+ queue *output;
+ int instances;
+ struct mtx *autofs_dev_lock;
+ autofs_instance_t *this_instance;
+};
+
+
+
+
+#define AUTOFS_GET_BUFFERS( p_info )\
+ ( AUTOFS_DEV_GET_BUFFERS( AUTOFS_GET_DEV( ( p_info ) ) ) )
+
+#define AUTOFS_DEV_GET_PRIVATE AUTOFS_DEV_GET_BUFFERS
+#define AUTOFS_DEV_GET_BUFFERS( afs_dev )\
+ ( (struct autofs_dev_bufs *) ( ( afs_dev )->si_priv ) )
+
+#define AUTOFS_GET_DEV( p_info )\
+ ( (struct cdev *) ( ( p_info )->pi_priv ) )
+
+
+#endif /*** __AUTOFS_DEVICE_HEADER__ ***/
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_pfsops.c#6 (text+ko) ====
@@ -59,6 +59,7 @@
#include "protocol.h"
#include "debug.h"
#include "autofs_ctl.h"
+#include "autofs_dev.h"
MALLOC_DEFINE(M_AUTOFS_MOUNTBUF, "AutoFS mntbuf", "AutoFS mountpoint data, to simulate filesystem contents.");
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_subr.c#3 (text+ko) ====
@@ -4,7 +4,8 @@
int
autofs_queue_write( queue *q, void *buf, int len )
{
- m_append( (struct mbuf *) q, len, buf );
+ struct mbuf *mb= (struct mbuf *) q;
+ m_append( mb, len, buf );
return 0;
}
@@ -12,8 +13,10 @@
int
autofs_queue_read( queue *q, void *buf, int len )
{
- m_copydata( (struct mbuf *) q, 0, len, (caddr_t) buf );
- m_adj( (struct mbuf *) q, len );
+ struct mbuf *mb= (struct mbuf *) q;
+
+ m_copydata( mb, 0, len, (caddr_t) buf );
+ m_adj( mb, len );
return 0;
}
@@ -27,3 +30,14 @@
return (queue *) rv;
}
+
+int
+autofs_queue_remaining( queue *q )
+{
+ struct mbuf *mb= (struct mbuf *) q;
+ int len;
+
+ len= m_length( mb, NULL );
+
+ return len; /* How much remains... */
+}
More information about the p4-projects
mailing list