]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/InoTable.h
import 15.2.0 Octopus source
[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 {
7c673cae 25 public:
9f95a23c
TL
26 explicit InoTable(MDSRank *m) : MDSTable(m, "inotable", true) {}
27 InoTable() : MDSTable(NULL, "inotable", true) {}
7c673cae
FG
28
29 inodeno_t project_alloc_id(inodeno_t id=0);
30 void apply_alloc_id(inodeno_t id);
31
32 void project_alloc_ids(interval_set<inodeno_t>& inos, int want);
33 void apply_alloc_ids(interval_set<inodeno_t>& inos);
34
9f95a23c
TL
35 void project_release_ids(const interval_set<inodeno_t>& inos);
36 void apply_release_ids(const interval_set<inodeno_t>& inos);
7c673cae
FG
37
38 void replay_alloc_id(inodeno_t ino);
39 void replay_alloc_ids(interval_set<inodeno_t>& inos);
40 void replay_release_ids(interval_set<inodeno_t>& inos);
41 void replay_reset();
42 bool repair(inodeno_t id);
43 bool is_marked_free(inodeno_t id) const;
44 bool intersects_free(
45 const interval_set<inodeno_t> &other,
46 interval_set<inodeno_t> *intersection);
47
48 void reset_state() override;
49 void encode_state(bufferlist& bl) const override {
50 ENCODE_START(2, 2, bl);
11fdf7f2 51 encode(free, bl);
7c673cae
FG
52 ENCODE_FINISH(bl);
53 }
11fdf7f2 54 void decode_state(bufferlist::const_iterator& bl) override {
7c673cae 55 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
11fdf7f2 56 decode(free, bl);
7c673cae
FG
57 projected_free = free;
58 DECODE_FINISH(bl);
59 }
60
61 // To permit enc/decoding in isolation in dencoder
7c673cae
FG
62 void encode(bufferlist& bl) const {
63 encode_state(bl);
64 }
11fdf7f2 65 void decode(bufferlist::const_iterator& bl) {
7c673cae
FG
66 decode_state(bl);
67 }
68 void dump(Formatter *f) const;
9f95a23c 69 static void generate_test_instances(std::list<InoTable*>& ls);
7c673cae
FG
70
71 void skip_inos(inodeno_t i);
72
73 /**
74 * If the specified inode is marked as free, mark it as used.
75 * For use in tools, not normal operations.
76 *
77 * @returns true if the inode was previously marked as free
78 */
79 bool force_consume(inodeno_t ino)
80 {
81 if (free.contains(ino)) {
82 free.erase(ino);
83 return true;
84 } else {
85 return false;
86 }
87 }
88
89 /**
90 * If this ino is in this rank's range, consume up to and including it.
91 * For use in tools, when we know the max ino in use and want to make
92 * sure we're only allocating new inodes from above it.
93 *
94 * @return true if the table was modified
95 */
11fdf7f2 96 bool force_consume_to(inodeno_t ino);
9f95a23c
TL
97
98 private:
99 interval_set<inodeno_t> free; // unused ids
100 interval_set<inodeno_t> projected_free;
7c673cae
FG
101};
102WRITE_CLASS_ENCODER(InoTable)
103
104#endif