-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextent_server.cc
More file actions
79 lines (69 loc) · 1.96 KB
/
extent_server.cc
File metadata and controls
79 lines (69 loc) · 1.96 KB
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
// the extent server implementation
#include "extent_server.h"
#include <sstream>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
extent_server::extent_server() {
}
int extent_server::put(extent_protocol::extentid_t id, std::string buf, int &) {
metatable_iterator miter = metadata.find(0x00000001);
if (miter == metadata.end()) {
finfo root;
root.size = 0;
root.atime = 0;
root.mtime = 0;
root.ctime = 0;
root.content = "";
metadata[0x00000001] = root;
}
miter = metadata.find(id);
if (miter != metadata.end()) {
metadata[id].content = buf;
metadata[id].size = buf.length();
metadata[id].mtime = time(NULL);
metadata[id].ctime = time(NULL);
} else {
finfo f;
f.content = buf;
time_t t;
time(&t);
f.atime = t;
f.mtime = t;
f.ctime = t;
f.size = buf.length();
metadata[id] = f;
}
return extent_protocol::OK;
}
int extent_server::get(extent_protocol::extentid_t id, std::string &buf) {
metatable_iterator miter = metadata.find(id);
if (miter != metadata.end()) {
metadata[id].atime = time(NULL);
buf = metadata[id].content;
return extent_protocol::OK;
} else {
return extent_protocol::IOERR;
}
}
int extent_server::getattr(extent_protocol::extentid_t id, extent_protocol::attr &a) {
metatable_iterator miter = metadata.find(id);
if (miter != metadata.end()) {
a.atime = metadata[id].atime;
a.mtime = metadata[id].mtime;
a.ctime = metadata[id].ctime;
a.size = metadata[id].size;
return extent_protocol::OK;
} else {
return extent_protocol::IOERR;
}
}
int extent_server::remove(extent_protocol::extentid_t id, int &) {
if (metadata.erase(id)) {
return extent_protocol::OK;
} else {
return extent_protocol::IOERR;
}
}