lib: Drop inotify support and replace with mtime checks
PATCH 1/1 lib: Drop inotify support and replace with mtime checks
With the flush in serverlog() removed and a memory resident bitbake with a 60s timeout, the following could fail in strange ways:
rm bitbake-cookerdaemon.log
bitbake-layers add-layer ../meta-virtualization/ bitbake-layers add-layer ../meta-openembedded/meta-oe/ bitbake -m
specifically that it might error adding meta-oe with an error related to meta-virt.
This clearly shows that whilst bblayers.conf was modified, bitbake was not recognising that. This would fit with the random autobuilder issues seen when the serverlog flush() call was removed.
The issue appears to be that you have no way to "sync()" the inotify events with the command stream coming over the socket. There is no way to know if there are changes in the IO queue which bitbake needs to wait for before proceeding with the next command.
I did experiment with os.sync() and fsync on the inotify fd, however nothing addressed the issue. Since it is extremely important we have accurate cache data, the only realistic thing to do is to switch to stat() calls and check mtime.
For bitbake commands, this is straightforward since we can revalidate the cache upon new connections/commands. For tinfoil this is problematic and we need to introduce and explict command "revalidateCaches" that the code can use to force bitbake to re-check it's cache validity. I've exposed this through tinfoil with a new "modified_files" function.
So, this patch:
a) drops inotify support within bitbake's cooker/server and switch to using mtime
b) requires a new function call in tinfoil when metadata has been modified
--- lib/bb/command.py | 8 +- lib/bb/cooker.py | 179 +++++++++------------------------------ lib/bb/parse/__init__.py | 8 ++ lib/bb/server/process.py | 6 -- lib/bb/tinfoil.py | 6 ++ lib/bblayers/action.py | 6 ++ 6 files changed, 65 insertions(+), 148 deletions(-)
lib/bb/command.py +5 -3
@@ -85,8 +85,6 @@ class Command: if not hasattr(command_method, 'readonly') or not getattr(command_method, 'readonly'): return None, "Not able to execute not readonly commands in readonly mode" try: - if command != "ping": - self.cooker.process_inotify_updates_apply() if getattr(command_method, 'needconfig', True): self.cooker.updateCacheSync() result = command_method(self, commandline)
@@ -110,7 +108,6 @@ class Command: def runAsyncCommand(self, _, process_server, halt): try: - self.cooker.process_inotify_updates_apply() 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
@@ -310,6 +307,11 @@ class CommandsSync: return ret getLayerPriorities.readonly = True + def revalidateCaches(self, command, params): + """Called by UI clients when metadata may have changed""" + command.cooker.revalidateCaches() + parseConfiguration.needconfig = False + def getRecipes(self, command, params): try: mc = params[0]
lib/bb/cooker.py +40 -139
266 lines not on this page · raw message
lib/bb/parse/__init__.py +8 -0
@@ -60,6 +60,14 @@ def cached_mtime_noerror(f): return 0 return __mtime_cache[f] +def check_mtime(f, mtime): + try: + current_mtime = os.stat(f)[stat.ST_MTIME] + __mtime_cache[f] = current_mtime + except OSError: + current_mtime = 0 + return current_mtime == mtime + def update_mtime(f): try: __mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
lib/bb/server/process.py +0 -6
@@ -411,12 +411,6 @@ class ProcessServer(): nextsleep = 0.1 fds = [] - try: - self.cooker.process_inotify_updates() - except Exception as exc: - serverlog("Exception %s in inofify updates broke the idle_thread, exiting" % traceback.format_exc()) - self.quit = True - with bb.utils.lock_timeout(self._idlefuncsLock): items = list(self._idlefuns.items())
lib/bb/tinfoil.py +6 -0
@@ -449,6 +449,12 @@ class Tinfoil: self.run_actions(config_params) self.recipes_parsed = True + def modified_files(self): + """ + Notify the server it needs to revalidate it's caches since the client has modified files + """ + self.run_command("revalidateCaches") + def run_command(self, command, *params, handle_events=True): """ Run a command on the server (as implemented in bb.command).
lib/bblayers/action.py +6 -0
@@ -50,12 +50,14 @@ class ActionPlugin(LayerPlugin): try: notadded, _ = bb.utils.edit_bblayers_conf(bblayers_conf, layerdirs, None) + self.tinfoil.modified_files() if not (args.force or notadded): try: self.tinfoil.run_command('parseConfiguration') except (bb.tinfoil.TinfoilUIException, bb.BBHandledException): # Restore the back up copy of bblayers.conf shutil.copy2(backup, bblayers_conf) + self.tinfoil.modified_files() bb.fatal("Parse failure with the specified layer added, exiting.") else: for item in notadded:
@@ -81,6 +83,7 @@ class ActionPlugin(LayerPlugin): layerdir = os.path.abspath(item) layerdirs.append(layerdir) (_, notremoved) = bb.utils.edit_bblayers_conf(bblayers_conf, None, layerdirs) + self.tinfoil.modified_files() if notremoved: for item in notremoved: sys.stderr.write("No layers matching %s found in BBLAYERS\n" % item)
@@ -240,6 +243,9 @@ build results (as the layer priority order has effectively changed). if not entry_found: logger.warning("File %s does not match the flattened layer's BBFILES setting, you may need to edit conf/layer.conf or move the file elsewhere" % f1full) + self.tinfoil.modified_files() + + def get_file_layer(self, filename): layerdir = self.get_file_layerdir(filename) if layerdir:
Signature · 1 line
2.39.2