Skip to content

Commit 55145e6

Browse files
committed
initial with lab1
0 parents  commit 55145e6

38 files changed

+5226
-0
lines changed

Diff for: GNUmakefile

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
LAB=1
2+
SOL=0
3+
RPC=./rpc
4+
LAB1GE=$(shell expr $(LAB) \>\= 1)
5+
LAB2GE=$(shell expr $(LAB) \>\= 2)
6+
LAB3GE=$(shell expr $(LAB) \>\= 3)
7+
LAB4GE=$(shell expr $(LAB) \>\= 4)
8+
LAB5GE=$(shell expr $(LAB) \>\= 5)
9+
LAB6GE=$(shell expr $(LAB) \>\= 6)
10+
LAB7GE=$(shell expr $(LAB) \>\= 7)
11+
CXXFLAGS = -g -MMD -Wall -I. -I$(RPC) -DLAB=$(LAB) -DSOL=$(SOL) -D_FILE_OFFSET_BITS=64
12+
13+
ifeq ($(shell uname -s),Darwin)
14+
MACFLAGS= -D__FreeBSD__=10
15+
else
16+
MACFLAGS=
17+
endif
18+
LDFLAGS = -L. -L/usr/local/lib
19+
LDLIBS = -lpthread
20+
21+
LDLIBS += $(shell test -f `gcc -print-file-name=librt.so` && echo -lrt)
22+
LDLIBS += $(shell test -f `gcc -print-file-name=libdl.so` && echo -ldl)
23+
CC = g++
24+
CXX = g++
25+
26+
lab: lab$(LAB)
27+
lab1: lab1_tester
28+
lab2: yfs_client
29+
lab3: yfs_client extent_server lock_server test-lab-3-b test-lab-3-c
30+
lab4: yfs_client extent_server lock_server lock_tester test-lab-3-b\
31+
test-lab-3-c
32+
lab5: yfs_client extent_server lock_server test-lab-3-b test-lab-3-c
33+
lab6: lock_server rsm_tester
34+
lab7: lock_tester lock_server rsm_tester
35+
36+
hfiles1=rpc/fifo.h rpc/connection.h rpc/rpc.h rpc/marshall.h rpc/method_thread.h\
37+
rpc/thr_pool.h rpc/pollmgr.h rpc/jsl_log.h rpc/slock.h rpc/rpctest.cc\
38+
lock_protocol.h lock_server.h lock_client.h gettime.h gettime.cc lang/verify.h \
39+
lang/algorithm.h
40+
hfiles2=yfs_client.h extent_client.h extent_protocol.h extent_server.h
41+
hfiles3=lock_client_cache.h lock_server_cache.h handle.h tprintf.h
42+
hfiles4=log.h rsm.h rsm_protocol.h config.h paxos.h paxos_protocol.h rsm_state_transfer.h rsmtest_client.h tprintf.h
43+
hfiles5=rsm_state_transfer.h rsm_client.h
44+
rsm_files = rsm.cc paxos.cc config.cc log.cc handle.cc
45+
46+
rpclib=rpc/rpc.cc rpc/connection.cc rpc/pollmgr.cc rpc/thr_pool.cc rpc/jsl_log.cc gettime.cc
47+
rpc/librpc.a: $(patsubst %.cc,%.o,$(rpclib))
48+
rm -f $@
49+
ar cq $@ $^
50+
ranlib rpc/librpc.a
51+
52+
rpc/rpctest=rpc/rpctest.cc
53+
rpc/rpctest: $(patsubst %.cc,%.o,$(rpctest)) rpc/librpc.a
54+
55+
lock_demo=lock_demo.cc lock_client.cc
56+
lock_demo : $(patsubst %.cc,%.o,$(lock_demo)) rpc/librpc.a
57+
58+
lock_tester=lock_tester.cc lock_client.cc
59+
ifeq ($(LAB4GE),1)
60+
lock_tester += lock_client_cache.cc
61+
endif
62+
ifeq ($(LAB7GE),1)
63+
lock_tester+=rsm_client.cc handle.cc lock_client_cache_rsm.cc
64+
endif
65+
lock_tester : $(patsubst %.cc,%.o,$(lock_tester)) rpc/librpc.a
66+
67+
lock_server=lock_server.cc lock_smain.cc
68+
ifeq ($(LAB4GE),1)
69+
lock_server+=lock_server_cache.cc handle.cc
70+
endif
71+
ifeq ($(LAB6GE),1)
72+
lock_server+= $(rsm_files)
73+
endif
74+
ifeq ($(LAB7GE),1)
75+
lock_server+= lock_server_cache_rsm.cc
76+
endif
77+
78+
lock_server : $(patsubst %.cc,%.o,$(lock_server)) rpc/librpc.a
79+
80+
lab1_tester=lab1_tester.cc extent_client.cc extent_server.cc inode_manager.cc
81+
lab1_tester : $(patsubst %.cc,%.o,$(lab1_tester))
82+
yfs_client=yfs_client.cc extent_client.cc fuse.cc extent_server.cc inode_manager.cc
83+
ifeq ($(LAB3GE),1)
84+
yfs_client += lock_client.cc
85+
endif
86+
ifeq ($(LAB7GE),1)
87+
yfs_client += rsm_client.cc lock_client_cache_rsm.cc
88+
endif
89+
ifeq ($(LAB4GE),1)
90+
yfs_client += lock_client_cache.cc
91+
endif
92+
yfs_client : $(patsubst %.cc,%.o,$(yfs_client)) rpc/librpc.a
93+
94+
extent_server=extent_server.cc extent_smain.cc
95+
extent_server : $(patsubst %.cc,%.o,$(extent_server)) rpc/librpc.a
96+
97+
test-lab-3-b=test-lab-3-b.c
98+
test-lab-3-b: $(patsubst %.c,%.o,$(test_lab_4-b)) rpc/librpc.a
99+
100+
test-lab-3-c=test-lab-3-c.c
101+
test-lab-4-c: $(patsubst %.c,%.o,$(test_lab_4-c)) rpc/librpc.a
102+
103+
rsm_tester=rsm_tester.cc rsmtest_client.cc
104+
rsm_tester: $(patsubst %.cc,%.o,$(rsm_tester)) rpc/librpc.a
105+
106+
%.o: %.cc
107+
$(CXX) $(CXXFLAGS) -c $< -o $@
108+
109+
fuse.o: fuse.cc
110+
$(CXX) -c $(CXXFLAGS) $(FUSEFLAGS) $(MACFLAGS) $<
111+
112+
# mklab.inc is needed by 6.824 staff only. Just ignore it.
113+
-include mklab.inc
114+
115+
-include *.d
116+
-include rpc/*.d
117+
118+
clean_files=rpc/rpctest rpc/*.o rpc/*.d rpc/librpc.a *.o *.d yfs_client extent_server lock_server lock_tester lock_demo rpctest test-lab-3-b test-lab-3-c rsm_tester lab1_tester
119+
.PHONY: clean handin
120+
clean:
121+
rm $(clean_files) -rf
122+
123+
handin_ignore=$(clean_files) core* *log
124+
handin_file=lab$(LAB).tgz
125+
labdir=$(shell basename $(PWD))
126+
handin:
127+
@bash -c "cd ../; tar -X <(tr ' ' '\n' < <(echo '$(handin_ignore)')) -czvf $(handin_file) $(labdir); mv $(handin_file) $(labdir); cd $(labdir)"
128+
@echo Please modify lab1.tgz to lab1_[your student id].tgz and upload it to ftp://ytliu.cc:[email protected]/upload/
129+
@echo Thanks!

Diff for: extent_client.cc

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RPC stubs for clients to talk to extent_server
2+
3+
#include "extent_client.h"
4+
#include <sstream>
5+
#include <iostream>
6+
#include <stdio.h>
7+
#include <unistd.h>
8+
#include <time.h>
9+
10+
extent_client::extent_client()
11+
{
12+
es = new extent_server();
13+
}
14+
15+
extent_protocol::status
16+
extent_client::create(uint32_t type, extent_protocol::extentid_t &id)
17+
{
18+
extent_protocol::status ret = extent_protocol::OK;
19+
ret = es->create(type, id);
20+
return ret;
21+
}
22+
23+
extent_protocol::status
24+
extent_client::get(extent_protocol::extentid_t eid, std::string &buf)
25+
{
26+
extent_protocol::status ret = extent_protocol::OK;
27+
ret = es->get(eid, buf);
28+
return ret;
29+
}
30+
31+
extent_protocol::status
32+
extent_client::getattr(extent_protocol::extentid_t eid,
33+
extent_protocol::attr &attr)
34+
{
35+
extent_protocol::status ret = extent_protocol::OK;
36+
ret = es->getattr(eid, attr);
37+
return ret;
38+
}
39+
40+
extent_protocol::status
41+
extent_client::put(extent_protocol::extentid_t eid, std::string buf)
42+
{
43+
extent_protocol::status ret = extent_protocol::OK;
44+
int r;
45+
ret = es->put(eid, buf, r);
46+
return ret;
47+
}
48+
49+
extent_protocol::status
50+
extent_client::remove(extent_protocol::extentid_t eid)
51+
{
52+
extent_protocol::status ret = extent_protocol::OK;
53+
int r;
54+
ret = es->remove(eid, r);
55+
return ret;
56+
}
57+
58+

Diff for: extent_client.d

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extent_client.o: extent_client.cc extent_client.h extent_protocol.h \
2+
rpc/rpc.h rpc/thr_pool.h rpc/fifo.h rpc/slock.h lang/verify.h \
3+
rpc/marshall.h lang/algorithm.h rpc/connection.h rpc/pollmgr.h \
4+
extent_server.h inode_manager.h

Diff for: extent_client.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// extent client interface.
2+
3+
#ifndef extent_client_h
4+
#define extent_client_h
5+
6+
#include <string>
7+
#include "extent_protocol.h"
8+
#include "extent_server.h"
9+
10+
class extent_client {
11+
private:
12+
extent_server *es;
13+
14+
public:
15+
extent_client();
16+
17+
extent_protocol::status create(uint32_t type, extent_protocol::extentid_t &eid);
18+
extent_protocol::status get(extent_protocol::extentid_t eid,
19+
std::string &buf);
20+
extent_protocol::status getattr(extent_protocol::extentid_t eid,
21+
extent_protocol::attr &a);
22+
extent_protocol::status put(extent_protocol::extentid_t eid, std::string buf);
23+
extent_protocol::status remove(extent_protocol::extentid_t eid);
24+
};
25+
26+
#endif
27+

Diff for: extent_client.o

77.9 KB
Binary file not shown.

Diff for: extent_protocol.h

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// extent wire protocol
2+
3+
#ifndef extent_protocol_h
4+
#define extent_protocol_h
5+
6+
#include "rpc.h"
7+
8+
class extent_protocol {
9+
public:
10+
typedef int status;
11+
typedef unsigned long long extentid_t;
12+
enum xxstatus { OK, RPCERR, NOENT, IOERR };
13+
enum rpc_numbers {
14+
put = 0x6001,
15+
get,
16+
getattr,
17+
remove
18+
};
19+
20+
enum types {
21+
T_DIR = 1,
22+
T_FILE
23+
};
24+
25+
struct attr {
26+
uint32_t type;
27+
unsigned int atime;
28+
unsigned int mtime;
29+
unsigned int ctime;
30+
unsigned int size;
31+
};
32+
};
33+
34+
inline unmarshall &
35+
operator>>(unmarshall &u, extent_protocol::attr &a)
36+
{
37+
u >> a.type;
38+
u >> a.atime;
39+
u >> a.mtime;
40+
u >> a.ctime;
41+
u >> a.size;
42+
return u;
43+
}
44+
45+
inline marshall &
46+
operator<<(marshall &m, extent_protocol::attr a)
47+
{
48+
m << a.type;
49+
m << a.atime;
50+
m << a.mtime;
51+
m << a.ctime;
52+
m << a.size;
53+
return m;
54+
}
55+
56+
#endif

Diff for: extent_server.cc

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// the extent server implementation
2+
3+
#include "extent_server.h"
4+
#include <sstream>
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include <unistd.h>
8+
#include <sys/types.h>
9+
#include <sys/stat.h>
10+
#include <fcntl.h>
11+
12+
extent_server::extent_server()
13+
{
14+
im = new inode_manager();
15+
}
16+
17+
int extent_server::create(uint32_t type, extent_protocol::extentid_t &id)
18+
{
19+
// alloc a new inode and return inum
20+
printf("extent_server: create inode\n");
21+
id = im->alloc_inode(type);
22+
23+
return extent_protocol::OK;
24+
}
25+
26+
int extent_server::put(extent_protocol::extentid_t id, std::string buf, int &)
27+
{
28+
id &= 0x7fffffff;
29+
30+
const char * cbuf = buf.c_str();
31+
int size = buf.size();
32+
im->write_file(id, cbuf, size);
33+
34+
return extent_protocol::OK;
35+
}
36+
37+
int extent_server::get(extent_protocol::extentid_t id, std::string &buf)
38+
{
39+
printf("extent_server: get %lld\n", id);
40+
41+
id &= 0x7fffffff;
42+
43+
int size = 0;
44+
char *cbuf = NULL;
45+
46+
im->read_file(id, &cbuf, &size);
47+
if (size == 0)
48+
buf = "";
49+
else {
50+
buf.assign(cbuf, size);
51+
free(cbuf);
52+
}
53+
54+
return extent_protocol::OK;
55+
}
56+
57+
int extent_server::getattr(extent_protocol::extentid_t id, extent_protocol::attr &a)
58+
{
59+
printf("extent_server: getattr %lld\n", id);
60+
61+
id &= 0x7fffffff;
62+
63+
extent_protocol::attr attr;
64+
memset(&attr, 0, sizeof(attr));
65+
im->getattr(id, attr);
66+
a = attr;
67+
68+
return extent_protocol::OK;
69+
}
70+
71+
int extent_server::remove(extent_protocol::extentid_t id, int &)
72+
{
73+
printf("extent_server: write %lld\n", id);
74+
75+
id &= 0x7fffffff;
76+
im->remove_file(id);
77+
78+
return extent_protocol::OK;
79+
}
80+

Diff for: extent_server.d

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extent_server.o: extent_server.cc extent_server.h extent_protocol.h \
2+
rpc/rpc.h rpc/thr_pool.h rpc/fifo.h rpc/slock.h lang/verify.h \
3+
rpc/marshall.h lang/algorithm.h rpc/connection.h rpc/pollmgr.h \
4+
inode_manager.h

0 commit comments

Comments
 (0)