Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 May 2022 22:56:25 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: bc0c8c4d0cea - stable/13 - Clean up some of the core dumping code.
Message-ID:  <202205122256.24CMuP0V020462@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=bc0c8c4d0cea689c2a098adf6fd7c3471a21e36e

commit bc0c8c4d0cea689c2a098adf6fd7c3471a21e36e
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2021-05-25 10:48:15 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-12 22:12:59 +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
    
    (cherry picked from commit 3b9971c8da7532462048062d589ef85cbb904f7e)
---
 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 5be0dee94197..656de54cabc2 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1974,7 +1974,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, size_t len)
+compress_chunk(struct coredump_params *cp, char *base, char *buf, size_t len)
 {
 	size_t chunk_len;
 	int error;
@@ -1989,7 +1989,7 @@ compress_chunk(struct coredump_params *p, char *base, char *buf, size_t 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;
@@ -1999,17 +1999,17 @@ compress_chunk(struct coredump_params *p, char *base, char *buf, size_t 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;
@@ -2021,10 +2021,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
@@ -2044,7 +2044,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)
@@ -2067,13 +2067,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;
@@ -2088,10 +2088,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
@@ -2101,19 +2103,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);
 }
-



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202205122256.24CMuP0V020462>