Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fHDf5-00080v-VB for mharc-grub-devel@gnu.org; Fri, 11 May 2018 15:25:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHDf3-0007rB-F5 for grub-devel@gnu.org; Fri, 11 May 2018 15:25:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fHDey-0001tG-Is for grub-devel@gnu.org; Fri, 11 May 2018 15:25:01 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:33520) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fHDey-0001sr-Cs for grub-devel@gnu.org; Fri, 11 May 2018 15:24:56 -0400 Received: by mail-wr0-x244.google.com with SMTP id o4-v6so6356077wrm.0 for ; Fri, 11 May 2018 12:24:56 -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=fFH/oJ/7vw9/jErJx6YAoEIeft5xWtdtL5r69a1oU3w=; b=YCKWXCUwTbaS85pHN8Su1kPw9TlikjFF6bPztJi1obh18FcUILidipBlVyCM+Op3gJ pVFR68XE50EdVyqhMoIt+MdB2lD4HvW30R+3WVmEfNrYQtKgQfFxFbDjfBXCdP5lkRn+ YCQqTnp4Jk4CQ6mfrY2IHC7EXB52lclCG5Xz+2yuBAvZlVtEU6bdD3K8z4gwga1gtBRa IQVd+jsbUzO3fstVCDKGhMhFkCxn8iM+3kqe3tMvE76Kj3Ab8aivk8+DDYgsqnDWFBvn sryKNj2QMb+5mLKSFJqPrPbiay0JZpgTRCZLau8duNPM6m6VJZno12T1a0jxJlxaabo+ xlFA== 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=fFH/oJ/7vw9/jErJx6YAoEIeft5xWtdtL5r69a1oU3w=; b=Zib2LFkk3ZFbXYUS9eEohFSpq/kyWfxzowhT4FbSWDEzK0aYNQlnc4WtUCGxZa+DzW 3h4o9KKqKqMCV4bAmP+yfWOK/pcFXPo7V7xPsCSZ7NrKm2/IEOx0kC/F1UXyFvue8pO/ YANRqoZCAasCZD/mxv8phs7y7EJols8OTBmedjkLtWkhJDjF87s8q7QCW0q4O/65+Lq9 5JfM5MhfujoSNUhpCxexoVbFf3BKnFoeG1hZPaYYGC9akhg7LHiAkqAG1BIK94pHfC0M 3haSAKwXSlQQWmF+AMmVy4hPpr9a1PzbIEIsWYfXABcDbHfBhSjfrUUDY+rmZs1ExNuc WVpg== X-Gm-Message-State: ALKqPwclcj8yb4W+B21sfpeoR/HL3OSi5RzFN15HteSOu01rPMPF7P0m JfgrxMu0CYz3hGrQX+hjMUcQhA== X-Google-Smtp-Source: AB8JxZpw2465owvVAOeOcPUrup3iHq3ONyYkgpFgIY1Bf9GJFMAhzB+SpTvAEMm75CLMQyaF5GUJgg== X-Received: by 2002:adf:de87:: with SMTP id w7-v6mr208216wrl.37.1526066694996; Fri, 11 May 2018 12:24:54 -0700 (PDT) Received: from venice.bhome (94-38-18-100.adsl-ull.clienti.tiscali.it. [94.38.18.100]) by smtp.gmail.com with ESMTPSA id m134-v6sm3495664wmg.13.2018.05.11.12.24.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 12:24:54 -0700 (PDT) From: Goffredo Baroncelli X-Google-Original-From: Goffredo Baroncelli To: grub-devel@gnu.org Cc: Goffredo Baroncelli Subject: [PATCH 1/8] Add support for reading a filesystem with a raid5 or raid6 profile. Date: Fri, 11 May 2018 21:24:39 +0200 Message-Id: <20180511192446.15942-2-kreijack@inwind.it> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511192446.15942-1-kreijack@inwind.it> References: <20180511192446.15942-1-kreijack@inwind.it> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::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: Fri, 11 May 2018 19:25:02 -0000 Signed-off-by: Goffredo Baroncelli --- grub-core/fs/btrfs.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index be195448d..7e287d0ec 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,65 @@ 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; + } + + /* + * A raid 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 by the 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 number of disk) + * off -> logical address to read (from teh beginning of the + * chunk space) + * chunk_stripe_length -> size of a stripe (typically 64k) + * nstripes -> number of disks + * + */ + stripe_nr = grub_divmod64 (off, chunk_stripe_length, &low); + + high = grub_divmod64 (stripe_nr, nstripes - nparities, &stripen); + + /* + * until now stripen is evaluated without the parities (0 for A1, + * A2, A3... 1 for B1, B2...); now consider also the parities (0 + * for A1, 1 for A2, 2 for A3....); the math is done "modulo" + * number of disk + */ + grub_divmod64 (high + stripen, nstripes, &stripen); + + stripe_offset = low + chunk_stripe_length * high; + csize = chunk_stripe_length - low; + break; } default: -- 2.17.0