drbd: Minimal struct drbd_tconn
[linux-block.git] / drivers / block / drbd / drbd_int.h
index 058371318da492a841782ed5164f2f2d64297f88..1f486f001dfddbffd3829d57ba8fb72ad0d3be81 100644 (file)
@@ -94,6 +94,7 @@ extern char usermode_helper[];
 #define UUID_NEW_BM_OFFSET ((u64)0x0001000000000000ULL)
 
 struct drbd_conf;
+struct drbd_tconn;
 
 
 /* to shorten dev_warn(DEV, "msg"); and relatives statements */
@@ -102,12 +103,18 @@ struct drbd_conf;
 #define D_ASSERT(exp)  if (!(exp)) \
         dev_err(DEV, "ASSERT( " #exp " ) in %s:%d\n", __FILE__, __LINE__)
 
-#define ERR_IF(exp) if (({                                             \
-       int _b = (exp) != 0;                                            \
-       if (_b) dev_err(DEV, "ASSERT FAILED: %s: (%s) in %s:%d\n",      \
-                       __func__, #exp, __FILE__, __LINE__);            \
-       _b;                                                             \
-       }))
+/**
+ * expect  -  Make an assertion
+ *
+ * Unlike the assert macro, this macro returns a boolean result.
+ */
+#define expect(exp) ({                                                         \
+               bool _bool = (exp);                                             \
+               if (!_bool)                                                     \
+                       dev_err(DEV, "ASSERTION %s FAILED in %s\n",             \
+                               #exp, __func__);                                \
+               _bool;                                                          \
+               })
 
 /* Defines to control fault insertion */
 enum {
@@ -649,10 +656,10 @@ union p_polymorph {
 
 /**********************************************************************/
 enum drbd_thread_state {
-       None,
-       Running,
-       Exiting,
-       Restarting
+       NONE,
+       RUNNING,
+       EXITING,
+       RESTARTING
 };
 
 struct drbd_thread {
@@ -694,7 +701,6 @@ struct drbd_request {
         * see drbd_endio_pri(). */
        struct bio *private_bio;
 
-       struct hlist_node collision;
        struct drbd_interval i;
        unsigned int epoch; /* barrier_nr */
 
@@ -759,15 +765,13 @@ struct digest_info {
 
 struct drbd_epoch_entry {
        struct drbd_work w;
-       struct hlist_node collision;
        struct drbd_epoch *epoch; /* for writes */
        struct drbd_conf *mdev;
        struct page *pages;
        atomic_t pending_bios;
-       unsigned int size;
+       struct drbd_interval i;
        /* see comments on ee flag bits below */
        unsigned long flags;
-       sector_t sector;
        union {
                u64 block_id;
                struct digest_info *digest;
@@ -957,7 +961,18 @@ struct fifo_buffer {
        unsigned int size;
 };
 
+struct drbd_tconn {                    /* is a resource from the config file */
+       char *name;                     /* Resource name */
+       struct list_head all_tconn;     /* List of all drbd_tconn, prot by global_state_lock */
+       struct drbd_conf *volume0;      /* TODO: Remove me again */
+
+       struct net_conf *net_conf;      /* protected by get_net_conf() and put_net_conf() */
+};
+
 struct drbd_conf {
+       struct drbd_tconn *tconn;
+       int vnr;                        /* volume number within the connection */
+
        /* things that are stored as / read from meta data on disk */
        unsigned long flags;
 
@@ -1016,10 +1031,9 @@ struct drbd_conf {
        struct drbd_tl_epoch *newest_tle;
        struct drbd_tl_epoch *oldest_tle;
        struct list_head out_of_sequence_requests;
-       struct hlist_head *tl_hash;
-       unsigned int tl_hash_s;
 
-       /* Interval tree of pending local write requests */
+       /* Interval tree of pending local requests */
+       struct rb_root read_requests;
        struct rb_root write_requests;
 
        /* blocks to resync in this run [unit BM_BLOCK_SIZE] */
@@ -1077,14 +1091,14 @@ struct drbd_conf {
        struct list_head done_ee;   /* send ack */
        struct list_head read_ee;   /* IO in progress (any read) */
        struct list_head net_ee;    /* zero-copy network send in progress */
-       struct hlist_head *ee_hash; /* is proteced by req_lock! */
-       unsigned int ee_hash_s;
+
+       /* Interval tree of pending remote write requests (struct drbd_epoch_entry) */
+       struct rb_root epoch_entries;
 
        /* this one is protected by ee_lock, single thread */
        struct drbd_epoch_entry *last_write_w_barrier;
 
        int next_barrier_nr;
-       struct hlist_head *app_reads_hash; /* is proteced by req_lock */
        struct list_head resync_reads;
        atomic_t pp_in_use;             /* allocated from page pool */
        atomic_t pp_in_use_by_net;      /* sendpage()d, still referenced by tcp */
@@ -1425,18 +1439,12 @@ struct bm_extent {
 #endif
 #endif
 
-/* Sector shift value for the "hash" functions of tl_hash and ee_hash tables.
- * With a value of 8 all IO in one 128K block make it to the same slot of the
- * hash table. */
 #define HT_SHIFT 8
 #define DRBD_MAX_BIO_SIZE (1U<<(9+HT_SHIFT))
 #define DRBD_MAX_BIO_SIZE_SAFE (1 << 12)       /* Works always = 4k */
 
 #define DRBD_MAX_SIZE_H80_PACKET (1 << 15) /* The old header only allows packets up to 32Kib data */
 
-/* Number of elements in the app_reads_hash */
-#define APP_R_HSIZE 15
-
 extern int  drbd_bm_init(struct drbd_conf *mdev);
 extern int  drbd_bm_resize(struct drbd_conf *mdev, sector_t sectors, int set_new_bits);
 extern void drbd_bm_cleanup(struct drbd_conf *mdev);
@@ -1500,6 +1508,9 @@ extern rwlock_t global_state_lock;
 extern struct drbd_conf *drbd_new_device(unsigned int minor);
 extern void drbd_free_mdev(struct drbd_conf *mdev);
 
+struct drbd_tconn *drbd_new_tconn(char *name);
+extern void drbd_free_tconn(struct drbd_tconn *tconn);
+
 extern int proc_details;
 
 /* drbd_req */
@@ -2041,21 +2052,21 @@ static inline void drbd_thread_restart_nowait(struct drbd_thread *thi)
  * or implicit barrier packets as necessary.
  * increased:
  *  w_send_barrier
- *  _req_mod(req, queue_for_net_write or queue_for_net_read);
+ *  _req_mod(req, QUEUE_FOR_NET_WRITE or QUEUE_FOR_NET_READ);
  *    it is much easier and equally valid to count what we queue for the
  *    worker, even before it actually was queued or send.
  *    (drbd_make_request_common; recovery path on read io-error)
  * decreased:
  *  got_BarrierAck (respective tl_clear, tl_clear_barrier)
- *  _req_mod(req, data_received)
+ *  _req_mod(req, DATA_RECEIVED)
  *     [from receive_DataReply]
- *  _req_mod(req, write_acked_by_peer or recv_acked_by_peer or neg_acked)
+ *  _req_mod(req, WRITE_ACKED_BY_PEER or RECV_ACKED_BY_PEER or NEG_ACKED)
  *     [from got_BlockAck (P_WRITE_ACK, P_RECV_ACK)]
  *     for some reason it is NOT decreased in got_NegAck,
  *     but in the resulting cleanup code from report_params.
  *     we should try to remember the reason for that...
- *  _req_mod(req, send_failed or send_canceled)
- *  _req_mod(req, connection_lost_while_pending)
+ *  _req_mod(req, SEND_FAILED or SEND_CANCELED)
+ *  _req_mod(req, CONNECTION_LOST_WHILE_PENDING)
  *     [from tl_clear_barrier]
  */
 static inline void inc_ap_pending(struct drbd_conf *mdev)