blob: 1988899db63acf37008ff2bec741ef99812ec171 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Al Viro83a87612013-05-12 10:14:07 -04002 * loop.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Written by Theodore Ts'o, 3/29/93.
5 *
6 * Copyright 1993 by Theodore Ts'o. Redistribution of this file is
7 * permitted under the GNU General Public License.
8 */
David Howells607ca462012-10-13 10:46:48 +01009#ifndef _LINUX_LOOP_H
10#define _LINUX_LOOP_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/bio.h>
13#include <linux/blkdev.h>
Jens Axboe78e367a2015-01-02 15:20:25 -070014#include <linux/blk-mq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/spinlock.h>
Ingo Molnarf85221d2006-03-23 03:00:38 -080016#include <linux/mutex.h>
David Howells607ca462012-10-13 10:46:48 +010017#include <uapi/linux/loop.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/* Possible states of device */
20enum {
21 Lo_unbound,
22 Lo_bound,
23 Lo_rundown,
Christoph Hellwig990e7812021-06-05 17:09:50 +030024 Lo_deleting,
Linus Torvalds1da177e2005-04-16 15:20:36 -070025};
26
27struct loop_func_table;
28
29struct loop_device {
30 int lo_number;
Ming Leif8933662015-05-06 12:26:23 +080031 atomic_t lo_refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 loff_t lo_offset;
33 loff_t lo_sizelimit;
34 int lo_flags;
35 int (*transfer)(struct loop_device *, int cmd,
36 struct page *raw_page, unsigned raw_off,
37 struct page *loop_page, unsigned loop_off,
38 int size, sector_t real_block);
39 char lo_file_name[LO_NAME_SIZE];
40 char lo_crypt_name[LO_NAME_SIZE];
41 char lo_encrypt_key[LO_KEY_SIZE];
42 int lo_encrypt_key_size;
43 struct loop_func_table *lo_encryption;
44 __u32 lo_init[2];
Eric W. Biedermane4849732012-02-11 11:23:51 -080045 kuid_t lo_key_owner; /* Who set the key */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 int (*ioctl)(struct loop_device *, int cmd,
47 unsigned long arg);
48
49 struct file * lo_backing_file;
50 struct block_device *lo_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 void *key_data;
52
Al Virob4e3ca12005-10-21 03:22:34 -040053 gfp_t old_gfp_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 spinlock_t lo_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 int lo_state;
Dan Schatzberg87579e92021-06-28 19:38:15 -070057 spinlock_t lo_work_lock;
58 struct workqueue_struct *workqueue;
59 struct work_struct rootcg_work;
60 struct list_head rootcg_cmd_list;
61 struct list_head idle_worker_list;
62 struct rb_root worker_tree;
63 struct timer_list timer;
Ming Lei2e5ab5f2015-08-17 10:31:49 +080064 bool use_dio;
Tetsuo Handad3349b62018-05-04 10:58:09 -060065 bool sysfs_inited;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Arnd Bergmann01e457c2007-07-23 18:44:00 -070067 struct request_queue *lo_queue;
Ming Leib5dd2f62014-12-31 13:22:57 +000068 struct blk_mq_tag_set tag_set;
Ken Chen73285082007-05-08 00:28:20 -070069 struct gendisk *lo_disk;
Pavel Tatashin6cc8e742021-01-26 09:46:30 -050070 struct mutex lo_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071};
72
Ming Leib5dd2f62014-12-31 13:22:57 +000073struct loop_cmd {
Dan Schatzberg87579e92021-06-28 19:38:15 -070074 struct list_head list_entry;
Omar Sandovale5313c12017-09-20 14:24:34 -070075 bool use_aio; /* use AIO interface to handle I/O */
76 atomic_t ref; /* only for aio */
Christoph Hellwigfe2cb292017-04-20 16:03:02 +020077 long ret;
Ming Leibc07c102015-08-17 10:31:51 +080078 struct kiocb iocb;
Shaohua Li40326d82017-08-31 22:09:46 -070079 struct bio_vec *bvec;
Dan Schatzbergc74d40e2021-06-28 19:38:21 -070080 struct cgroup_subsys_state *blkcg_css;
81 struct cgroup_subsys_state *memcg_css;
Ming Leib5dd2f62014-12-31 13:22:57 +000082};
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/* Support for loadable transfer modules */
85struct loop_func_table {
86 int number; /* filter type */
87 int (*transfer)(struct loop_device *lo, int cmd,
88 struct page *raw_page, unsigned raw_off,
89 struct page *loop_page, unsigned loop_off,
90 int size, sector_t real_block);
91 int (*init)(struct loop_device *, const struct loop_info64 *);
92 /* release is called from loop_unregister_transfer or clr_fd */
93 int (*release)(struct loop_device *);
94 int (*ioctl)(struct loop_device *, int cmd, unsigned long arg);
95 struct module *owner;
96};
97
98int loop_register_transfer(struct loop_func_table *funcs);
99int loop_unregister_transfer(int number);
100
101#endif