return totalwritten;
}
+int Client::_flush(Fh *f)
+{
+ // no-op, for now. hrm.
+ return 0;
+}
+
int Client::truncate(const char *relpath, off_t length)
{
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);
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);
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);
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();
} 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];
#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;
}
#include <cassert>
#include <list>
#include <string>
+#include <fstream>
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;
}
};