diff options
author | delphij <delphij@FreeBSD.org> | 2007-06-29 05:23:15 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2007-06-29 05:23:15 +0000 |
commit | f5523801a379fd60b10766884cebdfc21bf8db35 (patch) | |
tree | 9a995329467ed0aa6c8c5a4ae50ea68413fc2cf5 /sys/fs | |
parent | 4f8f7b63aaea072afdf83c9faec421752039cbc6 (diff) | |
download | FreeBSD-src-f5523801a379fd60b10766884cebdfc21bf8db35.zip FreeBSD-src-f5523801a379fd60b10766884cebdfc21bf8db35.tar.gz |
MFp4:
- Remove unnecessary NULL checks after M_WAITOK allocations.
- Use VOP_ACCESS instead of hand-rolled suser_cred()
calls. [1]
- Use malloc(9) KPI to allocate memory for string. The
optimization taken from NetBSD is not valid for FreeBSD
because our malloc(9) already act that way. [2]
Requested by: rwatson [1]
Submitted by: Howard Su [2]
Approved by: re (tmpfs blanket)
Diffstat (limited to 'sys/fs')
-rw-r--r-- | sys/fs/tmpfs/tmpfs.h | 4 | ||||
-rw-r--r-- | sys/fs/tmpfs/tmpfs_subr.c | 42 | ||||
-rw-r--r-- | sys/fs/tmpfs/tmpfs_uma.c | 61 | ||||
-rw-r--r-- | sys/fs/tmpfs/tmpfs_uma.h | 81 | ||||
-rw-r--r-- | sys/fs/tmpfs/tmpfs_vfsops.c | 6 | ||||
-rw-r--r-- | sys/fs/tmpfs/tmpfs_vnops.c | 13 |
6 files changed, 20 insertions, 187 deletions
diff --git a/sys/fs/tmpfs/tmpfs.h b/sys/fs/tmpfs/tmpfs.h index 69e5174..34e439b 100644 --- a/sys/fs/tmpfs/tmpfs.h +++ b/sys/fs/tmpfs/tmpfs.h @@ -60,8 +60,7 @@ #include <vm/swap_pager.h> MALLOC_DECLARE(M_TMPFSMNT); - -#include <fs/tmpfs/tmpfs_uma.h> +MALLOC_DECLARE(M_TMPFSNAME); /* --------------------------------------------------------------------- */ @@ -323,7 +322,6 @@ struct tmpfs_mount { * tmpfs_pool.c. */ uma_zone_t tm_dirent_pool; uma_zone_t tm_node_pool; - struct tmpfs_str_zone tm_str_pool; }; #define TMPFS_LOCK(tm) mtx_lock(&(tm)->allnode_lock) #define TMPFS_UNLOCK(tm) mtx_unlock(&(tm)->allnode_lock) diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c index ac02b81..76d2b54 100644 --- a/sys/fs/tmpfs/tmpfs_subr.c +++ b/sys/fs/tmpfs/tmpfs_subr.c @@ -105,8 +105,6 @@ tmpfs_alloc_node(struct tmpfs_mount *tmp, enum vtype type, nnode = (struct tmpfs_node *)uma_zalloc_arg( tmp->tm_node_pool, tmp, M_WAITOK); - if (nnode == NULL) - return (ENOSPC); /* Generic initialization. */ nnode->tn_type = type; @@ -141,13 +139,8 @@ tmpfs_alloc_node(struct tmpfs_mount *tmp, enum vtype type, case VLNK: MPASS(strlen(target) < MAXPATHLEN); nnode->tn_size = strlen(target); - nnode->tn_link = tmpfs_str_zone_alloc(&tmp->tm_str_pool, - M_WAITOK, nnode->tn_size); - if (nnode->tn_link == NULL) { - nnode->tn_type = VNON; - uma_zfree(tmp->tm_node_pool, nnode); - return ENOSPC; - } + nnode->tn_link = malloc(nnode->tn_size, M_TMPFSNAME, + M_WAITOK); memcpy(nnode->tn_link, target, nnode->tn_size); break; @@ -217,8 +210,7 @@ tmpfs_free_node(struct tmpfs_mount *tmp, struct tmpfs_node *node) break; case VLNK: - tmpfs_str_zone_free(&tmp->tm_str_pool, node->tn_link, - node->tn_size); + free(node->tn_link, M_TMPFSNAME); break; case VREG: @@ -259,14 +251,7 @@ tmpfs_alloc_dirent(struct tmpfs_mount *tmp, struct tmpfs_node *node, nde = (struct tmpfs_dirent *)uma_zalloc( tmp->tm_dirent_pool, M_WAITOK); - if (nde == NULL) - return ENOSPC; - - nde->td_name = tmpfs_str_zone_alloc(&tmp->tm_str_pool, M_WAITOK, len); - if (nde->td_name == NULL) { - uma_zfree(tmp->tm_dirent_pool, nde); - return ENOSPC; - } + nde->td_name = malloc(len, M_TMPFSNAME, M_WAITOK); nde->td_namelen = len; memcpy(nde->td_name, name, len); @@ -302,7 +287,7 @@ tmpfs_free_dirent(struct tmpfs_mount *tmp, struct tmpfs_dirent *de, node->tn_links--; } - tmpfs_str_zone_free(&tmp->tm_str_pool, de->td_name, de->td_namelen); + free(de->td_name, M_TMPFSNAME); uma_zfree(tmp->tm_dirent_pool, de); } @@ -1174,14 +1159,15 @@ tmpfs_chtimes(struct vnode *vp, struct timespec *atime, struct timespec *mtime, if (node->tn_flags & (IMMUTABLE | APPEND)) return EPERM; - /* XXX: The following comes from UFS code, and can be found in - * several other file systems. Shouldn't this be centralized - * somewhere? */ - if (cred->cr_uid != node->tn_uid && - (error = suser_cred(cred, 0)) && - ((vaflags & VA_UTIMES_NULL) == 0 || - (error = VOP_ACCESS(vp, VWRITE, cred, l)))) - return error; + /* Determine if the user have proper privilege to update time. */ + if (vaflags & VA_UTIMES_NULL) { + error = VOP_ACCESS(vp, VADMIN, cred, l); + if (error) + error = VOP_ACCESS(vp, VWRITE, cred, l); + } else + error = VOP_ACCESS(vp, VADMIN, cred, l); + if (error) + return (error); if (atime->tv_sec != VNOVAL && atime->tv_nsec != VNOVAL) node->tn_status |= TMPFS_NODE_ACCESSED; diff --git a/sys/fs/tmpfs/tmpfs_uma.c b/sys/fs/tmpfs/tmpfs_uma.c deleted file mode 100644 index f23e05d..0000000 --- a/sys/fs/tmpfs/tmpfs_uma.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 2007 Rohit Jalan (rohitj@purpe.com) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice unmodified, this list of conditions, and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <vm/vm.h> - -#include <fs/tmpfs/tmpfs.h> - -void -tmpfs_str_zone_create(struct tmpfs_str_zone *tsz) -{ - int i, len; - - len = TMPFS_STRZONE_STARTLEN; - for (i = 0; i < TMPFS_STRZONE_ZONECOUNT; ++i) { - tsz->tsz_zone[i] = uma_zcreate( - "TMPFS str", len, - NULL, NULL, NULL, NULL, - UMA_ALIGN_PTR, 0); - len <<= 1; - } -} - -void -tmpfs_str_zone_destroy(struct tmpfs_str_zone *tsz) -{ - int i, len; - - len = TMPFS_STRZONE_STARTLEN; - for (i = 0; i < TMPFS_STRZONE_ZONECOUNT; ++i) { - uma_zdestroy(tsz->tsz_zone[i]); - len <<= 1; - } -} - diff --git a/sys/fs/tmpfs/tmpfs_uma.h b/sys/fs/tmpfs/tmpfs_uma.h deleted file mode 100644 index 142be78..0000000 --- a/sys/fs/tmpfs/tmpfs_uma.h +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * Copyright (c) 2007 Rohit Jalan (rohitj@purpe.com) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice unmodified, this list of conditions, and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _TMPFS_UMA_H -#define _TMPFS_UMA_H - -#include <vm/uma.h> - -#define TMPFS_STRZONE_ZONECOUNT 7 -#define TMPFS_STRZONE_STARTLEN (1 << 4) - -struct tmpfs_mount; - -struct tmpfs_str_zone { - uma_zone_t tsz_zone[TMPFS_STRZONE_ZONECOUNT]; -}; - -void tmpfs_str_zone_create(struct tmpfs_str_zone *); -void tmpfs_str_zone_destroy(struct tmpfs_str_zone *); - -static __inline char* -tmpfs_str_zone_alloc(struct tmpfs_str_zone *tsz, int flags, size_t len) -{ - - size_t i, zlen; - char *ptr; - - MPASS(len <= (TMPFS_STRZONE_STARTLEN << (TMPFS_STRZONE_ZONECOUNT-1))); - - i = 0; - zlen = TMPFS_STRZONE_STARTLEN; - while (len > zlen) { - ++i; - zlen <<= 1; - } - ptr = (char *)uma_zalloc(tsz->tsz_zone[i], flags); - return ptr; -} - -static __inline void -tmpfs_str_zone_free(struct tmpfs_str_zone *tsz, char *item, size_t len) -{ - size_t i, zlen; - - MPASS(len <= (TMPFS_STRZONE_STARTLEN << (TMPFS_STRZONE_ZONECOUNT-1))); - - i = 0; - zlen = TMPFS_STRZONE_STARTLEN; - while (len > zlen) { - ++i; - zlen <<= 1; - } - uma_zfree(tsz->tsz_zone[i], item); -} - -#endif diff --git a/sys/fs/tmpfs/tmpfs_vfsops.c b/sys/fs/tmpfs/tmpfs_vfsops.c index 007661b..0546cbf 100644 --- a/sys/fs/tmpfs/tmpfs_vfsops.c +++ b/sys/fs/tmpfs/tmpfs_vfsops.c @@ -70,6 +70,7 @@ __FBSDID("$FreeBSD$"); #define TMPFS_DEFAULT_ROOT_MODE (S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) MALLOC_DEFINE(M_TMPFSMNT, "tmpfs mount", "tmpfs mount structures"); +MALLOC_DEFINE(M_TMPFSNAME, "tmpfs name", "tmpfs file names"); /* --------------------------------------------------------------------- */ @@ -276,8 +277,7 @@ tmpfs_mount(struct mount *mp, struct thread *l) tmpfs_node_ctor, tmpfs_node_dtor, tmpfs_node_init, tmpfs_node_fini, UMA_ALIGN_PTR, - 0); - tmpfs_str_zone_create(&tmp->tm_str_pool); + UMA_ZONE_NOFREE); /* Allocate the root node. */ error = tmpfs_alloc_node(tmp, VDIR, args.ta_root_uid, @@ -285,7 +285,6 @@ tmpfs_mount(struct mount *mp, struct thread *l) VNOVAL, l, &root); if (error != 0 || root == NULL) { - tmpfs_str_zone_destroy(&tmp->tm_str_pool); uma_zdestroy(tmp->tm_node_pool); uma_zdestroy(tmp->tm_dirent_pool); free(tmp, M_TMPFSMNT); @@ -358,7 +357,6 @@ tmpfs_unmount(struct mount *mp, int mntflags, struct thread *l) uma_zdestroy(tmp->tm_dirent_pool); uma_zdestroy(tmp->tm_node_pool); - tmpfs_str_zone_destroy(&tmp->tm_str_pool); mtx_destroy(&tmp->allnode_lock); MPASS(tmp->tm_pages_used == 0); diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index 10d515a..520fff7e 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -830,12 +830,7 @@ tmpfs_rename(struct vop_rename_args *v) * has to be changed. */ if (fcnp->cn_namelen != tcnp->cn_namelen || memcmp(fcnp->cn_nameptr, tcnp->cn_nameptr, fcnp->cn_namelen) != 0) { - newname = tmpfs_str_zone_alloc(&tmp->tm_str_pool, M_WAITOK, - tcnp->cn_namelen); - if (newname == NULL) { - error = ENOSPC; - goto out_locked; - } + newname = malloc(tcnp->cn_namelen, M_TMPFSNAME, M_WAITOK); } else newname = NULL; @@ -855,8 +850,7 @@ tmpfs_rename(struct vop_rename_args *v) if (n == fnode) { error = EINVAL; if (newname != NULL) - tmpfs_str_zone_free(&tmp->tm_str_pool, - newname, tcnp->cn_namelen); + free(newname, M_TMPFSNAME); goto out_locked; } n = n->tn_dir.tn_parent; @@ -884,8 +878,7 @@ tmpfs_rename(struct vop_rename_args *v) if (newname != NULL) { MPASS(tcnp->cn_namelen <= MAXNAMLEN); - tmpfs_str_zone_free(&tmp->tm_str_pool, de->td_name, - de->td_namelen); + free(de->td_name, M_TMPFSNAME); de->td_namelen = (uint16_t)tcnp->cn_namelen; memcpy(newname, tcnp->cn_nameptr, tcnp->cn_namelen); de->td_name = newname; |