Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/mds/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4085,6 +4085,7 @@ CDir* Server::try_open_auth_dirfrag(CInode *diri, frag_t fg, const MDRequestRef&
void Server::handle_client_getattr(const MDRequestRef& mdr, bool is_lookup)
{
const cref_t<MClientRequest> &req = mdr->client_request;
client_t client = mdr->get_client();

if (req->get_filepath().depth() == 0 && is_lookup) {
// refpath can't be empty for lookup but it can for
Expand All @@ -4106,6 +4107,17 @@ void Server::handle_client_getattr(const MDRequestRef& mdr, bool is_lookup)
if (r > 0)
return; // delayed

// Do not batch if any xlock is held
if (!r) {
CInode *in = mdr->in[0];
if (((mask & CEPH_CAP_LINK_SHARED) && (in->linklock.is_xlocked_by_client(client))) ||
((mask & CEPH_CAP_AUTH_SHARED) && (in->authlock.is_xlocked_by_client(client))) ||
((mask & CEPH_CAP_XATTR_SHARED) && (in->xattrlock.is_xlocked_by_client(client))) ||
((mask & CEPH_CAP_FILE_SHARED) && (in->filelock.is_xlocked_by_client(client)))) {
r = -1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another bug I think. This won't handle the case where we're skipping e.g. a rdlock when the client is issued an exclusive cap, like Ax. Consider:

client 1: issued pAx
client 2: getattr pAsLsXsFs issued pLxXx
client 3: getattr pAsLsXsFs issued p

client 2 will skip acquiring the linklock/xattrlock because it's issued LxXx. It will block on recall of Ax from client 1.

Client 2's getattr cannot be a batch head for client 3's `getattr.

This all exposes a problem I believe exists with where we're constructing the batch head: this should be constructed only after this acquire_locks fails:

ceph/src/mds/Server.cc

Lines 4217 to 4218 in 2c16096

if (!mds->locker->acquire_locks(mdr, lov))
return;

Before that point, record whether we've skipped any locks due to issued caps or (for this particular bug) the lock is already xlocked by the client. The latter cannot be easily checked without looking at the inode's lock because the Locker state machine hides why a rdlock succeeds (in this case, the client has an xlock already).

@xiubli xiubli Jul 3, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another bug I think. This won't handle the case where we're skipping e.g. a rdlock when the client is issued an exclusive cap, like Ax. Consider:

client 1: issued pAx client 2: getattr pAsLsXsFs issued pLxXx client 3: getattr pAsLsXsFs issued p

@batrick Correct me if I am wrong here.

From mds/lock.c I can see that only the loner client could get the x caps. Could you point me out in which case could we see the x in different locks will be issued to different clients at the same time ?

Different locks could have different loners at the same time ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another bug I think. This won't handle the case where we're skipping e.g. a rdlock when the client is issued an exclusive cap, like Ax. Consider:
client 1: issued pAx client 2: getattr pAsLsXsFs issued pLxXx client 3: getattr pAsLsXsFs issued p

@batrick Correct me if I am wrong here.

From mds/lock.c I can see that only the loner client could get the x caps. Could you point me out in which case could we see the x in different locks will be issued to different clients at the same time ?

You might be right; I'm not sure. In principle I don't see why it wouldn't be allowed but the state diagram suggests it is not.

Different locks could have different loners at the same time ?

It doesn't look like it but it's worth checking.

I think the batch leader construction should still be moved however. And that "detail" of the loner client shouldn't be relied on for the checks in any case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another bug I think. This won't handle the case where we're skipping e.g. a rdlock when the client is issued an exclusive cap, like Ax. Consider:
client 1: issued pAx client 2: getattr pAsLsXsFs issued pLxXx client 3: getattr pAsLsXsFs issued p

@batrick Correct me if I am wrong here.
From mds/lock.c I can see that only the loner client could get the x caps. Could you point me out in which case could we see the x in different locks will be issued to different clients at the same time ?

You might be right; I'm not sure. In principle I don't see why it wouldn't be allowed but the state diagram suggests it is not.

Different locks could have different loners at the same time ?

It doesn't look like it but it's worth checking.

I think the batch leader construction should still be moved however. And that "detail" of the loner client shouldn't be relied on for the checks in any case.

I couldn't remember I ever saw this case, just now I checked some debug logs, such as the debug logs from:

ceph-post-file: fb9a96f9-5f6d-46b4-b1fa-8580928b2241

I didn't find any case will do this. And also by going through the mds code, only when a longer is successfully set will the EXCL locker state could be set. And all the lockers in a CInode will be set to the same single longer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then perhaps the better check is: "is this client the loner for the CInode? In that case, do not make it a batch head".

Let's move the batch code below this call to acquire_locks on failure:

ceph/src/mds/Server.cc

Lines 4217 to 4218 in 2c16096

if (!mds->locker->acquire_locks(mdr, lov))
return;

If we fail to acquire the locks, then make it the batch head if one does not exist. If a batch head does exist already, then drop locks and add it to the batch queue.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the batch code below this call to acquire_locks on failure:

ceph/src/mds/Server.cc

Lines 4217 to 4218 in 2c16096

if (!mds->locker->acquire_locks(mdr, lov))
return;

If we fail to acquire the locks, then make it the batch head if one does not exist. If a batch head does exist already, then drop locks and add it to the batch queue.

Sure.

Checked the code carefully again, if my understanding is correct this won't work well as expected ?

For example, if the first lookup request just wants to acquire the rdlock for linklock and it succeeds, and then later the second lookup request comes and also just wants to the rdlock for the linklock. If both these two requests succeeds there won't be any chance to batch them. Actually we should batch them, right ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no further waits after that acquire_locks so I don't think so?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you should right here. Let me check it more.

@xiubli xiubli Jul 4, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@batrick If we will move the batch code after acquire_locks, we also should adjust the acquire_locks and other callers to make sure that they won't add the current request to any waiter, which will retry the request later, and then try to batch this request.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that's right. Let's leave it this way then.

}
}

if (r < 0) {
// fall-thru. let rdlock_path_pin_ref() check again.
} else if (is_lookup) {
Expand Down Expand Up @@ -4147,7 +4159,6 @@ void Server::handle_client_getattr(const MDRequestRef& mdr, bool is_lookup)
* handling this case here is easier than weakening rdlock
* semantics... that would cause problems elsewhere.
*/
client_t client = mdr->get_client();
int issued = 0;
Capability *cap = ref->get_client_cap(client);
if (cap && (mdr->snapid == CEPH_NOSNAP ||
Expand Down