loop.h 2.3 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
A
Al Viro 已提交
2
 * loop.h
L
Linus Torvalds 已提交
3 4 5 6 7 8
 *
 * Written by Theodore Ts'o, 3/29/93.
 *
 * Copyright 1993 by Theodore Ts'o.  Redistribution of this file is
 * permitted under the GNU General Public License.
 */
9 10
#ifndef _LINUX_LOOP_H
#define _LINUX_LOOP_H
L
Linus Torvalds 已提交
11 12 13

#include <linux/bio.h>
#include <linux/blkdev.h>
J
Jens Axboe 已提交
14
#include <linux/blk-mq.h>
L
Linus Torvalds 已提交
15
#include <linux/spinlock.h>
16
#include <linux/mutex.h>
M
Ming Lei 已提交
17
#include <linux/kthread.h>
18
#include <uapi/linux/loop.h>
L
Linus Torvalds 已提交
19 20 21 22 23 24 25 26 27 28 29 30

/* Possible states of device */
enum {
	Lo_unbound,
	Lo_bound,
	Lo_rundown,
};

struct loop_func_table;

struct loop_device {
	int		lo_number;
31
	atomic_t	lo_refcnt;
L
Linus Torvalds 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44
	loff_t		lo_offset;
	loff_t		lo_sizelimit;
	int		lo_flags;
	int		(*transfer)(struct loop_device *, int cmd,
				    struct page *raw_page, unsigned raw_off,
				    struct page *loop_page, unsigned loop_off,
				    int size, sector_t real_block);
	char		lo_file_name[LO_NAME_SIZE];
	char		lo_crypt_name[LO_NAME_SIZE];
	char		lo_encrypt_key[LO_KEY_SIZE];
	int		lo_encrypt_key_size;
	struct loop_func_table *lo_encryption;
	__u32           lo_init[2];
45
	kuid_t		lo_key_owner;	/* Who set the key */
L
Linus Torvalds 已提交
46 47 48 49 50 51 52
	int		(*ioctl)(struct loop_device *, int cmd, 
				 unsigned long arg); 

	struct file *	lo_backing_file;
	struct block_device *lo_device;
	void		*key_data; 

53
	gfp_t		old_gfp_mask;
L
Linus Torvalds 已提交
54 55 56

	spinlock_t		lo_lock;
	int			lo_state;
57
	struct mutex		lo_ctl_mutex;
M
Ming Lei 已提交
58 59
	struct kthread_worker	worker;
	struct task_struct	*worker_task;
60
	bool			use_dio;
L
Linus Torvalds 已提交
61

A
Arnd Bergmann 已提交
62
	struct request_queue	*lo_queue;
63
	struct blk_mq_tag_set	tag_set;
64
	struct gendisk		*lo_disk;
L
Linus Torvalds 已提交
65 66
};

67
struct loop_cmd {
M
Ming Lei 已提交
68
	struct kthread_work work;
69 70
	struct request *rq;
	struct list_head list;
S
Shaohua Li 已提交
71 72 73 74
	union {
		bool use_aio; /* use AIO interface to handle I/O */
		atomic_t ref; /* only for aio */
	};
75
	long ret;
M
Ming Lei 已提交
76
	struct kiocb iocb;
77
	struct bio_vec *bvec;
78 79
};

L
Linus Torvalds 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/* Support for loadable transfer modules */
struct loop_func_table {
	int number;	/* filter type */ 
	int (*transfer)(struct loop_device *lo, int cmd,
			struct page *raw_page, unsigned raw_off,
			struct page *loop_page, unsigned loop_off,
			int size, sector_t real_block);
	int (*init)(struct loop_device *, const struct loop_info64 *); 
	/* release is called from loop_unregister_transfer or clr_fd */
	int (*release)(struct loop_device *); 
	int (*ioctl)(struct loop_device *, int cmd, unsigned long arg);
	struct module *owner;
}; 

int loop_register_transfer(struct loop_func_table *funcs);
int loop_unregister_transfer(int number); 

#endif