Skip to contentSkip to conversation

grub-0.97: btrfs multidevice configuration support

PATCH In review Edward Shishkin 2 participants 5 messages Sep 24, 2009 – Dec 11, 2009 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 grub-0.97: btrfs multidevice configuration support

---
 grub/Makefile.am    |    2 
 stage2/btrfs.h      |   55 ++--
 stage2/builtins.c   |   10 
 stage2/disk_io.c    |    2 
 stage2/filesys.h    |    4 
 stage2/fsys_btrfs.c |  693 +++++++++++++++++++++++++++++++++++++++++-----------
 6 files changed, 595 insertions(+), 171 deletions(-)
stage2/btrfs.h +28 -27
@@ -124,6 +124,7 @@ static int btrfs_csum_sizes[] = { 4, 0 }
 #define BTRFS_DEFAULT_NUM_DEVICES     1
 #define BTRFS_DEFAULT_NODE_SIZE       4096
 #define BTRFS_DEFAULT_LEAF_SIZE       4096
+#define BTRFS_NUM_CACHED_DEVICES      128
 
 #define WARN_ON(c)
 #define cassert(cond) ({ switch (-1) { case (cond): case 0: break; } })
@@ -315,13 +316,22 @@ struct btrfs_node {
 	struct btrfs_key_ptr ptrs[];
 } __attribute__ ((__packed__));
 
+struct btrfs_device {
+	/* the internal btrfs device id */
+	u64 devid;
+	/* the internal grub device representation */
+	unsigned long drive;
+	unsigned long part;
+	unsigned long length;
+};
+
 struct extent_buffer {
 	/* metadata */
+	struct btrfs_device dev;
 	u64 start;
 	u64 dev_bytenr;
 	u32 len;
-	int refs;
-	int flags;
+	/* data */
 	char *data;
 };
 
@@ -555,12 +565,8 @@ struct btrfs_block_group_item {
 struct btrfs_root {
 	struct extent_buffer   node;
 	char                   data[4096];
-	struct extent_buffer   *commit_root;
 	struct btrfs_root_item root_item;
-	struct btrfs_key       root_key;
-	struct btrfs_fs_info   *fs_info;
 	u64 objectid;
-	u64 last_trans;
 
 	/* data allocations are done in sectorsize units */
 	u32 sectorsize;
@@ -573,42 +579,31 @@ struct btrfs_root {
 
 	/* leaf allocations are done in leafsize units */
 	u32 stripesize;
+};
 
-	int ref_cows;
-	int track_dirty;
-
-
-	u32 type;
-	u64 highest_inode;
-	u64 last_inode_alloc;
+struct btrfs_file_info {
+	struct btrfs_key key;
 };
 
 struct btrfs_root;
 struct btrfs_fs_devices;
 struct btrfs_fs_info {
 	u8 fsid[BTRFS_FSID_SIZE];
-	u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
 	struct btrfs_root fs_root;
 	struct btrfs_root tree_root;
 	struct btrfs_root chunk_root;
 
-	struct btrfs_key  file_info; /* currently opened file */
+	struct btrfs_file_info file_info; /* currently opened file */
 	struct btrfs_path paths [LAST_LOOKUP_POOL];
 
-	u64 generation;
-	u64 last_trans_committed;
+	char mbr[SECTOR_SIZE];
 
-	u64 system_alloc_profile;
-	u64 alloc_start;
+	int sb_mirror;
+	u64 sb_transid;
+	struct btrfs_device sb_dev;
+   	struct btrfs_super_block sb_copy;
 
-	struct btrfs_super_block super_temp;
-   	struct btrfs_super_block super_copy;
-
-	u64 super_bytenr;
-	u64 total_pinned;
-
-	int system_allocs;
-	int readonly;
+	struct btrfs_device devices[BTRFS_NUM_CACHED_DEVICES + 1];
 };
 
 /*
@@ -1129,6 +1124,11 @@ static inline void btrfs_set_key_type(st
 	key->type = val;
 }
 
+static inline u64 btrfs_super_devid(struct btrfs_super_block *disk_super)
+{
+	return le64_to_cpu(disk_super->dev_item.devid);
+}
+
 /* struct btrfs_header */
 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
@@ -1317,6 +1317,7 @@ struct btrfs_fs_devices {
 };
 
 struct btrfs_bio_stripe {
+	struct btrfs_device dev;
 	u64 physical;
 };
 
stage2/fsys_btrfs.c +553 -140

958 lines not on this page · raw message

stage2/filesys.h +2 -2
@@ -137,8 +137,8 @@ int iso9660_dir (char *dirname);
 #ifndef NUM_FSYS
 #define NUM_FSYS	\
   (FSYS_FFS_NUM + FSYS_FAT_NUM + FSYS_EXT2FS_NUM + FSYS_MINIX_NUM	\
-   + FSYS_REISERFS_NUM + FSYS_VSTAFS_NUM + FSYS_JFS_NUM + FSYS_XFS_NUM	\
-   + FSYS_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM)
+   + FSYS_REISERFS_NUM + FSYS_BTRFS_NUM + FSYS_VSTAFS_NUM + FSYS_JFS_NUM \
+   + FSYS_XFS_NUM + FSYS_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM)
 #endif
 
 /* defines for the block filesystem info area */
grub/Makefile.am +1 -1
@@ -8,7 +8,7 @@ endif
 
 AM_CPPFLAGS = -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
 	-DFSYS_ISO9660=1 -DFSYS_JFS=1 -DFSYS_MINIX=1 -DFSYS_REISERFS=1 \
-	-DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
+	-DFSYS_BTRFS=1 -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
 	-DUSE_MD5_PASSWORDS=1 -DSUPPORT_HERCULES=1 \
 	$(SERIAL_FLAGS) -I$(top_srcdir)/stage2 \
 	-I$(top_srcdir)/stage1 -I$(top_srcdir)/lib
stage2/disk_io.c +1 -1
@@ -65,7 +65,7 @@ struct fsys_entry fsys_table[NUM_FSYS + 
   {"reiserfs", reiserfs_mount, reiserfs_read, reiserfs_dir, 0, reiserfs_embed},
 # endif
 # ifdef FSYS_BTRFS
-  {"btrfs", btrfs_mount, btrfs_read, btrfs_dir, 0, 0},
+  {"btrfs", btrfs_mount, btrfs_read, btrfs_dir, 0, btrfs_embed},
 # endif
 # ifdef FSYS_VSTAFS
   {"vstafs", vstafs_mount, vstafs_read, vstafs_dir, 0, 0},
stage2/builtins.c +10 -0
@@ -2423,6 +2423,16 @@ install_func (char *arg, int flags)
 	  else
 #endif /* GRUB_UTIL */
 	    {
+	      /*
+	       * FIXME: Ugly hack.
+	       * Do not write to btrfs partition
+	       * without a help of the file system!
+	       */
+	      if (!strcmp(fsys_table[fsys_type].name, "btrfs"))
+		{
+		  errnum = ERR_BAD_ARGUMENT;
+		  goto fail;
+		}
 	      if (! devwrite (*saved_sector - part_start, 1, stage2_buffer))
 		goto fail;
 	    }
#1 lore raw

Am Freitag 25 September 2009 00:06:40 schrieb Edward Shishkin:

Quoted 1 line

Hi Edward,

I was pointed to a problem with this patch.

+static u64 scan_grub_devices(struct btrfs_device *dev,
+ int (*discerner)(struct btrfs_device **, int),
+ int lookup)
+{
...
+#ifdef SUPPORT_NETBOOT
+ errnum = ERR_NONE;
+ if (network_ready &&
+ !get_diskinfo(NETWORK_DRIVE, &geom)) {

+               dev->drive = NETWORK_DRIVE;
+               dev->part = 0;
+               dev->length = geom.total_sectors;
+               if (discerner(&dev, lookup)) {

+ count++;
+ if (lookup)
+ goto exit;
+ }
+ }
+#endif /* SUPPORT_NETBOOT */
+ exit:
+ return count;
+}

This won't compile since network_ready is undeclared. Why is the btrfs code dealing with network devices at all?

regards
Johannes

#2 lore raw
Quoted 30 lines · Johannes Hirte

Am Freitag 25 September 2009 00:06:40 schrieb Edward Shishkin:

Hi Edward,

I was pointed to a problem with this patch.

(quoted diff) +21 -0
+static u64 scan_grub_devices(struct btrfs_device *dev,
+                            int (*discerner)(struct btrfs_device **, int),
+                            int lookup)
+{
...
+#ifdef SUPPORT_NETBOOT
+       errnum = ERR_NONE;
+       if (network_ready &&
+           !get_diskinfo(NETWORK_DRIVE, &geom)) {
+               dev->drive = NETWORK_DRIVE;
+               dev->part = 0;
+               dev->length = geom.total_sectors;
+               if (discerner(&dev, lookup)) {
+                       count++;
+                       if (lookup)
+                               goto exit;
+               }
+       }
+#endif /* SUPPORT_NETBOOT */
+ exit:
+       return count;
+}
Quoted 1 line

This won't compile since network_ready is undeclared.

Yup, indeed..

Quoted 3 lines

Why is the btrfs code
dealing with network devices at all?

Why not? :)
Well, would you please disable it for now with the attached patch?

Thanks,
Edward.

Disable booting from network devices.

---
 stage2/fsys_btrfs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
stage2/fsys_btrfs.c +2 -2
@@ -452,7 +452,7 @@ static u64 scan_grub_devices(struct btrf
 				goto exit;
 		}
 	}
-#ifdef SUPPORT_NETBOOT
+#if 0
 	errnum = ERR_NONE;
 	if (network_ready &&
 	    !get_diskinfo(NETWORK_DRIVE, &geom)) {
@@ -465,7 +465,7 @@ static u64 scan_grub_devices(struct btrf
 				goto exit;
 		}
 	}
-#endif /* SUPPORT_NETBOOT */
+#endif /* 0 */
  exit:
 	return count;
 }
#3 lore raw

Am Dienstag 03 November 2009 01:59:39 schrieb Edward Shishkin:

Quoted 5 lines
Quoted 2 lines · Johannes Hirte

Why is the btrfs code
dealing with network devices at all?

Why not? :)

I don't see the possiblity to get a btrfs filesystem this way. So as far as I understand this, it's complete useless. The CD support doesn't look very usefull too to me. It's possible to put a btrfs filesystem on a CD or DVD. But that seems rather theoretical.

regards,
Johannes

#4 lore raw
Quoted 4 lines · Johannes Hirte

Am Dienstag 03 November 2009 01:59:39 schrieb Edward Shishkin:

Quoted 2 lines

Johannes Hirte wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Why is the btrfs code
dealing with network devices at all?

Why not? :)

I don't see the possiblity to get a btrfs filesystem this way. So as far as I understand this, it's complete useless. The CD support doesn't look very usefull too to me. It's possible to put a btrfs filesystem on a CD or DVD. But that seems rather theoretical.

Ok, let's keep this theoretical possibility,
I don't see wrong things here..

Thanks,
Edward.