librgw: create dir file handles w/correct type

RGW objects which happen to represent directories will always end
in '/', but the trailing slash will not be present in cached versions
of the name.

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
This commit is contained in:
Matt Benjamin 2015-12-06 16:39:35 -05:00
parent 103eda1c6f
commit fcd432032f
2 changed files with 14 additions and 11 deletions

View File

@ -44,6 +44,7 @@ LookupFHResult RGWLibFS::stat_leaf(RGWFileHandle* parent,
RGWLibFS* fs = parent->get_fs();
LookupFHResult fhr{nullptr, 0};
std::string object_name{path};
uint32_t cflags = RGWFileHandle::FLAG_NONE;
for (auto ix : { 0, 1 }) {
ignore(ix);
@ -53,9 +54,10 @@ LookupFHResult RGWLibFS::stat_leaf(RGWFileHandle* parent,
int rc = librgw.get_fe()->execute_req(&req);
if ((rc == 0) &&
(req.get_ret() == 0)) {
fhr = fs->lookup_fh(parent, path);
fhr = fs->lookup_fh(parent, path, cflags);
break;
}
cflags = RGWFileHandle::FLAG_DIRECTORY;
object_name += "/";
}
return fhr;

View File

@ -141,12 +141,13 @@ namespace rgw {
static constexpr uint16_t MAX_DEPTH = 256;
static constexpr uint32_t FLAG_NONE = 0x0000;
static constexpr uint32_t FLAG_OPEN = 0x0001;
static constexpr uint32_t FLAG_ROOT = 0x0002;
static constexpr uint32_t FLAG_CREATE = 0x0004;
static constexpr uint32_t FLAG_PSEUDO = 0x0008;
static constexpr uint32_t FLAG_LOCK = 0x0010;
static constexpr uint32_t FLAG_NONE = 0x0000;
static constexpr uint32_t FLAG_OPEN = 0x0001;
static constexpr uint32_t FLAG_ROOT = 0x0002;
static constexpr uint32_t FLAG_CREATE = 0x0004;
static constexpr uint32_t FLAG_PSEUDO = 0x0008;
static constexpr uint32_t FLAG_DIRECTORY = 0x0010;
static constexpr uint32_t FLAG_LOCK = 0x0020;
friend class RGWLibFS;
@ -173,10 +174,10 @@ namespace rgw {
public:
RGWFileHandle(RGWLibFS* fs, uint32_t fs_inst, RGWFileHandle* _parent,
const fh_key& _fhk, std::string& _name)
: parent(_parent), name(std::move(_name)), fhk(_fhk), flags(FLAG_NONE) {
const fh_key& _fhk, std::string& _name, uint32_t _flags)
: parent(_parent), name(std::move(_name)), fhk(_fhk), flags(_flags) {
fh.fh_type = parent->is_root()
fh.fh_type = (parent->is_root() || (flags & FLAG_DIRECTORY))
? RGW_FS_TYPE_DIRECTORY : RGW_FS_TYPE_FILE;
depth = parent->depth + 1;
@ -476,7 +477,7 @@ namespace rgw {
/* LATCHED */
if ((! fh) &&
(cflags & RGWFileHandle::FLAG_CREATE)) {
fh = new RGWFileHandle(this, get_inst(), parent, fhk, sname);
fh = new RGWFileHandle(this, get_inst(), parent, fhk, sname, cflags);
intrusive_ptr_add_ref(fh); /* sentinel ref */
fh_cache.insert_latched(fh, lat,
RGWFileHandle::FHCache::FLAG_NONE);