On Tue, Aug 31, 2010 at 08:44:21PM +0200, Fabian Keil wrote:
> Pawel Jakub Dawidek <p...@freebsd.org> wrote:
> >  static int
> > +is_root_pool(zpool_handle_t *zhp)
> > +{
> > +   static struct statfs sfs;
> > +   static char *poolname = NULL;
> > +   static boolean_t stated = B_FALSE;
> 
> 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 = B_TRUE;
> > +           if (statfs("/", &sfs) == -1) {
> > +                   (void) fprintf(stderr,
> > +                       "Unable to stat root file system: %s.\n",
> > +                       strerror(errno));
> > +                   break;
> > +           }
> > +           if (strcmp(sfs.f_fstypename, "zfs") != 0)
> > +                   break;
> > +           poolname = sfs.f_mntfromname;
> > +           if ((slash = strchr(poolname, '/')) != NULL)
> > +                   *slash = '\0';
> > +           break;
> > +   }
> > +   return (poolname != NULL && strcmp(poolname, zpool_get_name(zhp)) == 0);
> > +}
> 
> 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.

-- 
Pawel Jakub Dawidek                       http://www.wheelsystems.com
p...@freebsd.org                           http://www.FreeBSD.org
FreeBSD committer                         Am I Evil? Yes, I Am!

Attachment: pgpzOMlShWybW.pgp
Description: PGP signature

Reply via email to