Clean up some of the core dumping code.
No functional changes. Reviewed By: kib Sponsored By: EPSRC Differential Revision: https://reviews.freebsd.org/D30397
This commit is contained in:
parent
6f4bb8ecc2
commit
3b9971c8da
@ -1869,7 +1869,7 @@ exec_unregister(const struct execsw *execsw_arg)
|
|||||||
* Write out a core segment to the compression stream.
|
* Write out a core segment to the compression stream.
|
||||||
*/
|
*/
|
||||||
static int
|
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;
|
u_int chunk_len;
|
||||||
int error;
|
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);
|
error = copyin(base, buf, chunk_len);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
bzero(buf, chunk_len);
|
bzero(buf, chunk_len);
|
||||||
error = compressor_write(p->comp, buf, chunk_len);
|
error = compressor_write(cp->comp, buf, chunk_len);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
break;
|
break;
|
||||||
base += chunk_len;
|
base += chunk_len;
|
||||||
@ -1894,17 +1894,17 @@ compress_chunk(struct coredump_params *p, char *base, char *buf, u_int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
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)
|
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,
|
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
|
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)
|
void *tmpbuf)
|
||||||
{
|
{
|
||||||
vm_map_t map;
|
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,
|
KASSERT((uintptr_t)base % PAGE_SIZE == 0,
|
||||||
("%s: user address %p is not page-aligned", __func__, base));
|
("%s: user address %p is not page-aligned", __func__, base));
|
||||||
|
|
||||||
if (p->comp != NULL)
|
if (cp->comp != NULL)
|
||||||
return (compress_chunk(p, base, tmpbuf, len));
|
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) {
|
for (; len > 0; base += runlen, offset += runlen, len -= runlen) {
|
||||||
/*
|
/*
|
||||||
* Attempt to page in all virtual pages in the range. If a
|
* 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) {
|
if (success) {
|
||||||
error = core_write(p, base, runlen, offset,
|
error = core_write(cp, base, runlen, offset,
|
||||||
UIO_USERSPACE, &resid);
|
UIO_USERSPACE, &resid);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
if (error != EFAULT)
|
if (error != EFAULT)
|
||||||
@ -1960,13 +1960,13 @@ core_output(char *base, size_t len, off_t offset, struct coredump_params *p,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
error = vn_start_write(p->vp, &mp, V_WAIT);
|
error = vn_start_write(cp->vp, &mp, V_WAIT);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
break;
|
break;
|
||||||
vn_lock(p->vp, LK_EXCLUSIVE | LK_RETRY);
|
vn_lock(cp->vp, LK_EXCLUSIVE | LK_RETRY);
|
||||||
error = vn_truncate_locked(p->vp, offset + runlen,
|
error = vn_truncate_locked(cp->vp, offset + runlen,
|
||||||
false, p->td->td_ucred);
|
false, cp->td->td_ucred);
|
||||||
VOP_UNLOCK(p->vp);
|
VOP_UNLOCK(cp->vp);
|
||||||
vn_finished_write(mp);
|
vn_finished_write(mp);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
break;
|
break;
|
||||||
@ -1981,10 +1981,12 @@ core_output(char *base, size_t len, off_t offset, struct coredump_params *p,
|
|||||||
int
|
int
|
||||||
sbuf_drain_core_output(void *arg, const char *data, int len)
|
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;
|
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
|
* 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
|
* can safely release the lock before draining and acquire
|
||||||
* again after.
|
* again after.
|
||||||
*/
|
*/
|
||||||
locked = PROC_LOCKED(p->td->td_proc);
|
locked = PROC_LOCKED(p);
|
||||||
if (locked)
|
if (locked)
|
||||||
PROC_UNLOCK(p->td->td_proc);
|
PROC_UNLOCK(p);
|
||||||
if (p->comp != NULL)
|
if (cp->comp != NULL)
|
||||||
error = compressor_write(p->comp, __DECONST(char *, data), len);
|
error = compressor_write(cp->comp, __DECONST(char *, data), len);
|
||||||
else
|
else
|
||||||
error = core_write(p, __DECONST(void *, data), len, p->offset,
|
error = core_write(cp, __DECONST(void *, data), len, cp->offset,
|
||||||
UIO_SYSSPACE, NULL);
|
UIO_SYSSPACE, NULL);
|
||||||
if (locked)
|
if (locked)
|
||||||
PROC_LOCK(p->td->td_proc);
|
PROC_LOCK(p);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (-error);
|
return (-error);
|
||||||
p->offset += len;
|
cp->offset += len;
|
||||||
return (len);
|
return (len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user