#include <sys/stat.h>
#include <sys/xattr.h>
#include <unistd.h>
+#include <cstdint>
#include "rgw_multi.h"
#include "include/scope_guard.h"
#include "common/Clock.h" // for ceph_clock_now()
static inline rgw_obj_key decode_obj_key(const char* fname)
{
- std::string dname, oname, ns;
+ std::string dname, oname, ns; // XXX ns is unused?
dname = url_decode(fname);
rgw_obj_key key;
rgw_obj_key::parse_raw_oid(dname, &key);
return get_x_attrs(y, dpp, get_fd(), attrs, get_name());
}
-int FSEnt::fill_cache(const DoutPrefixProvider *dpp, optional_yield y, fill_cache_cb_t& cb)
+int FSEnt::fill_cache(const DoutPrefixProvider *dpp, optional_yield y, fill_cache_cb_t& cb, uint32_t flags)
{
rgw_bucket_dir_entry bde{};
case ObjectType::VERSIONED:
bde.flags = rgw_bucket_dir_entry::FLAG_VER;
bde.exists = true;
- if (!key.have_instance()) {
+ if (flags & FSEnt::FLAG_CURRENT) {
bde.flags |= rgw_bucket_dir_entry::FLAG_CURRENT;
}
break;
}
int Directory::fill_cache(const DoutPrefixProvider *dpp, optional_yield y,
- fill_cache_cb_t &cb)
+ fill_cache_cb_t &cb, uint32_t flags)
{
int ret = for_each(dpp, [this, &cb, &dpp, &y](const char *name) {
std::unique_ptr<FSEnt> ent;
ent->stat(dpp); // Stat the object to get the type
- ret = ent->fill_cache(dpp, y, cb);
+ ret = ent->fill_cache(dpp, y, cb, FSEnt::FLAG_NONE);
if (ret < 0)
return ret;
return 0;
return fill_target(dpp, parent, get_name(), std::string(), target, ctx);
}
-int Symlink::fill_cache(const DoutPrefixProvider *dpp, optional_yield y, fill_cache_cb_t& cb)
-{
- rgw_bucket_dir_entry bde{};
- int ret;
-
- rgw_obj_key key = decode_obj_key(get_name());
- key.get_index_key(&bde.key);
- bde.ver.pool = 1;
- bde.ver.epoch = 1;
-
- bde.flags = rgw_bucket_dir_entry::FLAG_VER;
- bde.exists = true;
- bde.flags |= rgw_bucket_dir_entry::FLAG_CURRENT;
-
- if (!target) {
- ret = stat(dpp, /*force=*/false);
- if (ret < 0)
- return ret;
- }
-
- Attrs attrs;
- ret = target->read_attrs(dpp, y, attrs);
- if (ret < 0)
- return ret;
-
- POSIXOwner o;
- ret = decode_owner(attrs, o);
- if (ret < 0) {
- bde.meta.owner = "unknown";
- bde.meta.owner_display_name = "unknown";
- } else {
- bde.meta.owner = o.user.to_str();
- bde.meta.owner_display_name = o.display_name;
- }
- bde.meta.category = RGWObjCategory::Main;
- bde.meta.size = stx.stx_size;
- bde.meta.accounted_size = stx.stx_size;
- bde.meta.mtime = from_statx_timestamp(stx.stx_mtime);
- bde.meta.storage_class = RGW_STORAGE_CLASS_STANDARD;
- bde.meta.appendable = true;
- bufferlist etag_bl;
- if (rgw::sal::get_attr(attrs, RGW_ATTR_ETAG, etag_bl)) {
- bde.meta.etag = etag_bl.to_str();
- }
-
- return cb(dpp, bde);
-}
-
int Symlink::read_attrs(const DoutPrefixProvider* dpp, optional_yield y, Attrs& attrs)
{
if (target)
}
int MPDirectory::fill_cache(const DoutPrefixProvider *dpp, optional_yield y,
- fill_cache_cb_t &cb)
+ fill_cache_cb_t &cb, uint32_t flags)
{
- int ret = FSEnt::fill_cache(dpp, y, cb);
+ int ret = FSEnt::fill_cache(dpp, y, cb, FSEnt::FLAG_NONE);
if (ret < 0)
return ret;
- return Directory::fill_cache(dpp, y, cb);
+ return Directory::fill_cache(dpp, y, cb, FSEnt::FLAG_NONE);
}
int VersionedDirectory::open(const DoutPrefixProvider* dpp)
}
int VersionedDirectory::fill_cache(const DoutPrefixProvider *dpp, optional_yield y,
- fill_cache_cb_t &cb)
+ fill_cache_cb_t &cb, uint32_t flags)
{
+ /* Fill cur_version */
+ stat(dpp, /*force=*/false);
+
int ret = for_each(dpp, [this, &cb, &dpp, &y](const char *name) {
std::unique_ptr<FSEnt> ent;
ent->stat(dpp); // Stat the object to get the type
- ret = ent->fill_cache(dpp, y, cb);
- if (ret < 0)
- return ret;
+ if (ent->get_type() != ObjectType::SYMLINK) {
+ uint32_t fill_flags =
+ (cur_version &&
+ (ent->get_name() == cur_version->get_name())) ?
+ FSEnt::FLAG_CURRENT :
+ FSEnt::FLAG_NONE;
+
+ ret = ent->fill_cache(dpp, y, cb, fill_flags);
+ if (ret < 0)
+ return ret;
+ }
return 0;
});
int POSIXObject::fill_cache(const DoutPrefixProvider *dpp, optional_yield y, fill_cache_cb_t& cb)
{
- return ent->fill_cache(dpp, y, cb);
+ return ent->fill_cache(dpp, y, cb, FSEnt::FLAG_NONE);
}
int POSIXDriver::mint_listing_entry(const std::string &bname,
}
int POSIXBucket::fill_cache(const DoutPrefixProvider* dpp, optional_yield y,
- fill_cache_cb_t& cb)
+ fill_cache_cb_t& cb)
{
-return dir->fill_cache(dpp, y, cb);
+ return dir->fill_cache(dpp, y, cb, FSEnt::FLAG_NONE);
}
int POSIXBucket::list(const DoutPrefixProvider* dpp, ListParams& params,
#include "rgw_sal_filter.h"
#include "rgw_sal_store.h"
+#include <cstdint>
#include <memory>
#include "common/dout.h"
#include "bucket_cache.h"
CephContext* ctx;
public:
+ static constexpr uint32_t FLAG_NONE = 0x0;
+ static constexpr uint32_t FLAG_CURRENT = 0x2;
+
FSEnt(std::string _name, Directory* _parent, CephContext* _ctx) : fname(_name), parent(_parent), ctx(_ctx) {}
FSEnt(std::string _name, Directory* _parent, struct statx& _stx, CephContext* _ctx) : fname(_name), parent(_parent), exist(true), stx(_stx), stat_done(true), ctx(_ctx) {}
FSEnt(const FSEnt& _e) :
virtual int copy(const DoutPrefixProvider *dpp, optional_yield y, Directory* dst_dir, const std::string& name) = 0;
virtual int link_temp_file(const DoutPrefixProvider* dpp, optional_yield y, std::string target_fname) = 0;
virtual std::unique_ptr<FSEnt> clone_base() = 0;
- virtual int fill_cache(const DoutPrefixProvider* dpp, optional_yield y, fill_cache_cb_t& cb);
+ virtual int fill_cache(const DoutPrefixProvider* dpp, optional_yield y, fill_cache_cb_t& cb, uint32_t flags);
virtual std::string get_cur_version() { return ""; };
};
}
virtual int copy(const DoutPrefixProvider *dpp, optional_yield y, Directory* dst_dir, const std::string& name) override;
virtual int link_temp_file(const DoutPrefixProvider* dpp, optional_yield y, std::string target_fname) override;
- virtual int fill_cache(const DoutPrefixProvider* dpp, optional_yield y, fill_cache_cb_t& cb) override;
+ virtual int fill_cache(const DoutPrefixProvider* dpp, optional_yield y, fill_cache_cb_t& cb, uint32_t flags) override;
int get_ent(const DoutPrefixProvider *dpp, optional_yield y, const std::string& name, const std::string& version, std::unique_ptr<FSEnt>& ent);
};
return std::make_unique<Symlink>(*this);
}
virtual int copy(const DoutPrefixProvider *dpp, optional_yield y, Directory* dst_dir, const std::string& name) override;
- virtual int fill_cache(const DoutPrefixProvider* dpp, optional_yield y, fill_cache_cb_t& cb) override;
};
class MPDirectory : public Directory {
std::unique_ptr<MPDirectory> clone() {
return std::make_unique<MPDirectory>(*this);
}
- virtual int fill_cache(const DoutPrefixProvider* dpp, optional_yield y, fill_cache_cb_t& cb) override;
+ virtual int fill_cache(const DoutPrefixProvider* dpp, optional_yield y, fill_cache_cb_t& cb, uint32_t flags) override;
};
class VersionedDirectory : public Directory {
return std::make_unique<VersionedDirectory>(*this);
}
virtual int copy(const DoutPrefixProvider *dpp, optional_yield y, Directory* dst_dir, const std::string& name) override;
- virtual int fill_cache(const DoutPrefixProvider* dpp, optional_yield y, fill_cache_cb_t& cb) override;
+ virtual int fill_cache(const DoutPrefixProvider* dpp, optional_yield y, fill_cache_cb_t& cb, uint32_t flags) override;
};
std::string get_key_fname(rgw_obj_key& key, bool use_version);