Skip to content

Commit

Permalink
ksmbd: lazy v2 lease break on smb2_write()
Browse files Browse the repository at this point in the history
[ Upstream commit c2a721e ]

Don't immediately send directory lease break notification on smb2_write().
Instead, It postpones it until smb2_close().

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
namjaejeon authored and gregkh committed Jan 5, 2024
1 parent 500c7a5 commit 34f7d5b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
45 changes: 43 additions & 2 deletions fs/smb/server/oplock.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ void close_id_del_oplock(struct ksmbd_file *fp)
{
struct oplock_info *opinfo;

if (S_ISDIR(file_inode(fp->filp)->i_mode))
return;
if (fp->reserve_lease_break)
smb_lazy_parent_lease_break_close(fp);

opinfo = opinfo_get(fp);
if (!opinfo)
Expand Down Expand Up @@ -1127,6 +1127,47 @@ void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,
ksmbd_inode_put(p_ci);
}

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();

if (!opinfo->is_lease || opinfo->o_lease->version != 2)
return;

p_ci = ksmbd_inode_lookup_lock(fp->filp->f_path.dentry->d_parent);
if (!p_ci)
return;

read_lock(&p_ci->m_lock);
list_for_each_entry(opinfo, &p_ci->m_op_list, op_entry) {
if (!opinfo->is_lease)
continue;

if (opinfo->o_lease->state != SMB2_OPLOCK_LEVEL_NONE) {
if (!atomic_inc_not_zero(&opinfo->refcount))
continue;

atomic_inc(&opinfo->conn->r_count);
if (ksmbd_conn_releasing(opinfo->conn)) {
atomic_dec(&opinfo->conn->r_count);
continue;
}
read_unlock(&p_ci->m_lock);
oplock_break(opinfo, SMB2_OPLOCK_LEVEL_NONE);
opinfo_conn_put(opinfo);
read_lock(&p_ci->m_lock);
}
}
read_unlock(&p_ci->m_lock);

ksmbd_inode_put(p_ci);
}

/**
* smb_grant_oplock() - handle oplock/lease request on file open
* @work: smb work
Expand Down
1 change: 1 addition & 0 deletions fs/smb/server/oplock.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,
void destroy_lease_table(struct ksmbd_conn *conn);
void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,
struct lease_ctx_info *lctx);
void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp);
#endif /* __KSMBD_OPLOCK_H */
3 changes: 3 additions & 0 deletions fs/smb/server/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
}
}

/* Reserve lease break for parent dir at closing time */
fp->reserve_lease_break = true;

/* Do we need to break any of a levelII oplock? */
smb_break_all_levII_oplock(work, fp, 1);

Expand Down
1 change: 1 addition & 0 deletions fs/smb/server/vfs_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct ksmbd_file {
struct ksmbd_readdir_data readdir_data;
int dot_dotdot[2];
unsigned int f_state;
bool reserve_lease_break;
};

static inline void set_ctx_actor(struct dir_context *ctx,
Expand Down

0 comments on commit 34f7d5b

Please sign in to comment.