git: 3b9971c8da75 - main - Clean up some of the core dumping code.
Edward Tomasz Napierala
trasz at FreeBSD.org
Tue May 25 15:30:47 UTC 2021
The branch main has been updated by trasz:
URL: https://cgit.FreeBSD.org/src/commit/?id=3b9971c8da7532462048062d589ef85cbb904f7e
commit 3b9971c8da7532462048062d589ef85cbb904f7e
Author: Edward Tomasz Napierala <trasz at FreeBSD.org>
AuthorDate: 2021-05-25 10:48:15 +0000
Commit: Edward Tomasz Napierala <trasz at FreeBSD.org>
CommitDate: 2021-05-25 15:30:32 +0000
Clean up some of the core dumping code.
No functional changes.
Reviewed By: kib
Sponsored By: EPSRC
Differential Revision: https://reviews.freebsd.org/D30397
---
sys/kern/kern_exec.c | 51 ++++++++++++++++++++++++++-------------------------
1 file changed, 26 insertions(+), 25 deletions(-)
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 709c1b0ff28a..50451c1242eb 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1869,7 +1869,7 @@ exec_unregister(const struct execsw *execsw_arg)
* Write out a core segment to the compression stream.
*/
static int
-compress_chunk(struct coredump_params *p, char *base, char *buf, u_int len)
+compress_chunk(struct coredump_params *cp, char *base, char *buf, u_int len)
{
u_int chunk_len;
int error;
@@ -1884,7 +1884,7 @@ compress_chunk(struct coredump_params *p, char *base, char *buf, u_int len)
error = copyin(base, buf, chunk_len);
if (error != 0)
bzero(buf, chunk_len);
- error = compressor_write(p->comp, buf, chunk_len);
+ error = compressor_write(cp->comp, buf, chunk_len);
if (error != 0)
break;
base += chunk_len;
@@ -1894,17 +1894,17 @@ compress_chunk(struct coredump_params *p, char *base, char *buf, u_int len)
}
int
-core_write(struct coredump_params *p, const void *base, size_t len,
+core_write(struct coredump_params *cp, const void *base, size_t len,
off_t offset, enum uio_seg seg, size_t *resid)
{
- return (vn_rdwr_inchunks(UIO_WRITE, p->vp, __DECONST(void *, base),
+ return (vn_rdwr_inchunks(UIO_WRITE, cp->vp, __DECONST(void *, base),
len, offset, seg, IO_UNIT | IO_DIRECT | IO_RANGELOCKED,
- p->active_cred, p->file_cred, resid, p->td));
+ cp->active_cred, cp->file_cred, resid, cp->td));
}
int
-core_output(char *base, size_t len, off_t offset, struct coredump_params *p,
+core_output(char *base, size_t len, off_t offset, struct coredump_params *cp,
void *tmpbuf)
{
vm_map_t map;
@@ -1916,10 +1916,10 @@ core_output(char *base, size_t len, off_t offset, struct coredump_params *p,
KASSERT((uintptr_t)base % PAGE_SIZE == 0,
("%s: user address %p is not page-aligned", __func__, base));
- if (p->comp != NULL)
- return (compress_chunk(p, base, tmpbuf, len));
+ if (cp->comp != NULL)
+ return (compress_chunk(cp, base, tmpbuf, len));
- map = &p->td->td_proc->p_vmspace->vm_map;
+ map = &cp->td->td_proc->p_vmspace->vm_map;
for (; len > 0; base += runlen, offset += runlen, len -= runlen) {
/*
* Attempt to page in all virtual pages in the range. If a
@@ -1937,7 +1937,7 @@ core_output(char *base, size_t len, off_t offset, struct coredump_params *p,
}
if (success) {
- error = core_write(p, base, runlen, offset,
+ error = core_write(cp, base, runlen, offset,
UIO_USERSPACE, &resid);
if (error != 0) {
if (error != EFAULT)
@@ -1960,13 +1960,13 @@ core_output(char *base, size_t len, off_t offset, struct coredump_params *p,
}
}
if (!success) {
- error = vn_start_write(p->vp, &mp, V_WAIT);
+ error = vn_start_write(cp->vp, &mp, V_WAIT);
if (error != 0)
break;
- vn_lock(p->vp, LK_EXCLUSIVE | LK_RETRY);
- error = vn_truncate_locked(p->vp, offset + runlen,
- false, p->td->td_ucred);
- VOP_UNLOCK(p->vp);
+ vn_lock(cp->vp, LK_EXCLUSIVE | LK_RETRY);
+ error = vn_truncate_locked(cp->vp, offset + runlen,
+ false, cp->td->td_ucred);
+ VOP_UNLOCK(cp->vp);
vn_finished_write(mp);
if (error != 0)
break;
@@ -1981,10 +1981,12 @@ core_output(char *base, size_t len, off_t offset, struct coredump_params *p,
int
sbuf_drain_core_output(void *arg, const char *data, int len)
{
- struct coredump_params *p;
+ struct coredump_params *cp;
+ struct proc *p;
int error, locked;
- p = (struct coredump_params *)arg;
+ cp = arg;
+ p = cp->td->td_proc;
/*
* Some kern_proc out routines that print to this sbuf may
@@ -1994,19 +1996,18 @@ sbuf_drain_core_output(void *arg, const char *data, int len)
* can safely release the lock before draining and acquire
* again after.
*/
- locked = PROC_LOCKED(p->td->td_proc);
+ locked = PROC_LOCKED(p);
if (locked)
- PROC_UNLOCK(p->td->td_proc);
- if (p->comp != NULL)
- error = compressor_write(p->comp, __DECONST(char *, data), len);
+ PROC_UNLOCK(p);
+ if (cp->comp != NULL)
+ error = compressor_write(cp->comp, __DECONST(char *, data), len);
else
- error = core_write(p, __DECONST(void *, data), len, p->offset,
+ error = core_write(cp, __DECONST(void *, data), len, cp->offset,
UIO_SYSSPACE, NULL);
if (locked)
- PROC_LOCK(p->td->td_proc);
+ PROC_LOCK(p);
if (error != 0)
return (-error);
- p->offset += len;
+ cp->offset += len;
return (len);
}
-
More information about the dev-commits-src-all
mailing list