Commit a6b32bc3 authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Philipp Reisner

drbd: Introduce "peer_device" object between "device" and "connection"

In a setup where a device (aka volume) can replicate to multiple peers and one
connection can be shared between multiple devices, we need separate objects to
represent devices on peer nodes and network connections.

As a first step to introduce multiple connections per device, give each
drbd_device object a single drbd_peer_device object which connects it to a
drbd_connection object.
Signed-off-by: default avatarAndreas Gruenbacher <agruen@linbit.com>
Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
parent bde89a9e
......@@ -315,7 +315,7 @@ void drbd_al_begin_io_commit(struct drbd_device *device, bool delegate)
{
bool locked = false;
BUG_ON(delegate && current == device->connection->worker.task);
BUG_ON(delegate && current == first_peer_device(device)->connection->worker.task);
/* Serialize multiple transactions.
* This uses test_and_set_bit, memory barrier is implicit.
......@@ -354,7 +354,7 @@ void drbd_al_begin_io_commit(struct drbd_device *device, bool delegate)
*/
void drbd_al_begin_io(struct drbd_device *device, struct drbd_interval *i, bool delegate)
{
BUG_ON(delegate && current == device->connection->worker.task);
BUG_ON(delegate && current == first_peer_device(device)->connection->worker.task);
if (drbd_al_begin_io_prepare(device, i))
drbd_al_begin_io_commit(device, delegate);
......@@ -614,7 +614,7 @@ static int al_write_transaction(struct drbd_device *device, bool delegate)
init_completion(&al_work.event);
al_work.w.cb = w_al_write_transaction;
al_work.w.device = device;
drbd_queue_work_front(&device->connection->sender_work, &al_work.w);
drbd_queue_work_front(&first_peer_device(device)->connection->sender_work, &al_work.w);
wait_for_completion(&al_work.event);
return al_work.err;
} else
......@@ -796,7 +796,7 @@ static void drbd_try_clear_on_disk_bm(struct drbd_device *device, sector_t secto
udw->enr = ext->lce.lc_number;
udw->w.cb = w_update_odbm;
udw->w.device = device;
drbd_queue_work_front(&device->connection->sender_work, &udw->w);
drbd_queue_work_front(&first_peer_device(device)->connection->sender_work, &udw->w);
} else {
dev_warn(DEV, "Could not kmalloc an udw\n");
}
......
......@@ -119,9 +119,9 @@ static void __bm_print_lock_info(struct drbd_device *device, const char *func)
if (!__ratelimit(&drbd_ratelimit_state))
return;
dev_err(DEV, "FIXME %s in %s, bitmap locked for '%s' by %s\n",
drbd_task_to_thread_name(device->connection, current),
drbd_task_to_thread_name(first_peer_device(device)->connection, current),
func, b->bm_why ?: "?",
drbd_task_to_thread_name(device->connection, b->bm_task));
drbd_task_to_thread_name(first_peer_device(device)->connection, b->bm_task));
}
void drbd_bm_lock(struct drbd_device *device, char *why, enum bm_flag flags)
......@@ -138,9 +138,9 @@ void drbd_bm_lock(struct drbd_device *device, char *why, enum bm_flag flags)
if (trylock_failed) {
dev_warn(DEV, "%s going to '%s' but bitmap already locked for '%s' by %s\n",
drbd_task_to_thread_name(device->connection, current),
drbd_task_to_thread_name(first_peer_device(device)->connection, current),
why, b->bm_why ?: "?",
drbd_task_to_thread_name(device->connection, b->bm_task));
drbd_task_to_thread_name(first_peer_device(device)->connection, b->bm_task));
mutex_lock(&b->bm_change);
}
if (BM_LOCKED_MASK & b->bm_flags)
......
......@@ -483,7 +483,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: device->connection->conf_update */
struct disk_conf *disk_conf; /* RCU, for updates: first_peer_device(device)->connection->conf_update */
sector_t known_size; /* last known size of that backing device */
};
......@@ -617,8 +617,14 @@ struct submit_worker {
struct list_head writes;
};
struct drbd_device {
struct drbd_peer_device {
struct list_head peer_devices;
struct drbd_device *device;
struct drbd_connection *connection;
};
struct drbd_device {
struct list_head peer_devices;
int vnr; /* volume number within the connection */
struct kref kref;
......@@ -744,7 +750,7 @@ struct drbd_device {
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 device->connection->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 */
......@@ -768,6 +774,20 @@ static inline struct drbd_device *minor_to_device(unsigned int minor)
return (struct drbd_device *)idr_find(&minors, minor);
}
static inline struct drbd_peer_device *first_peer_device(struct drbd_device *device)
{
return list_first_entry(&device->peer_devices, struct drbd_peer_device, peer_devices);
}
#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 device->minor;
......@@ -1154,7 +1174,7 @@ extern struct bio *bio_alloc_drbd(gfp_t gfp_mask);
extern rwlock_t global_state_lock;
extern int conn_lowest_minor(struct drbd_connection *connection);
enum drbd_ret_code conn_new_minor(struct drbd_connection *connection, unsigned int minor, int vnr);
enum drbd_ret_code drbd_create_minor(struct drbd_connection *connection, unsigned int minor, int vnr);
extern void drbd_minor_destroy(struct kref *kref);
extern int set_resource_options(struct drbd_connection *connection, struct res_opts *res_opts);
......@@ -1275,7 +1295,7 @@ 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(device->connection);
conn_flush_workqueue(first_peer_device(device)->connection);
}
/* Yes, there is kernel_setsockopt, but only since 2.6.18.
......@@ -1421,9 +1441,9 @@ static inline union drbd_state drbd_read_state(struct drbd_device *device)
union drbd_state rv;
rv.i = device->state.i;
rv.susp = device->connection->susp;
rv.susp_nod = device->connection->susp_nod;
rv.susp_fen = device->connection->susp_fen;
rv.susp = first_peer_device(device)->connection->susp;
rv.susp_nod = first_peer_device(device)->connection->susp_nod;
rv.susp_fen = first_peer_device(device)->connection->susp_fen;
return rv;
}
......@@ -1505,9 +1525,9 @@ static inline void drbd_chk_io_error_(struct drbd_device *device,
{
if (error) {
unsigned long flags;
spin_lock_irqsave(&device->connection->req_lock, flags);
spin_lock_irqsave(&first_peer_device(device)->connection->req_lock, flags);
__drbd_chk_io_error_(device, forcedetach, where);
spin_unlock_irqrestore(&device->connection->req_lock, flags);
spin_unlock_irqrestore(&first_peer_device(device)->connection->req_lock, flags);
}
}
......@@ -1783,7 +1803,7 @@ static inline void put_ldev(struct drbd_device *device)
if (device->state.disk == D_FAILED) {
/* all application IO references gone. */
if (!test_and_set_bit(GO_DISKLESS, &device->flags))
drbd_queue_work(&device->connection->sender_work, &device->go_diskless);
drbd_queue_work(&first_peer_device(device)->connection->sender_work, &device->go_diskless);
}
wake_up(&device->misc_wait);
}
......@@ -1865,7 +1885,7 @@ static inline int drbd_get_max_buffers(struct drbd_device *device)
int mxb;
rcu_read_lock();
nc = rcu_dereference(device->connection->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();
......@@ -1908,7 +1928,7 @@ static inline int drbd_state_is_stable(struct drbd_device *device)
/* Allow IO in BM exchange states with new protocols */
case C_WF_BITMAP_S:
if (device->connection->agreed_pro_version < 96)
if (first_peer_device(device)->connection->agreed_pro_version < 96)
return 0;
break;
......@@ -1944,7 +1964,7 @@ static inline int drbd_state_is_stable(struct drbd_device *device)
static inline int drbd_suspended(struct drbd_device *device)
{
struct drbd_connection *connection = device->connection;
struct drbd_connection *connection = first_peer_device(device)->connection;
return connection->susp || connection->susp_fen || connection->susp_nod;
}
......@@ -1979,11 +1999,11 @@ static inline bool inc_ap_bio_cond(struct drbd_device *device)
{
bool rv = false;
spin_lock_irq(&device->connection->req_lock);
spin_lock_irq(&first_peer_device(device)->connection->req_lock);
rv = may_inc_ap_bio(device);
if (rv)
atomic_inc(&device->ap_bio_cnt);
spin_unlock_irq(&device->connection->req_lock);
spin_unlock_irq(&first_peer_device(device)->connection->req_lock);
return rv;
}
......@@ -2010,7 +2030,7 @@ static inline void dec_ap_bio(struct drbd_device *device)
if (ap_bio == 0 && test_bit(BITMAP_IO, &device->flags)) {
if (!test_and_set_bit(BITMAP_IO_QUEUED, &device->flags))
drbd_queue_work(&device->connection->sender_work, &device->bm_io_work.w);
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!
......@@ -2022,8 +2042,8 @@ static inline void dec_ap_bio(struct drbd_device *device)
static inline bool verify_can_do_stop_sector(struct drbd_device *device)
{
return device->connection->agreed_pro_version >= 97 &&
device->connection->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_device *device, u64 val)
......
This diff is collapsed.
This diff is collapsed.
......@@ -251,7 +251,7 @@ static int drbd_seq_show(struct seq_file *seq, void *v)
/* reset device->congestion_reason */
bdi_rw_congested(&device->rq_queue->backing_dev_info);
nc = rcu_dereference(device->connection->net_conf);
nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' ';
seq_printf(seq,
"%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n"
......@@ -280,8 +280,8 @@ static int drbd_seq_show(struct seq_file *seq, void *v)
atomic_read(&device->rs_pending_cnt),
atomic_read(&device->unacked_cnt),
atomic_read(&device->ap_bio_cnt),
device->connection->epochs,
write_ordering_chars[device->connection->write_ordering]
first_peer_device(device)->connection->epochs,
write_ordering_chars[first_peer_device(device)->connection->write_ordering]
);
seq_printf(seq, " oos:%llu\n",
Bit2KB((unsigned long long)
......
This diff is collapsed.
......@@ -274,8 +274,8 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m)
* and reset the transfer log epoch write_cnt.
*/
if (rw == WRITE &&
req->epoch == atomic_read(&device->connection->current_tle_nr))
start_new_tl_epoch(device->connection);
req->epoch == atomic_read(&first_peer_device(device)->connection->current_tle_nr))
start_new_tl_epoch(first_peer_device(device)->connection);
/* Update disk stats */
_drbd_end_io_acct(device, req);
......@@ -477,7 +477,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
* and from w_read_retry_remote */
D_ASSERT(!(req->rq_state & RQ_NET_MASK));
rcu_read_lock();
nc = rcu_dereference(device->connection->net_conf);
nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
p = nc->wire_protocol;
rcu_read_unlock();
req->rq_state |=
......@@ -542,7 +542,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
D_ASSERT((req->rq_state & RQ_LOCAL_MASK) == 0);
mod_rq_state(req, m, 0, RQ_NET_QUEUED);
req->w.cb = w_send_read_req;
drbd_queue_work(&device->connection->sender_work, &req->w);
drbd_queue_work(&first_peer_device(device)->connection->sender_work, &req->w);
break;
case QUEUE_FOR_NET_WRITE:
......@@ -577,22 +577,22 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
D_ASSERT(req->rq_state & RQ_NET_PENDING);
mod_rq_state(req, m, 0, RQ_NET_QUEUED|RQ_EXP_BARR_ACK);
req->w.cb = w_send_dblock;
drbd_queue_work(&device->connection->sender_work, &req->w);
drbd_queue_work(&first_peer_device(device)->connection->sender_work, &req->w);
/* close the epoch, in case it outgrew the limit */
rcu_read_lock();
nc = rcu_dereference(device->connection->net_conf);
nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
p = nc->max_epoch_size;
rcu_read_unlock();
if (device->connection->current_tle_writes >= p)
start_new_tl_epoch(device->connection);
if (first_peer_device(device)->connection->current_tle_writes >= p)
start_new_tl_epoch(first_peer_device(device)->connection);
break;
case QUEUE_FOR_SEND_OOS:
mod_rq_state(req, m, 0, RQ_NET_QUEUED);
req->w.cb = w_send_out_of_sync;
drbd_queue_work(&device->connection->sender_work, &req->w);
drbd_queue_work(&first_peer_device(device)->connection->sender_work, &req->w);
break;
case READ_RETRY_REMOTE_CANCELED:
......@@ -704,7 +704,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
get_ldev(device); /* always succeeds in this call path */
req->w.cb = w_restart_disk_io;
drbd_queue_work(&device->connection->sender_work, &req->w);
drbd_queue_work(&first_peer_device(device)->connection->sender_work, &req->w);
break;
case RESEND:
......@@ -725,7 +725,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
mod_rq_state(req, m, RQ_COMPLETION_SUSP, RQ_NET_QUEUED|RQ_NET_PENDING);
if (req->w.cb) {
drbd_queue_work(&device->connection->sender_work, &req->w);
drbd_queue_work(&first_peer_device(device)->connection->sender_work, &req->w);
rv = req->rq_state & RQ_WRITE ? MR_WRITE : MR_READ;
} /* else: FIXME can this happen? */
break;
......@@ -757,7 +757,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
break;
case QUEUE_AS_DRBD_BARRIER:
start_new_tl_epoch(device->connection);
start_new_tl_epoch(first_peer_device(device)->connection);
mod_rq_state(req, m, 0, RQ_NET_OK|RQ_NET_DONE);
break;
};
......@@ -851,9 +851,9 @@ static void complete_conflicting_writes(struct drbd_request *req)
break;
/* Indicate to wake up device->misc_wait on progress. */
i->waiting = true;
spin_unlock_irq(&device->connection->req_lock);
spin_unlock_irq(&first_peer_device(device)->connection->req_lock);
schedule();
spin_lock_irq(&device->connection->req_lock);
spin_lock_irq(&first_peer_device(device)->connection->req_lock);
}
finish_wait(&device->misc_wait, &wait);
}
......@@ -861,7 +861,7 @@ static void complete_conflicting_writes(struct drbd_request *req)
/* called within req_lock and rcu_read_lock() */
static void maybe_pull_ahead(struct drbd_device *device)
{
struct drbd_connection *connection = device->connection;
struct drbd_connection *connection = first_peer_device(device)->connection;
struct net_conf *nc;
bool congested = false;
enum drbd_on_congestion on_congestion;
......@@ -894,7 +894,7 @@ static void maybe_pull_ahead(struct drbd_device *device)
if (congested) {
/* start a new epoch for non-mirrored writes */
start_new_tl_epoch(device->connection);
start_new_tl_epoch(first_peer_device(device)->connection);
if (on_congestion == OC_PULL_AHEAD)
_drbd_set_state(_NS(device, conn, C_AHEAD), 0, NULL);
......@@ -1078,7 +1078,7 @@ static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request
struct bio_and_error m = { NULL, };
bool no_remote = false;
spin_lock_irq(&device->connection->req_lock);
spin_lock_irq(&first_peer_device(device)->connection->req_lock);
if (rw == WRITE) {
/* This may temporarily give up the req_lock,
* but will re-aquire it before it returns here.
......@@ -1112,15 +1112,15 @@ static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request
}
/* which transfer log epoch does this belong to? */
req->epoch = atomic_read(&device->connection->current_tle_nr);
req->epoch = atomic_read(&first_peer_device(device)->connection->current_tle_nr);
/* no point in adding empty flushes to the transfer log,
* they are mapped to drbd barriers already. */
if (likely(req->i.size!=0)) {
if (rw == WRITE)
device->connection->current_tle_writes++;
first_peer_device(device)->connection->current_tle_writes++;
list_add_tail(&req->tl_requests, &device->connection->transfer_log);
list_add_tail(&req->tl_requests, &first_peer_device(device)->connection->transfer_log);
}
if (rw == WRITE) {
......@@ -1140,9 +1140,9 @@ static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request
/* needs to be marked within the same spinlock */
_req_mod(req, TO_BE_SUBMITTED);
/* but we need to give up the spinlock to submit */
spin_unlock_irq(&device->connection->req_lock);
spin_unlock_irq(&first_peer_device(device)->connection->req_lock);
drbd_submit_req_private_bio(req);
spin_lock_irq(&device->connection->req_lock);
spin_lock_irq(&first_peer_device(device)->connection->req_lock);
} else if (no_remote) {
nodata:
if (__ratelimit(&drbd_ratelimit_state))
......@@ -1155,7 +1155,7 @@ static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request
out:
if (drbd_req_put_completion_ref(req, &m, 1))
kref_put(&req->kref, drbd_req_destroy);
spin_unlock_irq(&device->connection->req_lock);
spin_unlock_irq(&first_peer_device(device)->connection->req_lock);
if (m.bio)
complete_master_bio(device, &m);
......@@ -1336,7 +1336,7 @@ static struct drbd_request *find_oldest_request(struct drbd_connection *connecti
void request_timer_fn(unsigned long data)
{
struct drbd_device *device = (struct drbd_device *) data;
struct drbd_connection *connection = device->connection;
struct drbd_connection *connection = first_peer_device(device)->connection;
struct drbd_request *req; /* oldest request */
struct net_conf *nc;
unsigned long ent = 0, dt = 0, et, nt; /* effective timeout = ko_count * timeout */
......
......@@ -318,9 +318,9 @@ static inline int req_mod(struct drbd_request *req,
struct bio_and_error m;
int rv;
spin_lock_irqsave(&device->connection->req_lock, flags);
spin_lock_irqsave(&first_peer_device(device)->connection->req_lock, flags);
rv = __req_mod(req, what, &m);
spin_unlock_irqrestore(&device->connection->req_lock, flags);
spin_unlock_irqrestore(&first_peer_device(device)->connection->req_lock, flags);
if (m.bio)
complete_master_bio(device, &m);
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment