Skip to content

Commit b84e4eb

Browse files
committed
libsubprocess: eliminate extra write buffer
Problem: when stdin is written to a remote subprocess before the pid has been received, a buffer is created on the client side, but now that the protocol uses the matchtag instead of the pid, data can be sent early and this extra complexity can be avoided. Drop pre-running stdin buffering.
1 parent 2a5b765 commit b84e4eb

File tree

3 files changed

+10
-79
lines changed

3 files changed

+10
-79
lines changed

src/common/libsubprocess/remote.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -468,41 +468,6 @@ static int remote_output_buffered (flux_subprocess_t *p,
468468
return 0;
469469
}
470470

471-
/* In the event channel had data / closed before process running */
472-
static int send_channel_data (flux_subprocess_t *p)
473-
{
474-
struct subprocess_channel *c;
475-
c = zhash_first (p->channels);
476-
while (c) {
477-
int bytes = fbuf_bytes (c->write_buffer);
478-
if (c->closed || bytes > 0) {
479-
const char *ptr = NULL;
480-
int len = 0;
481-
if (bytes > 0) {
482-
if (!(ptr = fbuf_read (c->write_buffer, -1, &len))) {
483-
llog_debug (p,
484-
"error reading buffered data: %s",
485-
strerror (errno));
486-
set_failed (p, "internal fbuf_read error");
487-
return -1;
488-
}
489-
}
490-
if (subprocess_write (p->f, c->name, ptr, len, c->closed) < 0) {
491-
llog_debug (p,
492-
"error sending rexec.write request: %s",
493-
strerror (errno));
494-
set_failed (p, "internal close error");
495-
return -1;
496-
}
497-
/* Don't need this buffer anymore, reclaim the space */
498-
fbuf_destroy (c->write_buffer);
499-
c->write_buffer = NULL;
500-
}
501-
c = zhash_next (p->channels);
502-
}
503-
return 0;
504-
}
505-
506471
static void rexec_continuation (flux_future_t *f, void *arg)
507472
{
508473
flux_subprocess_t *p = arg;
@@ -536,8 +501,6 @@ static void rexec_continuation (flux_future_t *f, void *arg)
536501
if (subprocess_rexec_is_started (f, &p->pid)) {
537502
p->pid_set = true;
538503
process_new_state (p, FLUX_SUBPROCESS_RUNNING);
539-
if (send_channel_data (p) < 0)
540-
goto error;
541504
}
542505
else if (subprocess_rexec_is_stopped (f)) {
543506
process_new_state (p, FLUX_SUBPROCESS_STOPPED);

src/common/libsubprocess/subprocess.c

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void channel_destroy (void *arg)
5454
flux_watcher_destroy (c->buffer_read_stopped_w);
5555
c->buffer_read_w_started = false;
5656

57-
fbuf_destroy (c->write_buffer);
5857
fbuf_destroy (c->read_buffer);
5958
flux_watcher_destroy (c->out_prep_w);
6059
flux_watcher_destroy (c->out_idle_w);
@@ -707,35 +706,12 @@ int flux_subprocess_write (flux_subprocess_t *p,
707706
errno = EPIPE;
708707
return -1;
709708
}
710-
if (p->state == FLUX_SUBPROCESS_INIT) {
711-
if (!c->write_buffer) {
712-
int buffer_size;
713-
if ((buffer_size = cmd_option_bufsize (p, stream)) < 0) {
714-
log_err ("cmd_option_bufsize: %s", strerror (errno));
715-
return -1;
716-
}
717-
if (!(c->write_buffer = fbuf_create (buffer_size))) {
718-
log_err ("fbuf_create");
719-
return -1;
720-
}
721-
}
722-
if (fbuf_space (c->write_buffer) < len) {
723-
errno = ENOSPC;
724-
return -1;
725-
}
726-
if ((ret = fbuf_write (c->write_buffer, buf, len)) < 0) {
727-
log_err ("fbuf_write");
728-
return -1;
729-
}
730-
}
731-
else { /* p->state == FLUX_SUBPROCESS_RUNNING */
732-
if (subprocess_write (p->f, c->name, buf, len, false) < 0) {
733-
log_err ("error sending rexec.write request: %s",
734-
strerror (errno));
735-
return -1;
736-
}
737-
ret = len;
709+
if (subprocess_write (p->f, c->name, buf, len, false) < 0) {
710+
log_err ("error sending rexec.write request: %s",
711+
strerror (errno));
712+
return -1;
738713
}
714+
ret = len;
739715
}
740716

741717
return ret;
@@ -773,19 +749,12 @@ int flux_subprocess_close (flux_subprocess_t *p, const char *stream)
773749
c->closed = true;
774750
}
775751
else {
776-
/* if process isn't running, eof plus any previously written
777-
* data will be sent after process converts to running. See
778-
* send_channel_data() in remote.c. If subprocess has already
779-
* exited, this does nothing.
780-
*/
781-
c->closed = true;
782-
if (p->state == FLUX_SUBPROCESS_RUNNING) {
783-
if (subprocess_write (p->f, c->name, NULL, 0, true) < 0) {
784-
log_err ("error sending rexec.write request: %s",
785-
strerror (errno));
786-
return -1;
787-
}
752+
if (subprocess_write (p->f, c->name, NULL, 0, true) < 0) {
753+
log_err ("error sending rexec.write request: %s",
754+
strerror (errno));
755+
return -1;
788756
}
757+
c->closed = true;
789758
}
790759

791760
return 0;

src/common/libsubprocess/subprocess_private.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct subprocess_channel {
4545
bool buffer_read_w_started;
4646

4747
/* remote */
48-
struct fbuf *write_buffer; /* buffer pre-running data */
4948
struct fbuf *read_buffer;
5049
bool read_eof_received;
5150
flux_watcher_t *out_prep_w;

0 commit comments

Comments
 (0)