1 /*
2 Copyright 2005-2010 Jakub Kruszona-Zawadzki, Gemius SA, 2013-2016 Skytechnology sp. z o.o.
3
4 This file is part of LizardFS.
5
6 LizardFS is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3.
9
10 LizardFS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "common/platform.h"
20
21 #include "mount/client_common.h"
22 #include "mount/special_inode.h"
23
24 using namespace LizardClient;
25
26 namespace InodeMasterInfo {
lookup(const Context & ctx,Inode parent,const char * name,char attrstr[256])27 static EntryParam lookup(const Context &ctx, Inode parent, const char *name,
28 char attrstr[256]) {
29 EntryParam e;
30 e.ino = inode_;
31 e.attr_timeout = 3600.0;
32 e.entry_timeout = 3600.0;
33 attr_to_stat(inode_, attr, &e.attr);
34 stats_inc(OP_LOOKUP_INTERNAL);
35 makeattrstr(attrstr, 256, &e.attr);
36 oplog_printf(ctx, "lookup (%lu,%s) (internal node: MASTERINFO): OK (%.1f,%lu,%.1f,%s)",
37 (unsigned long int)parent,
38 name,
39 e.entry_timeout,
40 (unsigned long int)e.ino,
41 e.attr_timeout,
42 attrstr);
43 return e;
44 }
45 } // InodeMasterInfo
46
47 namespace InodeStats {
lookup(const Context & ctx,Inode parent,const char * name,char attrstr[256])48 static EntryParam lookup(const Context &ctx, Inode parent, const char *name,
49 char attrstr[256]) {
50 EntryParam e;
51 e.ino = inode_;
52 e.attr_timeout = 3600.0;
53 e.entry_timeout = 3600.0;
54 attr_to_stat(inode_, attr, &e.attr);
55 stats_inc(OP_LOOKUP_INTERNAL);
56 makeattrstr(attrstr, 256, &e.attr);
57 oplog_printf(ctx, "lookup (%lu,%s) (internal node: STATS): OK (%.1f,%lu,%.1f,%s)",
58 (unsigned long int)parent,
59 name,
60 e.entry_timeout,
61 (unsigned long int)e.ino,
62 e.attr_timeout,
63 attrstr);
64 return e;
65 }
66 } //InodeStats
67
68 namespace InodeOplog {
lookup(const Context & ctx,Inode parent,const char * name,char attrstr[256])69 static EntryParam lookup(const Context &ctx, Inode parent, const char *name,
70 char attrstr[256]) {
71 EntryParam e;
72 e.ino = inode_;
73 e.attr_timeout = 3600.0;
74 e.entry_timeout = 3600.0;
75 attr_to_stat(inode_, attr, &e.attr);
76 stats_inc(OP_LOOKUP_INTERNAL);
77 makeattrstr(attrstr, 256, &e.attr);
78 oplog_printf(ctx, "lookup (%lu,%s) (internal node: OPLOG): OK (%.1f,%lu,%.1f,%s)",
79 (unsigned long int)parent,
80 name,
81 e.entry_timeout,
82 (unsigned long int)e.ino,
83 e.attr_timeout,
84 attrstr);
85 return e;
86 }
87 } // InodeOplog
88
89 namespace InodeOphistory {
lookup(const Context & ctx,Inode parent,const char * name,char attrstr[256])90 static EntryParam lookup(const Context &ctx, Inode parent, const char *name,
91 char attrstr[256]) {
92 EntryParam e;
93 e.ino = inode_;
94 e.attr_timeout = 3600.0;
95 e.entry_timeout = 3600.0;
96 attr_to_stat(inode_, attr, &e.attr);
97 stats_inc(OP_LOOKUP_INTERNAL);
98 makeattrstr(attrstr, 256, &e.attr);
99 oplog_printf(ctx, "lookup (%lu,%s) (internal node: OPHISTORY): OK (%.1f,%lu,%.1f,%s)",
100 (unsigned long int)parent,
101 name,
102 e.entry_timeout,
103 (unsigned long int)e.ino,
104 e.attr_timeout,
105 attrstr);
106 return e;
107 }
108 } // InodeOphistory
109
110 namespace InodeTweaks {
lookup(const Context & ctx,Inode parent,const char * name,char attrstr[256])111 static EntryParam lookup(const Context &ctx, Inode parent, const char *name,
112 char attrstr[256]) {
113 EntryParam e;
114 e.ino = inode_;
115 e.attr_timeout = 3600.0;
116 e.entry_timeout = 3600.0;
117 attr_to_stat(inode_, attr, &e.attr);
118 stats_inc(OP_LOOKUP_INTERNAL);
119 makeattrstr(attrstr, 256, &e.attr);
120 oplog_printf(ctx, "lookup (%lu,%s) (internal node: TWEAKS_FILE): OK (%.1f,%lu,%.1f,%s)",
121 (unsigned long int)parent,
122 name,
123 e.entry_timeout,
124 (unsigned long int)e.ino,
125 e.attr_timeout,
126 attrstr);
127 return e;
128 }
129 } // InodeTweaks
130
131 namespace InodeFileByInode {
lookup(const Context & ctx,Inode parent,const char * name,char attrstr[256])132 static EntryParam lookup(const Context &ctx, Inode parent, const char *name,
133 char attrstr[256]) {
134 EntryParam e;
135 e.ino = inode_;
136 e.attr_timeout = 3600.0;
137 e.entry_timeout = 3600.0;
138 attr_to_stat(inode_, attr, &e.attr);
139 stats_inc(OP_LOOKUP_INTERNAL);
140 makeattrstr(attrstr, 256, &e.attr);
141 oplog_printf(ctx, "lookup (%lu,%s) (internal node: FILE_BY_INODE_FILE): OK (%.1f,%lu,%.1f,%s)",
142 (unsigned long int)parent,
143 name,
144 e.entry_timeout,
145 (unsigned long int)e.ino,
146 e.attr_timeout,
147 attrstr);
148 return e;
149 }
150 } // InodeFileByInode
151
152 static const std::array<std::function<EntryParam
153 (const Context&, Inode, const char*, char[256])>, 16> funcs = {{
154 &InodeStats::lookup, //0x0U
155 &InodeOplog::lookup, //0x1U
156 &InodeOphistory::lookup, //0x2U
157 &InodeTweaks::lookup, //0x3U
158 &InodeFileByInode::lookup, //0x4U
159 nullptr, //0x5U
160 nullptr, //0x6U
161 nullptr, //0x7U
162 nullptr, //0x8U
163 nullptr, //0x9U
164 nullptr, //0xAU
165 nullptr, //0xBU
166 nullptr, //0xCU
167 nullptr, //0xDU
168 nullptr, //0xEU
169 &InodeMasterInfo::lookup //0xFU
170 }};
171
special_lookup(Inode ino,const Context & ctx,Inode parent,const char * name,char attrstr[256])172 EntryParam special_lookup(Inode ino, const Context &ctx, Inode parent, const char *name,
173 char attrstr[256]) {
174 auto func = funcs[ino - SPECIAL_INODE_BASE];
175 if (!func) {
176 lzfs_pretty_syslog(LOG_WARNING,
177 "Trying to call unimplemented 'lookup' function for special inode");
178 throw RequestException(LIZARDFS_ERROR_EINVAL);
179 }
180 return func(ctx, parent, name, attrstr);
181 }
182