Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2345127imm; Thu, 9 Aug 2018 11:14:07 -0700 (PDT) X-Google-Smtp-Source: AA+uWPySKCUWzZnj0eMV2av5ujk2siBAo6lx8P6Slemh30jLZmKVpdDXwWjPO9jsQk+dDRXExMZj X-Received: by 2002:a62:6283:: with SMTP id w125-v6mr3474121pfb.108.1533838447888; Thu, 09 Aug 2018 11:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533838447; cv=none; d=google.com; s=arc-20160816; b=FQ4AsPOxyCjezZaF+gus2z4GjXtlldosrKELYPAHKdA0cmSVWoAUJo0f7yZBuUicUt gmFrArN/HTpu2IQOhKCnC/aPdecPiYpwK+Q7pCbOoCGWj19i7iWMK/KoHtIE3aiaNzP2 ChR7P4AdI15RW1KYliIbflRnmXHlr7nd3Q5jTE/FuEIR6oSbe+XlAQvXTo/Kj3WSSiex pASdba3GohoOy6f02cdWN0zgFBatt4l1FXTM4mnV8UoiocUULQyAMuQLaK/9SoXPJfrU RKf183epU8F+iHYrfxCvUOp+9SJhNDkceCIfJyb8EhFK121giCAHgy/Y8YgYjNWuNGzX yeqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=hE4t/T5xBCjUgD1IFsfSM9RZtqZj7metO9MTlR+zsb8=; b=HFO/MRnL84awJcQzCj0xymf3hMo074YlOdQHgOMp3vHBtNta55ylV0S1V690ROwHdT b4TVAOi51+4mdS76POFqllwIIr5tuz8npDpVOiDHyHlt9JbpNsofKFhqZwfY6vyRbdnC +IwonAGMFODBYGPbTwzWQ/ex6WVT3JzhuHhFyFXIWxaXVkuOuSQMDOrm8uFclNpPYyS8 R5FwPp4tnTHpE5KLLbbWaiO8OgKHUKjdiBgclP2+x5aZ0rKqe89T/SbL7AgkTO+C7cKd vbb+c/8acmyvyPsNc++XRuf2yTCNJa7wOcKilI0M53rRgYNiQySVwj1wIynSsV4iGDX0 AMaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Xk+K3KwU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n137-v6si8375171pfd.177.2018.08.09.11.13.53; Thu, 09 Aug 2018 11:14:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Xk+K3KwU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727493AbeHIUhh (ORCPT + 99 others); Thu, 9 Aug 2018 16:37:37 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:38694 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727390AbeHIUhh (ORCPT ); Thu, 9 Aug 2018 16:37:37 -0400 Received: by mail-pl0-f65.google.com with SMTP id u11-v6so2881103plq.5; Thu, 09 Aug 2018 11:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=hE4t/T5xBCjUgD1IFsfSM9RZtqZj7metO9MTlR+zsb8=; b=Xk+K3KwUHXcywGM+K3ut6NnKXWYEqvXnqXIz2VvWDycdVMxNYfdkSGfQATZ0aIMiKp 1k0TWycLBJmcxbU5pLVJkEy85akmJPaupu1JfdhFso09KTcootzUISgUI57Pl9LLwJdX q31Vb+tun4nLl7X7AAnTf2kUd4bkYc7TdT68qEulTDDrF2BOiDYWqHzUaROTspX+ElJR k5c8aCbaTDBlIciziy0Wnpkiwv1BTJYkeBBDPgOF3N+9/LIMtaEkJIAQfNtMg+5r1pzA SwJVI1jUQHAUwKQAmVZPQlZzr5i5SBLdXR1EfjSblxNBDhs0V4iJ/1gTque3BsnjG5ia sqUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=hE4t/T5xBCjUgD1IFsfSM9RZtqZj7metO9MTlR+zsb8=; b=Ssa2V18CEL/BAurzSuCRsX6aSkcrrCpcii7Bq1cxvKtk5cN8UzNZ1N/vFlpuo6fAUT edLFIEioCNnndsp1YlynB8PTgpOw0amp5XEQt99SDT9b3CJMzh5Fadslj18L408oGxLs 2MsX42B6fNVz7d4tAkFeuFLGxBhzl7gMsgrJhSUsfkHJGdmRmb+ea87cgurXfgGRLCHI VV8kgoPT2vMR9P7SP3gz/rSqlA244eYaGV48sEUkCM1tCeQI9un75m7rrT/Znb+nd2kv 0hYWTj5p8aJxj6gcWtYkN19YY/uYEkFguMWtwDx7CbAz/yKSM1CuCRdCBTMTcHXpUDUc fOdg== X-Gm-Message-State: AOUpUlFxe2vU8BeVals/9pn2DVzuCHBC5Cdwr3JWq8XI8LXuj9GXJ+6T aqFrFUXxxCCCNJwS2fzwDmw= X-Received: by 2002:a17:902:6105:: with SMTP id t5-v6mr3025295plj.92.1533838295955; Thu, 09 Aug 2018 11:11:35 -0700 (PDT) Received: from localhost (h101-111-148-072.catv02.itscom.jp. [101.111.148.72]) by smtp.gmail.com with ESMTPSA id t12-v6sm14913213pgg.72.2018.08.09.11.11.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 11:11:35 -0700 (PDT) From: Naohiro Aota To: David Sterba , linux-btrfs@vger.kernel.org Cc: Chris Mason , Josef Bacik , linux-kernel@vger.kernel.org, Hannes Reinecke , Damien Le Moal , Bart Van Assche , Matias Bjorling , Naohiro Aota Subject: [RFC PATCH 10/12] btrfs-progs: device-add: support HMZONED device Date: Fri, 10 Aug 2018 03:11:03 +0900 Message-Id: <20180809181105.12856-10-naota@elisp.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180809181105.12856-1-naota@elisp.net> References: <20180809180450.5091-1-naota@elisp.net> <20180809181105.12856-1-naota@elisp.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch check if the target file system is flagged as HMZONED. If it is, the device to be added is flagged PREP_DEVICE_HMZONED. Also add checks to prevent mixing non-zoned devices and zoned devices. Signed-off-by: Naohiro Aota --- cmds-device.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index 2a05f70a..10696bf7 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -56,6 +56,9 @@ static int cmd_device_add(int argc, char **argv) int discard = 1; int force = 0; int last_dev; + int res; + int hmzoned; + struct btrfs_ioctl_feature_flags feature_flags; optind = 0; while (1) { @@ -91,12 +94,33 @@ static int cmd_device_add(int argc, char **argv) if (fdmnt < 0) return 1; + res = ioctl(fdmnt, BTRFS_IOC_GET_FEATURES, &feature_flags); + if (res) { + error("error getting feature flags '%s': %m", mntpnt); + return 1; + } + hmzoned = feature_flags.incompat_flags & BTRFS_FEATURE_INCOMPAT_HMZONED; + for (i = optind; i < last_dev; i++){ struct btrfs_ioctl_vol_args ioctl_args; - int devfd, res; + int devfd; u64 dev_block_count = 0; char *path; + if (hmzoned && zoned_model(argv[i]) == ZONED_NONE) { + error("cannot add non-zoned device to HMZONED file system '%s'", + argv[i]); + ret++; + continue; + } + + if (!hmzoned && zoned_model(argv[i]) == ZONED_HOST_MANAGED) { + error("cannot add host managed zoned device to non-HMZONED file system '%s'", + argv[i]); + ret++; + continue; + } + res = test_dev_for_mkfs(argv[i], force); if (res) { ret++; @@ -112,7 +136,8 @@ static int cmd_device_add(int argc, char **argv) res = btrfs_prepare_device(devfd, argv[i], &dev_block_count, 0, PREP_DEVICE_ZERO_END | PREP_DEVICE_VERBOSE | - (discard ? PREP_DEVICE_DISCARD : 0)); + (discard ? PREP_DEVICE_DISCARD : 0) | + (hmzoned ? PREP_DEVICE_HMZONED : 0)); close(devfd); if (res) { ret++; -- 2.18.0