Skip to content

Commit

Permalink
ksmbd: move credit charge deduction under processing request
Browse files Browse the repository at this point in the history
Moves the credit charge deduction from total_credits under the processing
a request. When repeating smb2 lock request and other command request,
there will be a problem that ->total_credits does not decrease.

Signed-off-by: Namjae Jeon <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
namjaejeon authored and Steve French committed Jan 10, 2022
1 parent 004443b commit 914d7e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 2 additions & 5 deletions fs/ksmbd/smb2misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,
unsigned int req_len = 0, expect_resp_len = 0, calc_credit_num, max_len;
unsigned short credit_charge = le16_to_cpu(hdr->CreditCharge);
void *__hdr = hdr;
int ret;
int ret = 0;

switch (hdr->Command) {
case SMB2_QUERY_INFO:
Expand Down Expand Up @@ -332,10 +332,7 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,
}

spin_lock(&conn->credits_lock);
if (credit_charge <= conn->total_credits) {
conn->total_credits -= credit_charge;
ret = 0;
} else {
if (credit_charge > conn->total_credits) {
ksmbd_debug(SMB, "Insufficient credits granted, given: %u, granted: %u\n",
credit_charge, conn->total_credits);
ret = 1;
Expand Down
16 changes: 10 additions & 6 deletions fs/ksmbd/smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,8 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
struct smb2_hdr *req_hdr = ksmbd_req_buf_next(work);
struct smb2_hdr *hdr = ksmbd_resp_buf_next(work);
struct ksmbd_conn *conn = work->conn;
unsigned short credits_requested;
unsigned short credits_requested, aux_max;
unsigned short credit_charge, credits_granted = 0;
unsigned short aux_max, aux_credits;

if (work->send_no_response)
return 0;
Expand All @@ -316,6 +315,13 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)

credit_charge = max_t(unsigned short,
le16_to_cpu(req_hdr->CreditCharge), 1);
if (credit_charge > conn->total_credits) {
ksmbd_debug(SMB, "Insufficient credits granted, given: %u, granted: %u\n",
credit_charge, conn->total_credits);
return -EINVAL;
}

conn->total_credits -= credit_charge;
credits_requested = max_t(unsigned short,
le16_to_cpu(req_hdr->CreditRequest), 1);

Expand All @@ -325,13 +331,11 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
* TODO: Need to adjuct CreditRequest value according to
* current cpu load
*/
aux_credits = credits_requested - 1;
if (hdr->Command == SMB2_NEGOTIATE)
aux_max = 0;
aux_max = 1;
else
aux_max = conn->vals->max_credits - credit_charge;
aux_credits = min_t(unsigned short, aux_credits, aux_max);
credits_granted = credit_charge + aux_credits;
credits_granted = min_t(unsigned short, credits_requested, aux_max);

if (conn->vals->max_credits - conn->total_credits < credits_granted)
credits_granted = conn->vals->max_credits -
Expand Down

0 comments on commit 914d7e5

Please sign in to comment.