-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfs_common.hpp
137 lines (113 loc) · 3.3 KB
/
pfs_common.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#pragma once
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <sys/types.h>
#include <unistd.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <bits/stdc++.h>
#include <semaphore.h>
#include <bits/stdc++.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <map>
#include <errno.h>
#include <memory>
#include <semaphore.h>
#include <unordered_map>
#include "pfs_config.hpp"
#define ll long long int
#define CACHE_ENABLED 1
using namespace std;
struct fileopeninfo {
int fd;
int mode;
};
struct tokeninterval {
ll startoffset;
ll endoffset;
bool operator<(const tokeninterval& other) const {
return (startoffset < other.startoffset) || ((startoffset == other.startoffset) && (endoffset < other.endoffset));
}
void print() {
cout<<startoffset << " " << endoffset <<endl;
}
};
struct CacheBlock {
int fd;
ll blocknum;
bool operator<(const CacheBlock& other) const {
return (fd < other.fd) || ((fd == other.fd) && (blocknum < other.blocknum));
}
};
struct heldorrequestedtokenbyclient {
int fd;
int clientid;
vector<struct tokeninterval> tokens;
int type;
void print() {
cout << "FD: " << fd << " " << "clientid:" << clientid << "TYPE:" << type <<endl;
for (int i = 0; i < (int)tokens.size(); i++) tokens[i].print();
}
};
struct requestedtokenbyclient {
struct heldorrequestedtokenbyclient r;
mutex mlock;
};
struct pfs_filerecipe
{
int stripe_width;
vector<int> servers;
map<ll, int> blockToServerid;
int getSid(ll blocknum) {
ll x = (blocknum % ((ll) STRIPE_BLOCKS * stripe_width));
int xx = (x / (int) STRIPE_BLOCKS);
return servers[xx];
}
};
struct pfs_metadata
{
// Given metadata
char filename[256];
uint64_t file_size;
time_t ctime;
time_t mtime;
struct pfs_filerecipe recipe;
// Additional metadata
int fd;
int accessed; //pfs_open increase this, pfs-close decreses this
};
struct pfs_execstat
{
long num_read_hits;
long num_write_hits;
long num_evictions;
long num_writebacks;
long num_invalidations;
long num_close_writebacks;
long num_close_evictions;
};
std::string getMyHostname();
std::string getMyIP();
std::string getMyPort(std::string hostnameorip);
int isMetaServer(std::string hostnameorip);
int isFileServer(std::string hostnameorip);
string getFileServer(int serverid);
std::string getMetaServerAddress();
time_t getCurTime();
vector<struct tokeninterval> missingTokenintervals(vector<struct tokeninterval> list, struct tokeninterval required);
bool conflict(struct heldorrequestedtokenbyclient p, struct heldorrequestedtokenbyclient q);
struct heldorrequestedtokenbyclient exclude(struct heldorrequestedtokenbyclient p, struct heldorrequestedtokenbyclient q);
vector<struct tokeninterval> excludetokeninterval(struct tokeninterval original, struct tokeninterval exclude);
vector<struct tokeninterval> excludetokenintervals(vector<struct tokeninterval> originals, struct tokeninterval exclude);
void printtokenlist(vector<struct tokeninterval> v);
void printtokenlistMeta(vector<struct heldorrequestedtokenbyclient> v);
map<int, string> getFileServers();
void setpfslist(string x);