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

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