Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Introduce struct pathbuf. This is an abstraction to hold a p...



details:   https://anonhg.NetBSD.org/src/rev/c6aa4438037d
branches:  trunk
changeset: 758873:c6aa4438037d
user:      dholland <dholland%NetBSD.org@localhost>
date:      Fri Nov 19 06:44:33 2010 +0000

description:
Introduce struct pathbuf. This is an abstraction to hold a pathname
and the metadata required to interpret it. Callers of namei must now
create a pathbuf and pass it to NDINIT (instead of a string and a
uio_seg), then destroy the pathbuf after the namei session is
complete.

Update all namei call sites accordingly. Add a pathbuf(9) man page and
update namei(9).

The pathbuf interface also now appears in a couple of related
additional places that were passing string/uio_seg pairs that were
later fed into NDINIT. Update other call sites accordingly.

diffstat:

 distrib/sets/lists/comp/mi            |    5 +-
 external/cddl/osnet/sys/sys/vnode.h   |   10 +-
 share/man/man9/Makefile               |    4 +-
 share/man/man9/namei.9                |   22 +-
 share/man/man9/pathbuf.9              |  110 +++++++++++
 sys/compat/common/compat_util.c       |   14 +-
 sys/compat/common/vfs_syscalls_30.c   |   13 +-
 sys/compat/common/vfs_syscalls_43.c   |   14 +-
 sys/compat/darwin/darwin_attr.c       |   19 +-
 sys/compat/ibcs2/ibcs2_fcntl.c        |   18 +-
 sys/compat/irix/irix_mount.c          |   18 +-
 sys/compat/linux/common/linux_file.c  |   17 +-
 sys/compat/netbsd32/netbsd32_netbsd.c |   22 +-
 sys/compat/sunos32/sunos32_misc.c     |   14 +-
 sys/compat/svr4/svr4_misc.c           |   17 +-
 sys/compat/svr4/svr4_stream.c         |   21 +-
 sys/compat/svr4_32/svr4_32_misc.c     |   17 +-
 sys/dev/ccd.c                         |   14 +-
 sys/dev/cgd.c                         |   16 +-
 sys/dev/dksubr.c                      |    9 +-
 sys/dev/dkvar.h                       |    7 +-
 sys/dev/dm/dm_pdev.c                  |   13 +-
 sys/dev/firmload.c                    |   18 +-
 sys/dev/fss.c                         |   20 +-
 sys/dev/kloader.c                     |   15 +-
 sys/dev/raidframe/rf_copyback.c       |   18 +-
 sys/dev/raidframe/rf_disks.c          |   15 +-
 sys/dev/raidframe/rf_reconstruct.c    |   14 +-
 sys/dev/vnd.c                         |   17 +-
 sys/fs/efs/efs_vfsops.c               |   21 +-
 sys/fs/ptyfs/ptyfs_subr.c             |   18 +-
 sys/fs/unionfs/unionfs_vfsops.c       |   14 +-
 sys/kern/exec_macho.c                 |   16 +-
 sys/kern/exec_script.c                |   13 +-
 sys/kern/kern_acct.c                  |   22 +-
 sys/kern/kern_core.c                  |   18 +-
 sys/kern/kern_exec.c                  |   36 ++-
 sys/kern/kern_ktrace.c                |   14 +-
 sys/kern/kern_module_vfs.c            |   30 ++-
 sys/kern/subr_exec_fd.c               |   13 +-
 sys/kern/subr_kobj_vfs.c              |   16 +-
 sys/kern/tty.c                        |   17 +-
 sys/kern/tty_bsdpty.c                 |   17 +-
 sys/kern/uipc_usrreq.c                |   38 +++-
 sys/kern/vfs_lookup.c                 |  192 ++++++++++++++++++--
 sys/kern/vfs_syscalls.c               |  314 +++++++++++++++++++++++++--------
 sys/kern/vfs_vnops.c                  |   15 +-
 sys/kern/vfs_xattr.c                  |   17 +-
 sys/miscfs/nullfs/null_vfsops.c       |   13 +-
 sys/miscfs/umapfs/umap_vfsops.c       |   19 +-
 sys/nfs/nfs_export.c                  |   16 +-
 sys/nfs/nfs_srvsubs.c                 |    6 +-
 sys/rump/librump/rumpvfs/rump_vfs.c   |   16 +-
 sys/sys/exec.h                        |    7 +-
 sys/sys/namei.src                     |   41 +++-
 sys/sys/verified_exec.h               |   18 +-
 sys/ufs/ufs/ufs_quota.c               |   20 +-
 sys/uvm/uvm_swap.c                    |   39 ++-
 58 files changed, 1197 insertions(+), 370 deletions(-)

diffs (truncated from 3892 to 300 lines):

diff -r f04bca3dd88f -r c6aa4438037d distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Fri Nov 19 05:38:10 2010 +0000
+++ b/distrib/sets/lists/comp/mi        Fri Nov 19 06:44:33 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.1523 2010/11/04 22:05:43 pooka Exp $
+#      $NetBSD: mi,v 1.1524 2010/11/19 06:44:34 dholland Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -9478,6 +9478,7 @@
 ./usr/share/man/cat9/optstr_get.0              comp-sys-catman         .cat
 ./usr/share/man/cat9/p_find.0                  comp-obsolete           obsolete
 ./usr/share/man/cat9/panic.0                   comp-sys-catman         .cat
+./usr/share/man/cat9/pathbuf.0                 comp-sys-catman         .cat
 ./usr/share/man/cat9/pci.0                     comp-sys-catman         .cat
 ./usr/share/man/cat9/pci_conf_hook.0           comp-sys-catman         .cat
 ./usr/share/man/cat9/pci_conf_interrupt.0      comp-sys-catman         .cat
@@ -15298,6 +15299,7 @@
 ./usr/share/man/html9/optstr_get.html          comp-sys-htmlman        html
 ./usr/share/man/html9/p_find.html              comp-obsolete           obsolete
 ./usr/share/man/html9/panic.html               comp-sys-htmlman        html
+./usr/share/man/html9/pathbuf.html             comp-sys-htmlman        html
 ./usr/share/man/html9/pci.html                 comp-sys-htmlman        html
 ./usr/share/man/html9/pci_conf_hook.html       comp-sys-htmlman        html
 ./usr/share/man/html9/pci_conf_interrupt.html  comp-sys-htmlman        html
@@ -21285,6 +21287,7 @@
 ./usr/share/man/man9/optstr_get.9              comp-sys-man            .man
 ./usr/share/man/man9/p_find.9                  comp-obsolete           obsolete
 ./usr/share/man/man9/panic.9                   comp-sys-man            .man
+./usr/share/man/man9/pathbuf.9                 comp-sys-man            .man
 ./usr/share/man/man9/pci.9                     comp-sys-man            .man
 ./usr/share/man/man9/pci_conf_hook.9           comp-sys-man            .man
 ./usr/share/man/man9/pci_conf_interrupt.9      comp-sys-man            .man
diff -r f04bca3dd88f -r c6aa4438037d external/cddl/osnet/sys/sys/vnode.h
--- a/external/cddl/osnet/sys/sys/vnode.h       Fri Nov 19 05:38:10 2010 +0000
+++ b/external/cddl/osnet/sys/sys/vnode.h       Fri Nov 19 06:44:33 2010 +0000
@@ -1,5 +1,5 @@
 
-/*     $NetBSD: vnode.h,v 1.5 2010/06/24 13:03:05 hannken Exp $        */
+/*     $NetBSD: vnode.h,v 1.6 2010/11/19 06:44:33 dholland Exp $       */
 
 /*
  * CDDL HEADER START
@@ -511,6 +511,7 @@
 zfs_vn_open(const char *pnamep, enum uio_seg seg, int filemode, int createmode,
     vnode_t **vpp, enum create crwhy, mode_t umask)
 {
+       struct pathbuf *pb;
        struct nameidata nd;
        int error;
 
@@ -519,12 +520,17 @@
        ASSERT(crwhy == CRCREAT);
        ASSERT(umask == 0);
 
-       NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pnamep);
+       pb = pathbuf_create(pnamep);
+       if (pb == NULL) {
+               return ENOMEM;
+       }
+       NDINIT(&nd, LOOKUP, NOFOLLOW, pb);
        error = vn_open(&nd, filemode, createmode);
        if (error == 0) {
                VOP_UNLOCK(nd.ni_vp);
                *vpp = nd.ni_vp;
        }
+       pathbuf_destroy(pb);
        return (error);
 }
 #define        vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask)   \
diff -r f04bca3dd88f -r c6aa4438037d share/man/man9/Makefile
--- a/share/man/man9/Makefile   Fri Nov 19 05:38:10 2010 +0000
+++ b/share/man/man9/Makefile   Fri Nov 19 06:44:33 2010 +0000
@@ -1,4 +1,4 @@
-#       $NetBSD: Makefile,v 1.342 2010/08/22 18:56:20 rmind Exp $
+#       $NetBSD: Makefile,v 1.343 2010/11/19 06:44:48 dholland Exp $
 
 #      Makefile for section 9 (kernel function and variable) manual pages.
 
@@ -37,7 +37,7 @@
        microtime.9 microuptime.9 mi_switch.9 module.9 \
        mstohz.9 mutex.9 m_tag.9 namecache.9 \
        namei.9 npf_ncode.9 nullop.9 opencrypto.9 optstr.9 \
-       panic.9 pci.9 pci_configure_bus.9 pci_intr.9 pckbport.9 \
+       panic.9 pathbuf.9 pci.9 pci_configure_bus.9 pci_intr.9 pckbport.9 \
        pcmcia.9 pcq.9 percpu.9 pfil.9 physio.9 pmap.9 pmatch.9 \
        pmc.9 pmf.9 pool.9 pool_cache.9 powerhook_establish.9 ppsratecheck.9 \
        preempt.9 proc_find.9 putter.9 \
diff -r f04bca3dd88f -r c6aa4438037d share/man/man9/namei.9
--- a/share/man/man9/namei.9    Fri Nov 19 05:38:10 2010 +0000
+++ b/share/man/man9/namei.9    Fri Nov 19 06:44:33 2010 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: namei.9,v 1.24 2009/09/27 21:05:55 wiz Exp $
+.\"     $NetBSD: namei.9,v 1.25 2010/11/19 06:44:48 dholland Exp $
 .\"
 .\" Copyright (c) 2001, 2005, 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -55,7 +55,7 @@
 "struct componentname *cnp"
 .Ft void
 .Fn NDINIT "struct nameidata *ndp" "u_long op" "u_long flags" \
-"enum uio_seg segflg" "const char *namep"
+"struct pathbuf *pathbuf"
 .Ft int
 .Fn namei_simple_kernel "const char *path" "namei_simple_flags_t sflags" \
 "struct vnode **ret"
@@ -323,7 +323,7 @@
 .Fa cnp .
 The vnode of the pathname is returned in the address specified by
 .Fa vpp .
-.It Fn NDINIT "ndp" "op" "flags" "segflg" "namep"
+.It Fn NDINIT "ndp" "op" "flags" "pathbuf"
 Initialise a nameidata structure pointed to by
 .Fa ndp
 for use by the
@@ -341,14 +341,14 @@
 and
 .Em ndp-\*[Gt]ni_cnd.cn_flags
 are respectively set.
-The segment flags which defines whether the pathname is in kernel
-address space or user address space is specified by
-.Fa segflag .
-The argument
-.Fa namep
-is a pointer to the pathname that
-.Em ndp-\*[Gt]ni_dirp
-is set to.
+The pathname is passed as a pathbuf structure, which should be
+initialized using one of the
+.Xr pathbuf 9
+operations.
+Destroying the pathbuf is the responsibility of the caller; this must
+not be done until the caller is finished with all of the
+.Nm
+results and all of the nameidata contents except for the result vnode.
 .Pp
 This routine stores the credentials of the calling thread
 .Va ( curlwp )
diff -r f04bca3dd88f -r c6aa4438037d share/man/man9/pathbuf.9
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man9/pathbuf.9  Fri Nov 19 06:44:33 2010 +0000
@@ -0,0 +1,110 @@
+.\"     $NetBSD: pathbuf.9,v 1.1 2010/11/19 06:44:48 dholland Exp $
+.\"
+.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by David A. Holland.
+.\"
+.\" 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, 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``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 FOUNDATION OR CONTRIBUTORS
+.\" 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.
+.\"
+.Dd November 16, 2010
+.Dt PATHBUF 9
+.Os
+.Sh NAME
+.Nm pathbuf ,
+.Nm pathbuf_create ,
+.Nm pathbuf_copyin ,
+.Nm pathbuf_destroy
+.Nd path buffer abstraction
+.Sh SYNOPSIS
+.In sys/namei.h
+.Ft struct pathbuf *
+.Fn pathbuf_create "const char *path"
+.Ft int
+.Fn pathbuf_copyin "const char *userpath" "struct pathbuf **ret"
+.Ft void
+.Fn pathbuf_destroy "struct pathbuf *path"
+.Sh DESCRIPTION
+The
+.Nm
+interface is used to carry around pathnames.
+This helps simplify the
+.Xr namei 9
+interface.
+A pathbuf should be thought of as a path name string combined with
+whatever flags and metadata are needed to interpret it correctly.
+It is an abstract type; the internals are hidden within the
+.Xr namei 9
+implementation.
+.Pp
+The
+.Fn pathbuf_create
+function allocates and initializes a new pathbuf containing a copy of
+the path string
+.Fa path ,
+which should be a kernel pointer.
+The return value should be checked for being
+.Dv NULL
+in case the system is out of memory.
+Passing a path name larger than
+.Dv PATH_MAX
+will cause an assertion failure.
+.Pp
+The
+.Fn pathbuf_copyin
+function allocates and initializes a new pathbuf containing a path
+string copied from user space with
+.Xr copyinstr 9 .
+It returns an error code.
+.Pp
+The
+.Fn pathbuf_destroy
+function deallocates a pathbuf.
+Caution: because calling
+.Xr namei 9
+loads pointers to memory belonging to the pathbuf into the nameidata
+structure, a pathbuf should only be destroyed by the
+.Fn namei
+caller once all manipulations of the nameidata are complete.
+.Pp
+Also note that calling
+.Fn namei
+destroys the contents of the pathbuf.
+Do not reuse a pathbuf for a second call to
+.Fn namei .
+.Sh CODE REFERENCES
+The
+.Nm
+code is part of the name lookup code in
+.Pa sys/kern/vfs_lookup.c .
+.Sh SEE ALSO
+.Xr namei 9
+.Sh BUGS
+There are cases where it is necessary to get the path string left
+behind after
+.Fn namei
+has run.
+This produces an effect similar to
+.Xr realpath 3 .
+The interface for doing this is, for the time being, intentionally
+undocumented and subject to change.
diff -r f04bca3dd88f -r c6aa4438037d sys/compat/common/compat_util.c
--- a/sys/compat/common/compat_util.c   Fri Nov 19 05:38:10 2010 +0000
+++ b/sys/compat/common/compat_util.c   Fri Nov 19 06:44:33 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_util.c,v 1.43 2009/12/14 04:09:38 mrg Exp $     */
+/*     $NetBSD: compat_util.c,v 1.44 2010/11/19 06:44:35 dholland Exp $        */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_util.c,v 1.43 2009/12/14 04:09:38 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_util.c,v 1.44 2010/11/19 06:44:35 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -107,9 +107,15 @@
 emul_find_interp(struct lwp *l, struct exec_package *epp, const char *itp)
 {
        int error;
+       struct pathbuf *pb;
        struct nameidata nd;
        unsigned int flags;
 
+       pb = pathbuf_create(itp);
+       if (pb == NULL) {
+               return ENOMEM;
+       }
+
        /* If we haven't found the emulation root already, do so now */
        /* Maybe we should remember failures somehow ? */
        if (epp->ep_esch->es_emul->e_path != 0 && epp->ep_emul_root == NULL)
@@ -129,7 +135,7 @@
                flags = FOLLOW | TRYEMULROOT | EMULROOTSET;
        }
 
-       NDINIT(&nd, LOOKUP, flags, UIO_SYSSPACE, itp);
+       NDINIT(&nd, LOOKUP, flags, pb);
        error = namei(&nd);
        if (error != 0) {
                epp->ep_interp = NULL;
@@ -139,6 +145,8 @@
        /* Save interpreter in case we actually need to load it */
        epp->ep_interp = nd.ni_vp;
 
+       pathbuf_destroy(pb);



Home | Main Index | Thread Index | Old Index