From 08a7d6d8d1e562a40eb7bcb30fb968b3a68faf43 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 10 Oct 2012 12:13:35 -0700 Subject: [PATCH] kernel - Adjust cache_fullpath() API * Add another argument to explicitly specify the base directory that the path is to be relative to. --- .../linux/i386/linprocfs/linprocfs_vnops.c | 17 +++++++++++------ sys/kern/kern_jail.c | 2 +- sys/kern/kern_proc.c | 3 ++- sys/kern/vfs_cache.c | 11 +++++++---- sys/kern/vfs_syscalls.c | 5 +++-- sys/sys/namecache.h | 3 ++- sys/vfs/isofs/cd9660/cd9660_rrip.c | 2 +- sys/vfs/procfs/procfs_vnops.c | 4 ++-- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c b/sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c index b076ac4a15..86327eb4a7 100644 --- a/sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c +++ b/sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c @@ -562,7 +562,8 @@ linprocfs_getattr(struct vop_getattr_args *ap) case Pexe: { char *fullpath, *freepath; - error = cache_fullpath(procp, &procp->p_textnch, &fullpath, &freepath, 0); + error = cache_fullpath(procp, &procp->p_textnch, NULL, + &fullpath, &freepath, 0); /* error = vn_fullpath(procp, NULL, &fullpath, &freepath); */ if (error == 0) { vap->va_size = strlen(fullpath); @@ -576,7 +577,8 @@ linprocfs_getattr(struct vop_getattr_args *ap) } case Pcwd: { char *fullpath, *freepath; - error = cache_fullpath(procp, &procp->p_fd->fd_ncdir, &fullpath, &freepath, 0); + error = cache_fullpath(procp, &procp->p_fd->fd_ncdir, NULL, + &fullpath, &freepath, 0); if (error == 0) { vap->va_size = strlen(fullpath); kfree(freepath, M_TEMP); @@ -591,7 +593,8 @@ linprocfs_getattr(struct vop_getattr_args *ap) struct nchandle *nchp; char *fullpath, *freepath; nchp = jailed(procp->p_ucred) ? &procp->p_fd->fd_njdir : &procp->p_fd->fd_nrdir; - error = cache_fullpath(procp, nchp, &fullpath, &freepath, 0); + error = cache_fullpath(procp, nchp, NULL, + &fullpath, &freepath, 0); if (error == 0) { vap->va_size = strlen(fullpath); kfree(freepath, M_TEMP); @@ -1560,7 +1563,8 @@ linprocfs_readlink(struct vop_readlink_args *ap) ap->a_uio); break; } - error = cache_fullpath(procp, &procp->p_textnch, &fullpath, &freepath, 0); + error = cache_fullpath(procp, &procp->p_textnch, NULL, + &fullpath, &freepath, 0); if (error != 0) { error = uiomove("unknown", sizeof("unknown") - 1, ap->a_uio); @@ -1578,7 +1582,7 @@ linprocfs_readlink(struct vop_readlink_args *ap) ap->a_uio); break; } - error = cache_fullpath(procp, &procp->p_fd->fd_ncdir, + error = cache_fullpath(procp, &procp->p_fd->fd_ncdir, NULL, &fullpath, &freepath, 0); if (error != 0) { error = uiomove("unknown", sizeof("unknown") - 1, @@ -1598,7 +1602,8 @@ linprocfs_readlink(struct vop_readlink_args *ap) break; } nchp = jailed(procp->p_ucred) ? &procp->p_fd->fd_njdir : &procp->p_fd->fd_nrdir; - error = cache_fullpath(procp, nchp, &fullpath, &freepath, 0); + error = cache_fullpath(procp, nchp, NULL, + &fullpath, &freepath, 0); if (error != 0) { error = uiomove("unknown", sizeof("unknown") - 1, ap->a_uio); diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index fad701a161..b17a55e956 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -587,7 +587,7 @@ retry: count = prisoncount; LIST_FOREACH(pr, &allprison, pr_list) { - error = cache_fullpath(lp->lwp_proc, &pr->pr_root, + error = cache_fullpath(lp->lwp_proc, &pr->pr_root, NULL, &fullpath, &freepath, 0); if (error) continue; diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 3af2cd30a6..54fac4cd7a 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1345,7 +1345,8 @@ sysctl_kern_proc_cwd(SYSCTL_HANDLER_ARGS) struct nchandle nch; cache_copy(&p->p_fd->fd_ncdir, &nch); - error = cache_fullpath(p, &nch, &fullpath, &freepath, 0); + error = cache_fullpath(p, &nch, NULL, + &fullpath, &freepath, 0); cache_drop(&nch); if (error) goto done; diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index d4899d364d..07ecbfd9c9 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -3228,7 +3228,7 @@ SYSCTL_UINT(_vfs_cache, OID_AUTO, numfullpathfound, CTLFLAG_RD, "Number of full path resolution successes"); int -cache_fullpath(struct proc *p, struct nchandle *nchp, +cache_fullpath(struct proc *p, struct nchandle *nchp, struct nchandle *nchbase, char **retbuf, char **freebuf, int guess) { struct nchandle fd_nrdir; @@ -3248,7 +3248,9 @@ cache_fullpath(struct proc *p, struct nchandle *nchp, buf = kmalloc(MAXPATHLEN, M_TEMP, M_WAITOK); bp = buf + MAXPATHLEN - 1; *bp = '\0'; - if (p != NULL) + if (nchbase) + fd_nrdir = *nchbase; + else if (p != NULL) fd_nrdir = p->p_fd->fd_nrdir; else fd_nrdir = rootnch; @@ -3265,7 +3267,8 @@ cache_fullpath(struct proc *p, struct nchandle *nchp, /* * If we are asked to guess the upwards path, we do so whenever * we encounter an ncp marked as a mountpoint. We try to find - * the actual mountpoint by finding the mountpoint with this ncp. + * the actual mountpoint by finding the mountpoint with this + * ncp. */ if (guess && (ncp->nc_flag & NCF_ISMOUNTPT)) { new_mp = mount_get_by_nc(ncp); @@ -3389,7 +3392,7 @@ vn_fullpath(struct proc *p, struct vnode *vn, char **retbuf, char **freebuf, atomic_add_int(&numfullpathcalls, -1); nch.ncp = ncp;; nch.mount = vn->v_mount; - error = cache_fullpath(p, &nch, retbuf, freebuf, guess); + error = cache_fullpath(p, &nch, NULL, retbuf, freebuf, guess); _cache_drop(ncp); return (error); } diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 7d39c666d4..dfeadc9f91 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -822,7 +822,8 @@ mount_warning(struct mount *mp, const char *ctl, ...) __va_list va; __va_start(va, ctl); - if (cache_fullpath(NULL, &mp->mnt_ncmounton, &ptr, &buf, 0) == 0) { + if (cache_fullpath(NULL, &mp->mnt_ncmounton, NULL, + &ptr, &buf, 0) == 0) { kprintf("unmount(%s): ", ptr); kvprintf(ctl, va); kprintf("\n"); @@ -855,7 +856,7 @@ mount_path(struct proc *p, struct mount *mp, char **rb, char **fb) nch = &p->p_fd->fd_nrdir; else nch = &mp->mnt_ncmountpt; - return(cache_fullpath(p, nch, rb, fb, 0)); + return(cache_fullpath(p, nch, NULL, rb, fb, 0)); } /* diff --git a/sys/sys/namecache.h b/sys/sys/namecache.h index 8fb09dc007..aad7e67fb1 100644 --- a/sys/sys/namecache.h +++ b/sys/sys/namecache.h @@ -215,7 +215,8 @@ void cache_unlink(struct nchandle *nch); int cache_vget(struct nchandle *, struct ucred *, int, struct vnode **); int cache_vref(struct nchandle *, struct ucred *, struct vnode **); int cache_fromdvp(struct vnode *, struct ucred *, int, struct nchandle *); -int cache_fullpath(struct proc *, struct nchandle *, char **, char **, int); +int cache_fullpath(struct proc *, struct nchandle *, struct nchandle *, + char **, char **, int); #endif diff --git a/sys/vfs/isofs/cd9660/cd9660_rrip.c b/sys/vfs/isofs/cd9660/cd9660_rrip.c index 4148b22fbc..cf62d5b99e 100644 --- a/sys/vfs/isofs/cd9660/cd9660_rrip.c +++ b/sys/vfs/isofs/cd9660/cd9660_rrip.c @@ -176,7 +176,7 @@ cd9660_rrip_slink(ISO_RRIP_SLINK *p, ISO_RRIP_ANALYZE *ana) /* same as above */ outbuf -= len; len = 0; - error = cache_fullpath(NULL, &ana->imp->im_mountp->mnt_ncmountpt, + error = cache_fullpath(NULL, &ana->imp->im_mountp->mnt_ncmountpt, NULL, &inbuf, &freebuf, 0); if (error) goto bad; diff --git a/sys/vfs/procfs/procfs_vnops.c b/sys/vfs/procfs/procfs_vnops.c index 89744790e8..06520c813e 100644 --- a/sys/vfs/procfs/procfs_vnops.c +++ b/sys/vfs/procfs/procfs_vnops.c @@ -638,7 +638,7 @@ procfs_getattr(struct vop_getattr_args *ap) struct nchandle nch; cache_copy(&procp->p_textnch, &nch); - error = cache_fullpath(procp, &nch, + error = cache_fullpath(procp, &nch, NULL, &fullpath, &freepath, 0); cache_drop(&nch); } else { @@ -1121,7 +1121,7 @@ procfs_readlink(struct vop_readlink_args *ap) struct nchandle nch; cache_copy(&procp->p_textnch, &nch); - error = cache_fullpath(procp, &nch, + error = cache_fullpath(procp, &nch, NULL, &fullpath, &freepath, 0); cache_drop(&nch); } else { -- 2.41.0