From owner-svn-src-all@FreeBSD.ORG Tue Aug 31 18:58:11 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 03AB61065696 for ; Tue, 31 Aug 2010 18:58:11 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: from mail.garage.freebsd.pl (60.wheelsystems.com [83.12.187.60]) by mx1.freebsd.org (Postfix) with ESMTP id A0BFB8FC31 for ; Tue, 31 Aug 2010 18:58:10 +0000 (UTC) Received: by mail.garage.freebsd.pl (Postfix, from userid 65534) id 7F21245C9B; Tue, 31 Aug 2010 20:58:08 +0200 (CEST) Received: from localhost (chello089077043238.chello.pl [89.77.43.238]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.garage.freebsd.pl (Postfix) with ESMTP id 458E545D8D; Tue, 31 Aug 2010 20:58:01 +0200 (CEST) Date: Tue, 31 Aug 2010 20:57:52 +0200 From: Pawel Jakub Dawidek To: Fabian Keil Message-ID: <20100831185752.GA1932@garage.freebsd.pl> References: <201008311041.o7VAfrAF028012@svn.freebsd.org> <20100831204421.4ad0a99a@r500.local> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline In-Reply-To: <20100831204421.4ad0a99a@r500.local> User-Agent: Mutt/1.4.2.3i X-PGP-Key-URL: http://people.freebsd.org/~pjd/pjd.asc X-OS: FreeBSD 9.0-CURRENT amd64 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on mail.garage.freebsd.pl X-Spam-Level: X-Spam-Status: No, score=-0.6 required=4.5 tests=BAYES_00,RCVD_IN_SORBS_DUL autolearn=no version=3.0.4 Cc: svn-src-all@freebsd.org Subject: Re: svn commit: r212050 - head/cddl/contrib/opensolaris/cmd/zpool X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Aug 2010 18:58:11 -0000 --17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 31, 2010 at 08:44:21PM +0200, Fabian Keil wrote: > Pawel Jakub Dawidek wrote: > > static int > > +is_root_pool(zpool_handle_t *zhp) > > +{ > > + static struct statfs sfs; > > + static char *poolname =3D NULL; > > + static boolean_t stated =3D B_FALSE; >=20 > Why are those variables static? They all seem to be (re)initialized > before first-use in the function. Not really. We enter while () loop only if stated is false and it will be false only for the first call. By having those variables static we statfs(2) the root file system only once. > > + while (!stated) { > > + stated =3D B_TRUE; > > + if (statfs("/", &sfs) =3D=3D -1) { > > + (void) fprintf(stderr, > > + "Unable to stat root file system: %s.\n", > > + strerror(errno)); > > + break; > > + } > > + if (strcmp(sfs.f_fstypename, "zfs") !=3D 0) > > + break; > > + poolname =3D sfs.f_mntfromname; > > + if ((slash =3D strchr(poolname, '/')) !=3D NULL) > > + *slash =3D '\0'; > > + break; > > + } > > + return (poolname !=3D NULL && strcmp(poolname, zpool_get_name(zhp)) = =3D=3D 0); > > +} >=20 > This while "loop" doesn't seem to loop at all, is this intended? Yes. This is a trick to avoid goto. I don't like tricks in code in general, but I hope the code is readable. --=20 Pawel Jakub Dawidek http://www.wheelsystems.com pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! --17pEHd4RhPHOinZp Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iEYEARECAAYFAkx9UK8ACgkQForvXbEpPzS7dQCdFIZ6wn6CO5YwpH7oBq1qQ7j1 j3AAnRKDz8NOiea4PBltE+8JpIvjSzqs =jP5a -----END PGP SIGNATURE----- --17pEHd4RhPHOinZp--