PERFORCE change 112729 for review
Adam Martin
adamartin at FreeBSD.org
Wed Jan 10 13:49:16 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=112729
Change 112729 by adamartin at adamartin_hobbes on 2007/01/10 21:49:13
Partially completed the move to uniform "instance" object private
pointers. Readying for fork of pseudofs to templatefs.
Affected files ...
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs.h#9 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.c#8 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.h#7 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.c#8 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.h#6 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_pfsops.c#8 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_subr.h#3 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_tfsops.c#1 branch
.. //depot/projects/soc2006/adamartin_autofs/autofs/autofs_types.h#2 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/protocol.c#7 edit
.. //depot/projects/soc2006/adamartin_autofs/autofs/protocol.h#7 edit
.. //depot/projects/soc2006/adamartin_autofs/pseudofs/pseudofs.c#2 edit
.. //depot/projects/soc2006/adamartin_autofs/pseudofs/pseudofs.h#4 edit
Differences ...
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs.h#9 (text+ko) ====
@@ -64,89 +64,6 @@
#define KPRINTF EPRINTF
-
-/** TODO: move this to autofs_types.h **/
-
-/**************** FORWARD DEFINITIONS ******************/
-struct autofs_instance;
-struct autofs_dev_bufs;
-struct autofs_mount;
-struct vnode;
-struct pfs_node;
-struct autofs_transaction;
-
-struct proc;
-
-typedef struct autofs_transaction autofs_transaction_t;
-typedef struct proc kthread_t;
-typedef struct autofs_instance autofs_instance_t;
-typedef struct autofs_mount autofs_mount_t;
-
-/************** END FORWARD DEFINITIONS *****************/
-
-
-//typedef struct autofs_dev_bufs autofs_dev_bufs_t;
-
-
-
-/* This is needed as there's no true private field on pfs_node */
-#define pn_priv pn_data
-
-
-struct autofs_instance
-{
- struct autofs_dev_bufs *device;
- kthread_t *controller_thread;
-
- autofs_mounts_t *mount_list; /** This will be a hash **/
- autofs_transaction_t *in_flight; /** A hash of inflight
- transactions **/
-
- void *extensions;
-};
-
-
-/*** TODO: store in a hash, not a linked list. ***/
-struct autofs_mount
-{
- /** FIXME: Not ANSI C, but I'll fix it later. **/
- union
- {
- autofs_mounts_t *next; /** This field is deprecated **/
- uint32_t hash_code;
- };
-
- autofs_instance_t *instance_p;
- char *mountpoint;
-
- int state;
- unsigned long long int flags;
-
- struct pfs_node *mount_file; /* The pn_priv field points to
- the autofs mount structure */
-
- int timeout; /* Timeout in seconds */
- int time_remaining; /* Time remaining until next
- timeout event */
-};
-
-
-struct autofs_transaction
-{
- uint32_t hash_code;
- uint32_t transaction_id;
- int32_t next_expected_command;
- struct message_header last_message; /** This must be freed, after a successful command, with the expected transaction ID **/
-}
-
-#define AUTOFS_NODE_GET_PRIVATE( p_node )\
- ( (autofs_mount_t *) ( ( p_node )->pn_priv ) )
-
-#define AUTOFS_NODE_GET_INSTANCE( p_node )\
- ( (autofs_instance_t *)\
- ( AUTOFS_NODE_GET_PRIVATE( p_node )->instance_p ) )
-
-#define AUTOFS_NODE_GET_BUFFERS( p_node )\
- ( (autofs_instance_t *) ( AUTOFS_GET_INSTANCE( p_node )->device ) )
+#include "autofs_types.h"
#endif /*** __AUTOFS_MAIN_HEADER__ ***/
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.c#8 (text+ko) ====
@@ -151,6 +151,9 @@
int error= 0;
int *argp;
int arg;
+ autofs_instance_t *instance;
+
+ instance= AUTOFS_GET_INSTANCE( DEV, i_dev );
//argp= NULL;
argp= (int *) arg_c;
@@ -170,7 +173,7 @@
)
*/
arg= autofs_ctl_state.next_assignable_node++;
- error= create_autofs_node( arg );
+ error= create_autofs_node( arg, instance );
$do_cleanup;
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_ctl.h#7 (text+ko) ====
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.c#8 (text+ko) ====
@@ -74,9 +74,14 @@
{
int error;
int *inst_p;
+ autofs_instance_t *instance;
+ autofs_dev_bufs_t *buffers;
+
error= 0;
- inst_p= & ( AUTOFS_DEV_GET_PRIVATE( dev )->instances );
+ instance= AUTOFS_GET_INSTANCE( DEV, dev );
+ buffers= AUTOFS_GET_BUFFERS( DEV, dev );
+ inst_p= &( buffers->instances );
if( *inst_p == 0 )
{
@@ -96,9 +101,14 @@
{
int error;
int *inst_p;
+ autofs_instance_t *instance;
+ autofs_dev_bufs_t *buffers;
+
error= 0;
- inst_p= &( AUTOFS_DEV_GET_PRIVATE( dev )->instances );
+ instance= AUTOFS_GET_INSTANCE( DEV, dev );
+ buffers= AUTOFS_GET_BUFFERS( DEV, dev );
+ inst_p= &( buffers->instances );
if( *inst_p == 0 )
{
@@ -123,7 +133,7 @@
autofs_dev_read( struct cdev *dev, struct uio *uio, int ioflag )
{
int remains;
- struct autofs_dev_bufs *bufs;
+ autofs_dev_bufs_t *bufs;
queue *q;
int amt;
int error;
@@ -132,7 +142,7 @@
error= 0;
amt= MIN( uio->uio_resid, AUTOFS_IO_BUF_SIZE );
- bufs= AUTOFS_DEV_GET_BUFFERS( dev );
+ bufs= AUTOFS_GET_BUFFERS( DEV, dev );
q= bufs->output;
@@ -145,7 +155,7 @@
* right now.
*/
}
- while( remains > 0 );
+ while( remains > 0 ); /** FIXME: Shouldn't this be == **/
amt= MIN( remains, amt );
autofs_queue_read( q, out_buf, amt );
@@ -168,7 +178,7 @@
error= 0;
amt= MIN( uio->uio_resid, AUTOFS_IO_BUF_SIZE );
- bufs= AUTOFS_DEV_GET_BUFFERS( dev );
+ bufs= AUTOFS_GET_BUFFERS( DEV, dev );
q= bufs->input;
@@ -192,7 +202,7 @@
struct autofs_dev_bufs *bufs;
queue *q;
- bufs= AUTOFS_DEV_GET_BUFFERS( dev );
+ bufs= AUTOFS_GET_BUFFERS( DEV, dev );
q= bufs->output;
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_dev.h#6 (text+ko) ====
@@ -48,43 +48,4 @@
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;
-typedef struct autofs_dev_bufs autofs_info_t;
-
-struct autofs_dev_bufs
-{
- queue *input;
- queue *output;
- int instances;
- struct mtx *autofs_dev_lock;
- autofs_instance_t *this_instance;
-};
-
-
-
-
-#define AUTOFS_GET_PRIVATE( p_info )\
- ( (autofs_info_t *) AUTOFS_GET_BUFFERS( p_info ) )
-
-#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_DEV_GET_INSTANCE( afs_dev )\
- ( (autofs_instance_t *) ( AUTOFS_DEV_GET_PRIVATE( \
- afs_dev )->this_instance ) )
-
-#define AUTOFS_DEV_GET_TXNS( afs_dev )\
- ( (autofs_transaction_t *) ( AUTOFS_DEV_GET_INSTANCE( \
- afs_dev )->in_flight ) )
-
-#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#8 (text+ko) ====
@@ -54,7 +54,7 @@
#include <machine/setjmp.h>
#include "cleanup.h"
-#include <fs/pseudofs/pseudofs.h>
+#include "../templatefs/templatefs.h"
#include <sys/time.h>
@@ -67,7 +67,7 @@
MALLOC_DEFINE( M_AUTOFS_MOUNTBUF, "AutoFS mntbuf",
"AutoFS mountpoint data, to simulate filesystem contents.");
-struct pfs_node *foo;
+struct tfs_node *foo;
static int
autofs_vis(PFS_VIS_ARGS)
@@ -100,18 +100,20 @@
static int
-autofs_lookup( PFS_LOOKUP_ARGS )
+autofs_lookup( TFS_LOOKUP_ARGS )
{
struct componentname c= *cnp;
struct message_header msg;
struct mount_request mr;
- struct pfs_info *pi;
- autofs_info_t *instance;
+ struct tfs_info *ti;
+ autofs_instance_t *instance;
+ autofs_dev_bufs_t *buffers;
- pi= pn->pn_info;
+ instance= AUTOFS_GET_INSTANCE( NODE, tn );
+ buffers= AUTOFS_GET_BUFFERS( NODE, tn );
- instance= AUTOFS_GET_PRIVATE( pi );
+ ti= tn->tn_info;
DEBUG1 KPRINTF( "autofs lookup called\n" );
DEBUG7 KPRINTF( "cn_nameptr= %s, cn_pnbuf= %s\n", c.cn_nameptr,
@@ -133,14 +135,14 @@
//if( take_autofs_lock( instance, node ) )
//{
- send_mount_request( &msg, instance->output );
+ send_mount_request( &msg, buffers->output );
//}
return 1;
}
static int
-autofs_init(struct pfs_info *pi, struct vfsconf *vfc)
+autofs_init(struct tfs_info *ti, struct vfsconf *vfc)
{
struct vnode *devvp;
struct cdev *dev;
@@ -153,7 +155,7 @@
/** Get the fake device vnode from name **/
- NDINIT( ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, pi->pi_name, td );
+ NDINIT( ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, ti->ti_name, td );
if( ( error= namei( ndp ) ) != 0 )
{
return error;
@@ -168,26 +170,26 @@
}
/* Get out the cdev object, and store in the private field for the
- pfs_info object (I think we need to release the vnode too!)*/
+ tfs_info object (I think we need to release the vnode too!)*/
dev= devvp->v_rdev;
- pi->pi_priv= (void *) dev;
+ ti->ti_priv= (void *) dev;
VOP_UNLOCK( devvp, LK_RELEASE, td );
/** Make some fake files... **/
- foo= pfs_create_dir( pi->pi_root, "foo", autofs_attr, autofs_vis, 0 );
- foo->pn_lookup= autofs_lookup;
+ foo= tfs_create_dir( ti->ti_root, "foo", autofs_attr, autofs_vis, 0 );
+ foo->tn_lookup= autofs_lookup;
return 0;
}
static int
-autofs_uninit(struct pfs_info *pi, struct vfsconf *vfc)
+autofs_uninit(struct tfs_info *ti, struct vfsconf *vfc)
{
return 0;
}
-PSEUDOFS( autofs, AUTOFS_VERSION );
+TEMPLATEFS( autofs, AUTOFS_VERSION, NULL );
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_subr.h#3 (text+ko) ====
@@ -4,17 +4,16 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
-
+#include "autofs_types.h"
-typedef struct mbuf queue;
-
queue *autofs_queue_init( void );
int autofs_queue_write( queue *q, void *buf, int len );
int autofs_queue_read( queue *q, void *buf, int len ); /* Removes from head */
+int autofs_queue_remaining( queue *q );
==== //depot/projects/soc2006/adamartin_autofs/autofs/autofs_types.h#2 (text+ko) ====
@@ -1,0 +1,153 @@
+#ifndef __AUTOFS_TYPES_H__
+#define __AUTOFS_TYPES_H__
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+/**************** FORWARD DEFINITIONS ******************/
+
+/** Kernel forward definitions **/
+
+struct vnode;
+struct pfs_node;
+struct proc;
+struct cdev;
+struct mbuf;
+
+
+
+typedef struct proc kthread_t;
+
+
+
+struct autofs_instance;
+struct autofs_transaction;
+struct autofs_dev_bufs;
+struct autofs_mount;
+
+struct message_header;
+
+
+typedef struct mbuf queue;
+
+typedef struct autofs_instance autofs_instance_t;
+typedef struct autofs_transaction autofs_transaction_t;
+typedef struct autofs_dev_bufs autofs_dev_bufs_t;
+typedef struct autofs_mount autofs_mount_t;
+
+/************** END FORWARD DEFINITIONS *****************/
+
+
+//typedef struct autofs_dev_bufs autofs_dev_bufs_t;
+
+
+
+/* This is needed as there's no true private field on pfs_node */
+#define pn_priv pn_data
+
+
+struct autofs_instance
+{
+ autofs_dev_bufs_t *dev_buffers;
+ struct cdevsw *device_struct;
+ kthread_t *controller_thread;
+
+ autofs_mount_t *mount_list; /** This will be a hash **/
+ autofs_transaction_t *in_flight; /** A hash of inflight
+ transactions **/
+
+ void *extensions;
+};
+
+
+/*** TODO: store in a hash, not a linked list. ***/
+struct autofs_mount
+{
+ /** FIXME: Not ANSI C, but I'll fix it later. **/
+ uint32_t hash_code;
+
+ autofs_instance_t *this_instance;
+ char *mountpoint;
+
+ int state;
+ unsigned long long int flags;
+
+ struct pfs_node *mount_file; /* The pn_priv field points to
+ the autofs mount structure */
+
+ int timeout; /* Timeout in seconds */
+ int time_remaining; /* Time remaining until next
+ timeout event */
+};
+
+
+struct autofs_transaction
+{
+ uint32_t hash_code;
+ uint32_t transaction_id;
+ int32_t next_expected_command;
+ struct message_header *last_message; /** This must be freed, after a
+ successful command, with the
+ expected transaction ID **/
+};
+
+
+
+
+struct autofs_dev_bufs
+{
+ queue *input;
+ queue *output;
+ int instances;
+ struct mtx *autofs_dev_lock;
+ autofs_instance_t *this_instance;
+};
+
+
+
+/***************************************************************************
+The GET* macros get a piece of autofs state, from a "holder", where
+holder is DEV, NODE, INSTANCE or ROOT:
+
+ DEV - the input/output device of the AutoFS system
+ NODE - a node (mountpoint) within the AutoFS system
+ INSTANCE - the instance descriptor of an AutoFS system
+ ROOT - the pfs_info (vfs_info) descriptor of the underlying pseudofs
+
+E.G.: AUTOFS_GET_BUFFERS( ROOT, autofs_pfs_info )
+E.G.: AUTOFS_GET_TXNS( DEV, autofs_cdevsw )
+
+one can get:
+ BUFFERS, DEV, TXNS, INSTANCE
+
+****************************************************************************/
+
+#define AUTOFS_GET_INSTANCE( TYPE, __datum__ )\
+ ( (autofs_instance_t *) ( __CONCAT( AUTOFS_, __CONCAT( TYPE,\
+ _GET_INSTANCE( __datum__ ) ) ) ) )
+
+#define AUTOFS_GET_BUFFERS( TYPE, __datum__ )\
+ ( (autofs_dev_bufs_t *) ( AUTOFS_GET_INSTANCE( TYPE, __datum__ )->\
+ dev_buffers ) )
+
+#define AUTOFS_GET_TXNS( TYPE, __datum__ )\
+ ( (autofs_transaction_t *) ( AUTOFS_GET_INSTANCE( TYPE, __datum__ )->\
+ in_flight ) )
+
+#define AUTOFS_GET_DEV( TYPE, __datum__ )\
+ ( (struct cdev *) ( AUTOFS_GET_INSTANCE( TYPE, __datum__ )->\
+ device_struct ) )
+
+
+#define AUTOFS_DEV_GET_INSTANCE( dev )\
+ ( ( dev )->si_priv )
+
+#define AUTOFS_NODE_GET_INSTANCE( node )\
+ ( ( node )->pn_priv )
+
+#define AUTOFS_ROOT_GET_INSTANCE( p_info )\
+ ( ( p_info )->pi_priv )
+
+#define AUTOFS_INSTANCE_GET_INSTANCE( instance )\
+ ( ( instance ) )
+
+#endif /*** __AUTOFS_TYPES_H__ ***/
==== //depot/projects/soc2006/adamartin_autofs/autofs/protocol.c#7 (text+ko) ====
@@ -36,6 +36,8 @@
#include "autofs_subr.h"
#include "autofs_dev.h"
+#include "autofs_types.h"
+
int process_mount_complete( struct message_header *, autofs_instance_t * );
==== //depot/projects/soc2006/adamartin_autofs/autofs/protocol.h#7 (text+ko) ====
==== //depot/projects/soc2006/adamartin_autofs/pseudofs/pseudofs.c#2 (text+ko) ====
@@ -282,6 +282,10 @@
sbp->f_files = 1;
sbp->f_ffree = 0;
+ /** Mount intercept handler, by ADAM **/
+ if( pi->pi_mount_handler != NULL )
+ pi->pi_mount_handler( pi, mp, td );
+
return (0);
}
@@ -308,6 +312,8 @@
int
pfs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
{
+
+ /** ADAM: TODO: Make this handle multiple clients of the same type **/
struct pfs_info *pi;
pi = (struct pfs_info *)mp->mnt_data;
@@ -325,7 +331,7 @@
}
/*
- * Initialize a pseudofs instance
+ * Initialize a (static) pseudofs instance
*/
int
pfs_init(struct pfs_info *pi, struct vfsconf *vfc)
==== //depot/projects/soc2006/adamartin_autofs/pseudofs/pseudofs.h#4 (text+ko) ====
@@ -92,6 +92,15 @@
typedef int (*pfs_init_t)(PFS_INIT_ARGS);
/*
+ * Mount callback (ADAM)
+ */
+#define PFS_MOUNT_HANDLER_ARGS \
+ struct pfs_info *pi, struct mount *mp, struct thread *td
+#define PFS_MOUNT_HANDLER_PROTO(name) \
+ int name(PFS_MOUNT_HANDLER_ARGS);
+typedef int (*pfs_mount_handler_t)(PFS_MOUNT_HANDLER_ARGS);
+
+/*
* Filler callback
*/
#define PFS_FILL_ARGS \
@@ -172,6 +181,7 @@
pfs_init_t pi_init;
pfs_init_t pi_uninit;
/* members below this line aren't initialized */
+ pfs_mount_handler_t pi_mount;
struct pfs_node *pi_root;
/* currently, the mutex is only used to protect the bitmap */
struct mtx pi_mutex;
@@ -275,4 +285,45 @@
MODULE_VERSION(name, version); \
MODULE_DEPEND(name, pseudofs, 1, 1, 1);
+
+/*
+ * Dynamic pseudofs initialization by ADAM...
+ */
+#define PSEUDOFS_DYNAMIC(name, version) \
+ \
+static struct pfs_info name##_info = { \
+ #name, \
+ name##_init, \
+ name##_uninit, \
+}; \
+ \
+static int \
+_##name##_mount(struct mount *mp, struct thread *td) { \
+ return pfs_mount(&name##_info, mp, td); \
+} \
+ \
+static int \
+_##name##_init(struct vfsconf *vfc) { \
+ return pfs_init(&name##_info, vfc); \
+} \
+ \
+static int \
+_##name##_uninit(struct vfsconf *vfc) { \
+ return pfs_uninit(&name##_info, vfc); \
+} \
+ \
+static struct vfsops name##_vfsops = { \
+ .vfs_init = _##name##_init, \
+ .vfs_mount = _##name##_mount, \
+ .vfs_root = pfs_root, \
+ .vfs_statfs = pfs_statfs, \
+ .vfs_uninit = _##name##_uninit, \
+ .vfs_unmount = pfs_unmount, \
+}; \
+VFS_SET(name##_vfsops, name, VFCF_SYNTHETIC); \
+MODULE_VERSION(name, version); \
+MODULE_DEPEND(name, pseudofs, 1, 1, 1);
+
+
+
#endif
More information about the p4-projects
mailing list