From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from <gentoo-commits+bounces-345220-garchives=archives.gentoo.org@lists.gentoo.org>) id 1QLRJW-000434-EI for garchives@archives.gentoo.org; Sun, 15 May 2011 02:44:14 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2C9581C002; Sun, 15 May 2011 02:44:07 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id CC8B11C002 for <gentoo-commits@lists.gentoo.org>; Sun, 15 May 2011 02:44:06 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2104E1B4061 for <gentoo-commits@lists.gentoo.org>; Sun, 15 May 2011 02:44:06 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 823DC45B46 for <gentoo-commits@lists.gentoo.org>; Sun, 15 May 2011 02:44:05 +0000 (UTC) From: "Zac Medico" <zmedico@gentoo.org> To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org> Message-ID: <39b034d11b8a3118e8c1cfc6f6d06df43e5efa35.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/dbapi/vartree.py X-VCS-Directories: pym/portage/dbapi/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 39b034d11b8a3118e8c1cfc6f6d06df43e5efa35 Date: Sun, 15 May 2011 02:44:05 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 50c307db570b07dbcf21b9e702c970fd commit: 39b034d11b8a3118e8c1cfc6f6d06df43e5efa35 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Sun May 15 02:43:12 2011 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Sun May 15 02:43:12 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D39b034d1 vardbapi: add reentrant _fs_lock/unlock methods --- pym/portage/dbapi/vartree.py | 65 +++++++++++++++++++++++++++---------= ----- 1 files changed, 43 insertions(+), 22 deletions(-) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index d190566..a2e38f6 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -140,6 +140,10 @@ class vardbapi(dbapi): self._lock =3D None self._lock_count =3D 0 =20 + self._conf_mem_file =3D self._eroot + CONFIG_MEMORY_FILE + self._fs_lock_obj =3D None + self._fs_lock_count =3D 0 + if vartree is None: vartree =3D portage.db[self.root]["vartree"] self.vartree =3D vartree @@ -210,6 +214,28 @@ class vardbapi(dbapi): unlockdir(self._lock) self._lock =3D None =20 + def _fs_lock(self): + """ + Acquire a reentrant lock, blocking, for cooperation with concurrent + processes. + """ + if self._fs_lock_count < 1: + if self._fs_lock_obj is not None: + raise AssertionError("already locked") + self._fs_lock_obj =3D lockfile(self._conf_mem_file) + self._fs_lock_count +=3D 1 + + def _fs_unlock(self): + """ + Release a lock, decrementing the recursion level. + """ + if self._fs_lock_count <=3D 1: + if self._fs_lock_obj is None: + raise AssertionError("not locked") + unlockfile(self._fs_lock_obj) + self._fs_lock_obj =3D None + self._fs_lock_count -=3D 1 + def _bump_mtime(self, cpv): """ This is called before an after any modifications, so that consumers @@ -1680,12 +1706,11 @@ class dblink(object): showMessage(_("!!! FAILED prerm: %s\n") % retval, level=3Dlogging.ERROR, noiselevel=3D-1) =20 - conf_mem_file =3D os.path.join(self._eroot, CONFIG_MEMORY_FILE) - conf_mem_lock =3D lockfile(conf_mem_file) + self.vartree.dbapi._fs_lock() try: - self._unmerge_pkgfiles(pkgfiles, others_in_slot, conf_mem_file) + self._unmerge_pkgfiles(pkgfiles, others_in_slot) finally: - unlockfile(conf_mem_lock) + self.vartree.dbapi._fs_unlock() self._clear_contents_cache() =20 if myebuildpath: @@ -1795,15 +1820,14 @@ class dblink(object): =20 # Lock the config memory file to prevent symlink creation # in merge_contents from overlapping with env-update. - conf_mem_file =3D os.path.join(self._eroot, CONFIG_MEMORY_FILE) - conf_mem_lock =3D lockfile(conf_mem_file) + self.vartree.dbapi._fs_lock() try: env_update(target_root=3Dself.settings['ROOT'], prev_mtimes=3Dldpath_mtimes, contents=3Dcontents, env=3Dself.settings.environ(), writemsg_level=3Dself._display_merge) finally: - unlockfile(conf_mem_lock) + self.vartree.dbapi._fs_unlock() =20 return os.EX_OK =20 @@ -1826,7 +1850,7 @@ class dblink(object): log_path=3Dlog_path, background=3Dbackground, level=3Dlevel, noiselevel=3Dnoiselevel) =20 - def _unmerge_pkgfiles(self, pkgfiles, others_in_slot, conf_mem_file): + def _unmerge_pkgfiles(self, pkgfiles, others_in_slot): """ =09 Unmerges the contents of a package from the liveFS @@ -1862,7 +1886,7 @@ class dblink(object): dest_root =3D self._eroot dest_root_len =3D len(dest_root) - 1 =20 - cfgfiledict =3D grabdict(conf_mem_file) + cfgfiledict =3D grabdict(self.vartree.dbapi._conf_mem_file) stale_confmem =3D [] =20 unmerge_orphans =3D "unmerge-orphans" in self.settings.features @@ -2112,7 +2136,7 @@ class dblink(object): if stale_confmem: for filename in stale_confmem: del cfgfiledict[filename] - writedict(cfgfiledict, conf_mem_file) + writedict(cfgfiledict, self.vartree.dbapi._conf_mem_file) =20 #remove self from vartree database so that our own virtual gets zapped= if we're the last node self.vartree.zap(self.mycpv) @@ -3342,10 +3366,9 @@ class dblink(object): self.updateprotect() =20 #if we have a file containing previously-merged config file md5sums, g= rab it. - conf_mem_file =3D os.path.join(self._eroot, CONFIG_MEMORY_FILE) - conf_mem_lock =3D lockfile(conf_mem_file) + self.vartree.dbapi._fs_lock() try: - cfgfiledict =3D grabdict(conf_mem_file) + cfgfiledict =3D grabdict(self.vartree.dbapi._conf_mem_file) if "NOCONFMEM" in self.settings: cfgfiledict["IGNORE"]=3D1 else: @@ -3360,12 +3383,11 @@ class dblink(object): cfgfiledict["IGNORE"] =3D 1 break =20 - rval =3D self._merge_contents(srcroot, destroot, cfgfiledict, - conf_mem_file) + rval =3D self._merge_contents(srcroot, destroot, cfgfiledict) if rval !=3D os.EX_OK: return rval finally: - unlockfile(conf_mem_lock) + self.vartree.dbapi._fs_unlock() =20 # These caches are populated during collision-protect and the data # they contain is now invalid. It's very important to invalidate @@ -3573,8 +3595,7 @@ class dblink(object): =20 # Lock the config memory file to prevent symlink creation # in merge_contents from overlapping with env-update. - conf_mem_file =3D os.path.join(self._eroot, CONFIG_MEMORY_FILE) - conf_mem_lock =3D lockfile(conf_mem_file) + self.vartree.dbapi._fs_lock() try: #update environment settings, library paths. DO NOT change symlinks. env_update(makelinks=3D(not downgrade), @@ -3582,7 +3603,7 @@ class dblink(object): contents=3Dcontents, env=3Dself.settings.environ(), writemsg_level=3Dself._display_merge) finally: - unlockfile(conf_mem_lock) + self.vartree.dbapi._fs_unlock() =20 # For gcc upgrades, preserved libs have to be removed after the # the library path has been updated. @@ -3610,7 +3631,7 @@ class dblink(object): =20 return backup_p =20 - def _merge_contents(self, srcroot, destroot, cfgfiledict, conf_mem_file= ): + def _merge_contents(self, srcroot, destroot, cfgfiledict): =20 cfgfiledict_orig =3D cfgfiledict.copy() =20 @@ -3672,9 +3693,9 @@ class dblink(object): # write out our collection of md5sums if cfgfiledict !=3D cfgfiledict_orig: cfgfiledict.pop("IGNORE", None) - ensure_dirs(os.path.dirname(conf_mem_file), + ensure_dirs(os.path.dirname(self.vartree.dbapi._conf_mem_file), gid=3Dportage_gid, mode=3D0o2750, mask=3D0o2) - writedict(cfgfiledict, conf_mem_file) + writedict(cfgfiledict, self.vartree.dbapi._conf_mem_file) =20 return os.EX_OK =20