1 /*
2    Copyright 2005-2010 Jakub Kruszona-Zawadzki, Gemius SA, 2013-2014 EditShare,
3    2013-2015 Skytechnology sp. z o.o..
4 
5    This file was part of MooseFS and is part of LizardFS.
6 
7    LizardFS is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, version 3.
10 
11    LizardFS is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with LizardFS  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "common/platform.h"
23 
24 #include <map>
25 
26 #include "common/goal.h"
27 #include "master/fs_context.h"
28 #include "master/locks.h"
29 #include "master/setgoal_task.h"
30 #include "protocol/lock_info.h"
31 
32 #define DEFAULT_GOAL 1
33 #define DEFAULT_TRASHTIME 86400
34 
35 namespace FsStats {
36 enum {
37 	Statfs = 0,
38 	Getattr,
39 	Setattr,
40 	Lookup,
41 	Mkdir,
42 	Rmdir,
43 	Symlink,
44 	Readlink,
45 	Mknod,
46 	Unlink,
47 	Rename,
48 	Link,
49 	Readdir,
50 	Open,
51 	Read,
52 	Write,
53 	Size
54 };
55 }
56 
57 extern std::array<uint32_t, FsStats::Size> gFsStatsArray;
58 
59 void fs_retrieve_stats(std::array<uint32_t, FsStats::Size> &output_stats);
60 
61 const std::map<int, Goal> &fs_get_goal_definitions();
62 const Goal &fs_get_goal_definition(uint8_t goalId);
63 
64 void fs_broadcast_metadata_saved(uint8_t status);
65 
66 // Adds an entry to a changelog, updates filesystem.cc internal structures, prepends a
67 // proper timestamp to changelog entry and broadcasts it to metaloggers and shadow masters
68 void fs_changelog(uint32_t ts, const char *format, ...) __attribute__((__format__(__printf__, 2, 3)));
69 void fs_add_files_to_chunks();
70 
71 uint64_t fs_getversion();
72 uint8_t fs_repair(uint32_t rootinode, uint8_t sesflags, uint32_t inode, uint32_t uid, uint32_t gid,
73 			uint8_t correct_only, uint32_t *notchanged, uint32_t *erased, uint32_t *repaired);
74 
75 /*! \brief Perform a flock operation on filesystem
76  * Possible operations:
77  * - unlock
78  * - shared/exlusive blocking/nonblocking lock
79  * - handle interrupt
80  */
81 int fs_flock_op(const FsContext &context, uint32_t inode, uint64_t owner, uint32_t sessionid,
82 		uint32_t reqid, uint32_t msgid, uint16_t op, bool nonblocking,
83 		std::vector<FileLocks::Owner> &applied);
84 
85 /*! \brief Perform a posix lock operation on filesystem
86  * Possible operations:
87  * - unlock
88  * - shared/exlusive blocking/nonblocking lock
89  * - handle interrupt
90  */
91 int fs_posixlock_op(const FsContext &context, uint32_t inode, uint64_t start,
92 		uint64_t end, uint64_t owner, uint32_t sessionid, uint32_t reqid, uint32_t msgid,
93 		uint16_t op, bool nonblocking, std::vector<FileLocks::Owner> &applied);
94 
95 /*! \brief Perform a POSIX lock probe on filesystem
96  * \param info - wrapper around 'struct flock', filled with data appropriate with getlk standard
97  */
98 int fs_posixlock_probe(const FsContext &context, uint32_t inode, uint64_t start, uint64_t end,
99 		uint64_t owner, uint32_t sessionid, uint32_t reqid, uint32_t msgid, uint16_t op,
100 		lzfs_locks::FlockWrapper &info);
101 
102 /*! \brief Release (unlock + unqueue) all locks from a given session
103  */
104 int fs_locks_clear_session(const FsContext &context, uint8_t type, uint32_t inode,
105 		uint32_t sessionid, std::vector<FileLocks::Owner> &applied);
106 
107 /*! \brief Perform a lock management operation on inode */
108 int fs_locks_list_all(const FsContext &context, uint8_t type, bool pending,
109 		uint64_t start, uint64_t max, std::vector<lzfs_locks::Info> &locks);
110 int fs_locks_list_inode(const FsContext &context, uint8_t type, bool pending,
111 		uint32_t inode, uint64_t start, uint64_t max, std::vector<lzfs_locks::Info> &locks);
112 int fs_locks_unlock_inode(const FsContext &context, uint8_t type, uint32_t inode,
113 		std::vector<FileLocks::Owner> &applied);
114 int fs_locks_remove_pending(const FsContext &context, uint8_t type, uint64_t ownerid,
115 		uint32_t sessionid, uint32_t inode, uint64_t reqid);
116