123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
#ifndef _FS_FUSE_DEV_I_H
#define _FS_FUSE_DEV_I_H
#include <linux/fuse.h>
#include <linux/types.h>
#include <linux/refcount.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
#include <linux/fs.h>
#define FUSE_INT_REQ_BIT (1ULL << 0)
#define FUSE_REQ_ID_STEP (1ULL << 1)
struct fuse_arg;
struct fuse_args;
struct fuse_pqueue;
struct fuse_iqueue;
enum fuse_req_flag {
FR_ISREPLY,
FR_FORCE,
FR_BACKGROUND,
FR_WAITING,
FR_ABORTED,
FR_INTERRUPTED,
FR_LOCKED,
FR_PENDING,
FR_SENT,
FR_FINISHED,
FR_PRIVATE,
FR_ASYNC,
FR_URING,
FR_SYNC_WAKEUP,
};
struct fuse_req {
struct list_head list;
struct list_head intr_entry;
struct fuse_args *args;
refcount_t count;
unsigned long flags;
struct {
struct fuse_in_header h;
} in;
struct {
struct fuse_out_header h;
} out;
wait_queue_head_t waitq;
#if IS_ENABLED(CONFIG_VIRTIO_FS)
void *argbuf;
#endif
struct fuse_chan *chan;
#ifdef CONFIG_FUSE_IO_URING
void *ring_entry;
void *ring_queue;
#endif
unsigned long create_time;
};
struct fuse_forget_link {
struct fuse_forget_one forget_one;
struct fuse_forget_link *next;
};
struct fuse_iqueue_ops {
void (*send_forget)(struct fuse_iqueue *fiq, struct fuse_forget_link *link);
void (*send_interrupt)(struct fuse_iqueue *fiq, struct fuse_req *req);
void (*send_req)(struct fuse_iqueue *fiq, struct fuse_req *req);
void (*release)(struct fuse_iqueue *fiq);
};
struct fuse_iqueue {
unsigned connected;
spinlock_t lock;
wait_queue_head_t waitq;
u64 reqctr;
struct list_head pending;
struct list_head interrupts;
struct fuse_forget_link forget_list_head;
struct fuse_forget_link *forget_list_tail;
int forget_batch;
struct fasync_struct *fasync;
const struct fuse_iqueue_ops *ops;
void *priv;
};
struct fuse_chan {
spinlock_t lock;
struct fuse_conn *conn;
struct fuse_iqueue iq;
struct list_head devices;
unsigned max_background;
unsigned num_background;
unsigned active_background;
struct list_head bg_queue;
spinlock_t bg_lock;
int initialized;
int blocked;
wait_queue_head_t blocked_waitq;
unsigned connected;
atomic_t num_waiting;
bool no_interrupt;
bool conn_refused;
unsigned int io_uring;
unsigned int minor;
unsigned int max_write;
unsigned int max_pages;
struct list_head *pq_prealloc;
bool abort_with_err;
#ifdef CONFIG_FUSE_IO_URING
struct fuse_ring *ring;
#endif
struct {
struct delayed_work work;
unsigned int req_timeout;
} timeout;
};
#define FUSE_PQ_HASH_BITS 8
#define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
struct fuse_pqueue {
unsigned connected;
spinlock_t lock;
struct list_head *processing;
struct list_head io;
};
struct fuse_dev {
refcount_t ref;
bool sync_init;
struct fuse_chan *chan;
struct fuse_pqueue pq;
struct list_head entry;
};
struct fuse_copy_state {
struct fuse_req *req;
struct iov_iter *iter;
struct pipe_buffer *pipebufs;
struct pipe_buffer *currbuf;
struct pipe_inode_info *pipe;
unsigned long nr_segs;
struct page *pg;
unsigned int len;
unsigned int offset;
bool write:1;
bool is_uring:1;
bool skip_folio_copy:1;
struct {
unsigned int copied_sz;
} ring;
};
#define FUSE_DEV_CHAN_DISCONNECTED ((struct fuse_chan *) 1)
static inline struct fuse_chan *fuse_dev_chan_get(struct fuse_dev *fud)
{
return smp_load_acquire(&fud->chan);
}
static inline struct fuse_dev *fuse_file_to_fud(struct file *file)
{
return file->private_data;
}
static inline struct fuse_dev *__fuse_get_dev(struct file *file)
{
struct fuse_dev *fud = fuse_file_to_fud(file);
if (!fuse_dev_chan_get(fud))
return NULL;
return fud;
}
void fuse_iqueue_init(struct fuse_iqueue *fiq, const struct fuse_iqueue_ops *ops, void *priv);
struct fuse_dev *fuse_get_dev(struct file *file);
unsigned int fuse_req_hash(u64 unique);
struct fuse_req *fuse_request_find(struct fuse_pqueue *fpq, u64 unique);
void fuse_dev_end_requests(struct list_head *head);
void fuse_request_bg_finish(struct fuse_chan *fch, struct fuse_req *req);
void fuse_copy_init(struct fuse_copy_state *cs, bool write,
struct iov_iter *iter);
unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
int fuse_copy_args(struct fuse_copy_state *cs, unsigned int numargs,
unsigned int argpages, struct fuse_arg *args,
int zeroing);
int fuse_copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args,
unsigned int nbytes);
void fuse_dev_queue_forget(struct fuse_iqueue *fiq,
struct fuse_forget_link *forget);
void fuse_dev_queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req);
bool fuse_remove_pending_req(struct fuse_req *req, spinlock_t *lock);
bool fuse_request_expired(struct fuse_chan *fch, struct list_head *list);
void fuse_request_assign_unique(struct fuse_iqueue *fiq, struct fuse_req *req);
u64 fuse_get_unique(struct fuse_iqueue *fiq);
struct fuse_dev *fuse_dev_alloc_install(struct fuse_chan *fch);
struct fuse_dev *fuse_dev_alloc(void);
int fuse_dev_release(struct inode *inode, struct file *file);
struct list_head *fuse_pqueue_alloc(void);
void fuse_pqueue_init(struct fuse_pqueue *fpq);
void fuse_request_end(struct fuse_req *req);
#endif