Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Jun 2010 18:52:26 +0200
From:      David Naylor <naylor.b.david@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   [RFC] mtree improvements
Message-ID:  <201006251852.30302.naylor.b.david@gmail.com>

next in thread | raw e-mail | index | archive | help
--nextPart42614793.5JcOpxEqdd
Content-Type: multipart/mixed;
  boundary="Boundary-01=_K7NJM4EmdaaEL6R"
Content-Transfer-Encoding: 7bit


--Boundary-01=_K7NJM4EmdaaEL6R
Content-Type: Text/Plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi,

I've created a patch that increases the performance of mtree.  This is of=20
particular use during a port install.  In an extreme case I have experience=
d a=20
~20% increase [1]. =20

=46or a full discussion see PR bin/143732.  This arose out of [2] where I=20
experienced the increase. =20

=46or your convenience I have attached the patch. =20

Please review this patch and if it is acceptable, commit it. =20

Regards,

David

1] http://markmail.org/message/iju3l6hyv7s7emrb
2] http://markmail.org/message/gfztjpszl5dozzii

--Boundary-01=_K7NJM4EmdaaEL6R
Content-Type: text/x-patch;
  charset="ISO-8859-1";
  name="mtree.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="mtree.diff"


=2D-- /usr/src/usr.sbin/mtree/verify.c	2010-02-07 15:07:28.000000000 +0200
+++ verify.c	2010-02-07 15:04:10.000000000 +0200
@@ -50,17 +50,23 @@
 static NODE *root;
 static char path[MAXPATHLEN];
=20
=2Dstatic void	miss(NODE *, char *);
+static int	miss(NODE *, char *);
+static int	check(NODE *, char *);
 static int	vwalk(void);
=20
 int
 mtree_verifyspec(FILE *fi)
 {
=2D	int rval;
+	int rval =3D 0;
=20
 	root =3D mtree_readspec(fi);
=2D	rval =3D vwalk();
=2D	miss(root, path);
+	/*
+	 * No need to walk entire tree if we are only updating the structure
+	 * and extra files are ignored.
+	 */
+	if (!(uflag && eflag))
+		rval =3D vwalk();
+	rval |=3D miss(root, path);
 	return (rval);
 }
=20
@@ -155,15 +161,47 @@
 	return (rval);
 }
=20
=2Dstatic void
+static int
+check(NODE *p, char *tail)
+{
+	FTSENT fts;
+	struct stat fts_stat;
+
+	strcpy(tail, p->name);
+
+	/*
+	 * It is assumed that compare() only requires fts_accpath and fts_statp
+	 * fields in the FTSENT structure.
+	 */
+	fts.fts_accpath =3D path;
+	fts.fts_statp =3D &fts_stat;
+
+	if (stat(path, fts.fts_statp))
+		return (0);
+
+	p->flags |=3D F_VISIT;
+	if ((p->flags & F_NOCHANGE) =3D=3D 0 && compare(p->name, p, &fts))
+		return (MISMATCHEXIT);
+	else
+		return (0);
+
+	/*
+	 * tail is not restored to '\0' as the next time tail (or path) is used
+	 * is with a strcpy (thus overriding the '\0').  See +19 lines below.
+	 */
+}
+
+static int
 miss(NODE *p, char *tail)
 {
 	int create;
 	char *tp;
 	const char *type, *what;
=2D	int serr;
+	int serr, rval =3D 0;
=20
 	for (; p; p =3D p->next) {
+		if (uflag && eflag)
+			rval |=3D check(p, tail);
 		if (p->flags & F_OPT && !(p->flags & F_VISIT))
 			continue;
 		if (p->type !=3D F_DIR && (dflag || p->flags & F_VISIT))
@@ -256,4 +294,5 @@
 			(void)printf("%s: file flags not set: %s\n",
 			    path, strerror(errno));
 	}
+	return (rval);
 }



--Boundary-01=_K7NJM4EmdaaEL6R--

--nextPart42614793.5JcOpxEqdd
Content-Type: application/pgp-signature; name=signature.asc 
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEABECAAYFAkwk3s4ACgkQUaaFgP9pFrLcYQCfaS+oZhomdmcQBGZLHNnR+e12
uVkAoIBLLnexJ0tjEgsxSnvF/ooToQMQ
=57B8
-----END PGP SIGNATURE-----

--nextPart42614793.5JcOpxEqdd--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006251852.30302.naylor.b.david>