From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id C34E65A0287 for ; Tue, 16 May 2023 06:06:58 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4QL2k45ttjz4x46; Tue, 16 May 2023 14:06:52 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1684210012; bh=D+Wb3bFPnTqW5vxc8yjVXkzxjoQwYvUW09tWDL5sK4U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=apGjXb+3WWl4Sy+Vtyk0xkwayfcro7nduZfGen+A0dz8vPabxQ6Kr9IDBuyBnl7C3 ppNVS9CPKgG5ml3rl7B1RA0nrX9Q5xw5wNbFIKsoyiBlozpsGFKA/Ox1nzgTOhJnwx rl0acR4u5uMf9OYWouZV0tZOQfjWwOlPXErhZFDQ= Date: Tue, 16 May 2023 13:24:01 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 02/10] pasta: Improve error handling on failure to join network namespace Message-ID: References: <20230514181415.313420-1-sbrivio@redhat.com> <20230514181415.313420-3-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="vWGSY/MT1LxERBE7" Content-Disposition: inline In-Reply-To: <20230514181415.313420-3-sbrivio@redhat.com> Message-ID-Hash: XVILJXWWXODGHUL27AFCD5RYNTG2GFWC X-Message-ID-Hash: XVILJXWWXODGHUL27AFCD5RYNTG2GFWC X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, Callum Parsey , me@yawnt.com, lemmi@nerd2nerd.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --vWGSY/MT1LxERBE7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, May 14, 2023 at 08:14:07PM +0200, Stefano Brivio wrote: > In pasta_wait_for_ns(), open() failing with ENOENT is expected: we're > busy-looping until the network namespace appears. But any other > failure is not something we're going to recover from: return right > away if we don't get either success or ENOENT. >=20 > Now that pasta_wait_for_ns() can actually fail, handle that in > pasta_start_ns() by reporting the issue and exiting. >=20 > Looping on EPERM, when pasta doesn't actually have the permissions to > join a given namespace, isn't exactly a productive thing to do. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson Also makes sense regardless of the rest of the series. > --- > pasta.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) >=20 > diff --git a/pasta.c b/pasta.c > index 3a4d704..2fa0168 100644 > --- a/pasta.c > +++ b/pasta.c > @@ -94,8 +94,11 @@ static int pasta_wait_for_ns(void *arg) > char ns[PATH_MAX]; > =20 > snprintf(ns, PATH_MAX, "/proc/%i/ns/net", pasta_child_pid); > - do > - while ((c->pasta_netns_fd =3D open(ns, flags)) < 0); > + while ((c->pasta_netns_fd =3D open(ns, flags)) < 0) { > + if (errno !=3D ENOENT) > + return 0; > + } > + > while (setns(c->pasta_netns_fd, CLONE_NEWNET) && > !close(c->pasta_netns_fd)); > =20 > @@ -252,6 +255,8 @@ void pasta_start_ns(struct ctx *c, uid_t uid, gid_t g= id, > } > =20 > NS_CALL(pasta_wait_for_ns, c); > + if (c->pasta_netns_fd < 0) > + die("Failed to join network namespace"); > } > =20 > /** --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --vWGSY/MT1LxERBE7 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmRi90sACgkQzQJF27ox 2Gf9oRAAm7wJiCNV6d4q9uKtimYqjFp4sl4YpvEX6a/DvXmrYnBD7J37stt9Ks7X 29H8X91K0kTAF4LIHPF84suMg2nGbMgtlrsdNZjSbkWnMDW0ZkVeyCzwplj7LhGq WNj+SUsqv4ELDQdt1uMwzqW71RJWiJJmpfCCGBBt3yc7eKnuWh1YWpOBgBzgUor5 LTz/CFWnynTXk9OkkGJLl+S/mjgGeQ0ETa1jXDYQy2E2I758OrNwd4glDx2FKq9R vVp10LEbE8ePfgBg1CVpfD0sfVkMQnbHXRClBmmUkc3pQEiTg8ZUsLuh7v7qG5cJ c+IEJMjO2vb5AWeIsdREbkMTQFY9E3obrppJEQeZ31FNUyWIXPeRQ/wEiAdS56W9 dxhvShzhIrFZ0TPZ3qos6BBcwVAr/hdC+MB1qwvQSzfPBristXLDFzkegAgfi+Vu SO92teLV8aDKBY3K1YhEBj5onJ4WJMkrBmmjhuHyz2sJ9gIDEhWcjiNpgfTAFTLB Jq8uWFGGKuRSy7TZN7Q5f5LWYLTJVlfOiSEcwWa3mkd3a7dVxweoO4wIBptin53M UwQdU9gHvbJhaLCw+z7rHuZ0hRels5HfqV0KhTVsnj35xP83JS4XzB1XGwOAsqVd 6KkOIonfdrqARAV3s9I96eE0N/ZyRhX68gu9tbQ+baB/a+s4g44= =84dO -----END PGP SIGNATURE----- --vWGSY/MT1LxERBE7--