Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * Copyright (C) 2019 Samsung Electronics Co., Ltd. |
| 4 | */ |
| 5 | |
| 6 | #ifndef __VFS_CACHE_H__ |
| 7 | #define __VFS_CACHE_H__ |
| 8 | |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 9 | #include <linux/file.h> |
| 10 | #include <linux/fs.h> |
| 11 | #include <linux/rwsem.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/idr.h> |
| 14 | #include <linux/workqueue.h> |
| 15 | |
| 16 | #include "vfs.h" |
| 17 | |
| 18 | /* Windows style file permissions for extended response */ |
| 19 | #define FILE_GENERIC_ALL 0x1F01FF |
| 20 | #define FILE_GENERIC_READ 0x120089 |
| 21 | #define FILE_GENERIC_WRITE 0x120116 |
| 22 | #define FILE_GENERIC_EXECUTE 0X1200a0 |
| 23 | |
| 24 | #define KSMBD_START_FID 0 |
Namjae Jeon | 3867369 | 2021-07-08 12:32:27 +0900 | [diff] [blame] | 25 | #define KSMBD_NO_FID (INT_MAX) |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 26 | #define SMB2_NO_FID (0xFFFFFFFFFFFFFFFFULL) |
| 27 | |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 28 | struct ksmbd_conn; |
| 29 | struct ksmbd_session; |
| 30 | |
| 31 | struct ksmbd_lock { |
| 32 | struct file_lock *fl; |
Hyunchul Lee | d63528e | 2021-07-10 16:22:41 +0900 | [diff] [blame] | 33 | struct list_head clist; |
| 34 | struct list_head flist; |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 35 | struct list_head llist; |
| 36 | unsigned int flags; |
| 37 | int cmd; |
| 38 | int zero_len; |
| 39 | unsigned long long start; |
| 40 | unsigned long long end; |
| 41 | }; |
| 42 | |
| 43 | struct stream { |
| 44 | char *name; |
| 45 | ssize_t size; |
| 46 | }; |
| 47 | |
| 48 | struct ksmbd_inode { |
| 49 | rwlock_t m_lock; |
| 50 | atomic_t m_count; |
| 51 | atomic_t op_count; |
| 52 | /* opinfo count for streams */ |
| 53 | atomic_t sop_count; |
| 54 | struct inode *m_inode; |
| 55 | unsigned int m_flags; |
| 56 | struct hlist_node m_hash; |
| 57 | struct list_head m_fp_list; |
| 58 | struct list_head m_op_list; |
| 59 | struct oplock_info *m_opinfo; |
| 60 | __le32 m_fattr; |
| 61 | }; |
| 62 | |
| 63 | struct ksmbd_file { |
| 64 | struct file *filp; |
| 65 | char *filename; |
Namjae Jeon | 3867369 | 2021-07-08 12:32:27 +0900 | [diff] [blame] | 66 | u64 persistent_id; |
| 67 | u64 volatile_id; |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 68 | |
| 69 | spinlock_t f_lock; |
| 70 | |
| 71 | struct ksmbd_inode *f_ci; |
| 72 | struct ksmbd_inode *f_parent_ci; |
| 73 | struct oplock_info __rcu *f_opinfo; |
| 74 | struct ksmbd_conn *conn; |
| 75 | struct ksmbd_tree_connect *tcon; |
| 76 | |
| 77 | atomic_t refcount; |
| 78 | __le32 daccess; |
| 79 | __le32 saccess; |
| 80 | __le32 coption; |
| 81 | __le32 cdoption; |
| 82 | __u64 create_time; |
| 83 | __u64 itime; |
| 84 | |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 85 | bool is_nt_open; |
| 86 | bool attrib_only; |
| 87 | |
| 88 | char client_guid[16]; |
| 89 | char create_guid[16]; |
| 90 | char app_instance_id[16]; |
| 91 | |
| 92 | struct stream stream; |
| 93 | struct list_head node; |
| 94 | struct list_head blocked_works; |
Hyunchul Lee | d63528e | 2021-07-10 16:22:41 +0900 | [diff] [blame] | 95 | struct list_head lock_list; |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 96 | |
| 97 | int durable_timeout; |
| 98 | |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 99 | /* if ls is happening on directory, below is valid*/ |
| 100 | struct ksmbd_readdir_data readdir_data; |
| 101 | int dot_dotdot[2]; |
| 102 | }; |
| 103 | |
| 104 | static inline void set_ctx_actor(struct dir_context *ctx, |
| 105 | filldir_t actor) |
| 106 | { |
| 107 | ctx->actor = actor; |
| 108 | } |
| 109 | |
| 110 | #define KSMBD_NR_OPEN_DEFAULT BITS_PER_LONG |
| 111 | |
| 112 | struct ksmbd_file_table { |
| 113 | rwlock_t lock; |
| 114 | struct idr *idr; |
| 115 | }; |
| 116 | |
Namjae Jeon | 3867369 | 2021-07-08 12:32:27 +0900 | [diff] [blame] | 117 | static inline bool has_file_id(u64 id) |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 118 | { |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 119 | return id < KSMBD_NO_FID; |
| 120 | } |
| 121 | |
| 122 | static inline bool ksmbd_stream_fd(struct ksmbd_file *fp) |
| 123 | { |
| 124 | return fp->stream.name != NULL; |
| 125 | } |
| 126 | |
| 127 | int ksmbd_init_file_table(struct ksmbd_file_table *ft); |
| 128 | void ksmbd_destroy_file_table(struct ksmbd_file_table *ft); |
Namjae Jeon | 3867369 | 2021-07-08 12:32:27 +0900 | [diff] [blame] | 129 | int ksmbd_close_fd(struct ksmbd_work *work, u64 id); |
| 130 | struct ksmbd_file *ksmbd_lookup_fd_fast(struct ksmbd_work *work, u64 id); |
| 131 | struct ksmbd_file *ksmbd_lookup_foreign_fd(struct ksmbd_work *work, u64 id); |
| 132 | struct ksmbd_file *ksmbd_lookup_fd_slow(struct ksmbd_work *work, u64 id, |
| 133 | u64 pid); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 134 | void ksmbd_fd_put(struct ksmbd_work *work, struct ksmbd_file *fp); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 135 | struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id); |
| 136 | struct ksmbd_file *ksmbd_lookup_fd_cguid(char *cguid); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 137 | struct ksmbd_file *ksmbd_lookup_fd_inode(struct inode *inode); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 138 | unsigned int ksmbd_open_durable_fd(struct ksmbd_file *fp); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 139 | struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 140 | void ksmbd_close_tree_conn_fds(struct ksmbd_work *work); |
| 141 | void ksmbd_close_session_fds(struct ksmbd_work *work); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 142 | int ksmbd_close_inode_fds(struct ksmbd_work *work, struct inode *inode); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 143 | int ksmbd_init_global_file_table(void); |
| 144 | void ksmbd_free_global_file_table(void); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 145 | void ksmbd_set_fd_limit(unsigned long limit); |
| 146 | |
| 147 | /* |
| 148 | * INODE hash |
| 149 | */ |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 150 | int __init ksmbd_inode_hash_init(void); |
Dan Carpenter | 849f59e | 2021-03-23 16:27:04 +0300 | [diff] [blame] | 151 | void ksmbd_release_inode_hash(void); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 152 | |
| 153 | enum KSMBD_INODE_STATUS { |
| 154 | KSMBD_INODE_STATUS_OK, |
| 155 | KSMBD_INODE_STATUS_UNKNOWN, |
| 156 | KSMBD_INODE_STATUS_PENDING_DELETE, |
| 157 | }; |
| 158 | |
| 159 | int ksmbd_query_inode_status(struct inode *inode); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 160 | bool ksmbd_inode_pending_delete(struct ksmbd_file *fp); |
| 161 | void ksmbd_set_inode_pending_delete(struct ksmbd_file *fp); |
| 162 | void ksmbd_clear_inode_pending_delete(struct ksmbd_file *fp); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 163 | void ksmbd_fd_set_delete_on_close(struct ksmbd_file *fp, |
| 164 | int file_info); |
Namjae Jeon | c30f4eb | 2021-06-18 10:17:37 +0900 | [diff] [blame] | 165 | int ksmbd_init_file_cache(void); |
| 166 | void ksmbd_exit_file_cache(void); |
Namjae Jeon | f441584 | 2021-03-16 10:50:04 +0900 | [diff] [blame] | 167 | #endif /* __VFS_CACHE_H__ */ |