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: 10404443 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 D6F786037D 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 C61CB284FC for ; Wed, 16 May 2018 16:46:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAF542856A; 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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 708F3284AF for ; Wed, 16 May 2018 16:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbeEPQqK (ORCPT ); Wed, 16 May 2018 12:46:10 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:46518 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751370AbeEPQqA (ORCPT ); Wed, 16 May 2018 12:46:00 -0400 Received: by mail-pl0-f66.google.com with SMTP id 30-v6so746721pld.13 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=UbuRRMnlyfjHdxaSeme+ZRj85hKWOLOtvbJIlFx9hK47aq+HWeSRtM6MvlxcVFXgIC FnIvfL/ZOvTqDpsGV2NcPGuS3Ne7SeRqbt1ghRkMoZHhOYe63KtPcQlPNGkWwJ0rTtXN +g1Hq22F8PxiNUT/n5cJRc4FvFOuQDSCIUS3V3MXtvWmudyz/KG43dHjq8twjbWYJ2aC QCi32bfyNEYZNYwSU3bEgGt2fmohF7aM0oqm3oc20c9rw9b5Wvms8wWRMMrGmp/ho59W pdcKY8twLhhWaXiNc35eLU0v8kbllbGKqoq4lWPXYHazaEJo7GUbmEtlsuC41FSRKgyU j6DQ== X-Gm-Message-State: ALKqPwfIhJm0WlVPbP+YkVVfeRppaHr7ODci21UNNF9gwMF180DAyW3C GtM6F9pckSDtZfxnzqJEsyGxjQ== 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-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@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; } /*