]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/block/drbd/drbd_int.h
drbd: moved receiver, worker and asender from mdev to tconn
[mirror_ubuntu-bionic-kernel.git] / drivers / block / drbd / drbd_int.h
index d871b14ed5a186a22d758308f1a498fbfe66de26..c5b1167aab5005f2e468d3b63faadbc3e65f2928 100644 (file)
@@ -87,20 +87,14 @@ extern char usermode_helper[];
  */
 #define DRBD_SIGKILL SIGHUP
 
-/* All EEs on the free list should have ID_VACANT (== 0)
- * freshly allocated EEs get !ID_VACANT (== 1)
- * so if it says "cannot dereference null pointer at address 0x00000001",
- * it is most likely one of these :( */
-
 #define ID_IN_SYNC      (4711ULL)
 #define ID_OUT_OF_SYNC  (4712ULL)
-
 #define ID_SYNCER (-1ULL)
-#define ID_VACANT 0
-#define is_syncer_block_id(id) ((id) == ID_SYNCER)
+
 #define UUID_NEW_BM_OFFSET ((u64)0x0001000000000000ULL)
 
 struct drbd_conf;
+struct drbd_tconn;
 
 
 /* to shorten dev_warn(DEV, "msg"); and relatives statements */
@@ -109,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 {
@@ -656,10 +656,10 @@ union p_polymorph {
 
 /**********************************************************************/
 enum drbd_thread_state {
-       None,
-       Running,
-       Exiting,
-       Restarting
+       NONE,
+       RUNNING,
+       EXITING,
+       RESTARTING
 };
 
 struct drbd_thread {
@@ -689,7 +689,8 @@ struct drbd_work {
        drbd_work_cb cb;
 };
 
-struct drbd_tl_epoch;
+#include "drbd_interval.h"
+
 struct drbd_request {
        struct drbd_work w;
        struct drbd_conf *mdev;
@@ -700,9 +701,7 @@ struct drbd_request {
         * see drbd_endio_pri(). */
        struct bio *private_bio;
 
-       struct hlist_node colision;
-       sector_t sector;
-       unsigned int size;
+       struct drbd_interval i;
        unsigned int epoch; /* barrier_nr */
 
        /* barrier_nr: used to check on "completion" whether this req was in
@@ -766,15 +765,13 @@ struct digest_info {
 
 struct drbd_epoch_entry {
        struct drbd_work w;
-       struct hlist_node colision;
        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;
@@ -964,12 +961,31 @@ 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() */
+       atomic_t net_cnt;               /* Users of net_conf */
+       wait_queue_head_t net_cnt_wait;
+
+       struct drbd_socket data;        /* data/barrier/cstate/parameter packets */
+       struct drbd_socket meta;        /* ping/ack (metadata) packets */
+
+       struct drbd_thread receiver;
+       struct drbd_thread worker;
+       struct drbd_thread asender;
+};
+
 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;
 
        /* configured by drbdsetup */
-       struct net_conf *net_conf; /* protected by get_net_conf() and put_net_conf() */
        struct syncer_conf sync_conf;
        struct drbd_backing_dev *ldev __protected_by(local);
 
@@ -978,8 +994,6 @@ struct drbd_conf {
        struct block_device *this_bdev;
        struct gendisk      *vdisk;
 
-       struct drbd_socket data; /* data/barrier/cstate/parameter packets */
-       struct drbd_socket meta; /* ping/ack (metadata) packets */
        int agreed_pro_version;  /* actually used protocol version */
        unsigned long last_received; /* in jiffies, either socket */
        unsigned int ko_count;
@@ -1005,7 +1019,6 @@ struct drbd_conf {
        union drbd_state state;
        wait_queue_head_t misc_wait;
        wait_queue_head_t state_wait;  /* upon each state change. */
-       wait_queue_head_t net_cnt_wait;
        unsigned int send_cnt;
        unsigned int recv_cnt;
        unsigned int read_cnt;
@@ -1017,14 +1030,16 @@ struct drbd_conf {
        atomic_t rs_pending_cnt; /* RS request/data packets on the wire */
        atomic_t unacked_cnt;    /* Need to send replys for */
        atomic_t local_cnt;      /* Waiting for local completion */
-       atomic_t net_cnt;        /* Users of net_conf */
+
        spinlock_t req_lock;
        struct drbd_tl_epoch *unused_spare_tle; /* for pre-allocation */
        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 requests */
+       struct rb_root read_requests;
+       struct rb_root write_requests;
 
        /* blocks to resync in this run [unit BM_BLOCK_SIZE] */
        unsigned long rs_total;
@@ -1057,9 +1072,6 @@ struct drbd_conf {
        struct crypto_hash *csums_tfm;
        struct crypto_hash *verify_tfm;
 
-       struct drbd_thread receiver;
-       struct drbd_thread worker;
-       struct drbd_thread asender;
        struct drbd_bitmap *bitmap;
        unsigned long bm_resync_fo; /* bit offset for drbd_bm_find_next */
 
@@ -1081,14 +1093,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 */
@@ -1129,6 +1141,8 @@ struct drbd_conf {
        int rs_in_flight; /* resync sectors in flight (to proxy, in proxy and from proxy) */
        int rs_planed;    /* resync sectors already planned */
        atomic_t ap_in_flight; /* App sectors in flight (waiting for ack) */
+       int peer_max_bio_size;
+       int local_max_bio_size;
 };
 
 static inline struct drbd_conf *minor_to_mdev(unsigned int minor)
@@ -1155,11 +1169,11 @@ static inline unsigned int mdev_to_minor(struct drbd_conf *mdev)
  */
 static inline int drbd_get_data_sock(struct drbd_conf *mdev)
 {
-       mutex_lock(&mdev->data.mutex);
+       mutex_lock(&mdev->tconn->data.mutex);
        /* drbd_disconnect() could have called drbd_free_sock()
         * while we were waiting in down()... */
-       if (unlikely(mdev->data.socket == NULL)) {
-               mutex_unlock(&mdev->data.mutex);
+       if (unlikely(mdev->tconn->data.socket == NULL)) {
+               mutex_unlock(&mdev->tconn->data.mutex);
                return 0;
        }
        return 1;
@@ -1167,7 +1181,7 @@ static inline int drbd_get_data_sock(struct drbd_conf *mdev)
 
 static inline void drbd_put_data_sock(struct drbd_conf *mdev)
 {
-       mutex_unlock(&mdev->data.mutex);
+       mutex_unlock(&mdev->tconn->data.mutex);
 }
 
 /*
@@ -1218,8 +1232,6 @@ extern void drbd_free_resources(struct drbd_conf *mdev);
 extern void tl_release(struct drbd_conf *mdev, unsigned int barrier_nr,
                       unsigned int set_size);
 extern void tl_clear(struct drbd_conf *mdev);
-enum drbd_req_event;
-extern void tl_restart(struct drbd_conf *mdev, enum drbd_req_event what);
 extern void _tl_add_barrier(struct drbd_conf *, struct drbd_tl_epoch *);
 extern void drbd_free_sock(struct drbd_conf *mdev);
 extern int drbd_send(struct drbd_conf *mdev, struct socket *sock,
@@ -1429,17 +1441,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);
@@ -1503,6 +1510,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 */
@@ -1518,9 +1528,9 @@ extern void drbd_resume_io(struct drbd_conf *mdev);
 extern char *ppsize(char *buf, unsigned long long size);
 extern sector_t drbd_new_dev_size(struct drbd_conf *, struct drbd_backing_dev *, int);
 enum determine_dev_size { dev_size_error = -1, unchanged = 0, shrunk = 1, grew = 2 };
-extern enum determine_dev_size drbd_determin_dev_size(struct drbd_conf *, enum dds_flags) __must_hold(local);
+extern enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *, enum dds_flags) __must_hold(local);
 extern void resync_after_online_grow(struct drbd_conf *);
-extern void drbd_setup_queue_param(struct drbd_conf *mdev, unsigned int) __must_hold(local);
+extern void drbd_reconsider_max_bio_size(struct drbd_conf *mdev);
 extern enum drbd_state_rv drbd_set_role(struct drbd_conf *mdev,
                                        enum drbd_role new_role,
                                        int force);
@@ -1599,7 +1609,6 @@ extern void _drbd_wait_ee_list_empty(struct drbd_conf *mdev,
 extern void drbd_set_recv_tcq(struct drbd_conf *mdev, int tcq_enabled);
 extern void _drbd_clear_done_ee(struct drbd_conf *mdev, struct list_head *to_be_freed);
 extern void drbd_flush_workqueue(struct drbd_conf *mdev);
-extern void drbd_free_tl_hash(struct drbd_conf *mdev);
 
 /* yes, there is kernel_setsockopt, but only since 2.6.18. we don't need to
  * mess with get_fs/set_fs, we know we are KERNEL_DS always. */
@@ -1828,6 +1837,8 @@ static inline void __drbd_chk_io_error_(struct drbd_conf *mdev, int forcedetach,
                if (!forcedetach) {
                        if (__ratelimit(&drbd_ratelimit_state))
                                dev_err(DEV, "Local IO failed in %s.\n", where);
+                       if (mdev->state.disk > D_INCONSISTENT)
+                               _drbd_set_state(_NS(mdev, disk, D_INCONSISTENT), CS_HARD, NULL);
                        break;
                }
                /* NOTE fall through to detach case if forcedetach set */
@@ -1995,7 +2006,7 @@ drbd_queue_work(struct drbd_work_queue *q, struct drbd_work *w)
 static inline void wake_asender(struct drbd_conf *mdev)
 {
        if (test_bit(SIGNAL_ASENDER, &mdev->flags))
-               force_sig(DRBD_SIG, mdev->asender.task);
+               force_sig(DRBD_SIG, mdev->tconn->asender.task);
 }
 
 static inline void request_ping(struct drbd_conf *mdev)
@@ -2043,21 +2054,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)
@@ -2118,26 +2129,26 @@ static inline void inc_unacked(struct drbd_conf *mdev)
        ERR_IF_CNT_IS_NEGATIVE(unacked_cnt); } while (0)
 
 
-static inline void put_net_conf(struct drbd_conf *mdev)
+static inline void put_net_conf(struct drbd_tconn *tconn)
 {
-       if (atomic_dec_and_test(&mdev->net_cnt))
-               wake_up(&mdev->net_cnt_wait);
+       if (atomic_dec_and_test(&tconn->net_cnt))
+               wake_up(&tconn->net_cnt_wait);
 }
 
 /**
- * get_net_conf() - Increase ref count on mdev->net_conf; Returns 0 if nothing there
+ * get_net_conf() - Increase ref count on mdev->tconn->net_conf; Returns 0 if nothing there
  * @mdev:      DRBD device.
  *
- * You have to call put_net_conf() when finished working with mdev->net_conf.
+ * You have to call put_net_conf() when finished working with mdev->tconn->net_conf.
  */
-static inline int get_net_conf(struct drbd_conf *mdev)
+static inline int get_net_conf(struct drbd_tconn *tconn)
 {
        int have_net_conf;
 
-       atomic_inc(&mdev->net_cnt);
-       have_net_conf = mdev->state.conn >= C_UNCONNECTED;
+       atomic_inc(&tconn->net_cnt);
+       have_net_conf = tconn->volume0->state.conn >= C_UNCONNECTED;
        if (!have_net_conf)
-               put_net_conf(mdev);
+               put_net_conf(tconn);
        return have_net_conf;
 }
 
@@ -2153,6 +2164,10 @@ static inline int get_net_conf(struct drbd_conf *mdev)
 static inline void put_ldev(struct drbd_conf *mdev)
 {
        int i = atomic_dec_return(&mdev->local_cnt);
+
+       /* This may be called from some endio handler,
+        * so we must not sleep here. */
+
        __release(local);
        D_ASSERT(i >= 0);
        if (i == 0) {
@@ -2239,9 +2254,9 @@ static inline void drbd_get_syncer_progress(struct drbd_conf *mdev,
 static inline int drbd_get_max_buffers(struct drbd_conf *mdev)
 {
        int mxb = 1000000; /* arbitrary limit on open requests */
-       if (get_net_conf(mdev)) {
-               mxb = mdev->net_conf->max_buffers;
-               put_net_conf(mdev);
+       if (get_net_conf(mdev->tconn)) {
+               mxb = mdev->tconn->net_conf->max_buffers;
+               put_net_conf(mdev->tconn);
        }
        return mxb;
 }
@@ -2386,7 +2401,7 @@ static inline void dec_ap_bio(struct drbd_conf *mdev)
                wake_up(&mdev->misc_wait);
        if (ap_bio == 0 && test_bit(BITMAP_IO, &mdev->flags)) {
                if (!test_and_set_bit(BITMAP_IO_QUEUED, &mdev->flags))
-                       drbd_queue_work(&mdev->data.work, &mdev->bm_io_work.w);
+                       drbd_queue_work(&mdev->tconn->data.work, &mdev->bm_io_work.w);
        }
 }
 
@@ -2426,7 +2441,7 @@ static inline void update_peer_seq(struct drbd_conf *mdev, unsigned int new_seq)
 
 static inline void drbd_update_congested(struct drbd_conf *mdev)
 {
-       struct sock *sk = mdev->data.socket->sk;
+       struct sock *sk = mdev->tconn->data.socket->sk;
        if (sk->sk_wmem_queued > sk->sk_sndbuf * 4 / 5)
                set_bit(NET_CONGESTED, &mdev->flags);
 }