提交 f399002e 编写于 作者: L Lars Ellenberg 提交者: Philipp Reisner

drbd: distribute former syncer_conf settings to disk, connection, and resource level

This commit breaks the API again.

Move per-volume former syncer options into disk_conf.
Move per-connection former syncer options into net_conf.
Renamed the remainign sync_conf to res_opts

Syncer settings have been changeable at runtime, so we need to prepare
for these settings to be runtime-changeable in their new home as well.

Introduce new configuration operations, and share the netlink attribute
between "attach" (create new disk) and "disk-opts" (change options).
Same for "connect" and "net-opts".

Some fields cannot be changed at runtime, however.
Introduce a new flag GENLA_F_INVARIANT to be able to trigger on that in
the generated validation and assignment functions.
Signed-off-by: NPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: NLars Ellenberg <lars.ellenberg@linbit.com>
上级 6b75dced
......@@ -860,7 +860,7 @@ struct drbd_md {
s32 bm_offset; /* signed relative sector offset to bitmap */
/* u32 al_nr_extents; important for restoring the AL
* is stored into sync_conf.al_extents, which in turn
* is stored into ldev->dc.al_extents, which in turn
* gets applied to act_log->nr_elements
*/
};
......@@ -929,6 +929,7 @@ struct drbd_tconn { /* is a resource from the config file */
atomic_t net_cnt; /* Users of net_conf */
wait_queue_head_t net_cnt_wait;
wait_queue_head_t ping_wait; /* Woken upon reception of a ping, and a state change */
struct res_opts res_opts;
struct drbd_socket data; /* data/barrier/cstate/parameter packets */
struct drbd_socket meta; /* ping/ack (metadata) packets */
......@@ -945,6 +946,8 @@ struct drbd_tconn { /* is a resource from the config file */
struct crypto_hash *cram_hmac_tfm;
struct crypto_hash *integrity_w_tfm; /* to be used by the worker thread */
struct crypto_hash *integrity_r_tfm; /* to be used by the receiver thread */
struct crypto_hash *csums_tfm;
struct crypto_hash *verify_tfm;
void *int_dig_out;
void *int_dig_in;
void *int_dig_vv;
......@@ -963,7 +966,6 @@ struct drbd_conf {
unsigned long flags;
/* configured by drbdsetup */
struct syncer_conf sync_conf;
struct drbd_backing_dev *ldev __protected_by(local);
sector_t p_size; /* partner's disk size */
......@@ -1037,8 +1039,6 @@ struct drbd_conf {
/* size of out-of-sync range in sectors. */
sector_t ov_last_oos_size;
unsigned long ov_left; /* in bits */
struct crypto_hash *csums_tfm;
struct crypto_hash *verify_tfm;
struct drbd_bitmap *bitmap;
unsigned long bm_resync_fo; /* bit offset for drbd_bm_find_next */
......@@ -1188,7 +1188,7 @@ extern int conn_send_cmd2(struct drbd_tconn *tconn, enum drbd_packet cmd,
char *data, size_t size);
#define USE_DATA_SOCKET 1
#define USE_META_SOCKET 0
extern int drbd_send_sync_param(struct drbd_conf *mdev, struct syncer_conf *sc);
extern int drbd_send_sync_param(struct drbd_conf *mdev);
extern int drbd_send_b_ack(struct drbd_conf *mdev, u32 barrier_nr,
u32 set_size);
extern int drbd_send_ack(struct drbd_conf *, enum drbd_packet,
......
......@@ -784,7 +784,7 @@ int conn_send_cmd2(struct drbd_tconn *tconn, enum drbd_packet cmd, char *data,
return ok;
}
int drbd_send_sync_param(struct drbd_conf *mdev, struct syncer_conf *sc)
int drbd_send_sync_param(struct drbd_conf *mdev)
{
struct p_rs_param_95 *p;
struct socket *sock;
......@@ -793,7 +793,7 @@ int drbd_send_sync_param(struct drbd_conf *mdev, struct syncer_conf *sc)
size = apv <= 87 ? sizeof(struct p_rs_param)
: apv == 88 ? sizeof(struct p_rs_param)
+ strlen(mdev->sync_conf.verify_alg) + 1
+ strlen(mdev->tconn->net_conf->verify_alg) + 1
: apv <= 94 ? sizeof(struct p_rs_param_89)
: /* apv >= 95 */ sizeof(struct p_rs_param_95);
......@@ -812,16 +812,25 @@ int drbd_send_sync_param(struct drbd_conf *mdev, struct syncer_conf *sc)
/* initialize verify_alg and csums_alg */
memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX);
p->rate = cpu_to_be32(sc->rate);
p->c_plan_ahead = cpu_to_be32(sc->c_plan_ahead);
p->c_delay_target = cpu_to_be32(sc->c_delay_target);
p->c_fill_target = cpu_to_be32(sc->c_fill_target);
p->c_max_rate = cpu_to_be32(sc->c_max_rate);
if (get_ldev(mdev)) {
p->rate = cpu_to_be32(mdev->ldev->dc.resync_rate);
p->c_plan_ahead = cpu_to_be32(mdev->ldev->dc.c_plan_ahead);
p->c_delay_target = cpu_to_be32(mdev->ldev->dc.c_delay_target);
p->c_fill_target = cpu_to_be32(mdev->ldev->dc.c_fill_target);
p->c_max_rate = cpu_to_be32(mdev->ldev->dc.c_max_rate);
put_ldev(mdev);
} else {
p->rate = cpu_to_be32(DRBD_RATE_DEF);
p->c_plan_ahead = cpu_to_be32(DRBD_C_PLAN_AHEAD_DEF);
p->c_delay_target = cpu_to_be32(DRBD_C_DELAY_TARGET_DEF);
p->c_fill_target = cpu_to_be32(DRBD_C_FILL_TARGET_DEF);
p->c_max_rate = cpu_to_be32(DRBD_C_MAX_RATE_DEF);
}
if (apv >= 88)
strcpy(p->verify_alg, mdev->sync_conf.verify_alg);
strcpy(p->verify_alg, mdev->tconn->net_conf->verify_alg);
if (apv >= 89)
strcpy(p->csums_alg, mdev->sync_conf.csums_alg);
strcpy(p->csums_alg, mdev->tconn->net_conf->csums_alg);
rv = _drbd_send_cmd(mdev, sock, cmd, &p->head, size, 0);
} else
......@@ -1043,7 +1052,7 @@ int fill_bitmap_rle_bits(struct drbd_conf *mdev,
int bits;
/* may we use this feature? */
if ((mdev->sync_conf.use_rle == 0) ||
if ((mdev->tconn->net_conf->use_rle == 0) ||
(mdev->tconn->agreed_pro_version < 90))
return 0;
......@@ -1790,26 +1799,8 @@ static int drbd_release(struct gendisk *gd, fmode_t mode)
static void drbd_set_defaults(struct drbd_conf *mdev)
{
/* This way we get a compile error when sync_conf grows,
and we forgot to initialize it here */
mdev->sync_conf = (struct syncer_conf) {
/* .rate = */ DRBD_RATE_DEF,
/* .after = */ DRBD_AFTER_DEF,
/* .al_extents = */ DRBD_AL_EXTENTS_DEF,
/* .verify_alg = */ {}, 0,
/* .cpu_mask = */ {}, 0,
/* .csums_alg = */ {}, 0,
/* .use_rle = */ 0,
/* .on_no_data = */ DRBD_ON_NO_DATA_DEF,
/* .c_plan_ahead = */ DRBD_C_PLAN_AHEAD_DEF,
/* .c_delay_target = */ DRBD_C_DELAY_TARGET_DEF,
/* .c_fill_target = */ DRBD_C_FILL_TARGET_DEF,
/* .c_max_rate = */ DRBD_C_MAX_RATE_DEF,
/* .c_min_rate = */ DRBD_C_MIN_RATE_DEF
};
/* Have to use that way, because the layout differs between
big endian and little endian */
/* Beware! The actual layout differs
* between big endian and little endian */
mdev->state = (union drbd_state) {
{ .role = R_SECONDARY,
.peer = R_UNKNOWN,
......@@ -2286,6 +2277,11 @@ struct drbd_tconn *drbd_new_tconn(const char *name)
drbd_thread_init(tconn, &tconn->worker, drbd_worker, "worker");
drbd_thread_init(tconn, &tconn->asender, drbd_asender, "asender");
tconn->res_opts = (struct res_opts) {
{}, 0, /* cpu_mask */
DRBD_ON_NO_DATA_DEF, /* on_no_data */
};
mutex_lock(&drbd_cfg_mutex);
list_add_tail(&tconn->all_tconn, &drbd_tconns);
mutex_unlock(&drbd_cfg_mutex);
......@@ -2559,10 +2555,10 @@ void drbd_free_sock(struct drbd_tconn *tconn)
void drbd_free_resources(struct drbd_conf *mdev)
{
crypto_free_hash(mdev->csums_tfm);
mdev->csums_tfm = NULL;
crypto_free_hash(mdev->verify_tfm);
mdev->verify_tfm = NULL;
crypto_free_hash(mdev->tconn->csums_tfm);
mdev->tconn->csums_tfm = NULL;
crypto_free_hash(mdev->tconn->verify_tfm);
mdev->tconn->verify_tfm = NULL;
crypto_free_hash(mdev->tconn->cram_hmac_tfm);
mdev->tconn->cram_hmac_tfm = NULL;
crypto_free_hash(mdev->tconn->integrity_w_tfm);
......@@ -2589,7 +2585,7 @@ struct meta_data_on_disk {
u32 md_size_sect;
u32 al_offset; /* offset to this block */
u32 al_nr_extents; /* important for restoring the AL */
/* `-- act_log->nr_elements <-- sync_conf.al_extents */
/* `-- act_log->nr_elements <-- ldev->dc.al_extents */
u32 bm_offset; /* offset to the bitmap, from here */
u32 bm_bytes_per_bit; /* BM_BLOCK_SIZE */
u32 la_peer_max_bio_size; /* last peer max_bio_size */
......@@ -2715,7 +2711,7 @@ int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev)
for (i = UI_CURRENT; i < UI_SIZE; i++)
bdev->md.uuid[i] = be64_to_cpu(buffer->uuid[i]);
bdev->md.flags = be32_to_cpu(buffer->flags);
mdev->sync_conf.al_extents = be32_to_cpu(buffer->al_nr_extents);
bdev->dc.al_extents = be32_to_cpu(buffer->al_nr_extents);
bdev->md.device_uuid = be64_to_cpu(buffer->device_uuid);
spin_lock_irq(&mdev->tconn->req_lock);
......@@ -2727,8 +2723,8 @@ int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev)
}
spin_unlock_irq(&mdev->tconn->req_lock);
if (mdev->sync_conf.al_extents < 7)
mdev->sync_conf.al_extents = 127;
if (bdev->dc.al_extents < 7)
bdev->dc.al_extents = 127;
err:
mutex_unlock(&mdev->md_io_mutex);
......
此差异已折叠。
......@@ -763,7 +763,7 @@ int drbd_connected(int vnr, void *p, void *data)
&mdev->tconn->cstate_mutex :
&mdev->own_state_mutex;
ok &= drbd_send_sync_param(mdev, &mdev->sync_conf);
ok &= drbd_send_sync_param(mdev);
ok &= drbd_send_sizes(mdev, 0, 0);
ok &= drbd_send_uuids(mdev);
ok &= drbd_send_state(mdev);
......@@ -2085,7 +2085,7 @@ int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector)
int throttle = 0;
/* feature disabled? */
if (mdev->sync_conf.c_min_rate == 0)
if (mdev->ldev->dc.c_min_rate == 0)
return 0;
spin_lock_irq(&mdev->al_lock);
......@@ -2125,7 +2125,7 @@ int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector)
db = mdev->rs_mark_left[i] - rs_left;
dbdt = Bit2KB(db/dt);
if (dbdt > mdev->sync_conf.c_min_rate)
if (dbdt > mdev->ldev->dc.c_min_rate)
throttle = 1;
}
return throttle;
......@@ -3001,7 +3001,10 @@ static int receive_SyncParam(struct drbd_conf *mdev, enum drbd_packet cmd,
if (drbd_recv(mdev->tconn, &p->head.payload, header_size) != header_size)
return false;
mdev->sync_conf.rate = be32_to_cpu(p->rate);
if (get_ldev(mdev)) {
mdev->ldev->dc.resync_rate = be32_to_cpu(p->rate);
put_ldev(mdev);
}
if (apv >= 88) {
if (apv == 88) {
......@@ -3029,10 +3032,10 @@ static int receive_SyncParam(struct drbd_conf *mdev, enum drbd_packet cmd,
p->csums_alg[SHARED_SECRET_MAX-1] = 0;
}
if (strcmp(mdev->sync_conf.verify_alg, p->verify_alg)) {
if (strcmp(mdev->tconn->net_conf->verify_alg, p->verify_alg)) {
if (mdev->state.conn == C_WF_REPORT_PARAMS) {
dev_err(DEV, "Different verify-alg settings. me=\"%s\" peer=\"%s\"\n",
mdev->sync_conf.verify_alg, p->verify_alg);
mdev->tconn->net_conf->verify_alg, p->verify_alg);
goto disconnect;
}
verify_tfm = drbd_crypto_alloc_digest_safe(mdev,
......@@ -3043,10 +3046,10 @@ static int receive_SyncParam(struct drbd_conf *mdev, enum drbd_packet cmd,
}
}
if (apv >= 89 && strcmp(mdev->sync_conf.csums_alg, p->csums_alg)) {
if (apv >= 89 && strcmp(mdev->tconn->net_conf->csums_alg, p->csums_alg)) {
if (mdev->state.conn == C_WF_REPORT_PARAMS) {
dev_err(DEV, "Different csums-alg settings. me=\"%s\" peer=\"%s\"\n",
mdev->sync_conf.csums_alg, p->csums_alg);
mdev->tconn->net_conf->csums_alg, p->csums_alg);
goto disconnect;
}
csums_tfm = drbd_crypto_alloc_digest_safe(mdev,
......@@ -3057,37 +3060,39 @@ static int receive_SyncParam(struct drbd_conf *mdev, enum drbd_packet cmd,
}
}
if (apv > 94) {
mdev->sync_conf.rate = be32_to_cpu(p->rate);
mdev->sync_conf.c_plan_ahead = be32_to_cpu(p->c_plan_ahead);
mdev->sync_conf.c_delay_target = be32_to_cpu(p->c_delay_target);
mdev->sync_conf.c_fill_target = be32_to_cpu(p->c_fill_target);
mdev->sync_conf.c_max_rate = be32_to_cpu(p->c_max_rate);
if (apv > 94 && get_ldev(mdev)) {
mdev->ldev->dc.resync_rate = be32_to_cpu(p->rate);
mdev->ldev->dc.c_plan_ahead = be32_to_cpu(p->c_plan_ahead);
mdev->ldev->dc.c_delay_target = be32_to_cpu(p->c_delay_target);
mdev->ldev->dc.c_fill_target = be32_to_cpu(p->c_fill_target);
mdev->ldev->dc.c_max_rate = be32_to_cpu(p->c_max_rate);
fifo_size = (mdev->sync_conf.c_plan_ahead * 10 * SLEEP_TIME) / HZ;
fifo_size = (mdev->ldev->dc.c_plan_ahead * 10 * SLEEP_TIME) / HZ;
if (fifo_size != mdev->rs_plan_s.size && fifo_size > 0) {
rs_plan_s = kzalloc(sizeof(int) * fifo_size, GFP_KERNEL);
if (!rs_plan_s) {
dev_err(DEV, "kmalloc of fifo_buffer failed");
put_ldev(mdev);
goto disconnect;
}
}
put_ldev(mdev);
}
spin_lock(&mdev->peer_seq_lock);
/* lock against drbd_nl_syncer_conf() */
if (verify_tfm) {
strcpy(mdev->sync_conf.verify_alg, p->verify_alg);
mdev->sync_conf.verify_alg_len = strlen(p->verify_alg) + 1;
crypto_free_hash(mdev->verify_tfm);
mdev->verify_tfm = verify_tfm;
strcpy(mdev->tconn->net_conf->verify_alg, p->verify_alg);
mdev->tconn->net_conf->verify_alg_len = strlen(p->verify_alg) + 1;
crypto_free_hash(mdev->tconn->verify_tfm);
mdev->tconn->verify_tfm = verify_tfm;
dev_info(DEV, "using verify-alg: \"%s\"\n", p->verify_alg);
}
if (csums_tfm) {
strcpy(mdev->sync_conf.csums_alg, p->csums_alg);
mdev->sync_conf.csums_alg_len = strlen(p->csums_alg) + 1;
crypto_free_hash(mdev->csums_tfm);
mdev->csums_tfm = csums_tfm;
strcpy(mdev->tconn->net_conf->csums_alg, p->csums_alg);
mdev->tconn->net_conf->csums_alg_len = strlen(p->csums_alg) + 1;
crypto_free_hash(mdev->tconn->csums_tfm);
mdev->tconn->csums_tfm = csums_tfm;
dev_info(DEV, "using csums-alg: \"%s\"\n", p->csums_alg);
}
if (fifo_size != mdev->rs_plan_s.size) {
......
......@@ -402,7 +402,7 @@ is_valid_state(struct drbd_conf *mdev, union drbd_state ns)
rv = SS_CONNECTED_OUTDATES;
else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
(mdev->sync_conf.verify_alg[0] == 0))
(mdev->tconn->net_conf->verify_alg[0] == 0))
rv = SS_NO_VERIFY_ALG;
else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
......@@ -668,7 +668,7 @@ static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state
(ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.pdsk > D_OUTDATED))
ns.susp_fen = 1; /* Suspend IO while fence-peer handler runs (peer lost) */
if (mdev->sync_conf.on_no_data == OND_SUSPEND_IO &&
if (mdev->tconn->res_opts.on_no_data == OND_SUSPEND_IO &&
(ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE))
ns.susp_nod = 1; /* Suspend IO while no data available (no accessible data available) */
......
......@@ -310,12 +310,12 @@ static int w_e_send_csum(struct drbd_work *w, int cancel)
if (unlikely((peer_req->flags & EE_WAS_ERROR) != 0))
goto out;
digest_size = crypto_hash_digestsize(mdev->csums_tfm);
digest_size = crypto_hash_digestsize(mdev->tconn->csums_tfm);
digest = kmalloc(digest_size, GFP_NOIO);
if (digest) {
sector_t sector = peer_req->i.sector;
unsigned int size = peer_req->i.size;
drbd_csum_ee(mdev, mdev->csums_tfm, peer_req, digest);
drbd_csum_ee(mdev, mdev->tconn->csums_tfm, peer_req, digest);
/* Free peer_req and pages before send.
* In case we block on congestion, we could otherwise run into
* some distributed deadlock, if the other side blocks on
......@@ -451,13 +451,13 @@ static int drbd_rs_controller(struct drbd_conf *mdev)
spin_lock(&mdev->peer_seq_lock); /* get an atomic view on mdev->rs_plan_s */
steps = mdev->rs_plan_s.size; /* (mdev->sync_conf.c_plan_ahead * 10 * SLEEP_TIME) / HZ; */
steps = mdev->rs_plan_s.size; /* (mdev->ldev->dc.c_plan_ahead * 10 * SLEEP_TIME) / HZ; */
if (mdev->rs_in_flight + sect_in == 0) { /* At start of resync */
want = ((mdev->sync_conf.rate * 2 * SLEEP_TIME) / HZ) * steps;
want = ((mdev->ldev->dc.resync_rate * 2 * SLEEP_TIME) / HZ) * steps;
} else { /* normal path */
want = mdev->sync_conf.c_fill_target ? mdev->sync_conf.c_fill_target :
sect_in * mdev->sync_conf.c_delay_target * HZ / (SLEEP_TIME * 10);
want = mdev->ldev->dc.c_fill_target ? mdev->ldev->dc.c_fill_target :
sect_in * mdev->ldev->dc.c_delay_target * HZ / (SLEEP_TIME * 10);
}
correction = want - mdev->rs_in_flight - mdev->rs_planed;
......@@ -476,7 +476,7 @@ static int drbd_rs_controller(struct drbd_conf *mdev)
if (req_sect < 0)
req_sect = 0;
max_sect = (mdev->sync_conf.c_max_rate * 2 * SLEEP_TIME) / HZ;
max_sect = (mdev->ldev->dc.c_max_rate * 2 * SLEEP_TIME) / HZ;
if (req_sect > max_sect)
req_sect = max_sect;
......@@ -492,11 +492,11 @@ static int drbd_rs_controller(struct drbd_conf *mdev)
static int drbd_rs_number_requests(struct drbd_conf *mdev)
{
int number;
if (mdev->rs_plan_s.size) { /* mdev->sync_conf.c_plan_ahead */
if (mdev->rs_plan_s.size) { /* mdev->ldev->dc.c_plan_ahead */
number = drbd_rs_controller(mdev) >> (BM_BLOCK_SHIFT - 9);
mdev->c_sync_rate = number * HZ * (BM_BLOCK_SIZE / 1024) / SLEEP_TIME;
} else {
mdev->c_sync_rate = mdev->sync_conf.rate;
mdev->c_sync_rate = mdev->ldev->dc.resync_rate;
number = SLEEP_TIME * mdev->c_sync_rate / ((BM_BLOCK_SIZE / 1024) * HZ);
}
......@@ -619,7 +619,7 @@ static int w_make_resync_request(struct drbd_work *w, int cancel)
/* adjust very last sectors, in case we are oddly sized */
if (sector + (size>>9) > capacity)
size = (capacity-sector)<<9;
if (mdev->tconn->agreed_pro_version >= 89 && mdev->csums_tfm) {
if (mdev->tconn->agreed_pro_version >= 89 && mdev->tconn->csums_tfm) {
switch (read_for_csum(mdev, sector, size)) {
case -EIO: /* Disk failure */
put_ldev(mdev);
......@@ -810,7 +810,7 @@ int drbd_resync_finished(struct drbd_conf *mdev)
if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T)
khelper_cmd = "after-resync-target";
if (mdev->csums_tfm && mdev->rs_total) {
if (mdev->tconn->csums_tfm && mdev->rs_total) {
const unsigned long s = mdev->rs_same_csum;
const unsigned long t = mdev->rs_total;
const int ratio =
......@@ -1019,13 +1019,13 @@ int w_e_end_csum_rs_req(struct drbd_work *w, int cancel)
/* quick hack to try to avoid a race against reconfiguration.
* a real fix would be much more involved,
* introducing more locking mechanisms */
if (mdev->csums_tfm) {
digest_size = crypto_hash_digestsize(mdev->csums_tfm);
if (mdev->tconn->csums_tfm) {
digest_size = crypto_hash_digestsize(mdev->tconn->csums_tfm);
D_ASSERT(digest_size == di->digest_size);
digest = kmalloc(digest_size, GFP_NOIO);
}
if (digest) {
drbd_csum_ee(mdev, mdev->csums_tfm, peer_req, digest);
drbd_csum_ee(mdev, mdev->tconn->csums_tfm, peer_req, digest);
eq = !memcmp(digest, di->digest, digest_size);
kfree(digest);
}
......@@ -1069,7 +1069,7 @@ int w_e_end_ov_req(struct drbd_work *w, int cancel)
if (unlikely(cancel))
goto out;
digest_size = crypto_hash_digestsize(mdev->verify_tfm);
digest_size = crypto_hash_digestsize(mdev->tconn->verify_tfm);
digest = kmalloc(digest_size, GFP_NOIO);
if (!digest) {
ok = 0; /* terminate the connection in case the allocation failed */
......@@ -1077,7 +1077,7 @@ int w_e_end_ov_req(struct drbd_work *w, int cancel)
}
if (likely(!(peer_req->flags & EE_WAS_ERROR)))
drbd_csum_ee(mdev, mdev->verify_tfm, peer_req, digest);
drbd_csum_ee(mdev, mdev->tconn->verify_tfm, peer_req, digest);
else
memset(digest, 0, digest_size);
......@@ -1141,10 +1141,10 @@ int w_e_end_ov_reply(struct drbd_work *w, int cancel)
di = peer_req->digest;
if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) {
digest_size = crypto_hash_digestsize(mdev->verify_tfm);
digest_size = crypto_hash_digestsize(mdev->tconn->verify_tfm);
digest = kmalloc(digest_size, GFP_NOIO);
if (digest) {
drbd_csum_ee(mdev, mdev->verify_tfm, peer_req, digest);
drbd_csum_ee(mdev, mdev->tconn->verify_tfm, peer_req, digest);
D_ASSERT(digest_size == di->digest_size);
eq = !memcmp(digest, di->digest, digest_size);
......@@ -1319,9 +1319,9 @@ static int _drbd_may_sync_now(struct drbd_conf *mdev)
struct drbd_conf *odev = mdev;
while (1) {
if (odev->sync_conf.after == -1)
if (odev->ldev->dc.resync_after == -1)
return 1;
odev = minor_to_mdev(odev->sync_conf.after);
odev = minor_to_mdev(odev->ldev->dc.resync_after);
if (!expect(odev))
return 1;
if ((odev->state.conn >= C_SYNC_SOURCE &&
......@@ -1408,11 +1408,11 @@ static int sync_after_error(struct drbd_conf *mdev, int o_minor)
return ERR_SYNC_AFTER_CYCLE;
/* dependency chain ends here, no cycles. */
if (odev->sync_conf.after == -1)
if (odev->ldev->dc.resync_after == -1)
return NO_ERROR;
/* follow the dependency chain */
odev = minor_to_mdev(odev->sync_conf.after);
odev = minor_to_mdev(odev->ldev->dc.resync_after);
}
}
......@@ -1424,7 +1424,7 @@ int drbd_alter_sa(struct drbd_conf *mdev, int na)
write_lock_irq(&global_state_lock);
retcode = sync_after_error(mdev, na);
if (retcode == NO_ERROR) {
mdev->sync_conf.after = na;
mdev->ldev->dc.resync_after = na;
do {
changes = _drbd_pause_after(mdev);
changes |= _drbd_resume_next(mdev);
......@@ -1637,7 +1637,7 @@ int drbd_worker(struct drbd_thread *thi)
struct drbd_work *w = NULL;
struct drbd_conf *mdev;
LIST_HEAD(work_list);
int minor, intr = 0;
int vnr, intr = 0;
while (get_t_state(thi) == RUNNING) {
drbd_thread_current_set_cpu(thi);
......@@ -1722,7 +1722,7 @@ int drbd_worker(struct drbd_thread *thi)
spin_unlock_irq(&tconn->data.work.q_lock);
drbd_thread_stop(&tconn->receiver);
idr_for_each_entry(&tconn->volumes, mdev, minor) {
idr_for_each_entry(&tconn->volumes, mdev, vnr) {
D_ASSERT(mdev->state.disk == D_DISKLESS && mdev->state.conn == C_STANDALONE);
/* _drbd_set_state only uses stop_nowait.
* wait here for the exiting receiver. */
......
......@@ -102,66 +102,73 @@ GENL_struct(DRBD_NLA_CFG_CONTEXT, 2, drbd_cfg_context,
)
GENL_struct(DRBD_NLA_DISK_CONF, 3, disk_conf,
__u64_field(1, GENLA_F_MANDATORY, disk_size)
__str_field(2, GENLA_F_REQUIRED, backing_dev, 128)
__str_field(3, GENLA_F_REQUIRED, meta_dev, 128)
__u32_field(4, GENLA_F_REQUIRED, meta_dev_idx)
__u32_field(5, GENLA_F_MANDATORY, max_bio_bvecs)
__str_field(1, GENLA_F_REQUIRED | GENLA_F_INVARIANT, backing_dev, 128)
__str_field(2, GENLA_F_REQUIRED | GENLA_F_INVARIANT, meta_dev, 128)
__u32_field(3, GENLA_F_REQUIRED | GENLA_F_INVARIANT, meta_dev_idx)
/* use the resize command to try and change the disk_size */
__u64_field(4, GENLA_F_MANDATORY | GENLA_F_INVARIANT, disk_size)
/* we could change the max_bio_bvecs,
* but it won't propagate through the stack */
__u32_field(5, GENLA_F_MANDATORY | GENLA_F_INVARIANT, max_bio_bvecs)
__u32_field(6, GENLA_F_MANDATORY, on_io_error)
__u32_field(7, GENLA_F_MANDATORY, fencing)
__flg_field(8, GENLA_F_MANDATORY, no_disk_barrier)
__flg_field(9, GENLA_F_MANDATORY, no_disk_flush)
__flg_field(10, GENLA_F_MANDATORY, no_disk_drain)
__flg_field(11, GENLA_F_MANDATORY, no_md_flush)
__flg_field(12, GENLA_F_MANDATORY, use_bmbv)
__u32_field(8, GENLA_F_MANDATORY, resync_rate)
__u32_field(9, GENLA_F_MANDATORY, resync_after)
__u32_field(10, GENLA_F_MANDATORY, al_extents)
__u32_field(11, GENLA_F_MANDATORY, c_plan_ahead)
__u32_field(12, GENLA_F_MANDATORY, c_delay_target)
__u32_field(13, GENLA_F_MANDATORY, c_fill_target)
__u32_field(14, GENLA_F_MANDATORY, c_max_rate)
__u32_field(15, GENLA_F_MANDATORY, c_min_rate)
__flg_field(16, GENLA_F_MANDATORY, no_disk_barrier)
__flg_field(17, GENLA_F_MANDATORY, no_disk_flush)
__flg_field(18, GENLA_F_MANDATORY, no_disk_drain)
__flg_field(19, GENLA_F_MANDATORY, no_md_flush)
)
GENL_struct(DRBD_NLA_SYNCER_CONF, 4, syncer_conf,
__u32_field(1, GENLA_F_MANDATORY, rate)
__u32_field(2, GENLA_F_MANDATORY, after)
__u32_field(3, GENLA_F_MANDATORY, al_extents)
__str_field(4, GENLA_F_MANDATORY, cpu_mask, 32)
__str_field(5, GENLA_F_MANDATORY, verify_alg, SHARED_SECRET_MAX)
__str_field(6, GENLA_F_MANDATORY, csums_alg, SHARED_SECRET_MAX)
__flg_field(7, GENLA_F_MANDATORY, use_rle)
__u32_field(8, GENLA_F_MANDATORY, on_no_data)
__u32_field(9, GENLA_F_MANDATORY, c_plan_ahead)
__u32_field(10, GENLA_F_MANDATORY, c_delay_target)
__u32_field(11, GENLA_F_MANDATORY, c_fill_target)
__u32_field(12, GENLA_F_MANDATORY, c_max_rate)
__u32_field(13, GENLA_F_MANDATORY, c_min_rate)
GENL_struct(DRBD_NLA_RESOURCE_OPTS, 4, res_opts,
__str_field(1, GENLA_F_MANDATORY, cpu_mask, 32)
__u32_field(2, GENLA_F_MANDATORY, on_no_data)
)
GENL_struct(DRBD_NLA_NET_CONF, 5, net_conf,
__str_field(1, GENLA_F_MANDATORY | GENLA_F_SENSITIVE,
__bin_field(1, GENLA_F_REQUIRED | GENLA_F_INVARIANT, my_addr, 128)
__bin_field(2, GENLA_F_REQUIRED | GENLA_F_INVARIANT, peer_addr, 128)
__str_field(3, GENLA_F_MANDATORY | GENLA_F_SENSITIVE,
shared_secret, SHARED_SECRET_MAX)
__str_field(2, GENLA_F_MANDATORY, cram_hmac_alg, SHARED_SECRET_MAX)
__str_field(3, GENLA_F_MANDATORY, integrity_alg, SHARED_SECRET_MAX)
__str_field(4, GENLA_F_REQUIRED, my_addr, 128)
__str_field(5, GENLA_F_REQUIRED, peer_addr, 128)
__u32_field(6, GENLA_F_REQUIRED, wire_protocol)
__u32_field(7, GENLA_F_MANDATORY, try_connect_int)
__u32_field(8, GENLA_F_MANDATORY, timeout)
__u32_field(9, GENLA_F_MANDATORY, ping_int)
__u32_field(10, GENLA_F_MANDATORY, ping_timeo)
__u32_field(11, GENLA_F_MANDATORY, sndbuf_size)
__u32_field(12, GENLA_F_MANDATORY, rcvbuf_size)
__u32_field(13, GENLA_F_MANDATORY, ko_count)
__u32_field(14, GENLA_F_MANDATORY, max_buffers)
__u32_field(15, GENLA_F_MANDATORY, max_epoch_size)
__u32_field(16, GENLA_F_MANDATORY, unplug_watermark)
__u32_field(17, GENLA_F_MANDATORY, after_sb_0p)
__u32_field(18, GENLA_F_MANDATORY, after_sb_1p)
__u32_field(19, GENLA_F_MANDATORY, after_sb_2p)
__u32_field(20, GENLA_F_MANDATORY, rr_conflict)
__u32_field(21, GENLA_F_MANDATORY, on_congestion)
__u32_field(22, GENLA_F_MANDATORY, cong_fill)
__u32_field(23, GENLA_F_MANDATORY, cong_extents)
__flg_field(24, GENLA_F_MANDATORY, two_primaries)
__flg_field(25, GENLA_F_MANDATORY, want_lose)
__flg_field(26, GENLA_F_MANDATORY, no_cork)
__flg_field(27, GENLA_F_MANDATORY, always_asbp)
__flg_field(28, GENLA_F_MANDATORY, dry_run)
__str_field(4, GENLA_F_MANDATORY, cram_hmac_alg, SHARED_SECRET_MAX)
__str_field(5, GENLA_F_MANDATORY, integrity_alg, SHARED_SECRET_MAX)
__str_field(6, GENLA_F_MANDATORY, verify_alg, SHARED_SECRET_MAX)
__str_field(7, GENLA_F_MANDATORY, csums_alg, SHARED_SECRET_MAX)
__u32_field(8, GENLA_F_MANDATORY, wire_protocol)
__u32_field(9, GENLA_F_MANDATORY, try_connect_int)
__u32_field(10, GENLA_F_MANDATORY, timeout)
__u32_field(11, GENLA_F_MANDATORY, ping_int)
__u32_field(12, GENLA_F_MANDATORY, ping_timeo)
__u32_field(13, GENLA_F_MANDATORY, sndbuf_size)
__u32_field(14, GENLA_F_MANDATORY, rcvbuf_size)
__u32_field(15, GENLA_F_MANDATORY, ko_count)
__u32_field(16, GENLA_F_MANDATORY, max_buffers)
__u32_field(17, GENLA_F_MANDATORY, max_epoch_size)
__u32_field(18, GENLA_F_MANDATORY, unplug_watermark)
__u32_field(19, GENLA_F_MANDATORY, after_sb_0p)
__u32_field(20, GENLA_F_MANDATORY, after_sb_1p)
__u32_field(21, GENLA_F_MANDATORY, after_sb_2p)
__u32_field(22, GENLA_F_MANDATORY, rr_conflict)
__u32_field(23, GENLA_F_MANDATORY, on_congestion)
__u32_field(24, GENLA_F_MANDATORY, cong_fill)
__u32_field(25, GENLA_F_MANDATORY, cong_extents)
__flg_field(26, GENLA_F_MANDATORY, two_primaries)
__flg_field(27, GENLA_F_MANDATORY | GENLA_F_INVARIANT, want_lose)
__flg_field(28, GENLA_F_MANDATORY, no_cork)
__flg_field(29, GENLA_F_MANDATORY, always_asbp)
__flg_field(30, GENLA_F_MANDATORY | GENLA_F_INVARIANT, dry_run)
__flg_field(31, GENLA_F_MANDATORY, use_rle)
)
GENL_struct(DRBD_NLA_SET_ROLE_PARMS, 6, set_role_parms,
......@@ -270,11 +277,10 @@ GENL_op(DRBD_ADM_ADD_LINK, 7, GENL_doit(drbd_adm_create_connection),
GENL_op(DRBD_ADM_DEL_LINK, 8, GENL_doit(drbd_adm_delete_connection),
GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
/* operates on replication links */
GENL_op(DRBD_ADM_SYNCER, 9,
GENL_doit(drbd_adm_syncer),
GENL_op(DRBD_ADM_RESOURCE_OPTS, 9,
GENL_doit(drbd_adm_resource_opts),
GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
GENL_tla_expected(DRBD_NLA_SYNCER_CONF, GENLA_F_MANDATORY)
GENL_tla_expected(DRBD_NLA_RESOURCE_OPTS, GENLA_F_MANDATORY)
)
GENL_op(
......@@ -284,16 +290,28 @@ GENL_op(
GENL_tla_expected(DRBD_NLA_NET_CONF, GENLA_F_REQUIRED)
)
GENL_op(
DRBD_ADM_CHG_NET_OPTS, 29,
GENL_doit(drbd_adm_net_opts),
GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
GENL_tla_expected(DRBD_NLA_NET_CONF, GENLA_F_REQUIRED)
)
GENL_op(DRBD_ADM_DISCONNECT, 11, GENL_doit(drbd_adm_disconnect),
GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED))
/* operates on minors */
GENL_op(DRBD_ADM_ATTACH, 12,
GENL_doit(drbd_adm_attach),
GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
GENL_tla_expected(DRBD_NLA_DISK_CONF, GENLA_F_REQUIRED)
)
GENL_op(DRBD_ADM_CHG_DISK_OPTS, 28,
GENL_doit(drbd_adm_disk_opts),
GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, GENLA_F_REQUIRED)
GENL_tla_expected(DRBD_NLA_DISK_OPTS, GENLA_F_REQUIRED)
)
GENL_op(
DRBD_ADM_RESIZE, 13,
GENL_doit(drbd_adm_resize),
......@@ -301,7 +319,6 @@ GENL_op(
GENL_tla_expected(DRBD_NLA_RESIZE_PARMS, GENLA_F_MANDATORY)
)
/* operates on all volumes within a resource */
GENL_op(
DRBD_ADM_PRIMARY, 14,
GENL_doit(drbd_adm_set_role),
......
......@@ -166,5 +166,7 @@
#define DRBD_CONG_EXTENTS_MAX DRBD_AL_EXTENTS_MAX
#define DRBD_CONG_EXTENTS_DEF DRBD_AL_EXTENTS_DEF
#define DRBD_PROTOCOL_DEF DRBD_PROT_C
#undef RANGE
#endif
......@@ -190,11 +190,12 @@ static struct nlattr *nested_attr_tb[128];
#undef GENL_struct
#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
/* static, potentially unused */ \
int s_name ## _from_attrs(struct s_name *s, struct nlattr *tb[]) \
/* *_from_attrs functions are static, but potentially unused */ \
static int __ ## s_name ## _from_attrs(struct s_name *s, \
struct genl_info *info, bool exclude_invariants) \
{ \
const int maxtype = ARRAY_SIZE(s_name ## _nl_policy)-1; \
struct nlattr *tla = tb[tag_number]; \
struct nlattr *tla = info->attrs[tag_number]; \
struct nlattr **ntb = nested_attr_tb; \
struct nlattr *nla; \
int err; \
......@@ -211,33 +212,49 @@ int s_name ## _from_attrs(struct s_name *s, struct nlattr *tb[]) \
\
s_fields \
return 0; \
}
} __attribute__((unused)) \
static int s_name ## _from_attrs(struct s_name *s, \
struct genl_info *info) \
{ \
return __ ## s_name ## _from_attrs(s, info, false); \
} __attribute__((unused)) \
static int s_name ## _from_attrs_for_change(struct s_name *s, \
struct genl_info *info) \
{ \
return __ ## s_name ## _from_attrs(s, info, true); \
} __attribute__((unused)) \
#undef __field
#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) \
#define __assign(attr_nr, attr_flag, name, nla_type, type, assignment...) \
nla = ntb[__nla_type(attr_nr)]; \
if (nla) { \
if (s) \
s->name = __get(nla); \
DPRINT_FIELD("<<", nla_type, name, s, nla); \
if (exclude_invariants && ((attr_flag) & GENLA_F_INVARIANT)) { \
pr_info("<< must not change invariant attr: %s\n", #name); \
return -EEXIST; \
} \
assignment; \
} else if (exclude_invariants && ((attr_flag) & GENLA_F_INVARIANT)) { \
/* attribute missing from payload, */ \
/* which was expected */ \
} else if ((attr_flag) & GENLA_F_REQUIRED) { \
pr_info("<< missing attr: %s\n", #name); \
return -ENOMSG; \
}
#undef __field
#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put) \
__assign(attr_nr, attr_flag, name, nla_type, type, \
if (s) \
s->name = __get(nla); \
DPRINT_FIELD("<<", nla_type, name, s, nla))
/* validate_nla() already checked nla_len <= maxlen appropriately. */
#undef __array
#define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, __get, __put) \
nla = ntb[__nla_type(attr_nr)]; \
if (nla) { \
__assign(attr_nr, attr_flag, name, nla_type, type, \
if (s) \
s->name ## _len = \
__get(s->name, nla, maxlen); \
DPRINT_ARRAY("<<", nla_type, name, s, nla); \
} else if ((attr_flag) & GENLA_F_REQUIRED) { \
pr_info("<< missing attr: %s\n", #name); \
return -ENOMSG; \
} \
DPRINT_ARRAY("<<", nla_type, name, s, nla))
#include GENL_MAGIC_INCLUDE_FILE
......
......@@ -59,12 +59,20 @@ enum {
GENLA_F_MANDATORY = 1 << 14,
GENLA_F_REQUIRED = 1 << 15,
/* This will not be present in the __u16 .nla_type, but can be
* triggered on in <struct>_to_skb, to exclude "sensitive"
* information from broadcasts, or on unpriviledged get requests.
* This is useful because genetlink multicast groups can be listened in
* on by anyone. */
/* Below will not be present in the __u16 .nla_type, but can be
* triggered on in <struct>_to_skb resp. <struct>_from_attrs */
/* To exclude "sensitive" information from broadcasts, or on
* unpriviledged get requests. This is useful because genetlink
* multicast groups can be listened in on by anyone. */
GENLA_F_SENSITIVE = 1 << 16,
/* INVARIAN options cannot be changed at runtime.
* Useful to share an attribute policy and struct definition,
* between some "create" and "change" commands,
* but disallow certain fields to be changed online.
*/
GENLA_F_INVARIANT = 1 << 17,
};
#define __nla_type(x) ((__u16)((__u16)(x) & (__u16)NLA_TYPE_MASK))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册