From a01c764c1ea693db0d4cb513f315d4af7468ff23 Mon Sep 17 00:00:00 2001 From: sage Date: Wed, 6 Jul 2005 04:41:06 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@402 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/client/Client.cc | 14 ++++++++---- ceph/client/Client.h | 16 ++++++++++++++ ceph/client/SyntheticClient.cc | 39 ++++++++++++++++++++-------------- ceph/client/SyntheticClient.h | 20 +++++++++++++---- ceph/common/LogType.h | 24 ++++++++++++--------- ceph/common/Logger.cc | 18 +++++++++------- ceph/common/Logger.h | 2 +- ceph/config.cc | 17 +++++++++------ ceph/config.h | 1 + ceph/msg/FakeMessenger.cc | 6 +++--- 10 files changed, 104 insertions(+), 53 deletions(-) diff --git a/ceph/client/Client.cc b/ceph/client/Client.cc index b7f86543bb0..c3c5535ba66 100644 --- a/ceph/client/Client.cc +++ b/ceph/client/Client.cc @@ -21,7 +21,7 @@ #include "include/config.h" #undef dout -#define dout(l) if (l<=g_conf.debug) cout << "client" << "." << pthread_self() << " " +#define dout(l) if (l<=g_conf.debug || l<=g_conf.debug_client) cout << "client" << "." << pthread_self() << " " @@ -184,11 +184,17 @@ Inode* Client::insert_inode_info(Dir *dir, c_inode_info *in_info) } if (!dn) { + // have inode linked elsewhere? -> unlink and relink! if (inode_map.count(in_info->inode.ino)) { Inode *in = inode_map[in_info->inode.ino]; - if (in) { - dout(12) << " had ino " << in->inode.ino << " at wrong position, moving" << endl; - if (in->dn) unlink(in->dn); + assert(in); + + if (in->dn) { + dout(12) << " had ino " << in->inode.ino << " linked at wrong position, unlinking" << endl; + dn = relink(in->dn, dir, dname); + } else { + // link + dout(12) << " had ino " << in->inode.ino << " unlinked, linking" << endl; dn = link(dir, dname, in); } } diff --git a/ceph/client/Client.h b/ceph/client/Client.h index 11afd17d1af..0146a54c8a9 100644 --- a/ceph/client/Client.h +++ b/ceph/client/Client.h @@ -225,6 +225,22 @@ class Client : public Dispatcher { delete dn; } + Dentry *relink(Dentry *dn, Dir *dir, string& name) { + // first link new dn to dir + dir->dentries[name] = dn; + + // unlink from old dir + dn->dir->dentries.erase(dn->name); + if (dn->dir->is_empty()) + close_dir(dn->dir); + + // fix up dn + dn->name = name; + dn->dir = dir; + + return dn; + } + // move dentry to top of lru void touch_dn(Dentry *dn) { lru.lru_touch(dn); } diff --git a/ceph/client/SyntheticClient.cc b/ceph/client/SyntheticClient.cc index 447276f2a10..8f7ae4fe0a9 100644 --- a/ceph/client/SyntheticClient.cc +++ b/ceph/client/SyntheticClient.cc @@ -12,7 +12,7 @@ #include "include/config.h" #undef dout -#define dout(l) if (l<=g_conf.debug) cout << "synthetic" << client->get_nodeid() << " " +#define dout(l) if (l<=g_conf.debug || l<=g_conf.debug_client) cout << "synthetic" << client->get_nodeid() << " " #define DBL 2 @@ -294,13 +294,14 @@ int SyntheticClient::random_walk(int num_req) if (run_until.first && g_clock.gettimepair() > run_until) break; // ascend? - if (cwd.depth() && roll_die(.05)) { + if (cwd.depth() && roll_die(.1)) { + dout(DBL) << "die says up" << endl; up(); continue; } // descend? - if (roll_die(.5) && subdirs.size()) { + if (roll_die(.3) && subdirs.size()) { string s = get_random_subdir(); cwd.add_dentry( s ); dout(DBL) << "cd " << s << " -> " << cwd << endl; @@ -311,10 +312,11 @@ int SyntheticClient::random_walk(int num_req) int op = 0; filepath path; - if (contents.empty() && roll_die(.7)) { - if (did_readdir) + if (contents.empty() && roll_die(.3)) { + if (did_readdir) { + dout(DBL) << "empty dir, up" << endl; up(); - else + } else op = MDS_OP_READDIR; } else { op = op_dist.sample(); @@ -335,7 +337,7 @@ int SyntheticClient::random_walk(int num_req) if (contents.empty()) op = MDS_OP_READDIR; else { - + r = client->rename( get_random_sub(), make_sub("ren") ); } } @@ -407,9 +409,14 @@ int SyntheticClient::random_walk(int num_req) if (op == MDS_OP_STAT) { struct stat st; if (contents.empty()) { - if (did_readdir) - up(); - else + if (did_readdir) { + if (roll_die(.1)) { + dout(DBL) << "stat in empty dir, up" << endl; + up(); + } else { + op = MDS_OP_MKNOD; + } + } else op = MDS_OP_READDIR; } else r = client->lstat(get_random_sub(), &st); @@ -436,13 +443,13 @@ int SyntheticClient::random_walk(int num_req) // errors? if (r < 0) { // reevaluate cwd. - while (cwd.depth()) { - //if (client->lookup(cwd)) break; // it's in the cache + //while (cwd.depth()) { + //if (client->lookup(cwd)) break; // it's in the cache - //dout(DBL) << "r = " << r << ", client doesn't have " << cwd << ", cd .." << endl; - dout(DBL) << "r = " << r << ", client may not have " << cwd << ", cd .." << endl; - cwd = cwd.prefixpath(cwd.depth()-1); - } + //dout(DBL) << "r = " << r << ", client doesn't have " << cwd << ", cd .." << endl; + dout(DBL) << "r = " << r << ", client may not have " << cwd << ", cd .." << endl; + up(); + //} } } diff --git a/ceph/client/SyntheticClient.h b/ceph/client/SyntheticClient.h index 74df64fd5b3..e067c75b436 100644 --- a/ceph/client/SyntheticClient.h +++ b/ceph/client/SyntheticClient.h @@ -45,20 +45,32 @@ class SyntheticClient { return *it; } + + filepath n1; const char *get_random_subdir() { assert(!subdirs.empty()); - int r = rand() % subdirs.size(); + int r = ((rand() % subdirs.size()) + (rand() % subdirs.size())) / 2; // non-uniform distn set::iterator it = subdirs.begin(); while (r--) it++; - return (*it).c_str(); + n1 = cwd; + n1.add_dentry( *it ); + return n1.get_path().c_str(); } + filepath n2; const char *get_random_sub() { assert(!contents.empty()); - int r = rand() % contents.size(); + int r = ((rand() % contents.size()) + (rand() % contents.size())) / 2; // non-uniform distn + if (cwd.depth() && cwd.last_bit().length()) + r += cwd.last_bit().c_str()[0]; // slightly permuted + r %= contents.size(); + map::iterator it = contents.begin(); while (r--) it++; - return it->first.c_str(); + + n2 = cwd; + n2.add_dentry( it->first ); + return n2.get_path().c_str(); } filepath sub; diff --git a/ceph/common/LogType.h b/ceph/common/LogType.h index efc444c5941..10f601c7060 100644 --- a/ceph/common/LogType.h +++ b/ceph/common/LogType.h @@ -9,6 +9,8 @@ using namespace std; #include using namespace __gnu_cxx; +#include "Mutex.h" + // for const char* comparisons struct ltstr { @@ -34,18 +36,20 @@ class LogType { version = 1; } void add_inc(const char* key) { - if (have_key(key)) return; - keys.push_back(key); - keyset.insert(key); - inc_keys.push_back(key); - version++; + if (!have_key(key)) { + keys.push_back(key); + keyset.insert(key); + inc_keys.push_back(key); + version++; + } } void add_set(const char* key){ - if (have_key(key)) return; - keys.push_back(key); - keyset.insert(key); - set_keys.push_back(key); - version++; + if (!have_key(key)) { + keys.push_back(key); + keyset.insert(key); + set_keys.push_back(key); + version++; + } } bool have_key(const char* key) { return keyset.count(key) ? true:false; diff --git a/ceph/common/Logger.cc b/ceph/common/Logger.cc index 6242522333c..086b04b3e45 100644 --- a/ceph/common/Logger.cc +++ b/ceph/common/Logger.cc @@ -9,6 +9,8 @@ #include "include/config.h" +// per-process lock. lame, but this way I protect LogType too! +Mutex logger_lock; Logger::Logger(string fn, LogType *type) { @@ -39,43 +41,43 @@ Logger::~Logger() long Logger::inc(const char *key, long v) { if (!g_conf.log) return 0; - lock.Lock(); + logger_lock.Lock(); if (!type->have_key(key)) type->add_inc(key); flush(); vals[key] += v; long r = vals[key]; - lock.Unlock(); + logger_lock.Unlock(); return r; } long Logger::set(const char *key, long v) { if (!g_conf.log) return 0; - lock.Lock(); + logger_lock.Lock(); if (!type->have_key(key)) type->add_set(key); flush(); vals[key] = v; long r = vals[key]; - lock.Unlock(); + logger_lock.Unlock(); return r; } long Logger::get(const char* key) { if (!g_conf.log) return 0; - lock.Lock(); + logger_lock.Lock(); long r = vals[key]; - lock.Unlock(); + logger_lock.Unlock(); return r; } void Logger::flush(bool force) { if (!g_conf.log) return; - lock.Lock(); + logger_lock.Lock(); if (!open) { out.open(filename.c_str(), ofstream::out); @@ -124,7 +126,7 @@ void Logger::flush(bool force) this->vals[*it] = 0; } - lock.Unlock(); + logger_lock.Unlock(); } diff --git a/ceph/common/Logger.h b/ceph/common/Logger.h index 39315f79174..8c3c79d9f4a 100644 --- a/ceph/common/Logger.h +++ b/ceph/common/Logger.h @@ -27,7 +27,7 @@ struct eqstr class Logger { protected: hash_map, eqstr> vals; - Mutex lock; + //Mutex lock; LogType *type; timepair_t start; diff --git a/ceph/config.cc b/ceph/config.cc index 044fe3c7459..2d73eb5a07e 100644 --- a/ceph/config.cc +++ b/ceph/config.cc @@ -52,6 +52,7 @@ md_config_t g_conf = { debug_mds_log: 1, debug_buffer: 0, debug_filer: 0, + debug_client: 0, // --- client --- client_cache_size: 400, @@ -106,15 +107,15 @@ md_config_t g_conf = { fakeclient_op_chmod: 1, fakeclient_op_chown: 1, - fakeclient_op_readdir: 20, - fakeclient_op_mknod: 10, + fakeclient_op_readdir: 2, + fakeclient_op_mknod: 30, fakeclient_op_link: false, - fakeclient_op_unlink: 5, - fakeclient_op_rename: 100, + fakeclient_op_unlink: 20, + fakeclient_op_rename: 40, - fakeclient_op_mkdir: 50, - fakeclient_op_rmdir: 0, // there's a bug...10, - fakeclient_op_symlink: 10, + fakeclient_op_mkdir: 10, + fakeclient_op_rmdir: 20, + fakeclient_op_symlink: 20, fakeclient_op_openrd: 200, fakeclient_op_openwr: 0, @@ -160,6 +161,8 @@ void parse_config_options(int argc, char **argv, g_conf.debug_buffer = atoi(argv[++i]); else if (strcmp(argv[i], "--debug_filer") == 0) g_conf.debug_filer = atoi(argv[++i]); + else if (strcmp(argv[i], "--debug_client") == 0) + g_conf.debug_client = atoi(argv[++i]); else if (strcmp(argv[i], "--log") == 0) g_conf.log = atoi(argv[++i]); diff --git a/ceph/config.h b/ceph/config.h index 033c4f70ce6..8fc9c0ecc6a 100644 --- a/ceph/config.h +++ b/ceph/config.h @@ -27,6 +27,7 @@ struct md_config_t { int debug_mds_log; int debug_buffer; int debug_filer; + int debug_client; // client int client_cache_size; diff --git a/ceph/msg/FakeMessenger.cc b/ceph/msg/FakeMessenger.cc index f0235d10797..b4a8c8f72e7 100644 --- a/ceph/msg/FakeMessenger.cc +++ b/ceph/msg/FakeMessenger.cc @@ -281,10 +281,10 @@ int FakeMessenger::send_message(Message *m, msg_addr_t dest, int port, int fromp if (!awake) { dout(10) << "waking up fakemessenger thread" << endl; awake = true; - lock.Unlock(); cond.Signal(); - } else - lock.Unlock(); + } + + lock.Unlock(); }