Page MenuHomeFreeBSD

D23993.id69288.diff
No OneTemporary

D23993.id69288.diff

Index: sys/fs/fifofs/fifo_vnops.c
===================================================================
--- sys/fs/fifofs/fifo_vnops.c
+++ sys/fs/fifofs/fifo_vnops.c
@@ -151,7 +151,9 @@
if (fp == NULL || (ap->a_mode & FEXEC) != 0)
return (EINVAL);
if ((fip = vp->v_fifoinfo) == NULL) {
- pipe_named_ctor(&fpipe, td);
+ error = pipe_named_ctor(&fpipe, td);
+ if (error != 0)
+ return (error);
fip = malloc(sizeof(*fip), M_VNODE, M_WAITOK);
fip->fi_pipe = fpipe;
fpipe->pipe_wgen = fip->fi_readers = fip->fi_writers = 0;
Index: sys/kern/sys_pipe.c
===================================================================
--- sys/kern/sys_pipe.c
+++ sys/kern/sys_pipe.c
@@ -226,8 +226,8 @@
static void pipeinit(void *dummy __unused);
static void pipeclose(struct pipe *cpipe);
static void pipe_free_kmem(struct pipe *cpipe);
-static void pipe_create(struct pipe *pipe, int backing);
-static void pipe_paircreate(struct thread *td, struct pipepair **p_pp);
+static int pipe_create(struct pipe *pipe, bool backing);
+static int pipe_paircreate(struct thread *td, struct pipepair **p_pp);
static __inline int pipelock(struct pipe *cpipe, int catch);
static __inline void pipeunlock(struct pipe *cpipe);
#ifndef PIPE_NODIRECT
@@ -335,11 +335,12 @@
mtx_destroy(&pp->pp_mtx);
}
-static void
+static int
pipe_paircreate(struct thread *td, struct pipepair **p_pp)
{
struct pipepair *pp;
struct pipe *rpipe, *wpipe;
+ int error;
*p_pp = pp = uma_zalloc(pipe_zone, M_WAITOK);
#ifdef MAC
@@ -357,22 +358,44 @@
knlist_init_mtx(&rpipe->pipe_sel.si_note, PIPE_MTX(rpipe));
knlist_init_mtx(&wpipe->pipe_sel.si_note, PIPE_MTX(wpipe));
- /* Only the forward direction pipe is backed by default */
- pipe_create(rpipe, 1);
- pipe_create(wpipe, 0);
+ /*
+ * Only the forward direction pipe is backed by big buffer by
+ * default.
+ */
+ error = pipe_create(rpipe, true);
+ if (error != 0)
+ goto fail;
+ error = pipe_create(wpipe, false);
+ if (error != 0) {
+ pipe_free_kmem(rpipe);
+ goto fail;
+ }
rpipe->pipe_state |= PIPE_DIRECTOK;
wpipe->pipe_state |= PIPE_DIRECTOK;
+ return (0);
+
+fail:
+ knlist_destroy(&rpipe->pipe_sel.si_note);
+ knlist_destroy(&wpipe->pipe_sel.si_note);
+#ifdef MAC
+ mac_pipe_destroy(pp);
+#endif
+ return (error);
}
-void
+int
pipe_named_ctor(struct pipe **ppipe, struct thread *td)
{
struct pipepair *pp;
+ int error;
- pipe_paircreate(td, &pp);
+ error = pipe_paircreate(td, &pp);
+ if (error != 0)
+ return (error);
pp->pp_rpipe.pipe_state |= PIPE_NAMED;
*ppipe = &pp->pp_rpipe;
+ return (0);
}
void
@@ -402,7 +425,9 @@
struct pipepair *pp;
int fd, fflags, error;
- pipe_paircreate(td, &pp);
+ error = pipe_paircreate(td, &pp);
+ if (error != 0)
+ return (error);
rpipe = &pp->pp_rpipe;
wpipe = &pp->pp_wpipe;
error = falloc_caps(td, &rf, &fd, flags, fcaps1);
@@ -507,8 +532,8 @@
error = vm_map_find(pipe_map, NULL, 0, (vm_offset_t *)&buffer, size, 0,
VMFS_ANY_SPACE, VM_PROT_RW, VM_PROT_RW, 0);
if (error != KERN_SUCCESS) {
- if ((cpipe->pipe_buffer.buffer == NULL) &&
- (size > SMALL_PIPE_SIZE)) {
+ if (cpipe->pipe_buffer.buffer == NULL &&
+ size > SMALL_PIPE_SIZE) {
size = SMALL_PIPE_SIZE;
pipefragretry++;
goto retry;
@@ -555,7 +580,7 @@
{
KASSERT(cpipe->pipe_state & PIPE_LOCKFL,
- ("Unlocked pipe passed to pipespace"));
+ ("Unlocked pipe passed to pipespace"));
return (pipespace_new(cpipe, size));
}
@@ -616,25 +641,17 @@
* Initialize and allocate VM and memory for pipe. The structure
* will start out zero'd from the ctor, so we just manage the kmem.
*/
-static void
-pipe_create(struct pipe *pipe, int backing)
+static int
+pipe_create(struct pipe *pipe, bool large_backing)
{
+ int error;
- if (backing) {
- /*
- * Note that these functions can fail if pipe map is exhausted
- * (as a result of too many pipes created), but we ignore the
- * error as it is not fatal and could be provoked by
- * unprivileged users. The only consequence is worse performance
- * with given pipe.
- */
- if (amountpipekva > maxpipekva / 2)
- (void)pipespace_new(pipe, SMALL_PIPE_SIZE);
- else
- (void)pipespace_new(pipe, PIPE_SIZE);
- }
-
+ if (!large_backing || amountpipekva > maxpipekva / 2)
+ error = pipespace_new(pipe, SMALL_PIPE_SIZE);
+ else
+ error = pipespace_new(pipe, PIPE_SIZE);
pipe->pipe_ino = alloc_unr64(&pipeino_unr);
+ return (error);
}
/* ARGSUSED */
@@ -660,10 +677,10 @@
goto locked_error;
#endif
if (amountpipekva > (3 * maxpipekva) / 4) {
- if (!(rpipe->pipe_state & PIPE_DIRECTW) &&
- (rpipe->pipe_buffer.size > SMALL_PIPE_SIZE) &&
- (rpipe->pipe_buffer.cnt <= SMALL_PIPE_SIZE) &&
- (piperesizeallowed == 1)) {
+ if ((rpipe->pipe_state & PIPE_DIRECTW) == 0 &&
+ rpipe->pipe_buffer.size > SMALL_PIPE_SIZE &&
+ rpipe->pipe_buffer.cnt <= SMALL_PIPE_SIZE &&
+ piperesizeallowed == 1) {
PIPE_UNLOCK(rpipe);
pipespace(rpipe, SMALL_PIPE_SIZE);
PIPE_LOCK(rpipe);
@@ -1011,10 +1028,9 @@
pipe_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{
- int error = 0;
- int desiredsize;
- ssize_t orig_resid;
struct pipe *wpipe, *rpipe;
+ ssize_t orig_resid;
+ int desiredsize, error;
rpipe = fp->f_data;
wpipe = PIPE_PEER(rpipe);
@@ -1056,30 +1072,20 @@
}
/* Choose a smaller size if we're in a OOM situation */
- if ((amountpipekva > (3 * maxpipekva) / 4) &&
- (wpipe->pipe_buffer.size > SMALL_PIPE_SIZE) &&
- (wpipe->pipe_buffer.cnt <= SMALL_PIPE_SIZE) &&
- (piperesizeallowed == 1))
+ if (amountpipekva > (3 * maxpipekva) / 4 &&
+ wpipe->pipe_buffer.size > SMALL_PIPE_SIZE &&
+ wpipe->pipe_buffer.cnt <= SMALL_PIPE_SIZE &&
+ piperesizeallowed == 1)
desiredsize = SMALL_PIPE_SIZE;
/* Resize if the above determined that a new size was necessary */
- if ((desiredsize != wpipe->pipe_buffer.size) &&
- ((wpipe->pipe_state & PIPE_DIRECTW) == 0)) {
+ if (desiredsize != wpipe->pipe_buffer.size &&
+ (wpipe->pipe_state & PIPE_DIRECTW) == 0) {
PIPE_UNLOCK(wpipe);
pipespace(wpipe, desiredsize);
PIPE_LOCK(wpipe);
}
- if (wpipe->pipe_buffer.size == 0) {
- /*
- * This can only happen for reverse direction use of pipes
- * in a complete OOM situation.
- */
- error = ENOMEM;
- --wpipe->pipe_busy;
- pipeunlock(wpipe);
- PIPE_UNLOCK(wpipe);
- return (error);
- }
+ MPASS(wpipe->pipe_buffer.size != 0);
pipeunlock(wpipe);
Index: sys/sys/pipe.h
===================================================================
--- sys/sys/pipe.h
+++ sys/sys/pipe.h
@@ -142,6 +142,6 @@
#define PIPE_LOCK_ASSERT(pipe, type) mtx_assert(PIPE_MTX(pipe), (type))
void pipe_dtor(struct pipe *dpipe);
-void pipe_named_ctor(struct pipe **ppipe, struct thread *td);
+int pipe_named_ctor(struct pipe **ppipe, struct thread *td);
void pipeselwakeup(struct pipe *cpipe);
#endif /* !_SYS_PIPE_H_ */

File Metadata

Mime Type
text/plain
Expires
Tue, May 19, 6:10 PM (12 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33324334
Default Alt Text
D23993.id69288.diff (6 KB)

Event Timeline