Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/fs/tmpfs Allocate direntp on the stack in tmpfs_dir_getd...
details: https://anonhg.NetBSD.org/src/rev/d376b202d1e7
branches: trunk
changeset: 325837:d376b202d1e7
user: pedro <pedro%NetBSD.org@localhost>
date: Wed Jan 08 16:11:04 2014 +0000
description:
Allocate direntp on the stack in tmpfs_dir_getdents(), thus saving
calls to kmem_zalloc() and kmem_free(); OK rmind@. From OpenBSD.
diffstat:
sys/fs/tmpfs/tmpfs_subr.c | 37 ++++++++++++++++++-------------------
1 files changed, 18 insertions(+), 19 deletions(-)
diffs (96 lines):
diff -r d08b860d16df -r d376b202d1e7 sys/fs/tmpfs/tmpfs_subr.c
--- a/sys/fs/tmpfs/tmpfs_subr.c Wed Jan 08 12:30:27 2014 +0000
+++ b/sys/fs/tmpfs/tmpfs_subr.c Wed Jan 08 16:11:04 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_subr.c,v 1.93 2014/01/03 09:53:12 hannken Exp $ */
+/* $NetBSD: tmpfs_subr.c,v 1.94 2014/01/08 16:11:04 pedro Exp $ */
/*
* Copyright (c) 2005-2013 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.93 2014/01/03 09:53:12 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.94 2014/01/08 16:11:04 pedro Exp $");
#include <sys/param.h>
#include <sys/cprng.h>
@@ -797,26 +797,26 @@
tmpfs_dir_getdents(tmpfs_node_t *node, struct uio *uio, off_t *cntp)
{
tmpfs_dirent_t *de;
- struct dirent *dentp;
+ struct dirent dent;
int error = 0;
KASSERT(VOP_ISLOCKED(node->tn_vnode));
TMPFS_VALIDATE_DIR(node);
/*
- * Allocate struct dirent and first check for the "." and "..".
+ * First check for the "." and ".." cases.
* Note: tmpfs_dir_getdotents() will "seek" for us.
*/
- dentp = kmem_zalloc(sizeof(struct dirent), KM_SLEEP);
+ memset(&dent, 0, sizeof(dent));
if (uio->uio_offset == TMPFS_DIRSEQ_DOT) {
- if ((error = tmpfs_dir_getdotents(node, dentp, uio)) != 0) {
+ if ((error = tmpfs_dir_getdotents(node, &dent, uio)) != 0) {
goto done;
}
(*cntp)++;
}
if (uio->uio_offset == TMPFS_DIRSEQ_DOTDOT) {
- if ((error = tmpfs_dir_getdotents(node, dentp, uio)) != 0) {
+ if ((error = tmpfs_dir_getdotents(node, &dent, uio)) != 0) {
goto done;
}
(*cntp)++;
@@ -840,26 +840,26 @@
*/
do {
if (de->td_node == TMPFS_NODE_WHITEOUT) {
- dentp->d_fileno = 1;
- dentp->d_type = DT_WHT;
+ dent.d_fileno = 1;
+ dent.d_type = DT_WHT;
} else {
- dentp->d_fileno = de->td_node->tn_id;
- dentp->d_type = vtype2dt(de->td_node->tn_type);
+ dent.d_fileno = de->td_node->tn_id;
+ dent.d_type = vtype2dt(de->td_node->tn_type);
}
- dentp->d_namlen = de->td_namelen;
- KASSERT(de->td_namelen < sizeof(dentp->d_name));
- memcpy(dentp->d_name, de->td_name, de->td_namelen);
- dentp->d_name[de->td_namelen] = '\0';
- dentp->d_reclen = _DIRENT_SIZE(dentp);
+ dent.d_namlen = de->td_namelen;
+ KASSERT(de->td_namelen < sizeof(dent.d_name));
+ memcpy(dent.d_name, de->td_name, de->td_namelen);
+ dent.d_name[de->td_namelen] = '\0';
+ dent.d_reclen = _DIRENT_SIZE(&dent);
- if (dentp->d_reclen > uio->uio_resid) {
+ if (dent.d_reclen > uio->uio_resid) {
/* Exhausted UIO space. */
error = EJUSTRETURN;
break;
}
/* Copy out the directory entry and continue. */
- error = uiomove(dentp, dentp->d_reclen, uio);
+ error = uiomove(&dent, dent.d_reclen, uio);
if (error) {
break;
}
@@ -873,7 +873,6 @@
node->tn_spec.tn_dir.tn_readdir_lastp = de;
done:
tmpfs_update(node->tn_vnode, TMPFS_UPDATE_ATIME);
- kmem_free(dentp, sizeof(struct dirent));
if (error == EJUSTRETURN) {
/* Exhausted UIO space - just return. */
Home |
Main Index |
Thread Index |
Old Index