drbd: Function prototype cleanups
[deliverable/linux.git] / drivers / block / drbd / drbd_int.h
index 0e06f0c5dd1e60d8d4a4656160f23ed0d6f4cde1..cf605fa0b9dac3107ff95473d9839c4693312ebb 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/drbd_genl_api.h>
 #include <linux/drbd.h>
 #include "drbd_state.h"
+#include "drbd_protocol.h"
 
 #ifdef __CHECKER__
 # define __protected_by(x)       __attribute__((require_context(x,1,999,"rdwr")))
@@ -65,6 +66,7 @@
 extern unsigned int minor_count;
 extern bool disable_sendpage;
 extern bool allow_oos;
+void tl_abort_disk_io(struct drbd_device *device);
 
 #ifdef CONFIG_DRBD_FAULT_INJECTION
 extern int enable_faults;
@@ -95,25 +97,60 @@ 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 */
-#define DEV (disk_to_dev(mdev->vdisk))
-
-#define conn_printk(LEVEL, TCONN, FMT, ARGS...) \
-       printk(LEVEL "d-con %s: " FMT, TCONN->name , ## ARGS)
-#define conn_alert(TCONN, FMT, ARGS...)  conn_printk(KERN_ALERT, TCONN, FMT, ## ARGS)
-#define conn_crit(TCONN, FMT, ARGS...)   conn_printk(KERN_CRIT, TCONN, FMT, ## ARGS)
-#define conn_err(TCONN, FMT, ARGS...)    conn_printk(KERN_ERR, TCONN, FMT, ## ARGS)
-#define conn_warn(TCONN, FMT, ARGS...)   conn_printk(KERN_WARNING, TCONN, FMT, ## ARGS)
-#define conn_notice(TCONN, FMT, ARGS...) conn_printk(KERN_NOTICE, TCONN, FMT, ## ARGS)
-#define conn_info(TCONN, FMT, ARGS...)   conn_printk(KERN_INFO, TCONN, FMT, ## ARGS)
-#define conn_dbg(TCONN, FMT, ARGS...)    conn_printk(KERN_DEBUG, TCONN, FMT, ## ARGS)
-
-#define D_ASSERT(exp)  if (!(exp)) \
-        dev_err(DEV, "ASSERT( " #exp " ) in %s:%d\n", __FILE__, __LINE__)
+struct drbd_device;
+struct drbd_connection;
+
+#define __drbd_printk_device(level, device, fmt, args...) \
+       dev_printk(level, disk_to_dev((device)->vdisk), fmt, ## args)
+#define __drbd_printk_peer_device(level, peer_device, fmt, args...) \
+       dev_printk(level, disk_to_dev((peer_device)->device->vdisk), fmt, ## args)
+#define __drbd_printk_resource(level, resource, fmt, args...) \
+       printk(level "drbd %s: " fmt, (resource)->name, ## args)
+#define __drbd_printk_connection(level, connection, fmt, args...) \
+       printk(level "drbd %s: " fmt, (connection)->resource->name, ## args)
+
+void drbd_printk_with_wrong_object_type(void);
+
+#define __drbd_printk_if_same_type(obj, type, func, level, fmt, args...) \
+       (__builtin_types_compatible_p(typeof(obj), type) || \
+        __builtin_types_compatible_p(typeof(obj), const type)), \
+       func(level, (const type)(obj), fmt, ## args)
+
+#define drbd_printk(level, obj, fmt, args...) \
+       __builtin_choose_expr( \
+         __drbd_printk_if_same_type(obj, struct drbd_device *, \
+                            __drbd_printk_device, level, fmt, ## args), \
+         __builtin_choose_expr( \
+           __drbd_printk_if_same_type(obj, struct drbd_resource *, \
+                              __drbd_printk_resource, level, fmt, ## args), \
+           __builtin_choose_expr( \
+             __drbd_printk_if_same_type(obj, struct drbd_connection *, \
+                                __drbd_printk_connection, level, fmt, ## args), \
+             __builtin_choose_expr( \
+               __drbd_printk_if_same_type(obj, struct drbd_peer_device *, \
+                                __drbd_printk_peer_device, level, fmt, ## args), \
+               drbd_printk_with_wrong_object_type()))))
+
+#define drbd_dbg(obj, fmt, args...) \
+       drbd_printk(KERN_DEBUG, obj, fmt, ## args)
+#define drbd_alert(obj, fmt, args...) \
+       drbd_printk(KERN_ALERT, obj, fmt, ## args)
+#define drbd_err(obj, fmt, args...) \
+       drbd_printk(KERN_ERR, obj, fmt, ## args)
+#define drbd_warn(obj, fmt, args...) \
+       drbd_printk(KERN_WARNING, obj, fmt, ## args)
+#define drbd_info(obj, fmt, args...) \
+       drbd_printk(KERN_INFO, obj, fmt, ## args)
+#define drbd_emerg(obj, fmt, args...) \
+       drbd_printk(KERN_EMERG, obj, fmt, ## args)
+
+#define dynamic_drbd_dbg(device, fmt, args...) \
+       dynamic_dev_dbg(disk_to_dev(device->vdisk), fmt, ## args)
+
+#define D_ASSERT(device, exp)  do { \
+       if (!(exp)) \
+               drbd_err(device, "ASSERT( " #exp " ) in %s:%d\n", __FILE__, __LINE__); \
+       } while (0)
 
 /**
  * expect  -  Make an assertion
@@ -123,7 +160,7 @@ struct drbd_tconn;
 #define expect(exp) ({                                                         \
                bool _bool = (exp);                                             \
                if (!_bool)                                                     \
-                       dev_err(DEV, "ASSERTION %s FAILED in %s\n",             \
+                       drbd_err(device, "ASSERTION %s FAILED in %s\n",         \
                                #exp, __func__);                                \
                _bool;                                                          \
                })
@@ -145,14 +182,14 @@ enum {
 };
 
 extern unsigned int
-_drbd_insert_fault(struct drbd_conf *mdev, unsigned int type);
+_drbd_insert_fault(struct drbd_device *device, unsigned int type);
 
 static inline int
-drbd_insert_fault(struct drbd_conf *mdev, unsigned int type) {
+drbd_insert_fault(struct drbd_device *device, unsigned int type) {
 #ifdef CONFIG_DRBD_FAULT_INJECTION
        return fault_rate &&
                (enable_faults & (1<<type)) &&
-               _drbd_insert_fault(mdev, type);
+               _drbd_insert_fault(device, type);
 #else
        return 0;
 #endif
@@ -164,74 +201,8 @@ drbd_insert_fault(struct drbd_conf *mdev, unsigned int type) {
 #define div_floor(A, B) ((A)/(B))
 
 extern struct ratelimit_state drbd_ratelimit_state;
-extern struct idr minors; /* RCU, updates: genl_lock() */
-extern struct list_head drbd_tconns; /* RCU, updates: genl_lock() */
-
-/* on the wire */
-enum drbd_packet {
-       /* receiver (data socket) */
-       P_DATA                = 0x00,
-       P_DATA_REPLY          = 0x01, /* Response to P_DATA_REQUEST */
-       P_RS_DATA_REPLY       = 0x02, /* Response to P_RS_DATA_REQUEST */
-       P_BARRIER             = 0x03,
-       P_BITMAP              = 0x04,
-       P_BECOME_SYNC_TARGET  = 0x05,
-       P_BECOME_SYNC_SOURCE  = 0x06,
-       P_UNPLUG_REMOTE       = 0x07, /* Used at various times to hint the peer */
-       P_DATA_REQUEST        = 0x08, /* Used to ask for a data block */
-       P_RS_DATA_REQUEST     = 0x09, /* Used to ask for a data block for resync */
-       P_SYNC_PARAM          = 0x0a,
-       P_PROTOCOL            = 0x0b,
-       P_UUIDS               = 0x0c,
-       P_SIZES               = 0x0d,
-       P_STATE               = 0x0e,
-       P_SYNC_UUID           = 0x0f,
-       P_AUTH_CHALLENGE      = 0x10,
-       P_AUTH_RESPONSE       = 0x11,
-       P_STATE_CHG_REQ       = 0x12,
-
-       /* asender (meta socket */
-       P_PING                = 0x13,
-       P_PING_ACK            = 0x14,
-       P_RECV_ACK            = 0x15, /* Used in protocol B */
-       P_WRITE_ACK           = 0x16, /* Used in protocol C */
-       P_RS_WRITE_ACK        = 0x17, /* Is a P_WRITE_ACK, additionally call set_in_sync(). */
-       P_SUPERSEDED          = 0x18, /* Used in proto C, two-primaries conflict detection */
-       P_NEG_ACK             = 0x19, /* Sent if local disk is unusable */
-       P_NEG_DREPLY          = 0x1a, /* Local disk is broken... */
-       P_NEG_RS_DREPLY       = 0x1b, /* Local disk is broken... */
-       P_BARRIER_ACK         = 0x1c,
-       P_STATE_CHG_REPLY     = 0x1d,
-
-       /* "new" commands, no longer fitting into the ordering scheme above */
-
-       P_OV_REQUEST          = 0x1e, /* data socket */
-       P_OV_REPLY            = 0x1f,
-       P_OV_RESULT           = 0x20, /* meta socket */
-       P_CSUM_RS_REQUEST     = 0x21, /* data socket */
-       P_RS_IS_IN_SYNC       = 0x22, /* meta socket */
-       P_SYNC_PARAM89        = 0x23, /* data socket, protocol version 89 replacement for P_SYNC_PARAM */
-       P_COMPRESSED_BITMAP   = 0x24, /* compressed or otherwise encoded bitmap transfer */
-       /* P_CKPT_FENCE_REQ      = 0x25, * currently reserved for protocol D */
-       /* P_CKPT_DISABLE_REQ    = 0x26, * currently reserved for protocol D */
-       P_DELAY_PROBE         = 0x27, /* is used on BOTH sockets */
-       P_OUT_OF_SYNC         = 0x28, /* Mark as out of sync (Outrunning), data socket */
-       P_RS_CANCEL           = 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */
-       P_CONN_ST_CHG_REQ     = 0x2a, /* data sock: Connection wide state request */
-       P_CONN_ST_CHG_REPLY   = 0x2b, /* meta sock: Connection side state req reply */
-       P_RETRY_WRITE         = 0x2c, /* Protocol C: retry conflicting write request */
-       P_PROTOCOL_UPDATE     = 0x2d, /* data sock: is used in established connections */
-
-       P_MAY_IGNORE          = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
-       P_MAX_OPT_CMD         = 0x101,
-
-       /* special command ids for handshake */
-
-       P_INITIAL_META        = 0xfff1, /* First Packet on the MetaSock */
-       P_INITIAL_DATA        = 0xfff2, /* First Packet on the Socket */
-
-       P_CONNECTION_FEATURES = 0xfffe  /* FIXED for the next century! */
-};
+extern struct idr drbd_devices; /* RCU, updates: genl_lock() */
+extern struct list_head drbd_resources; /* RCU, updates: genl_lock() */
 
 extern const char *cmdname(enum drbd_packet cmd);
 
@@ -253,7 +224,7 @@ struct bm_xfer_ctx {
        unsigned bytes[2];
 };
 
-extern void INFO_bm_xfer_stats(struct drbd_conf *mdev,
+extern void INFO_bm_xfer_stats(struct drbd_device *device,
                const char *direction, struct bm_xfer_ctx *c);
 
 static inline void bm_xfer_ctx_bit_to_word_offset(struct bm_xfer_ctx *c)
@@ -275,233 +246,7 @@ static inline void bm_xfer_ctx_bit_to_word_offset(struct bm_xfer_ctx *c)
 #endif
 }
 
-#ifndef __packed
-#define __packed __attribute__((packed))
-#endif
-
-/* This is the layout for a packet on the wire.
- * The byteorder is the network byte order.
- *     (except block_id and barrier fields.
- *     these are pointers to local structs
- *     and have no relevance for the partner,
- *     which just echoes them as received.)
- *
- * NOTE that the payload starts at a long aligned offset,
- * regardless of 32 or 64 bit arch!
- */
-struct p_header80 {
-       u32       magic;
-       u16       command;
-       u16       length;       /* bytes of data after this header */
-} __packed;
-
-/* Header for big packets, Used for data packets exceeding 64kB */
-struct p_header95 {
-       u16       magic;        /* use DRBD_MAGIC_BIG here */
-       u16       command;
-       u32       length;
-} __packed;
-
-struct p_header100 {
-       u32       magic;
-       u16       volume;
-       u16       command;
-       u32       length;
-       u32       pad;
-} __packed;
-
-extern unsigned int drbd_header_size(struct drbd_tconn *tconn);
-
-/* these defines must not be changed without changing the protocol version */
-#define DP_HARDBARRIER       1 /* depricated */
-#define DP_RW_SYNC           2 /* equals REQ_SYNC    */
-#define DP_MAY_SET_IN_SYNC    4
-#define DP_UNPLUG             8 /* not used anymore   */
-#define DP_FUA               16 /* equals REQ_FUA     */
-#define DP_FLUSH             32 /* equals REQ_FLUSH   */
-#define DP_DISCARD           64 /* equals REQ_DISCARD */
-#define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */
-#define DP_SEND_WRITE_ACK   256 /* This is a proto C write request */
-
-struct p_data {
-       u64         sector;    /* 64 bits sector number */
-       u64         block_id;  /* to identify the request in protocol B&C */
-       u32         seq_num;
-       u32         dp_flags;
-} __packed;
-
-/*
- * commands which share a struct:
- *  p_block_ack:
- *   P_RECV_ACK (proto B), P_WRITE_ACK (proto C),
- *   P_SUPERSEDED (proto C, two-primaries conflict detection)
- *  p_block_req:
- *   P_DATA_REQUEST, P_RS_DATA_REQUEST
- */
-struct p_block_ack {
-       u64         sector;
-       u64         block_id;
-       u32         blksize;
-       u32         seq_num;
-} __packed;
-
-struct p_block_req {
-       u64 sector;
-       u64 block_id;
-       u32 blksize;
-       u32 pad;        /* to multiple of 8 Byte */
-} __packed;
-
-/*
- * commands with their own struct for additional fields:
- *   P_CONNECTION_FEATURES
- *   P_BARRIER
- *   P_BARRIER_ACK
- *   P_SYNC_PARAM
- *   ReportParams
- */
-
-struct p_connection_features {
-       u32 protocol_min;
-       u32 feature_flags;
-       u32 protocol_max;
-
-       /* should be more than enough for future enhancements
-        * for now, feature_flags and the reserved array shall be zero.
-        */
-
-       u32 _pad;
-       u64 reserved[7];
-} __packed;
-
-struct p_barrier {
-       u32 barrier;    /* barrier number _handle_ only */
-       u32 pad;        /* to multiple of 8 Byte */
-} __packed;
-
-struct p_barrier_ack {
-       u32 barrier;
-       u32 set_size;
-} __packed;
-
-struct p_rs_param {
-       u32 resync_rate;
-
-             /* Since protocol version 88 and higher. */
-       char verify_alg[0];
-} __packed;
-
-struct p_rs_param_89 {
-       u32 resync_rate;
-        /* protocol version 89: */
-       char verify_alg[SHARED_SECRET_MAX];
-       char csums_alg[SHARED_SECRET_MAX];
-} __packed;
-
-struct p_rs_param_95 {
-       u32 resync_rate;
-       char verify_alg[SHARED_SECRET_MAX];
-       char csums_alg[SHARED_SECRET_MAX];
-       u32 c_plan_ahead;
-       u32 c_delay_target;
-       u32 c_fill_target;
-       u32 c_max_rate;
-} __packed;
-
-enum drbd_conn_flags {
-       CF_DISCARD_MY_DATA = 1,
-       CF_DRY_RUN = 2,
-};
-
-struct p_protocol {
-       u32 protocol;
-       u32 after_sb_0p;
-       u32 after_sb_1p;
-       u32 after_sb_2p;
-       u32 conn_flags;
-       u32 two_primaries;
-
-              /* Since protocol version 87 and higher. */
-       char integrity_alg[0];
-
-} __packed;
-
-struct p_uuids {
-       u64 uuid[UI_EXTENDED_SIZE];
-} __packed;
-
-struct p_rs_uuid {
-       u64         uuid;
-} __packed;
-
-struct p_sizes {
-       u64         d_size;  /* size of disk */
-       u64         u_size;  /* user requested size */
-       u64         c_size;  /* current exported size */
-       u32         max_bio_size;  /* Maximal size of a BIO */
-       u16         queue_order_type;  /* not yet implemented in DRBD*/
-       u16         dds_flags; /* use enum dds_flags here. */
-} __packed;
-
-struct p_state {
-       u32         state;
-} __packed;
-
-struct p_req_state {
-       u32         mask;
-       u32         val;
-} __packed;
-
-struct p_req_state_reply {
-       u32         retcode;
-} __packed;
-
-struct p_drbd06_param {
-       u64       size;
-       u32       state;
-       u32       blksize;
-       u32       protocol;
-       u32       version;
-       u32       gen_cnt[5];
-       u32       bit_map_gen[5];
-} __packed;
-
-struct p_block_desc {
-       u64 sector;
-       u32 blksize;
-       u32 pad;        /* to multiple of 8 Byte */
-} __packed;
-
-/* Valid values for the encoding field.
- * Bump proto version when changing this. */
-enum drbd_bitmap_code {
-       /* RLE_VLI_Bytes = 0,
-        * and other bit variants had been defined during
-        * algorithm evaluation. */
-       RLE_VLI_Bits = 2,
-};
-
-struct p_compressed_bm {
-       /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code
-        * (encoding & 0x80): polarity (set/unset) of first runlength
-        * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits
-        * used to pad up to head.length bytes
-        */
-       u8 encoding;
-
-       u8 code[0];
-} __packed;
-
-struct p_delay_probe93 {
-       u32     seq_num; /* sequence number to match the two probe packets */
-       u32     offset;  /* usecs the probe got sent after the reference time point */
-} __packed;
-
-/*
- * Bitmap packets need to fit within a single page on the sender and receiver,
- * so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger).
- */
-#define DRBD_SOCKET_BUFFER_SIZE 4096
+extern unsigned int drbd_header_size(struct drbd_connection *connection);
 
 /**********************************************************************/
 enum drbd_thread_state {
@@ -517,7 +262,7 @@ struct drbd_thread {
        struct completion stop;
        enum drbd_thread_state t_state;
        int (*function) (struct drbd_thread *);
-       struct drbd_tconn *tconn;
+       struct drbd_connection *connection;
        int reset_cpu_mask;
        char name[9];
 };
@@ -536,14 +281,14 @@ struct drbd_work {
        struct list_head list;
        int (*cb)(struct drbd_work *, int cancel);
        union {
-               struct drbd_conf *mdev;
-               struct drbd_tconn *tconn;
+               struct drbd_device *device;
+               struct drbd_connection *connection;
        };
 };
 
 #include "drbd_interval.h"
 
-extern int drbd_wait_misc(struct drbd_conf *, struct drbd_interval *);
+extern int drbd_wait_misc(struct drbd_device *, struct drbd_interval *);
 
 struct drbd_request {
        struct drbd_work w;
@@ -579,7 +324,7 @@ struct drbd_request {
 };
 
 struct drbd_epoch {
-       struct drbd_tconn *tconn;
+       struct drbd_connection *connection;
        struct list_head list;
        unsigned int barrier_nr;
        atomic_t epoch_size; /* increased on every request added. */
@@ -587,6 +332,10 @@ struct drbd_epoch {
        unsigned long flags;
 };
 
+/* Prototype declaration of function defined in drbd_receiver.c */
+int drbdd_init(struct drbd_thread *);
+int drbd_asender(struct drbd_thread *);
+
 /* drbd_epoch flag bits */
 enum {
        DE_HAVE_BARRIER_NUMBER,
@@ -663,7 +412,7 @@ enum {
 #define EE_SEND_WRITE_ACK      (1<<__EE_SEND_WRITE_ACK)
 #define EE_IN_INTERVAL_TREE    (1<<__EE_IN_INTERVAL_TREE)
 
-/* flag bits per mdev */
+/* flag bits per device */
 enum {
        UNPLUG_REMOTE,          /* sending a "UnplugRemote" could help */
        MD_DIRTY,               /* current uuids and flags not yet on disk */
@@ -695,7 +444,7 @@ enum {
        READ_BALANCE_RR,
 };
 
-struct drbd_bitmap; /* opaque for drbd_conf */
+struct drbd_bitmap; /* opaque for drbd_device */
 
 /* definition of bits in bm_flags to be used in drbd_bm_lock
  * and drbd_bitmap_io and friends. */
@@ -769,7 +518,7 @@ struct drbd_backing_dev {
        struct block_device *backing_bdev;
        struct block_device *md_bdev;
        struct drbd_md md;
-       struct disk_conf *disk_conf; /* RCU, for updates: mdev->tconn->conf_update */
+       struct disk_conf *disk_conf; /* RCU, for updates: resource->conf_update */
        sector_t known_size; /* last known size of that backing device */
 };
 
@@ -782,8 +531,8 @@ struct bm_io_work {
        struct drbd_work w;
        char *why;
        enum bm_flag flags;
-       int (*io_fn)(struct drbd_conf *mdev);
-       void (*done)(struct drbd_conf *mdev, int rv);
+       int (*io_fn)(struct drbd_device *device);
+       void (*done)(struct drbd_device *device, int rv);
 };
 
 enum write_ordering_e {
@@ -800,7 +549,7 @@ struct fifo_buffer {
 };
 extern struct fifo_buffer *fifo_alloc(int fifo_size);
 
-/* flag bits per tconn */
+/* flag bits per connection */
 enum {
        NET_CONGESTED,          /* The data socket is congested */
        RESOLVE_CONFLICTS,      /* Set on one node, cleared on the peer! */
@@ -822,23 +571,35 @@ enum {
        DISCONNECT_SENT,
 };
 
-struct drbd_tconn {                    /* is a resource from the config file */
-       char *name;                     /* Resource name */
-       struct list_head all_tconn;     /* linked on global drbd_tconns */
+struct drbd_resource {
+       char *name;
        struct kref kref;
-       struct idr volumes;             /* <tconn, vnr> to mdev mapping */
-       enum drbd_conns cstate;         /* Only C_STANDALONE to C_WF_REPORT_PARAMS */
+       struct idr devices;             /* volume number to device mapping */
+       struct list_head connections;
+       struct list_head resources;
+       struct res_opts res_opts;
+       struct mutex conf_update;       /* mutex for ready-copy-update of net_conf and disk_conf */
+       spinlock_t req_lock;
+
        unsigned susp:1;                /* IO suspended by user */
        unsigned susp_nod:1;            /* IO suspended because no data */
        unsigned susp_fen:1;            /* IO suspended because fence peer handler runs */
+
+       cpumask_var_t cpu_mask;
+};
+
+struct drbd_connection {
+       struct list_head connections;
+       struct drbd_resource *resource;
+       struct kref kref;
+       struct idr peer_devices;        /* volume number to peer device mapping */
+       enum drbd_conns cstate;         /* Only C_STANDALONE to C_WF_REPORT_PARAMS */
        struct mutex cstate_mutex;      /* Protects graceful disconnects */
        unsigned int connect_cnt;       /* Inc each time a connection is established */
 
        unsigned long flags;
        struct net_conf *net_conf;      /* content protected by rcu */
-       struct mutex conf_update;       /* mutex for ready-copy-update of net_conf and disk_conf */
        wait_queue_head_t ping_wait;    /* Woken upon reception of a ping, and a state change */
-       struct res_opts res_opts;
 
        struct sockaddr_storage my_addr;
        int my_addr_len;
@@ -851,12 +612,10 @@ struct drbd_tconn {                       /* is a resource from the config file */
        unsigned long last_received;    /* in jiffies, either socket */
        unsigned int ko_count;
 
-       spinlock_t req_lock;
-
        struct list_head transfer_log;  /* all requests not yet fully processed */
 
        struct crypto_hash *cram_hmac_tfm;
-       struct crypto_hash *integrity_tfm;  /* checksums we compute, updates protected by tconn->data->mutex */
+       struct crypto_hash *integrity_tfm;  /* checksums we compute, updates protected by connection->data->mutex */
        struct crypto_hash *peer_integrity_tfm;  /* checksums we verify, only accessed from receiver thread  */
        struct crypto_hash *csums_tfm;
        struct crypto_hash *verify_tfm;
@@ -875,7 +634,6 @@ struct drbd_tconn {                 /* is a resource from the config file */
        struct drbd_thread receiver;
        struct drbd_thread worker;
        struct drbd_thread asender;
-       cpumask_var_t cpu_mask;
 
        /* sender side */
        struct drbd_work_queue sender_work;
@@ -903,8 +661,15 @@ struct submit_worker {
        struct list_head writes;
 };
 
-struct drbd_conf {
-       struct drbd_tconn *tconn;
+struct drbd_peer_device {
+       struct list_head peer_devices;
+       struct drbd_device *device;
+       struct drbd_connection *connection;
+};
+
+struct drbd_device {
+       struct drbd_resource *resource;
+       struct list_head peer_devices;
        int vnr;                        /* volume number within the connection */
        struct kref kref;
 
@@ -1030,7 +795,7 @@ struct drbd_conf {
        struct bm_io_work bm_io_work;
        u64 ed_uuid; /* UUID of the exposed data */
        struct mutex own_state_mutex;
-       struct mutex *state_mutex; /* either own_state_mutex or mdev->tconn->cstate_mutex */
+       struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
        char congestion_reason;  /* Why we where congested... */
        atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
        atomic_t rs_sect_ev; /* for submitted resync data rate, both */
@@ -1038,7 +803,7 @@ struct drbd_conf {
        int rs_last_events;  /* counter of read or write "events" (unit sectors)
                              * on the lower level device when we last looked. */
        int c_sync_rate; /* current resync rate after syncer throttle magic */
-       struct fifo_buffer *rs_plan_s; /* correction values of resync planer (RCU, tconn->conn_update) */
+       struct fifo_buffer *rs_plan_s; /* correction values of resync planer (RCU, connection->conn_update) */
        int rs_in_flight; /* resync sectors in flight (to proxy, in proxy and from proxy) */
        atomic_t ap_in_flight; /* App sectors in flight (waiting for ack) */
        unsigned int peer_max_bio_size;
@@ -1049,19 +814,54 @@ struct drbd_conf {
        struct submit_worker submit;
 };
 
-static inline struct drbd_conf *minor_to_mdev(unsigned int minor)
+static inline struct drbd_device *minor_to_device(unsigned int minor)
+{
+       return (struct drbd_device *)idr_find(&drbd_devices, minor);
+}
+
+static inline struct drbd_peer_device *first_peer_device(struct drbd_device *device)
 {
-       return (struct drbd_conf *)idr_find(&minors, minor);
+       return list_first_entry(&device->peer_devices, struct drbd_peer_device, peer_devices);
 }
 
-static inline unsigned int mdev_to_minor(struct drbd_conf *mdev)
+#define for_each_resource(resource, _resources) \
+       list_for_each_entry(resource, _resources, resources)
+
+#define for_each_resource_rcu(resource, _resources) \
+       list_for_each_entry_rcu(resource, _resources, resources)
+
+#define for_each_resource_safe(resource, tmp, _resources) \
+       list_for_each_entry_safe(resource, tmp, _resources, resources)
+
+#define for_each_connection(connection, resource) \
+       list_for_each_entry(connection, &resource->connections, connections)
+
+#define for_each_connection_rcu(connection, resource) \
+       list_for_each_entry_rcu(connection, &resource->connections, connections)
+
+#define for_each_connection_safe(connection, tmp, resource) \
+       list_for_each_entry_safe(connection, tmp, &resource->connections, connections)
+
+#define for_each_peer_device(peer_device, device) \
+       list_for_each_entry(peer_device, &device->peer_devices, peer_devices)
+
+#define for_each_peer_device_rcu(peer_device, device) \
+       list_for_each_entry_rcu(peer_device, &device->peer_devices, peer_devices)
+
+#define for_each_peer_device_safe(peer_device, tmp, device) \
+       list_for_each_entry_safe(peer_device, tmp, &device->peer_devices, peer_devices)
+
+static inline unsigned int device_to_minor(struct drbd_device *device)
 {
-       return mdev->minor;
+       return device->minor;
 }
 
-static inline struct drbd_conf *vnr_to_mdev(struct drbd_tconn *tconn, int vnr)
+static inline struct drbd_device *vnr_to_device(struct drbd_connection *connection, int vnr)
 {
-       return (struct drbd_conf *)idr_find(&tconn->volumes, vnr);
+       struct drbd_peer_device *peer_device;
+
+       peer_device = idr_find(&connection->peer_devices, vnr);
+       return peer_device ? peer_device->device : NULL;
 }
 
 /*
@@ -1075,96 +875,94 @@ enum dds_flags {
        DDSF_NO_RESYNC = 2, /* Do not run a resync for the new space */
 };
 
-extern void drbd_init_set_defaults(struct drbd_conf *mdev);
+extern void drbd_init_set_defaults(struct drbd_device *device);
 extern int  drbd_thread_start(struct drbd_thread *thi);
 extern void _drbd_thread_stop(struct drbd_thread *thi, int restart, int wait);
-extern char *drbd_task_to_thread_name(struct drbd_tconn *tconn, struct task_struct *task);
+extern char *drbd_task_to_thread_name(struct drbd_connection *connection, struct task_struct *task);
 #ifdef CONFIG_SMP
 extern void drbd_thread_current_set_cpu(struct drbd_thread *thi);
-extern void drbd_calc_cpu_mask(struct drbd_tconn *tconn);
 #else
 #define drbd_thread_current_set_cpu(A) ({})
-#define drbd_calc_cpu_mask(A) ({})
 #endif
-extern void tl_release(struct drbd_tconn *, unsigned int barrier_nr,
+extern void tl_release(struct drbd_connection *, unsigned int barrier_nr,
                       unsigned int set_size);
-extern void tl_clear(struct drbd_tconn *);
-extern void drbd_free_sock(struct drbd_tconn *tconn);
-extern int drbd_send(struct drbd_tconn *tconn, struct socket *sock,
+extern void tl_clear(struct drbd_connection *);
+extern void drbd_free_sock(struct drbd_connection *connection);
+extern int drbd_send(struct drbd_connection *connection, struct socket *sock,
                     void *buf, size_t size, unsigned msg_flags);
-extern int drbd_send_all(struct drbd_tconn *, struct socket *, void *, size_t,
+extern int drbd_send_all(struct drbd_connection *, struct socket *, void *, size_t,
                         unsigned);
 
-extern int __drbd_send_protocol(struct drbd_tconn *tconn, enum drbd_packet cmd);
-extern int drbd_send_protocol(struct drbd_tconn *tconn);
-extern int drbd_send_uuids(struct drbd_conf *mdev);
-extern int drbd_send_uuids_skip_initial_sync(struct drbd_conf *mdev);
-extern void drbd_gen_and_send_sync_uuid(struct drbd_conf *mdev);
-extern int drbd_send_sizes(struct drbd_conf *mdev, int trigger_reply, enum dds_flags flags);
-extern int drbd_send_state(struct drbd_conf *mdev, union drbd_state s);
-extern int drbd_send_current_state(struct drbd_conf *mdev);
-extern int drbd_send_sync_param(struct drbd_conf *mdev);
-extern void drbd_send_b_ack(struct drbd_tconn *tconn, u32 barrier_nr,
+extern int __drbd_send_protocol(struct drbd_connection *connection, enum drbd_packet cmd);
+extern int drbd_send_protocol(struct drbd_connection *connection);
+extern int drbd_send_uuids(struct drbd_device *device);
+extern int drbd_send_uuids_skip_initial_sync(struct drbd_device *device);
+extern void drbd_gen_and_send_sync_uuid(struct drbd_device *device);
+extern int drbd_send_sizes(struct drbd_device *device, int trigger_reply, enum dds_flags flags);
+extern int drbd_send_state(struct drbd_device *device, union drbd_state s);
+extern int drbd_send_current_state(struct drbd_device *device);
+extern int drbd_send_sync_param(struct drbd_device *device);
+extern void drbd_send_b_ack(struct drbd_connection *connection, u32 barrier_nr,
                            u32 set_size);
-extern int drbd_send_ack(struct drbd_conf *, enum drbd_packet,
+extern int drbd_send_ack(struct drbd_device *, enum drbd_packet,
                         struct drbd_peer_request *);
-extern void drbd_send_ack_rp(struct drbd_conf *mdev, enum drbd_packet cmd,
+extern void drbd_send_ack_rp(struct drbd_device *device, enum drbd_packet cmd,
                             struct p_block_req *rp);
-extern void drbd_send_ack_dp(struct drbd_conf *mdev, enum drbd_packet cmd,
+extern void drbd_send_ack_dp(struct drbd_device *device, enum drbd_packet cmd,
                             struct p_data *dp, int data_size);
-extern int drbd_send_ack_ex(struct drbd_conf *mdev, enum drbd_packet cmd,
+extern int drbd_send_ack_ex(struct drbd_device *device, enum drbd_packet cmd,
                            sector_t sector, int blksize, u64 block_id);
-extern int drbd_send_out_of_sync(struct drbd_conf *, struct drbd_request *);
-extern int drbd_send_block(struct drbd_conf *, enum drbd_packet,
+extern int drbd_send_out_of_sync(struct drbd_device *, struct drbd_request *);
+extern int drbd_send_block(struct drbd_device *, enum drbd_packet,
                           struct drbd_peer_request *);
-extern int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req);
-extern int drbd_send_drequest(struct drbd_conf *mdev, int cmd,
+extern int drbd_send_dblock(struct drbd_device *device, struct drbd_request *req);
+extern int drbd_send_drequest(struct drbd_device *device, int cmd,
                              sector_t sector, int size, u64 block_id);
-extern int drbd_send_drequest_csum(struct drbd_conf *mdev, sector_t sector,
+extern int drbd_send_drequest_csum(struct drbd_device *device, sector_t sector,
                                   int size, void *digest, int digest_size,
                                   enum drbd_packet cmd);
-extern int drbd_send_ov_request(struct drbd_conf *mdev,sector_t sector,int size);
+extern int drbd_send_ov_request(struct drbd_device *device, sector_t sector, int size);
 
-extern int drbd_send_bitmap(struct drbd_conf *mdev);
-extern void drbd_send_sr_reply(struct drbd_conf *mdev, enum drbd_state_rv retcode);
-extern void conn_send_sr_reply(struct drbd_tconn *tconn, enum drbd_state_rv retcode);
+extern int drbd_send_bitmap(struct drbd_device *device);
+extern void drbd_send_sr_reply(struct drbd_device *device, enum drbd_state_rv retcode);
+extern void conn_send_sr_reply(struct drbd_connection *connection, enum drbd_state_rv retcode);
 extern void drbd_free_bc(struct drbd_backing_dev *ldev);
-extern void drbd_mdev_cleanup(struct drbd_conf *mdev);
-void drbd_print_uuids(struct drbd_conf *mdev, const char *text);
-
-extern void conn_md_sync(struct drbd_tconn *tconn);
-extern void drbd_md_write(struct drbd_conf *mdev, void *buffer);
-extern void drbd_md_sync(struct drbd_conf *mdev);
-extern int  drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev);
-extern void drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local);
-extern void _drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local);
-extern void drbd_uuid_new_current(struct drbd_conf *mdev) __must_hold(local);
-extern void drbd_uuid_set_bm(struct drbd_conf *mdev, u64 val) __must_hold(local);
-extern void drbd_uuid_move_history(struct drbd_conf *mdev) __must_hold(local);
-extern void __drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local);
-extern void drbd_md_set_flag(struct drbd_conf *mdev, int flags) __must_hold(local);
-extern void drbd_md_clear_flag(struct drbd_conf *mdev, int flags)__must_hold(local);
+extern void drbd_device_cleanup(struct drbd_device *device);
+void drbd_print_uuids(struct drbd_device *device, const char *text);
+
+extern void conn_md_sync(struct drbd_connection *connection);
+extern void drbd_md_write(struct drbd_device *device, void *buffer);
+extern void drbd_md_sync(struct drbd_device *device);
+extern int  drbd_md_read(struct drbd_device *device, struct drbd_backing_dev *bdev);
+extern void drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must_hold(local);
+extern void _drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must_hold(local);
+extern void drbd_uuid_new_current(struct drbd_device *device) __must_hold(local);
+extern void drbd_uuid_set_bm(struct drbd_device *device, u64 val) __must_hold(local);
+extern void drbd_uuid_move_history(struct drbd_device *device) __must_hold(local);
+extern void __drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must_hold(local);
+extern void drbd_md_set_flag(struct drbd_device *device, int flags) __must_hold(local);
+extern void drbd_md_clear_flag(struct drbd_device *device, int flags)__must_hold(local);
 extern int drbd_md_test_flag(struct drbd_backing_dev *, int);
 #ifndef DRBD_DEBUG_MD_SYNC
-extern void drbd_md_mark_dirty(struct drbd_conf *mdev);
+extern void drbd_md_mark_dirty(struct drbd_device *device);
 #else
 #define drbd_md_mark_dirty(m)  drbd_md_mark_dirty_(m, __LINE__ , __func__ )
-extern void drbd_md_mark_dirty_(struct drbd_conf *mdev,
+extern void drbd_md_mark_dirty_(struct drbd_device *device,
                unsigned int line, const char *func);
 #endif
-extern void drbd_queue_bitmap_io(struct drbd_conf *mdev,
-                                int (*io_fn)(struct drbd_conf *),
-                                void (*done)(struct drbd_conf *, int),
+extern void drbd_queue_bitmap_io(struct drbd_device *device,
+                                int (*io_fn)(struct drbd_device *),
+                                void (*done)(struct drbd_device *, int),
                                 char *why, enum bm_flag flags);
-extern int drbd_bitmap_io(struct drbd_conf *mdev,
-               int (*io_fn)(struct drbd_conf *),
+extern int drbd_bitmap_io(struct drbd_device *device,
+               int (*io_fn)(struct drbd_device *),
                char *why, enum bm_flag flags);
-extern int drbd_bitmap_io_from_worker(struct drbd_conf *mdev,
-               int (*io_fn)(struct drbd_conf *),
+extern int drbd_bitmap_io_from_worker(struct drbd_device *device,
+               int (*io_fn)(struct drbd_device *),
                char *why, enum bm_flag flags);
-extern int drbd_bmio_set_n_write(struct drbd_conf *mdev);
-extern int drbd_bmio_clear_n_write(struct drbd_conf *mdev);
-extern void drbd_ldev_destroy(struct drbd_conf *mdev);
+extern int drbd_bmio_set_n_write(struct drbd_device *device);
+extern int drbd_bmio_clear_n_write(struct drbd_device *device);
+extern void drbd_ldev_destroy(struct drbd_device *device);
 
 /* Meta data layout
  *
@@ -1350,52 +1148,52 @@ struct bm_extent {
 #define DRBD_MAX_SIZE_H80_PACKET (1U << 15) /* Header 80 only allows packets up to 32KiB data */
 #define DRBD_MAX_BIO_SIZE_P95    (1U << 17) /* Protocol 95 to 99 allows bios up to 128KiB */
 
-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);
-extern void drbd_bm_set_all(struct drbd_conf *mdev);
-extern void drbd_bm_clear_all(struct drbd_conf *mdev);
+extern int  drbd_bm_init(struct drbd_device *device);
+extern int  drbd_bm_resize(struct drbd_device *device, sector_t sectors, int set_new_bits);
+extern void drbd_bm_cleanup(struct drbd_device *device);
+extern void drbd_bm_set_all(struct drbd_device *device);
+extern void drbd_bm_clear_all(struct drbd_device *device);
 /* set/clear/test only a few bits at a time */
 extern int  drbd_bm_set_bits(
-               struct drbd_conf *mdev, unsigned long s, unsigned long e);
+               struct drbd_device *device, unsigned long s, unsigned long e);
 extern int  drbd_bm_clear_bits(
-               struct drbd_conf *mdev, unsigned long s, unsigned long e);
+               struct drbd_device *device, unsigned long s, unsigned long e);
 extern int drbd_bm_count_bits(
-       struct drbd_conf *mdev, const unsigned long s, const unsigned long e);
+       struct drbd_device *device, const unsigned long s, const unsigned long e);
 /* bm_set_bits variant for use while holding drbd_bm_lock,
  * may process the whole bitmap in one go */
-extern void _drbd_bm_set_bits(struct drbd_conf *mdev,
+extern void _drbd_bm_set_bits(struct drbd_device *device,
                const unsigned long s, const unsigned long e);
-extern int  drbd_bm_test_bit(struct drbd_conf *mdev, unsigned long bitnr);
-extern int  drbd_bm_e_weight(struct drbd_conf *mdev, unsigned long enr);
-extern int  drbd_bm_write_page(struct drbd_conf *mdev, unsigned int idx) __must_hold(local);
-extern int  drbd_bm_read(struct drbd_conf *mdev) __must_hold(local);
-extern void drbd_bm_mark_for_writeout(struct drbd_conf *mdev, int page_nr);
-extern int  drbd_bm_write(struct drbd_conf *mdev) __must_hold(local);
-extern int  drbd_bm_write_hinted(struct drbd_conf *mdev) __must_hold(local);
-extern int drbd_bm_write_all(struct drbd_conf *mdev) __must_hold(local);
-extern int  drbd_bm_write_copy_pages(struct drbd_conf *mdev) __must_hold(local);
-extern size_t       drbd_bm_words(struct drbd_conf *mdev);
-extern unsigned long drbd_bm_bits(struct drbd_conf *mdev);
-extern sector_t      drbd_bm_capacity(struct drbd_conf *mdev);
+extern int  drbd_bm_test_bit(struct drbd_device *device, unsigned long bitnr);
+extern int  drbd_bm_e_weight(struct drbd_device *device, unsigned long enr);
+extern int  drbd_bm_write_page(struct drbd_device *device, unsigned int idx) __must_hold(local);
+extern int  drbd_bm_read(struct drbd_device *device) __must_hold(local);
+extern void drbd_bm_mark_for_writeout(struct drbd_device *device, int page_nr);
+extern int  drbd_bm_write(struct drbd_device *device) __must_hold(local);
+extern int  drbd_bm_write_hinted(struct drbd_device *device) __must_hold(local);
+extern int drbd_bm_write_all(struct drbd_device *device) __must_hold(local);
+extern int  drbd_bm_write_copy_pages(struct drbd_device *device) __must_hold(local);
+extern size_t       drbd_bm_words(struct drbd_device *device);
+extern unsigned long drbd_bm_bits(struct drbd_device *device);
+extern sector_t      drbd_bm_capacity(struct drbd_device *device);
 
 #define DRBD_END_OF_BITMAP     (~(unsigned long)0)
-extern unsigned long drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo);
+extern unsigned long drbd_bm_find_next(struct drbd_device *device, unsigned long bm_fo);
 /* bm_find_next variants for use while you hold drbd_bm_lock() */
-extern unsigned long _drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo);
-extern unsigned long _drbd_bm_find_next_zero(struct drbd_conf *mdev, unsigned long bm_fo);
-extern unsigned long _drbd_bm_total_weight(struct drbd_conf *mdev);
-extern unsigned long drbd_bm_total_weight(struct drbd_conf *mdev);
-extern int drbd_bm_rs_done(struct drbd_conf *mdev);
+extern unsigned long _drbd_bm_find_next(struct drbd_device *device, unsigned long bm_fo);
+extern unsigned long _drbd_bm_find_next_zero(struct drbd_device *device, unsigned long bm_fo);
+extern unsigned long _drbd_bm_total_weight(struct drbd_device *device);
+extern unsigned long drbd_bm_total_weight(struct drbd_device *device);
+extern int drbd_bm_rs_done(struct drbd_device *device);
 /* for receive_bitmap */
-extern void drbd_bm_merge_lel(struct drbd_conf *mdev, size_t offset,
+extern void drbd_bm_merge_lel(struct drbd_device *device, size_t offset,
                size_t number, unsigned long *buffer);
 /* for _drbd_send_bitmap */
-extern void drbd_bm_get_lel(struct drbd_conf *mdev, size_t offset,
+extern void drbd_bm_get_lel(struct drbd_device *device, size_t offset,
                size_t number, unsigned long *buffer);
 
-extern void drbd_bm_lock(struct drbd_conf *mdev, char *why, enum bm_flag flags);
-extern void drbd_bm_unlock(struct drbd_conf *mdev);
+extern void drbd_bm_lock(struct drbd_device *device, char *why, enum bm_flag flags);
+extern void drbd_bm_unlock(struct drbd_device *device);
 /* drbd_main.c */
 
 extern struct kmem_cache *drbd_request_cache;
@@ -1439,35 +1237,40 @@ extern struct bio *bio_alloc_drbd(gfp_t gfp_mask);
 
 extern rwlock_t global_state_lock;
 
-extern int conn_lowest_minor(struct drbd_tconn *tconn);
-enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor, int vnr);
-extern void drbd_minor_destroy(struct kref *kref);
+extern int conn_lowest_minor(struct drbd_connection *connection);
+enum drbd_ret_code drbd_create_device(struct drbd_resource *resource, unsigned int minor, int vnr);
+extern void drbd_destroy_device(struct kref *kref);
+extern void drbd_delete_device(struct drbd_device *mdev);
 
-extern int set_resource_options(struct drbd_tconn *tconn, struct res_opts *res_opts);
-extern struct drbd_tconn *conn_create(const char *name, struct res_opts *res_opts);
-extern void conn_destroy(struct kref *kref);
-struct drbd_tconn *conn_get_by_name(const char *name);
-extern struct drbd_tconn *conn_get_by_addrs(void *my_addr, int my_addr_len,
+extern struct drbd_resource *drbd_create_resource(const char *name);
+extern void drbd_free_resource(struct drbd_resource *resource);
+
+extern int set_resource_options(struct drbd_resource *resource, struct res_opts *res_opts);
+extern struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts);
+extern void drbd_destroy_connection(struct kref *kref);
+extern struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len,
                                            void *peer_addr, int peer_addr_len);
-extern void conn_free_crypto(struct drbd_tconn *tconn);
+extern struct drbd_resource *drbd_find_resource(const char *name);
+extern void drbd_destroy_resource(struct kref *kref);
+extern void conn_free_crypto(struct drbd_connection *connection);
 
 extern int proc_details;
 
 /* drbd_req */
 extern void do_submit(struct work_struct *ws);
-extern void __drbd_make_request(struct drbd_conf *, struct bio *, unsigned long);
+extern void __drbd_make_request(struct drbd_device *, struct bio *, unsigned long);
 extern void drbd_make_request(struct request_queue *q, struct bio *bio);
-extern int drbd_read_remote(struct drbd_conf *mdev, struct drbd_request *req);
+extern int drbd_read_remote(struct drbd_device *device, struct drbd_request *req);
 extern int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec);
 extern int is_valid_ar_handle(struct drbd_request *, sector_t);
 
 
 /* drbd_nl.c */
 extern int drbd_msg_put_info(const char *info);
-extern void drbd_suspend_io(struct drbd_conf *mdev);
-extern void drbd_resume_io(struct drbd_conf *mdev);
+extern void drbd_suspend_io(struct drbd_device *device);
+extern void drbd_resume_io(struct drbd_device *device);
 extern char *ppsize(char *buf, unsigned long long size);
-extern sector_t drbd_new_dev_size(struct drbd_conf *, struct drbd_backing_dev *, sector_t, int);
+extern sector_t drbd_new_dev_size(struct drbd_device *, struct drbd_backing_dev *, sector_t, int);
 enum determine_dev_size {
        DS_ERROR_SHRINK = -3,
        DS_ERROR_SPACE_MD = -2,
@@ -1478,47 +1281,47 @@ enum determine_dev_size {
        DS_GREW_FROM_ZERO = 3,
 };
 extern enum determine_dev_size
-drbd_determine_dev_size(struct drbd_conf *, enum dds_flags, struct resize_parms *) __must_hold(local);
-extern void resync_after_online_grow(struct drbd_conf *);
-extern void drbd_reconsider_max_bio_size(struct drbd_conf *mdev);
-extern enum drbd_state_rv drbd_set_role(struct drbd_conf *mdev,
+drbd_determine_dev_size(struct drbd_device *, enum dds_flags, struct resize_parms *) __must_hold(local);
+extern void resync_after_online_grow(struct drbd_device *);
+extern void drbd_reconsider_max_bio_size(struct drbd_device *device);
+extern enum drbd_state_rv drbd_set_role(struct drbd_device *device,
                                        enum drbd_role new_role,
                                        int force);
-extern bool conn_try_outdate_peer(struct drbd_tconn *tconn);
-extern void conn_try_outdate_peer_async(struct drbd_tconn *tconn);
-extern int drbd_khelper(struct drbd_conf *mdev, char *cmd);
+extern bool conn_try_outdate_peer(struct drbd_connection *connection);
+extern void conn_try_outdate_peer_async(struct drbd_connection *connection);
+extern int drbd_khelper(struct drbd_device *device, char *cmd);
 
 /* drbd_worker.c */
 extern int drbd_worker(struct drbd_thread *thi);
-enum drbd_ret_code drbd_resync_after_valid(struct drbd_conf *mdev, int o_minor);
-void drbd_resync_after_changed(struct drbd_conf *mdev);
-extern void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side);
-extern void resume_next_sg(struct drbd_conf *mdev);
-extern void suspend_other_sg(struct drbd_conf *mdev);
-extern int drbd_resync_finished(struct drbd_conf *mdev);
+enum drbd_ret_code drbd_resync_after_valid(struct drbd_device *device, int o_minor);
+void drbd_resync_after_changed(struct drbd_device *device);
+extern void drbd_start_resync(struct drbd_device *device, enum drbd_conns side);
+extern void resume_next_sg(struct drbd_device *device);
+extern void suspend_other_sg(struct drbd_device *device);
+extern int drbd_resync_finished(struct drbd_device *device);
 /* maybe rather drbd_main.c ? */
-extern void *drbd_md_get_buffer(struct drbd_conf *mdev);
-extern void drbd_md_put_buffer(struct drbd_conf *mdev);
-extern int drbd_md_sync_page_io(struct drbd_conf *mdev,
+extern void *drbd_md_get_buffer(struct drbd_device *device);
+extern void drbd_md_put_buffer(struct drbd_device *device);
+extern int drbd_md_sync_page_io(struct drbd_device *device,
                struct drbd_backing_dev *bdev, sector_t sector, int rw);
-extern void drbd_ov_out_of_sync_found(struct drbd_conf *, sector_t, int);
-extern void wait_until_done_or_force_detached(struct drbd_conf *mdev,
+extern void drbd_ov_out_of_sync_found(struct drbd_device *, sector_t, int);
+extern void wait_until_done_or_force_detached(struct drbd_device *device,
                struct drbd_backing_dev *bdev, unsigned int *done);
-extern void drbd_rs_controller_reset(struct drbd_conf *mdev);
+extern void drbd_rs_controller_reset(struct drbd_device *device);
 
-static inline void ov_out_of_sync_print(struct drbd_conf *mdev)
+static inline void ov_out_of_sync_print(struct drbd_device *device)
 {
-       if (mdev->ov_last_oos_size) {
-               dev_err(DEV, "Out of sync: start=%llu, size=%lu (sectors)\n",
-                    (unsigned long long)mdev->ov_last_oos_start,
-                    (unsigned long)mdev->ov_last_oos_size);
+       if (device->ov_last_oos_size) {
+               drbd_err(device, "Out of sync: start=%llu, size=%lu (sectors)\n",
+                    (unsigned long long)device->ov_last_oos_start,
+                    (unsigned long)device->ov_last_oos_size);
        }
-       mdev->ov_last_oos_size=0;
+       device->ov_last_oos_size = 0;
 }
 
 
-extern void drbd_csum_bio(struct drbd_conf *, struct crypto_hash *, struct bio *, void *);
-extern void drbd_csum_ee(struct drbd_conf *, struct crypto_hash *,
+extern void drbd_csum_bio(struct drbd_device *, struct crypto_hash *, struct bio *, void *);
+extern void drbd_csum_ee(struct drbd_device *, struct crypto_hash *,
                         struct drbd_peer_request *, void *);
 /* worker callbacks */
 extern int w_e_end_data_req(struct drbd_work *, int);
@@ -1542,26 +1345,28 @@ extern void resync_timer_fn(unsigned long data);
 extern void start_resync_timer_fn(unsigned long data);
 
 /* drbd_receiver.c */
-extern int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector);
-extern int drbd_submit_peer_request(struct drbd_conf *,
+extern int drbd_receiver(struct drbd_thread *thi);
+extern int drbd_asender(struct drbd_thread *thi);
+extern int drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector);
+extern int drbd_submit_peer_request(struct drbd_device *,
                                    struct drbd_peer_request *, const unsigned,
                                    const int);
-extern int drbd_free_peer_reqs(struct drbd_conf *, struct list_head *);
-extern struct drbd_peer_request *drbd_alloc_peer_req(struct drbd_conf *, u64,
+extern int drbd_free_peer_reqs(struct drbd_device *, struct list_head *);
+extern struct drbd_peer_request *drbd_alloc_peer_req(struct drbd_device *, u64,
                                                     sector_t, unsigned int,
                                                     gfp_t) __must_hold(local);
-extern void __drbd_free_peer_req(struct drbd_conf *, struct drbd_peer_request *,
+extern void __drbd_free_peer_req(struct drbd_device *, struct drbd_peer_request *,
                                 int);
 #define drbd_free_peer_req(m,e) __drbd_free_peer_req(m, e, 0)
 #define drbd_free_net_peer_req(m,e) __drbd_free_peer_req(m, e, 1)
-extern struct page *drbd_alloc_pages(struct drbd_conf *, unsigned int, bool);
-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 conn_flush_workqueue(struct drbd_tconn *tconn);
-extern int drbd_connected(struct drbd_conf *mdev);
-static inline void drbd_flush_workqueue(struct drbd_conf *mdev)
+extern struct page *drbd_alloc_pages(struct drbd_device *, unsigned int, bool);
+extern void drbd_set_recv_tcq(struct drbd_device *device, int tcq_enabled);
+extern void _drbd_clear_done_ee(struct drbd_device *device, struct list_head *to_be_freed);
+extern void conn_flush_workqueue(struct drbd_connection *connection);
+extern int drbd_connected(struct drbd_device *device);
+static inline void drbd_flush_workqueue(struct drbd_device *device)
 {
-       conn_flush_workqueue(mdev->tconn);
+       conn_flush_workqueue(first_peer_device(device)->connection);
 }
 
 /* Yes, there is kernel_setsockopt, but only since 2.6.18.
@@ -1613,7 +1418,7 @@ static inline void drbd_tcp_quickack(struct socket *sock)
                        (char*)&val, sizeof(val));
 }
 
-void drbd_bump_write_ordering(struct drbd_tconn *tconn, enum write_ordering_e wo);
+void drbd_bump_write_ordering(struct drbd_connection *connection, enum write_ordering_e wo);
 
 /* drbd_proc.c */
 extern struct proc_dir_entry *drbd_proc;
@@ -1622,29 +1427,29 @@ extern const char *drbd_conn_str(enum drbd_conns s);
 extern const char *drbd_role_str(enum drbd_role s);
 
 /* drbd_actlog.c */
-extern int drbd_al_begin_io_nonblock(struct drbd_conf *mdev, struct drbd_interval *i);
-extern void drbd_al_begin_io_commit(struct drbd_conf *mdev, bool delegate);
-extern bool drbd_al_begin_io_fastpath(struct drbd_conf *mdev, struct drbd_interval *i);
-extern void drbd_al_begin_io(struct drbd_conf *mdev, struct drbd_interval *i, bool delegate);
-extern void drbd_al_complete_io(struct drbd_conf *mdev, struct drbd_interval *i);
-extern void drbd_rs_complete_io(struct drbd_conf *mdev, sector_t sector);
-extern int drbd_rs_begin_io(struct drbd_conf *mdev, sector_t sector);
-extern int drbd_try_rs_begin_io(struct drbd_conf *mdev, sector_t sector);
-extern void drbd_rs_cancel_all(struct drbd_conf *mdev);
-extern int drbd_rs_del_all(struct drbd_conf *mdev);
-extern void drbd_rs_failed_io(struct drbd_conf *mdev,
+extern int drbd_al_begin_io_nonblock(struct drbd_device *device, struct drbd_interval *i);
+extern void drbd_al_begin_io_commit(struct drbd_device *device, bool delegate);
+extern bool drbd_al_begin_io_fastpath(struct drbd_device *device, struct drbd_interval *i);
+extern void drbd_al_begin_io(struct drbd_device *device, struct drbd_interval *i, bool delegate);
+extern void drbd_al_complete_io(struct drbd_device *device, struct drbd_interval *i);
+extern void drbd_rs_complete_io(struct drbd_device *device, sector_t sector);
+extern int drbd_rs_begin_io(struct drbd_device *device, sector_t sector);
+extern int drbd_try_rs_begin_io(struct drbd_device *device, sector_t sector);
+extern void drbd_rs_cancel_all(struct drbd_device *device);
+extern int drbd_rs_del_all(struct drbd_device *device);
+extern void drbd_rs_failed_io(struct drbd_device *device,
                sector_t sector, int size);
-extern void drbd_advance_rs_marks(struct drbd_conf *mdev, unsigned long still_to_go);
-extern void __drbd_set_in_sync(struct drbd_conf *mdev, sector_t sector,
+extern void drbd_advance_rs_marks(struct drbd_device *device, unsigned long still_to_go);
+extern void __drbd_set_in_sync(struct drbd_device *device, sector_t sector,
                int size, const char *file, const unsigned int line);
-#define drbd_set_in_sync(mdev, sector, size) \
-       __drbd_set_in_sync(mdev, sector, size, __FILE__, __LINE__)
-extern int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector,
+#define drbd_set_in_sync(device, sector, size) \
+       __drbd_set_in_sync(device, sector, size, __FILE__, __LINE__)
+extern int __drbd_set_out_of_sync(struct drbd_device *device, sector_t sector,
                int size, const char *file, const unsigned int line);
-#define drbd_set_out_of_sync(mdev, sector, size) \
-       __drbd_set_out_of_sync(mdev, sector, size, __FILE__, __LINE__)
-extern void drbd_al_shrink(struct drbd_conf *mdev);
-extern int drbd_initialize_al(struct drbd_conf *, void *);
+#define drbd_set_out_of_sync(device, sector, size) \
+       __drbd_set_out_of_sync(device, sector, size, __FILE__, __LINE__)
+extern void drbd_al_shrink(struct drbd_device *device);
+extern int drbd_initialize_al(struct drbd_device *, void *);
 
 /* drbd_nl.c */
 /* state info broadcast */
@@ -1661,7 +1466,7 @@ struct sib_info {
                };
        };
 };
-void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib);
+void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib);
 
 /*
  * inline helper functions
@@ -1690,26 +1495,27 @@ static inline int drbd_peer_req_has_active_page(struct drbd_peer_request *peer_r
 }
 
 static inline enum drbd_state_rv
-_drbd_set_state(struct drbd_conf *mdev, union drbd_state ns,
+_drbd_set_state(struct drbd_device *device, union drbd_state ns,
                enum chg_state_flags flags, struct completion *done)
 {
        enum drbd_state_rv rv;
 
        read_lock(&global_state_lock);
-       rv = __drbd_set_state(mdev, ns, flags, done);
+       rv = __drbd_set_state(device, ns, flags, done);
        read_unlock(&global_state_lock);
 
        return rv;
 }
 
-static inline union drbd_state drbd_read_state(struct drbd_conf *mdev)
+static inline union drbd_state drbd_read_state(struct drbd_device *device)
 {
+       struct drbd_resource *resource = device->resource;
        union drbd_state rv;
 
-       rv.i = mdev->state.i;
-       rv.susp = mdev->tconn->susp;
-       rv.susp_nod = mdev->tconn->susp_nod;
-       rv.susp_fen = mdev->tconn->susp_fen;
+       rv.i = device->state.i;
+       rv.susp = resource->susp;
+       rv.susp_nod = resource->susp_nod;
+       rv.susp_fen = resource->susp_fen;
 
        return rv;
 }
@@ -1722,22 +1528,22 @@ enum drbd_force_detach_flags {
 };
 
 #define __drbd_chk_io_error(m,f) __drbd_chk_io_error_(m,f, __func__)
-static inline void __drbd_chk_io_error_(struct drbd_conf *mdev,
+static inline void __drbd_chk_io_error_(struct drbd_device *device,
                enum drbd_force_detach_flags df,
                const char *where)
 {
        enum drbd_io_error_p ep;
 
        rcu_read_lock();
-       ep = rcu_dereference(mdev->ldev->disk_conf)->on_io_error;
+       ep = rcu_dereference(device->ldev->disk_conf)->on_io_error;
        rcu_read_unlock();
        switch (ep) {
        case EP_PASS_ON: /* FIXME would this be better named "Ignore"? */
                if (df == DRBD_READ_ERROR || df == DRBD_WRITE_ERROR) {
                        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);
+                               drbd_err(device, "Local IO failed in %s.\n", where);
+                       if (device->state.disk > D_INCONSISTENT)
+                               _drbd_set_state(_NS(device, disk, D_INCONSISTENT), CS_HARD, NULL);
                        break;
                }
                /* NOTE fall through for DRBD_META_IO_ERROR or DRBD_FORCE_DETACH */
@@ -1763,14 +1569,14 @@ static inline void __drbd_chk_io_error_(struct drbd_conf *mdev,
                 * we read meta data only once during attach,
                 * which will fail in case of errors.
                 */
-               set_bit(WAS_IO_ERROR, &mdev->flags);
+               set_bit(WAS_IO_ERROR, &device->flags);
                if (df == DRBD_READ_ERROR)
-                       set_bit(WAS_READ_ERROR, &mdev->flags);
+                       set_bit(WAS_READ_ERROR, &device->flags);
                if (df == DRBD_FORCE_DETACH)
-                       set_bit(FORCE_DETACH, &mdev->flags);
-               if (mdev->state.disk > D_FAILED) {
-                       _drbd_set_state(_NS(mdev, disk, D_FAILED), CS_HARD, NULL);
-                       dev_err(DEV,
+                       set_bit(FORCE_DETACH, &device->flags);
+               if (device->state.disk > D_FAILED) {
+                       _drbd_set_state(_NS(device, disk, D_FAILED), CS_HARD, NULL);
+                       drbd_err(device,
                                "Local IO failed in %s. Detaching...\n", where);
                }
                break;
@@ -1779,21 +1585,21 @@ static inline void __drbd_chk_io_error_(struct drbd_conf *mdev,
 
 /**
  * drbd_chk_io_error: Handle the on_io_error setting, should be called from all io completion handlers
- * @mdev:       DRBD device.
+ * @device:     DRBD device.
  * @error:      Error code passed to the IO completion callback
  * @forcedetach: Force detach. I.e. the error happened while accessing the meta data
  *
  * See also drbd_main.c:after_state_ch() if (os.disk > D_FAILED && ns.disk == D_FAILED)
  */
 #define drbd_chk_io_error(m,e,f) drbd_chk_io_error_(m,e,f, __func__)
-static inline void drbd_chk_io_error_(struct drbd_conf *mdev,
+static inline void drbd_chk_io_error_(struct drbd_device *device,
        int error, enum drbd_force_detach_flags forcedetach, const char *where)
 {
        if (error) {
                unsigned long flags;
-               spin_lock_irqsave(&mdev->tconn->req_lock, flags);
-               __drbd_chk_io_error_(mdev, forcedetach, where);
-               spin_unlock_irqrestore(&mdev->tconn->req_lock, flags);
+               spin_lock_irqsave(&device->resource->req_lock, flags);
+               __drbd_chk_io_error_(device, forcedetach, where);
+               spin_unlock_irqrestore(&device->resource->req_lock, flags);
        }
 }
 
@@ -1916,31 +1722,31 @@ drbd_queue_work(struct drbd_work_queue *q, struct drbd_work *w)
        wake_up(&q->q_wait);
 }
 
-static inline void wake_asender(struct drbd_tconn *tconn)
+static inline void wake_asender(struct drbd_connection *connection)
 {
-       if (test_bit(SIGNAL_ASENDER, &tconn->flags))
-               force_sig(DRBD_SIG, tconn->asender.task);
+       if (test_bit(SIGNAL_ASENDER, &connection->flags))
+               force_sig(DRBD_SIG, connection->asender.task);
 }
 
-static inline void request_ping(struct drbd_tconn *tconn)
+static inline void request_ping(struct drbd_connection *connection)
 {
-       set_bit(SEND_PING, &tconn->flags);
-       wake_asender(tconn);
+       set_bit(SEND_PING, &connection->flags);
+       wake_asender(connection);
 }
 
-extern void *conn_prepare_command(struct drbd_tconn *, struct drbd_socket *);
-extern void *drbd_prepare_command(struct drbd_conf *, struct drbd_socket *);
-extern int conn_send_command(struct drbd_tconn *, struct drbd_socket *,
+extern void *conn_prepare_command(struct drbd_connection *, struct drbd_socket *);
+extern void *drbd_prepare_command(struct drbd_device *, struct drbd_socket *);
+extern int conn_send_command(struct drbd_connection *, struct drbd_socket *,
                             enum drbd_packet, unsigned int, void *,
                             unsigned int);
-extern int drbd_send_command(struct drbd_conf *, struct drbd_socket *,
+extern int drbd_send_command(struct drbd_device *, struct drbd_socket *,
                             enum drbd_packet, unsigned int, void *,
                             unsigned int);
 
-extern int drbd_send_ping(struct drbd_tconn *tconn);
-extern int drbd_send_ping_ack(struct drbd_tconn *tconn);
-extern int drbd_send_state_req(struct drbd_conf *, union drbd_state, union drbd_state);
-extern int conn_send_state_req(struct drbd_tconn *, union drbd_state, union drbd_state);
+extern int drbd_send_ping(struct drbd_connection *connection);
+extern int drbd_send_ping_ack(struct drbd_connection *connection);
+extern int drbd_send_state_req(struct drbd_device *, union drbd_state, union drbd_state);
+extern int conn_send_state_req(struct drbd_connection *, union drbd_state, union drbd_state);
 
 static inline void drbd_thread_stop(struct drbd_thread *thi)
 {
@@ -1979,22 +1785,22 @@ static inline void drbd_thread_restart_nowait(struct drbd_thread *thi)
  *  _req_mod(req, CONNECTION_LOST_WHILE_PENDING)
  *     [from tl_clear_barrier]
  */
-static inline void inc_ap_pending(struct drbd_conf *mdev)
+static inline void inc_ap_pending(struct drbd_device *device)
 {
-       atomic_inc(&mdev->ap_pending_cnt);
+       atomic_inc(&device->ap_pending_cnt);
 }
 
 #define ERR_IF_CNT_IS_NEGATIVE(which, func, line)                      \
-       if (atomic_read(&mdev->which) < 0)                              \
-               dev_err(DEV, "in %s:%d: " #which " = %d < 0 !\n",       \
+       if (atomic_read(&device->which) < 0)                            \
+               drbd_err(device, "in %s:%d: " #which " = %d < 0 !\n",   \
                        func, line,                                     \
-                       atomic_read(&mdev->which))
+                       atomic_read(&device->which))
 
-#define dec_ap_pending(mdev) _dec_ap_pending(mdev, __FUNCTION__, __LINE__)
-static inline void _dec_ap_pending(struct drbd_conf *mdev, const char *func, int line)
+#define dec_ap_pending(device) _dec_ap_pending(device, __FUNCTION__, __LINE__)
+static inline void _dec_ap_pending(struct drbd_device *device, const char *func, int line)
 {
-       if (atomic_dec_and_test(&mdev->ap_pending_cnt))
-               wake_up(&mdev->misc_wait);
+       if (atomic_dec_and_test(&device->ap_pending_cnt))
+               wake_up(&device->misc_wait);
        ERR_IF_CNT_IS_NEGATIVE(ap_pending_cnt, func, line);
 }
 
@@ -2004,15 +1810,15 @@ static inline void _dec_ap_pending(struct drbd_conf *mdev, const char *func, int
  * C_SYNC_SOURCE sends P_RS_DATA_REPLY   (and expects P_WRITE_ACK with ID_SYNCER)
  *                                        (or P_NEG_ACK with ID_SYNCER)
  */
-static inline void inc_rs_pending(struct drbd_conf *mdev)
+static inline void inc_rs_pending(struct drbd_device *device)
 {
-       atomic_inc(&mdev->rs_pending_cnt);
+       atomic_inc(&device->rs_pending_cnt);
 }
 
-#define dec_rs_pending(mdev) _dec_rs_pending(mdev, __FUNCTION__, __LINE__)
-static inline void _dec_rs_pending(struct drbd_conf *mdev, const char *func, int line)
+#define dec_rs_pending(device) _dec_rs_pending(device, __FUNCTION__, __LINE__)
+static inline void _dec_rs_pending(struct drbd_device *device, const char *func, int line)
 {
-       atomic_dec(&mdev->rs_pending_cnt);
+       atomic_dec(&device->rs_pending_cnt);
        ERR_IF_CNT_IS_NEGATIVE(rs_pending_cnt, func, line);
 }
 
@@ -2025,103 +1831,103 @@ static inline void _dec_rs_pending(struct drbd_conf *mdev, const char *func, int
  *  receive_DataRequest (receive_RSDataRequest) we need to send back P_DATA
  *  receive_Barrier_*  we need to send a P_BARRIER_ACK
  */
-static inline void inc_unacked(struct drbd_conf *mdev)
+static inline void inc_unacked(struct drbd_device *device)
 {
-       atomic_inc(&mdev->unacked_cnt);
+       atomic_inc(&device->unacked_cnt);
 }
 
-#define dec_unacked(mdev) _dec_unacked(mdev, __FUNCTION__, __LINE__)
-static inline void _dec_unacked(struct drbd_conf *mdev, const char *func, int line)
+#define dec_unacked(device) _dec_unacked(device, __FUNCTION__, __LINE__)
+static inline void _dec_unacked(struct drbd_device *device, const char *func, int line)
 {
-       atomic_dec(&mdev->unacked_cnt);
+       atomic_dec(&device->unacked_cnt);
        ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line);
 }
 
-#define sub_unacked(mdev, n) _sub_unacked(mdev, n, __FUNCTION__, __LINE__)
-static inline void _sub_unacked(struct drbd_conf *mdev, int n, const char *func, int line)
+#define sub_unacked(device, n) _sub_unacked(device, n, __FUNCTION__, __LINE__)
+static inline void _sub_unacked(struct drbd_device *device, int n, const char *func, int line)
 {
-       atomic_sub(n, &mdev->unacked_cnt);
+       atomic_sub(n, &device->unacked_cnt);
        ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line);
 }
 
 /**
- * get_ldev() - Increase the ref count on mdev->ldev. Returns 0 if there is no ldev
+ * get_ldev() - Increase the ref count on device->ldev. Returns 0 if there is no ldev
  * @M:         DRBD device.
  *
- * You have to call put_ldev() when finished working with mdev->ldev.
+ * You have to call put_ldev() when finished working with device->ldev.
  */
 #define get_ldev(M) __cond_lock(local, _get_ldev_if_state(M,D_INCONSISTENT))
 #define get_ldev_if_state(M,MINS) __cond_lock(local, _get_ldev_if_state(M,MINS))
 
-static inline void put_ldev(struct drbd_conf *mdev)
+static inline void put_ldev(struct drbd_device *device)
 {
-       int i = atomic_dec_return(&mdev->local_cnt);
+       int i = atomic_dec_return(&device->local_cnt);
 
        /* This may be called from some endio handler,
         * so we must not sleep here. */
 
        __release(local);
-       D_ASSERT(i >= 0);
+       D_ASSERT(device, i >= 0);
        if (i == 0) {
-               if (mdev->state.disk == D_DISKLESS)
+               if (device->state.disk == D_DISKLESS)
                        /* even internal references gone, safe to destroy */
-                       drbd_ldev_destroy(mdev);
-               if (mdev->state.disk == D_FAILED) {
+                       drbd_ldev_destroy(device);
+               if (device->state.disk == D_FAILED) {
                        /* all application IO references gone. */
-                       if (!test_and_set_bit(GO_DISKLESS, &mdev->flags))
-                               drbd_queue_work(&mdev->tconn->sender_work, &mdev->go_diskless);
+                       if (!test_and_set_bit(GO_DISKLESS, &device->flags))
+                               drbd_queue_work(&first_peer_device(device)->connection->sender_work, &device->go_diskless);
                }
-               wake_up(&mdev->misc_wait);
+               wake_up(&device->misc_wait);
        }
 }
 
 #ifndef __CHECKER__
-static inline int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_state mins)
+static inline int _get_ldev_if_state(struct drbd_device *device, enum drbd_disk_state mins)
 {
        int io_allowed;
 
        /* never get a reference while D_DISKLESS */
-       if (mdev->state.disk == D_DISKLESS)
+       if (device->state.disk == D_DISKLESS)
                return 0;
 
-       atomic_inc(&mdev->local_cnt);
-       io_allowed = (mdev->state.disk >= mins);
+       atomic_inc(&device->local_cnt);
+       io_allowed = (device->state.disk >= mins);
        if (!io_allowed)
-               put_ldev(mdev);
+               put_ldev(device);
        return io_allowed;
 }
 #else
-extern int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_state mins);
+extern int _get_ldev_if_state(struct drbd_device *device, enum drbd_disk_state mins);
 #endif
 
 /* you must have an "get_ldev" reference */
-static inline void drbd_get_syncer_progress(struct drbd_conf *mdev,
+static inline void drbd_get_syncer_progress(struct drbd_device *device,
                unsigned long *bits_left, unsigned int *per_mil_done)
 {
        /* this is to break it at compile time when we change that, in case we
         * want to support more than (1<<32) bits on a 32bit arch. */
-       typecheck(unsigned long, mdev->rs_total);
+       typecheck(unsigned long, device->rs_total);
 
        /* note: both rs_total and rs_left are in bits, i.e. in
         * units of BM_BLOCK_SIZE.
         * for the percentage, we don't care. */
 
-       if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T)
-               *bits_left = mdev->ov_left;
+       if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T)
+               *bits_left = device->ov_left;
        else
-               *bits_left = drbd_bm_total_weight(mdev) - mdev->rs_failed;
+               *bits_left = drbd_bm_total_weight(device) - device->rs_failed;
        /* >> 10 to prevent overflow,
         * +1 to prevent division by zero */
-       if (*bits_left > mdev->rs_total) {
+       if (*bits_left > device->rs_total) {
                /* doh. maybe a logic bug somewhere.
                 * may also be just a race condition
                 * between this and a disconnect during sync.
                 * for now, just prevent in-kernel buffer overflow.
                 */
                smp_rmb();
-               dev_warn(DEV, "cs:%s rs_left=%lu > rs_total=%lu (rs_failed %lu)\n",
-                               drbd_conn_str(mdev->state.conn),
-                               *bits_left, mdev->rs_total, mdev->rs_failed);
+               drbd_warn(device, "cs:%s rs_left=%lu > rs_total=%lu (rs_failed %lu)\n",
+                               drbd_conn_str(device->state.conn),
+                               *bits_left, device->rs_total, device->rs_failed);
                *per_mil_done = 0;
        } else {
                /* Make sure the division happens in long context.
@@ -2133,9 +1939,9 @@ static inline void drbd_get_syncer_progress(struct drbd_conf *mdev,
                 * Note: currently we don't support such large bitmaps on 32bit
                 * arch anyways, but no harm done to be prepared for it here.
                 */
-               unsigned int shift = mdev->rs_total > UINT_MAX ? 16 : 10;
+               unsigned int shift = device->rs_total > UINT_MAX ? 16 : 10;
                unsigned long left = *bits_left >> shift;
-               unsigned long total = 1UL + (mdev->rs_total >> shift);
+               unsigned long total = 1UL + (device->rs_total >> shift);
                unsigned long tmp = 1000UL - left * 1000UL/total;
                *per_mil_done = tmp;
        }
@@ -2145,22 +1951,22 @@ static inline void drbd_get_syncer_progress(struct drbd_conf *mdev,
 /* this throttles on-the-fly application requests
  * according to max_buffers settings;
  * maybe re-implement using semaphores? */
-static inline int drbd_get_max_buffers(struct drbd_conf *mdev)
+static inline int drbd_get_max_buffers(struct drbd_device *device)
 {
        struct net_conf *nc;
        int mxb;
 
        rcu_read_lock();
-       nc = rcu_dereference(mdev->tconn->net_conf);
+       nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
        mxb = nc ? nc->max_buffers : 1000000;  /* arbitrary limit on open requests */
        rcu_read_unlock();
 
        return mxb;
 }
 
-static inline int drbd_state_is_stable(struct drbd_conf *mdev)
+static inline int drbd_state_is_stable(struct drbd_device *device)
 {
-       union drbd_dev_state s = mdev->state;
+       union drbd_dev_state s = device->state;
 
        /* DO NOT add a default clause, we want the compiler to warn us
         * for any newly introduced state we may have forgotten to add here */
@@ -2194,7 +2000,7 @@ static inline int drbd_state_is_stable(struct drbd_conf *mdev)
 
                /* Allow IO in BM exchange states with new protocols */
        case C_WF_BITMAP_S:
-               if (mdev->tconn->agreed_pro_version < 96)
+               if (first_peer_device(device)->connection->agreed_pro_version < 96)
                        return 0;
                break;
 
@@ -2228,20 +2034,20 @@ static inline int drbd_state_is_stable(struct drbd_conf *mdev)
        return 1;
 }
 
-static inline int drbd_suspended(struct drbd_conf *mdev)
+static inline int drbd_suspended(struct drbd_device *device)
 {
-       struct drbd_tconn *tconn = mdev->tconn;
+       struct drbd_resource *resource = device->resource;
 
-       return tconn->susp || tconn->susp_fen || tconn->susp_nod;
+       return resource->susp || resource->susp_fen || resource->susp_nod;
 }
 
-static inline bool may_inc_ap_bio(struct drbd_conf *mdev)
+static inline bool may_inc_ap_bio(struct drbd_device *device)
 {
-       int mxb = drbd_get_max_buffers(mdev);
+       int mxb = drbd_get_max_buffers(device);
 
-       if (drbd_suspended(mdev))
+       if (drbd_suspended(device))
                return false;
-       if (test_bit(SUSPEND_IO, &mdev->flags))
+       if (test_bit(SUSPEND_IO, &device->flags))
                return false;
 
        /* to avoid potential deadlock or bitmap corruption,
@@ -2249,32 +2055,32 @@ static inline bool may_inc_ap_bio(struct drbd_conf *mdev)
         * to start during "stable" states. */
 
        /* no new io accepted when attaching or detaching the disk */
-       if (!drbd_state_is_stable(mdev))
+       if (!drbd_state_is_stable(device))
                return false;
 
        /* since some older kernels don't have atomic_add_unless,
         * and we are within the spinlock anyways, we have this workaround.  */
-       if (atomic_read(&mdev->ap_bio_cnt) > mxb)
+       if (atomic_read(&device->ap_bio_cnt) > mxb)
                return false;
-       if (test_bit(BITMAP_IO, &mdev->flags))
+       if (test_bit(BITMAP_IO, &device->flags))
                return false;
        return true;
 }
 
-static inline bool inc_ap_bio_cond(struct drbd_conf *mdev)
+static inline bool inc_ap_bio_cond(struct drbd_device *device)
 {
        bool rv = false;
 
-       spin_lock_irq(&mdev->tconn->req_lock);
-       rv = may_inc_ap_bio(mdev);
+       spin_lock_irq(&device->resource->req_lock);
+       rv = may_inc_ap_bio(device);
        if (rv)
-               atomic_inc(&mdev->ap_bio_cnt);
-       spin_unlock_irq(&mdev->tconn->req_lock);
+               atomic_inc(&device->ap_bio_cnt);
+       spin_unlock_irq(&device->resource->req_lock);
 
        return rv;
 }
 
-static inline void inc_ap_bio(struct drbd_conf *mdev)
+static inline void inc_ap_bio(struct drbd_device *device)
 {
        /* we wait here
         *    as long as the device is suspended
@@ -2284,42 +2090,42 @@ static inline void inc_ap_bio(struct drbd_conf *mdev)
         * to avoid races with the reconnect code,
         * we need to atomic_inc within the spinlock. */
 
-       wait_event(mdev->misc_wait, inc_ap_bio_cond(mdev));
+       wait_event(device->misc_wait, inc_ap_bio_cond(device));
 }
 
-static inline void dec_ap_bio(struct drbd_conf *mdev)
+static inline void dec_ap_bio(struct drbd_device *device)
 {
-       int mxb = drbd_get_max_buffers(mdev);
-       int ap_bio = atomic_dec_return(&mdev->ap_bio_cnt);
+       int mxb = drbd_get_max_buffers(device);
+       int ap_bio = atomic_dec_return(&device->ap_bio_cnt);
 
-       D_ASSERT(ap_bio >= 0);
+       D_ASSERT(device, ap_bio >= 0);
 
-       if (ap_bio == 0 && test_bit(BITMAP_IO, &mdev->flags)) {
-               if (!test_and_set_bit(BITMAP_IO_QUEUED, &mdev->flags))
-                       drbd_queue_work(&mdev->tconn->sender_work, &mdev->bm_io_work.w);
+       if (ap_bio == 0 && test_bit(BITMAP_IO, &device->flags)) {
+               if (!test_and_set_bit(BITMAP_IO_QUEUED, &device->flags))
+                       drbd_queue_work(&first_peer_device(device)->connection->sender_work, &device->bm_io_work.w);
        }
 
        /* this currently does wake_up for every dec_ap_bio!
         * maybe rather introduce some type of hysteresis?
         * e.g. (ap_bio == mxb/2 || ap_bio == 0) ? */
        if (ap_bio < mxb)
-               wake_up(&mdev->misc_wait);
+               wake_up(&device->misc_wait);
 }
 
-static inline bool verify_can_do_stop_sector(struct drbd_conf *mdev)
+static inline bool verify_can_do_stop_sector(struct drbd_device *device)
 {
-       return mdev->tconn->agreed_pro_version >= 97 &&
-               mdev->tconn->agreed_pro_version != 100;
+       return first_peer_device(device)->connection->agreed_pro_version >= 97 &&
+               first_peer_device(device)->connection->agreed_pro_version != 100;
 }
 
-static inline int drbd_set_ed_uuid(struct drbd_conf *mdev, u64 val)
+static inline int drbd_set_ed_uuid(struct drbd_device *device, u64 val)
 {
-       int changed = mdev->ed_uuid != val;
-       mdev->ed_uuid = val;
+       int changed = device->ed_uuid != val;
+       device->ed_uuid = val;
        return changed;
 }
 
-static inline int drbd_queue_order_type(struct drbd_conf *mdev)
+static inline int drbd_queue_order_type(struct drbd_device *device)
 {
        /* sorry, we currently have no working implementation
         * of distributed TCQ stuff */
@@ -2329,23 +2135,29 @@ static inline int drbd_queue_order_type(struct drbd_conf *mdev)
        return QUEUE_ORDERED_NONE;
 }
 
-static inline void drbd_md_flush(struct drbd_conf *mdev)
+static inline void drbd_md_flush(struct drbd_device *device)
 {
        int r;
 
-       if (mdev->ldev == NULL) {
-               dev_warn(DEV, "mdev->ldev == NULL in drbd_md_flush\n");
+       if (device->ldev == NULL) {
+               drbd_warn(device, "device->ldev == NULL in drbd_md_flush\n");
                return;
        }
 
-       if (test_bit(MD_NO_FUA, &mdev->flags))
+       if (test_bit(MD_NO_FUA, &device->flags))
                return;
 
-       r = blkdev_issue_flush(mdev->ldev->md_bdev, GFP_NOIO, NULL);
+       r = blkdev_issue_flush(device->ldev->md_bdev, GFP_NOIO, NULL);
        if (r) {
-               set_bit(MD_NO_FUA, &mdev->flags);
-               dev_err(DEV, "meta data flush failed with status %d, disabling md-flushes\n", r);
+               set_bit(MD_NO_FUA, &device->flags);
+               drbd_err(device, "meta data flush failed with status %d, disabling md-flushes\n", r);
        }
 }
 
+static inline struct drbd_connection *first_connection(struct drbd_resource *resource)
+{
+       return list_first_entry(&resource->connections,
+                               struct drbd_connection, connections);
+}
+
 #endif
This page took 0.064116 seconds and 5 git commands to generate.