loop.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. void *key_data;
  47. gfp_t old_gfp_mask;
  48. spinlock_t lo_lock;
  49. int lo_state;
  50. struct kthread_worker worker;
  51. struct task_struct *worker_task;
  52. bool use_dio;
  53. bool sysfs_inited;
  54. struct request_queue *lo_queue;
  55. struct blk_mq_tag_set tag_set;
  56. struct gendisk *lo_disk;
  57. };
  58. struct loop_cmd {
  59. struct kthread_work work;
  60. bool use_aio; /* use AIO interface to handle I/O */
  61. atomic_t ref; /* only for aio */
  62. long ret;
  63. struct kiocb iocb;
  64. struct bio_vec *bvec;
  65. struct cgroup_subsys_state *css;
  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