From patchwork Fri Feb 19 01:37:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12094611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28322C433E0 for ; Fri, 19 Feb 2021 01:40:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB56764D9A for ; Fri, 19 Feb 2021 01:40:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229468AbhBSBjq (ORCPT ); Thu, 18 Feb 2021 20:39:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50737 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbhBSBjp (ORCPT ); Thu, 18 Feb 2021 20:39:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613698698; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ofKQc4D7mS3cNuXAUON8kLtIoct0mNDX6qGCuosRrnk=; b=HF+ooR3kQxNPtWPFUwFQ1B4SF+eqMmWF5hyToouULU8ZTekDSH/p8dYcB/dSqm+s3xyOoQ S84ztEdHAgyJWzCX287I5MwOWjECLtMRqJuuBo3uu6DWLz4A38J1gMxYG48qTgAbofaVrw 5kU2ZsI0/AQt5xBfE0P6ThRuICFnytY= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-vJeOHnATNYGiWgMjNRIw-w-1; Thu, 18 Feb 2021 20:38:14 -0500 X-MC-Unique: vJeOHnATNYGiWgMjNRIw-w-1 Received: by mail-pf1-f200.google.com with SMTP id 68so2849256pfe.2 for ; Thu, 18 Feb 2021 17:38:14 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=ofKQc4D7mS3cNuXAUON8kLtIoct0mNDX6qGCuosRrnk=; b=OzKTQmxAPPhFcNhyplAYY8Nzz9GzzTtNxIVEbbGV2YDyIu9lGQoN2ZbLEX9SlxOmxe Cht2ZHODIz1OKIJKfIhzasrkmlOsXgAnAehjCKrJ1ix3rjUd1mJ8lorYtbAXLxK7/t5e 3mI756BJ1xum/3oUpTxDB2zkiExDfz79NwVIH4FEmn7EY2GJSMqpzJUIOHus0bq7S9gf DDlIlw0g1cOqVI6dkffo+XG7nTvhN+ZSdkKdeOboowx57aAF8Gvj9Xig/OsIcgKrkuIT VrrXJKjqhwFd4jcXUHmWHKcZELFpUjLTAAdpzjHfkq8SUJCzgl4pU/L2mr65kRxpyvaA RrjQ== X-Gm-Message-State: AOAM533lT8PBYDNp4vxHFzK0rtkIjXRqLS+RFEKi2ubZfa0KhVW45IpC HBuPnaOVO5V1N8gdOe1jNgMgezEYiB2zExLg1tjrcI6fU2Ph7JZUJ0bjYyUriASaBJMG96wbykp ifJT927xAKOWL6qu6R/m+PNG68gCTiNDYV/6Eju7E2A0pGwztJq9+R9wAvoj49RwNs3mTL/Davw == X-Received: by 2002:aa7:99db:0:b029:1e1:fe8a:4948 with SMTP id v27-20020aa799db0000b02901e1fe8a4948mr7001913pfi.59.1613698693742; Thu, 18 Feb 2021 17:38:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6lkfDwUTtW8AK/yX/UZqjpZnKVhkTQSXUrZtFfz8XEAvIZqW5yxeZg47Fp3zbWSV0AZzSpQ== X-Received: by 2002:aa7:99db:0:b029:1e1:fe8a:4948 with SMTP id v27-20020aa799db0000b02901e1fe8a4948mr7001888pfi.59.1613698693394; Thu, 18 Feb 2021 17:38:13 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id 9sm7414144pfw.48.2021.02.18.17.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Feb 2021 17:38:13 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org, Eric Sandeen Cc: Brian Foster , "Darrick J. Wong" , Dave Chinner , Gao Xiang Subject: [PATCH v7 3/3] mkfs: make use of xfs_validate_stripe_geometry() Date: Fri, 19 Feb 2021 09:37:34 +0800 Message-Id: <20210219013734.428396-1-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201013040627.13932-4-hsiangkao@redhat.com> References: <20201013040627.13932-4-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Check stripe numbers in calc_stripe_factors() by using xfs_validate_stripe_geometry(). Signed-off-by: Gao Xiang Reviewed-by: Eric Sandeen --- changes since v6: - fix dsu round-down issue (the related print message has also been turned into bytes to avoid round-down issue); - rebase on for-next. libxfs/libxfs_api_defs.h | 1 + mkfs/xfs_mkfs.c | 35 +++++++++++++++-------------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 9a00ce66..e4192e1b 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -192,6 +192,7 @@ #define xfs_trans_roll libxfs_trans_roll #define xfs_trim_extent libxfs_trim_extent +#define xfs_validate_stripe_geometry libxfs_validate_stripe_geometry #define xfs_verify_agbno libxfs_verify_agbno #define xfs_verify_agino libxfs_verify_agino #define xfs_verify_cksum libxfs_verify_cksum diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index d72d21ef..dcdd5262 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -2361,28 +2361,22 @@ _("both data su and data sw options must be specified\n")); usage(); } - if (dsu % cfg->sectorsize) { + big_dswidth = (long long int)dsu * dsw; + if (BTOBBT(big_dswidth) > INT_MAX) { fprintf(stderr, -_("data su must be a multiple of the sector size (%d)\n"), cfg->sectorsize); +_("data stripe width (%lld) is too large of a multiple of the data stripe unit (%d)\n"), + big_dswidth, dsu); usage(); } - dsunit = (int)BTOBBT(dsu); - big_dswidth = (long long int)dsunit * dsw; - if (big_dswidth > INT_MAX) { - fprintf(stderr, -_("data stripe width (%lld) is too large of a multiple of the data stripe unit (%d)\n"), - big_dswidth, dsunit); + if (!libxfs_validate_stripe_geometry(NULL, dsu, big_dswidth, + cfg->sectorsize, false)) usage(); - } - dswidth = big_dswidth; - } - if ((dsunit && !dswidth) || (!dsunit && dswidth) || - (dsunit && (dswidth % dsunit != 0))) { - fprintf(stderr, -_("data stripe width (%d) must be a multiple of the data stripe unit (%d)\n"), - dswidth, dsunit); + dsunit = BTOBBT(dsu); + dswidth = BTOBBT(big_dswidth); + } else if (!libxfs_validate_stripe_geometry(NULL, BBTOB(dsunit), + BBTOB(dswidth), cfg->sectorsize, false)) { usage(); } @@ -2400,11 +2394,12 @@ _("data stripe width (%d) must be a multiple of the data stripe unit (%d)\n"), /* if no stripe config set, use the device default */ if (!dsunit) { - /* Ignore nonsense from device. XXX add more validation */ - if (ft->dsunit && ft->dswidth == 0) { + /* Ignore nonsense from device report. */ + if (!libxfs_validate_stripe_geometry(NULL, BBTOB(ft->dsunit), + BBTOB(ft->dswidth), 0, true)) { fprintf(stderr, -_("%s: Volume reports stripe unit of %d bytes and stripe width of 0, ignoring.\n"), - progname, BBTOB(ft->dsunit)); +_("%s: Volume reports invalid stripe unit (%d) and stripe width (%d), ignoring.\n"), + progname, BBTOB(ft->dsunit), BBTOB(ft->dswidth)); ft->dsunit = 0; ft->dswidth = 0; } else {