tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
fix for 37878 and 37550
Hello,
I've implemented stat functions for all the devices that called fbadop_stat
and tried to fill the fields as best as I could. I am concerned about the
cost of getnanotime() and the extra fields in the softc struct. Is it worth
it? We could also simply fix this by implementing fnullop_stat, which is
effectively what soo_stat() ends up being for non-unix sockets.
Comments?
christos
Index: dev/dmover/dmover_io.c
===================================================================
RCS file: /cvsroot/src/sys/dev/dmover/dmover_io.c,v
retrieving revision 1.32
diff -u -u -r1.32 dmover_io.c
--- dev/dmover/dmover_io.c 4 Apr 2009 10:12:51 -0000 1.32
+++ dev/dmover/dmover_io.c 10 Apr 2009 21:23:18 -0000
@@ -100,6 +100,9 @@
volatile int ds_flags;
u_int ds_nreqs;
struct simplelock ds_slock;
+ struct timespec ds_atime;
+ struct timespec ds_mtime;
+ struct timespec ds_btime;
};
static ONCE_DECL(dmio_cleaner_control);
@@ -358,6 +361,7 @@
if (ds->ds_session == NULL)
return (ENXIO);
+ getnanotime(&ds->ds_atime);
s = splsoftclock();
simple_lock(&ds->ds_slock);
@@ -487,6 +491,7 @@
if (ds->ds_session == NULL)
return (ENXIO);
+ getnanotime(&ds->ds_mtime);
s = splsoftclock();
simple_lock(&ds->ds_slock);
@@ -569,6 +574,19 @@
return (error);
}
+static int
+dmio_stat(struct file *fp, struct stat *st)
+{
+ struct dmio_state *ds = fp->f_data;
+
+ (void)memset(st, 0, sizeof(st));
+ st->st_dev = makedev(cdevsw_lookup_major(&dmoverio_cdevsw), 0);
+ st->st_atime = ds->ds_atime;
+ st->st_mtime = ds->ds_mtime;
+ st->st_ctime = st->st_birthtime = ds->ds_btime;
+ return 0;
+}
+
/*
* dmio_ioctl:
*
@@ -734,7 +752,7 @@
.fo_ioctl = dmio_ioctl,
.fo_fcntl = fnullop_fcntl,
.fo_poll = dmio_poll,
- .fo_stat = fbadop_stat,
+ .fo_stat = dmio_stat,
.fo_close = dmio_close,
.fo_kqfilter = fnullop_kqfilter,
.fo_drain = fnullop_drain,
@@ -759,6 +777,7 @@
s = splsoftclock();
ds = pool_get(&dmio_state_pool, PR_WAITOK);
splx(s);
+ getnanotime(&ds->ds_btime);
memset(ds, 0, sizeof(*ds));
simple_lock_init(&ds->ds_slock);
Index: dev/putter/putter.c
===================================================================
RCS file: /cvsroot/src/sys/dev/putter/putter.c,v
retrieving revision 1.21
diff -u -u -r1.21 putter.c
--- dev/putter/putter.c 4 Apr 2009 10:12:51 -0000 1.21
+++ dev/putter/putter.c 10 Apr 2009 21:23:20 -0000
@@ -44,12 +44,29 @@
#include <sys/filedesc.h>
#include <sys/kmem.h>
#include <sys/poll.h>
+#include <sys/stat.h>
#include <sys/socketvar.h>
#include <sys/module.h>
#include <dev/putter/putter_sys.h>
/*
+ * Device routines. These are for when /dev/puffs is initially
+ * opened before it has been cloned.
+ */
+
+dev_type_open(puttercdopen);
+dev_type_close(puttercdclose);
+dev_type_ioctl(puttercdioctl);
+
+/* dev */
+const struct cdevsw putter_cdevsw = {
+ puttercdopen, puttercdclose, noread, nowrite,
+ noioctl, nostop, notty, nopoll,
+ nommap, nokqfilter, D_OTHER
+};
+
+/*
* Configuration data.
*
* This is static-size for now. Will be redone for devfs.
@@ -111,6 +128,9 @@
uint8_t *pi_curput;
size_t pi_curres;
void *pi_curopaq;
+ struct timespec pi_atime;
+ struct timespec pi_mtime;
+ struct timespec pi_btime;
TAILQ_ENTRY(putter_instance) pi_entries;
};
@@ -171,6 +191,7 @@
kauth_cred_t, int);
static int putter_fop_ioctl(file_t*, u_long, void *);
static int putter_fop_poll(file_t *, int);
+static int putter_fop_stat(file_t *, struct stat *);
static int putter_fop_close(file_t *);
static int putter_fop_kqfilter(file_t *, struct knote *);
@@ -181,7 +202,7 @@
.fo_ioctl = putter_fop_ioctl,
.fo_fcntl = fnullop_fcntl,
.fo_poll = putter_fop_poll,
- .fo_stat = fbadop_stat,
+ .fo_stat = putter_fop_stat,
.fo_close = putter_fop_close,
.fo_kqfilter = putter_fop_kqfilter,
.fo_drain = fnullop_drain,
@@ -195,6 +216,7 @@
size_t origres, moved;
int error;
+ getnanotime(&pi->pi_atime);
KERNEL_LOCK(1, NULL);
if (pi->pi_private == PUTTER_EMBRYO || pi->pi_private == PUTTER_DEAD) {
@@ -243,6 +265,7 @@
size_t frsize;
int error;
+ getnanotime(&pi->pi_mtime);
KERNEL_LOCK(1, NULL);
DPRINTF(("putter_fop_write (%p): writing response, resid %zu\n",
@@ -383,6 +406,19 @@
}
static int
+putter_fop_stat(file_t *fp, struct stat *st)
+{
+ struct putter_instance *pi = fp->f_data;
+
+ (void)memset(st, 0, sizeof(*st));
+ st->st_dev = makedev(cdevsw_lookup_major(&putter_cdevsw), pi->pi_idx);
+ st->st_atimespec = pi->pi_atime;
+ st->st_mtimespec = pi->pi_mtime;
+ st->st_ctimespec = st->st_birthtimespec = pi->pi_btime;
+ return 0;
+}
+
+static int
putter_fop_ioctl(file_t *fp, u_long cmd, void *data)
{
@@ -467,21 +503,6 @@
return 0;
}
-/*
- * Device routines. These are for when /dev/puffs is initially
- * opened before it has been cloned.
- */
-
-dev_type_open(puttercdopen);
-dev_type_close(puttercdclose);
-dev_type_ioctl(puttercdioctl);
-
-/* dev */
-const struct cdevsw putter_cdevsw = {
- puttercdopen, puttercdclose, noread, nowrite,
- noioctl, nostop, notty, nopoll,
- nommap, nokqfilter, D_OTHER
-};
int
puttercdopen(dev_t dev, int flags, int fmt, struct lwp *l)
{
@@ -500,6 +521,7 @@
pi->pi_curput = NULL;
pi->pi_curres = 0;
pi->pi_curopaq = NULL;
+ getnanotime(&pi->pi_btime);
selinit(&pi->pi_sel);
mutex_exit(&pi_mtx);
Index: kern/kern_drvctl.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_drvctl.c,v
retrieving revision 1.24
diff -u -u -r1.24 kern_drvctl.c
--- kern/kern_drvctl.c 4 Apr 2009 21:49:05 -0000 1.24
+++ kern/kern_drvctl.c 10 Apr 2009 21:23:21 -0000
@@ -44,6 +44,7 @@
#include <sys/poll.h>
#include <sys/drvctlio.h>
#include <sys/devmon.h>
+#include <sys/stat.h>
struct drvctl_event {
TAILQ_ENTRY(drvctl_event) dce_link;
@@ -75,6 +76,7 @@
kauth_cred_t, int);
static int drvctl_ioctl(struct file *, u_long, void *);
static int drvctl_poll(struct file *, int);
+static int drvctl_stat(struct file *, struct stat *);
static int drvctl_close(struct file *);
static const struct fileops drvctl_fileops = {
@@ -83,7 +85,7 @@
.fo_ioctl = drvctl_ioctl,
.fo_fcntl = fnullop_fcntl,
.fo_poll = drvctl_poll,
- .fo_stat = fbadop_stat,
+ .fo_stat = drvctl_stat,
.fo_close = drvctl_close,
.fo_kqfilter = fnullop_kqfilter,
.fo_drain = fnullop_drain,
@@ -370,6 +372,13 @@
}
static int
+drvctl_stat(struct file *fp, struct stat *st)
+{
+ (void)memset(st, 0, sizeof(*st));
+ return 0;
+}
+
+static int
drvctl_poll(struct file *fp, int events)
{
int revents = 0;
Index: kern/sys_mqueue.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sys_mqueue.c,v
retrieving revision 1.14
diff -u -u -r1.14 sys_mqueue.c
--- kern/sys_mqueue.c 4 Apr 2009 10:12:51 -0000 1.14
+++ kern/sys_mqueue.c 10 Apr 2009 21:23:22 -0000
@@ -84,6 +84,7 @@
LIST_HEAD_INITIALIZER(mqueue_head);
static int mq_poll_fop(file_t *, int);
+static int mq_stat_fop(file_t *, struct stat *);
static int mq_close_fop(file_t *);
#define FNOVAL -1
@@ -94,7 +95,7 @@
.fo_ioctl = fbadop_ioctl,
.fo_fcntl = fnullop_fcntl,
.fo_poll = mq_poll_fop,
- .fo_stat = fbadop_stat,
+ .fo_stat = mq_stat_fop,
.fo_close = mq_close_fop,
.fo_kqfilter = fnullop_kqfilter,
.fo_drain = fnullop_drain,
@@ -240,6 +241,21 @@
}
static int
+mq_stat_fop(file_t *fp, struct stat *st)
+{
+ struct mqueue *mq = fp->f_data;
+
+ (void)memset(st, 0, sizeof(*st));
+ st->st_mode = mq->mq_mode;
+ st->st_uid = mq->mq_euid;
+ st->st_gid = mq->mq_egid;
+ st->st_atimespec = mq->mq_atime;
+ st->st_mtimespec = mq->mq_mtime;
+ st->st_ctimespec = st->st_birthtimespec = mq->mq_btime;
+ return 0;
+}
+
+static int
mq_poll_fop(file_t *fp, int events)
{
struct mqueue *mq = fp->f_data;
@@ -493,6 +509,7 @@
return error;
mq = fp->f_data;
+ getnanotime(&mq->mq_atime);
/* Check the message size limits */
if (msg_len < mq->mq_attrib.mq_msgsize) {
error = EMSGSIZE;
@@ -655,6 +672,8 @@
}
mq = fp->f_data;
+ getnanotime(&mq->mq_mtime);
+
/* Check the message size limit */
if (msg_len <= 0 || msg_len > mq->mq_attrib.mq_msgsize) {
error = EMSGSIZE;
Index: net/bpf.c
===================================================================
RCS file: /cvsroot/src/sys/net/bpf.c,v
retrieving revision 1.144
diff -u -u -r1.144 bpf.c
--- net/bpf.c 4 Apr 2009 10:12:51 -0000 1.144
+++ net/bpf.c 10 Apr 2009 21:23:28 -0000
@@ -58,6 +58,7 @@
#include <sys/conf.h>
#include <sys/vnode.h>
#include <sys/queue.h>
+#include <sys/stat.h>
#include <sys/file.h>
#include <sys/filedesc.h>
@@ -151,6 +152,7 @@
int);
static int bpf_ioctl(struct file *, u_long, void *);
static int bpf_poll(struct file *, int);
+static int bpf_stat(struct file *, struct stat *);
static int bpf_close(struct file *);
static int bpf_kqfilter(struct file *, struct knote *);
static void bpf_softintr(void *);
@@ -161,7 +163,7 @@
.fo_ioctl = bpf_ioctl,
.fo_fcntl = fnullop_fcntl,
.fo_poll = bpf_poll,
- .fo_stat = fbadop_stat,
+ .fo_stat = bpf_stat,
.fo_close = bpf_close,
.fo_kqfilter = bpf_kqfilter,
.fo_drain = fnullop_drain,
@@ -402,6 +404,7 @@
d->bd_bufsize = bpf_bufsize;
d->bd_seesent = 1;
d->bd_pid = l->l_proc->p_pid;
+ getnanotime(&d->bd_btime);
callout_init(&d->bd_callout, 0);
selinit(&d->bd_sel);
d->bd_sih = softint_establish(SOFTINT_CLOCK, bpf_softintr, d);
@@ -476,6 +479,7 @@
int error;
int s;
+ getnanotime(&d->bd_atime);
/*
* Restrict application to use a buffer the same size as
* the kernel buffers.
@@ -625,6 +629,7 @@
KERNEL_UNLOCK_ONE(NULL);
return (ENXIO);
}
+ getnanotime(&d->bd_mtime);
ifp = d->bd_bif->bif_ifp;
@@ -1120,6 +1125,19 @@
memcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
}
+static int
+bpf_stat(struct file *fp, struct stat *st)
+{
+ struct bpf_d *d = fp->f_data;
+
+ (void)memset(st, 0, sizeof(*st));
+ st->st_dev = makedev(cdevsw_lookup_major(&bpf_cdevsw), d->bd_pid);
+ st->st_atimespec = d->bd_atime;
+ st->st_mtimespec = d->bd_mtime;
+ st->st_ctimespec = st->st_birthtimespec = d->bd_btime;
+ return 0;
+}
+
/*
* Support for poll() system call
*
Index: net/bpfdesc.h
===================================================================
RCS file: /cvsroot/src/sys/net/bpfdesc.h,v
retrieving revision 1.29
diff -u -u -r1.29 bpfdesc.h
--- net/bpfdesc.h 14 Mar 2009 14:46:10 -0000 1.29
+++ net/bpfdesc.h 10 Apr 2009 21:23:29 -0000
@@ -93,6 +93,9 @@
pid_t bd_pid; /* corresponding PID */
LIST_ENTRY(bpf_d) bd_list; /* list of all BPF's */
void *bd_sih; /* soft interrupt handle */
+ struct timespec bd_atime; /* access time */
+ struct timespec bd_mtime; /* modification time */
+ struct timespec bd_btime; /* birth time */
};
Index: net/if_tap.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_tap.c,v
retrieving revision 1.55
diff -u -u -r1.55 if_tap.c
--- net/if_tap.c 4 Apr 2009 10:12:51 -0000 1.55
+++ net/if_tap.c 10 Apr 2009 21:23:29 -0000
@@ -61,6 +61,7 @@
#include <sys/mutex.h>
#include <sys/simplelock.h>
#include <sys/intr.h>
+#include <sys/stat.h>
#include <net/if.h>
#include <net/if_dl.h>
@@ -115,6 +116,9 @@
kmutex_t sc_rdlock;
struct simplelock sc_kqlock;
void *sc_sih;
+ struct timespec sc_atime;
+ struct timespec sc_mtime;
+ struct timespec sc_btime;
};
/* autoconf(9) glue */
@@ -135,6 +139,7 @@
static int tap_dev_write(int, struct uio *, int);
static int tap_dev_ioctl(int, u_long, void *, struct lwp *);
static int tap_dev_poll(int, int, struct lwp *);
+static int tap_dev_stat(int , struct stat *);
static int tap_dev_kqfilter(int, struct knote *);
/* Fileops access routines */
@@ -145,6 +150,7 @@
kauth_cred_t, int);
static int tap_fops_ioctl(file_t *, u_long, void *);
static int tap_fops_poll(file_t *, int);
+static int tap_fops_stat(file_t *, struct stat *);
static int tap_fops_kqfilter(file_t *, struct knote *);
static const struct fileops tap_fileops = {
@@ -153,7 +159,7 @@
.fo_ioctl = tap_fops_ioctl,
.fo_fcntl = fnullop_fcntl,
.fo_poll = tap_fops_poll,
- .fo_stat = fbadop_stat,
+ .fo_stat = tap_fops_stat,
.fo_close = tap_fops_close,
.fo_kqfilter = tap_fops_kqfilter,
.fo_drain = fnullop_drain,
@@ -268,6 +274,7 @@
sc->sc_dev = self;
sc->sc_sih = softint_establish(SOFTINT_CLOCK, tap_softintr, sc);
+ getnanotime(&sc->sc_btime);
if (!pmf_device_register(self, NULL, NULL))
aprint_error_dev(self, "couldn't establish power handler\n");
@@ -891,6 +898,8 @@
if (sc == NULL)
return (ENXIO);
+ getnanotime(&sc->sc_atime);
+
ifp = &sc->sc_ec.ec_if;
if ((ifp->if_flags & IFF_UP) == 0)
return (EHOSTDOWN);
@@ -966,6 +975,33 @@
}
static int
+tap_fops_stat(file_t *fp, struct stat *st)
+{
+ int error;
+ KERNEL_LOCK(1, NULL);
+ error = tap_dev_stat((intptr_t)fp->f_data, st);
+ KERNEL_UNLOCK_ONE(NULL);
+ return error;
+}
+
+static int
+tap_dev_stat(int unit, struct stat *st)
+{
+ struct tap_softc *sc =
+ device_lookup_private(&tap_cd, unit);
+
+ if (sc == NULL)
+ return ENXIO;
+
+ (void)memset(st, 0, sizeof(*st));
+ st->st_dev = makedev(cdevsw_lookup_major(&tap_cdevsw), unit);
+ st->st_atimespec = sc->sc_atime;
+ st->st_mtimespec = sc->sc_mtime;
+ st->st_ctimespec = st->st_birthtimespec = sc->sc_btime;
+ return 0;
+}
+
+static int
tap_cdev_write(dev_t dev, struct uio *uio, int flags)
{
return tap_dev_write(minor(dev), uio, flags);
@@ -996,6 +1032,7 @@
if (sc == NULL)
return (ENXIO);
+ getnanotime(&sc->sc_mtime);
ifp = &sc->sc_ec.ec_if;
/* One write, one packet, that's the rule */
Index: opencrypto/cryptodev.c
===================================================================
RCS file: /cvsroot/src/sys/opencrypto/cryptodev.c,v
retrieving revision 1.47
diff -u -u -r1.47 cryptodev.c
--- opencrypto/cryptodev.c 4 Apr 2009 10:12:52 -0000 1.47
+++ opencrypto/cryptodev.c 10 Apr 2009 21:23:31 -0000
@@ -84,6 +84,7 @@
#include <sys/select.h>
#include <sys/poll.h>
#include <sys/atomic.h>
+#include <sys/stat.h>
#include "opt_ocf.h"
#include <opencrypto/cryptodev.h>
@@ -122,6 +123,9 @@
int sesn;
struct selinfo sinfo;
u_int32_t requestid;
+ struct timespec atime;
+ struct timespec mtime;
+ struct timespec btime;
};
/* For our fixed-size allocations */
@@ -142,6 +146,7 @@
static int cryptof_ioctl(struct file *, u_long, void *);
static int cryptof_close(struct file *);
static int cryptof_poll(struct file *, int);
+static int cryptof_stat(struct file *, struct stat *);
static const struct fileops cryptofops = {
.fo_read = cryptof_read,
@@ -149,7 +154,7 @@
.fo_ioctl = cryptof_ioctl,
.fo_fcntl = fnullop_fcntl,
.fo_poll = cryptof_poll,
- .fo_stat = fbadop_stat,
+ .fo_stat = cryptof_stat,
.fo_close = cryptof_close,
.fo_kqfilter = fnullop_kqfilter,
.fo_drain = fnullop_drain,
@@ -228,6 +233,8 @@
struct fcrypt *criofcr;
int criofd;
+ getnanotime(&fcr->atime);
+
switch (cmd) {
case CRIOGET: /* XXX deprecated, remove after 5.0 */
if ((error = fd_allocfile(&criofp, &criofd)) != 0)
@@ -265,6 +272,7 @@
goto mbail;
}
+ fcr->mtime = fcr->atime;
error = cryptodev_msession(fcr, snop, sgop->count);
if (error) {
goto mbail;
@@ -276,6 +284,7 @@
kmem_free(snop, sgop->count * sizeof(struct session_n_op));
break;
case CIOCFSESSION:
+ fcr->mtime = fcr->atime;
mutex_spin_enter(&crypto_mtx);
ses = *(u_int32_t *)data;
cse = csefind(fcr, ses);
@@ -286,6 +295,7 @@
mutex_spin_exit(&crypto_mtx);
break;
case CIOCNFSESSION:
+ fcr->mtime = fcr->atime;
sfop = (struct crypt_sfop *)data;
sesid = kmem_alloc((sfop->count * sizeof(u_int32_t)),
KM_SLEEP);
@@ -297,6 +307,7 @@
kmem_free(sesid, (sfop->count * sizeof(u_int32_t)));
break;
case CIOCCRYPT:
+ fcr->mtime = fcr->atime;
mutex_spin_enter(&crypto_mtx);
cop = (struct crypt_op *)data;
cse = csefind(fcr, cop->ses);
@@ -309,6 +320,7 @@
DPRINTF(("cryptodev_op error = %d\n", error));
break;
case CIOCNCRYPTM:
+ fcr->mtime = fcr->atime;
mop = (struct crypt_mop *)data;
cnop = kmem_alloc((mop->count * sizeof(struct crypt_n_op)),
KM_SLEEP);
@@ -328,6 +340,7 @@
DPRINTF(("cryptodev_key error = %d\n", error));
break;
case CIOCNFKEYM:
+ fcr->mtime = fcr->atime;
mkop = (struct crypt_mkop *)data;
knop = kmem_alloc((mkop->count * sizeof(struct crypt_n_kop)),
KM_SLEEP);
@@ -345,6 +358,7 @@
error = crypto_getfeat((int *)data);
break;
case CIOCNCRYPTRETM:
+ fcr->mtime = fcr->atime;
crypt_ret = (struct cryptret *)data;
count = crypt_ret->count;
crypt_res = kmem_alloc((count * sizeof(struct crypt_result)),
@@ -1010,6 +1024,7 @@
return error;
fcr = pool_get(&fcrpl, PR_WAITOK);
+ getnanotime(&fcr->btime);
mutex_spin_enter(&crypto_mtx);
TAILQ_INIT(&fcr->csessions);
TAILQ_INIT(&fcr->crp_ret_mq);
@@ -1939,6 +1954,19 @@
}
static int
+cryptof_stat(struct file *fp, struct stat *st)
+{
+ struct fcrypt *fcr = fp->f_data;
+
+ (void)memset(st, 0, sizeof(st));
+ st->st_dev = makedev(cdevsw_lookup_major(&crypto_cdevsw), fcr->sesn);
+ st->st_atimespec = fcr->atime;
+ st->st_mtimespec = fcr->mtime;
+ st->st_ctimespec = st->st_birthtimespec = fcr->btime;
+ return 0;
+}
+
+static int
cryptof_poll(struct file *fp, int events)
{
struct fcrypt *fcr = (struct fcrypt *)fp->f_data;
Index: sys/mqueue.h
===================================================================
RCS file: /cvsroot/src/sys/sys/mqueue.h,v
retrieving revision 1.6
diff -u -u -r1.6 mqueue.h
--- sys/mqueue.h 20 Jan 2009 02:15:32 -0000 1.6
+++ sys/mqueue.h 10 Apr 2009 21:23:31 -0000
@@ -88,6 +88,9 @@
TAILQ_HEAD(, mq_msg) mq_head;
/* Entry of the global list */
LIST_ENTRY(mqueue) mq_list;
+ struct timespec mq_atime;
+ struct timespec mq_mtime;
+ struct timespec mq_btime;
};
/* Structure of the message */
Home |
Main Index |
Thread Index |
Old Index