From patchwork Tue Apr 17 19:57:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 10346777 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 942516039A for ; Tue, 17 Apr 2018 19:57:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84A62260CD for ; Tue, 17 Apr 2018 19:57:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7802426E90; Tue, 17 Apr 2018 19:57:48 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 EC0C6260CD for ; Tue, 17 Apr 2018 19:57:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752624AbeDQT5p (ORCPT ); Tue, 17 Apr 2018 15:57:45 -0400 Received: from mail-wr0-f173.google.com ([209.85.128.173]:47100 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751204AbeDQT5o (ORCPT ); Tue, 17 Apr 2018 15:57:44 -0400 Received: by mail-wr0-f173.google.com with SMTP id d1so38740969wrj.13 for ; Tue, 17 Apr 2018 12:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:reply-to:from:subject:cc:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=k1/wvcirrp9IE1S3M/ld79JrxkLBEiBsHgtaILHLAuw=; b=iT193jib61xaOJKL4sQhqbWXcXIN1pEDGr4aPanqUq+yN8ZXVJLYQhAAPyDrBPHsXX M6FWTEp2PszDPceilvpckZf1JFYSDLcLoOkA3CGjK/NxOQlSHPe2Q+DROMi7JN/wK9OG V1yikCfrO9yQ084Qrg55H+9tRdkqWqu/rMRjxPAw1+LuYnTNyZja938Fghhk3hPhBWym dPyuNxVgmq27+9i0zx0qOcs1c91x/Sawliwv6QRZbh7u3F6M33pz4YR/jKbCjUT1BTjP j+mzZ/SXjiwXUkDQC7s1tm/3ZTaS8faPlwlrB+s/9i6K0iSCI8YY+VKzrfBktlGjTVM7 Iv4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:reply-to:from:subject:cc:message-id:date :user-agent:mime-version:content-language:content-transfer-encoding; bh=k1/wvcirrp9IE1S3M/ld79JrxkLBEiBsHgtaILHLAuw=; b=VSqFOpPkOE9C3XCi7oWUL7vc/IifwCdSoQl3Lt7GDGaH67KUOcovDCYlMLJKATuvqh oyeFiYHfivf26ySY0FgTkOIkhj4L1MygI/p6zRnrNfLuTTxhbTHYsoYSkzJVgi/SToJm KeMBleYxSj8EYnO/iLJgLHOvMItNszIqppE7MHuTWGsD3KLUo2D4PCbW9ezCVTEX4wb8 Dq+DFqTfM1QllC535nK//aAQBLEL2Wqd41qVuG21vGEyPiLBlfraeogC0N9lmcBJGwz3 pjxw2clbxDApoeGD/X52Y1935bCfHsqn0QsRiNylvSAl2ZLIK61zN/V8pCkjnOuedf0e N/3A== X-Gm-Message-State: ALQs6tAKQoVc3qC68MuENJeW9+ZU+FbR8hnrZBsnMkIydECiqwcaNkxj 7P/nR+Agttqa6rEPGt0T0v8MGw== X-Google-Smtp-Source: AIpwx4/tJwgkKlUFnfvkycug8TAvKOTkV9376/clJkTcs8tcHSsDXlGz5I1HSAz4XUp6YHwHz0BIDw== X-Received: by 10.223.152.83 with SMTP id v77mr2580141wrb.225.1523995063158; Tue, 17 Apr 2018 12:57:43 -0700 (PDT) Received: from venice.bhome (94-38-4-71.adsl-ull.clienti.tiscali.it. [94.38.4.71]) by smtp.googlemail.com with ESMTPSA id y51sm13737278wrc.38.2018.04.17.12.57.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 12:57:42 -0700 (PDT) To: Grub-devel@gnu.org Reply-To: kreijack@inwind.it From: Goffredo Baroncelli Subject: [RFC] Add support for BTRFS raid5/6 to GRUB Cc: linux-btrfs Message-ID: <2708f56e-1dac-481e-af8a-d81066df8b42@gmail.com> Date: Tue, 17 Apr 2018 21:57:40 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Content-Language: en-US Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi All, Below you can find a patch to add support for accessing files from grub in a RAID5/6 btrfs filesystem. This is a RFC because it is missing the support for recovery (i.e. if some devices are missed). In the next days (weeks ?) I will extend this patch to support also this case. Comments are welcome. BR G.Baroncelli --- commit 8c80a1b7c913faf50f95c5c76b4666ed17685666 Author: Goffredo Baroncelli Date: Tue Apr 17 21:40:31 2018 +0200 Add initial support for btrfs raid5/6 chunk diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index be195448d..4c5632acb 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -119,6 +119,8 @@ struct grub_btrfs_chunk_item #define GRUB_BTRFS_CHUNK_TYPE_RAID1 0x10 #define GRUB_BTRFS_CHUNK_TYPE_DUPLICATED 0x20 #define GRUB_BTRFS_CHUNK_TYPE_RAID10 0x40 +#define GRUB_BTRFS_CHUNK_TYPE_RAID5 0x80 +#define GRUB_BTRFS_CHUNK_TYPE_RAID6 0x100 grub_uint8_t dummy2[0xc]; grub_uint16_t nstripes; grub_uint16_t nsubstripes; @@ -764,6 +766,39 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; + break; + } + case GRUB_BTRFS_CHUNK_TYPE_RAID5: + case GRUB_BTRFS_CHUNK_TYPE_RAID6: + { + grub_uint64_t nparities; + grub_uint64_t parity_pos; + grub_uint64_t stripe_nr, high; + grub_uint64_t low; + + redundancy = 1; /* no redundancy for now */ + + if (grub_le_to_cpu64 (chunk->type) & GRUB_BTRFS_CHUNK_TYPE_RAID5) + { + grub_dprintf ("btrfs", "RAID5\n"); + nparities = 1; + } + else + { + grub_dprintf ("btrfs", "RAID6\n"); + nparities = 2; + } + + stripe_nr = grub_divmod64 (off, chunk_stripe_length, &low); + + high = grub_divmod64 (stripe_nr, nstripes - nparities, &stripen); + grub_divmod64 (high+nstripes-nparities, nstripes, &parity_pos); + grub_divmod64 (parity_pos+nparities+stripen, nstripes, &stripen); + + stripe_offset = low + chunk_stripe_length * high; + csize = chunk_stripe_length - low; + break; } default: