PERFORCE change 45246 for review
Robert Watson
rwatson at FreeBSD.org
Tue Jan 13 04:55:04 GMT 2004
http://perforce.freebsd.org/chv.cgi?CH=45246
Change 45246 by rwatson at rwatson_paprika on 2004/01/12 20:54:08
Modify vn_fullpath() memory ownership model: the caller now
allocates the memory, rather than vn_fullpath() allocating it.
This brings us closer to Apple's vn_getpath(), and permits the
storage for a path in the audit system to be owned by the
audit system. Also prevents a lot of extra mallocs in procfs...
Affected files ...
.. //depot/projects/trustedbsd/audit2/sys/compat/linprocfs/linprocfs.c#4 edit
.. //depot/projects/trustedbsd/audit2/sys/fs/procfs/procfs.c#3 edit
.. //depot/projects/trustedbsd/audit2/sys/fs/procfs/procfs_map.c#3 edit
.. //depot/projects/trustedbsd/audit2/sys/kern/vfs_cache.c#3 edit
.. //depot/projects/trustedbsd/audit2/sys/sys/vnode.h#3 edit
Differences ...
==== //depot/projects/trustedbsd/audit2/sys/compat/linprocfs/linprocfs.c#4 (text+ko) ====
@@ -349,17 +349,19 @@
struct mount *mp;
const char *lep;
char *dlep, *flep, *mntto, *mntfrom, *fstype;
+ char *fullpath, *lep;
size_t lep_len;
int error;
/* resolve symlinks etc. in the emulation tree prefix */
+ fullpath = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path, td);
flep = NULL;
- if (namei(&nd) != 0 || vn_fullpath_thread(td, nd.ni_vp, &dlep, &flep)
- != 0)
+ if (namei(&nd) != 0 || vn_fullpath_proc(td, nd.ni_vp, fullpath,
+ MAXPATHLEN) != 0)
lep = linux_emul_path;
else
- lep = dlep;
+ lep = fullpath;
lep_len = strlen(lep);
mtx_lock(&mountlist_mtx);
@@ -403,8 +405,7 @@
sbuf_printf(sb, " 0 0\n");
}
mtx_unlock(&mountlist_mtx);
- if (flep != NULL)
- free(flep, M_TEMP);
+ free(fullpath);
return (error);
}
@@ -737,13 +738,14 @@
static int
linprocfs_doproccwd(PFS_FILL_ARGS)
{
- char *fullpath = "unknown";
- char *freepath = NULL;
+ char *fullpath;
- vn_fullpath_thread(td, p->p_fd->fd_cdir, &fullpath, &freepath);
- sbuf_printf(sb, "%s", fullpath);
- if (freepath)
- free(freepath, M_TEMP);
+ fullpath = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
+ if (vn_fullpath_proc(td, p->p_fd->fd_cdir, fullpath, MAXPATHLEN) == 0)
+ sbuf_printf(sb, "%s", fullpath);
+ else
+ sbuf_printf(sb, "unknown");
+ free(fullpath, M_TEMP);
return (0);
}
@@ -754,14 +756,15 @@
linprocfs_doprocroot(PFS_FILL_ARGS)
{
struct vnode *rvp;
- char *fullpath = "unknown";
- char *freepath = NULL;
+ char *fullpath;
+ fullpath = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
rvp = jailed(p->p_ucred) ? p->p_fd->fd_jdir : p->p_fd->fd_rdir;
- vn_fullpath_thread(td, rvp, &fullpath, &freepath);
- sbuf_printf(sb, "%s", fullpath);
- if (freepath)
- free(freepath, M_TEMP);
+ if (vn_fullpath_proc(td, rvp, fullpath, MAXPATHLEN) == 0)
+ sbuf_printf(sb, "%s", fullpath);
+ else
+ sbuf_printf(sb, "unknown");
+ free(fullpath);
return (0);
}
@@ -828,12 +831,12 @@
vm_map_entry_t entry;
vm_object_t obj, tobj, lobj;
vm_ooffset_t off = 0;
- char *name = "", *freename = NULL;
+ char *name = "", *fullpath;
size_t len;
ino_t ino;
int ref_count, shadow_count, flags;
int error;
-
+
PROC_LOCK(p);
error = p_candebug(td, p);
PROC_UNLOCK(p);
@@ -846,6 +849,7 @@
if (uio->uio_offset != 0)
return (0);
+ fullpath = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
error = 0;
if (map != &curthread->td_proc->p_vmspace->vm_map)
vm_map_lock_read(map);
@@ -864,9 +868,12 @@
VM_OBJECT_LOCK(lobj);
off = IDX_TO_OFF(lobj->size);
if (lobj->type == OBJT_VNODE && lobj->handle) {
- vn_fullpath_thread(td,
- (struct vnode *)lobj->handle, &name,
- &freename);
+ if (vn_fullpath_proc(td,
+ (struct vnode *)lobj->handle, fullpath,
+ MAXPATHLEN) == 0)
+ name = fullpath;
+ else
+ name = "";
ino = ((struct vnode *)
lobj->handle)->v_cachedid;
}
@@ -898,8 +905,6 @@
*name ? " " : "",
name
);
- if (freename)
- free(freename, M_TEMP);
len = strlen(mebuffer);
if (len > uio->uio_resid)
len = uio->uio_resid; /*
@@ -912,7 +917,7 @@
}
if (map != &curthread->td_proc->p_vmspace->vm_map)
vm_map_unlock_read(map);
-
+ free(fullpath);
return (error);
}
==== //depot/projects/trustedbsd/audit2/sys/fs/procfs/procfs.c#3 (text+ko) ====
@@ -67,13 +67,14 @@
int
procfs_doprocfile(PFS_FILL_ARGS)
{
- char *fullpath = "unknown";
- char *freepath = NULL;
+ char *path;
- vn_fullpath_thread(td, p->p_textvp, &fullpath, &freepath);
- sbuf_printf(sb, "%s", fullpath);
- if (freepath)
- free(freepath, M_TEMP);
+ path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
+ if (vn_fullpath_proc(td, p->p_textvp, path, MAXPATHLEN) == 0)
+ sbuf_printf(sb, "%s", path);
+ else
+ sbuf_printf(sb, "unknown");
+ free(path, M_TEMP);
return (0);
}
==== //depot/projects/trustedbsd/audit2/sys/fs/procfs/procfs_map.c#3 (text+ko) ====
@@ -80,7 +80,7 @@
pmap_t pmap = vmspace_pmap(p->p_vmspace);
vm_map_entry_t entry;
char mebuffer[MEBUFFERSIZE];
- char *fullpath, *freepath;
+ char *path, *thepath;
GIANT_REQUIRED;
@@ -95,7 +95,8 @@
if (uio->uio_offset != 0)
return (0);
-
+
+ path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
error = 0;
if (map != &curthread->td_proc->p_vmspace->vm_map)
vm_map_lock_read(map);
@@ -128,26 +129,30 @@
for (lobj = tobj = obj; tobj; tobj = tobj->backing_object)
lobj = tobj;
- freepath = NULL;
- fullpath = "-";
+ path = NULL;
if (lobj) {
switch(lobj->type) {
default:
case OBJT_DEFAULT:
+ thepath = "-";
type = "default";
break;
case OBJT_VNODE:
type = "vnode";
- vn_fullpath_thread(td,
- (struct vnode *)lobj->handle,
- &fullpath,
- &freepath);
+ if (vn_fullpath_proc(td,
+ (struct vnode *)lobj->handle, path,
+ MAXPATHLEN) == 0)
+ thepath = path;
+ else
+ thepath = "unknown";
break;
case OBJT_SWAP:
type = "swap";
+ thepath = "-";
break;
case OBJT_DEVICE:
type = "device";
+ thepath = "-";
break;
}
@@ -156,6 +161,7 @@
shadow_count = obj->shadow_count;
} else {
type = "none";
+ thepath = "-";
flags = 0;
ref_count = 0;
shadow_count = 0;
@@ -175,11 +181,8 @@
ref_count, shadow_count, flags,
(entry->eflags & MAP_ENTRY_COW)?"COW":"NCOW",
(entry->eflags & MAP_ENTRY_NEEDS_COPY)?"NC":"NNC",
- type, fullpath);
+ type, thepath);
- if (freepath != NULL)
- free(freepath, M_TEMP);
-
len = strlen(mebuffer);
if (len > uio->uio_resid) {
error = EFBIG;
@@ -191,6 +194,7 @@
}
if (map != &curthread->td_proc->p_vmspace->vm_map)
vm_map_unlock_read(map);
+ free(path, M_TEMP);
return (error);
}
==== //depot/projects/trustedbsd/audit2/sys/kern/vfs_cache.c#3 (text+ko) ====
@@ -927,10 +927,10 @@
* cache (if available)
*/
int
-vn_fullpath(struct vnode *optional_root, struct vnode *vn, char **retbuf,
- char **freebuf)
+vn_fullpath(struct vnode *optional_root, struct vnode *vn, char *buf,
+ u_int buflen)
{
- char *bp, *buf;
+ char *bp;
int i, slash_prefixed;
struct namecache *ncp;
struct vnode *vp;
@@ -941,8 +941,7 @@
return (ENODEV);
if (vn == NULL)
return (EINVAL);
- buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
- bp = buf + MAXPATHLEN - 1;
+ bp = buf + buflen - 1;
*bp = '\0';
slash_prefixed = 0;
error = 0;
@@ -1000,25 +999,21 @@
*--bp = '/';
}
numfullpathfound++;
- *retbuf = bp;
- *freebuf = buf;
out2:
CACHE_UNLOCK();
out1:
- if (error)
- free(buf, M_TEMP);
- return (0);
+ return (error);
}
/*
* Perform a vn_fullpath() operation relative to a specific process's
* root. The process is specified using a thread, which for locking
- * reasons, should be curthread. A better API might pass in a reference
- * to struct filedesc * to specify what root to use.
+ * reasons, (must) should be curthread. A better API might pass in a
+ * reference to struct filedesc * to specify what root to use.
*/
int
-vn_fullpath_thread(struct thread *td, struct vnode *vn, char **retbuf,
- char **freebuf)
+vn_fullpath_proc(struct thread *td, struct vnode *vn, char *buf,
+ u_int buflen)
{
struct filedesc *fdp;
int error;
@@ -1031,7 +1026,7 @@
*/
fdp = td->td_proc->p_fd;
FILEDESC_LOCK(fdp);
- error = vn_fullpath(fdp->fd_rdir, vn, retbuf, freebuf);
+ error = vn_fullpath(fdp->fd_rdir, vn, buf, buflen);
FILEDESC_UNLOCK(fdp);
return (error);
}
==== //depot/projects/trustedbsd/audit2/sys/sys/vnode.h#3 (text+ko) ====
@@ -609,12 +609,12 @@
int lease_check(struct vop_lease_args *ap);
int spec_vnoperate(struct vop_generic_args *);
int speedup_syncer(void);
-#define textvp_fullpath(p, rb, rfb) \
- vn_fullpath_thread(FIRST_THREAD_IN_PROC(p), (p)->p_textvp, rb, rfb)
+#define textvp_fullpath(p, rb, rbl) \
+ vn_fullpath_proc(FIRST_THREAD_IN_PROC(p), (p)->p_textvp, rb, rbl)
int vn_fullpath(struct vnode *optional_root, struct vnode *vn,
- char **retbuf, char **freebuf);
-int vn_fullpath_thread(struct thread *td, struct vnode *vn,
- char **retbuf, char **freebuf);
+ char *buf, u_int buflen);
+int vn_fullpath_proc(struct thread *td, struct vnode *vn,
+ char *buf, u_int buflen);
int vaccess(enum vtype type, mode_t file_mode, uid_t uid, gid_t gid,
mode_t acc_mode, struct ucred *cred, int *privused);
int vaccess_acl_posix1e(enum vtype type, uid_t file_uid,
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list