]> www.infradead.org Git - users/hch/nvmetcli.git/commitdiff
Ensure internal buffers are flushed json after dumping json to disk
authorChristoph Hellwig <hch@lst.de>
Thu, 24 Mar 2016 15:42:26 +0000 (16:42 +0100)
committerChristoph Hellwig <hch@lst.de>
Thu, 24 Mar 2016 15:42:26 +0000 (16:42 +0100)
A power-outage, unexpected reboot, etc can lead to zero byte file
after a saveconfig.

Based on a rtslib-fb patch from Jon Magrini <jmagrini@redhat.com>.

Signed-off-by: Christoph Hellwig <hch@lst.de>
nvmet/nvme.py

index fb8dcbd796f88679f983721c38b0d7f64267e92c..a05e50c7bd2f4eb79ec2e0c9b74e6c980e80a67d 100644 (file)
@@ -240,7 +240,9 @@ class Root(CFSNode):
             os.fchmod(f.fileno(), stat.S_IRUSR | stat.S_IWUSR)
             f.write(json.dumps(self.dump(), sort_keys=True, indent=2))
             f.write("\n")
+            f.flush()
             os.fsync(f.fileno())
+            f.close()
 
         os.rename(savefile + ".temp", savefile)