Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *   Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
0004  *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
0005  */
0006 
0007 #ifndef __KSMBD_OPLOCK_H
0008 #define __KSMBD_OPLOCK_H
0009 
0010 #include "smb_common.h"
0011 
0012 #define OPLOCK_WAIT_TIME    (35 * HZ)
0013 
0014 /* SMB2 Oplock levels */
0015 #define SMB2_OPLOCK_LEVEL_NONE          0x00
0016 #define SMB2_OPLOCK_LEVEL_II            0x01
0017 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE     0x08
0018 #define SMB2_OPLOCK_LEVEL_BATCH         0x09
0019 #define SMB2_OPLOCK_LEVEL_LEASE         0xFF
0020 
0021 /* Oplock states */
0022 #define OPLOCK_STATE_NONE   0x00
0023 #define OPLOCK_ACK_WAIT     0x01
0024 #define OPLOCK_CLOSING      0x02
0025 
0026 #define OPLOCK_WRITE_TO_READ        0x01
0027 #define OPLOCK_READ_HANDLE_TO_READ  0x02
0028 #define OPLOCK_WRITE_TO_NONE        0x04
0029 #define OPLOCK_READ_TO_NONE     0x08
0030 
0031 struct lease_ctx_info {
0032     __u8            lease_key[SMB2_LEASE_KEY_SIZE];
0033     __le32          req_state;
0034     __le32          flags;
0035     __le64          duration;
0036     __u8            parent_lease_key[SMB2_LEASE_KEY_SIZE];
0037     int         version;
0038 };
0039 
0040 struct lease_table {
0041     char            client_guid[SMB2_CLIENT_GUID_SIZE];
0042     struct list_head    lease_list;
0043     struct list_head    l_entry;
0044     spinlock_t      lb_lock;
0045 };
0046 
0047 struct lease {
0048     __u8            lease_key[SMB2_LEASE_KEY_SIZE];
0049     __le32          state;
0050     __le32          new_state;
0051     __le32          flags;
0052     __le64          duration;
0053     __u8            parent_lease_key[SMB2_LEASE_KEY_SIZE];
0054     int         version;
0055     unsigned short      epoch;
0056     struct lease_table  *l_lb;
0057 };
0058 
0059 struct oplock_info {
0060     struct ksmbd_conn   *conn;
0061     struct ksmbd_session    *sess;
0062     struct ksmbd_work   *work;
0063     struct ksmbd_file   *o_fp;
0064     int                     level;
0065     int                     op_state;
0066     unsigned long       pending_break;
0067     u64         fid;
0068     atomic_t        breaking_cnt;
0069     atomic_t        refcount;
0070     __u16                   Tid;
0071     bool            is_lease;
0072     bool            open_trunc; /* truncate on open */
0073     struct lease        *o_lease;
0074     struct list_head        interim_list;
0075     struct list_head        op_entry;
0076     struct list_head        lease_entry;
0077     wait_queue_head_t oplock_q; /* Other server threads */
0078     wait_queue_head_t oplock_brk; /* oplock breaking wait */
0079     struct rcu_head     rcu_head;
0080 };
0081 
0082 struct lease_break_info {
0083     __le32          curr_state;
0084     __le32          new_state;
0085     __le16          epoch;
0086     char            lease_key[SMB2_LEASE_KEY_SIZE];
0087 };
0088 
0089 struct oplock_break_info {
0090     int level;
0091     int open_trunc;
0092     int fid;
0093 };
0094 
0095 int smb_grant_oplock(struct ksmbd_work *work, int req_op_level,
0096              u64 pid, struct ksmbd_file *fp, __u16 tid,
0097              struct lease_ctx_info *lctx, int share_ret);
0098 void smb_break_all_levII_oplock(struct ksmbd_work *work,
0099                 struct ksmbd_file *fp, int is_trunc);
0100 int opinfo_write_to_read(struct oplock_info *opinfo);
0101 int opinfo_read_handle_to_read(struct oplock_info *opinfo);
0102 int opinfo_write_to_none(struct oplock_info *opinfo);
0103 int opinfo_read_to_none(struct oplock_info *opinfo);
0104 void close_id_del_oplock(struct ksmbd_file *fp);
0105 void smb_break_all_oplock(struct ksmbd_work *work, struct ksmbd_file *fp);
0106 struct oplock_info *opinfo_get(struct ksmbd_file *fp);
0107 void opinfo_put(struct oplock_info *opinfo);
0108 
0109 /* Lease related functions */
0110 void create_lease_buf(u8 *rbuf, struct lease *lease);
0111 struct lease_ctx_info *parse_lease_state(void *open_req);
0112 __u8 smb2_map_lease_to_oplock(__le32 lease_state);
0113 int lease_read_to_write(struct oplock_info *opinfo);
0114 
0115 /* Durable related functions */
0116 void create_durable_rsp_buf(char *cc);
0117 void create_durable_v2_rsp_buf(char *cc, struct ksmbd_file *fp);
0118 void create_mxac_rsp_buf(char *cc, int maximal_access);
0119 void create_disk_id_rsp_buf(char *cc, __u64 file_id, __u64 vol_id);
0120 void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp);
0121 struct create_context *smb2_find_context_vals(void *open_req, const char *str);
0122 struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,
0123                       char *lease_key);
0124 int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,
0125             struct lease_ctx_info *lctx);
0126 void destroy_lease_table(struct ksmbd_conn *conn);
0127 #endif /* __KSMBD_OPLOCK_H */