Allow to register configuration routines to putter. Once a

configuration routine has been attached to the putter device minor
number, the configuration routine will be called when the device
is opened.  This is required for subsystems which enter the kernel
only through the file descriptor and cannot configure themselves
via another route (like puffs does via the mount() syscall).  Keep
the minor number 0 for "wildcard" uses where we do not require a
hardwired config routine (e.g. the puffs case).
This commit is contained in:
pooka 2007-11-20 18:35:22 +00:00
parent 58406f0ac9
commit b6cf4ea195
2 changed files with 82 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: putter.c,v 1.4 2007/11/13 13:11:51 pooka Exp $ */
/* $NetBSD: putter.c,v 1.5 2007/11/20 18:35:22 pooka Exp $ */
/*
* Copyright (c) 2006, 2007 Antti Kantee. All Rights Reserved.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: putter.c,v 1.4 2007/11/13 13:11:51 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: putter.c,v 1.5 2007/11/20 18:35:22 pooka Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@ -47,6 +47,52 @@ __KERNEL_RCSID(0, "$NetBSD: putter.c,v 1.4 2007/11/13 13:11:51 pooka Exp $");
#include <dev/putter/putter_sys.h>
/*
* Configuration data.
*
* This is static-size for now. Will be redone for devfs.
*/
#define PUTTER_CONFSIZE 16
static struct putter_config {
int pc_minor;
int (*pc_config)(int, int, int);
} putterconf[PUTTER_CONFSIZE];
static int
putter_configure(dev_t dev, int flags, int fmt, int fd)
{
struct putter_config *pc;
/* are we the catch-all node? */
if (minor(dev) == PUTTER_MINOR_WILDCARD
|| minor(dev) == PUTTER_MINOR_COMPAT)
return 0;
/* nopes? try to configure us */
for (pc = putterconf; pc->pc_config; pc++)
if (minor(dev) == pc->pc_minor)
return pc->pc_config(fd, flags, fmt);
return ENXIO;
}
int
putter_register(putter_config_fn pcfn, int minor)
{
int i;
for (i = 0; i < PUTTER_CONFSIZE; i++)
if (putterconf[i].pc_config == NULL)
break;
if (i == PUTTER_CONFSIZE)
return EBUSY;
putterconf[i].pc_minor = minor;
putterconf[i].pc_config = pcfn;
return 0;
}
/*
* putter instance structures. these are always allocated and freed
* from the context of the transport user.
@ -401,11 +447,7 @@ puttercdopen(dev_t dev, int flags, int fmt, struct lwp *l)
struct file *fp;
int error, fd, idx;
if ((error = falloc(l, &fp, &fd)) != 0)
return error;
pi = kmem_alloc(sizeof(struct putter_instance), KM_SLEEP);
mutex_enter(&pi_mtx);
idx = get_pi_idx(pi);
@ -417,10 +459,27 @@ puttercdopen(dev_t dev, int flags, int fmt, struct lwp *l)
selinit(&pi->pi_sel);
mutex_exit(&pi_mtx);
if ((error = falloc(l, &fp, &fd)) != 0)
goto bad1;
if ((error = putter_configure(dev, flags, fmt, fd)) != 0)
goto bad2;
DPRINTF(("puttercdopen: registered embryonic pmp for pid: %d\n",
pi->pi_pid));
return fdclone(l, fp, fd, FREAD|FWRITE, &putter_fileops, pi);
error = fdclone(l, fp, fd, FREAD|FWRITE, &putter_fileops, pi);
KASSERT(error = EMOVEFD);
return error;
bad2:
FILE_UNUSE(fp, l);
fdremove(l->l_proc->p_fd, fd);
ffree(fp);
bad1:
putter_detach(pi);
kmem_free(pi, sizeof(struct putter_instance));
return error;
}
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: putter_sys.h,v 1.2 2007/11/12 17:42:13 pooka Exp $ */
/* $NetBSD: putter_sys.h,v 1.3 2007/11/20 18:35:22 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -36,6 +36,18 @@
#include <dev/putter/putter.h>
/*
* Configuration data.
*
* Users of putter currently must be registered statically. This sucks,
* I know, but what are you going to do since you need static allocation
* for /dev nodes anyway. Ok, we could be slightly more forgiving about
* this, but let's just wait for devfs for now.
*/
#define PUTTER_MINOR_WILDCARD 0
#define PUTTER_MINOR_PUD 1
#define PUTTER_MINOR_COMPAT 0x7ffff /* will die sometime soon */
struct putter_ops {
int (*pop_getout)(void *, size_t, int, uint8_t **,size_t *,void **);
void (*pop_releaseout)(void *, void *, int);
@ -44,10 +56,13 @@ struct putter_ops {
int (*pop_close)(void *);
};
typedef int (*putter_config_fn)(int, int, int);
struct putter_instance;
struct putter_instance *putter_attach(pid_t, int, void *,
struct putter_ops *);
void putter_detach(struct putter_instance *);
void putter_notify(struct putter_instance *);
int putter_register(putter_config_fn, int);
#endif /* _DEV_PUTTER_PUTTERSYS_H_ */