fix module attachment and cdevsw

This commit is contained in:
christos 2018-01-09 16:19:39 +00:00
parent 63d9fe88a0
commit 0d40f5669e
2 changed files with 41 additions and 33 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: autofs.c,v 1.2 2018/01/09 13:56:00 martin Exp $ */
/* $NetBSD: autofs.c,v 1.3 2018/01/09 16:19:39 christos Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@ -68,23 +68,33 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autofs.c,v 1.2 2018/01/09 13:56:00 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: autofs.c,v 1.3 2018/01/09 16:19:39 christos Exp $");
#include "autofs.h"
#include "ioconf.h"
#include <sys/atomic.h>
#include <sys/queue.h>
#include <sys/signalvar.h>
static int autofs_open(dev_t dev, int flags, int mode, struct lwp *l);
static int autofs_close(dev_t dev, int flags, int mode, struct lwp *l);
static int autofs_ioctl(dev_t dev, const u_long cmd, void *data, int flag,
struct lwp *l);
dev_type_open(autofs_open);
dev_type_close(autofs_close);
dev_type_ioctl(autofs_ioctl);
struct cdevsw autofs_ops = {
.d_open = autofs_open,
.d_close = autofs_close,
.d_ioctl = autofs_ioctl,
const struct cdevsw autofs_cdevsw = {
.d_open = autofs_open,
.d_close = autofs_close,
.d_read = noread,
.d_write = nowrite,
.d_ioctl = autofs_ioctl,
.d_stop = nostop,
.d_tty = notty,
.d_poll = nopoll,
.d_mmap = nommap,
.d_kqfilter = nokqfilter,
.d_discard = nodiscard,
.d_flag = D_OTHER,
};
/*
@ -111,6 +121,11 @@ int autofs_retry_attempts = 3;
int autofs_retry_delay = 1;
int autofs_interruptible = 1;
void
autofsattach(int n)
{
}
static int
autofs_node_cmp(const struct autofs_node *a, const struct autofs_node *b)
{
@ -504,7 +519,7 @@ autofs_ioctl_done(struct autofs_daemon_done *add)
return 0;
}
static int
int
autofs_open(dev_t dev, int flags, int mode, struct lwp *l)
{
@ -528,7 +543,7 @@ autofs_open(dev_t dev, int flags, int mode, struct lwp *l)
return 0;
}
static int
int
autofs_close(dev_t dev, int flags, int mode, struct lwp *l)
{
@ -540,7 +555,7 @@ autofs_close(dev_t dev, int flags, int mode, struct lwp *l)
return 0;
}
static int
int
autofs_ioctl(dev_t dev, const u_long cmd, void *data, int flag, struct lwp *l)
{

View File

@ -33,7 +33,7 @@
*
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autofs_vfsops.c,v 1.1 2018/01/09 03:31:14 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: autofs_vfsops.c,v 1.2 2018/01/09 16:19:39 christos Exp $");
#include "autofs.h"
@ -46,6 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: autofs_vfsops.c,v 1.1 2018/01/09 03:31:14 christos E
MODULE(MODULE_CLASS_VFS, autofs, NULL);
static int autofs_statvfs(struct mount *, struct statvfs *);
static int autofs_sysctl_create(void);
static void
autofs_init(void)
@ -64,6 +65,10 @@ autofs_init(void)
cv_init(&autofs_softc->sc_cv, "autofscv");
mutex_init(&autofs_softc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
autofs_softc->sc_dev_opened = false;
autofs_sysctl_create();
workqueue_create(&autofs_tmo_wq, "autofstmo",
autofs_timeout_wq, NULL, 0, 0, WQ_MPSAFE);
}
static void
@ -72,6 +77,8 @@ autofs_done(void)
KASSERT(autofs_softc);
KASSERT(!autofs_softc->sc_dev_opened);
workqueue_destroy(autofs_tmo_wq);
struct autofs_softc *sc = autofs_softc;
autofs_softc = NULL;
@ -437,6 +444,8 @@ fail:
return error;
}
extern const struct cdevsw autofs_cdevsw;
static int
autofs_modcmd(modcmd_t cmd, void *arg)
{
@ -451,30 +460,16 @@ autofs_modcmd(modcmd_t cmd, void *arg)
if (error)
break;
#ifdef _MODULE
error = devsw_attach("autofs", NULL, &bmajor, &autofs_ops,
error = devsw_attach("autofs", NULL, &bmajor, &autofs_cdevsw,
&cmajor);
if (error) {
vfs_detach(&autofs_vfsops);
break;
}
#endif
error = workqueue_create(&autofs_tmo_wq, "autofstmo",
autofs_timeout_wq, NULL, 0, 0, WQ_MPSAFE);
if (error) {
devsw_detach(NULL, &autofs_ops);
vfs_detach(&autofs_vfsops);
break;
}
error = autofs_sysctl_create();
if (error) {
workqueue_destroy(autofs_tmo_wq);
devsw_detach(NULL, &autofs_ops);
vfs_detach(&autofs_vfsops);
break;
}
break;
case MODULE_CMD_FINI:
#ifdef _MODULE
KASSERT(autofs_softc);
mutex_enter(&autofs_softc->sc_lock);
if (autofs_softc->sc_dev_opened) {
@ -484,9 +479,7 @@ autofs_modcmd(modcmd_t cmd, void *arg)
}
mutex_exit(&autofs_softc->sc_lock);
workqueue_destroy(autofs_tmo_wq);
#ifdef _MODULE
error = devsw_detach(NULL, &autofs_ops);
error = devsw_detach(NULL, &autofs_cdevsw);
if (error)
break;
#endif