From: mvs Date: Thu, 2 Feb 2023 09:35:07 +0000 (+0000) Subject: Move the rest of common socket initialization within soalloc(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b8f696365f165a6cd05872e98192e516a8b9333f;p=openbsd Move the rest of common socket initialization within soalloc(). ok visa@ --- diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index f4ef162fb1f..612999623a6 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.299 2023/01/27 21:01:59 mvs Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.300 2023/02/02 09:35:07 mvs Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -112,6 +112,16 @@ const struct filterops soexcept_filtops = { .f_process = filt_soprocess, }; +void klist_soassertlk(void *); +int klist_solock(void *); +void klist_sounlock(void *, int); + +const struct klistops socket_klistops = { + .klo_assertlk = klist_soassertlk, + .klo_lock = klist_solock, + .klo_unlock = klist_sounlock, +}; + #ifndef SOMINCONN #define SOMINCONN 80 #endif /* SOMINCONN */ @@ -148,6 +158,11 @@ soalloc(int wait) return (NULL); rw_init_flags(&so->so_lock, "solock", RWL_DUPOK); refcnt_init(&so->so_refcnt); + klist_init(&so->so_rcv.sb_klist, &socket_klistops, so); + klist_init(&so->so_snd.sb_klist, &socket_klistops, so); + sigio_init(&so->so_sigio); + TAILQ_INIT(&so->so_q0); + TAILQ_INIT(&so->so_q); return (so); } @@ -176,11 +191,6 @@ socreate(int dom, struct socket **aso, int type, int proto) if (prp->pr_type != type) return (EPROTOTYPE); so = soalloc(M_WAIT); - klist_init(&so->so_rcv.sb_klist, &socket_klistops, so); - klist_init(&so->so_snd.sb_klist, &socket_klistops, so); - sigio_init(&so->so_sigio); - TAILQ_INIT(&so->so_q0); - TAILQ_INIT(&so->so_q); so->so_type = type; if (suser(p) == 0) so->so_state = SS_PRIV; @@ -2334,12 +2344,6 @@ klist_sounlock(void *arg, int ls) sounlock(so); } -const struct klistops socket_klistops = { - .klo_assertlk = klist_soassertlk, - .klo_lock = klist_solock, - .klo_unlock = klist_sounlock, -}; - #ifdef DDB void sobuf_print(struct sockbuf *, diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index e37fef4c503..80ac5fc7c01 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.134 2023/01/27 18:46:34 mvs Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.135 2023/02/02 09:35:07 mvs Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -41,7 +41,6 @@ #include #include #include -#include #include /* @@ -213,12 +212,8 @@ sonewconn(struct socket *head, int connstatus, int wait) /* * Inherit watermarks but those may get clamped in low mem situations. */ - if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat)) { - if (persocket) - sounlock(so); - pool_put(&socket_pool, so); - return (NULL); - } + if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat)) + goto fail; so->so_snd.sb_wat = head->so_snd.sb_wat; so->so_snd.sb_lowat = head->so_snd.sb_lowat; so->so_snd.sb_timeo_nsecs = head->so_snd.sb_timeo_nsecs; @@ -226,9 +221,6 @@ sonewconn(struct socket *head, int connstatus, int wait) so->so_rcv.sb_lowat = head->so_rcv.sb_lowat; so->so_rcv.sb_timeo_nsecs = head->so_rcv.sb_timeo_nsecs; - klist_init(&so->so_rcv.sb_klist, &socket_klistops, so); - klist_init(&so->so_snd.sb_klist, &socket_klistops, so); - sigio_init(&so->so_sigio); sigio_copy(&so->so_sigio, &head->so_sigio); soqinsque(head, so, 0); @@ -259,13 +251,7 @@ sonewconn(struct socket *head, int connstatus, int wait) if (error) { soqremque(so, 0); - if (persocket) - sounlock(so); - sigio_free(&so->so_sigio); - klist_free(&so->so_rcv.sb_klist); - klist_free(&so->so_snd.sb_klist); - pool_put(&socket_pool, so); - return (NULL); + goto fail; } if (connstatus) { @@ -280,6 +266,16 @@ sonewconn(struct socket *head, int connstatus, int wait) sounlock(so); return (so); + +fail: + if (persocket) + sounlock(so); + sigio_free(&so->so_sigio); + klist_free(&so->so_rcv.sb_klist); + klist_free(&so->so_snd.sb_klist); + pool_put(&socket_pool, so); + + return (NULL); } void diff --git a/sys/sys/event.h b/sys/sys/event.h index d5dd8d8da27..ec555b2b6df 100644 --- a/sys/sys/event.h +++ b/sys/sys/event.h @@ -1,4 +1,4 @@ -/* $OpenBSD: event.h,v 1.67 2022/03/31 01:41:22 millert Exp $ */ +/* $OpenBSD: event.h,v 1.68 2023/02/02 09:35:07 mvs Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon @@ -286,7 +286,6 @@ struct timespec; extern const struct filterops sig_filtops; extern const struct filterops dead_filtops; -extern const struct klistops socket_klistops; extern void kqpoll_init(unsigned int); extern void kqpoll_done(unsigned int);