rnbd-clt.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * RDMA Network Block Driver
  4. *
  5. * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
  6. * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
  7. * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
  8. */
  9. #ifndef RNBD_CLT_H
  10. #define RNBD_CLT_H
  11. #include <linux/wait.h>
  12. #include <linux/in.h>
  13. #include <linux/inet.h>
  14. #include <linux/blk-mq.h>
  15. #include <linux/refcount.h>
  16. #include <rtrs.h>
  17. #include "rnbd-proto.h"
  18. #include "rnbd-log.h"
  19. /* time in seconds between reconnect tries, default to 30 s */
  20. #define RECONNECT_DELAY 30
  21. /*
  22. * Number of times to reconnect on error before giving up, 0 for * disabled,
  23. * -1 for forever
  24. */
  25. #define MAX_RECONNECTS -1
  26. enum rnbd_clt_dev_state {
  27. DEV_STATE_INIT,
  28. DEV_STATE_MAPPED,
  29. DEV_STATE_MAPPED_DISCONNECTED,
  30. DEV_STATE_UNMAPPED,
  31. };
  32. struct rnbd_iu_comp {
  33. wait_queue_head_t wait;
  34. int errno;
  35. };
  36. #ifdef CONFIG_ARCH_NO_SG_CHAIN
  37. #define RNBD_INLINE_SG_CNT 0
  38. #else
  39. #define RNBD_INLINE_SG_CNT 2
  40. #endif
  41. #define RNBD_RDMA_SGL_SIZE (sizeof(struct scatterlist) * RNBD_INLINE_SG_CNT)
  42. struct rnbd_iu {
  43. union {
  44. struct request *rq; /* for block io */
  45. void *buf; /* for user messages */
  46. };
  47. struct rtrs_permit *permit;
  48. union {
  49. /* use to send msg associated with a dev */
  50. struct rnbd_clt_dev *dev;
  51. /* use to send msg associated with a sess */
  52. struct rnbd_clt_session *sess;
  53. };
  54. struct sg_table sgt;
  55. struct work_struct work;
  56. int errno;
  57. struct rnbd_iu_comp comp;
  58. atomic_t refcount;
  59. struct scatterlist first_sgl[]; /* must be the last one */
  60. };
  61. struct rnbd_cpu_qlist {
  62. struct list_head requeue_list;
  63. spinlock_t requeue_lock;
  64. unsigned int cpu;
  65. };
  66. struct rnbd_clt_session {
  67. struct list_head list;
  68. struct rtrs_clt_sess *rtrs;
  69. wait_queue_head_t rtrs_waitq;
  70. bool rtrs_ready;
  71. struct rnbd_cpu_qlist __percpu
  72. *cpu_queues;
  73. DECLARE_BITMAP(cpu_queues_bm, NR_CPUS);
  74. int __percpu *cpu_rr; /* per-cpu var for CPU round-robin */
  75. atomic_t busy;
  76. size_t queue_depth;
  77. u32 max_io_size;
  78. u32 max_segments;
  79. struct blk_mq_tag_set tag_set;
  80. u32 nr_poll_queues;
  81. struct mutex lock; /* protects state and devs_list */
  82. struct list_head devs_list; /* list of struct rnbd_clt_dev */
  83. refcount_t refcount;
  84. char sessname[NAME_MAX];
  85. u8 ver; /* protocol version */
  86. };
  87. /**
  88. * Submission queues.
  89. */
  90. struct rnbd_queue {
  91. struct list_head requeue_list;
  92. unsigned long in_list;
  93. struct rnbd_clt_dev *dev;
  94. struct blk_mq_hw_ctx *hctx;
  95. };
  96. struct rnbd_clt_dev {
  97. struct kobject kobj;
  98. struct rnbd_clt_session *sess;
  99. struct request_queue *queue;
  100. struct rnbd_queue *hw_queues;
  101. u32 device_id;
  102. /* local Idr index - used to track minor number allocations. */
  103. int clt_device_id;
  104. struct mutex lock;
  105. enum rnbd_clt_dev_state dev_state;
  106. refcount_t refcount;
  107. char *pathname;
  108. enum rnbd_access_mode access_mode;
  109. u32 nr_poll_queues;
  110. u64 size; /* device size in bytes */
  111. struct list_head list;
  112. struct gendisk *gd;
  113. char *blk_symlink_name;
  114. struct work_struct unmap_on_rmmod_work;
  115. };
  116. /* rnbd-clt.c */
  117. struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
  118. struct rtrs_addr *paths,
  119. size_t path_cnt, u16 port_nr,
  120. const char *pathname,
  121. enum rnbd_access_mode access_mode,
  122. u32 nr_poll_queues);
  123. int rnbd_clt_unmap_device(struct rnbd_clt_dev *dev, bool force,
  124. const struct attribute *sysfs_self);
  125. int rnbd_clt_remap_device(struct rnbd_clt_dev *dev);
  126. int rnbd_clt_resize_disk(struct rnbd_clt_dev *dev, sector_t newsize);
  127. /* rnbd-clt-sysfs.c */
  128. int rnbd_clt_create_sysfs_files(void);
  129. void rnbd_clt_destroy_sysfs_files(void);
  130. void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev *dev);
  131. #endif /* RNBD_CLT_H */