Commit d589a21e authored by Philipp Reisner's avatar Philipp Reisner

drbd: Enforce limits of disk_conf members; centralized these checks

Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent 9958c857
...@@ -937,9 +937,6 @@ static int drbd_check_al_size(struct drbd_conf *mdev, struct disk_conf *dc) ...@@ -937,9 +937,6 @@ static int drbd_check_al_size(struct drbd_conf *mdev, struct disk_conf *dc)
unsigned int in_use; unsigned int in_use;
int i; int i;
if (!expect(dc->al_extents >= DRBD_AL_EXTENTS_MIN))
dc->al_extents = DRBD_AL_EXTENTS_MIN;
if (mdev->act_log && if (mdev->act_log &&
mdev->act_log->nr_elements == dc->al_extents) mdev->act_log->nr_elements == dc->al_extents)
return 0; return 0;
...@@ -1102,6 +1099,17 @@ static bool should_set_defaults(struct genl_info *info) ...@@ -1102,6 +1099,17 @@ static bool should_set_defaults(struct genl_info *info)
return 0 != (flags & DRBD_GENL_F_SET_DEFAULTS); return 0 != (flags & DRBD_GENL_F_SET_DEFAULTS);
} }
static void enforce_disk_conf_limits(struct disk_conf *dc)
{
if (dc->al_extents < DRBD_AL_EXTENTS_MIN)
dc->al_extents = DRBD_AL_EXTENTS_MIN;
if (dc->al_extents > DRBD_AL_EXTENTS_MAX)
dc->al_extents = DRBD_AL_EXTENTS_MAX;
if (dc->c_plan_ahead > DRBD_C_PLAN_AHEAD_MAX)
dc->c_plan_ahead = DRBD_C_PLAN_AHEAD_MAX;
}
int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
{ {
enum drbd_ret_code retcode; enum drbd_ret_code retcode;
...@@ -1146,11 +1154,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) ...@@ -1146,11 +1154,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
if (!expect(new_disk_conf->resync_rate >= 1)) if (!expect(new_disk_conf->resync_rate >= 1))
new_disk_conf->resync_rate = 1; new_disk_conf->resync_rate = 1;
/* clip to allowed range */ enforce_disk_conf_limits(new_disk_conf);
if (!expect(new_disk_conf->al_extents >= DRBD_AL_EXTENTS_MIN))
new_disk_conf->al_extents = DRBD_AL_EXTENTS_MIN;
if (!expect(new_disk_conf->al_extents <= DRBD_AL_EXTENTS_MAX))
new_disk_conf->al_extents = DRBD_AL_EXTENTS_MAX;
fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ; fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ;
if (fifo_size != mdev->rs_plan_s->size) { if (fifo_size != mdev->rs_plan_s->size) {
...@@ -1273,6 +1277,8 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) ...@@ -1273,6 +1277,8 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
goto fail; goto fail;
} }
enforce_disk_conf_limits(new_disk_conf);
new_plan = fifo_alloc((new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ); new_plan = fifo_alloc((new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ);
if (!new_plan) { if (!new_plan) {
retcode = ERR_NOMEM; retcode = ERR_NOMEM;
...@@ -1450,8 +1456,6 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) ...@@ -1450,8 +1456,6 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
else else
clear_bit(MD_NO_FUA, &mdev->flags); clear_bit(MD_NO_FUA, &mdev->flags);
/* FIXME Missing stuff: clip al range */
/* Point of no return reached. /* Point of no return reached.
* Devices and memory are no longer released by error cleanup below. * Devices and memory are no longer released by error cleanup below.
* now mdev takes over responsibility, and the state engine should * now mdev takes over responsibility, and the state engine should
......
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