Skip to content

Commit 8244685

Browse files
MaxKellermannvshankar
authored andcommitted
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 <[email protected]>
1 parent c914920 commit 8244685

File tree

3 files changed

+82
-62
lines changed

3 files changed

+82
-62
lines changed

src/include/cephfs/json.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2+
// vim: ts=8 sw=2 smarttab
3+
/*
4+
* Ceph - scalable distributed file system
5+
*
6+
* Copyright (C) 2020 Red Hat, Inc.
7+
*
8+
* This is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License version 2.1, as published by the Free Software
11+
* Foundation. See file COPYING.
12+
*/
13+
14+
#pragma once
15+
16+
#include "types.h"
17+
18+
#include "common/ceph_json.h"
19+
20+
template<template<typename> class Allocator>
21+
void inode_t<Allocator>::client_ranges_cb(typename inode_t<Allocator>::client_range_map& c, JSONObj *obj){
22+
23+
int64_t client;
24+
JSONDecoder::decode_json("client", client, obj, true);
25+
client_writeable_range_t client_range_tmp;
26+
JSONDecoder::decode_json("byte range", client_range_tmp.range, obj, true);
27+
JSONDecoder::decode_json("follows", client_range_tmp.follows.val, obj, true);
28+
c[client] = client_range_tmp;
29+
}
30+
31+
template<template<typename> class Allocator>
32+
void inode_t<Allocator>::old_pools_cb(compact_set<int64_t, std::less<int64_t>, Allocator<int64_t> >& c, JSONObj *obj){
33+
34+
int64_t tmp;
35+
decode_json_obj(tmp, obj);
36+
c.insert(tmp);
37+
}
38+
39+
template<template<typename> class Allocator>
40+
void inode_t<Allocator>::decode_json(JSONObj *obj)
41+
{
42+
43+
JSONDecoder::decode_json("ino", ino.val, obj, true);
44+
JSONDecoder::decode_json("rdev", rdev, obj, true);
45+
//JSONDecoder::decode_json("ctime", ctime, obj, true);
46+
//JSONDecoder::decode_json("btime", btime, obj, true);
47+
JSONDecoder::decode_json("mode", mode, obj, true);
48+
JSONDecoder::decode_json("uid", uid, obj, true);
49+
JSONDecoder::decode_json("gid", gid, obj, true);
50+
JSONDecoder::decode_json("nlink", nlink, obj, true);
51+
JSONDecoder::decode_json("dir_layout", dir_layout, obj, true);
52+
JSONDecoder::decode_json("layout", layout, obj, true);
53+
JSONDecoder::decode_json("old_pools", old_pools, inode_t<Allocator>::old_pools_cb, obj, true);
54+
JSONDecoder::decode_json("size", size, obj, true);
55+
JSONDecoder::decode_json("truncate_seq", truncate_seq, obj, true);
56+
JSONDecoder::decode_json("truncate_size", truncate_size, obj, true);
57+
JSONDecoder::decode_json("truncate_from", truncate_from, obj, true);
58+
JSONDecoder::decode_json("truncate_pending", truncate_pending, obj, true);
59+
//JSONDecoder::decode_json("mtime", mtime, obj, true);
60+
//JSONDecoder::decode_json("atime", atime, obj, true);
61+
JSONDecoder::decode_json("time_warp_seq", time_warp_seq, obj, true);
62+
JSONDecoder::decode_json("change_attr", change_attr, obj, true);
63+
JSONDecoder::decode_json("export_pin", export_pin, obj, true);
64+
JSONDecoder::decode_json("client_ranges", client_ranges, inode_t<Allocator>::client_ranges_cb, obj, true);
65+
JSONDecoder::decode_json("dirstat", dirstat, obj, true);
66+
JSONDecoder::decode_json("rstat", rstat, obj, true);
67+
JSONDecoder::decode_json("accounted_rstat", accounted_rstat, obj, true);
68+
JSONDecoder::decode_json("version", version, obj, true);
69+
JSONDecoder::decode_json("file_data_version", file_data_version, obj, true);
70+
JSONDecoder::decode_json("xattr_version", xattr_version, obj, true);
71+
JSONDecoder::decode_json("backtrace_version", backtrace_version, obj, true);
72+
JSONDecoder::decode_json("stray_prior_path", stray_prior_path, obj, true);
73+
JSONDecoder::decode_json("max_size_ever", max_size_ever, obj, true);
74+
JSONDecoder::decode_json("quota", quota, obj, true);
75+
JSONDecoder::decode_json("last_scrub_stamp", last_scrub_stamp, obj, true);
76+
JSONDecoder::decode_json("last_scrub_version", last_scrub_version, obj, true);
77+
JSONDecoder::decode_json("remote_ino", remote_ino.val, obj, true);
78+
JSONDecoder::decode_json("referent_inodes", referent_inodes, obj, true);
79+
}

src/include/cephfs/types.h

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232

3333
#include "include/ceph_assert.h"
3434
#include <boost/serialization/strong_typedef.hpp>
35-
#include "common/ceph_json.h"
3635

3736
#define CEPH_FS_ONDISK_MAGIC "ceph fs volume v011"
3837
#define MAX_MDS 0x100
3938

39+
class JSONObj;
40+
4041
BOOST_STRONG_TYPEDEF(uint64_t, mds_gid_t)
4142
extern const mds_gid_t MDS_GID_NONE;
4243

@@ -1233,67 +1234,6 @@ void inode_t<Allocator>::dump(ceph::Formatter *f) const
12331234
f->close_section();
12341235
}
12351236

1236-
template<template<typename> class Allocator>
1237-
void inode_t<Allocator>::client_ranges_cb(typename inode_t<Allocator>::client_range_map& c, JSONObj *obj){
1238-
1239-
int64_t client;
1240-
JSONDecoder::decode_json("client", client, obj, true);
1241-
client_writeable_range_t client_range_tmp;
1242-
JSONDecoder::decode_json("byte range", client_range_tmp.range, obj, true);
1243-
JSONDecoder::decode_json("follows", client_range_tmp.follows.val, obj, true);
1244-
c[client] = client_range_tmp;
1245-
}
1246-
1247-
template<template<typename> class Allocator>
1248-
void inode_t<Allocator>::old_pools_cb(compact_set<int64_t, std::less<int64_t>, Allocator<int64_t> >& c, JSONObj *obj){
1249-
1250-
int64_t tmp;
1251-
decode_json_obj(tmp, obj);
1252-
c.insert(tmp);
1253-
}
1254-
1255-
template<template<typename> class Allocator>
1256-
void inode_t<Allocator>::decode_json(JSONObj *obj)
1257-
{
1258-
1259-
JSONDecoder::decode_json("ino", ino.val, obj, true);
1260-
JSONDecoder::decode_json("rdev", rdev, obj, true);
1261-
//JSONDecoder::decode_json("ctime", ctime, obj, true);
1262-
//JSONDecoder::decode_json("btime", btime, obj, true);
1263-
JSONDecoder::decode_json("mode", mode, obj, true);
1264-
JSONDecoder::decode_json("uid", uid, obj, true);
1265-
JSONDecoder::decode_json("gid", gid, obj, true);
1266-
JSONDecoder::decode_json("nlink", nlink, obj, true);
1267-
JSONDecoder::decode_json("dir_layout", dir_layout, obj, true);
1268-
JSONDecoder::decode_json("layout", layout, obj, true);
1269-
JSONDecoder::decode_json("old_pools", old_pools, inode_t<Allocator>::old_pools_cb, obj, true);
1270-
JSONDecoder::decode_json("size", size, obj, true);
1271-
JSONDecoder::decode_json("truncate_seq", truncate_seq, obj, true);
1272-
JSONDecoder::decode_json("truncate_size", truncate_size, obj, true);
1273-
JSONDecoder::decode_json("truncate_from", truncate_from, obj, true);
1274-
JSONDecoder::decode_json("truncate_pending", truncate_pending, obj, true);
1275-
//JSONDecoder::decode_json("mtime", mtime, obj, true);
1276-
//JSONDecoder::decode_json("atime", atime, obj, true);
1277-
JSONDecoder::decode_json("time_warp_seq", time_warp_seq, obj, true);
1278-
JSONDecoder::decode_json("change_attr", change_attr, obj, true);
1279-
JSONDecoder::decode_json("export_pin", export_pin, obj, true);
1280-
JSONDecoder::decode_json("client_ranges", client_ranges, inode_t<Allocator>::client_ranges_cb, obj, true);
1281-
JSONDecoder::decode_json("dirstat", dirstat, obj, true);
1282-
JSONDecoder::decode_json("rstat", rstat, obj, true);
1283-
JSONDecoder::decode_json("accounted_rstat", accounted_rstat, obj, true);
1284-
JSONDecoder::decode_json("version", version, obj, true);
1285-
JSONDecoder::decode_json("file_data_version", file_data_version, obj, true);
1286-
JSONDecoder::decode_json("xattr_version", xattr_version, obj, true);
1287-
JSONDecoder::decode_json("backtrace_version", backtrace_version, obj, true);
1288-
JSONDecoder::decode_json("stray_prior_path", stray_prior_path, obj, true);
1289-
JSONDecoder::decode_json("max_size_ever", max_size_ever, obj, true);
1290-
JSONDecoder::decode_json("quota", quota, obj, true);
1291-
JSONDecoder::decode_json("last_scrub_stamp", last_scrub_stamp, obj, true);
1292-
JSONDecoder::decode_json("last_scrub_version", last_scrub_version, obj, true);
1293-
JSONDecoder::decode_json("remote_ino", remote_ino.val, obj, true);
1294-
JSONDecoder::decode_json("referent_inodes", referent_inodes, obj, true);
1295-
}
1296-
12971237
template<template<typename> class Allocator>
12981238
void inode_t<Allocator>::generate_test_instances(std::list<inode_t*>& ls)
12991239
{

src/mds/CInode.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "global/global_context.h"
4545
#include "include/denc.h"
4646
#include "include/ceph_assert.h"
47+
#include "include/cephfs/json.h"
4748
#include "include/int_types.h"
4849
#include "include/random.h" // for ceph::util::generate_random_number()
4950

0 commit comments

Comments
 (0)