Skip to content

Commit

Permalink
posix-pstat/istat() - bail early if iatt structure is NULL
Browse files Browse the repository at this point in the history
In some cases, we can return early - when iatt structure is NULL.
Specifically, this happens when we call those functions in part of
MAKE_INODE_HANDLE() macro - which in some cases is not using that structure.

This saves us few calls. Specifically, we do not need to fetch mdata xattr, which may save
us from some lgetxattr() and such.

Updates: gluster#1000
Signed-off-by: Yaniv Kaul <[email protected]>
  • Loading branch information
mykaul committed May 24, 2024
1 parent 929d71b commit 427ff93
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions xlators/storage/posix/src/posix-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,12 @@ posix_istat(xlator_t *this, inode_t *inode, uuid_t gfid, const char *basename,
return -1;
}

if (!buf_p)
/* the rest of the code fills stbuf with more data. If it's not going to
* be copied over to buf_p, we can return here.
*/
goto out;

if (!S_ISDIR(lstatbuf.st_mode))
lstatbuf.st_nlink--;

Expand All @@ -770,8 +776,7 @@ posix_istat(xlator_t *this, inode_t *inode, uuid_t gfid, const char *basename,

posix_fill_ino_from_gfid(&stbuf);

if (buf_p)
memcpy(buf_p, &stbuf, sizeof(struct iatt));
memcpy(buf_p, &stbuf, sizeof(struct iatt));
out:
return ret;
}
Expand All @@ -789,29 +794,30 @@ posix_pstat(xlator_t *this, inode_t *inode, uuid_t gfid, const char *path,
int op_errno = 0;
struct posix_private *priv = NULL;

priv = this->private;

ret = sys_lstat(path, &lstatbuf);
if (ret != 0) {
if (errno != ENOENT) {
op_errno = errno;
gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_LSTAT_FAILED,
op_errno = errno;
if (op_errno != ENOENT) {
gf_msg(this->name, GF_LOG_WARNING, op_errno, P_MSG_LSTAT_FAILED,
"lstat failed on %s", path);
errno = op_errno; /*gf_msg could have changed errno*/
} else {
op_errno = errno;
gf_msg_debug(this->name, errno, "lstat failed on %s ", path);
errno = op_errno; /*gf_msg could have changed errno*/
gf_msg_debug(this->name, op_errno, "lstat failed on %s ", path);
}
errno = op_errno; /*gf_msg could have changed errno*/
goto out;
}

priv = this->private;

if ((lstatbuf.st_ino == priv->handledir_st_ino) &&
(lstatbuf.st_dev == priv->handledir_st_dev)) {
errno = ENOENT;
return -1;
}

if (!buf_p)
goto out;

if (!S_ISDIR(lstatbuf.st_mode))
lstatbuf.st_nlink--;

Expand Down Expand Up @@ -848,8 +854,7 @@ posix_pstat(xlator_t *this, inode_t *inode, uuid_t gfid, const char *path,

posix_fill_ino_from_gfid(&stbuf);

if (buf_p)
memcpy(buf_p, &stbuf, sizeof(struct iatt));
memcpy(buf_p, &stbuf, sizeof(struct iatt));
out:
return ret;
}
Expand Down

0 comments on commit 427ff93

Please sign in to comment.