Re: relayd uses more socket splicing

2012-11-02 Thread Ian McWilliam

fushed -> flushed

Though if we were speaking with an extremely broad Australian accent -
"I fushed the dunny.", maybe what you would hear. So ends today's lesson 
on spelling.  ;-)


Ian McWilliam

On 3/11/2012 5:03 AM, Alexander Bluhm wrote:

Hi,

I have changed relayd so that it uses socket splicing also for
persistent http connections.  Before it spliced the incomming and
outgoing tcp streams only if the data should go unmodified through
the kernel until the end of stream.

With this diff, relayd can give the kernel a maximum splice length.
So it can take back control on persitent http sessions or with http
chunking.

As the diff contains a bunch of independent fixes, I will break it
into small pieces for review and commit.  But for those who want
to test the whole thing, here it is.

bluhm

Index: usr.sbin/relayd/relay.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.157
diff -u -p -r1.157 relay.c
--- usr.sbin/relayd/relay.c 19 Oct 2012 16:49:50 -  1.157
+++ usr.sbin/relayd/relay.c 2 Nov 2012 17:49:50 -
@@ -70,9 +70,6 @@ void   relay_input(struct rsession *);
  
  u_int32_t	 relay_hash_addr(struct sockaddr_storage *, u_int32_t);
  
-int		 relay_splice(struct ctl_relay_event *);

-int relay_splicelen(struct ctl_relay_event *);
-
  SSL_CTX   *relay_ssl_ctx_create(struct relay *);
  void   relay_ssl_transaction(struct rsession *,
struct ctl_relay_event *);
@@ -643,6 +640,7 @@ relay_connected(int fd, short sig, void
case RELAY_PROTO_HTTP:
/* Check the servers's HTTP response */
if (!RB_EMPTY(&rlay->rl_proto->response_tree)) {
+   con->se_out.toread = TOREAD_HTTP_HEADER;
outrd = relay_read_http;
if ((con->se_out.nodes = calloc(proto->response_nodes,
sizeof(u_int8_t))) == NULL) {
@@ -681,9 +679,6 @@ relay_connected(int fd, short sig, void
bufferevent_settimeout(bev,
rlay->rl_conf.timeout.tv_sec, rlay->rl_conf.timeout.tv_sec);
bufferevent_enable(bev, EV_READ|EV_WRITE);
-
-   if (relay_splice(&con->se_out) == -1)
-   relay_close(con, strerror(errno));
  }
  
  void

@@ -699,6 +694,7 @@ relay_input(struct rsession *con)
/* Check the client's HTTP request */
if (!RB_EMPTY(&rlay->rl_proto->request_tree) ||
proto->lateconnect) {
+   con->se_in.toread = TOREAD_HTTP_HEADER;
inrd = relay_read_http;
if ((con->se_in.nodes = calloc(proto->request_nodes,
sizeof(u_int8_t))) == NULL) {
@@ -731,9 +727,6 @@ relay_input(struct rsession *con)
bufferevent_settimeout(con->se_in.bev,
rlay->rl_conf.timeout.tv_sec, rlay->rl_conf.timeout.tv_sec);
bufferevent_enable(con->se_in.bev, EV_READ|EV_WRITE);
-
-   if (relay_splice(&con->se_in) == -1)
-   relay_close(con, strerror(errno));
  }
  
  void

@@ -741,10 +734,19 @@ relay_write(struct bufferevent *bev, voi
  {
struct ctl_relay_event  *cre = (struct ctl_relay_event *)arg;
struct rsession *con = cre->con;
+
if (gettimeofday(&con->se_tv_last, NULL) == -1)
-   con->se_done = 1;
+   goto fail;
if (con->se_done)
-   relay_close(con, "last write (done)");
+   goto done;
+   if (relay_splice(cre->dst) == -1)
+   goto fail;
+   return;
+ done:
+   relay_close(con, "last write (done)");
+   return;
+ fail:
+   relay_close(con, strerror(errno));
  }
  
  void

@@ -822,11 +824,27 @@ relay_splice(struct ctl_relay_event *cre
(proto->tcpflags & TCPFLAG_NSPLICE))
return (0);
  
-	if (cre->bev->readcb != relay_read)

+   if (cre->splicelen >= 0)
return (0);
  
+	if (! (cre->toread == TOREAD_UNLIMITED || cre->toread > 0)) {

+   DPRINTF("%s: session %d: splice dir %d, nothing to read %lld",
+   __func__, con->se_id, cre->dir, cre->toread);
+   return (0);
+   }
+
+   /* do not splice before buffers have not been completely fushed */
+   if (EVBUFFER_LENGTH(cre->bev->input) ||
+   EVBUFFER_LENGTH(cre->dst->bev->output)) {
+   DPRINTF("%s: session %d: splice dir %d, dirty buffer",
+   __func__, con->se_id, cre->dir);
+   bufferevent_disable(cre->bev, EV_READ);
+   return (2);
+   }
+
bzero(&sp, sizeof(sp));
sp.sp_fd = cre->dst->s;
+   sp.sp_max = cre->toread > 0 ? cre->toread : 0;
sp.sp_idle = rlay->rl_conf.timeout;
if (setsockopt(cre->s, SOL_SOCKET, SO_SPLICE, &sp, sizeof(sp)) == -1) {
log_debug("%s: session %d: splice d

relayd uses more socket splicing

2012-11-02 Thread Alexander Bluhm
Hi,

I have changed relayd so that it uses socket splicing also for
persistent http connections.  Before it spliced the incomming and
outgoing tcp streams only if the data should go unmodified through
the kernel until the end of stream.

With this diff, relayd can give the kernel a maximum splice length.
So it can take back control on persitent http sessions or with http
chunking.

As the diff contains a bunch of independent fixes, I will break it
into small pieces for review and commit.  But for those who want
to test the whole thing, here it is.

bluhm

Index: usr.sbin/relayd/relay.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.157
diff -u -p -r1.157 relay.c
--- usr.sbin/relayd/relay.c 19 Oct 2012 16:49:50 -  1.157
+++ usr.sbin/relayd/relay.c 2 Nov 2012 17:49:50 -
@@ -70,9 +70,6 @@ void   relay_input(struct rsession *);
 
 u_int32_t   relay_hash_addr(struct sockaddr_storage *, u_int32_t);
 
-int relay_splice(struct ctl_relay_event *);
-int relay_splicelen(struct ctl_relay_event *);
-
 SSL_CTX*relay_ssl_ctx_create(struct relay *);
 voidrelay_ssl_transaction(struct rsession *,
struct ctl_relay_event *);
@@ -643,6 +640,7 @@ relay_connected(int fd, short sig, void 
case RELAY_PROTO_HTTP:
/* Check the servers's HTTP response */
if (!RB_EMPTY(&rlay->rl_proto->response_tree)) {
+   con->se_out.toread = TOREAD_HTTP_HEADER;
outrd = relay_read_http;
if ((con->se_out.nodes = calloc(proto->response_nodes,
sizeof(u_int8_t))) == NULL) {
@@ -681,9 +679,6 @@ relay_connected(int fd, short sig, void 
bufferevent_settimeout(bev,
rlay->rl_conf.timeout.tv_sec, rlay->rl_conf.timeout.tv_sec);
bufferevent_enable(bev, EV_READ|EV_WRITE);
-
-   if (relay_splice(&con->se_out) == -1)
-   relay_close(con, strerror(errno));
 }
 
 void
@@ -699,6 +694,7 @@ relay_input(struct rsession *con)
/* Check the client's HTTP request */
if (!RB_EMPTY(&rlay->rl_proto->request_tree) ||
proto->lateconnect) {
+   con->se_in.toread = TOREAD_HTTP_HEADER;
inrd = relay_read_http;
if ((con->se_in.nodes = calloc(proto->request_nodes,
sizeof(u_int8_t))) == NULL) {
@@ -731,9 +727,6 @@ relay_input(struct rsession *con)
bufferevent_settimeout(con->se_in.bev,
rlay->rl_conf.timeout.tv_sec, rlay->rl_conf.timeout.tv_sec);
bufferevent_enable(con->se_in.bev, EV_READ|EV_WRITE);
-
-   if (relay_splice(&con->se_in) == -1)
-   relay_close(con, strerror(errno));
 }
 
 void
@@ -741,10 +734,19 @@ relay_write(struct bufferevent *bev, voi
 {
struct ctl_relay_event  *cre = (struct ctl_relay_event *)arg;
struct rsession *con = cre->con;
+
if (gettimeofday(&con->se_tv_last, NULL) == -1)
-   con->se_done = 1;
+   goto fail;
if (con->se_done)
-   relay_close(con, "last write (done)");
+   goto done;
+   if (relay_splice(cre->dst) == -1)
+   goto fail;
+   return;
+ done:
+   relay_close(con, "last write (done)");
+   return;
+ fail:
+   relay_close(con, strerror(errno));
 }
 
 void
@@ -822,11 +824,27 @@ relay_splice(struct ctl_relay_event *cre
(proto->tcpflags & TCPFLAG_NSPLICE))
return (0);
 
-   if (cre->bev->readcb != relay_read)
+   if (cre->splicelen >= 0)
return (0);
 
+   if (! (cre->toread == TOREAD_UNLIMITED || cre->toread > 0)) {
+   DPRINTF("%s: session %d: splice dir %d, nothing to read %lld",
+   __func__, con->se_id, cre->dir, cre->toread);
+   return (0);
+   }
+
+   /* do not splice before buffers have not been completely fushed */
+   if (EVBUFFER_LENGTH(cre->bev->input) ||
+   EVBUFFER_LENGTH(cre->dst->bev->output)) {
+   DPRINTF("%s: session %d: splice dir %d, dirty buffer",
+   __func__, con->se_id, cre->dir);
+   bufferevent_disable(cre->bev, EV_READ);
+   return (2);
+   }
+
bzero(&sp, sizeof(sp));
sp.sp_fd = cre->dst->s;
+   sp.sp_max = cre->toread > 0 ? cre->toread : 0;
sp.sp_idle = rlay->rl_conf.timeout;
if (setsockopt(cre->s, SOL_SOCKET, SO_SPLICE, &sp, sizeof(sp)) == -1) {
log_debug("%s: session %d: splice dir %d failed: %s",
@@ -834,8 +852,11 @@ relay_splice(struct ctl_relay_event *cre
return (-1);
}
cre->splicelen = 0;
-   DPRINTF("%s: session %d: splice dir %d successful",
-   __func__, con->se_

Re: [PATCH] cwm: function menu

2012-11-02 Thread Thomas Pfaff
On Tue, 30 Oct 2012 17:44:25 -0500
"Kent R. Spillner"  wrote:

This segfaults.  See comments below.

> Here is an initial attempt at adding a menu for searching/executing internal
> functions.  It's useful for those times you want to an unbound function, and
> even when the function is bound to some key combo you haven't memorized yet
> it can be faster than looking up the keybinding in the manual.  It also
> plays really nicely with the restart diff from earlier today as I found out
> while working on kbfunc_func_search itself. ;)
> 
> I'll work on the manpage bits on the train tonight.
> 
> Index: calmwm.h
> ===
> RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
> retrieving revision 1.153
> diff -p -u -r1.153 calmwm.h
> --- calmwm.h  9 Sep 2012 19:47:47 -   1.153
> +++ calmwm.h  30 Oct 2012 20:21:59 -
> @@ -225,6 +225,13 @@ struct screen_ctx {
>  };
>  TAILQ_HEAD(screen_ctx_q, screen_ctx);
>  
> +struct func {
> + char*tag;
> + void (*handler)(struct client_ctx *, union arg *);
> + int  flags;
> + union argargument;
> +};
> +
>  struct keybinding {
>   TAILQ_ENTRY(keybinding)  entry;
>   void(*callback)(struct client_ctx *, union arg *);
> @@ -393,6 +400,7 @@ void   kbfunc_client_vmaximize(struct 
> c
>union arg *);
>  void  kbfunc_cmdexec(struct client_ctx *, union arg *);
>  void  kbfunc_exec(struct client_ctx *, union arg *);
> +void  kbfunc_func_search(struct client_ctx *, union arg *);
>  void  kbfunc_lock(struct client_ctx *, union arg *);
>  void  kbfunc_menu_search(struct client_ctx *, union arg *);
>  void  kbfunc_moveresize(struct client_ctx *, union arg *);
> @@ -501,6 +509,7 @@ extern Cursor  Cursor_resize;
>  extern struct screen_ctx_qScreenq;
>  extern struct client_ctx_qClientq;
>  extern struct confConf;
> +extern struct funcname_to_kbfunc[];
>  
>  extern intHasXinerama, HasRandr, Randr_ev;
>  
> Index: conf.c
> ===
> RCS file: /cvs/xenocara/app/cwm/conf.c,v
> retrieving revision 1.100
> diff -p -u -r1.100 conf.c
> --- conf.c29 Oct 2012 19:46:03 -  1.100
> +++ conf.c30 Oct 2012 20:21:59 -
[...]
> @@ -427,6 +424,7 @@ static struct {
>   {.i = (CWM_LEFT|CWM_PTRMOVE|CWM_BIGMOVE)} },
>   { "bigptrmoveright", kbfunc_moveresize, 0,
>   {.i = (CWM_RIGHT|CWM_PTRMOVE|CWM_BIGMOVE)} },
> + { NULL, NULL, 0, {0} }

This breaks how name_to_kbfunc is currently being used;

   for (iter = 0; iter < nitems(name_to_kbfunc); iter++) {
  if (strcmp(name_to_kbfunc[iter]->tag, ...

I think you can see where this goes wrong with your patch
applied (hint: passing NULL to strcmp is not advised ;-) ).

>  };
>  
>  /*
> Index: kbfunc.c
> ===
> RCS file: /cvs/xenocara/app/cwm/kbfunc.c,v
> retrieving revision 1.63
> diff -p -u -r1.63 kbfunc.c
> --- kbfunc.c  9 Sep 2012 19:47:47 -   1.63
> +++ kbfunc.c  30 Oct 2012 20:21:59 -
> @@ -173,6 +173,35 @@ kbfunc_client_search(struct client_ctx *
>  }
>  
>  void
> +kbfunc_func_search(struct client_ctx *cc, union arg *arg)
> +{
> + struct screen_ctx   *sc = cc->sc;
> + struct func *func;
> + struct menu *mi;
> + struct menu_qmenuq;
> +
> + TAILQ_INIT(&menuq);
> +
> + for (func = name_to_kbfunc; func->tag != NULL; func++) {

I suppose this is why you added the NULL entry in the array ...

> + mi = xcalloc(1, sizeof(*mi));
> + (void)strlcpy(mi->text, func->tag, sizeof(mi->text));
> + mi->ctx = func;
> + TAILQ_INSERT_TAIL(&menuq, mi, entry);
> + }

Cheers,
Thomas.



Re: 512 hardcoded into scan_ffs(8)

2012-11-02 Thread Theo de Raadt
> Looking at the source of scan_ffs, 512 is hardcoded all over the place.
> Would it be an improvement to have that configurable, for the newer disks
> with bigger size?

No.  ffs information is layed out on the disk in 512 byte chunks.



Re: Replacing "err(1, (char *)NULL);" with "err(1, NULL);" in style(9) manpage

2012-11-02 Thread Jason McIntyre
On Thu, Nov 01, 2012 at 12:41:17AM -0200, Rafael wrote:
> Hi tech@,
> 
> The diff below replaces "err(1, (char *)NULL);" with "err(1, NULL);" on
> usage example of error functions in style(9) manpage. The casting seems to
> be a leftover from the changes from revision 1.38 to 1.39.
> 

fixed, thanks!
jmc

> Before 1.39 the text stated that "Use NULL instead of (type\ *)0 or (type\
> *)NULL in (type\ *)0 or (type\ *)NULL in contexts where the compiler knows
> the  type, e.g., in assignments. Use (type\ *)NULL in other contexts, in
> particular for all function args. (Casting is essential for variadic args
> and is necessary for other args  if the function prototype might not be in
> scope.)".
> 
> From revision 1.39 on the guidelines changed towards use casting only in
> variadic parameters, as text says "Use NULL instead of (type\ *)0 or (type\
> *)NULL in all cases except for arguments to variadic functions where the
> compiler does not know the type.".
> 
> In this case, the argument type is known. Further, this changes conforms
> with usage example in err(9) manpage.
> 
> Thanks
> 
> Index: style.9
> ===
> RCS file: /cvs/src/share/man/man9/style.9,v
> retrieving revision 1.53
> diff -u -p -r1.53 style.9
> --- style.9   11 Apr 2012 21:09:23 -  1.53
> +++ style.9   1 Nov 2012 02:25:39 -
> @@ -534,7 +534,7 @@ or
>  don't roll your own!
>  .Bd -literal -offset indent
>  if ((four = malloc(sizeof(struct foo))) == NULL)
> - err(1, (char *)NULL);
> + err(1, NULL);
>  if ((six = (int *)overflow()) == NULL)
>   errx(1, "Number overflowed.");
>  return (eight);



512 hardcoded into scan_ffs(8)

2012-11-02 Thread Jan Stary
Looking at the source of scan_ffs, 512 is hardcoded all over the place.
Would it be an improvement to have that configurable, for the newer disks
with bigger size?



5.2 SSD won't boot

2012-11-02 Thread Devin Ceartas
hp laptop with Intel SSD won't boot under 5.2 - the problem reported on
screen appears to be the one described here:
http://old.nabble.com/Re%3A-Fwd%3A--mSATA-failure-on-6501-w--OpenBSD-5.0-td32881415.html#a32884546


> ahci0: stopping the port, softreset slot 31 was still active.

> ahci0: failed to reset port during timeout handling, disabling it


Does anyone have a patch to try or is there a way to boot into the full
system starting from a CD or network boot?


-- devin



SSD won't be recognized

2012-11-02 Thread Devin Ceartas
hp laptop with Intel SSD won't boot under 5.2 - the problem reported on screen
appears to be the one described here:
http://old.nabble.com/Re%3A-Fwd%3A--mSATA-failure-on-6501-w--OpenBSD-5.0-td32
881415.html#a32884546

> ahci0: stopping the port, softreset slot 31 was still active.
> ahci0: failed to reset port during timeout handling, disabling it

Does anyone have a patch to try or is there a way to boot into the full system
starting from a CD or network boot?

-- devin