Skip to content

Commit 3bfd614

Browse files
committed
client: refactor / optimize chdir
In particular: there's no reason to do a getcwd after chdir. Signed-off-by: Patrick Donnelly <[email protected]>
1 parent 28bdb8e commit 3bfd614

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

src/client/Client.cc

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12292,10 +12292,7 @@ int Client::statxat(int dirfd, const char *relpath,
1229212292
return r;
1229312293
}
1229412294

12295-
// not written yet, but i want to link!
12296-
12297-
int Client::chdir(const char *relpath, std::string &new_cwd,
12298-
const UserPerm& perms)
12295+
int Client::chdir(const char *relpath, const UserPerm& perms)
1229912296
{
1230012297
RWRef_t mref_reader(mount_state, CLIENT_MOUNTING);
1230112298
if (!mref_reader.is_state_satisfied())
@@ -12311,18 +12308,17 @@ int Client::chdir(const char *relpath, std::string &new_cwd,
1231112308
return rc;
1231212309
}
1231312310

12314-
if (!(in.get()->is_dir()))
12311+
if (!in->is_dir())
1231512312
return -ENOTDIR;
1231612313

12317-
if (cwd != in)
12318-
cwd.swap(in);
12314+
cwd = std::move(in);
12315+
1231912316
ldout(cct, 3) << "chdir(" << relpath << ") cwd now " << cwd->ino << dendl;
1232012317

12321-
_getcwd(new_cwd, perms);
1232212318
return 0;
1232312319
}
1232412320

12325-
void Client::_getcwd(string& dir, const UserPerm& perms)
12321+
int Client::_getcwd(string& dir, const UserPerm& perms)
1232612322
{
1232712323
filepath path;
1232812324
ldout(cct, 10) << __func__ << " " << *cwd << dendl;
@@ -12333,7 +12329,7 @@ void Client::_getcwd(string& dir, const UserPerm& perms)
1233312329

1233412330
// A cwd or ancester is unlinked
1233512331
if (in->dentries.empty()) {
12336-
return;
12332+
return -ENOENT;
1233712333
}
1233812334

1233912335
Dentry *dn = in->get_first_parent();
@@ -12360,17 +12356,17 @@ void Client::_getcwd(string& dir, const UserPerm& perms)
1236012356
}
1236112357
dir = "/";
1236212358
dir += path.get_path();
12359+
return 0;
1236312360
}
1236412361

12365-
void Client::getcwd(string& dir, const UserPerm& perms)
12362+
int Client::getcwd(string& dir, const UserPerm& perms)
1236612363
{
1236712364
RWRef_t mref_reader(mount_state, CLIENT_MOUNTING);
1236812365
if (!mref_reader.is_state_satisfied())
12369-
return;
12366+
return -ENOTCONN;
1237012367

1237112368
std::scoped_lock l(client_lock);
12372-
12373-
_getcwd(dir, perms);
12369+
return _getcwd(dir, perms);
1237412370
}
1237512371

1237612372
int Client::statfs(const char *path, struct statvfs *stbuf,

src/client/Client.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,9 @@ class Client : public Dispatcher, public md_config_obs_t {
343343
// these should (more or less) mirror the actual system calls.
344344
int statfs(const char *path, struct statvfs *stbuf, const UserPerm& perms);
345345

346-
// crap
347-
int chdir(const char *s, std::string &new_cwd, const UserPerm& perms);
348-
void _getcwd(std::string& cwd, const UserPerm& perms);
349-
void getcwd(std::string& cwd, const UserPerm& perms);
346+
int chdir(const char *path, const UserPerm& perms);
347+
int _getcwd(std::string& cwd, const UserPerm& perms);
348+
int getcwd(std::string& cwd, const UserPerm& perms);
350349

351350
// namespace ops
352351
int opendir(const char *name, dir_result_t **dirpp, const UserPerm& perms);

src/client/SyntheticClient.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,8 +1219,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
12191219
const char *a = t.get_string(buf, p);
12201220
// Client users should remember their path, but since this
12211221
// is just a synthetic client we ignore it.
1222-
std::string ignore;
1223-
client->chdir(a, ignore, perms);
1222+
client->chdir(a, perms);
12241223
} else if (strcmp(op, "statfs") == 0) {
12251224
struct statvfs stbuf;
12261225
client->statfs("/", &stbuf, perms);

src/libcephfs.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ struct ceph_mount_info
322322

323323
int chdir(const char *to, const UserPerm& perms)
324324
{
325-
return client->chdir(to, cwd, perms);
325+
return client->chdir(to, perms);
326326
}
327327

328328
CephContext *get_ceph_context() const {

0 commit comments

Comments
 (0)