Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fJ1TX-000095-B1 for mharc-grub-devel@gnu.org; Wed, 16 May 2018 14:48:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJ1TT-00007f-SG for grub-devel@gnu.org; Wed, 16 May 2018 14:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJ1TP-0006tV-Qr for grub-devel@gnu.org; Wed, 16 May 2018 14:48:31 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35358) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fJ1TP-0006t9-Jg for grub-devel@gnu.org; Wed, 16 May 2018 14:48:27 -0400 Received: by mail-wm0-x243.google.com with SMTP id o78-v6so4277177wmg.0 for ; Wed, 16 May 2018 11:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6AVpdHy/VprWAwETMALDBpDWq6r6k52lr1+prsLRBGE=; b=d2Hb+CDcy3GgFyn2Zdf+74ZBwvEQXhIyxvgQUOI84FP8URLl/K0zjRmzK9vc2Dp59S IEdMdaMcWLdmFHZ//m7Ev9isrzQz1YlcXOoTAZAVc465xfD9eshhcvLvKEiUp4z9Awvf ZeGtDXgBj9xONeh3mHQEXcfb6ztGdYadL4iUogKsX2VtEb0XT0YTCg6ylCWfj/yuS25D SSDmr7inDXauI7VoxOItW+5TrVW+vit1o3wXnIg4AfZgntCryBcN9vwWB5QDAAIwgER4 1UwNa9DS5ct4cleSn6vEL/v28QjKPOuZHIY4ojmUi8Yr36Mjf8DwgF4zsD+gMDBfJjEk B0Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6AVpdHy/VprWAwETMALDBpDWq6r6k52lr1+prsLRBGE=; b=l3/Q2VgoM0hFsz5dU39Z+8Xia4ItoroS1+e29JxOrpXQOdIPpNOdP1u6HUQfSlhfHp LHpa77wVmCSTcoyILY0dWc+BoQnll9ejuMo6jg/syPNkvxw8r1REKTKA/iunAMJac9m2 M8DMnFZoIZfWBaEInvme+N1EArSoemVnAzsasj410jToLIC9Aw3VSx9EznmHiC6QmbSW YGWwPEWUnTvZSUI+Ya0RG908wzgGX5VfNILxwpRoRe9GXR2XmkjdiIwB6pwzbZmZtcxg aQebV0bZCZaS1Bu0NY54PottBU7MeF0xEMmGBkqKgWNafpGVBtoCK/Q+9YI0CKEhMtPV /9KA== X-Gm-Message-State: ALKqPwc4K9gDjgQm/MVEkBGz8NJHLcYSrhDXYvcqIT+SgSWEQUkarKGE iokHsH61IB7cnTMs4vLQEam71Q== X-Google-Smtp-Source: AB8JxZr1f44MrrDFA8yljKMHM3nBPfw+EyigXESdtd89et9uRuOO4xTX9nAHKBOE4JuPmks6vYfLjA== X-Received: by 2002:a1c:4ad9:: with SMTP id n86-v6mr1679322wmi.0.1526496506093; Wed, 16 May 2018 11:48:26 -0700 (PDT) Received: from venice.bhome (94-38-2-55.adsl-ull.clienti.tiscali.it. [94.38.2.55]) by smtp.gmail.com with ESMTPSA id d17-v6sm3797129wrc.0.2018.05.16.11.48.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 May 2018 11:48:25 -0700 (PDT) From: Goffredo Baroncelli X-Google-Original-From: Goffredo Baroncelli To: grub-devel@gnu.org Cc: Goffredo Baroncelli Subject: [PATCH 1/9] btrfs: add support for reading a filesystem with a RAID 5 or RAID 6 profile. Date: Wed, 16 May 2018 20:48:11 +0200 Message-Id: <20180516184819.23736-2-kreijack@inwind.it> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180516184819.23736-1-kreijack@inwind.it> References: <20180516184819.23736-1-kreijack@inwind.it> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 May 2018 18:48:33 -0000 Signed-off-by: Goffredo Baroncelli --- grub-core/fs/btrfs.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index be195448d..394611cbb 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,72 @@ 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, stripe_nr, high, 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; + } + + /* + * Below an example of a RAID6 layout and the meaning of the + * variables. The same apply to RAID5. The only differences is that + * there is only one parity instead of two. + * + * A RAID6 6 layout consists in several stripes spread + * on the disks, following a layout like the one below + * + * Disk1 Disk2 Disk3 Ddisk4 + * + * A1 B1 P1 Q1 + * Q2 A2 B2 P2 + * P3 Q3 A3 B3 + * [...] + * + * Note that the placement of the parities depends on row index; + * In the code below: + * stripe_nr -> is the stripe number not considering the parities + * (A1=0, B1=1, A2 = 2, B2 = 3, ...) + * high -> is the row number (0 for A1...Q1, 1 for Q2..P2, ...) + * stripen -> is the column number (or disk number) + * off -> logical address to read (from the beginning of the + * chunk space) + * chunk_stripe_length -> size of a stripe (typically 64k) + * nstripes -> number of disks + * low -> offset of the data inside a stripe + * + */ + stripe_nr = grub_divmod64 (off, chunk_stripe_length, &low); + + /* + * In the line below stripen is evaluated without considering + * the parities (0 for A1, A2, A3... 1 for B1, B2...); + */ + high = grub_divmod64 (stripe_nr, nstripes - nparities, &stripen); + + /* + * In the line below stripen, now consider also the parities (0 + * for A1, 1 for A2, 2 for A3....); the math is done "modulo" + * number of disks + */ + grub_divmod64 (high + stripen, nstripes, &stripen); + + stripe_offset = low + chunk_stripe_length * high; + csize = chunk_stripe_length - low; + break; } default: -- 2.17.0