]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
trace now reads from file, implemented ll_flush stub (still a noop)
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 21 Aug 2007 23:49:29 +0000 (23:49 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 21 Aug 2007 23:49:29 +0000 (23:49 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1650 29311d96-e01e-0410-9327-a35deaab8ce9

branches/sage/mds/client/Client.cc
branches/sage/mds/client/Client.h
branches/sage/mds/client/SyntheticClient.cc
branches/sage/mds/client/Trace.cc
branches/sage/mds/client/Trace.h

index a903d6417efb5b8abbdd5fdd69fafb6457e0f71f..07b22b2a97ae9061d9bde0c2457734a6c65f404d 100644 (file)
@@ -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);
index e7fafccc4b741c1527bbfc5a52f4c2ab9f0f6d52..58a4908eebf38886c4c87aaaf68bc58828d20a7b 100644 (file)
@@ -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);
 
index 68d3f3daf787ce7db3d2124081934a36f82a0d02..58a67f226e98137e60318d46e0ebc2befc1e99cb 100644 (file)
@@ -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];
index 06a64478230366b35647c2040a55c1f07e1d90a6..f6d244f4307df5574a398425f42cb1c54b16e4cc 100644 (file)
@@ -31,96 +31,50 @@ using namespace __gnu_cxx;
 #include <fcntl.h>
 
 
-Mutex trace_lock;
-
-class TokenList {
-public:
-  string filename;
-  char *data;
-  int len;
-  list<const char *> tokens;
-  int ref;
-
-  TokenList() : data(0), ref(0) {}
-  ~TokenList() {
-    delete[] data;
-  }
-};
-
-map<string, TokenList*> 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<const char*>& 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;
 }
index 5243f28d4a56cc432907ae1eb8791fa3f793659a..492795ed598c95792132984e6535bc411bed6007 100644 (file)
@@ -19,6 +19,7 @@
 #include <cassert>
 #include <list>
 #include <string>
+#include <fstream>
 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<const char*>& get_list();
 
-  list<const char*>::iterator _cur;
-  list<const char*>::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;
   }
 };