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
This commit is contained in:
Konstantin Belousov 2021-10-23 03:23:17 +03:00
parent 15bf81f354
commit 9a0bee9f6a
2 changed files with 16 additions and 15 deletions

View file

@ -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();

View file

@ -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);