From 4acdb0545efdd739b3c2d0998732bd5c0f0367b2 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Fri, 18 Sep 2009 15:20:29 -0700 Subject: [PATCH] uclient: Fixes for get_or_create --- src/client/Client.cc | 13 ++++++++----- src/client/Client.h | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index ef6f52c9774e6..0a0864a3b6252 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -2982,7 +2982,8 @@ int Client::_lookup(Inode *dir, const string& dname, Inode **target) return r; } -int Client::get_or_create(Inode *dir, const string& name, Dentry **pdn) +int Client::get_or_create(Inode *dir, const char* name, + Dentry **pdn, bool expect_null) { // lookup if (dir->dir && dir->dir->dentries.count(name)) { @@ -2997,13 +2998,15 @@ int Client::get_or_create(Inode *dir, const string& name, Dentry **pdn) MDSSession &s = mds_sessions[dn->lease_mds]; if (s.cap_ttl > now && s.cap_gen == dn->lease_gen) { - return -EEXIST; + if (expect_null) + return -EEXIST; + else return 0; } } - } else { - // link up new one - *pdn = link(dir->dir, name.c_str(), NULL); } + + // otherwise link up a new one + *pdn = link(dir->dir, name, NULL); return 0; } diff --git a/src/client/Client.h b/src/client/Client.h index 75ad46f9689f5..f0786c92d1d1c 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1182,7 +1182,8 @@ private: int _sync_fs(); MClientRequest* make_request_from_Meta(MetaRequest * request); - int get_or_create(Inode *dir, const string& name, Dentry **pdn); + int get_or_create(Inode *dir, const char* name, + Dentry **pdn, bool expect_null=false); public: int mount(); -- 2.39.5