From 8417a788fbd0c7e2800ccdd6b2f0138b10e8c93c Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Wed, 4 Nov 2015 16:20:45 -0500 Subject: [PATCH] librgw: bring back lookup_handle() Now as a member of RGWLibFS, and exposed via rgw_lookup_handle() for use by library clients. Signed-off-by: Matt Benjamin --- src/include/rados/rgw_file.h | 38 +++++++++++++++++++++--------------- src/rgw/rgw_file.cc | 22 ++++++++++++++++++++- src/rgw/rgw_file.h | 29 +++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/src/include/rados/rgw_file.h b/src/include/rados/rgw_file.h index 29a5520064808..5b41389aa4f86 100644 --- a/src/include/rados/rgw_file.h +++ b/src/include/rados/rgw_file.h @@ -76,6 +76,25 @@ struct rgw_statvfs { uint64_t f_namemax; /* maximum filename length */ }; +/* + lookup object by name (POSIX style) +*/ +int rgw_lookup(struct rgw_fs *rgw_fs, + struct rgw_file_handle *parent_fh, const char *path, + struct rgw_file_handle **fh, uint32_t flags); + +/* + lookup object by handle (NFS style) +*/ +int rgw_lookup_handle(struct rgw_fs *rgw_fs, struct rgw_fh_hk fh_hk, + struct rgw_file_handle **fh, uint32_t flags); + +/* + * release file handle + */ +int rgw_fh_rele(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, + uint32_t flags); + /* attach rgw namespace */ @@ -126,20 +145,7 @@ int rgw_unlink(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh, const char* path); /* - lookup a directory or file -*/ -int rgw_lookup(struct rgw_fs *rgw_fs, - struct rgw_file_handle *parent_fh, const char *path, - struct rgw_file_handle **fh, uint32_t flags); - -/* - * release file handle - */ -int rgw_fh_rele(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, - uint32_t flags); - -/* - read directory content + read directory content */ typedef bool (*rgw_readdir_cb)(const char *name, void *arg, uint64_t offset); @@ -187,7 +193,7 @@ int rgw_open(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh, #define RGW_CLOSE_FLAG_NONE 0x0000 #define RGW_CLOSE_FLAG_RELE 0x0001 - + int rgw_close(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, uint32_t flags); @@ -197,7 +203,7 @@ int rgw_close(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, int rgw_read(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, uint64_t offset, size_t length, size_t *bytes_read, void *buffer); - + /* write data to file */ diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index e3f86e1983e5a..9792749dfbbad 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -172,7 +172,7 @@ int rgw_unlink(struct rgw_fs *rgw_fs, struct rgw_file_handle* parent, } /* - lookup a directory or file + lookup object by name (POSIX style) */ int rgw_lookup(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh, const char* path, @@ -198,6 +198,26 @@ int rgw_lookup(struct rgw_fs *rgw_fs, return 0; } /* rgw_lookup */ +/* + lookup object by handle (NFS style) +*/ +int rgw_lookup_handle(struct rgw_fs *rgw_fs, struct rgw_fh_hk fh_hk, + struct rgw_file_handle **fh, uint32_t flags) +{ + RGWLibFS *fs = static_cast(rgw_fs->fs_private); + + RGWFileHandle* rgw_fh = fs->lookup_handle(fh_hk); + if (! rgw_fh) { + /* not found */ + return ENOENT; + } + + struct rgw_file_handle *rfh = rgw_fh->get_fh(); + *fh = rfh; + + return 0; +} + /* * release file handle */ diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index 8f2aec5f8fb96..d1d2d46cb3c43 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -313,6 +313,35 @@ namespace rgw { return fh; } + /* find or create an RGWFileHandle */ + RGWFileHandle* lookup_handle(struct rgw_fh_hk fh_hk) { + + RGWFileHandle::FHCache::Latch lat; + fh_key fhk(fh_hk); + + RGWFileHandle* fh = + fh_cache.find_latch(fhk.fh_hk.object /* partition selector*/, + fhk /* key */, lat /* serializer */, + RGWFileHandle::FHCache::FLAG_LOCK); + /* LATCHED */ + if (! fh) { + lsubdout(get_context(), rgw, 0) + << __func__ << " handle lookup failed <" + << fhk.fh_hk.bucket << "," << fhk.fh_hk.object << ">" + << "(need persistent handles)" + << dendl; + goto out; + } + intrusive_ptr_add_ref(fh); /* call path/handle ref */ + out: + lat.lock->unlock(); /* !LATCHED */ + return fh; + } + + CephContext* get_context() { + return static_cast(get_fs()->fs_private); + } + struct rgw_fs* get_fs() { return &fs; } RGWUserInfo* get_user() { return &user; } -- 2.39.5