From patchwork Fri Oct 28 08:45:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 9401601 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 18BB660588 for ; Fri, 28 Oct 2016 08:47:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F27C2A673 for ; Fri, 28 Oct 2016 08:47:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02AC92A675; Fri, 28 Oct 2016 08:47:02 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 5A5C82A673 for ; Fri, 28 Oct 2016 08:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758705AbcJ1Iq5 (ORCPT ); Fri, 28 Oct 2016 04:46:57 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:55263 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756227AbcJ1Iqm (ORCPT ); Fri, 28 Oct 2016 04:46:42 -0400 X-IronPort-AV: E=Sophos;i="5.31,557,1473091200"; d="scan'208";a="25250753" Received: from mail-bl2nam02lp0083.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([207.46.163.83]) by ob1.hgst.iphmx.com with ESMTP; 28 Oct 2016 16:46:40 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=GU3IQpI+qRgITgAFNC159f5a6tOE3c27cML3DABulgQ=; b=oWgCX21VePK0oDU5OVi5Vois0R3PR1vJ/ABGP4lnLC6RyPNgVgdmlmX0K3xV+1DfXcE8dALqmRci0ZCz3UtPPNp3Q0016pxu0chZi745Y+2n33eM/7aqzCfJFxmFyQ61R5cHydgu2Z8ryFiVmg+EVdbX6t4OxWFMZdNCQP1cQmA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Damien.LeMoal@wdc.com; Received: from washi.fujisawa.hgst.com (199.255.47.8) by BY2PR04MB1974.namprd04.prod.outlook.com (10.166.111.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12; Fri, 28 Oct 2016 08:46:37 +0000 From: Damien Le Moal To: , CC: , , Hannes Reinecke , Shaun Tancheff , Damien Le Moal Subject: [PATCH v2 8/9] f2fs: Reset sequential zones on zoned block devices Date: Fri, 28 Oct 2016 17:45:06 +0900 Message-ID: <1477644307-30115-9-git-send-email-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477644307-30115-1-git-send-email-damien.lemoal@wdc.com> References: <1477644307-30115-1-git-send-email-damien.lemoal@wdc.com> MIME-Version: 1.0 X-Originating-IP: [199.255.47.8] X-ClientProxiedBy: CY1PR19CA0030.namprd19.prod.outlook.com (10.162.38.168) To BY2PR04MB1974.namprd04.prod.outlook.com (10.166.111.14) X-MS-Office365-Filtering-Correlation-Id: 0a96625e-7c3e-43fc-3b1f-08d3ff0eeed8 X-Microsoft-Exchange-Diagnostics: 1; BY2PR04MB1974; 2:UvjayoEXV4zLjf+h5lD4DpjGwSPP6A/Eu7ayuReKoqZswTufz5cw/1WOBa+kTDdvn08E5MN9exBoUMS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IHtq60VjaJVhCXwfd8WygNHgqjxqoyp5CKbRYEfLkMi4hbJdVderZWqyeE= X-Microsoft-Exchange-Diagnostics: 1; BY2PR04MB1974; 31:XHcfum9zLkw8496kBxKm+2HJqe8h6nLtyTxyXObbdCAONuxgzhd5x/tC/QXroxMhytfTQi3G0NDnoQEWJPnkSh1ifn+P7zbxbbgEqJeGIIe5cjP4lwvyJKswr3c0Pg9ti3YBrVcuH3PjhCp/1efdFgTHlx1YFJihGhaUXE4Ww+N3kfivfITXlZRBdX/ztoOmCzXFIbwtDF8R6ig52GJrlqCa0GzmfhKSWyqDbWzwIomgRWpS2EYFIwYLf/6qMeIv; 20:fUKXbb6T0HTEz8TSo01sDglGNZ6he8G9aWS2H7yH81VJ1lY6juVBU3EUejzveNXF/nUfMevsOKG4epawIusX7EDw1X+42fekazdbVsd+Iq9lOE/85w12xC5wXJQB98FkP4AYdJw2vyKvhAUI9J4FM0YKbzBqbE5tus0+gge+FrMZszXk+fHV06kl/OIYUi8xVwkbujvTlhYi4L1phMkPwooqJNuQQQmVZ7PwxqU22Sv6FGQSUoZzYxTrY5KaGjphlhc6YoMBGuzTsBjx4fuFhyySG/ymV0hROTyRunzsGk3KMDBNgwNnyDNCMCYD0QCiUfEowFIQ07JsJypITWnsguMp0irNda9htL9SQm6PfglF9ZPHqSQEuqlkGaFf0KKPqzULqNsOE3M7rtV/S3WnW2L4vfhtQefBUZbpkRjvdn+vmTOMewjuUd640OrXE2B+5Js8gdLkexETcxBLmT9KZTjyx5F+mkV01Va1nBzXoO1l3fH0S3WIT1lLcQAZxa6X X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:BY2PR04MB1974; BCL:0; PCL:0; RULEID:; SRVR:BY2PR04MB1974; X-Microsoft-Exchange-Diagnostics: 1; BY2PR04MB1974; 4:23i8t945vVJYcp1d3dHwvRiBkd4iD/fCfRCVTWpU4ppu99y0sgLbu/Sdxn7DkGbpxAuN7RLeap6iEInzf4XW2W6JecFMMofwYx7JnNjMPoSpYm5fwfGhyqfK7/H5DsyrvQkyRQRp31g6PlrSgv8lTY326MsAnSRliXlFQPFTunIDUYtC3icDP1BwKoe3v5tFkJTDxOg0/jemn+NZrmMv9mIU6KtpQ+Ezkf4g9vGTexmoyoPE6O2+9uA1rLDlHgXsAUXX9Wna28fe+ZS+K5Nj+GLcWQTSUHlM4dI/oIaamy5YWXTboh0N4/edPiHorL397792QLBEudhEWa6bpWQEjWoW0MSy5EXQJmhTd1VyKuVwlASCoP43lcfV1Cmjo6lL9iIsMbGmexVPQToQ3gH7ZYYBkfNsqzvBQ7SHcPXgK14= X-Forefront-PRVS: 0109D382B0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(76176999)(2950100002)(50986999)(305945005)(42186005)(7846002)(6666003)(4326007)(86362001)(7736002)(5660300001)(106356001)(81166006)(81156014)(66066001)(47776003)(68736007)(48376002)(105586002)(8676002)(50466002)(5003940100001)(229853001)(92566002)(50226002)(101416001)(33646002)(19580405001)(586003)(6116002)(19580395003)(3846002)(36756003)(77096005)(189998001)(5001770100001)(2906002)(97736004)(7099028); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR04MB1974; H:washi.fujisawa.hgst.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: wdc.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR04MB1974; 23:5m7LupXrTrl5xp6hr5y9YG/ey9dvgzlFg1q9RpzFK?= =?us-ascii?Q?4nVldF8f8bKl6u++R/zRUgZ94HoA0dambdjLN6lHV3PO8cg+j75ESQZDmmL2?= =?us-ascii?Q?WAAEovoDqlCGjQ3PmxVtWHCvW5w7s4SUXn1ZYB98jm6X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PQcdg7opS6+7Nb7BhgeWP5P2qNOFM5DItdqbXgcFXVxA8B3HZ/8cT/ApYTaA2Dlz/G7FfMHnw/M0h6H5pWAs4ORnKkwXOk942wGIh57M8qkTkKoc=; 20:vstA3CPyIauXS5dfH82YRBVi6KhgZ+GEtDSG2/6uJ3Id8eoH0jq+QOfR9Sudpu+R30Y+OM1/tBlWJZRypStcUtjI26iTmK6Tex6D6Vi2OE2o5tz2k/PTRy/CdqibeN0H5t3Miu4KLC3Sxlk8rPndpg4LOnl7zmUdrgOdjN6YfqvFbx/JpzA0/KOTsJW2YDLjrTy2z/PFKt3l0QYb1iufwfJBgYPc0LIPPCsulEziI6Qq7m7IqkegZ6oslzuratYC X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2016 08:46:37.6443 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR04MB1974 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 When a zoned block device is mounted, discarding sections contained in sequential zones must reset the zone write pointer. For sections contained in conventional zones, the regular discard is used if the drive supports it. Signed-off-by: Damien Le Moal --- fs/f2fs/segment.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index fc886f0..ee66e08 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "f2fs.h" #include "segment.h" @@ -633,15 +634,19 @@ static void f2fs_submit_bio_wait_endio(struct bio *bio) } /* this function is copied from blkdev_issue_discard from block/blk-lib.c */ -int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi, sector_t sector, - sector_t nr_sects, gfp_t gfp_mask, unsigned long flags) +static int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi, + block_t blkstart, block_t blklen) { struct block_device *bdev = sbi->sb->s_bdev; struct bio *bio = NULL; int err; - err = __blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, flags, - &bio); + trace_f2fs_issue_discard(sbi->sb, blkstart, blklen); + + err = __blkdev_issue_discard(bdev, + SECTOR_FROM_BLOCK(blkstart), + SECTOR_FROM_BLOCK(blklen), + GFP_NOFS, 0, &bio); if (!err && bio) { struct bio_entry *be = __add_bio_entry(sbi, bio); @@ -654,11 +659,50 @@ int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi, sector_t sector, return err; } +#ifdef CONFIG_BLK_DEV_ZONED +static int f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, + block_t blkstart, block_t blklen) +{ + sector_t sector = SECTOR_FROM_BLOCK(blkstart); + sector_t nr_sects = SECTOR_FROM_BLOCK(blklen); + struct block_device *bdev = sbi->sb->s_bdev; + + if (nr_sects != bdev_zone_size(bdev)) { + f2fs_msg(sbi->sb, KERN_INFO, + "Unaligned discard attempted (sector %llu + %llu)", + (unsigned long long)sector, + (unsigned long long)nr_sects); + return -EIO; + } + + /* + * We need to know the type of the zone: for conventional zones, + * use regular discard if the drive supports it. For sequential + * zones, reset the zone write pointer. + */ + switch (get_blkz_type(sbi, blkstart)) { + + case BLK_ZONE_TYPE_CONVENTIONAL: + if (!blk_queue_discard(bdev_get_queue(bdev))) + return 0; + return __f2fs_issue_discard_async(sbi, blkstart, + blklen); + + case BLK_ZONE_TYPE_SEQWRITE_REQ: + case BLK_ZONE_TYPE_SEQWRITE_PREF: + return blkdev_reset_zones(bdev, sector, + nr_sects, GFP_NOFS); + + default: + /* Unknown zone type: broken device ? */ + return -EIO; + } +} +#endif + static int f2fs_issue_discard(struct f2fs_sb_info *sbi, block_t blkstart, block_t blklen) { - sector_t start = SECTOR_FROM_BLOCK(blkstart); - sector_t len = SECTOR_FROM_BLOCK(blklen); struct seg_entry *se; unsigned int offset; block_t i; @@ -670,8 +714,13 @@ static int f2fs_issue_discard(struct f2fs_sb_info *sbi, if (!f2fs_test_and_set_bit(offset, se->discard_map)) sbi->discard_blks--; } - trace_f2fs_issue_discard(sbi->sb, blkstart, blklen); - return __f2fs_issue_discard_async(sbi, start, len, GFP_NOFS, 0); + +#ifdef CONFIG_BLK_DEV_ZONED + if (f2fs_sb_mounted_blkzoned(sbi->sb)) + return f2fs_issue_discard_zone(sbi, blkstart, blklen); +#endif + + return __f2fs_issue_discard_async(sbi, blkstart, blklen); } static void __add_discard_entry(struct f2fs_sb_info *sbi,