From: Max Kellermann Date: Fri, 25 Oct 2024 16:04:27 +0000 (+0200) Subject: include/cephfs/types.h: move JSON methods to json.h X-Git-Tag: v21.0.0~256^2~78^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8244685cb3826072b955aa5f46c92bfea6881bfd;p=ceph.git include/cephfs/types.h: move JSON methods to json.h This eliminates the heavy header dependency on ceph_json.h from most includers. Signed-off-by: Max Kellermann --- diff --git a/src/include/cephfs/json.h b/src/include/cephfs/json.h new file mode 100644 index 000000000000..fde0d0071b82 --- /dev/null +++ b/src/include/cephfs/json.h @@ -0,0 +1,79 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2020 Red Hat, Inc. + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#pragma once + +#include "types.h" + +#include "common/ceph_json.h" + +template class Allocator> +void inode_t::client_ranges_cb(typename inode_t::client_range_map& c, JSONObj *obj){ + + int64_t client; + JSONDecoder::decode_json("client", client, obj, true); + client_writeable_range_t client_range_tmp; + JSONDecoder::decode_json("byte range", client_range_tmp.range, obj, true); + JSONDecoder::decode_json("follows", client_range_tmp.follows.val, obj, true); + c[client] = client_range_tmp; +} + +template class Allocator> +void inode_t::old_pools_cb(compact_set, Allocator >& c, JSONObj *obj){ + + int64_t tmp; + decode_json_obj(tmp, obj); + c.insert(tmp); +} + +template class Allocator> +void inode_t::decode_json(JSONObj *obj) +{ + + JSONDecoder::decode_json("ino", ino.val, obj, true); + JSONDecoder::decode_json("rdev", rdev, obj, true); + //JSONDecoder::decode_json("ctime", ctime, obj, true); + //JSONDecoder::decode_json("btime", btime, obj, true); + JSONDecoder::decode_json("mode", mode, obj, true); + JSONDecoder::decode_json("uid", uid, obj, true); + JSONDecoder::decode_json("gid", gid, obj, true); + JSONDecoder::decode_json("nlink", nlink, obj, true); + JSONDecoder::decode_json("dir_layout", dir_layout, obj, true); + JSONDecoder::decode_json("layout", layout, obj, true); + JSONDecoder::decode_json("old_pools", old_pools, inode_t::old_pools_cb, obj, true); + JSONDecoder::decode_json("size", size, obj, true); + JSONDecoder::decode_json("truncate_seq", truncate_seq, obj, true); + JSONDecoder::decode_json("truncate_size", truncate_size, obj, true); + JSONDecoder::decode_json("truncate_from", truncate_from, obj, true); + JSONDecoder::decode_json("truncate_pending", truncate_pending, obj, true); + //JSONDecoder::decode_json("mtime", mtime, obj, true); + //JSONDecoder::decode_json("atime", atime, obj, true); + JSONDecoder::decode_json("time_warp_seq", time_warp_seq, obj, true); + JSONDecoder::decode_json("change_attr", change_attr, obj, true); + JSONDecoder::decode_json("export_pin", export_pin, obj, true); + JSONDecoder::decode_json("client_ranges", client_ranges, inode_t::client_ranges_cb, obj, true); + JSONDecoder::decode_json("dirstat", dirstat, obj, true); + JSONDecoder::decode_json("rstat", rstat, obj, true); + JSONDecoder::decode_json("accounted_rstat", accounted_rstat, obj, true); + JSONDecoder::decode_json("version", version, obj, true); + JSONDecoder::decode_json("file_data_version", file_data_version, obj, true); + JSONDecoder::decode_json("xattr_version", xattr_version, obj, true); + JSONDecoder::decode_json("backtrace_version", backtrace_version, obj, true); + JSONDecoder::decode_json("stray_prior_path", stray_prior_path, obj, true); + JSONDecoder::decode_json("max_size_ever", max_size_ever, obj, true); + JSONDecoder::decode_json("quota", quota, obj, true); + JSONDecoder::decode_json("last_scrub_stamp", last_scrub_stamp, obj, true); + JSONDecoder::decode_json("last_scrub_version", last_scrub_version, obj, true); + JSONDecoder::decode_json("remote_ino", remote_ino.val, obj, true); + JSONDecoder::decode_json("referent_inodes", referent_inodes, obj, true); +} diff --git a/src/include/cephfs/types.h b/src/include/cephfs/types.h index dd449dd1ea48..94fa5e7d0b11 100644 --- a/src/include/cephfs/types.h +++ b/src/include/cephfs/types.h @@ -32,11 +32,12 @@ #include "include/ceph_assert.h" #include -#include "common/ceph_json.h" #define CEPH_FS_ONDISK_MAGIC "ceph fs volume v011" #define MAX_MDS 0x100 +class JSONObj; + BOOST_STRONG_TYPEDEF(uint64_t, mds_gid_t) extern const mds_gid_t MDS_GID_NONE; @@ -1233,67 +1234,6 @@ void inode_t::dump(ceph::Formatter *f) const f->close_section(); } -template class Allocator> -void inode_t::client_ranges_cb(typename inode_t::client_range_map& c, JSONObj *obj){ - - int64_t client; - JSONDecoder::decode_json("client", client, obj, true); - client_writeable_range_t client_range_tmp; - JSONDecoder::decode_json("byte range", client_range_tmp.range, obj, true); - JSONDecoder::decode_json("follows", client_range_tmp.follows.val, obj, true); - c[client] = client_range_tmp; -} - -template class Allocator> -void inode_t::old_pools_cb(compact_set, Allocator >& c, JSONObj *obj){ - - int64_t tmp; - decode_json_obj(tmp, obj); - c.insert(tmp); -} - -template class Allocator> -void inode_t::decode_json(JSONObj *obj) -{ - - JSONDecoder::decode_json("ino", ino.val, obj, true); - JSONDecoder::decode_json("rdev", rdev, obj, true); - //JSONDecoder::decode_json("ctime", ctime, obj, true); - //JSONDecoder::decode_json("btime", btime, obj, true); - JSONDecoder::decode_json("mode", mode, obj, true); - JSONDecoder::decode_json("uid", uid, obj, true); - JSONDecoder::decode_json("gid", gid, obj, true); - JSONDecoder::decode_json("nlink", nlink, obj, true); - JSONDecoder::decode_json("dir_layout", dir_layout, obj, true); - JSONDecoder::decode_json("layout", layout, obj, true); - JSONDecoder::decode_json("old_pools", old_pools, inode_t::old_pools_cb, obj, true); - JSONDecoder::decode_json("size", size, obj, true); - JSONDecoder::decode_json("truncate_seq", truncate_seq, obj, true); - JSONDecoder::decode_json("truncate_size", truncate_size, obj, true); - JSONDecoder::decode_json("truncate_from", truncate_from, obj, true); - JSONDecoder::decode_json("truncate_pending", truncate_pending, obj, true); - //JSONDecoder::decode_json("mtime", mtime, obj, true); - //JSONDecoder::decode_json("atime", atime, obj, true); - JSONDecoder::decode_json("time_warp_seq", time_warp_seq, obj, true); - JSONDecoder::decode_json("change_attr", change_attr, obj, true); - JSONDecoder::decode_json("export_pin", export_pin, obj, true); - JSONDecoder::decode_json("client_ranges", client_ranges, inode_t::client_ranges_cb, obj, true); - JSONDecoder::decode_json("dirstat", dirstat, obj, true); - JSONDecoder::decode_json("rstat", rstat, obj, true); - JSONDecoder::decode_json("accounted_rstat", accounted_rstat, obj, true); - JSONDecoder::decode_json("version", version, obj, true); - JSONDecoder::decode_json("file_data_version", file_data_version, obj, true); - JSONDecoder::decode_json("xattr_version", xattr_version, obj, true); - JSONDecoder::decode_json("backtrace_version", backtrace_version, obj, true); - JSONDecoder::decode_json("stray_prior_path", stray_prior_path, obj, true); - JSONDecoder::decode_json("max_size_ever", max_size_ever, obj, true); - JSONDecoder::decode_json("quota", quota, obj, true); - JSONDecoder::decode_json("last_scrub_stamp", last_scrub_stamp, obj, true); - JSONDecoder::decode_json("last_scrub_version", last_scrub_version, obj, true); - JSONDecoder::decode_json("remote_ino", remote_ino.val, obj, true); - JSONDecoder::decode_json("referent_inodes", referent_inodes, obj, true); -} - template class Allocator> void inode_t::generate_test_instances(std::list& ls) { diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index c0209e9cab8a..8f5f42b5adf7 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -44,6 +44,7 @@ #include "global/global_context.h" #include "include/denc.h" #include "include/ceph_assert.h" +#include "include/cephfs/json.h" #include "include/int_types.h" #include "include/random.h" // for ceph::util::generate_random_number()