Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1OGNiD-0002i8-TD for mharc-grub-devel@gnu.org; Sun, 23 May 2010 22:48:17 -0400 Received: from [140.186.70.92] (port=49088 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGNiB-0002gN-Fs for grub-devel@gnu.org; Sun, 23 May 2010 22:48:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGNi8-0005xr-Ty for grub-devel@gnu.org; Sun, 23 May 2010 22:48:15 -0400 Received: from mail2.asahi-net.or.jp ([202.224.39.198]:47597) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGNi8-0005xf-Dl for grub-devel@gnu.org; Sun, 23 May 2010 22:48:12 -0400 Received: from rabbit.sekiba.org (x238029.ppp.asahi-net.or.jp [122.249.238.29]) by mail2.asahi-net.or.jp (Postfix) with ESMTP id 5B8F3A42A7 for ; Mon, 24 May 2010 11:48:08 +0900 (JST) Date: Mon, 24 May 2010 11:48:08 +0900 Message-ID: <87sk5i9frr.wl%jir@sekiba.com> From: Jiro SEKIBA To: The development of GNU GRUB In-Reply-To: <87ljba3k30.wl%jir@sekiba.com> References: <87r5lhi4u4.wl%jir@sekiba.com> <4BF2BE7E.3090701@gmail.com> <87ljba3k30.wl%jir@sekiba.com> User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.7 Emacs/22.3 (i486-pc-linux-gnu) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Subject: Re: [PATCH]add supporting second super block of nilfs2 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 May 2010 02:48:16 -0000 Oops I forgot to supply ChangeLog entry. I'll resend the patch. Sorry for the careless-miss. At Sun, 23 May 2010 20:59:15 +0900, Jiro SEKIBA wrote: >=20 > [1 ] > Hi, >=20 > Thank you for the comments. >=20 > At Tue, 18 May 2010 18:21:18 +0200, > Vladimir '=F6-coder/phcoder' Serbinenko wrote: > >=20 > > Jiro SEKIBA wrote: > > > Hi, > > > > > > This is a patch to support second super block of nilfs2. > > > It will use the second super block when first one is accidentally > > > collapsed or not synced properly. > > > > > > =20 > > Is it limited to only 2 blocks? >=20 > Yes, nilfs2 has super blocks at the beginning and the end of the partitio= n. >=20 > > > NILFS has redundant super blocks. Those are identical if unmounted c= leanly. > > > However when one of these is collapsed or old, correct one or newer o= ne > > > should be used to find latest log correctly. > > > > > > Test on both PPC and x86. > > > > > > =20 > >=20 > > + grub_disk_read (disk, 1 * 2, 0, sizeof (struct grub_nilfs2_super_blo= ck), > > + &data->sblock); > > Please macroify > >=20 > > + grub_disk_read (disk, (disk->total_sectors - 8), 0, > > + sizeof (struct grub_nilfs2_super_block), &sb2); > > total_sectors is a size of disk, not partition. Use grub_disk_get_size = to automatically get the size of underlying object (disk or partition). > > Some disks have unknown size. CDROM is an example of it. Even worse try= ing to read from a sector past the boundary will hang the system for few mi= nutes. > > Disks on OFW suffer the same problem. Perhaps we should add GRUB_DISK_S= IZE_UNKNOWN 0xffffffffffffffffULL for this case >=20 > Thank you the correction. > I fixed to use grub_disk_get_size() to obtain the size. > Also, I added the macro in grub/disk.h for the case that size > of partition is unknown. >=20 > > as an indicator and avoid querying back labels of such disks > > + /* Swap if first super block is invalid or oloder than second one. */ > >=20 > > Typo > >=20 > > Could you supply the ChangeLog entry? > >=20 > > --=20 > > Regards > > Vladimir '=F6-coder/phcoder' Serbinenko > >=20 > >=20 >=20 > --=20 > Jiro SEKIBA >=20 > [2 nilfs2-support-2nd-sbv2.patch ] > =3D=3D=3D modified file 'fs/nilfs2.c' > --- fs/nilfs2.c 2010-04-24 20:09:08 +0000 > +++ fs/nilfs2.c 2010-05-23 19:50:16 +0000 > @@ -49,6 +49,13 @@ > #define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1) > #define NILFS_BTREE_LEVEL_MAX 14 > =20 > +/* nilfs 1st super block posission from beginning of the partition > + in 512 block size */ > +#define NILFS_1ST_SUPER_BLOCK 2 > +/* nilfs 2nd super block posission from end of the partition > + in 512 block size */ > +#define NILFS_2ND_SUPER_BLOCK 8 > + > struct grub_nilfs2_inode > { > grub_uint64_t i_blocks; > @@ -703,6 +710,52 @@ > return 1; > } > =20 > +static grub_err_t > +grub_nilfs2_load_sb (struct grub_nilfs2_data *data) > +{ > + grub_disk_t disk =3D data->disk; > + struct grub_nilfs2_super_block sb2; > + grub_uint64_t partition_size; > + int valid[2]; > + int swp =3D 0; > + > + /* Read first super block. */ > + grub_disk_read (disk, NILFS_1ST_SUPER_BLOCK, 0, > + sizeof (struct grub_nilfs2_super_block), &data->sblock); > + /* Make sure if 1st super block is valid. */ > + valid[0] =3D grub_nilfs2_valid_sb (&data->sblock); > + > + partition_size =3D grub_disk_get_size (disk); > + if (partition_size !=3D GRUB_DISK_SIZE_UNKNOWN) > + { > + /* Read second super block. */ > + grub_disk_read (disk, partition_size - NILFS_2ND_SUPER_BLOCK, 0, > + sizeof (struct grub_nilfs2_super_block), &sb2); > + /* Make sure if 2nd super block is valid. */ > + valid[1] =3D grub_nilfs2_valid_sb (&sb2); > + } > + else > + /* 2nd super block may not exist, so it's invalid. */ > + valid[1] =3D 0; > + > + > + > + if (!valid[0] && !valid[1]) > + return grub_error (GRUB_ERR_BAD_FS, "not a nilfs2 filesystem"); > + > + swp =3D valid[1] && (!valid[0] || > + grub_le_to_cpu64 (data->sblock.s_last_cno) < > + grub_le_to_cpu64 (sb2.s_last_cno)); > + > + /* swap if first super block is invalid or older than second one. */ > + if (swp) > + grub_memcpy (&data->sblock, &sb2, > + sizeof (struct grub_nilfs2_super_block)); > + > + grub_errno =3D GRUB_ERR_NONE; > + return grub_errno; > +} > + > static struct grub_nilfs2_data * > grub_nilfs2_mount (grub_disk_t disk) > { > @@ -717,19 +770,13 @@ > if (!data) > return 0; > =20 > + data->disk =3D disk; > + > /* Read the superblock. */ > - grub_disk_read (disk, 1 * 2, 0, sizeof (struct grub_nilfs2_super_block= ), > - &data->sblock); > + grub_nilfs2_load_sb (data); > if (grub_errno) > goto fail; > =20 > - /* Make sure this is an nilfs2 filesystem. */ > - if (!grub_nilfs2_valid_sb (&data->sblock)) > - { > - grub_error (GRUB_ERR_BAD_FS, "not a nilfs2 filesystem"); > - goto fail; > - } > - > nilfs2_block_count =3D (1 << LOG2_NILFS2_BLOCK_SIZE (data)); > =20 > /* Read the last segment summary. */ > @@ -748,8 +795,6 @@ > if (grub_errno) > goto fail; > =20 > - data->disk =3D disk; > - > grub_nilfs2_read_last_checkpoint (data, &last_checkpoint); > =20 > if (grub_errno) >=20 > =3D=3D=3D modified file 'include/grub/disk.h' > --- include/grub/disk.h 2010-01-07 00:58:54 +0000 > +++ include/grub/disk.h 2010-05-23 18:53:34 +0000 > @@ -138,6 +138,9 @@ > #define GRUB_DISK_CACHE_SIZE 8 > #define GRUB_DISK_CACHE_BITS 3 > =20 > +/* Return value of grub_disk_get_size() in case disk size is unknown. */ > +#define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL > + > /* This is called from the memory manager. */ > void grub_disk_cache_invalidate_all (void); > =20 >=20 > [3 ] >=20 > [4 ] > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel --=20 Jiro SEKIBA