2021-03-16 09:50:04 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Samsung Electronics Co., Ltd.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VFS_CACHE_H__
|
|
|
|
#define __VFS_CACHE_H__
|
|
|
|
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
|
|
|
|
#include "vfs.h"
|
2024-03-12 13:05:57 +08:00
|
|
|
#include "mgmt/share_config.h"
|
2021-03-16 09:50:04 +08:00
|
|
|
|
|
|
|
/* Windows style file permissions for extended response */
|
|
|
|
#define FILE_GENERIC_ALL 0x1F01FF
|
|
|
|
#define FILE_GENERIC_READ 0x120089
|
|
|
|
#define FILE_GENERIC_WRITE 0x120116
|
|
|
|
#define FILE_GENERIC_EXECUTE 0X1200a0
|
|
|
|
|
|
|
|
#define KSMBD_START_FID 0
|
2021-07-08 11:32:27 +08:00
|
|
|
#define KSMBD_NO_FID (INT_MAX)
|
2021-03-16 09:50:04 +08:00
|
|
|
#define SMB2_NO_FID (0xFFFFFFFFFFFFFFFFULL)
|
|
|
|
|
|
|
|
struct ksmbd_conn;
|
|
|
|
struct ksmbd_session;
|
|
|
|
|
|
|
|
struct ksmbd_lock {
|
|
|
|
struct file_lock *fl;
|
2021-07-10 15:22:41 +08:00
|
|
|
struct list_head clist;
|
|
|
|
struct list_head flist;
|
2021-03-16 09:50:04 +08:00
|
|
|
struct list_head llist;
|
|
|
|
unsigned int flags;
|
|
|
|
int cmd;
|
|
|
|
int zero_len;
|
|
|
|
unsigned long long start;
|
|
|
|
unsigned long long end;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stream {
|
|
|
|
char *name;
|
|
|
|
ssize_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ksmbd_inode {
|
2024-05-02 09:07:50 +08:00
|
|
|
struct rw_semaphore m_lock;
|
2021-03-16 09:50:04 +08:00
|
|
|
atomic_t m_count;
|
|
|
|
atomic_t op_count;
|
|
|
|
/* opinfo count for streams */
|
|
|
|
atomic_t sop_count;
|
2023-11-20 08:13:54 +08:00
|
|
|
struct dentry *m_de;
|
2021-03-16 09:50:04 +08:00
|
|
|
unsigned int m_flags;
|
|
|
|
struct hlist_node m_hash;
|
|
|
|
struct list_head m_fp_list;
|
|
|
|
struct list_head m_op_list;
|
|
|
|
struct oplock_info *m_opinfo;
|
|
|
|
__le32 m_fattr;
|
|
|
|
};
|
|
|
|
|
2023-10-04 17:28:39 +08:00
|
|
|
enum {
|
|
|
|
FP_NEW = 0,
|
|
|
|
FP_INITED,
|
|
|
|
FP_CLOSED
|
|
|
|
};
|
|
|
|
|
2021-03-16 09:50:04 +08:00
|
|
|
struct ksmbd_file {
|
|
|
|
struct file *filp;
|
2021-07-08 11:32:27 +08:00
|
|
|
u64 persistent_id;
|
|
|
|
u64 volatile_id;
|
2021-03-16 09:50:04 +08:00
|
|
|
|
|
|
|
spinlock_t f_lock;
|
|
|
|
|
|
|
|
struct ksmbd_inode *f_ci;
|
|
|
|
struct ksmbd_inode *f_parent_ci;
|
|
|
|
struct oplock_info __rcu *f_opinfo;
|
|
|
|
struct ksmbd_conn *conn;
|
|
|
|
struct ksmbd_tree_connect *tcon;
|
|
|
|
|
|
|
|
atomic_t refcount;
|
|
|
|
__le32 daccess;
|
|
|
|
__le32 saccess;
|
|
|
|
__le32 coption;
|
|
|
|
__le32 cdoption;
|
|
|
|
__u64 create_time;
|
|
|
|
__u64 itime;
|
|
|
|
|
|
|
|
bool is_nt_open;
|
|
|
|
bool attrib_only;
|
|
|
|
|
|
|
|
char client_guid[16];
|
|
|
|
char create_guid[16];
|
|
|
|
char app_instance_id[16];
|
|
|
|
|
|
|
|
struct stream stream;
|
|
|
|
struct list_head node;
|
|
|
|
struct list_head blocked_works;
|
2021-07-10 15:22:41 +08:00
|
|
|
struct list_head lock_list;
|
2021-03-16 09:50:04 +08:00
|
|
|
|
|
|
|
int durable_timeout;
|
2024-05-21 21:57:52 +08:00
|
|
|
int durable_scavenger_timeout;
|
2021-03-16 09:50:04 +08:00
|
|
|
|
|
|
|
/* if ls is happening on directory, below is valid*/
|
|
|
|
struct ksmbd_readdir_data readdir_data;
|
|
|
|
int dot_dotdot[2];
|
2023-10-04 17:28:39 +08:00
|
|
|
unsigned int f_state;
|
2023-12-08 13:37:56 +08:00
|
|
|
bool reserve_lease_break;
|
2024-03-12 13:05:57 +08:00
|
|
|
bool is_durable;
|
|
|
|
bool is_persistent;
|
|
|
|
bool is_resilient;
|
2021-03-16 09:50:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline void set_ctx_actor(struct dir_context *ctx,
|
|
|
|
filldir_t actor)
|
|
|
|
{
|
|
|
|
ctx->actor = actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define KSMBD_NR_OPEN_DEFAULT BITS_PER_LONG
|
|
|
|
|
|
|
|
struct ksmbd_file_table {
|
|
|
|
rwlock_t lock;
|
|
|
|
struct idr *idr;
|
|
|
|
};
|
|
|
|
|
2021-07-08 11:32:27 +08:00
|
|
|
static inline bool has_file_id(u64 id)
|
2021-03-16 09:50:04 +08:00
|
|
|
{
|
|
|
|
return id < KSMBD_NO_FID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool ksmbd_stream_fd(struct ksmbd_file *fp)
|
|
|
|
{
|
|
|
|
return fp->stream.name != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ksmbd_init_file_table(struct ksmbd_file_table *ft);
|
|
|
|
void ksmbd_destroy_file_table(struct ksmbd_file_table *ft);
|
2021-07-08 11:32:27 +08:00
|
|
|
int ksmbd_close_fd(struct ksmbd_work *work, u64 id);
|
|
|
|
struct ksmbd_file *ksmbd_lookup_fd_fast(struct ksmbd_work *work, u64 id);
|
|
|
|
struct ksmbd_file *ksmbd_lookup_foreign_fd(struct ksmbd_work *work, u64 id);
|
|
|
|
struct ksmbd_file *ksmbd_lookup_fd_slow(struct ksmbd_work *work, u64 id,
|
|
|
|
u64 pid);
|
2021-03-16 09:50:04 +08:00
|
|
|
void ksmbd_fd_put(struct ksmbd_work *work, struct ksmbd_file *fp);
|
2023-12-08 13:33:41 +08:00
|
|
|
struct ksmbd_inode *ksmbd_inode_lookup_lock(struct dentry *d);
|
|
|
|
void ksmbd_inode_put(struct ksmbd_inode *ci);
|
2024-03-12 13:05:57 +08:00
|
|
|
struct ksmbd_file *ksmbd_lookup_global_fd(unsigned long long id);
|
2021-03-16 09:50:04 +08:00
|
|
|
struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id);
|
2024-03-12 13:05:57 +08:00
|
|
|
void ksmbd_put_durable_fd(struct ksmbd_file *fp);
|
2021-03-16 09:50:04 +08:00
|
|
|
struct ksmbd_file *ksmbd_lookup_fd_cguid(char *cguid);
|
2023-11-20 08:13:54 +08:00
|
|
|
struct ksmbd_file *ksmbd_lookup_fd_inode(struct dentry *dentry);
|
2021-03-16 09:50:04 +08:00
|
|
|
unsigned int ksmbd_open_durable_fd(struct ksmbd_file *fp);
|
2021-03-30 13:25:35 +08:00
|
|
|
struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp);
|
2024-07-15 07:29:39 +08:00
|
|
|
void ksmbd_launch_ksmbd_durable_scavenger(void);
|
|
|
|
void ksmbd_stop_durable_scavenger(void);
|
2021-03-16 09:50:04 +08:00
|
|
|
void ksmbd_close_tree_conn_fds(struct ksmbd_work *work);
|
|
|
|
void ksmbd_close_session_fds(struct ksmbd_work *work);
|
|
|
|
int ksmbd_close_inode_fds(struct ksmbd_work *work, struct inode *inode);
|
|
|
|
int ksmbd_init_global_file_table(void);
|
|
|
|
void ksmbd_free_global_file_table(void);
|
|
|
|
void ksmbd_set_fd_limit(unsigned long limit);
|
2023-10-04 17:28:39 +08:00
|
|
|
void ksmbd_update_fstate(struct ksmbd_file_table *ft, struct ksmbd_file *fp,
|
|
|
|
unsigned int state);
|
2021-03-16 09:50:04 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* INODE hash
|
|
|
|
*/
|
|
|
|
int __init ksmbd_inode_hash_init(void);
|
2021-03-23 21:27:04 +08:00
|
|
|
void ksmbd_release_inode_hash(void);
|
2021-03-16 09:50:04 +08:00
|
|
|
|
|
|
|
enum KSMBD_INODE_STATUS {
|
|
|
|
KSMBD_INODE_STATUS_OK,
|
|
|
|
KSMBD_INODE_STATUS_UNKNOWN,
|
|
|
|
KSMBD_INODE_STATUS_PENDING_DELETE,
|
|
|
|
};
|
|
|
|
|
2023-11-20 08:13:54 +08:00
|
|
|
int ksmbd_query_inode_status(struct dentry *dentry);
|
2021-03-16 09:50:04 +08:00
|
|
|
bool ksmbd_inode_pending_delete(struct ksmbd_file *fp);
|
|
|
|
void ksmbd_set_inode_pending_delete(struct ksmbd_file *fp);
|
|
|
|
void ksmbd_clear_inode_pending_delete(struct ksmbd_file *fp);
|
|
|
|
void ksmbd_fd_set_delete_on_close(struct ksmbd_file *fp,
|
|
|
|
int file_info);
|
2024-03-12 13:05:57 +08:00
|
|
|
int ksmbd_reopen_durable_fd(struct ksmbd_work *work, struct ksmbd_file *fp);
|
|
|
|
int ksmbd_validate_name_reconnect(struct ksmbd_share_config *share,
|
|
|
|
struct ksmbd_file *fp, char *name);
|
2021-06-18 09:17:37 +08:00
|
|
|
int ksmbd_init_file_cache(void);
|
|
|
|
void ksmbd_exit_file_cache(void);
|
2021-03-16 09:50:04 +08:00
|
|
|
#endif /* __VFS_CACHE_H__ */
|