From: Andreas Dilger Subject: [PATCH] blkid detection for ZFS Date: Thu, 14 Feb 2008 18:07:40 -0700 Message-ID: <20080215010740.GZ3029@webber.adilger.int> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary_(ID_ugIBqQ0d8bX01sxgq5XDwA)" Cc: linux-ext4@vger.kernel.org To: "Theodore Ts'o" Return-path: Received: from sca-es-mail-2.Sun.COM ([192.18.43.133]:52443 "EHLO sca-es-mail-2.sun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756463AbYBOBHs (ORCPT ); Thu, 14 Feb 2008 20:07:48 -0500 Received: from fe-sfbay-10.sun.com ([192.18.43.129]) by sca-es-mail-2.sun.com (8.13.7+Sun/8.12.9) with ESMTP id m1F17lrD019723 for ; Thu, 14 Feb 2008 17:07:47 -0800 (PST) Received: from conversion-daemon.fe-sfbay-10.sun.com by fe-sfbay-10.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) id <0JW900D019RN0C00@fe-sfbay-10.sun.com> (original mail from adilger@sun.com) for linux-ext4@vger.kernel.org; Thu, 14 Feb 2008 17:07:47 -0800 (PST) Sender: linux-ext4-owner@vger.kernel.org List-ID: --Boundary_(ID_ugIBqQ0d8bX01sxgq5XDwA) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: inline Attached is a patch to detect ZFS in libblkid. It isn't by any means complete, because it doesn't report the LABEL or UUID of the device, nor names any of the constituent filesystems. The latter is quite complex to implement and may be beyond the scope of libblkid. Some input is welcome here also... There is a UUID (GUID) for the whole "pool" (aggregation of devices that ZFS filesystems might live on), a UUID for the "virtual device" (vdev) (akin to MD RAID set) that a disk is part of and also a separate UUID for each device. There is a LABEL (pool name) for the whole pool, but not one for an individual filesystem. I'm thinking of making the blkid UUID be the GUID of the whole pool, as any device in the pool would be sufficient to locate all of the component devices. This means all devices in the same pool will return the same UUID, but for identification that should be fine I think... I haven't checked for pathologies in libblkid regarding that yet. On a related note - on Solaris the ZFS filesystems always live in a GPT partition table, and I note that libblkid doesn't identify this. Is that something we want to start adding to libblkid (e.g. GPT, DOS, LVM, etc)? Cheers, Andreas -- Andreas Dilger Sr. Staff Engineer, Lustre Group Sun Microsystems of Canada, Inc. --Boundary_(ID_ugIBqQ0d8bX01sxgq5XDwA) Content-type: text/plain; NAME=e2fsprogs-blkid-zfs.patch; charset=utf-8 Content-transfer-encoding: QUOTED-PRINTABLE Content-disposition: attachment; filename=e2fsprogs-blkid-zfs.patch Index: e2fsprogs-cfs/lib/blkid/probe.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D --- e2fsprogs-cfs.orig/lib/blkid/probe.c +++ e2fsprogs-cfs/lib/blkid/probe.c @@ -647,6 +647,21 @@ static int probe_jfs(struct blkid_probe=20 =09return 0; } =20 +static int probe_zfs(struct blkid_probe *probe, struct blkid_magic *= id, +=09=09 unsigned char *buf) +{ +=09struct zfs_uber_block *zub; +=09char *vdev_label; +=09const char *pool_name =3D 0; + +=09zub =3D (struct zfs_uber_block *)buf; + +=09/* read nvpair data for pool name, pool GUID (complex) */ +=09//blkid_set_tag(probe->dev, "LABEL", pool_name, sizeof(pool_name)= ); +=09//set_uuid(probe->dev, pool_guid, 0); +=09return 0; +} + static int probe_luks(struct blkid_probe *probe, =09=09 struct blkid_magic *id __BLKID_ATTR((unused)), =09=09 unsigned char *buf) @@ -896,15 +911,6 @@ static int probe_hfsplus(struct blkid_pr } =20 /* - * BLKID_BLK_OFFS is at least as large as the highest bim_kboff defi= ned - * in the type_array table below + bim_kbalign. - * - * When probing for a lot of magics, we handle everything in 1kB buf= fers so - * that we don't have to worry about reading each combination of blo= ck sizes. - */ -#define BLKID_BLK_OFFS=0964=09/* currently reiserfs */ - -/* * Various filesystem magics that we can check for. Note that kboff= and * sboff are in kilobytes and bytes respectively. All magics are in * byte strings so we don't worry about endian issues. @@ -954,6 +960,8 @@ static struct blkid_magic type_array[] =3D { "iso9660",=0932,=09 1, 5, "CD001",=09=09probe_iso9660 }, { "iso9660",=0932,=09 9, 5, "CDROM",=09=09probe_iso9660 }, { "jfs",=0932,=09 0, 4, "JFS1",=09=09=09probe_jfs }, + { "zfs", 128,=09 0, 8, "\0\0\0\0\x00\xba\xb1\x0c", probe_zfs = }, + { "zfs", 128,=09 0, 8, "\x0c\xb1\xba\x00\0\0\0\0", probe_zfs = }, { "hfsplus",=09 1,=09 0, 2, "BD",=09=09=09probe_hfsplus }, { "hfsplus",=09 1,=09 0, 2, "H+",=09=09=090 }, { "hfs",=09 1,=09 0, 2, "BD",=09=09=090 }, @@ -1074,7 +1082,7 @@ try_again: =09=09if (!buf) =09=09=09continue; =20 -=09=09if (memcmp(id->bim_magic, buf + (id->bim_sboff&0x3ff), +=09=09if (memcmp(id->bim_magic, buf + (id->bim_sboff & 0x3ff), =09=09=09 id->bim_len)) =09=09=09continue; =20 @@ -1104,7 +1112,7 @@ try_again: =09=09dev =3D 0; =09=09goto found_type; =09} -=09=09 + found_type: =09if (dev && type) { =09=09dev->bid_devno =3D st.st_rdev; @@ -1113,7 +1121,7 @@ found_type: =09=09cache->bic_flags |=3D BLKID_BIC_FL_CHANGED; =20 =09=09blkid_set_tag(dev, "TYPE", type, 0); -=09=09=09=09 + =09=09DBG(DEBUG_PROBE, printf("%s: devno 0x%04llx, type %s\n", =09=09=09 dev->bid_name, (long long)st.st_rdev, type)); =09} Index: e2fsprogs-cfs/lib/blkid/probe.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D --- e2fsprogs-cfs.orig/lib/blkid/probe.h +++ e2fsprogs-cfs/lib/blkid/probe.h @@ -190,6 +190,16 @@ struct jfs_super_block { =09unsigned char=09js_loguuid[16]; }; =20 +#define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-blo= c! */ +struct zfs_uberblock { +=09__u64=09=09ub_magic;=09/* UBERBLOCK_MAGIC=09=09*/ +=09__u64=09=09ub_version;=09/* ZFS_VERSION=09=09=09*/ +=09__u64=09=09ub_txg;=09=09/* txg of last sync=09=09*/ +=09__u64=09=09ub_guid_sum;=09/* sum of all vdev guids=09*/ +=09__u64=09=09ub_timestamp;=09/* UTC time of last sync=09*/ +=09char=09=09ub_rootbp;=09/* MOS objset_phys_t=09=09*/ +}; + struct romfs_super_block { =09unsigned char=09ros_magic[8]; =09__u32=09=09ros_dummy1[2]; Index: e2fsprogs-cfs/lib/blkid/tests/zfs.results =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D --- /dev/null +++ e2fsprogs-cfs/lib/blkid/tests/zfs.results @@ -0,0 +1 @@ +TYPE=3D'zfs' Index: e2fsprogs-cfs/lib/blkid/tests/zfs.img.bz2 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D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