]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: restrict objects to single-open
authorMatt Benjamin <mbenjamin@redhat.com>
Mon, 14 Dec 2015 16:27:10 +0000 (11:27 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:06:37 +0000 (12:06 -0500)
this is the simplest consistent model for an open-write-close
transaction (and it reads stable)

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_file.cc
src/rgw/rgw_file.h

index d4e8a846a3141b3de1bf8ae9496aa2fec8207bfd..9f8030f109533270dd11c571fb23ea3dc6aba2a8 100644 (file)
@@ -510,9 +510,19 @@ int rgw_open(struct rgw_fs *rgw_fs,
             struct rgw_file_handle *fh, uint32_t flags)
 {
   RGWFileHandle* rgw_fh = get_rgwfh(fh);
-  rgw_fh->open(/* XXX */);
 
-  return 0;
+  /* XXX 
+   * need to track specific opens--at least read opens and
+   * a write open;  we need to know when a write open is returned,
+   * that closes a write transaction
+   *
+   * for now, we will support single-open only, it's preferable to
+   * anything we can otherwise do without access to the NFS state
+   */
+
+  // convert flags
+  uint32_t oflags = 0;
+  return rgw_fh->open(oflags);
 }
 
 /*
index 46e0231c8c4dd242e7dc5cca833471b7f0287433..d6cbbe1951c10f73a66a6be7d4834a82ee0ae831 100644 (file)
@@ -134,6 +134,9 @@ namespace rgw {
     /* const */ std::string name; /* XXX file or bucket name */
     /* const */ fh_key fhk;
 
+    using lock_guard = std::lock_guard<std::mutex>;
+    using unique_lock = std::unique_lock<std::mutex>;
+
     struct state {
       uint64_t dev;
       size_t size;
@@ -345,15 +348,22 @@ namespace rgw {
     bool creating() const { return flags & FLAG_CREATE; }
     bool pseudo() const { return flags & FLAG_PSEUDO; }
 
-    void open() {
-      flags |= FLAG_OPEN;
+    uint32_t open(uint32_t gsh_flags) {
+      lock_guard guard(mtx);
+      if (! (flags & FLAG_OPEN)) {
+       flags |= FLAG_OPEN;
+       return 0;
+      }
+      return EPERM;
     }
 
     void close() {
+      lock_guard guard(mtx);
       flags &= ~FLAG_OPEN;
     }
 
     void open_for_create() {
+      lock_guard guard(mtx);
       flags |= FLAG_CREATE;
     }