From patchwork Wed Jun 8 04:56:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12872907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09169C433EF for ; Wed, 8 Jun 2022 06:44:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbiFHGoA (ORCPT ); Wed, 8 Jun 2022 02:44:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236895AbiFHGEQ (ORCPT ); Wed, 8 Jun 2022 02:04:16 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86A9426D90D for ; Tue, 7 Jun 2022 21:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1654664351; x=1686200351; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gEIEXCYZy1bxZWP7CIJZ7DkiyLXVfXSlBA1Ynd5HU38=; b=ROzPSbY7aOM386Bo5uWX5FyJn8yv29m/66h0vTkx7iJ4nRbJnlNki8Zp cC0Zd/FiMSfj8BiaGYQW6WA9s7RudbzNKZPI0MezHZQdksit8aYayFEuz NqM2WDSZhIIHiuOajD1Ki3O/uYd+q++NWJOY0MR+BCn2iEAuux23W63jw tANg0Stux63CEld14IexU6azfuiP3VhyVnx+tNltareuPZpnsRe+LDkYS aE6HN9yirBAHUrrCw/kgoFgERomOIqpTjhYghiFXKNBCJHWKl/67tVzSp /mz9CnSx1PmDsz60rfhUs0xksIhiGH6y4gwcbSbET1N7TtNzhmgRLXbSv g==; X-IronPort-AV: E=Sophos;i="5.91,285,1647273600"; d="scan'208";a="201289625" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Jun 2022 12:56:31 +0800 IronPort-SDR: rhbpqddpf6h9y2FCWSJNNUVPaDCL40UoStDewDxF+RUv9GsCm6aHUh85tAF6IsdSp48rC0CZ6U GH4eaLzOTipsXprKGxV8igTUWagBym7pb5CgVhkj/cOnWZYLAnDgnwH8ZthSakaS6oSJgEXm9k Gq6akIEzFZBvjwjq62krKLWgh7kZ1is66GMq5V0MVHdL15sQeNyMZDq+C6hJoUYCE77XsqQphU 6rVJvyR8qPAKVTicw5ZQykBO66TJUZMzvm4lpDuVBYziQj8ecdul9zfiTM/QQsL9x9w3zaTiks C+FJZzGNJ2FiHzV5DI72LH4t Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Jun 2022 21:15:20 -0700 IronPort-SDR: jawGZo+S+b5S8PC10FsZELZ3jBQ8F2xgeRTmA+XAo/80jOezJdgRK4Jlgwq3I3CgpVtbRmEk9J z5gMWgWOk5Fv3LTi/z6G3y59z0zuhTM+AZo5mAYTLY0tKZjivk1co3fyzAqE5EkkJnzjcJ9goa PIHOVUFmsM46+22AjceBuFWJSMeRAlB2Fm6eVgvz9EPDD73MFDxtFp0MHM28+gnJLsBmtlVLum 0VnlPRoXUul6OoAxEZjPzA8z5W2Z30nsJytxkARjihW1j/uE7QFRg7wos29rFPidRKbDlPWLyW hos= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Jun 2022 21:56:32 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4LHw1C46RLz1SVnx for ; Tue, 7 Jun 2022 21:56:31 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1654664191; x=1657256192; bh=gEIEXCYZy1bxZWP7CI JZ7DkiyLXVfXSlBA1Ynd5HU38=; b=ro3njAENukHogAe8v1Mn68ai4id+gOAk84 Rya5AexUlRqcbtGm5tJ0E2iWKGXY/A3xkU8wh8dhYlXgOrm9pqoOYBb/oh/JG6AV xm5Uj9+/elbqoLemr8ei2ArApMVXujuqmN9eeA3H7qjMOu2bC2q/Foav+2KpjQBK tfxPojSR1nGZxZz+7eOn0Po8NhuVT/mDTYrePpls2D88jiGWtz0yjIX4pLVDhW9B my5fg3faR3f98irnZz6xbEq0u20U4ZfcYR9iyL5JeKI6T6213hO/AzwbqX550WD5 ezgKFh/zuC3RopkQXToK7vkntO9pYOdIuhgWSy0VV8Bt7a8wgKkA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jpGHqflJRT40 for ; Tue, 7 Jun 2022 21:56:31 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4LHw1B4K0kz1Rvlx; Tue, 7 Jun 2022 21:56:30 -0700 (PDT) From: Damien Le Moal To: linux-fsdevel@vger.kernel.org Cc: Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v2 1/3] zonefs: fix handling of explicit_open option on mount Date: Wed, 8 Jun 2022 13:56:25 +0900 Message-Id: <20220608045627.142408-2-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220608045627.142408-1-damien.lemoal@opensource.wdc.com> References: <20220608045627.142408-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Ignoring the explicit_open mount option on mount for devices that do not have a limit on the number of open zones must be done after the mount options are parsed and set in s_mount_opts. Move the check to ignore the explicit_open option after the call to zonefs_parse_options() in zonefs_fill_super(). Fixes: b5c00e975779 ("zonefs: open/close zone on file open/close") Cc: Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/zonefs/super.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index bcb21aea990a..ecce84909ca1 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -1760,12 +1760,6 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent) atomic_set(&sbi->s_wro_seq_files, 0); sbi->s_max_wro_seq_files = bdev_max_open_zones(sb->s_bdev); - if (!sbi->s_max_wro_seq_files && - sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) { - zonefs_info(sb, "No open zones limit. Ignoring explicit_open mount option\n"); - sbi->s_mount_opts &= ~ZONEFS_MNTOPT_EXPLICIT_OPEN; - } - atomic_set(&sbi->s_active_seq_files, 0); sbi->s_max_active_seq_files = bdev_max_active_zones(sb->s_bdev); @@ -1790,6 +1784,12 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent) zonefs_info(sb, "Mounting %u zones", blkdev_nr_zones(sb->s_bdev->bd_disk)); + if (!sbi->s_max_wro_seq_files && + sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) { + zonefs_info(sb, "No open zones limit. Ignoring explicit_open mount option\n"); + sbi->s_mount_opts &= ~ZONEFS_MNTOPT_EXPLICIT_OPEN; + } + /* Create root directory inode */ ret = -ENOMEM; inode = new_inode(sb); From patchwork Wed Jun 8 04:56:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12872911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5A2DCCA48A for ; Wed, 8 Jun 2022 06:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233891AbiFHGp2 (ORCPT ); Wed, 8 Jun 2022 02:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236902AbiFHGEQ (ORCPT ); Wed, 8 Jun 2022 02:04:16 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F10D244091 for ; Tue, 7 Jun 2022 21:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1654664353; x=1686200353; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CevkZZnhv6j2Mk73kiuiXO8Tmh2N1oB2gvlfpnKcSXs=; b=cufsK0OCBVBaHPrhqkbcmcecPPPTIAjoyl8o/ySgTzzwSMEn+JCTaKmh N2TVxFPva0AG8d7FRASoiGC/i9GoeOXWeWaoyw5iVibsxxXnRqS4XIEkK iZaezqlxumO2DpkyCXHwfV5ECmVRt4nrj4B+wzx+N0h0ywum6+b2ewnXl OAFbQDuO07MKqn7SweWAKXhqaXDHKLDqy3MZsexhz4/lsGkUZL3BeKziV z/K5lStIxjmvu3DxUue/yoosgT2kc8L1JqaBsI5e5NvvdbZzKbxsj4+3U CgJsLGBv7y6+9AkEZ8a+XLwxLdA4xs+rwSETLV55MADCKr7KVy61o17Yo Q==; X-IronPort-AV: E=Sophos;i="5.91,285,1647273600"; d="scan'208";a="201289626" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Jun 2022 12:56:33 +0800 IronPort-SDR: 68t6Yfuskz8xCr7SsUzWtaD65CfftbtwsKEbLTl7Q24HXFdQNUp/YccWHYXYEt/aNP3XR4xoau CfbzCLKn0OEaHxyXt8VlNNKXlXIQWJkybT1RY58K040TUKGpl/sf3zEPNLKHFx7ECJJX6ADt0N 9HDnVS8fNwv5UQbDyYprBVwxEKu1llI1kvMshfJ0lLKjKFbhxcNEqpcex1CFfO0xp8f3kY8sh8 xRCLKm7SjA7GrhwcuhYLK26hrtIfepWSOdlzZ3iBfJ0U6VNZJU8YV7A9N9gwD0kXbz+jeg7TY5 yuqGJr1DoffLK/Rf18Ab4N5C Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Jun 2022 21:15:22 -0700 IronPort-SDR: 4VRWl695KZdHYi3VsQggBnPVVIneZU8A0yxUqX/vxU2FYKCtc7AwAjevA5Z9FOj0SdCFChYI1v m8L9mxgI5hSGEGdduiqc+F5agwzf3RBs8yyGcmkZoDd9oZZ9YPY6ZepuqO/92/FdBYcbqL0qqk KFXu1QobZdCV6mrU1Zivtcfrif3sgFzboMTwm3iROh4olSwKo7bo+3rlfRV0RpxY+w2MbWp98i 0+NeII/Pwzzv0hEuPfc3GfDGwIkmrsNjDcSu8nEWAQ/OFusd+wNsxLfOnUxyjJP/JDtjsNh9LE h/o= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Jun 2022 21:56:34 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4LHw1D2ytlz1Rwrw for ; Tue, 7 Jun 2022 21:56:32 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1654664192; x=1657256193; bh=CevkZZnhv6j2Mk73ki uiXO8Tmh2N1oB2gvlfpnKcSXs=; b=fPYCwaG+BWMsBpnZgkdP1CbR8GsW/MDAi+ 4tYdNSpIVMNyjyP/1+VZsofflPOwnLl3SDplJoLLcAp8FYbuWl1vp2/fUxu9V2mz 0ySDNygvHnUOx/k4SQebt4RPki39zmy6U595AA+EDcq2uFsCFyamPEVzkvWSQqdI NV8/0Nawoo6Z2dqiPxwMA7prejpDfnm43dViXhfx2k9LkIOFGWlqFzaVHARkOj9J UcV39qUKKSjQfPPGOxh/15dFi5cPmv+99sIJWtYiVvwoWGdzMLa5JOLXCMzT4QKk lFZvUyzKWFhhzpi/SBvzI86IbS4mtA0wBhCcVXGG/+SASn0pXjbA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 3LsKR1Ne2NSe for ; Tue, 7 Jun 2022 21:56:32 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4LHw1C3WXpz1Rvlc; Tue, 7 Jun 2022 21:56:31 -0700 (PDT) From: Damien Le Moal To: linux-fsdevel@vger.kernel.org Cc: Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v2 2/3] zonefs: Do not ignore explicit_open with active zone limit Date: Wed, 8 Jun 2022 13:56:26 +0900 Message-Id: <20220608045627.142408-3-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220608045627.142408-1-damien.lemoal@opensource.wdc.com> References: <20220608045627.142408-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org A zoned device may have no limit on the number of open zones but may have a limit on the number of active zones it can support. In such case, the explicit_open mount option should not be ignored to ensure that the open() system call activates the zone with an explicit zone open command, thus guaranteeing that the zone can be written. Enforce this by ignoring the explicit_open mount option only for devices that have both the open and active zone limits equal to 0. Fixes: 87c9ce3ffec9 ("zonefs: Add active seq file accounting") Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig --- fs/zonefs/super.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index ecce84909ca1..123464d2145a 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -1085,7 +1085,8 @@ static int zonefs_seq_file_write_open(struct inode *inode) if (sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) { - if (wro > sbi->s_max_wro_seq_files) { + if (sbi->s_max_wro_seq_files + && wro > sbi->s_max_wro_seq_files) { atomic_dec(&sbi->s_wro_seq_files); ret = -EBUSY; goto unlock; @@ -1785,8 +1786,10 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent) blkdev_nr_zones(sb->s_bdev->bd_disk)); if (!sbi->s_max_wro_seq_files && + !sbi->s_max_active_seq_files && sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) { - zonefs_info(sb, "No open zones limit. Ignoring explicit_open mount option\n"); + zonefs_info(sb, + "No open and active zone limits. Ignoring explicit_open mount option\n"); sbi->s_mount_opts &= ~ZONEFS_MNTOPT_EXPLICIT_OPEN; } From patchwork Wed Jun 8 04:56:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12872909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFCBAC433EF for ; Wed, 8 Jun 2022 06:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231161AbiFHGoV (ORCPT ); Wed, 8 Jun 2022 02:44:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236907AbiFHGEQ (ORCPT ); Wed, 8 Jun 2022 02:04:16 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23EB126EE99 for ; Tue, 7 Jun 2022 21:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1654664355; x=1686200355; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0SMWDuWsxE3dyExXGKJTZLDWsylNdk2ZwEaW5DIMC38=; b=fGb+YE/mYPJ6lIDzrIPMxj87sFaaMZ8MDykqd0x+KHdkkhDtvbmK8Pvx JeuVqKovoiZZlM9ORX0Mm6loxqIknt1qLea8DKPkrtu4OvHEY2RxVTarG rOZlakEMISMEgB+ja3D5tnkjSfZvHqvCJwi7NHbJFUWTZmQAxJgQO8uS/ 9x4nlXT9wBKdMUwdcAvS0BDRGjId9UXZfjWpxIGfZ4HZ8zpp6WTcSvs9x 4BjcAXYsxLVBwNKivMyPiKYxmAvWJFlziw7KcPZka0A7euyU/lyidqiE4 DoS817m7wpbWTITqlelK9tqvKdDznc1dLrQOEk/PUItPNH2toW51R7SlT g==; X-IronPort-AV: E=Sophos;i="5.91,285,1647273600"; d="scan'208";a="201289627" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Jun 2022 12:56:33 +0800 IronPort-SDR: HZlaZ1+1cdEi3kFQ8zORJ3vh4YE0U97RSDjaD95AZ2Pe+AweMd/msPtv0XXhrEGUOT0AM8yn2R 4oOEgfvqqrnupAgYVU7pLbh3PuAoofz/zMovmuOT02R9BB+BI2v20iEPyJhRxnVXbQL3L465Cw BbCMOhK8ClV1BbtJLcu/YVknP47yBizBvVqzEpArf/VDzjS4HopxS8TTBSc+aNiaH036ZX8EVn EPSH8fme9Q+Dp7hYd618Xb78tCkBQDc3doBn9yqo+f4kXPYL/8Pbbz6ECzabbj91iPOim//3W5 QO+eae+kJxSEL5kWhUSL31Q9 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Jun 2022 21:15:23 -0700 IronPort-SDR: 73cpDNXSZBH43EvfzbpetU94JjohwJg5QyIuTcO9L+fC79M6KIUULnmDbXVcfGCahyeexX747U w/1vq8eP2wou7AwLZkUZXjO66k6okI3ieOsiCe9KdQTPfEJ1OgZ6ebjGzZ8LiUJjiaof3PjLYF DTrXIxDszsxVKX5xDWtvXEUVggmV5GLJpjs9lNKvtpDnwF8IkQhjd2qmydWM3h4QPWXypXHSG7 wre+6eJUmV5JDyJzspzmPM5sJYUCRpJMSvco/40EfVdyLwY9u9pD7IfzUK2hlTvEo2NT704IUM esk= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Jun 2022 21:56:34 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4LHw1F4Ds8z1SHwl for ; Tue, 7 Jun 2022 21:56:33 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1654664193; x=1657256194; bh=0SMWDuWsxE3dyExXGK JTZLDWsylNdk2ZwEaW5DIMC38=; b=RBjEY3vMOhzdmXTFSVlM9jmXtBsds1LDfv 7YTqb5ke0okbqqq+jxty6gGEHx/AU4thpc91epOPO6+7PMCMHlPJS4Z+WwIWhNvR /B7NT4EeydDhfeFcRRpg/ntGxezdFruZHaJEhJ4oA0cMR8Y13308g6HF/u+Gk5LC QuQIQ4POZgEp293BWysTb7Hwxzldkuyeusx75xFokhNm3Bcfl36cZ9anU8EQyNzA xykWxxsiMcPLQ67P0PF0hgnxuHIJumJ4yt1n4/n28o9gG3rlbj3rUveyGMhkJt/5 iuoy//jjR9MgPEqxEg+djN+aQuFscqKZyBDCW0iZ83vJq0G1xDjQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Ke2KqA5JOwL9 for ; Tue, 7 Jun 2022 21:56:33 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4LHw1D2ntbz1Rvlx; Tue, 7 Jun 2022 21:56:32 -0700 (PDT) From: Damien Le Moal To: linux-fsdevel@vger.kernel.org Cc: Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v2 3/3] zonefs: fix zonefs_iomap_begin() for reads Date: Wed, 8 Jun 2022 13:56:27 +0900 Message-Id: <20220608045627.142408-4-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220608045627.142408-1-damien.lemoal@opensource.wdc.com> References: <20220608045627.142408-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org If a readahead) is issued to a sequential zone file with an offset exactly equal to the current file size, the iomap type is set to IOMAP_UNWRITTEN, which will prevent an IO, but the iomap length is calculated as 0. This causes a WARN_ON() in iomap_iter(): [17309.548939] WARNING: CPU: 3 PID: 2137 at fs/iomap/iter.c:34 iomap_iter+0x9cf/0xe80 [...] [17309.650907] RIP: 0010:iomap_iter+0x9cf/0xe80 [...] [17309.754560] Call Trace: [17309.757078] [17309.759240] ? lock_is_held_type+0xd8/0x130 [17309.763531] iomap_readahead+0x1a8/0x870 [17309.767550] ? iomap_read_folio+0x4c0/0x4c0 [17309.771817] ? lockdep_hardirqs_on_prepare+0x400/0x400 [17309.778848] ? lock_release+0x370/0x750 [17309.784462] ? folio_add_lru+0x217/0x3f0 [17309.790220] ? reacquire_held_locks+0x4e0/0x4e0 [17309.796543] read_pages+0x17d/0xb60 [17309.801854] ? folio_add_lru+0x238/0x3f0 [17309.807573] ? readahead_expand+0x5f0/0x5f0 [17309.813554] ? policy_node+0xb5/0x140 [17309.819018] page_cache_ra_unbounded+0x27d/0x450 [17309.825439] filemap_get_pages+0x500/0x1450 [17309.831444] ? filemap_add_folio+0x140/0x140 [17309.837519] ? lock_is_held_type+0xd8/0x130 [17309.843509] filemap_read+0x28c/0x9f0 [17309.848953] ? zonefs_file_read_iter+0x1ea/0x4d0 [zonefs] [17309.856162] ? trace_contention_end+0xd6/0x130 [17309.862416] ? __mutex_lock+0x221/0x1480 [17309.868151] ? zonefs_file_read_iter+0x166/0x4d0 [zonefs] [17309.875364] ? filemap_get_pages+0x1450/0x1450 [17309.881647] ? __mutex_unlock_slowpath+0x15e/0x620 [17309.888248] ? wait_for_completion_io_timeout+0x20/0x20 [17309.895231] ? lock_is_held_type+0xd8/0x130 [17309.901115] ? lock_is_held_type+0xd8/0x130 [17309.906934] zonefs_file_read_iter+0x356/0x4d0 [zonefs] [17309.913750] new_sync_read+0x2d8/0x520 [17309.919035] ? __x64_sys_lseek+0x1d0/0x1d0 Furthermore, this causes iomap_readahead() to loop forever as iomap_readahead_iter() always returns 0, making no progress. Fix this by treating reads after the file size as access to holes, setting the iomap type to IOMAP_HOLE, the iomap addr to IOMAP_NULL_ADDR and using the length argument as is for the iomap length. To simplify the code with this change, zonefs_iomap_begin() is split into the read variant, zonefs_read_iomap_begin() and zonefs_read_iomap_ops, and the write variant, zonefs_write_iomap_begin() and zonefs_write_iomap_ops. Reported-by: Jorgen Hansen Fixes: 8dcc1a9d90c1 ("fs: New zonefs file system") Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Jorgen Hansen --- fs/zonefs/super.c | 94 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 30 deletions(-) diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index 123464d2145a..053299758deb 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -110,15 +110,51 @@ static inline void zonefs_i_size_write(struct inode *inode, loff_t isize) } } -static int zonefs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, - unsigned int flags, struct iomap *iomap, - struct iomap *srcmap) +static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, + loff_t length, unsigned int flags, + struct iomap *iomap, struct iomap *srcmap) { struct zonefs_inode_info *zi = ZONEFS_I(inode); struct super_block *sb = inode->i_sb; loff_t isize; - /* All I/Os should always be within the file maximum size */ + /* + * All blocks are always mapped below EOF. If reading past EOF, + * act as if there is a hole up to the file maximum size. + */ + mutex_lock(&zi->i_truncate_mutex); + iomap->bdev = inode->i_sb->s_bdev; + iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); + isize = i_size_read(inode); + if (iomap->offset >= isize) { + iomap->type = IOMAP_HOLE; + iomap->addr = IOMAP_NULL_ADDR; + iomap->length = length; + } else { + iomap->type = IOMAP_MAPPED; + iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset; + iomap->length = isize - iomap->offset; + } + mutex_unlock(&zi->i_truncate_mutex); + + trace_zonefs_iomap_begin(inode, iomap); + + return 0; +} + +static const struct iomap_ops zonefs_read_iomap_ops = { + .iomap_begin = zonefs_read_iomap_begin, +}; + +static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, + loff_t length, unsigned int flags, + struct iomap *iomap, struct iomap *srcmap) +{ + struct zonefs_inode_info *zi = ZONEFS_I(inode); + struct super_block *sb = inode->i_sb; + loff_t isize; + + /* All write I/Os should always be within the file maximum size */ if (WARN_ON_ONCE(offset + length > zi->i_max_size)) return -EIO; @@ -128,7 +164,7 @@ static int zonefs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, * operation. */ if (WARN_ON_ONCE(zi->i_ztype == ZONEFS_ZTYPE_SEQ && - (flags & IOMAP_WRITE) && !(flags & IOMAP_DIRECT))) + !(flags & IOMAP_DIRECT))) return -EIO; /* @@ -137,47 +173,44 @@ static int zonefs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, * write pointer) and unwriten beyond. */ mutex_lock(&zi->i_truncate_mutex); + iomap->bdev = inode->i_sb->s_bdev; + iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); + iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset; isize = i_size_read(inode); - if (offset >= isize) + if (iomap->offset >= isize) { iomap->type = IOMAP_UNWRITTEN; - else + iomap->length = zi->i_max_size - iomap->offset; + } else { iomap->type = IOMAP_MAPPED; - if (flags & IOMAP_WRITE) - length = zi->i_max_size - offset; - else - length = min(length, isize - offset); + iomap->length = isize - iomap->offset; + } mutex_unlock(&zi->i_truncate_mutex); - iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); - iomap->length = ALIGN(offset + length, sb->s_blocksize) - iomap->offset; - iomap->bdev = inode->i_sb->s_bdev; - iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset; - trace_zonefs_iomap_begin(inode, iomap); return 0; } -static const struct iomap_ops zonefs_iomap_ops = { - .iomap_begin = zonefs_iomap_begin, +static const struct iomap_ops zonefs_write_iomap_ops = { + .iomap_begin = zonefs_write_iomap_begin, }; static int zonefs_read_folio(struct file *unused, struct folio *folio) { - return iomap_read_folio(folio, &zonefs_iomap_ops); + return iomap_read_folio(folio, &zonefs_read_iomap_ops); } static void zonefs_readahead(struct readahead_control *rac) { - iomap_readahead(rac, &zonefs_iomap_ops); + iomap_readahead(rac, &zonefs_read_iomap_ops); } /* * Map blocks for page writeback. This is used only on conventional zone files, * which implies that the page range can only be within the fixed inode size. */ -static int zonefs_map_blocks(struct iomap_writepage_ctx *wpc, - struct inode *inode, loff_t offset) +static int zonefs_write_map_blocks(struct iomap_writepage_ctx *wpc, + struct inode *inode, loff_t offset) { struct zonefs_inode_info *zi = ZONEFS_I(inode); @@ -191,12 +224,12 @@ static int zonefs_map_blocks(struct iomap_writepage_ctx *wpc, offset < wpc->iomap.offset + wpc->iomap.length) return 0; - return zonefs_iomap_begin(inode, offset, zi->i_max_size - offset, - IOMAP_WRITE, &wpc->iomap, NULL); + return zonefs_write_iomap_begin(inode, offset, zi->i_max_size - offset, + IOMAP_WRITE, &wpc->iomap, NULL); } static const struct iomap_writeback_ops zonefs_writeback_ops = { - .map_blocks = zonefs_map_blocks, + .map_blocks = zonefs_write_map_blocks, }; static int zonefs_writepage(struct page *page, struct writeback_control *wbc) @@ -226,7 +259,8 @@ static int zonefs_swap_activate(struct swap_info_struct *sis, return -EINVAL; } - return iomap_swapfile_activate(sis, swap_file, span, &zonefs_iomap_ops); + return iomap_swapfile_activate(sis, swap_file, span, + &zonefs_read_iomap_ops); } static const struct address_space_operations zonefs_file_aops = { @@ -647,7 +681,7 @@ static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf) /* Serialize against truncates */ filemap_invalidate_lock_shared(inode->i_mapping); - ret = iomap_page_mkwrite(vmf, &zonefs_iomap_ops); + ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops); filemap_invalidate_unlock_shared(inode->i_mapping); sb_end_pagefault(inode->i_sb); @@ -899,7 +933,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from) if (append) ret = zonefs_file_dio_append(iocb, from); else - ret = iomap_dio_rw(iocb, from, &zonefs_iomap_ops, + ret = iomap_dio_rw(iocb, from, &zonefs_write_iomap_ops, &zonefs_write_dio_ops, 0, NULL, 0); if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && (ret > 0 || ret == -EIOCBQUEUED)) { @@ -948,7 +982,7 @@ static ssize_t zonefs_file_buffered_write(struct kiocb *iocb, if (ret <= 0) goto inode_unlock; - ret = iomap_file_buffered_write(iocb, from, &zonefs_iomap_ops); + ret = iomap_file_buffered_write(iocb, from, &zonefs_write_iomap_ops); if (ret > 0) iocb->ki_pos += ret; else if (ret == -EIO) @@ -1041,7 +1075,7 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) goto inode_unlock; } file_accessed(iocb->ki_filp); - ret = iomap_dio_rw(iocb, to, &zonefs_iomap_ops, + ret = iomap_dio_rw(iocb, to, &zonefs_read_iomap_ops, &zonefs_read_dio_ops, 0, NULL, 0); } else { ret = generic_file_read_iter(iocb, to);