blob: 082d4b6bfc6a6cbe789fa2c6361ae3a88a8b3e27 [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 char lo_file_name[LO_NAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 struct file * lo_backing_file;
38 struct block_device *lo_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Al Virob4e3ca12005-10-21 03:22:34 -040040 gfp_t old_gfp_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 spinlock_t lo_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 int lo_state;
Dan Schatzberg87579e92021-06-28 19:38:15 -070044 spinlock_t lo_work_lock;
45 struct workqueue_struct *workqueue;
46 struct work_struct rootcg_work;
47 struct list_head rootcg_cmd_list;
48 struct list_head idle_worker_list;
49 struct rb_root worker_tree;
50 struct timer_list timer;
Ming Lei2e5ab5f2015-08-17 10:31:49 +080051 bool use_dio;
Tetsuo Handad3349b62018-05-04 10:58:09 -060052 bool sysfs_inited;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Arnd Bergmann01e457c2007-07-23 18:44:00 -070054 struct request_queue *lo_queue;
Ming Leib5dd2f62014-12-31 13:22:57 +000055 struct blk_mq_tag_set tag_set;
Ken Chen73285082007-05-08 00:28:20 -070056 struct gendisk *lo_disk;
Pavel Tatashin6cc8e742021-01-26 09:46:30 -050057 struct mutex lo_mutex;
Tetsuo Handa1c500ad2021-09-02 09:07:35 +090058 bool idr_visible;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
Ming Leib5dd2f62014-12-31 13:22:57 +000061struct loop_cmd {
Dan Schatzberg87579e92021-06-28 19:38:15 -070062 struct list_head list_entry;
Omar Sandovale5313c12017-09-20 14:24:34 -070063 bool use_aio; /* use AIO interface to handle I/O */
64 atomic_t ref; /* only for aio */
Christoph Hellwigfe2cb292017-04-20 16:03:02 +020065 long ret;
Ming Leibc07c102015-08-17 10:31:51 +080066 struct kiocb iocb;
Shaohua Li40326d82017-08-31 22:09:46 -070067 struct bio_vec *bvec;
Dan Schatzbergc74d40e2021-06-28 19:38:21 -070068 struct cgroup_subsys_state *blkcg_css;
69 struct cgroup_subsys_state *memcg_css;
Ming Leib5dd2f62014-12-31 13:22:57 +000070};
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#endif