Skip to content

Commit

Permalink
ksmbd: test 2
Browse files Browse the repository at this point in the history
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
namjaejeon committed Aug 29, 2024
1 parent 445bb7f commit fd9c1bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
37 changes: 16 additions & 21 deletions oplock.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static struct oplock_info *opinfo_get_list(struct ksmbd_inode *ci)
return NULL;

down_read(&ci->m_lock);
opinfo = list_first_or_null_rcu(&ci->m_op_list, struct oplock_info,
opinfo = list_first_entry(&ci->m_op_list, struct oplock_info,
op_entry);
if (opinfo) {
if (opinfo->conn == NULL ||
Expand Down Expand Up @@ -466,7 +466,7 @@ void close_id_del_oplock(struct ksmbd_file *fp)

opinfo_del(opinfo);

rcu_assign_pointer(fp->f_opinfo, NULL);
fp->f_opinfo = NULL;
if (opinfo->op_state == OPLOCK_ACK_WAIT) {
opinfo->op_state = OPLOCK_CLOSING;
wake_up_interruptible_all(&opinfo->oplock_q);
Expand Down Expand Up @@ -1174,14 +1174,14 @@ void destroy_lease_table(struct ksmbd_conn *conn)
SMB2_CLIENT_GUID_SIZE))
continue;
again:
rcu_read_lock();
list_for_each_entry_rcu(opinfo, &lb->lease_list,
spin_lock(&lb->lb_lock);
list_for_each_entry(opinfo, &lb->lease_list,
lease_entry) {
rcu_read_unlock();
lease_del_list(opinfo);
spin_unlock(&lb->lb_lock);
goto again;
}
rcu_read_unlock();
spin_unlock(&lb->lb_lock);
list_del(&lb->l_entry);
kfree(lb);
}
Expand Down Expand Up @@ -1214,11 +1214,10 @@ int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,
return 0;

found:
rcu_read_lock();
list_for_each_entry_rcu(opinfo, &lb->lease_list, lease_entry) {
spin_lock(&lb->lb_lock);
list_for_each_entry(opinfo, &lb->lease_list, lease_entry) {
if (!atomic_inc_not_zero(&opinfo->refcount))
continue;
rcu_read_unlock();
if (opinfo->o_fp->f_ci == ci)
goto op_next;
err = compare_guid_key(opinfo, sess->ClientGUID,
Expand All @@ -1228,13 +1227,13 @@ int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,
ksmbd_debug(OPLOCK,
"found same lease key is already used in other files\n");
opinfo_put(opinfo);
spin_unlock(&lb->lb_lock);
goto out;
}
op_next:
opinfo_put(opinfo);
rcu_read_lock();
}
rcu_read_unlock();
spin_unlock(&lb->lb_lock);

out:
read_unlock(&lease_list_lock);
Expand Down Expand Up @@ -1352,9 +1351,7 @@ void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp)
struct oplock_info *opinfo;
struct ksmbd_inode *p_ci = NULL;

rcu_read_lock();
opinfo = rcu_dereference(fp->f_opinfo);
rcu_read_unlock();
opinfo = fp->f_opinfo;

if (!opinfo || !opinfo->is_lease || opinfo->o_lease->version != 2)
return;
Expand Down Expand Up @@ -1509,7 +1506,7 @@ int smb_grant_oplock(struct ksmbd_work *work, int req_op_level, u64 pid,
set_oplock_level(opinfo, req_op_level, lctx);

out:
rcu_assign_pointer(fp->f_opinfo, opinfo);
fp->f_opinfo = opinfo;
opinfo->o_fp = fp;

opinfo_count_inc(fp);
Expand Down Expand Up @@ -2057,11 +2054,10 @@ struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,
return NULL;

found:
rcu_read_lock();
list_for_each_entry_rcu(opinfo, &lt->lease_list, lease_entry) {
spin_lock(&lt->lb_lock);
list_for_each_entry(opinfo, &lt->lease_list, lease_entry) {
if (!atomic_inc_not_zero(&opinfo->refcount))
continue;
rcu_read_unlock();
if (!opinfo->op_state || opinfo->op_state == OPLOCK_CLOSING)
goto op_next;
if (!(opinfo->o_lease->state &
Expand All @@ -2073,16 +2069,15 @@ struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,
if (ret) {
ksmbd_debug(OPLOCK, "found opinfo\n");
ret_op = opinfo;
spin_unlock(&lt->lb_lock);
goto out;
}
op_next:
opinfo_put(opinfo);
rcu_read_lock();
}
rcu_read_unlock();
spin_unlock(&lt->lb_lock);

out:
read_unlock(&lease_list_lock);
return ret_op;
}

Expand Down
4 changes: 2 additions & 2 deletions vfs_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon,
conn = fp->conn;
ci = fp->f_ci;
down_write(&ci->m_lock);
list_for_each_entry_rcu(op, &ci->m_op_list, op_entry) {
list_for_each_entry(op, &ci->m_op_list, op_entry) {
if (op->conn != conn)
continue;
op->conn = NULL;
Expand Down Expand Up @@ -1037,7 +1037,7 @@ int ksmbd_reopen_durable_fd(struct ksmbd_work *work, struct ksmbd_file *fp)

ci = fp->f_ci;
down_write(&ci->m_lock);
list_for_each_entry_rcu(op, &ci->m_op_list, op_entry) {
list_for_each_entry(op, &ci->m_op_list, op_entry) {
if (op->conn)
continue;
op->conn = fp->conn;
Expand Down
2 changes: 1 addition & 1 deletion vfs_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct ksmbd_file {

struct ksmbd_inode *f_ci;
struct ksmbd_inode *f_parent_ci;
struct oplock_info __rcu *f_opinfo;
struct oplock_info *f_opinfo;
struct ksmbd_conn *conn;
struct ksmbd_tree_connect *tcon;

Expand Down

0 comments on commit fd9c1bc

Please sign in to comment.