]> www.infradead.org Git - users/hch/nvmetcli.git/commitdiff
nvme.py: Sync the containing directory
authorTony Asleson <tasleson@redhat.com>
Thu, 26 Mar 2020 18:07:47 +0000 (13:07 -0500)
committerChristoph Hellwig <hch@lst.de>
Wed, 1 Apr 2020 09:00:14 +0000 (11:00 +0200)
It's apparent that some thought went into making sure the config
file makes it atomically to the fs.  However, one thing is missing
which is doing a fsync on the containing directory of the config file.

See: https://lwn.net/Articles/457667/

Signed-off-by: Tony Asleson <tasleson@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
nvmet/nvme.py

index 687a45a1e197ff8ca8bc6fb90406170f70b53479..04659deed11f6d755cc6e1d8d3ac46522f93dffe 100644 (file)
@@ -305,6 +305,15 @@ class Root(CFSNode):
 
         os.rename(savefile + ".temp", savefile)
 
+        # Sync the containing directory too
+        dir_fd = None
+        try:
+            dir_fd = os.open(savefile_dir, os.O_RDONLY)
+            os.fsync(dir_fd)
+        finally:
+            if dir_fd:
+                os.close(dir_fd)
+
     def clear_existing(self):
         '''
         Remove entire current configuration.