From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-dm3nam03on0093.outbound.protection.outlook.com ([104.47.41.93]:1728 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726600AbeIBRXj (ORCPT ); Sun, 2 Sep 2018 13:23:39 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: John Pittman , Mike Snitzer , Sasha Levin Subject: [PATCH AUTOSEL 4.14 64/89] dm cache: only allow a single io_mode cache feature to be requested Date: Sun, 2 Sep 2018 13:07:28 +0000 Message-ID: <20180902064918.183387-64-alexander.levin@microsoft.com> References: <20180902064918.183387-1-alexander.levin@microsoft.com> In-Reply-To: <20180902064918.183387-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: John Pittman [ Upstream commit af9313c32c0fa2a0ac3b113669273833d60cc9de ] More than one io_mode feature can be requested when creating a dm cache device (as is: last one wins). The io_mode selections are incompatible with one another, we should force them to be selected exclusively. Add a counter to check for more than one io_mode selection. Fixes: 629d0a8a1a10 ("dm cache metadata: add "metadata2" feature") Signed-off-by: John Pittman Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/dm-cache-target.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c index 71c3507df9a0..a4b7c2698096 100644 --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c @@ -2330,7 +2330,7 @@ static int parse_features(struct cache_args *ca, stru= ct dm_arg_set *as, {0, 2, "Invalid number of cache feature arguments"}, }; =20 - int r; + int r, mode_ctr =3D 0; unsigned argc; const char *arg; struct cache_features *cf =3D &ca->features; @@ -2344,14 +2344,20 @@ static int parse_features(struct cache_args *ca, st= ruct dm_arg_set *as, while (argc--) { arg =3D dm_shift_arg(as); =20 - if (!strcasecmp(arg, "writeback")) + if (!strcasecmp(arg, "writeback")) { cf->io_mode =3D CM_IO_WRITEBACK; + mode_ctr++; + } =20 - else if (!strcasecmp(arg, "writethrough")) + else if (!strcasecmp(arg, "writethrough")) { cf->io_mode =3D CM_IO_WRITETHROUGH; + mode_ctr++; + } =20 - else if (!strcasecmp(arg, "passthrough")) + else if (!strcasecmp(arg, "passthrough")) { cf->io_mode =3D CM_IO_PASSTHROUGH; + mode_ctr++; + } =20 else if (!strcasecmp(arg, "metadata2")) cf->metadata_version =3D 2; @@ -2362,6 +2368,11 @@ static int parse_features(struct cache_args *ca, str= uct dm_arg_set *as, } } =20 + if (mode_ctr > 1) { + *error =3D "Duplicate cache io_mode features requested"; + return -EINVAL; + } + return 0; } =20 --=20 2.17.1