]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/InoTable.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / mds / InoTable.h
CommitLineData
7c673cae
FG
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) 2004-2006 Sage Weil <sage@newdream.net>
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
15
16#ifndef CEPH_INOTABLE_H
17#define CEPH_INOTABLE_H
18
19#include "MDSTable.h"
20#include "include/interval_set.h"
21
22class MDSRank;
23
24class InoTable : public MDSTable {
25 interval_set<inodeno_t> free; // unused ids
26 interval_set<inodeno_t> projected_free;
27
28 public:
29 explicit InoTable(MDSRank *m) : MDSTable(m, "inotable", true) { }
30
31 inodeno_t project_alloc_id(inodeno_t id=0);
32 void apply_alloc_id(inodeno_t id);
33
34 void project_alloc_ids(interval_set<inodeno_t>& inos, int want);
35 void apply_alloc_ids(interval_set<inodeno_t>& inos);
36
37 void project_release_ids(interval_set<inodeno_t>& inos);
38 void apply_release_ids(interval_set<inodeno_t>& inos);
39
40 void replay_alloc_id(inodeno_t ino);
41 void replay_alloc_ids(interval_set<inodeno_t>& inos);
42 void replay_release_ids(interval_set<inodeno_t>& inos);
43 void replay_reset();
44 bool repair(inodeno_t id);
45 bool is_marked_free(inodeno_t id) const;
46 bool intersects_free(
47 const interval_set<inodeno_t> &other,
48 interval_set<inodeno_t> *intersection);
49
50 void reset_state() override;
51 void encode_state(bufferlist& bl) const override {
52 ENCODE_START(2, 2, bl);
53 ::encode(free, bl);
54 ENCODE_FINISH(bl);
55 }
56 void decode_state(bufferlist::iterator& bl) override {
57 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
58 ::decode(free, bl);
59 projected_free = free;
60 DECODE_FINISH(bl);
61 }
62
63 // To permit enc/decoding in isolation in dencoder
64 InoTable() : MDSTable(NULL, "inotable", true) {}
65 void encode(bufferlist& bl) const {
66 encode_state(bl);
67 }
68 void decode(bufferlist::iterator& bl) {
69 decode_state(bl);
70 }
71 void dump(Formatter *f) const;
72 static void generate_test_instances(list<InoTable*>& ls);
73
74 void skip_inos(inodeno_t i);
75
76 /**
77 * If the specified inode is marked as free, mark it as used.
78 * For use in tools, not normal operations.
79 *
80 * @returns true if the inode was previously marked as free
81 */
82 bool force_consume(inodeno_t ino)
83 {
84 if (free.contains(ino)) {
85 free.erase(ino);
86 return true;
87 } else {
88 return false;
89 }
90 }
91
92 /**
93 * If this ino is in this rank's range, consume up to and including it.
94 * For use in tools, when we know the max ino in use and want to make
95 * sure we're only allocating new inodes from above it.
96 *
97 * @return true if the table was modified
98 */
99 bool force_consume_to(inodeno_t ino)
100 {
101 if (free.contains(ino)) {
102 inodeno_t min = free.begin().get_start();
103 std::cerr << "Erasing 0x" << std::hex << min << " to 0x" << ino << std::dec << std::endl;
104 free.erase(min, ino - min + 1);
105 projected_free = free;
106 projected_version = ++version;
107 return true;
108 } else {
109 return false;
110 }
111 }
112};
113WRITE_CLASS_ENCODER(InoTable)
114
115#endif