cooker: Track directories searched for bbappend/bb files
PATCH 1/4 cooker: Track directories searched for bbappend/bb files
Some of the directories searched by BBFILES are not currently being added to the inotify watch list. This can mean that added append files are not noticed leading to misleading metadata results when using BB_SERVER_TIMEOUT != 0.
We use glob to expand the BBFILES references and without writing our own implentation, figuring out the directories it searches is hard. We use some horrible hacks here to intecept the listdir calls, I'm open to better ways to handle this but this does ensure we have the right watches set.
--- lib/bb/cooker.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
lib/bb/cooker.py +21 -3
@@ -1192,7 +1192,7 @@ class BBCooker: bf = os.path.abspath(bf) self.collection = CookerCollectFiles(self.bbfile_config_priorities) - filelist, masked = self.collection.collect_bbfiles(self.data, self.data) + filelist, masked, searchdirs = self.collection.collect_bbfiles(self.data, self.data) try: os.stat(bf) bf = os.path.abspath(bf)
@@ -1482,7 +1482,11 @@ class BBCooker: self.recipecaches[mc].ignored_dependencies.add(dep) self.collection = CookerCollectFiles(self.bbfile_config_priorities) - (filelist, masked) = self.collection.collect_bbfiles(self.data, self.data) + (filelist, masked, searchdirs) = self.collection.collect_bbfiles(self.data, self.data) + + # Add inotify watches for directories searched for bb/bbappend files + for dirent in searchdirs: + self.add_filewatch([[dirent]]) self.parser = CookerParser(self, filelist, masked) self.parsecache_valid = True
@@ -1654,6 +1658,18 @@ class CookerCollectFiles(object): collectlog.error("no recipe files to build, check your BBPATH and BBFILES?") bb.event.fire(CookerExit(), eventdata) + # We need to track where we look so that we can add inotify watches. There + # is no nice way to do this, this is horrid. We intercept the os.listdir() + # calls while we run glob(). + origlistdir = os.listdir + searchdirs = [] + + def ourlistdir(d): + searchdirs.append(d) + return origlistdir(d) + + os.listdir = ourlistdir + # Can't use set here as order is important newfiles = [] for f in files:
@@ -1671,6 +1687,8 @@ class CookerCollectFiles(object): if g not in newfiles: newfiles.append(g) + os.listdir = origlistdir + bbmask = config.getVar('BBMASK') if bbmask:
@@ -1729,7 +1747,7 @@ class CookerCollectFiles(object): topfile = bbfile_seen[base] self.overlayed[topfile].append(f) - return (bbfiles, masked) + return (bbfiles, masked, searchdirs) def get_file_appends(self, fn): """
Signature · 1 line
2.7.4
PATCH 2/4 cooker: Ensure we handle inotify before running the next command
The inotify watch events are handled "at idle" which could in theory mean a command could run before any preceeding inotify events have been processed. This leads to a theoretical race window where those events may have a signficicant effect on the command.
Add a mechanism to allow us to ensure all pending events are processed before running commands.
--- lib/bb/command.py | 2 ++ lib/bb/cooker.py | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-)
lib/bb/command.py +2 -0
@@ -78,6 +78,7 @@ class Command: if not hasattr(command_method, 'readonly') or False == getattr(command_method, 'readonly'): return None, "Not able to execute not readonly commands in readonly mode" try: + self.cooker.process_inotify_updates() if getattr(command_method, 'needconfig', False): self.cooker.updateCacheSync() result = command_method(self, commandline)
@@ -98,6 +99,7 @@ class Command: def runAsyncCommand(self): try: + self.cooker.process_inotify_updates() if self.cooker.state in (bb.cooker.state.error, bb.cooker.state.shutdown, bb.cooker.state.forceshutdown): # updateCache will trigger a shutdown of the parser # and then raise BBHandledException triggering an exit
lib/bb/cooker.py +10 -7
@@ -205,15 +205,11 @@ class BBCooker: self.inotify_modified_files = [] - def _process_inotify_updates(server, notifier_list, abort): - for n in notifier_list: - if n.check_events(timeout=0): - # read notified events and enqeue them - n.read_events() - n.process_events() + def _process_inotify_updates(server, cooker, abort): + cooker.process_inotify_updates() return 1.0 - self.configuration.server_register_idlecallback(_process_inotify_updates, [self.confignotifier, self.notifier]) + self.configuration.server_register_idlecallback(_process_inotify_updates, self) # TOSTOP must not be set or our children will hang when they output try:
@@ -241,6 +237,13 @@ class BBCooker: os.write(readypipe, b"ready") os.close(readypipe) + def process_inotify_updates(self): + for n in [self.confignotifier, self.notifier]: + if n.check_events(timeout=0): + # read notified events and enqeue them + n.read_events() + n.process_events() + def config_notifications(self, event): if event.maskname == "IN_Q_OVERFLOW": bb.warn("inotify event queue overflowed, invalidating caches.")
Signature · 1 line
2.7.4
PATCH 3/4 cooker: Improve inotify overflow handling
In reply to Richard PurdieAdd a proper function for clearing the mtime cache. Clean up the inotify event overflow case to err on the side of caution and clear any potentially now out of sync caches.
--- lib/bb/cooker.py | 5 ++++- lib/bb/parse/__init__.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-)
lib/bb/cooker.py +4 -1
@@ -189,7 +189,7 @@ class BBCooker: # If being called by something like tinfoil, we need to clean cached data # which may now be invalid - bb.parse.__mtime_cache = {} + bb.parse.clear_cache() bb.parse.BBHandler.cached_statements = {} self.ui_cmdline = None
@@ -247,7 +247,9 @@ class BBCooker: def config_notifications(self, event): if event.maskname == "IN_Q_OVERFLOW": bb.warn("inotify event queue overflowed, invalidating caches.") + self.parsecache_valid = False self.baseconfig_valid = False + bb.parse.clear_cache() return if not event.pathname in self.configwatcher.bbwatchedfiles: return
@@ -259,6 +261,7 @@ class BBCooker: if event.maskname == "IN_Q_OVERFLOW": bb.warn("inotify event queue overflowed, invalidating caches.") self.parsecache_valid = False + bb.parse.clear_cache() return if not event.pathname in self.inotify_modified_files: self.inotify_modified_files.append(event.pathname)
lib/bb/parse/__init__.py +4 -0
@@ -84,6 +84,10 @@ def update_cache(f): logger.debug(1, "Updating mtime cache for %s" % f) update_mtime(f) +def clear_cache(): + global __mtime_cache + __mtime_cache = {} + def mark_dependency(d, f): if f.startswith('./'): f = "%s/%s" % (os.getcwd(), f[2:])
Signature · 1 line
2.7.4
PATCH 4/4 cooker: Ignore common bitbake files for the parse cache invalidation
In reply to Richard PurdieWrites to the cookerdaemon log and/or the lockfile were meaning the parser cache was always being invalidated and reparsed. This is unnecessary so spot accesses to these two common cases and ignore the files from a reparse perspective.
This doesn't remove many sources of reparse but does improve several common cases.
--- lib/bb/cooker.py | 3 +++ 1 file changed, 3 insertions(+)
lib/bb/cooker.py +3 -0
@@ -263,6 +263,9 @@ class BBCooker: self.parsecache_valid = False bb.parse.clear_cache() return + if event.pathname.endswith("bitbake-cookerdaemon.log") \ + or event.pathname.endswith("bitbake.lock"): + return if not event.pathname in self.inotify_modified_files: self.inotify_modified_files.append(event.pathname) self.parsecache_valid = False
Signature · 1 line
2.7.4