Skip to content

Commit

Permalink
Lab2 - part A ok
Browse files Browse the repository at this point in the history
  • Loading branch information
phlalx committed May 21, 2017
1 parent 6ee5e91 commit a48787c
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 50 deletions.
21 changes: 11 additions & 10 deletions extent_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
#include "rpc.h"

class extent_client {
private:
rpcc *cl;

private:
rpcc *cl;

public:
extent_client(std::string dst);
public:
extent_client(std::string dst);

extent_protocol::status get(extent_protocol::extentid_t eid,
std::string &buf);
extent_protocol::status getattr(extent_protocol::extentid_t eid,
extent_protocol::attr &a);
extent_protocol::status put(extent_protocol::extentid_t eid, std::string buf);
extent_protocol::status remove(extent_protocol::extentid_t eid);
extent_protocol::status get(extent_protocol::extentid_t eid,
std::string &buf);
extent_protocol::status getattr(extent_protocol::extentid_t eid,
extent_protocol::attr &a);
extent_protocol::status put(extent_protocol::extentid_t eid, std::string buf);
extent_protocol::status remove(extent_protocol::extentid_t eid);
};

#endif
Expand Down
2 changes: 2 additions & 0 deletions extent_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class extent_protocol {
unsigned int mtime;
unsigned int ctime;
unsigned int size;
attr() : atime(0), mtime(0), ctime(0), size(0) { }
};

};

inline unmarshall &
Expand Down
57 changes: 40 additions & 17 deletions extent_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,61 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <jsl_log.h>

extent_server::extent_server() {}


int extent_server::put(extent_protocol::extentid_t id, std::string buf, int &)
{
// You fill this in for Lab 2.
return extent_protocol::IOERR;
{
ScopedLock mut(&mutex);
// LAB 2
jsl_log(JSL_DBG_ME, "extent_server: put %llu\n", id);
Value &v = kv_store[id];
v.buf = buf;
v.attr.size = buf.size();
time_t cur_time = time(NULL);
if (v.attr.ctime == 0) {
// TODO why not set access time so it's not zero right after creation?
v.attr.ctime = cur_time;
}
v.attr.mtime = cur_time;
return extent_protocol::OK;
}

int extent_server::get(extent_protocol::extentid_t id, std::string &buf)
{
// You fill this in for Lab 2.
return extent_protocol::IOERR;
ScopedLock mut(&mutex);
// LAB 2
jsl_log(JSL_DBG_ME, "extent_server: get %llu\n", id);
if (kv_store.find(id) == kv_store.end()) {
return extent_protocol::NOENT;
}
Value &v = kv_store[id];
buf = v.buf;
v.attr.atime = time(NULL);
return extent_protocol::OK;
}

int extent_server::getattr(extent_protocol::extentid_t id, extent_protocol::attr &a)
{
// You fill this in for Lab 2.
// You replace this with a real implementation. We send a phony response
// for now because it's difficult to get FUSE to do anything (including
// unmount) if getattr fails.
a.size = 0;
a.atime = 0;
a.mtime = 0;
a.ctime = 0;
ScopedLock mut(&mutex);
// LAB 2
jsl_log(JSL_DBG_ME, "extent_server: get attr %llu\n", id);
if (kv_store.find(id) == kv_store.end()) {
return extent_protocol::NOENT;
}
a = kv_store[id].attr;
return extent_protocol::OK;
}

int extent_server::remove(extent_protocol::extentid_t id, int &)
{
// You fill this in for Lab 2.
return extent_protocol::IOERR;
ScopedLock mut(&mutex);
// LAB 2
jsl_log(JSL_DBG_ME, "extent_server: remove %llu\n", id);
if (kv_store.find(id) == kv_store.end()) {
return extent_protocol::NOENT;
}
kv_store.erase(id);
return extent_protocol::OK;
}

9 changes: 9 additions & 0 deletions extent_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@

class extent_server {

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

struct Value {
extent_protocol::attr attr;
std::string buf;
};

std::map<extent_protocol::extentid_t, Value> kv_store;

public:
extent_server();

Expand Down
3 changes: 3 additions & 0 deletions extent_smain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "extent_server.h"
#include "jsl_log.h"

// Main loop of extent server

int
main(int argc, char *argv[])
{
jsl_set_debug(JSL_DBG_ME);
int count = 0;

if(argc != 2){
Expand Down
50 changes: 37 additions & 13 deletions fuse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
#include <fcntl.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <map>
#include "lang/verify.h"
#include "yfs_client.h"
#include "jsl_log.h"

// TODO quel est le status de cette variable ?
int myid;
yfs_client *yfs;

Expand Down Expand Up @@ -45,7 +48,7 @@ getattr(yfs_client::inum inum, struct stat &st)
bzero(&st, sizeof(st));

st.st_ino = inum;
printf("getattr %016llx %d\n", inum, yfs->isfile(inum));
jsl_log(JSL_DBG_ME, "fuse getattr %016llx %d\n", inum, yfs->isfile(inum));
if(yfs->isfile(inum)){
yfs_client::fileinfo info;
ret = yfs->getfile(inum, info);
Expand All @@ -57,7 +60,7 @@ getattr(yfs_client::inum inum, struct stat &st)
st.st_mtime = info.mtime;
st.st_ctime = info.ctime;
st.st_size = info.size;
printf(" getattr -> %llu\n", info.size);
jsl_log(JSL_DBG_ME, " getattr -> %llu\n", info.size);
} else {
yfs_client::dirinfo info;
ret = yfs->getdir(inum, info);
Expand All @@ -68,7 +71,7 @@ getattr(yfs_client::inum inum, struct stat &st)
st.st_atime = info.atime;
st.st_mtime = info.mtime;
st.st_ctime = info.ctime;
printf(" getattr -> %lu %lu %lu\n", info.atime, info.mtime, info.ctime);
jsl_log(JSL_DBG_ME, " getattr -> %lu %lu %lu\n", info.atime, info.mtime, info.ctime);
}
return yfs_client::OK;
}
Expand Down Expand Up @@ -211,6 +214,7 @@ fuseserver_write(fuse_req_t req, fuse_ino_t ino,
//
// @return yfs_client::OK on success, and EXIST if @name already exists.
//
// TODO: ne pas plutot mettre ça dans yfs ? ou alors mes fonctions ici ?
yfs_client::status
fuseserver_createhelper(fuse_ino_t parent, const char *name,
mode_t mode, struct fuse_entry_param *e)
Expand All @@ -219,14 +223,23 @@ fuseserver_createhelper(fuse_ino_t parent, const char *name,
e->attr_timeout = 0.0;
e->entry_timeout = 0.0;
e->generation = 0;
// You fill this in for Lab 2
return yfs_client::NOENT;

yfs_client::inum file_inum = 0;
int st = yfs->create(parent, name, file_inum);
if (st < 0) {
return yfs_client::EXIST;
}
e->ino = file_inum;
getattr(file_inum, e->attr);

return yfs_client::OK;
}

void
fuseserver_create(fuse_req_t req, fuse_ino_t parent, const char *name,
mode_t mode, struct fuse_file_info *fi)
{
jsl_log(JSL_DBG_ME, "fuse fuseserver_create %016lx %s\n", parent, name);
struct fuse_entry_param e;
yfs_client::status ret;
if( (ret = fuseserver_createhelper( parent, name, mode, &e )) == yfs_client::OK ) {
Expand Down Expand Up @@ -263,18 +276,27 @@ void fuseserver_mknod( fuse_req_t req, fuse_ino_t parent,
void
fuseserver_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
{
jsl_log(JSL_DBG_ME, "fuse fuseserver_lookup %016lx %s\n", parent, name);
struct fuse_entry_param e;
// In yfs, timeouts are always set to 0.0, and generations are always set to 0
e.attr_timeout = 0.0;
e.entry_timeout = 0.0;
e.generation = 0;
bool found = false;

// You fill this in for Lab 2
if (found)
yfs_client::inum file_inum = 0L;
found = yfs->lookup(parent, name, file_inum);

e.ino = file_inum;

if (found) {
yfs_client::status st = getattr(file_inum, e.attr);
VERIFY(st == yfs_client::OK);
fuse_reply_entry(req, &e);
else
}
else {
fuse_reply_err(req, ENOENT);
}
}


Expand Down Expand Up @@ -321,18 +343,19 @@ fuseserver_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
yfs_client::inum inum = ino; // req->in.h.nodeid;
struct dirbuf b;

printf("fuseserver_readdir\n");

if(!yfs->isdir(inum)){
fuse_reply_err(req, ENOTDIR);
return;
}

memset(&b, 0, sizeof(b));

std::vector<yfs_client::dirent> v;
yfs->read_dir(ino, v);

// You fill this in for Lab 2
memset(&b, 0, sizeof(b));

for (auto const &de : v) {
dirbuf_add(&b, de.name.c_str(), de.inum);
}

reply_buf_limited(req, b.p, b.size, off, size);
free(b.p);
Expand Down Expand Up @@ -413,6 +436,7 @@ struct fuse_lowlevel_ops fuseserver_oper;
int
main(int argc, char *argv[])
{
jsl_set_debug(JSL_DBG_ME);
char *mountpoint = 0;
int err = -1;
int fd;
Expand Down
Loading

0 comments on commit a48787c

Please sign in to comment.