From 525631d8dc058910728e55def616358b0e7f2f69 Mon Sep 17 00:00:00 2001 From: Tim Rozet Date: Mon, 17 Dec 2018 19:44:54 -0500 Subject: [PATCH] Fixes race condition with privsep utime There is a race condition that occurs over NFS when multiple instances are being created where utime fails, due to some other process modifying the file path. This patch ensures the path is created and is readable before attempting to modify with utime. Closes-Bug: 1809123 Change-Id: Id68aa27a8ab08d9c00655e5ed6b48d194aa8e6f6 Signed-off-by: Tim Rozet --- nova/privsep/path.py | 10 ++++------ ...ix-image-utime-race-condition-3c404e272ea91b34.yaml | 8 ++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/fix-image-utime-race-condition-3c404e272ea91b34.yaml diff --git a/nova/privsep/path.py b/nova/privsep/path.py index c35e32ce54bb..680bce175179 100644 --- a/nova/privsep/path.py +++ b/nova/privsep/path.py @@ -70,12 +70,10 @@ def chmod(path, mode): def utime(path): if not os.path.exists(path): raise exception.FileNotFound(file_path=path) - - # NOTE(mikal): the old version of this used execute(touch, ...), which - # would apparently fail on shared storage when multiple instances were - # being launched at the same time. If we see failures here, we might need - # to wrap this in a try / except. - os.utime(path, None) + # context wrapper ensures the file exists before trying to modify time + # which fixes a race condition with NFS image caching (see LP#1809123) + with open(path, 'a'): + os.utime(path, None) @nova.privsep.sys_admin_pctxt.entrypoint diff --git a/releasenotes/notes/fix-image-utime-race-condition-3c404e272ea91b34.yaml b/releasenotes/notes/fix-image-utime-race-condition-3c404e272ea91b34.yaml new file mode 100644 index 000000000000..08aa6e4860f3 --- /dev/null +++ b/releasenotes/notes/fix-image-utime-race-condition-3c404e272ea91b34.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Fixes a race condition when multiple instances are launched at the same + time, which leads to a failure when modifying the modified time of the + instance base image. This issue was noticed when using an NFS backend. For + more information see https://bugs.launchpad.net/nova/+bug/1809123 +