From 857aa1e337df6b7cf5d21e311dce9576e27ea3a9 Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Sun, 8 Nov 2015 18:54:58 -0500 Subject: [PATCH] librgw: introduce RGW_LOOKUP_FLAG_CREATE The current API relies on rgw_lookup and rgw_lookup_filehandle to return file handle instances, and like POSIX, needs to deal in some way with the NFS/POSIX open-for-create concept. For now, allow rgw_lookup to return the canonical instance for an object being created, i.e., if the option RGW_LOOKUP_FLAG_CREATE is passed. (I added an RGW_OPEN_FLAG_CREATE also, but it doesn't do anything.) Signed-off-by: Matt Benjamin --- src/include/rados/rgw_file.h | 6 ++++++ src/rgw/rgw_file.cc | 5 +++-- src/test/librgw_file_gp.cc | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/include/rados/rgw_file.h b/src/include/rados/rgw_file.h index 7cfa5ec518dc4..040426ef7a019 100644 --- a/src/include/rados/rgw_file.h +++ b/src/include/rados/rgw_file.h @@ -79,6 +79,9 @@ struct rgw_statvfs { /* lookup object by name (POSIX style) */ +#define RGW_LOOKUP_FLAG_NONE 0x0000 +#define RGW_LOOKUP_FLAG_CREATE 0x0001 + 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); @@ -184,6 +187,9 @@ int rgw_truncate(struct rgw_fs *rgw_fs, /* open file */ +#define RGW_OPEN_FLAG_NONE 0x0000 +#define RGW_OPEN_FLAG_CREATE 0x0001 + int rgw_open(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh, uint32_t flags); diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index bd64f116ed89b..828760bf938e1 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -255,8 +255,9 @@ int rgw_lookup(struct rgw_fs *rgw_fs, RGWStatObjRequest::FLAG_NONE); int rc = librgw.get_fe()->execute_req(&req); - if ((rc != 0) || - (req.get_ret() != 0)) + if (((rc != 0) || + (req.get_ret() != 0)) && + (! (flags & RGW_LOOKUP_FLAG_CREATE))) return ENOENT; rgw_fh = fs->lookup_fh(parent, path); diff --git a/src/test/librgw_file_gp.cc b/src/test/librgw_file_gp.cc index adc9629de3b32..f35503e251975 100644 --- a/src/test/librgw_file_gp.cc +++ b/src/test/librgw_file_gp.cc @@ -219,7 +219,7 @@ TEST(LibRGW, LIST_OBJECTS) { TEST(LibRGW, LOOKUP_OBJECT) { if (do_get || do_put || do_bulk || do_readv || do_writev) { int ret = rgw_lookup(fs, bucket_fh, object_name.c_str(), &object_fh, - 0 /* flags */); + RGW_LOOKUP_FLAG_CREATE); ASSERT_EQ(ret, 0); } } -- 2.39.5