Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fVKbz-00011V-WC for mharc-grub-devel@gnu.org; Tue, 19 Jun 2018 13:40:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVKbx-0000xD-Jo for grub-devel@gnu.org; Tue, 19 Jun 2018 13:40:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVKbv-0007VB-Ex for grub-devel@gnu.org; Tue, 19 Jun 2018 13:40:09 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:52724) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fVKbv-0007Up-8I for grub-devel@gnu.org; Tue, 19 Jun 2018 13:40:07 -0400 Received: by mail-wm0-x244.google.com with SMTP id p126-v6so1738534wmb.2 for ; Tue, 19 Jun 2018 10:40:07 -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=HXHsG+HCuzd0F6hPIDLC8fhwygTRWMbG9BkZinznWXg=; b=MZqCFVy1qw70W6PKmWOyfK/n8Ubt/45fyP48jAJusfASHW4LyqWYaiXhUBawToO+7R m58DJ08pV5SojT/zUYt3fP4XYFNAhWYpgr5vcgHR10bHlQwjYo5OT20AKcRj051px2eW rbjX3JgN24BFbqUrLbXUkbkbGswKwx9hx97af2c9CnXjLGJnX0Wh3euAqXwK1avw37O0 3bq/bCDMdm3zeT+C8G4/jDCy+wONVEI5G2YXqPEVzkVVNUcxN78KaVYijv6SxtAmGUTs ad9aV6vA9rm30tv9m8wUwlUCXpgZe1sFBl+V9q13YkS6C9TzjQmuAm0IUwa+UOIGmFPJ 7cXg== 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=HXHsG+HCuzd0F6hPIDLC8fhwygTRWMbG9BkZinznWXg=; b=gwmOgOPAuu3+i12K3RJdbPFQPXHhm9yjVH5BWvMrsvbFQ4/kiX3xlanzze7N7SmlOv J1xNzHZ8MZ+qaQ8IZVEBvP4ppiV3W7WpWjfc3yinwB7oPcqGVm7ieoiEgVADXBntlnqv QzbMMPYT+8Djnd9suf++kMrvWFO+qWIqu63ZKsUpwgmBSG0W+2Obd3W08hVRUDtB9mWU HhTxfY8YtGMQYM0Z0T4QlOd0KQH1fUHH9aaB30YF7YgQvt4y3xuGJRaxbGwdRGitu9G+ aKkkInhS8mBsCPBuimgOz/++TvCGCPBjmC5fBpEGl5rq65cDvAfz6Y481SonJ2tqBONp DDKg== X-Gm-Message-State: APt69E2dfAopwKPUdjwkzhtC6ij6TecdGUl8R/RooYfm7VgGacZriYos arPV1GoBFieHLPnSnLLjEX9Omg== X-Google-Smtp-Source: ADUXVKII959xRtYsGlhM40GLk5ZmFaIFkbskcWhxDiqzTmtQXTJ36WMry4AqGUK73EYsIbrVMpdqWg== X-Received: by 2002:a1c:5d0e:: with SMTP id r14-v6mr12155035wmb.152.1529430005946; Tue, 19 Jun 2018 10:40:05 -0700 (PDT) Received: from venice.bhome (84-223-210-152.adsl-wholesale.clienti.tiscali.it. [84.223.210.152]) by smtp.gmail.com with ESMTPSA id i4-v6sm291776wrq.28.2018.06.19.10.40.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jun 2018 10:40:05 -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: Tue, 19 Jun 2018 19:39:48 +0200 Message-Id: <20180619173956.7356-2-kreijack@inwind.it> X-Mailer: git-send-email 2.18.0.rc2 In-Reply-To: <20180619173956.7356-1-kreijack@inwind.it> References: <20180619173956.7356-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::244 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: Tue, 19 Jun 2018 17:40:10 -0000 Signed-off-by: Goffredo Baroncelli --- grub-core/fs/btrfs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index be195448d..fbabaebbe 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,74 @@ 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 is an example of a RAID 6 layout and the meaning of the + * variables. The same applies to RAID 5. The only differences is + * that there is only one parity disk instead of two. + * + * A RAID 6 layout consists of several stripes spread + * on the disks, following a layout like the one below + * + * Disk0 Disk1 Disk2 Ddisk3 + * + * 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 is the logical address to read (from the beginning of + * the chunk space), + * - chunk_stripe_length is the size of a stripe (typically 64k), + * - nstripes is the number of disks, + * - low is the offset of the data inside a stripe, + * - stripe_offset is the disk offset from the beginning + * of the disk chunk mapping start, + * - csize is the "potential" data to read. It will be reduced to + * size if the latter is smaller. + */ + stripe_nr = grub_divmod64 (off, chunk_stripe_length, &low); + + /* + * stripen is evaluated without considering + * the parities (0 for A1, A2, A3... 1 for B1, B2...). + */ + high = grub_divmod64 (stripe_nr, nstripes - nparities, &stripen); + + /* + * stripen now considers also the parities (0 for A1, 1 for A2, + * 2 for A3....). The math is performed 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.18.0.rc2