From patchwork Wed May 16 16:45:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10404441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C774D601F7 for ; Wed, 16 May 2018 16:46:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5B7227F7F for ; Wed, 16 May 2018 16:46:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA9B328520; Wed, 16 May 2018 16:46:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40F4D27F7F for ; Wed, 16 May 2018 16:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751914AbeEPQqK (ORCPT ); Wed, 16 May 2018 12:46:10 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:36033 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751389AbeEPQqA (ORCPT ); Wed, 16 May 2018 12:46:00 -0400 Received: by mail-pl0-f65.google.com with SMTP id v24-v6so761760plo.3 for ; Wed, 16 May 2018 09:46:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=f3F1bcTA4GYjZ+v+w0RU/o0u1btGe7nqiPR3T7EHN3k=; b=VTd5OuaSUUglwJ8MRY6kTxCI8aGSALnN7rph5cMco/aRWFgxPXnrlGET0nj3Nz10gc bS2KYQm5zDRQG//XmGtJNvFP4sofQr0l4XnbO7IZJpQuUy8CEADDz8Q+W25+wNTzSJXk 8YYkbni3DS9dE9vTjckMi/i+8q8T16WfpuZm1Em+zdSt6Zvo1IuEugPsSoXSJ3DGf5wy XcDeO3ZjICIEVLlyyc/EhesVOl/XY2yMQVw+9nPYMAMoei6ky+fDJWca6hj62tXTluTs /ggnu6zdHpIb8ol0NQplwsGQ5EeuMcPc+facIbGP3xOp/ZvmRNOWBsj1oQMeJFHIMC83 r+Fg== 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:in-reply-to:references; bh=f3F1bcTA4GYjZ+v+w0RU/o0u1btGe7nqiPR3T7EHN3k=; b=pC5OcxsXCavdXe+io2j8DeZiuOvFoMwKL7fe8cKoOqxRcELor8Gf6l+ehrVUSmGnA6 oqkZqKjwYFnhJhem6G1AhwLohMyP4R7B3CsxP4Xv2lHUAE6KASLllKUb47R/aNuQCQKS WMKttdt+lZpscjAEU6dM1Y8/P6Hog6o1NdVXQdxOlfaX3axp337mSkqHDW4xl7tQX+KL 0AgchvLmYBdwoMNfPeAdAyivToaLtoUKl5phmKlO7HB6wQc9/+GqAG5nj4STRheX30vr ZdQeflw70N5ParaqQhieD2jqh8FBlblCssWEAnvDGxwiuzA2S3vFCUw88r4CJQFOsQiu 2rJQ== X-Gm-Message-State: ALKqPweCofEJGvFZk9x0Le9PmcdqIUEA3Hg5rAhI2eSih4HwZ2/p67Tg 4P4wiYeNXOGFTgaPQnu9gZOcjA== X-Google-Smtp-Source: AB8JxZpFINAwfb4x9tCnbevuA/bJbHrUiFPDkZAvg0fFqDaPqUs5dVTKbAd/5xt0hefiAsCtB5qDUA== X-Received: by 2002:a17:902:9a4c:: with SMTP id x12-v6mr1611236plv.213.1526489159331; Wed, 16 May 2018 09:45:59 -0700 (PDT) Received: from vader.hsd1.wa.comcast.net ([2601:602:8800:a9a9:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id u4-v6sm7914441pgn.10.2018.05.16.09.45.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 May 2018 09:45:58 -0700 (PDT) From: Omar Sandoval To: "Darrick J . Wong" , linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, Jan Kara , Christoph Hellwig , Aleksei Besogonov , kernel-team@fb.com Subject: [PATCH v2 1/2] iomap: provide more useful errors for invalid swap files Date: Wed, 16 May 2018 09:45:50 -0700 Message-Id: <9faf09627cfa469437b76edb73ac7cc822dc33c8.1526488995.git.osandov@fb.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval Currently, for an invalid swap file, we print the same error message regardless of the reason. This isn't very useful for an admin, who will likely want to know why exactly they can't use their swap file. So, let's add specific error messages for each reason, and also move the bdev check after the flags checks, since the latter are more fundamental. Signed-off-by: Omar Sandoval Reviewed-by: Darrick J. Wong --- fs/iomap.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/fs/iomap.c b/fs/iomap.c index d193390a1c20..318724375ffe 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -1218,22 +1218,32 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, if (iomap->type == IOMAP_HOLE) goto out; - /* Only one bdev per swap file. */ - if (iomap->bdev != isi->sis->bdev) - goto err; - /* Only real or unwritten extents. */ - if (iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN) - goto err; + if ((iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN) || + iomap->addr == IOMAP_NULL_ADDR) { + pr_err("swapon: file has unallocated extents\n"); + return -EINVAL; + } /* No uncommitted metadata or shared blocks or inline data. */ - if (iomap->flags & (IOMAP_F_DIRTY | IOMAP_F_SHARED | - IOMAP_F_DATA_INLINE)) - goto err; + if (iomap->flags & IOMAP_F_DIRTY) { + pr_err("swapon: file is not committed\n"); + return -EINVAL; + } + if (iomap->flags & IOMAP_F_SHARED) { + pr_err("swapon: file has shared extents\n"); + return -EINVAL; + } + if (iomap->flags & IOMAP_F_DATA_INLINE) { + pr_err("swapon: file is inline\n"); + return -EINVAL; + } - /* No null physical addresses. */ - if (iomap->addr == IOMAP_NULL_ADDR) - goto err; + /* Only one bdev per swap file. */ + if (iomap->bdev != isi->sis->bdev) { + pr_err("swapon: file is on multiple devices\n"); + return -EINVAL; + } if (isi->iomap.length == 0) { /* No accumulated extent, so just store it. */ @@ -1250,9 +1260,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, } out: return count; -err: - pr_err("swapon: file cannot be used for swap\n"); - return -EINVAL; } /*