From 5345042e7e912f2ae8ce2c33ca9d0850cad6de6d Mon Sep 17 00:00:00 2001 From: sage Date: Sat, 10 Jul 2004 01:07:55 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@22 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/client/ClNode.h | 9 ++++++ ceph/client/Client.cc | 73 +++++++++++++++++++++++++++++++++++++++++-- ceph/client/Client.h | 1 + 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/ceph/client/ClNode.h b/ceph/client/ClNode.h index 87b4a8f7536..c06f21639d6 100644 --- a/ceph/client/ClNode.h +++ b/ceph/client/ClNode.h @@ -37,6 +37,15 @@ class ClNode : public LRUObject { } } + void full_path(string& p) { + if (parent) + parent->full_path(p); + if (p.length()) { + p.append("/"); + } + p.append(ref_name); + } + void link(string name, ClNode* node) { if (children.size() == 0) get(); diff --git a/ceph/client/Client.cc b/ceph/client/Client.cc index ceb52ed8d9d..257c97f7a4e 100644 --- a/ceph/client/Client.cc +++ b/ceph/client/Client.cc @@ -11,6 +11,8 @@ #include "../messages/MClientRequest.h" #include "../messages/MClientReply.h" +#include + Client::Client(int id, Messenger *m) { whoami = id; @@ -49,7 +51,7 @@ void Client::dispatch(Message *m) assim_reply((MClientReply*)m); delete m; - //issue_request(); + issue_request(); break; default: @@ -81,16 +83,81 @@ void Client::assim_reply(MClientReply *r) cur->ino = r->trace_ino[i]; cur->dist = r->trace_dist[i]; } + + cwd = cur; } void Client::issue_request() { + if (!cwd) cwd = root; + string p = ""; + if (cwd) { + + if (rand() % 10 > 5) { + // descend + p = "/CVS/Root"; + } else { + // ascend + if (cwd->parent) + cwd = cwd->parent; + cwd->full_path(p); + } + } + + send_request(p); // root, if !cwd +} + +void Client::send_request(string& p) +{ + MClientRequest *req = new MClientRequest(tid++, MDS_OP_STAT); req->ino = 1; - req->path = "/CVS/Root"; + req->path = p; + + // direct it + int mds = 0; + + if (root) { + int off = 0; + ClNode *cur = root; + while (off < req->path.length()) { + int nextslash = req->path.find('/', off); + if (nextslash == off) { + off++; + continue; + } + if (nextslash < 0) + nextslash = req->path.length(); // no more slashes + + string dname = req->path.substr(off,nextslash-off); + cout << "//path segment is " << dname << endl; + + ClNode *n = cur->lookup(dname); + if (n) { + cur = n; + off = nextslash+1; + } else { + cout << " don't have it. " << endl; + int b = cur->dist.size(); + //cout << " b is " << b << endl; + for (int i=0; idist[i]) { + mds = i; + break; + } + } + break; + } + } + } else { + // we need the root inode + mds = 0; + } + + cout << "client" << whoami << " sending req to mds " << mds << " for " << req->path << endl; messenger->send_message(req, - MSG_ADDR_MDS(0), MDS_PORT_SERVER, + MSG_ADDR_MDS(mds), MDS_PORT_SERVER, 0); } diff --git a/ceph/client/Client.h b/ceph/client/Client.h index 8e5388b336f..6734ee546bf 100644 --- a/ceph/client/Client.h +++ b/ceph/client/Client.h @@ -35,6 +35,7 @@ class Client : public Dispatcher { virtual void assim_reply(MClientReply*); virtual void issue_request(); + virtual void send_request(string& p); };