loop.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * loop.h
  3. *
  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. */
  9. #ifndef _LINUX_LOOP_H
  10. #define _LINUX_LOOP_H
  11. #include <linux/bio.h>
  12. #include <linux/blkdev.h>
  13. #include <linux/blk-mq.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/mutex.h>
  16. #include <linux/kthread.h>
  17. #include <uapi/linux/loop.h>
  18. /* Possible states of device */
  19. enum {
  20. Lo_unbound,
  21. Lo_bound,
  22. Lo_rundown,
  23. };
  24. struct loop_func_table;
  25. struct loop_device {
  26. int lo_number;
  27. atomic_t lo_refcnt;
  28. loff_t lo_offset;
  29. loff_t lo_sizelimit;
  30. int lo_flags;
  31. int (*transfer)(struct loop_device *, int cmd,
  32. struct page *raw_page, unsigned raw_off,
  33. struct page *loop_page, unsigned loop_off,
  34. int size, sector_t real_block);
  35. char lo_file_name[LO_NAME_SIZE];
  36. char lo_crypt_name[LO_NAME_SIZE];
  37. char lo_encrypt_key[LO_KEY_SIZE];
  38. int lo_encrypt_key_size;
  39. struct loop_func_table *lo_encryption;
  40. __u32 lo_init[2];
  41. kuid_t lo_key_owner; /* Who set the key */
  42. int (*ioctl)(struct loop_device *, int cmd,
  43. unsigned long arg);
  44. struct file * lo_backing_file;
  45. struct block_device *lo_device;
  46. unsigned lo_blocksize;
  47. void *key_data;
  48. gfp_t old_gfp_mask;
  49. spinlock_t lo_lock;
  50. int lo_state;
  51. struct mutex lo_ctl_mutex;
  52. struct kthread_worker worker;
  53. struct task_struct *worker_task;
  54. bool use_dio;
  55. bool sysfs_inited;
  56. struct request_queue *lo_queue;
  57. struct blk_mq_tag_set tag_set;
  58. struct gendisk *lo_disk;
  59. };
  60. struct loop_cmd {
  61. struct kthread_work work;
  62. struct request *rq;
  63. struct list_head list;
  64. bool use_aio; /* use AIO interface to handle I/O */
  65. struct kiocb iocb;
  66. };
  67. /* Support for loadable transfer modules */
  68. struct loop_func_table {
  69. int number; /* filter type */
  70. int (*transfer)(struct loop_device *lo, int cmd,
  71. struct page *raw_page, unsigned raw_off,
  72. struct page *loop_page, unsigned loop_off,
  73. int size, sector_t real_block);
  74. int (*init)(struct loop_device *, const struct loop_info64 *);
  75. /* release is called from loop_unregister_transfer or clr_fd */
  76. int (*release)(struct loop_device *);
  77. int (*ioctl)(struct loop_device *, int cmd, unsigned long arg);
  78. struct module *owner;
  79. };
  80. int loop_register_transfer(struct loop_func_table *funcs);
  81. int loop_unregister_transfer(int number);
  82. #endif