mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Philipp Reisner <philipp.reisner@linbit.com>
To: linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: drbd-dev@lists.linbit.com
Subject: [PATCH 09/15] drbd: Enforce limits of disk_conf members; centralized these checks
Date: Thu,  6 Oct 2011 15:37:54 +0200	[thread overview]
Message-ID: <1317908280-28951-10-git-send-email-philipp.reisner@linbit.com> (raw)
In-Reply-To: <1317908280-28951-1-git-send-email-philipp.reisner@linbit.com>

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
---
 drivers/block/drbd/drbd_nl.c |   24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index ad81227..6d05bf5 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -959,9 +959,6 @@ static int drbd_check_al_size(struct drbd_conf *mdev, struct disk_conf *dc)
 	unsigned int in_use;
 	int i;
 
-	if (!expect(dc->al_extents >= DRBD_AL_EXTENTS_MIN))
-		dc->al_extents = DRBD_AL_EXTENTS_MIN;
-
 	if (mdev->act_log &&
 	    mdev->act_log->nr_elements == dc->al_extents)
 		return 0;
@@ -1124,6 +1121,17 @@ static bool should_set_defaults(struct genl_info *info)
 	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)
 {
 	enum drbd_ret_code retcode;
@@ -1182,11 +1190,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
 	if (!expect(new_disk_conf->resync_rate >= 1))
 		new_disk_conf->resync_rate = 1;
 
-	/* clip to allowed range */
-	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;
+	enforce_disk_conf_limits(new_disk_conf);
 
 	fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ;
 	if (fifo_size != mdev->rs_plan_s->size) {
@@ -1309,6 +1313,8 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
 		goto fail;
 	}
 
+	enforce_disk_conf_limits(new_disk_conf);
+
 	new_plan = fifo_alloc((new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ);
 	if (!new_plan) {
 		retcode = ERR_NOMEM;
@@ -1486,8 +1492,6 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
 	else
 		clear_bit(MD_NO_FUA, &mdev->flags);
 
-	/* FIXME Missing stuff: clip al range */
-
 	/* Point of no return reached.
 	 * Devices and memory are no longer released by error cleanup below.
 	 * now mdev takes over responsibility, and the state engine should
-- 
1.7.4.1


  parent reply	other threads:[~2011-10-06 13:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-06 13:37 [RFC 00/15] drbd: part 15 of adding multiple volume support to drbd Philipp Reisner
2011-10-06 13:37 ` [PATCH 01/15] drbd: Removed dead code Philipp Reisner
2011-10-06 13:37 ` [PATCH 02/15] drbd: Renamed the net_conf_update mutex to conf_update Philipp Reisner
2011-10-06 13:37 ` [PATCH 03/15] drbd: drbd_dew_dev_size() gets the user requests disk_size as argument Philipp Reisner
2011-10-06 13:37 ` [PATCH 04/15] drbd: Split drbd_alter_sa() into drbd_sync_after_valid() and drbd_sync_after_changed() Philipp Reisner
2011-10-06 13:37 ` [PATCH 05/15] drbd: Renamed (old|new)_conf into (old|new)_net_conf in receive_SyncParam Philipp Reisner
2011-10-06 13:37 ` [PATCH 06/15] drbd: Introduce __s32_field in the genetlink macro magic Philipp Reisner
2011-10-06 13:37 ` [PATCH 07/15] drbd: RCU for disk_conf Philipp Reisner
2011-10-06 13:37 ` [PATCH 08/15] drbd: Made the fifo object a self contained object (preparing for RCU) Philipp Reisner
2011-10-06 13:37 ` Philipp Reisner [this message]
2011-10-06 13:37 ` [PATCH 10/15] drbd: RCU for rs_plan_s Philipp Reisner
2011-10-06 13:37 ` [PATCH 11/15] drbd: Convert boolean flags on netlink from NLA_FLAG to NLA_U8 Philipp Reisner
2011-10-06 13:37 ` [PATCH 12/15] drbd: Turn no-disk-flushes into disk-flushes={yes|no} Philipp Reisner
2011-10-06 13:37 ` [PATCH 13/15] drbd: Turn no-disk-drain into disk-drain={yes|no} Philipp Reisner
2011-10-06 13:37 ` [PATCH 14/15] drbd: Turn no-md-flushes into md-flushes={yes|no} Philipp Reisner
2011-10-06 13:38 ` [PATCH 15/15] drbd: Turn no-tcp-cork into tcp-cork={yes|no} Philipp Reisner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1317908280-28951-10-git-send-email-philipp.reisner@linbit.com \
    --to=philipp.reisner@linbit.com \
    --cc=axboe@kernel.dk \
    --cc=drbd-dev@lists.linbit.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®