mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 04:19:10 -04:00
feat(fuse-driver): implement dwarfs.inodeinfo xattr
This commit is contained in:
parent
c2840cbe79
commit
07412cb7c0
@ -174,6 +174,10 @@ class filesystem_v2 {
|
||||
|
||||
history const& get_history() const { return impl_->get_history(); }
|
||||
|
||||
folly::dynamic get_inode_info(inode_view entry) const {
|
||||
return impl_->get_inode_info(entry);
|
||||
}
|
||||
|
||||
class impl {
|
||||
public:
|
||||
virtual ~impl() = default;
|
||||
@ -214,6 +218,7 @@ class filesystem_v2 {
|
||||
virtual size_t num_blocks() const = 0;
|
||||
virtual bool has_symlinks() const = 0;
|
||||
virtual history const& get_history() const = 0;
|
||||
virtual folly::dynamic get_inode_info(inode_view entry) const = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -134,6 +134,10 @@ class metadata_v2 {
|
||||
|
||||
bool has_symlinks() const { return impl_->has_symlinks(); }
|
||||
|
||||
folly::dynamic get_inode_info(inode_view iv) const {
|
||||
return impl_->get_inode_info(iv);
|
||||
}
|
||||
|
||||
static std::pair<std::vector<uint8_t>, std::vector<uint8_t>>
|
||||
freeze(const thrift::metadata::metadata& data);
|
||||
|
||||
@ -188,6 +192,8 @@ class metadata_v2 {
|
||||
virtual size_t block_size() const = 0;
|
||||
|
||||
virtual bool has_symlinks() const = 0;
|
||||
|
||||
virtual folly::dynamic get_inode_info(inode_view iv) const = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -387,6 +387,9 @@ class filesystem_ final : public filesystem_v2::impl {
|
||||
size_t num_blocks() const override { return ir_.num_blocks(); }
|
||||
bool has_symlinks() const override { return meta_.has_symlinks(); }
|
||||
history const& get_history() const override { return history_; }
|
||||
folly::dynamic get_inode_info(inode_view entry) const override {
|
||||
return meta_.get_inode_info(entry);
|
||||
}
|
||||
|
||||
private:
|
||||
filesystem_info const& get_info() const;
|
||||
|
@ -447,6 +447,8 @@ class metadata_ final : public metadata_v2::impl {
|
||||
|
||||
bool has_symlinks() const override { return !meta_.symlink_table().empty(); }
|
||||
|
||||
folly::dynamic get_inode_info(inode_view iv) const override;
|
||||
|
||||
private:
|
||||
template <typename K>
|
||||
using set_type = folly::F14ValueSet<K>;
|
||||
@ -1525,6 +1527,40 @@ metadata_<LoggerPolicy>::get_chunks(int inode) const {
|
||||
return get_chunk_range(inode - inode_offset_);
|
||||
}
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
folly::dynamic metadata_<LoggerPolicy>::get_inode_info(inode_view iv) const {
|
||||
folly::dynamic obj = folly::dynamic::object;
|
||||
|
||||
auto chunk_range = get_chunk_range(iv.inode_num());
|
||||
|
||||
if (chunk_range) {
|
||||
obj["chunks"] = folly::dynamic::array;
|
||||
|
||||
for (auto const& chunk : *chunk_range) {
|
||||
folly::dynamic chk = folly::dynamic::object;
|
||||
|
||||
chk["block"] = chunk.block();
|
||||
chk["offset"] = chunk.offset();
|
||||
chk["size"] = chunk.size();
|
||||
|
||||
if (meta_.category_names() && meta_.block_categories()) {
|
||||
chk["category"] =
|
||||
meta_.category_names()
|
||||
.value()[meta_.block_categories().value()[chunk.block()]];
|
||||
}
|
||||
|
||||
obj["chunks"].push_back(chk);
|
||||
}
|
||||
}
|
||||
|
||||
obj["mode"] = iv.mode();
|
||||
obj["modestring"] = modestring(iv.mode());
|
||||
obj["uid"] = iv.getuid();
|
||||
obj["gid"] = iv.getgid();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
std::pair<std::vector<uint8_t>, std::vector<uint8_t>>
|
||||
metadata_v2::freeze(const thrift::metadata::metadata& data) {
|
||||
return freeze_to_buffer(data);
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <folly/Conv.h>
|
||||
#include <folly/String.h>
|
||||
#include <folly/experimental/symbolizer/SignalHandler.h>
|
||||
#include <folly/json.h>
|
||||
|
||||
#ifndef DWARFS_FUSE_LOWLEVEL
|
||||
#define DWARFS_FUSE_LOWLEVEL 1
|
||||
@ -182,6 +183,7 @@ namespace {
|
||||
|
||||
constexpr std::string_view pid_xattr{"user.dwarfs.driver.pid"};
|
||||
constexpr std::string_view perfmon_xattr{"user.dwarfs.driver.perfmon"};
|
||||
constexpr std::string_view inodeinfo_xattr{"user.dwarfs.inodeinfo"};
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -828,6 +830,17 @@ void op_getxattr(fuse_req_t req, fuse_ino_t ino, char const* name,
|
||||
oss << "no performance monitor support\n";
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
if (name == inodeinfo_xattr) {
|
||||
auto entry = userdata->fs.find(ino);
|
||||
|
||||
if (entry) {
|
||||
auto ii = userdata->fs.get_inode_info(*entry);
|
||||
oss << folly::toPrettyJson(ii) << "\n";
|
||||
} else {
|
||||
err = ENOENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto value = oss.view();
|
||||
@ -886,6 +899,8 @@ void op_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) {
|
||||
if (ino == FUSE_ROOT_ID) {
|
||||
oss << pid_xattr << '\0';
|
||||
oss << perfmon_xattr << '\0';
|
||||
} else {
|
||||
oss << inodeinfo_xattr << '\0';
|
||||
}
|
||||
|
||||
auto xattrs = oss.view();
|
||||
|
Loading…
x
Reference in New Issue
Block a user