From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from imap.gmail.com [173.194.76.109] by localhost with POP3 (fetchmail-6.3.26) for (single-drop); Thu, 23 May 2024 12:05:35 +0200 (CEST) Received: by 2002:a05:6a11:2489:b0:55f:c3c0:ed08 with SMTP id sg9csp1202697pxb; Thu, 23 May 2024 03:05:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVG/7xfbcsL7Z1P5FyVEMJVFZtKPb8yG3HaQS/JLEimK96l4i/APX4ehre37KsSh4YCALT1krP6t3VHGiCq9RupsBCVON6ni/Y= X-Google-Smtp-Source: AGHT+IHpUzCmjaEAAl+KqKUEEi+9b+mmhmQYMqNEBinJnBLb1lhihq3hMh2qTqhP92VpPcdBbSV7 X-Received: by 2002:a05:622a:1109:b0:43a:e995:f1a4 with SMTP id d75a77b69052e-43f9e0d8ca1mr52131341cf.30.1716458709332; Thu, 23 May 2024 03:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716458709; cv=none; d=google.com; s=arc-20160816; b=VuzkFLRSA13EuvyFwNDQN0gsUdnWmYLHi0k6tlADYUcaokote4gjTQcT3P4lmpmClb QN19ZMSW36UChvX2EaDiecWn8A92nc7W+H/0/c9Nl7ePyIoWt/+g0xwK6bmxakVbtpK+ 0eVrSoNf/dYzDZ1f6w1PVcIYYeA8FrBmhUEgnZgQYhDBR+X9870wtp5I/hIoASUth2OQ DF1DsgLaKKYH+lQ3x8ZAj79jasOCgUQQ2vHo4kBu6E7Lj0I5+uUbft31vuRG4BzPRZ79 ca1qJ7jKT8TwxysGrf2z8GAMwZkPR7VgW8/dviP/e+8uZoOMFZHvZSWskUc0dgN9h348 FH5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:user-agent:in-reply-to:mime-version:references :message-id:subject:cc:to:from:date:delivered-to; bh=AbvMXikPc5ua7iemq1bc/u2dJhZYpiudpoeRDXKyG34=; fh=sa22/YzBg7gBlP1vWMAMO0ID50cEEzmrnuJNDeV9zT4=; b=NOhJiQIP7NkhGbBke4cVdk334L0XLHIjkX5iuzKFYd34SqEtu5Ffd+kgILoqL/WxH+ sdB87B3uC2YQKwzCNqvbA1SRUikn/dzKH4ofXEH2HOIZzrvCav3UYs2SjxRMHUXF3u0p cACiMbeQCFLrh0VwD8cQWE+/2LroyWtOyRM6b7UBm1iSMhD2FI2W3tTgFIRlBu0Ej3ZK itWhCWV3Hy6/ZO0plILVPjoZMsfFaZ5Ll6cmI464yBTjEhxAXjig3BT4xFQJipVbO3q/ 4x3PepTPanoFERRPqxtFYuxa1r+ZUBpb5b1SkzvLY+CDVWet3c2qvIgijQhPNsNhWxW4 ShWQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; gateway.spf=pass (google.com: domain gapps.redhat.com configured 170.10.128.131 as internal address) smtp.mailfrom=rjones@redhat.com smtp.remote-ip=170.10.128.131 policy.d=gapps.redhat.com Return-Path: Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com. [170.10.128.131]) by mx.google.com with ESMTPS id d75a77b69052e-43df54a1271si53679871cf.60.2024.05.23.03.05.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 03:05:09 -0700 (PDT) Received-SPF: pass (google.com: domain gapps.redhat.com configured 170.10.128.131 as internal address) Authentication-Results: mx.google.com; gateway.spf=pass (google.com: domain gapps.redhat.com configured 170.10.128.131 as internal address) smtp.mailfrom=rjones@redhat.com smtp.remote-ip=170.10.128.131 policy.d=gapps.redhat.com Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-NrjQGVA6N8GpM_PR6oTwQg-1; Thu, 23 May 2024 06:05:07 -0400 X-MC-Unique: NrjQGVA6N8GpM_PR6oTwQg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7B93385A58C for ; Thu, 23 May 2024 10:05:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 779FBC15BF4; Thu, 23 May 2024 10:05:07 +0000 (UTC) Received: from localhost (unknown [10.42.28.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id B85AFC15BED; Thu, 23 May 2024 10:05:06 +0000 (UTC) Date: Thu, 23 May 2024 11:05:06 +0100 From: "Richard W.M. Jones" To: Stefano Brivio Cc: passt-dev@passt.top, David Gibson , Minxi Hou Subject: Re: [PATCH 4/8] tap: Split tap_sock_unix_init() into opening and listening parts Message-ID: <20240523100506.GT4345@redhat.com> References: <20240522205911.261325-1-sbrivio@redhat.com> <20240522205911.261325-5-sbrivio@redhat.com> MIME-Version: 1.0 In-Reply-To: <20240522205911.261325-5-sbrivio@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: On Wed, May 22, 2024 at 10:59:07PM +0200, Stefano Brivio wrote: > We'll need to open and bind the socket a while before listening to it, > so split that into two different functions. No functional changes > intended. > > Signed-off-by: Stefano Brivio > --- > tap.c | 39 +++++++++++++++++++++++++++------------ > 1 file changed, 27 insertions(+), 12 deletions(-) > > diff --git a/tap.c b/tap.c > index cb6df5a..c9f580e 100644 > --- a/tap.c > +++ b/tap.c > @@ -1095,14 +1095,14 @@ restart: > } > > /** > - * tap_sock_unix_init() - Create and bind AF_UNIX socket, listen for connection > - * @c: Execution context > + * tap_sock_unix_open() - Create and bind AF_UNIX socket > + * @sock_path: Socket path. If empty, set on return (UNIX_SOCK_PATH as prefix) > + * > + * Return: socket descriptor on success, won't return on failure > */ > -static void tap_sock_unix_init(struct ctx *c) > +static int tap_sock_unix_open(char *sock_path) > { > int fd = socket(AF_UNIX, SOCK_STREAM, 0); > - union epoll_ref ref = { .type = EPOLL_TYPE_TAP_LISTEN }; > - struct epoll_event ev = { 0 }; > struct sockaddr_un addr = { > .sun_family = AF_UNIX, > }; > @@ -1115,8 +1115,8 @@ static void tap_sock_unix_init(struct ctx *c) > char *path = addr.sun_path; > int ex, ret; > > - if (*c->sock_path) > - memcpy(path, c->sock_path, UNIX_PATH_MAX); > + if (*sock_path) > + memcpy(path, sock_path, UNIX_PATH_MAX); > else > snprintf(path, UNIX_PATH_MAX - 1, UNIX_SOCK_PATH, i); > > @@ -1127,7 +1127,7 @@ static void tap_sock_unix_init(struct ctx *c) > ret = connect(ex, (const struct sockaddr *)&addr, sizeof(addr)); > if (!ret || (errno != ENOENT && errno != ECONNREFUSED && > errno != EACCES)) { > - if (*c->sock_path) > + if (*sock_path) > die("Socket path %s already in use", path); > > close(ex); > @@ -1137,7 +1137,7 @@ static void tap_sock_unix_init(struct ctx *c) > > unlink(path); > if (!bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) || > - *c->sock_path) > + *sock_path) > break; > } > > @@ -1145,17 +1145,31 @@ static void tap_sock_unix_init(struct ctx *c) > die("UNIX socket bind: %s", strerror(errno)); > > info("UNIX domain socket bound at %s\n", addr.sun_path); > + if (!*sock_path) > + memcpy(sock_path, addr.sun_path, UNIX_PATH_MAX); > + > + return fd; > +} > + > +/** > + * tap_sock_unix_init() - Start listening for connections on AF_UNIX socket > + * @c: Execution context > + */ > +static void tap_sock_unix_init(struct ctx *c) > +{ > + union epoll_ref ref = { .type = EPOLL_TYPE_TAP_LISTEN }; > + struct epoll_event ev = { 0 }; > > - listen(fd, 0); > + listen(c->fd_tap_listen, 0); > > - ref.fd = c->fd_tap_listen = fd; > + ref.fd = c->fd_tap_listen; > ev.events = EPOLLIN | EPOLLET; > ev.data.u64 = ref.u64; > epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap_listen, &ev); > > info("You can now start qemu (>= 7.2, with commit 13c6be96618c):"); > info(" kvm ... -device virtio-net-pci,netdev=s -netdev stream,id=s,server=off,addr.type=unix,addr.path=%s", > - addr.sun_path); > + c->sock_path); > info("or qrap, for earlier qemu versions:"); > info(" ./qrap 5 kvm ... -net socket,fd=5 -net nic,model=virtio"); > } > @@ -1304,6 +1318,7 @@ void tap_sock_init(struct ctx *c) > } > > if (c->mode == MODE_PASST) { > + c->fd_tap_listen = tap_sock_unix_open(c->sock_path); > tap_sock_unix_init(c); > > /* In passt mode, we don't know the guest's MAC address until it > -- Looks like a neutral factoring, so: Reviewed-by: Richard W.M. Jones Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW