From patchwork Thu Nov 5 02:02:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 7556661 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8599D9F2F7 for ; Thu, 5 Nov 2015 02:06:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A6A0220824 for ; Thu, 5 Nov 2015 02:06:18 +0000 (UTC) Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9FCB020823 for ; Thu, 5 Nov 2015 02:06:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tA523h6H042291; Wed, 4 Nov 2015 21:03:43 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id tA5238tb020857 for ; Wed, 4 Nov 2015 21:03:08 -0500 Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tA5238Uq025501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 4 Nov 2015 21:03:08 -0500 Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by mx1.redhat.com (Postfix) with ESMTPS id 83F7619F3A1 for ; Thu, 5 Nov 2015 02:03:06 +0000 (UTC) Received: by wijp11 with SMTP id p11so1487440wij.0 for ; Wed, 04 Nov 2015 18:03:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lXyARXopGcBZSzQ3Xn7vHGjmwah4IdDD1wzZ1f3nRPM=; b=M3hVL9b5/y6pc4C6VCzn36C3LoHgIibT+DYLAq40UCeLxTYOncCRC9gpd3a5A21pXn rLkisa3dJD7PuB170SjaRY4LkjDohpLGvFiM0vx8uXbopcu28mATLnGELfQjde65xWV3 JmsIhGU+3ZWZzUrlKbArldZ5jOcwHpaiCZq4tQhp+gYBbRE1AYR78Xalm3GvWJJCDpLJ +xzSFfwlxcLalgRpt/i+DkrqjkrM7O00FIrONc9Li1AfywYG2nw0CZ3TfHZyZV0ikZjq IEKjllgKLIhUVwq6D1AE+fkQc/ITjwdiRvoYh50Gg2U0+riBB6anVf2cAhDN/GtDojGm fdKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lXyARXopGcBZSzQ3Xn7vHGjmwah4IdDD1wzZ1f3nRPM=; b=gjaPtvBJwJxddMhu3wulwvl3pS1OOWJPVXRoYfK5LNkEe2rcP1cXn3j9C5rNWWk2sf QZ5a46w2/SdgIeY2lISQ32CyMDeCtc7UeWsie0XBiOI+iQfZFdQKAL6XyXUGnwdqldfg Vc8EIRCFAx0Ar8THI+nPyU81BZL0D9U3zX4RdRgsrc/To6a+7jBmjF75TtRKwG24S9Cq Er+zPHiTgFlOkS+R8gZW5VqkAoB8jlbiNqssDuqywPQQhVRI6shyUqqXdx2sxUeL/BuS cJom0d2y9hAvL6i6aLOPHUXteRv10zOx1Rhlk6X6PQ8VpRx/OwxHfyB65yUYLyGD0GTu JerA== X-Gm-Message-State: ALoCoQkw0TorDricH+gGgHIxgIjkHmpbUIBlk7HUzXM2ROhB11+b/JLp7xj0t5xZUxP5h9v20GW2 X-Received: by 10.194.192.167 with SMTP id hh7mr6022411wjc.79.1446688984730; Wed, 04 Nov 2015 18:03:04 -0800 (PST) Received: from samitolvanen1.lon.corp.google.com ([172.16.12.218]) by smtp.gmail.com with ESMTPSA id bf8sm4337693wjc.22.2015.11.04.18.03.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Nov 2015 18:03:03 -0800 (PST) From: Sami Tolvanen To: Mikulas Patocka , Mandeep Baines , Will Drewry Date: Thu, 5 Nov 2015 02:02:32 +0000 Message-Id: <1446688954-29589-3-git-send-email-samitolvanen@google.com> In-Reply-To: <1446688954-29589-1-git-send-email-samitolvanen@google.com> References: <1446688954-29589-1-git-send-email-samitolvanen@google.com> X-RedHat-Spam-Score: -0.431 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_RP_MATCHES_RCVD) 209.85.212.178 mail-wi0-f178.google.com 209.85.212.178 mail-wi0-f178.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-loop: dm-devel@redhat.com Cc: Kees Cook , Mike Snitzer , linux-kernel@vger.kernel.org, dm-devel@redhat.com, Alasdair Kergon , Sami Tolvanen , Mark Salyzyn Subject: [dm-devel] [PATCH 2/4] dm verity: separate function for parsing opt args X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move optional argument parsing into a separate function to make it easier to add more of them without making verity_ctr even longer. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- drivers/md/dm-verity.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/md/dm-verity.c b/drivers/md/dm-verity.c index 487cb66..da76f77 100644 --- a/drivers/md/dm-verity.c +++ b/drivers/md/dm-verity.c @@ -34,6 +34,8 @@ #define DM_VERITY_OPT_LOGGING "ignore_corruption" #define DM_VERITY_OPT_RESTART "restart_on_corruption" +#define DM_VERITY_OPTS_MAX 1 + static unsigned dm_verity_prefetch_cluster = DM_VERITY_DEFAULT_PREFETCH_SIZE; module_param_named(prefetch_cluster, dm_verity_prefetch_cluster, uint, S_IRUGO | S_IWUSR); @@ -725,6 +727,21 @@ static void verity_dtr(struct dm_target *ti) kfree(v); } +static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v, + const char *opt_string) +{ + if (!strcasecmp(opt_string, DM_VERITY_OPT_LOGGING)) { + v->mode = DM_VERITY_MODE_LOGGING; + return 0; + } else if (!strcasecmp(opt_string, DM_VERITY_OPT_RESTART)) { + v->mode = DM_VERITY_MODE_RESTART; + return 0; + } + + v->ti->error = "Invalid feature arguments"; + return -EINVAL; +} + /* * Target parameters: * The current format is version 1. @@ -752,7 +769,7 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) char dummy; static struct dm_arg _args[] = { - {0, 1, "Invalid number of feature args"}, + {0, DM_VERITY_OPTS_MAX, "Invalid number of feature args"}, }; v = kzalloc(sizeof(struct dm_verity), GFP_KERNEL); @@ -912,15 +929,11 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv) goto bad; } - if (!strcasecmp(opt_string, DM_VERITY_OPT_LOGGING)) - v->mode = DM_VERITY_MODE_LOGGING; - else if (!strcasecmp(opt_string, DM_VERITY_OPT_RESTART)) - v->mode = DM_VERITY_MODE_RESTART; - else { - ti->error = "Invalid feature arguments"; - r = -EINVAL; + r = verity_parse_opt_args(&as, v, opt_string); + if (r < 0) goto bad; - } + + opt_params -= r; } }