Date: Thu, 28 Oct 2021 17:50:40 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 9a0bee9f6a77 - main - Make vn_fullpath_hardlink() externally callable Message-ID: <202110281750.19SHoecR097696@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=9a0bee9f6a77a85e4dfb27c9a33d4e210d05b469 commit 9a0bee9f6a77a85e4dfb27c9a33d4e210d05b469 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-10-23 00:23:17 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-10-28 17:49:26 +0000 Make vn_fullpath_hardlink() externally callable Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32611 --- sys/kern/vfs_cache.c | 28 +++++++++++++--------------- sys/sys/vnode.h | 3 +++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 99f7314822f0..006f16587021 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -579,8 +579,6 @@ DEBUGNODE_ULONG(vnodes_cel_3_failures, cache_lock_vnodes_cel_3_failures, "Number of times 3-way vnode locking failed"); static void cache_zap_locked(struct namecache *ncp); -static int vn_fullpath_hardlink(struct nameidata *ndp, char **retbuf, - char **freebuf, size_t *buflen); static int vn_fullpath_any_smr(struct vnode *vp, struct vnode *rdir, char *buf, char **retbuf, size_t *buflen, size_t addend); static int vn_fullpath_any(struct vnode *vp, struct vnode *rdir, char *buf, @@ -3132,7 +3130,8 @@ kern___realpathat(struct thread *td, int fd, const char *path, char *buf, pathseg, path, fd, &cap_fstat_rights, td); if ((error = namei(&nd)) != 0) return (error); - error = vn_fullpath_hardlink(&nd, &retbuf, &freebuf, &size); + error = vn_fullpath_hardlink(nd.ni_vp, nd.ni_dvp, nd.ni_cnd.cn_nameptr, + nd.ni_cnd.cn_namelen, &retbuf, &freebuf, &size); if (error == 0) { error = copyout(retbuf, buf, size); free(freebuf, M_TEMP); @@ -3593,8 +3592,9 @@ vn_fullpath_any(struct vnode *vp, struct vnode *rdir, char *buf, char **retbuf, /* * Resolve an arbitrary vnode to a pathname (taking care of hardlinks). * - * Since the namecache does not track hardlinks, the caller is expected to first - * look up the target vnode with SAVENAME | WANTPARENT flags passed to namei. + * Since the namecache does not track hardlinks, the caller is + * expected to first look up the target vnode with SAVENAME | + * WANTPARENT flags passed to namei to get dvp and vp. * * Then we have 2 cases: * - if the found vnode is a directory, the path can be constructed just by @@ -3602,14 +3602,13 @@ vn_fullpath_any(struct vnode *vp, struct vnode *rdir, char *buf, char **retbuf, * - otherwise we populate the buffer with the saved name and start resolving * from the parent */ -static int -vn_fullpath_hardlink(struct nameidata *ndp, char **retbuf, char **freebuf, - size_t *buflen) +int +vn_fullpath_hardlink(struct vnode *vp, struct vnode *dvp, + const char *hrdl_name, size_t hrdl_name_length, + char **retbuf, char **freebuf, size_t *buflen) { char *buf, *tmpbuf; struct pwd *pwd; - struct componentname *cnp; - struct vnode *vp; size_t addend; int error; enum vtype type; @@ -3622,7 +3621,7 @@ vn_fullpath_hardlink(struct nameidata *ndp, char **retbuf, char **freebuf, buf = malloc(*buflen, M_TEMP, M_WAITOK); addend = 0; - vp = ndp->ni_vp; + /* * Check for VBAD to work around the vp_crossmp bug in lookup(). * @@ -3648,8 +3647,7 @@ vn_fullpath_hardlink(struct nameidata *ndp, char **retbuf, char **freebuf, goto out_bad; } if (type != VDIR) { - cnp = &ndp->ni_cnd; - addend = cnp->cn_namelen + 2; + addend = hrdl_name_length + 2; if (*buflen < addend) { error = ENOMEM; goto out_bad; @@ -3657,9 +3655,9 @@ vn_fullpath_hardlink(struct nameidata *ndp, char **retbuf, char **freebuf, *buflen -= addend; tmpbuf = buf + *buflen; tmpbuf[0] = '/'; - memcpy(&tmpbuf[1], cnp->cn_nameptr, cnp->cn_namelen); + memcpy(&tmpbuf[1], hrdl_name, hrdl_name_length); tmpbuf[addend - 1] = '\0'; - vp = ndp->ni_dvp; + vp = dvp; } vfs_smr_enter(); diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index a9b57dd4c25d..18bba17011e8 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -697,6 +697,9 @@ int vn_vptocnp(struct vnode **vp, char *buf, size_t *buflen); int vn_getcwd(char *buf, char **retbuf, size_t *buflen); int vn_fullpath(struct vnode *vp, char **retbuf, char **freebuf); int vn_fullpath_global(struct vnode *vp, char **retbuf, char **freebuf); +int vn_fullpath_hardlink(struct vnode *vp, struct vnode *dvp, + const char *hdrl_name, size_t hrdl_name_length, char **retbuf, + char **freebuf, size_t *buflen); struct vnode * vn_dir_dd_ino(struct vnode *vp); int vn_commname(struct vnode *vn, char *buf, u_int buflen);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202110281750.19SHoecR097696>