Skip to content

Commit f536650

Browse files
committed
Merge PR ceph#62230 into main
* refs/pull/62230/head: client: avoid multiple calls to path_walk Reviewed-by: Christopher Hoffman <[email protected]>
2 parents 67847ee + af8d267 commit f536650

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

src/client/Client.cc

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7892,7 +7892,13 @@ int Client::do_mkdirat(int dirfd, const char *relpath, mode_t mode, const UserPe
78927892
if (r < 0) {
78937893
return r;
78947894
}
7895-
return _mkdir(dirinode.get(), relpath, mode, perm, 0, {}, std::move(alternate_name));
7895+
7896+
walk_dentry_result wdr;
7897+
if (int rc = path_walk(dirinode, filepath(relpath), &wdr, perm, {.require_target = false}); rc < 0) {
7898+
return rc;
7899+
}
7900+
7901+
return _mkdir(wdr, mode, perm, 0, {}, std::move(alternate_name));
78967902
}
78977903

78987904
int Client::mkdirs(const char *relpath, mode_t mode, const UserPerm& perms)
@@ -7914,7 +7920,7 @@ int Client::mkdirs(const char *relpath, mode_t mode, const UserPerm& perms)
79147920
if (int rc = path_walk(cwd, path, &wdr, perms, {.followsym = false}); rc < 0) {
79157921
if (rc == -ENOENT) {
79167922
InodeRef in;
7917-
rc = _mkdir(wdr.diri.get(), wdr.dname.c_str(), mode, perms, &in);
7923+
rc = _mkdir(wdr, mode, perms, &in);
79187924
switch (rc) {
79197925
case 0:
79207926
case EEXIST:
@@ -13055,12 +13061,15 @@ int Client::mksnap(const char *relpath, const char *name, const UserPerm& perm,
1305513061
return -ENOTCONN;
1305613062

1305713063
std::scoped_lock l(client_lock);
13058-
InodeRef in;
13059-
if (int rc = path_walk(cwd, filepath(relpath), &in, perm, {}); rc < 0) {
13064+
walk_dentry_result wdr;
13065+
if (int rc = path_walk(cwd, filepath(relpath), &wdr, perm, {}); rc < 0) {
1306013066
return rc;
1306113067
}
13062-
auto snapdir = open_snapdir(in.get());
13063-
return _mkdir(snapdir.get(), name, mode, perm, nullptr, metadata);
13068+
auto snapdir = open_snapdir(wdr.target);
13069+
if (int rc = path_walk(std::move(snapdir), filepath(name), &wdr, perm, {.require_target = false}); rc < 0) {
13070+
return rc;
13071+
}
13072+
return _mkdir(wdr, mode, perm, nullptr, metadata);
1306413073
}
1306513074

1306613075
int Client::rmsnap(const char *relpath, const char *name, const UserPerm& perms, bool check_perms)
@@ -14873,18 +14882,15 @@ int Client::_create(const walk_dentry_result& wdr, int flags, mode_t mode,
1487314882
return res;
1487414883
}
1487514884

14876-
int Client::_mkdir(Inode *dir, const char *name, mode_t mode, const UserPerm& perm,
14885+
int Client::_mkdir(const walk_dentry_result& wdr, mode_t mode, const UserPerm& perm,
1487714886
InodeRef *inp, const std::map<std::string, std::string> &metadata,
1487814887
std::string alternate_name)
1487914888
{
14880-
ldout(cct, 8) << "_mkdir(" << dir->ino << " " << name << ", 0" << oct
14881-
<< mode << dec << ", uid " << perm.uid()
14889+
ldout(cct, 8) << "_mkdir(" << wdr << ", 0o" << std::oct << mode << std::dec
14890+
<< ", uid " << perm.uid()
1488214891
<< ", gid " << perm.gid() << ")" << dendl;
1488314892

14884-
walk_dentry_result wdr;
14885-
if (int rc = path_walk(dir, filepath(name), &wdr, perm, {.require_target = false}); rc < 0) {
14886-
return rc;
14887-
} else if (rc == 0 && wdr.target) {
14893+
if (wdr.target) {
1488814894
return -EEXIST;
1488914895
}
1489014896

@@ -14963,8 +14969,13 @@ int Client::ll_mkdir(Inode *parent, const char *name, mode_t mode,
1496314969

1496414970
std::scoped_lock lock(client_lock);
1496514971

14972+
walk_dentry_result wdr;
14973+
if (int rc = path_walk(parent, filepath(name), &wdr, perm, {.require_target = false}); rc < 0) {
14974+
return rc;
14975+
}
14976+
1496614977
InodeRef in;
14967-
int r = _mkdir(parent, name, mode, perm, &in);
14978+
int r = _mkdir(wdr, mode, perm, &in);
1496814979
if (r == 0) {
1496914980
fill_stat(in, attr);
1497014981
_ll_get(in.get());
@@ -14994,8 +15005,13 @@ int Client::ll_mkdirx(Inode *parent, const char *name, mode_t mode, Inode **out,
1499415005

1499515006
std::scoped_lock lock(client_lock);
1499615007

15008+
walk_dentry_result wdr;
15009+
if (int rc = path_walk(parent, filepath(name), &wdr, perms, {.require_target = false}); rc < 0) {
15010+
return rc;
15011+
}
15012+
1499715013
InodeRef in;
14998-
int r = _mkdir(parent, name, mode, perms, &in);
15014+
int r = _mkdir(wdr, mode, perms, &in);
1499915015
if (r == 0) {
1500015016
fill_statx(in, statx_to_mask(flags, want), stx);
1500115017
_ll_get(in.get());

src/client/Client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,7 @@ class Client : public Dispatcher, public md_config_obs_t {
17011701
int _link(Inode *diri_from, const char* path_from, Inode* diri_to, const char* path_to, const UserPerm& perm, std::string alternate_name);
17021702
int _unlink(Inode *dir, const char *name, const UserPerm& perm);
17031703
int _rename(Inode *olddir, const char *oname, Inode *ndir, const char *nname, const UserPerm& perm, std::string alternate_name);
1704-
int _mkdir(Inode *dir, const char *name, mode_t mode, const UserPerm& perm,
1704+
int _mkdir(const walk_dentry_result& wdr, mode_t mode, const UserPerm& perm,
17051705
InodeRef *inp = 0, const std::map<std::string, std::string> &metadata={},
17061706
std::string alternate_name="");
17071707
int _rmdir(Inode *dir, const char *name, const UserPerm& perms, bool check_perms=true);

0 commit comments

Comments
 (0)