1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
16 #ifndef CEPH_INOTABLE_H
17 #define CEPH_INOTABLE_H
20 #include "include/interval_set.h"
24 class InoTable : public MDSTable {
25 interval_set<inodeno_t> free; // unused ids
26 interval_set<inodeno_t> projected_free;
29 explicit InoTable(MDSRank *m) : MDSTable(m, "inotable", true) { }
31 inodeno_t project_alloc_id(inodeno_t id=0);
32 void apply_alloc_id(inodeno_t id);
34 void project_alloc_ids(interval_set<inodeno_t>& inos, int want);
35 void apply_alloc_ids(interval_set<inodeno_t>& inos);
37 void project_release_ids(interval_set<inodeno_t>& inos);
38 void apply_release_ids(interval_set<inodeno_t>& inos);
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);
44 bool repair(inodeno_t id);
45 bool is_marked_free(inodeno_t id) const;
47 const interval_set<inodeno_t> &other,
48 interval_set<inodeno_t> *intersection);
50 void reset_state() override;
51 void encode_state(bufferlist& bl) const override {
52 ENCODE_START(2, 2, bl);
56 void decode_state(bufferlist::iterator& bl) override {
57 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
59 projected_free = free;
63 // To permit enc/decoding in isolation in dencoder
64 InoTable() : MDSTable(NULL, "inotable", true) {}
65 void encode(bufferlist& bl) const {
68 void decode(bufferlist::iterator& bl) {
71 void dump(Formatter *f) const;
72 static void generate_test_instances(list<InoTable*>& ls);
74 void skip_inos(inodeno_t i);
77 * If the specified inode is marked as free, mark it as used.
78 * For use in tools, not normal operations.
80 * @returns true if the inode was previously marked as free
82 bool force_consume(inodeno_t ino)
84 if (free.contains(ino)) {
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.
97 * @return true if the table was modified
99 bool force_consume_to(inodeno_t ino)
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;
113 WRITE_CLASS_ENCODER(InoTable)