Blame SOURCES/0005-nvme.py-Sync-the-containing-directory.patch

26b18e
From 12a8764c6113887c5691cab6a92bb1c13414395c Mon Sep 17 00:00:00 2001
26b18e
From: Tony Asleson <tasleson@redhat.com>
26b18e
Date: Thu, 26 Mar 2020 13:07:47 -0500
26b18e
Subject: [PATCH 05/12] nvme.py: Sync the containing directory
26b18e
26b18e
It's apparent that some thought went into making sure the config
26b18e
file makes it atomically to the fs.  However, one thing is missing
26b18e
which is doing a fsync on the containing directory of the config file.
26b18e
26b18e
See: https://lwn.net/Articles/457667/
26b18e
26b18e
Signed-off-by: Tony Asleson <tasleson@redhat.com>
26b18e
Signed-off-by: Christoph Hellwig <hch@lst.de>
26b18e
---
26b18e
 nvmet/nvme.py | 9 +++++++++
26b18e
 1 file changed, 9 insertions(+)
26b18e
26b18e
diff --git a/nvmet/nvme.py b/nvmet/nvme.py
26b18e
index 687a45a..04659de 100644
26b18e
--- a/nvmet/nvme.py
26b18e
+++ b/nvmet/nvme.py
26b18e
@@ -305,6 +305,15 @@ class Root(CFSNode):
26b18e
 
26b18e
         os.rename(savefile + ".temp", savefile)
26b18e
 
26b18e
+        # Sync the containing directory too
26b18e
+        dir_fd = None
26b18e
+        try:
26b18e
+            dir_fd = os.open(savefile_dir, os.O_RDONLY)
26b18e
+            os.fsync(dir_fd)
26b18e
+        finally:
26b18e
+            if dir_fd:
26b18e
+                os.close(dir_fd)
26b18e
+
26b18e
     def clear_existing(self):
26b18e
         '''
26b18e
         Remove entire current configuration.
26b18e
-- 
26b18e
2.29.2
26b18e