]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: lookuphash
authorSage Weil <sage.weil@dreamhost.com>
Sat, 26 Mar 2011 21:47:52 +0000 (14:47 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Thu, 31 Mar 2011 23:07:10 +0000 (16:07 -0700)
Implement low-level lookuphash on client, for MDS testing.

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/client/Client.cc
src/client/Client.h
src/client/SyntheticClient.cc
src/client/SyntheticClient.h

index e3fa46e15d971f378fb3a9a3f9ecfc8e154a46cf..d09f2d56cb4dbcc4a1920c0f88d9b85dbc6dc541 100644 (file)
@@ -4519,6 +4519,27 @@ int Client::open(const char *relpath, int flags, mode_t mode)
   return r;
 }
 
+int Client::lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name)
+{
+  Mutex::Locker lock(client_lock);
+  dout(3) << "lookup_hash enter(" << ino << ", #" << dirino << "/" << name << ") = " << dendl;
+
+  MetaRequest *req = new MetaRequest(CEPH_MDS_OP_LOOKUPHASH);
+  filepath path(ino);
+  req->set_filepath(path);
+
+  uint32_t h = ceph_str_hash(0, name, strlen(name));
+  char f[30];
+  sprintf(f, "%d", h);
+  filepath path2(dirino);
+  path2.push_dentry(string(f));
+  req->set_filepath2(path2);
+
+  int r = make_request(req, -1, -1, NULL, rand() % mdsmap->get_num_mds());
+  dout(3) << "lookup_hash exit(" << ino << ", #" << dirino << "/" << name << ") = " << r << dendl;
+  return r;
+}
+
 Fh *Client::_create_fh(Inode *in, int flags, int cmode)
 {
   // yay
index f35b8bce7b9137799350dc30ffc5e8eb17549eda..900d21cbc167eb4e4112c4a8bf3fde61fb52cc60 100644 (file)
@@ -1282,6 +1282,7 @@ public:
   // file ops
   int mknod(const char *path, mode_t mode, dev_t rdev=0);
   int open(const char *path, int flags, mode_t mode=0);
+  int lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name);
   int close(int fd);
   loff_t lseek(int fd, loff_t offset, int whence);
   int read(int fd, char *buf, loff_t size, loff_t offset=-1);
index 418aac59ea074117f16c077440bf095b4d1be1f3..e96560232ca26d0fe7bddba2e537b2bf24634d70 100644 (file)
@@ -238,6 +238,12 @@ void parse_syn_options(vector<const char*>& args)
        syn_sargs.push_back(args[++i]);
        syn_iargs.push_back(atoi(args[++i]));
 
+      } else if (strcmp(args[i], "lookuphash") == 0) {
+       syn_modes.push_back(SYNCLIENT_MODE_LOOKUPHASH);
+       syn_sargs.push_back(args[++i]);
+       syn_sargs.push_back(args[++i]);
+       syn_sargs.push_back(args[++i]);
+
       } else if (strcmp(args[i], "chunkfile") == 0) {
        syn_modes.push_back(SYNCLIENT_MODE_CHUNK);
        syn_sargs.push_back(args[++i]);
@@ -860,6 +866,21 @@ int SyntheticClient::run()
        did_run_me();
       }
       break;
+
+    case SYNCLIENT_MODE_LOOKUPHASH:
+      {
+       inodeno_t ino;
+       string iname = get_sarg(0);
+       sscanf(iname.c_str(), "%llx", (long long unsigned*)&ino.val);
+       inodeno_t dirino;
+       string diname = get_sarg(0);
+       sscanf(diname.c_str(), "%llx", (long long unsigned*)&dirino.val);
+       string name = get_sarg(0);
+       if (run_me()) {
+         lookup_hash(ino, dirino, name.c_str());
+       }
+      }
+      break;
       
     case SYNCLIENT_MODE_MKSNAP:
       {
@@ -3313,6 +3334,13 @@ void SyntheticClient::import_find(const char *base, const char *find, bool data)
 }
 
 
+int SyntheticClient::lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name)
+{
+  int r = client->lookup_hash(ino, dirino, name);
+  dout(0) << "lookup_hash(" << ino << ", #" << dirino << "/" << name << ") = " << r << dendl;
+  return r;
+}
+
 int SyntheticClient::chunk_file(string &filename)
 {
   int fd = client->open(filename.c_str(), O_RDONLY);
index 3067d5e5139f45a55b6c492e21043df2b05876ee..475ea7c43becd59c0b9144ddeb6ce24b6c4c464f 100644 (file)
@@ -73,6 +73,7 @@
 
 #define SYNCLIENT_MODE_DUMP 63
 
+#define SYNCLIENT_MODE_LOOKUPHASH     70
 
 #define SYNCLIENT_MODE_TRUNCATE     200
 
@@ -89,6 +90,7 @@
 #define SYNCLIENT_MODE_MKSNAPFILE 1002
 
 
+
 void parse_syn_options(vector<const char*>& args);
 
 class SyntheticClient {
@@ -260,6 +262,8 @@ class SyntheticClient {
 
   void import_find(const char *basedir, const char *find, bool writedata);
 
+  int lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name);
+
   int chunk_file(string &filename);
 
   void mksnap(const char *base, const char *name);