]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/OpenFileTable.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / mds / OpenFileTable.h
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) 2018 Red Hat
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 #ifndef OPEN_FILE_TABLE_H
16 #define OPEN_FILE_TABLE_H
17
18 #include "mdstypes.h"
19 #include "Anchor.h"
20
21 #include "MDSContext.h"
22
23 class CDir;
24 class CInode;
25 class MDSRank;
26
27 class OpenFileTable
28 {
29 public:
30 explicit OpenFileTable(MDSRank *m);
31 ~OpenFileTable();
32
33 void add_inode(CInode *in);
34 void remove_inode(CInode *in);
35 void add_dirfrag(CDir *dir);
36 void remove_dirfrag(CDir *dir);
37 void notify_link(CInode *in);
38 void notify_unlink(CInode *in);
39 bool is_any_dirty() const { return !dirty_items.empty(); }
40
41 void commit(MDSContext *c, uint64_t log_seq, int op_prio);
42 uint64_t get_committed_log_seq() const { return committed_log_seq; }
43 uint64_t get_committing_log_seq() const { return committing_log_seq; }
44 bool is_any_committing() const { return num_pending_commit > 0; }
45
46 void load(MDSContext *c);
47 bool is_loaded() const { return load_done; }
48 void wait_for_load(MDSContext *c) {
49 ceph_assert(!load_done);
50 waiting_for_load.push_back(c);
51 }
52
53 bool get_ancestors(inodeno_t ino, vector<inode_backpointer_t>& ancestors,
54 mds_rank_t& auth_hint);
55
56 bool prefetch_inodes();
57 bool is_prefetched() const { return prefetch_state == DONE; }
58 void wait_for_prefetch(MDSContext *c) {
59 ceph_assert(!is_prefetched());
60 waiting_for_prefetch.push_back(c);
61 }
62
63 bool should_log_open(CInode *in);
64
65 void note_destroyed_inos(uint64_t seq, const vector<inodeno_t>& inos);
66 void trim_destroyed_inos(uint64_t seq);
67
68 protected:
69 friend class C_IO_OFT_Recover;
70 friend class C_IO_OFT_Load;
71 friend class C_IO_OFT_Save;
72 friend class C_IO_OFT_Journal;
73 friend class C_OFT_OpenInoFinish;
74
75 uint64_t MAX_ITEMS_PER_OBJ = g_conf().get_val<uint64_t>("osd_deep_scrub_large_omap_object_key_threshold");
76 static const unsigned MAX_OBJECTS = 1024; // (1024 * osd_deep_scrub_large_omap_object_key_threshold) items at most
77
78 static const int DIRTY_NEW = -1;
79 static const int DIRTY_UNDEF = -2;
80
81 unsigned num_pending_commit = 0;
82 void _encode_header(bufferlist& bl, int j_state);
83 void _commit_finish(int r, uint64_t log_seq, MDSContext *fin);
84 void _journal_finish(int r, uint64_t log_seq, MDSContext *fin,
85 std::map<unsigned, std::vector<ObjectOperation> >& ops);
86
87 void get_ref(CInode *in);
88 void put_ref(CInode *in);
89
90 object_t get_object_name(unsigned idx) const;
91
92 void _reset_states() {
93 omap_num_objs = 0;
94 omap_num_items.resize(0);
95 journal_state = JOURNAL_NONE;
96 loaded_journals.clear();
97 loaded_anchor_map.clear();
98 loaded_dirfrags.clear();
99 }
100 void _load_finish(int op_r, int header_r, int values_r,
101 unsigned idx, bool first, bool more,
102 bufferlist &header_bl,
103 std::map<std::string, bufferlist> &values);
104 void _recover_finish(int r);
105
106 void _open_ino_finish(inodeno_t ino, int r);
107 void _prefetch_inodes();
108 void _prefetch_dirfrags();
109
110 MDSRank *mds;
111
112 version_t omap_version = 0;
113
114 unsigned omap_num_objs = 0;
115 std::vector<unsigned> omap_num_items;
116
117 map<inodeno_t, OpenedAnchor> anchor_map;
118 set<dirfrag_t> dirfrags;
119
120 std::map<inodeno_t, int> dirty_items; // ino -> dirty state
121
122 uint64_t committed_log_seq = 0;
123 uint64_t committing_log_seq = 0;
124
125 enum {
126 JOURNAL_NONE = 0,
127 JOURNAL_START = 1,
128 JOURNAL_FINISH = 2,
129 };
130 int journal_state = 0;
131
132 std::vector<std::map<std::string, bufferlist> > loaded_journals;
133 map<inodeno_t, RecoveredAnchor> loaded_anchor_map;
134 set<dirfrag_t> loaded_dirfrags;
135 MDSContext::vec waiting_for_load;
136 bool load_done = false;
137
138 enum {
139 DIR_INODES = 1,
140 DIRFRAGS = 2,
141 FILE_INODES = 3,
142 DONE = 4,
143 };
144 unsigned prefetch_state = 0;
145 unsigned num_opening_inodes = 0;
146 MDSContext::vec waiting_for_prefetch;
147
148 std::map<uint64_t, vector<inodeno_t> > logseg_destroyed_inos;
149 std::set<inodeno_t> destroyed_inos_set;
150
151 std::unique_ptr<PerfCounters> logger;
152 };
153
154 #endif