From patchwork Fri Jun 15 20:56:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 930258 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="z5M8JQvw"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 416t820Xxtz9s3R for ; Sat, 16 Jun 2018 06:56:34 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752884AbeFOU4d (ORCPT ); Fri, 15 Jun 2018 16:56:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:60852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752815AbeFOU4c (ORCPT ); Fri, 15 Jun 2018 16:56:32 -0400 Received: from garbanzo.do-not-panic.com (c-73-15-241-2.hsd1.ca.comcast.net [73.15.241.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D47FA208AF; Fri, 15 Jun 2018 20:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529096192; bh=Sr8SOzz0bS8WstsyRVirK6BzpqW3geyUtxWnVb0Hx64=; h=From:To:Cc:Subject:Date:From; b=z5M8JQvwILZZCi+9pCoVBaxCwadhLWXWFm6QOMVwlbzmgXPTnhAC1WkiZ7rux9QcN C//QbTT707x3KbN0+gJWPSsEpHg8/fAwKPE9mzJ3FMAOAyzoga/5UtXojunaTCFRUp tGwc8IM7yFex+kd0MEmRZ0mbicIpyogX+GBkfKi4= From: "Luis R. Rodriguez" To: tytso@mit.edu, jack@suse.com, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: snitzer@redhat.com, hare@suse.de, axboe@kernel.dk, mwilck@suse.com, "Luis R. Rodriguez" , Damien Le Moal , Bart Van Assche Subject: [PATCH] e2fsprogs: detect zoned disks and prevent their raw use Date: Fri, 15 Jun 2018 13:56:30 -0700 Message-Id: <20180615205630.7989-1-mcgrof@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Using raw zoned disks by filesystems requires special handling, only f2fs currently supports this. All other filesystems do not support dealing with zoned disks directly. As such using raw zoned disks is not supported by e2fsprogs, to use them you need to use dm-zoned-tools, format them with dzadm, set the scheduler to deadline, and then setup a dmsetup with zoned type, and somehow set this up on every boot to live a semi-happy life for now. Even if you use dmsetup on every boot, the zoned disk is still exposed, and a user may still think they have to run mkfs.ext[234] on it instead of the /dev/mapper/ disk, and then mount it by mistake. In either case you may seem to believe your disk works and only eventually end up with alignmet issues and perhaps lose you data. For instance the below was observed with XFS but its expected ext[234] users would see the same: [10869.959501] device-mapper: zoned reclaim: (sda): Align zone 865 wp 28349 to 30842 (wp+2493) blocks failed -5 [10870.014488] sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE [10870.016137] sd 0:0:0:0: [sda] tag#0 Sense Key : Illegal Request [current] [10870.017696] sd 0:0:0:0: [sda] tag#0 Add. Sense: Unaligned write command We have to prevent these mistakes by avoiding mkfs use on zoned disks. Note that this not enough yet, if users are on old AHCI controllers, the disks may not be detected as zoned. More work through udev may be required to detect this situation old old parent PCI IDs for zoned disks, and then prevent their use somehow. If you are stuck on using ext[234] there a udev rule out there [0], this is far from perfect, and not fully what we want done upstream on Linux distributions long term but it should at least help developers for now enjoy their shiny big fat zoned disks with ext[234]. This check should help avoid having folks shoot themselves in the foot for now with zoned disks. If you make the mistake to use mkfs.ext4 on a zoned disk, you will now get: # mkfs.ext4 /dev/sda mke2fs 1.44.2 (14-May-2018) /dev/sda: zoned disk detected, refer to dm-zoned-tools for how to use while setting up superblock [0] https://lkml.kernel.org/r/20180614001147.1545-1-mcgrof@kernel.org Cc: Damien Le Moal Cc: Bart Van Assche Signed-off-by: Luis R. Rodriguez --- lib/ext2fs/ext2_err.et.in | 3 +++ lib/ext2fs/initialize.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/ext2fs/ext2_err.et.in b/lib/ext2fs/ext2_err.et.in index 16abd23d..34ee5793 100644 --- a/lib/ext2fs/ext2_err.et.in +++ b/lib/ext2fs/ext2_err.et.in @@ -545,4 +545,7 @@ ec EXT2_ET_INODE_CORRUPTED, ec EXT2_ET_EA_INODE_CORRUPTED, "Inode containing extended attribute value is corrupted" +ec EXT2_ET_ZONE_UNSUPPORTED, + "zoned disk detected, refer to dm-zoned-tools for how to use" + end diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index dbe798b2..cef8ebb2 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -32,6 +32,10 @@ #define O_BINARY 0 #endif +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif + #if defined(__linux__) && defined(EXT2_OS_LINUX) #define CREATOR_OS EXT2_OS_LINUX #else @@ -85,6 +89,28 @@ static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) return rsv_gdb; } +static errcode_t is_zoned_disk(const char *path) +{ + char str[PATH_MAX]; + char *devname = basename(path); + FILE *file; + int len; + + len = snprintf(str, sizeof(str), "/sys/block/%s/queue/zoned", devname); + + /* Indicates truncation */ + if (len >= PATH_MAX) + return EXT2_ET_INVALID_ARGUMENT; + + file = fopen(str, "r"); + if (!file) + return 0; + + fclose(file); + + return EXT2_ET_ZONE_UNSUPPORTED; +} + errcode_t ext2fs_initialize(const char *name, int flags, struct ext2_super_block *param, io_manager manager, ext2_filsys *ret_fs) @@ -112,6 +138,10 @@ errcode_t ext2fs_initialize(const char *name, int flags, if (!param || !ext2fs_blocks_count(param)) return EXT2_ET_INVALID_ARGUMENT; + retval = is_zoned_disk(name); + if (retval != 0) + return retval; + retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs); if (retval) return retval;