git: ff6abfec807e - main - pipe: sort out ino commentary on failed pipe creation
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 22 Sep 2025 08:44:50 UTC
The branch main has been updated by mjg:
URL: https://cgit.FreeBSD.org/src/commit/?id=ff6abfec807e31301e3bf9c0df14a22bb6bc3443
commit ff6abfec807e31301e3bf9c0df14a22bb6bc3443
Author: Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2025-09-22 08:37:50 +0000
Commit: Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2025-09-22 08:44:46 +0000
pipe: sort out ino commentary on failed pipe creation
Implements pipe_destroy as a counterpart to pipe_create, no functional
changes.
Arguably code could be refactored so that ino allocation only happens
after bufs are allocated.
---
sys/kern/sys_pipe.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index ed651da96b14..30527fdd4fd0 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -234,6 +234,7 @@ static void pipeinit(void *dummy __unused);
static void pipeclose(struct pipe *cpipe);
static void pipe_free_kmem(struct pipe *cpipe);
static int pipe_create(struct pipe *pipe, bool backing);
+static void pipe_destroy(struct pipe *pipe);
static int pipe_paircreate(struct thread *td, struct pipepair **p_pp);
static __inline int pipelock(struct pipe *cpipe, bool catch);
static __inline void pipeunlock(struct pipe *cpipe);
@@ -399,16 +400,7 @@ pipe_paircreate(struct thread *td, struct pipepair **p_pp)
goto fail;
error = pipe_create(wpipe, false);
if (error != 0) {
- /*
- * This cleanup leaves the pipe inode number for rpipe
- * still allocated, but never used. We do not free
- * inode numbers for opened pipes, which is required
- * for correctness because numbers must be unique.
- * But also it avoids any memory use by the unr
- * allocator, so stashing away the transient inode
- * number is reasonable.
- */
- pipe_free_kmem(rpipe);
+ pipe_destroy(rpipe);
goto fail;
}
@@ -743,6 +735,16 @@ pipe_create(struct pipe *pipe, bool large_backing)
return (error);
}
+static void
+pipe_destroy(struct pipe *pipe)
+{
+ pipe_free_kmem(pipe);
+ /*
+ * Note: we "leak" pipe_ino -- by design the alloc_unr64 mechanism does
+ * not undo allocations.
+ */
+}
+
/* ARGSUSED */
static int
pipe_read(struct file *fp, struct uio *uio, struct ucred *active_cred,