提交 b2fb6dbe 编写于 作者: P Philipp Reisner

drbd: moved net_cont and net_cnt_wait from mdev to tconn

Patch partly generated by:

sed -i -e 's/get_net_conf(mdev)/get_net_conf(mdev->tconn)/g' \
       -e 's/put_net_conf(mdev)/put_net_conf(mdev->tconn)/g' \
       -e 's/get_net_conf(odev)/get_net_conf(odev->tconn)/g' \
       -e 's/put_net_conf(odev)/put_net_conf(odev->tconn)/g' \
       *.[ch]
Signed-off-by: NPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: NLars Ellenberg <lars.ellenberg@linbit.com>
上级 89e58e75
...@@ -967,6 +967,8 @@ struct drbd_tconn { /* is a resource from the config file */ ...@@ -967,6 +967,8 @@ struct drbd_tconn { /* is a resource from the config file */
struct drbd_conf *volume0; /* TODO: Remove me again */ struct drbd_conf *volume0; /* TODO: Remove me again */
struct net_conf *net_conf; /* protected by get_net_conf() and put_net_conf() */ struct net_conf *net_conf; /* protected by get_net_conf() and put_net_conf() */
atomic_t net_cnt; /* Users of net_conf */
wait_queue_head_t net_cnt_wait;
}; };
struct drbd_conf { struct drbd_conf {
...@@ -1012,7 +1014,6 @@ struct drbd_conf { ...@@ -1012,7 +1014,6 @@ struct drbd_conf {
union drbd_state state; union drbd_state state;
wait_queue_head_t misc_wait; wait_queue_head_t misc_wait;
wait_queue_head_t state_wait; /* upon each state change. */ wait_queue_head_t state_wait; /* upon each state change. */
wait_queue_head_t net_cnt_wait;
unsigned int send_cnt; unsigned int send_cnt;
unsigned int recv_cnt; unsigned int recv_cnt;
unsigned int read_cnt; unsigned int read_cnt;
...@@ -1024,7 +1025,7 @@ struct drbd_conf { ...@@ -1024,7 +1025,7 @@ struct drbd_conf {
atomic_t rs_pending_cnt; /* RS request/data packets on the wire */ atomic_t rs_pending_cnt; /* RS request/data packets on the wire */
atomic_t unacked_cnt; /* Need to send replys for */ atomic_t unacked_cnt; /* Need to send replys for */
atomic_t local_cnt; /* Waiting for local completion */ atomic_t local_cnt; /* Waiting for local completion */
atomic_t net_cnt; /* Users of net_conf */
spinlock_t req_lock; spinlock_t req_lock;
struct drbd_tl_epoch *unused_spare_tle; /* for pre-allocation */ struct drbd_tl_epoch *unused_spare_tle; /* for pre-allocation */
struct drbd_tl_epoch *newest_tle; struct drbd_tl_epoch *newest_tle;
...@@ -2126,10 +2127,10 @@ static inline void inc_unacked(struct drbd_conf *mdev) ...@@ -2126,10 +2127,10 @@ static inline void inc_unacked(struct drbd_conf *mdev)
ERR_IF_CNT_IS_NEGATIVE(unacked_cnt); } while (0) ERR_IF_CNT_IS_NEGATIVE(unacked_cnt); } while (0)
static inline void put_net_conf(struct drbd_conf *mdev) static inline void put_net_conf(struct drbd_tconn *tconn)
{ {
if (atomic_dec_and_test(&mdev->net_cnt)) if (atomic_dec_and_test(&tconn->net_cnt))
wake_up(&mdev->net_cnt_wait); wake_up(&tconn->net_cnt_wait);
} }
/** /**
...@@ -2138,14 +2139,14 @@ static inline void put_net_conf(struct drbd_conf *mdev) ...@@ -2138,14 +2139,14 @@ static inline void put_net_conf(struct drbd_conf *mdev)
* *
* You have to call put_net_conf() when finished working with mdev->tconn->net_conf. * You have to call put_net_conf() when finished working with mdev->tconn->net_conf.
*/ */
static inline int get_net_conf(struct drbd_conf *mdev) static inline int get_net_conf(struct drbd_tconn *tconn)
{ {
int have_net_conf; int have_net_conf;
atomic_inc(&mdev->net_cnt); atomic_inc(&tconn->net_cnt);
have_net_conf = mdev->state.conn >= C_UNCONNECTED; have_net_conf = tconn->volume0->state.conn >= C_UNCONNECTED;
if (!have_net_conf) if (!have_net_conf)
put_net_conf(mdev); put_net_conf(tconn);
return have_net_conf; return have_net_conf;
} }
...@@ -2251,9 +2252,9 @@ static inline void drbd_get_syncer_progress(struct drbd_conf *mdev, ...@@ -2251,9 +2252,9 @@ static inline void drbd_get_syncer_progress(struct drbd_conf *mdev,
static inline int drbd_get_max_buffers(struct drbd_conf *mdev) static inline int drbd_get_max_buffers(struct drbd_conf *mdev)
{ {
int mxb = 1000000; /* arbitrary limit on open requests */ int mxb = 1000000; /* arbitrary limit on open requests */
if (get_net_conf(mdev)) { if (get_net_conf(mdev->tconn)) {
mxb = mdev->tconn->net_conf->max_buffers; mxb = mdev->tconn->net_conf->max_buffers;
put_net_conf(mdev); put_net_conf(mdev->tconn);
} }
return mxb; return mxb;
} }
......
...@@ -692,11 +692,11 @@ is_valid_state(struct drbd_conf *mdev, union drbd_state ns) ...@@ -692,11 +692,11 @@ is_valid_state(struct drbd_conf *mdev, union drbd_state ns)
put_ldev(mdev); put_ldev(mdev);
} }
if (get_net_conf(mdev)) { if (get_net_conf(mdev->tconn)) {
if (!mdev->tconn->net_conf->two_primaries && if (!mdev->tconn->net_conf->two_primaries &&
ns.role == R_PRIMARY && ns.peer == R_PRIMARY) ns.role == R_PRIMARY && ns.peer == R_PRIMARY)
rv = SS_TWO_PRIMARIES; rv = SS_TWO_PRIMARIES;
put_net_conf(mdev); put_net_conf(mdev->tconn);
} }
if (rv <= 0) if (rv <= 0)
...@@ -2972,7 +2972,6 @@ void drbd_init_set_defaults(struct drbd_conf *mdev) ...@@ -2972,7 +2972,6 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
atomic_set(&mdev->rs_pending_cnt, 0); atomic_set(&mdev->rs_pending_cnt, 0);
atomic_set(&mdev->unacked_cnt, 0); atomic_set(&mdev->unacked_cnt, 0);
atomic_set(&mdev->local_cnt, 0); atomic_set(&mdev->local_cnt, 0);
atomic_set(&mdev->net_cnt, 0);
atomic_set(&mdev->packet_seq, 0); atomic_set(&mdev->packet_seq, 0);
atomic_set(&mdev->pp_in_use, 0); atomic_set(&mdev->pp_in_use, 0);
atomic_set(&mdev->pp_in_use_by_net, 0); atomic_set(&mdev->pp_in_use_by_net, 0);
...@@ -3031,7 +3030,6 @@ void drbd_init_set_defaults(struct drbd_conf *mdev) ...@@ -3031,7 +3030,6 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
init_waitqueue_head(&mdev->misc_wait); init_waitqueue_head(&mdev->misc_wait);
init_waitqueue_head(&mdev->state_wait); init_waitqueue_head(&mdev->state_wait);
init_waitqueue_head(&mdev->net_cnt_wait);
init_waitqueue_head(&mdev->ee_wait); init_waitqueue_head(&mdev->ee_wait);
init_waitqueue_head(&mdev->al_wait); init_waitqueue_head(&mdev->al_wait);
init_waitqueue_head(&mdev->seq_wait); init_waitqueue_head(&mdev->seq_wait);
...@@ -3372,6 +3370,9 @@ struct drbd_tconn *drbd_new_tconn(char *name) ...@@ -3372,6 +3370,9 @@ struct drbd_tconn *drbd_new_tconn(char *name)
if (!tconn->name) if (!tconn->name)
goto fail; goto fail;
atomic_set(&tconn->net_cnt, 0);
init_waitqueue_head(&tconn->net_cnt_wait);
write_lock_irq(&global_state_lock); write_lock_irq(&global_state_lock);
list_add(&tconn->all_tconn, &drbd_tconns); list_add(&tconn->all_tconn, &drbd_tconns);
write_unlock_irq(&global_state_lock); write_unlock_irq(&global_state_lock);
......
...@@ -149,7 +149,7 @@ int drbd_khelper(struct drbd_conf *mdev, char *cmd) ...@@ -149,7 +149,7 @@ int drbd_khelper(struct drbd_conf *mdev, char *cmd)
snprintf(mb, 12, "minor-%d", mdev_to_minor(mdev)); snprintf(mb, 12, "minor-%d", mdev_to_minor(mdev));
if (get_net_conf(mdev)) { if (get_net_conf(mdev->tconn)) {
switch (((struct sockaddr *)mdev->tconn->net_conf->peer_addr)->sa_family) { switch (((struct sockaddr *)mdev->tconn->net_conf->peer_addr)->sa_family) {
case AF_INET6: case AF_INET6:
afs = "ipv6"; afs = "ipv6";
...@@ -169,7 +169,7 @@ int drbd_khelper(struct drbd_conf *mdev, char *cmd) ...@@ -169,7 +169,7 @@ int drbd_khelper(struct drbd_conf *mdev, char *cmd)
snprintf(af, 20, "DRBD_PEER_AF=%s", afs); snprintf(af, 20, "DRBD_PEER_AF=%s", afs);
envp[3]=af; envp[3]=af;
envp[4]=ad; envp[4]=ad;
put_net_conf(mdev); put_net_conf(mdev->tconn);
} }
/* The helper may take some time. /* The helper may take some time.
...@@ -409,9 +409,9 @@ drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) ...@@ -409,9 +409,9 @@ drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force)
put_ldev(mdev); put_ldev(mdev);
} }
} else { } else {
if (get_net_conf(mdev)) { if (get_net_conf(mdev->tconn)) {
mdev->tconn->net_conf->want_lose = 0; mdev->tconn->net_conf->want_lose = 0;
put_net_conf(mdev); put_net_conf(mdev->tconn);
} }
set_disk_ro(mdev->vdisk, false); set_disk_ro(mdev->vdisk, false);
if (get_ldev(mdev)) { if (get_ldev(mdev)) {
...@@ -971,9 +971,9 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp ...@@ -971,9 +971,9 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
goto fail; goto fail;
} }
if (get_net_conf(mdev)) { if (get_net_conf(mdev->tconn)) {
int prot = mdev->tconn->net_conf->wire_protocol; int prot = mdev->tconn->net_conf->wire_protocol;
put_net_conf(mdev); put_net_conf(mdev->tconn);
if (nbc->dc.fencing == FP_STONITH && prot == DRBD_PROT_A) { if (nbc->dc.fencing == FP_STONITH && prot == DRBD_PROT_A) {
retcode = ERR_STONITH_AND_PROT_A; retcode = ERR_STONITH_AND_PROT_A;
goto fail; goto fail;
...@@ -1438,7 +1438,7 @@ static int drbd_nl_net_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp, ...@@ -1438,7 +1438,7 @@ static int drbd_nl_net_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
odev = minor_to_mdev(i); odev = minor_to_mdev(i);
if (!odev || odev == mdev) if (!odev || odev == mdev)
continue; continue;
if (get_net_conf(odev)) { if (get_net_conf(odev->tconn)) {
taken_addr = (struct sockaddr *)&odev->tconn->net_conf->my_addr; taken_addr = (struct sockaddr *)&odev->tconn->net_conf->my_addr;
if (new_conf->my_addr_len == odev->tconn->net_conf->my_addr_len && if (new_conf->my_addr_len == odev->tconn->net_conf->my_addr_len &&
!memcmp(new_my_addr, taken_addr, new_conf->my_addr_len)) !memcmp(new_my_addr, taken_addr, new_conf->my_addr_len))
...@@ -1449,7 +1449,7 @@ static int drbd_nl_net_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp, ...@@ -1449,7 +1449,7 @@ static int drbd_nl_net_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
!memcmp(new_peer_addr, taken_addr, new_conf->peer_addr_len)) !memcmp(new_peer_addr, taken_addr, new_conf->peer_addr_len))
retcode = ERR_PEER_ADDR; retcode = ERR_PEER_ADDR;
put_net_conf(odev); put_net_conf(odev->tconn);
if (retcode != NO_ERROR) if (retcode != NO_ERROR)
goto fail; goto fail;
} }
...@@ -2050,9 +2050,9 @@ static int drbd_nl_get_config(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nl ...@@ -2050,9 +2050,9 @@ static int drbd_nl_get_config(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nl
put_ldev(mdev); put_ldev(mdev);
} }
if (get_net_conf(mdev)) { if (get_net_conf(mdev->tconn)) {
tl = net_conf_to_tags(mdev, mdev->tconn->net_conf, tl); tl = net_conf_to_tags(mdev, mdev->tconn->net_conf, tl);
put_net_conf(mdev); put_net_conf(mdev->tconn);
} }
tl = syncer_conf_to_tags(mdev, &mdev->sync_conf, tl); tl = syncer_conf_to_tags(mdev, &mdev->sync_conf, tl);
......
...@@ -578,7 +578,7 @@ static struct socket *drbd_try_connect(struct drbd_conf *mdev) ...@@ -578,7 +578,7 @@ static struct socket *drbd_try_connect(struct drbd_conf *mdev)
int err; int err;
int disconnect_on_error = 1; int disconnect_on_error = 1;
if (!get_net_conf(mdev)) if (!get_net_conf(mdev->tconn))
return NULL; return NULL;
what = "sock_create_kern"; what = "sock_create_kern";
...@@ -644,7 +644,7 @@ static struct socket *drbd_try_connect(struct drbd_conf *mdev) ...@@ -644,7 +644,7 @@ static struct socket *drbd_try_connect(struct drbd_conf *mdev)
if (disconnect_on_error) if (disconnect_on_error)
drbd_force_state(mdev, NS(conn, C_DISCONNECTING)); drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
} }
put_net_conf(mdev); put_net_conf(mdev->tconn);
return sock; return sock;
} }
...@@ -654,7 +654,7 @@ static struct socket *drbd_wait_for_connect(struct drbd_conf *mdev) ...@@ -654,7 +654,7 @@ static struct socket *drbd_wait_for_connect(struct drbd_conf *mdev)
struct socket *s_estab = NULL, *s_listen; struct socket *s_estab = NULL, *s_listen;
const char *what; const char *what;
if (!get_net_conf(mdev)) if (!get_net_conf(mdev->tconn))
return NULL; return NULL;
what = "sock_create_kern"; what = "sock_create_kern";
...@@ -692,7 +692,7 @@ static struct socket *drbd_wait_for_connect(struct drbd_conf *mdev) ...@@ -692,7 +692,7 @@ static struct socket *drbd_wait_for_connect(struct drbd_conf *mdev)
drbd_force_state(mdev, NS(conn, C_DISCONNECTING)); drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
} }
} }
put_net_conf(mdev); put_net_conf(mdev->tconn);
return s_estab; return s_estab;
} }
...@@ -3839,7 +3839,7 @@ static void drbd_disconnect(struct drbd_conf *mdev) ...@@ -3839,7 +3839,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
spin_unlock_irq(&mdev->req_lock); spin_unlock_irq(&mdev->req_lock);
if (os.conn == C_DISCONNECTING) { if (os.conn == C_DISCONNECTING) {
wait_event(mdev->net_cnt_wait, atomic_read(&mdev->net_cnt) == 0); wait_event(mdev->tconn->net_cnt_wait, atomic_read(&mdev->tconn->net_cnt) == 0);
crypto_free_hash(mdev->cram_hmac_tfm); crypto_free_hash(mdev->cram_hmac_tfm);
mdev->cram_hmac_tfm = NULL; mdev->cram_hmac_tfm = NULL;
...@@ -4166,9 +4166,9 @@ int drbdd_init(struct drbd_thread *thi) ...@@ -4166,9 +4166,9 @@ int drbdd_init(struct drbd_thread *thi)
} while (h == 0); } while (h == 0);
if (h > 0) { if (h > 0) {
if (get_net_conf(mdev)) { if (get_net_conf(mdev->tconn)) {
drbdd(mdev); drbdd(mdev);
put_net_conf(mdev); put_net_conf(mdev->tconn);
} }
} }
......
...@@ -323,7 +323,7 @@ static int _req_conflicts(struct drbd_request *req) ...@@ -323,7 +323,7 @@ static int _req_conflicts(struct drbd_request *req)
D_ASSERT(drbd_interval_empty(&req->i)); D_ASSERT(drbd_interval_empty(&req->i));
if (!get_net_conf(mdev)) if (!get_net_conf(mdev->tconn))
return 0; return 0;
i = drbd_find_overlap(&mdev->write_requests, sector, size); i = drbd_find_overlap(&mdev->write_requests, sector, size);
...@@ -359,11 +359,11 @@ static int _req_conflicts(struct drbd_request *req) ...@@ -359,11 +359,11 @@ static int _req_conflicts(struct drbd_request *req)
/* this is like it should be, and what we expected. /* this is like it should be, and what we expected.
* our users do behave after all... */ * our users do behave after all... */
put_net_conf(mdev); put_net_conf(mdev->tconn);
return 0; return 0;
out_conflict: out_conflict:
put_net_conf(mdev); put_net_conf(mdev->tconn);
return 1; return 1;
} }
...@@ -1181,9 +1181,9 @@ void request_timer_fn(unsigned long data) ...@@ -1181,9 +1181,9 @@ void request_timer_fn(unsigned long data)
struct list_head *le; struct list_head *le;
unsigned long et = 0; /* effective timeout = ko_count * timeout */ unsigned long et = 0; /* effective timeout = ko_count * timeout */
if (get_net_conf(mdev)) { if (get_net_conf(mdev->tconn)) {
et = mdev->tconn->net_conf->timeout*HZ/10 * mdev->tconn->net_conf->ko_count; et = mdev->tconn->net_conf->timeout*HZ/10 * mdev->tconn->net_conf->ko_count;
put_net_conf(mdev); put_net_conf(mdev->tconn);
} }
if (!et || mdev->state.conn < C_WF_REPORT_PARAMS) if (!et || mdev->state.conn < C_WF_REPORT_PARAMS)
return; /* Recurring timer stopped */ return; /* Recurring timer stopped */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册