From 949863a216f435019f11ef06cd733d17a1ca4a86 Mon Sep 17 00:00:00 2001 From: sageweil Date: Tue, 21 Aug 2007 23:49:29 +0000 Subject: [PATCH] trace now reads from file, implemented ll_flush stub (still a noop) git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1650 29311d96-e01e-0410-9327-a35deaab8ce9 --- branches/sage/mds/client/Client.cc | 16 +++ branches/sage/mds/client/Client.h | 2 + branches/sage/mds/client/SyntheticClient.cc | 6 +- branches/sage/mds/client/Trace.cc | 112 ++++++-------------- branches/sage/mds/client/Trace.h | 32 ++---- 5 files changed, 63 insertions(+), 105 deletions(-) diff --git a/branches/sage/mds/client/Client.cc b/branches/sage/mds/client/Client.cc index a903d6417efb5..07b22b2a97ae9 100644 --- a/branches/sage/mds/client/Client.cc +++ b/branches/sage/mds/client/Client.cc @@ -2991,6 +2991,12 @@ int Client::_write(Fh *f, off_t offset, off_t size, const char *buf) return totalwritten; } +int Client::_flush(Fh *f) +{ + // no-op, for now. hrm. + return 0; +} + int Client::truncate(const char *relpath, off_t length) { @@ -3725,6 +3731,16 @@ int Client::ll_write(Fh *fh, off_t off, off_t len, const char *data) return _write(fh, off, len, data); } +int Client::ll_flush(Fh *fh) +{ + Mutex::Locker lock(client_lock); + dout(3) << "ll_flush " << fh << endl; + tout << "ll_flush" << endl; + tout << (unsigned long)fh << endl; + + return _flush(fh); +} + int Client::ll_release(Fh *fh) { Mutex::Locker lock(client_lock); diff --git a/branches/sage/mds/client/Client.h b/branches/sage/mds/client/Client.h index e7fafccc4b741..58a4908eebf38 100644 --- a/branches/sage/mds/client/Client.h +++ b/branches/sage/mds/client/Client.h @@ -706,6 +706,7 @@ private: int _release(Fh *fh); int _read(Fh *fh, off_t offset, off_t size, bufferlist *bl); int _write(Fh *fh, off_t offset, off_t size, const char *buf); + int _flush(Fh *fh); int _truncate(const char *file, off_t length); int _ftruncate(Fh *fh, off_t length); int _fsync(Fh *fh, bool syncdataonly); @@ -803,6 +804,7 @@ public: int ll_create(inodeno_t parent, const char *name, mode_t mode, int flags, struct stat *attr, Fh **fh); int ll_read(Fh *fh, off_t off, off_t len, bufferlist *bl); int ll_write(Fh *fh, off_t off, off_t len, const char *data); + int ll_flush(Fh *fh); int ll_release(Fh *fh); int ll_statfs(inodeno_t, struct statvfs *stbuf); diff --git a/branches/sage/mds/client/SyntheticClient.cc b/branches/sage/mds/client/SyntheticClient.cc index 68d3f3daf787c..58a67f226e981 100644 --- a/branches/sage/mds/client/SyntheticClient.cc +++ b/branches/sage/mds/client/SyntheticClient.cc @@ -911,7 +911,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) const char *v = t.get_string(buf, p); int64_t ri = t.get_int(); struct stat attr; - if (client->ll_symlink(i, n, v, &attr) == 0) + if (client->ll_symlink(ll_inos[i], n, v, &attr) == 0) ll_inos[ri] = attr.st_ino; } else if (strcmp(op, "ll_unlink") == 0) { int64_t i = t.get_int(); @@ -987,6 +987,10 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) } else { client->ll_write(fh, off+size, 0, NULL); } + } else if (strcmp(op, "ll_flush") == 0) { + int64_t f = t.get_int(); + Fh *fh = ll_files[f]; + client->ll_flush(fh); } else if (strcmp(op, "ll_release") == 0) { int64_t f = t.get_int(); Fh *fh = ll_files[f]; diff --git a/branches/sage/mds/client/Trace.cc b/branches/sage/mds/client/Trace.cc index 06a6447823036..f6d244f4307df 100644 --- a/branches/sage/mds/client/Trace.cc +++ b/branches/sage/mds/client/Trace.cc @@ -31,96 +31,50 @@ using namespace __gnu_cxx; #include -Mutex trace_lock; - -class TokenList { -public: - string filename; - char *data; - int len; - list tokens; - - int ref; - - TokenList() : data(0), ref(0) {} - ~TokenList() { - delete[] data; - } -}; - -map traces; - // Trace::Trace(const char* f) { - string filename = f; - - trace_lock.Lock(); - - if (traces.count(filename)) - tl = traces[filename]; - else { - tl = new TokenList; - tl->filename = filename; - - // open file - crope cr; - int fd = open(filename.c_str(), O_RDONLY); - assert(fd > 0); - char buf[100]; - while (1) { - int r = read(fd, buf, 100); - if (r == 0) break; - assert(r > 0); - cr.append(buf, r); - } - close(fd); - - // copy - tl->len = cr.length()+1; - tl->data = new char[tl->len]; - memcpy(tl->data, cr.c_str(), cr.length()); - tl->data[tl->len-1] = '\n'; - - // index! - int o = 0; - while (o < tl->len) { - char *n = tl->data + o; - - // find newline - while (tl->data[o] != '\n') o++; - assert(tl->data[o] == '\n'); - tl->data[o] = 0; - - if (tl->data + o > n) tl->tokens.push_back(n); - o++; - } - - dout(1) << "trace " << filename << " loaded with " << tl->tokens.size() << " tokens" << endl; - traces[filename] = tl; + fs.open(f); + if (!fs.is_open()) { + dout(0) << "** unable to open trace file " << f << endl; + assert(0); } - - tl->ref++; - - trace_lock.Unlock(); + dout(2) << "opened traced file '" << f << "'" << endl; } Trace::~Trace() { - trace_lock.Lock(); - - tl->ref--; - if (tl->ref == 0) { - traces.erase(tl->filename); - delete tl; - } - - trace_lock.Unlock(); + fs.close(); } -list& Trace::get_list() +void Trace::start() { - return tl->tokens; + //cout << "start" << endl; + fs.seekg(0); + + // read first line + getline(fs, line); + + _line = 1; +} + +const char *Trace::get_string(char *buf, const char *prefix) +{ + if (prefix && + strstr(buf, "/prefix") == buf) { + strcpy(buf, prefix); + strcpy(buf + strlen(prefix), + line.c_str() + strlen("/prefix")); + } else { + strcpy(buf, line.c_str()); + } + //cout << "get_string got " << buf << endl; + + // read next line (and detect eof early) + _line++; + getline(fs, line); + //cout << "next line is " << line << endl; + return buf; } diff --git a/branches/sage/mds/client/Trace.h b/branches/sage/mds/client/Trace.h index 5243f28d4a56c..492795ed598c9 100644 --- a/branches/sage/mds/client/Trace.h +++ b/branches/sage/mds/client/Trace.h @@ -19,6 +19,7 @@ #include #include #include +#include using namespace std; /* @@ -29,46 +30,27 @@ using namespace std; */ class Trace { - class TokenList *tl; int _line; + ifstream fs; + string line; public: Trace(const char* filename); ~Trace(); int get_line() { return _line; } - list& get_list(); - list::iterator _cur; - list::iterator _end; + void start(); - void start() { - _cur = get_list().begin(); - _end = get_list().end(); - _line = 1; - } + const char *get_string(char *buf, const char *prefix); - const char *get_string(char *buf, const char *prefix) { - assert(_cur != _end); - const char *s = *_cur; - _cur++; _line++; - if (prefix) { - if (strstr(s, "/prefix") == s || - strstr(s, "/prefix") == s+1) { - strcpy(buf, prefix); - strcpy(buf + strlen(prefix), - s + strlen("/prefix")); - s = (const char*)buf; - } - } - return s; - } __int64_t get_int() { char buf[20]; return atoll(get_string(buf, 0)); } bool end() { - return _cur == _end; + return fs.eof(); + //return _cur == _end; } }; -- 2.39.5