Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp306719pxu; Fri, 23 Oct 2020 00:52:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyA8s8j5MhTJ9o0SVF3k2+2Xti117pxlYgY6z4SbUlakJFnXa2q5OI+a8JmXDpcnG/hfmpH X-Received: by 2002:aa7:ce18:: with SMTP id d24mr1025022edv.9.1603439572520; Fri, 23 Oct 2020 00:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603439572; cv=none; d=google.com; s=arc-20160816; b=B8rCrOgw/+KSBu8qLKzk+SVObofpTRSRKJ9Q7ucpkBQZhQR0GyCR6tug1EIdBdFKMz Yq/RG1dJj51xqEtdGOtrN8VNDZJZ+ad8wDs/XY+3599JHuhFGDjORWW2KdtkRqosjbOj foIRYsT16X/uJ8U1UBuAElB2SlnN8hLbHUc+KVLCvSIginriTd4Z/nESi0i2EJ+ZtCgl fgbswmhL3yoSsC48g23oZ8I8a1hGQ16NwDu8Qn4mTwtNtzKi9vkTX53WVaUM3fmtYf1i apWMXYFc6cRl2ho5E1rUXmJk4K0AHnkw5xb0JcfjCEFCZgAJN7OV8zyvp3QQ0jCUcM7L Yqog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=u4+0Y7bAzMg/YXqgTqUkzy2qMdgH2YnKP3AD74JymMo=; b=O0icpG3hoZGkqmIAWqLeBqKIKKMBFbTPGcWdiqQZg/usAhUJBr2uWDH4jdqCWnaD5C NRx6IeDAj2uzQXE8G7k32NRJYGNSQR1xRjvMMTL0dHyYAW2HR/OfNbOIXEMvEhW2FVFn ijgS+oFHmBeDJ8iVNjKKuYxnK5l6IUjk0A+pmm0lzaDSr6WHaHlzIH/g3AMXuO3mzFQZ ty3TUbAJbuCasghFS7twfx4/y9Fn0C9242sXRg7l/fBQ4tWJU1y7SGJx+0CGZbIylaYH N9op6b9jdjjOTqjsubdOO7I1Q4drZfYliAWVf14S65ztfGT2/JULdjEnYfdY0raWGq/+ f9Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@drivescale-com.20150623.gappssmtp.com header.s=20150623 header.b=Mt2ODQml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m3si277941edb.600.2020.10.23.00.52.30; Fri, 23 Oct 2020 00:52:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@drivescale-com.20150623.gappssmtp.com header.s=20150623 header.b=Mt2ODQml; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S460395AbgJWDbx (ORCPT + 99 others); Thu, 22 Oct 2020 23:31:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S460379AbgJWDbp (ORCPT ); Thu, 22 Oct 2020 23:31:45 -0400 Received: from mail-ua1-x964.google.com (mail-ua1-x964.google.com [IPv6:2607:f8b0:4864:20::964]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CA45C0613D8 for ; Thu, 22 Oct 2020 20:31:44 -0700 (PDT) Received: by mail-ua1-x964.google.com with SMTP id y1so1111665uac.13 for ; Thu, 22 Oct 2020 20:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=drivescale-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u4+0Y7bAzMg/YXqgTqUkzy2qMdgH2YnKP3AD74JymMo=; b=Mt2ODQmlOYCT3IidrPgKgGbfLpkgA2Psax0B2S4SZ1IhFmmMrYu/LmdpzG9dSy6S/P agS1OJiKqIEMbpEZKZTwLQ3qafEZfdlh/eCjZhk2OIWjoaHNeCI+vrnaQ9PU+n9WOZkb /UCIFEe/F/riaxkJpKvp9YXpvGlwNJOLgDajKXZ6Ki+KvguSIvGbdmm+Rhr1MRK8LevB J3QSnWnOGD1h09sr95Njjp5tbNnmDeWeguKlqYPrfMxasyCSZgxezfD2CiPI5Q0XSkZv 9tF0iEg5z3YmSsWN7H0tGbGZ3xYpn1CQhpZqz6L59Mcw/j5qwXPvhky3mJo1qj5S/1LN 412g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u4+0Y7bAzMg/YXqgTqUkzy2qMdgH2YnKP3AD74JymMo=; b=ZT/GfygD9LmKWUKiFR/kbWAlPETVM1oWEm0sZ678vTyD/lys4we+B7v1pwqBv3/DLy Xavy6amxSyWNK9ENDSH49x2VXYu897BBJDEa88XCO4XEjxGOkoEMXSbfomxDd8C/2txW xTq4T2a/jnPO9JsN+auTocLfdmStbcEIrg+l1jxReV656tB+CCoM5bTfAC5lSLsfYlDO jmuYJGoQlgUfHw3yScxXqTn+yYJQ43IevARwn6tg6qwenDPUYPdlnUaJ7X7WWgH0xqFA bl5xje2KLSf4x2dZC5T1cYJqnt3zw3mRGBOwcIfDqKYN9aD6jJ7Qxy4p06IJn5LSkoWh Nzqg== X-Gm-Message-State: AOAM532AF7vmDonCmGYjRzcm2Z3TvdY1qoxJyjUhhmmF2bVWSVxNowot djH/uH7nffB/0aQlNnKRAwKbupGU29UftEnsSkrboJcDUH3aJg== X-Received: by 2002:a9f:21ab:: with SMTP id 40mr121810uac.88.1603423903843; Thu, 22 Oct 2020 20:31:43 -0700 (PDT) Received: from dcs.hq.drivescale.com ([68.74.115.3]) by smtp-relay.gmail.com with ESMTP id y14sm25617vsd.5.2020.10.22.20.31.43; Thu, 22 Oct 2020 20:31:43 -0700 (PDT) X-Relaying-Domain: drivescale.com Received: from localhost.localdomain (gw1-dc.hq.drivescale.com [192.168.33.175]) by dcs.hq.drivescale.com (Postfix) with ESMTP id EA60A4211B; Fri, 23 Oct 2020 03:31:42 +0000 (UTC) From: Christopher Unkel To: linux-raid@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Song Liu , cunkel@drivescale.com Subject: [PATCH 2/3] md: factor sb write alignment check into function Date: Thu, 22 Oct 2020 20:31:29 -0700 Message-Id: <20201023033130.11354-3-cunkel@drivescale.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201023033130.11354-1-cunkel@drivescale.com> References: <20201023033130.11354-1-cunkel@drivescale.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor in preparation for a second use of the logic. Signed-off-by: Christopher Unkel --- drivers/md/md-bitmap.c | 72 +++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index 200c5d0f08bf..600b89d5a3ad 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -209,6 +209,44 @@ static struct md_rdev *next_active_rdev(struct md_rdev *rdev, struct mddev *mdde return NULL; } +static int sb_write_alignment_ok(struct mddev *mddev, struct md_rdev *rdev, + struct page *page, int offset, int size) +{ + if (mddev->external) { + /* Bitmap could be anywhere. */ + if (rdev->sb_start + offset + (page->index + * (PAGE_SIZE/512)) + > rdev->data_offset + && + rdev->sb_start + offset + < (rdev->data_offset + mddev->dev_sectors + + (PAGE_SIZE/512))) + return 0; + } else if (offset < 0) { + /* DATA BITMAP METADATA */ + if (offset + + (long)(page->index * (PAGE_SIZE/512)) + + size/512 > 0) + /* bitmap runs in to metadata */ + return 0; + if (rdev->data_offset + mddev->dev_sectors + > rdev->sb_start + offset) + /* data runs in to bitmap */ + return 0; + } else if (rdev->sb_start < rdev->data_offset) { + /* METADATA BITMAP DATA */ + if (rdev->sb_start + + offset + + page->index*(PAGE_SIZE/512) + size/512 + > rdev->data_offset) + /* bitmap runs in to data */ + return 0; + } else { + /* DATA METADATA BITMAP - no problems */ + } + return 1; +} + static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait) { struct md_rdev *rdev; @@ -234,38 +272,8 @@ static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait) /* Just make sure we aren't corrupting data or * metadata */ - if (mddev->external) { - /* Bitmap could be anywhere. */ - if (rdev->sb_start + offset + (page->index - * (PAGE_SIZE/512)) - > rdev->data_offset - && - rdev->sb_start + offset - < (rdev->data_offset + mddev->dev_sectors - + (PAGE_SIZE/512))) - goto bad_alignment; - } else if (offset < 0) { - /* DATA BITMAP METADATA */ - if (offset - + (long)(page->index * (PAGE_SIZE/512)) - + size/512 > 0) - /* bitmap runs in to metadata */ - goto bad_alignment; - if (rdev->data_offset + mddev->dev_sectors - > rdev->sb_start + offset) - /* data runs in to bitmap */ - goto bad_alignment; - } else if (rdev->sb_start < rdev->data_offset) { - /* METADATA BITMAP DATA */ - if (rdev->sb_start - + offset - + page->index*(PAGE_SIZE/512) + size/512 - > rdev->data_offset) - /* bitmap runs in to data */ - goto bad_alignment; - } else { - /* DATA METADATA BITMAP - no problems */ - } + if (!sb_write_alignment_ok(mddev, rdev, page, offset, size)) + goto bad_alignment; md_super_write(mddev, rdev, rdev->sb_start + offset + page->index * (PAGE_SIZE/512), -- 2.17.1