kernel - Adjust cache_fullpath() API
authorMatthew Dillon <dillon@apollo.backplane.com>
Wed, 10 Oct 2012 19:13:35 +0000 (12:13 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Wed, 10 Oct 2012 19:13:35 +0000 (12:13 -0700)
* Add another argument to explicitly specify the base directory that the
  path is to be relative to.

sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c
sys/kern/kern_jail.c
sys/kern/kern_proc.c
sys/kern/vfs_cache.c
sys/kern/vfs_syscalls.c
sys/sys/namecache.h
sys/vfs/isofs/cd9660/cd9660_rrip.c
sys/vfs/procfs/procfs_vnops.c

index b076ac4..86327eb 100644 (file)
@@ -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);
index fad701a..b17a55e 100644 (file)
@@ -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;
index 3af2cd3..54fac4c 100644 (file)
@@ -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;
index d4899d3..07ecbfd 100644 (file)
@@ -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);
 }
index 7d39c66..dfeadc9 100644 (file)
@@ -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));
 }
 
 /*
index 8fb09dc..aad7e67 100644 (file)
@@ -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
 
index 4148b22..cf62d5b 100644 (file)
@@ -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;
index 8974479..06520c8 100644 (file)
@@ -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 {