From eb99b448b1cf111a1338dd44d1fa3b4493405f12 Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Mon, 14 Dec 2015 11:27:10 -0500 Subject: [PATCH] librgw: restrict objects to single-open this is the simplest consistent model for an open-write-close transaction (and it reads stable) Signed-off-by: Matt Benjamin --- src/rgw/rgw_file.cc | 14 ++++++++++++-- src/rgw/rgw_file.h | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index d4e8a846a3141..9f8030f109533 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -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); } /* diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index 46e0231c8c4dd..d6cbbe1951c10 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -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; + using unique_lock = std::unique_lock; + 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; } -- 2.39.5