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