]> 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)
committerSage Weil <sage@redhat.com>
Wed, 23 Jul 2014 21:48:14 +0000 (14:48 -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>
src/os/LFNIndex.cc

index 52ce86e1e1f5bc6ae1627d9e84d17cbb277cafb9..6f14589ac15f73ee65e1abb4ca40dccc3ac32c81 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)