]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/LFNIndex: FDCloser helper
authorSage Weil <sage@redhat.com>
Mon, 21 Jul 2014 20:43:42 +0000 (13:43 -0700)
committerSamuel Just <sam.just@inktank.com>
Sun, 3 Aug 2014 19:47:10 +0000 (12:47 -0700)
Add a helper to close fd's when we leave scope.  This is important when
injecting failures by throwing exceptions.

Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit a320c260a9e088ab0a4ea3d5298c06a2d077de37)

src/os/LFNIndex.cc

index 04ad734447b0ba90254d18ec830092159a19cf65..c83e3535dbb617404885738178aa1681cd9608bb 100644 (file)
@@ -61,6 +61,17 @@ void LFNIndex::maybe_inject_failure()
   }
 }
 
+// Helper to close fd's when we leave scope.  This is useful when used
+// in combination with RetryException, thrown by the above.
+struct FDCloser {
+  int fd;
+  FDCloser(int f) : fd(f) {}
+  ~FDCloser() {
+    VOID_TEMP_FAILURE_RETRY(::close(fd));
+  }
+};
+
+
 /* Public methods */
 
 void LFNIndex::set_ref(ceph::shared_ptr<CollectionIndex> ref)