[PATCH] blkid detection for ZFS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Index: e2fsprogs-cfs/lib/blkid/probe.c
===================================================================
--- e2fsprogs-cfs.orig/lib/blkid/probe.c
+++ e2fsprogs-cfs/lib/blkid/probe.c
@@ -647,6 +647,21 @@ static int probe_jfs(struct blkid_probe 
 	return 0;
 }
 
+static int probe_zfs(struct blkid_probe *probe, struct blkid_magic *id,
+		     unsigned char *buf)
+{
+	struct zfs_uber_block *zub;
+	char *vdev_label;
+	const char *pool_name = 0;
+
+	zub = (struct zfs_uber_block *)buf;
+
+	/* read nvpair data for pool name, pool GUID (complex) */
+	//blkid_set_tag(probe->dev, "LABEL", pool_name, sizeof(pool_name));
+	//set_uuid(probe->dev, pool_guid, 0);
+	return 0;
+}
+
 static int probe_luks(struct blkid_probe *probe,
 		       struct blkid_magic *id __BLKID_ATTR((unused)),
 		       unsigned char *buf)
@@ -896,15 +911,6 @@ static int probe_hfsplus(struct blkid_pr
 }
 
 /*
- * BLKID_BLK_OFFS is at least as large as the highest bim_kboff defined
- * in the type_array table below + bim_kbalign.
- *
- * When probing for a lot of magics, we handle everything in 1kB buffers so
- * that we don't have to worry about reading each combination of block sizes.
- */
-#define BLKID_BLK_OFFS	64	/* 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[] =
   { "iso9660",	32,	 1,  5, "CD001",		probe_iso9660 },
   { "iso9660",	32,	 9,  5, "CDROM",		probe_iso9660 },
   { "jfs",	32,	 0,  4, "JFS1",			probe_jfs },
+  { "zfs",     128,	 0,  8, "\0\0\0\0\x00\xba\xb1\x0c", probe_zfs },
+  { "zfs",     128,	 0,  8, "\x0c\xb1\xba\x00\0\0\0\0", probe_zfs },
   { "hfsplus",	 1,	 0,  2, "BD",			probe_hfsplus },
   { "hfsplus",	 1,	 0,  2, "H+",			0 },
   { "hfs",	 1,	 0,  2, "BD",			0 },
@@ -1074,7 +1082,7 @@ try_again:
 		if (!buf)
 			continue;
 
-		if (memcmp(id->bim_magic, buf + (id->bim_sboff&0x3ff),
+		if (memcmp(id->bim_magic, buf + (id->bim_sboff & 0x3ff),
 			   id->bim_len))
 			continue;
 
@@ -1104,7 +1112,7 @@ try_again:
 		dev = 0;
 		goto found_type;
 	}
-		
+
 found_type:
 	if (dev && type) {
 		dev->bid_devno = st.st_rdev;
@@ -1113,7 +1121,7 @@ found_type:
 		cache->bic_flags |= BLKID_BIC_FL_CHANGED;
 
 		blkid_set_tag(dev, "TYPE", type, 0);
-				
+
 		DBG(DEBUG_PROBE, printf("%s: devno 0x%04llx, type %s\n",
 			   dev->bid_name, (long long)st.st_rdev, type));
 	}
Index: e2fsprogs-cfs/lib/blkid/probe.h
===================================================================
--- e2fsprogs-cfs.orig/lib/blkid/probe.h
+++ e2fsprogs-cfs/lib/blkid/probe.h
@@ -190,6 +190,16 @@ struct jfs_super_block {
 	unsigned char	js_loguuid[16];
 };
 
+#define UBERBLOCK_MAGIC         0x00bab10c              /* oo-ba-bloc!  */
+struct zfs_uberblock {
+	__u64		ub_magic;	/* UBERBLOCK_MAGIC		*/
+	__u64		ub_version;	/* ZFS_VERSION			*/
+	__u64		ub_txg;		/* txg of last sync		*/
+	__u64		ub_guid_sum;	/* sum of all vdev guids	*/
+	__u64		ub_timestamp;	/* UTC time of last sync	*/
+	char		ub_rootbp;	/* MOS objset_phys_t		*/
+};
+
 struct romfs_super_block {
 	unsigned char	ros_magic[8];
 	__u32		ros_dummy1[2];
Index: e2fsprogs-cfs/lib/blkid/tests/zfs.results
===================================================================
--- /dev/null
+++ e2fsprogs-cfs/lib/blkid/tests/zfs.results
@@ -0,0 +1 @@
+TYPE='zfs'
Index: e2fsprogs-cfs/lib/blkid/tests/zfs.img.bz2
===================================================================
--- /dev/null
+++ e2fsprogs-cfs/lib/blkid/tests/zfs.img.bz2
@@ -0,0 +1,18 @@
+BZh91AY&SYg��+=0�'��M2z��bL2i��i��z��3di��LOL�SL��B#Rz�执�Jy��&��M1�i0
+m
2L��O4���SPz���I�����
COS�&��Lhd����5<��2z����	�h������ɓ'�h��Q��M�cDɍO)�6�#M2i�����L�
4�P�D�2=OP�e�SƧ�E?H�5�OiI�&�#Q��ڧ�F�
+z�6hS�SS�����T�)�ڧ�j�(�=(=OhҞ��S4�4�ɦ��M6�<M��h2OF�4Lh�D��SzS���f�OP�ڞi5M'���y	�=5=����S�=�<��Q��f�ا����!�F���
 4�4dѦ�22z��Bl���4d`�h�ɠ4ѠF������ѧ�h���Ⱳ]&�Z@X�_E�rQg*rtLm��a�j��6~GQ�Z��p6�m�q���Oq�TO��B!�m9�6t�Ph�������7���e��������'ڪB��������U���Y	�?K��uC���6l�a>E���'��z������9��䂂6
+��]H�S0�lt�&���ͷN??+;Lx"�$ۈH%Ӱ@Q��SEK@�����*L�*M�=��@����xhBI!W�$��X4���0�,�g$�[����f��
+��΁|�X�2��4��J�#�_p<rK٦��
+�w!?C?���RT8L`m��)ME�Җ�1�*_&_�b��YQ���U@������<���ƑA����Ž�8��������*I��h��$3�=sh!�>Ӆ��X����u�2{���t��}���������TWjޛ��9u+�+���D�,���َUl]ࣺZ��*8/���0���h�*ފC ���N[n B�A��κXQ���yZ!e��(���À�k��G%Z@�wݡ�I��!Ƌ������z@�`��D�;�+���Y�����K�Sa�L�ٽvʃ���K��q���	�+0(�F������x�+�7���=L�[�v��kP��H�,���e�K�+#��U��WT����������:#�f)
+=����M�\A{�z|gN:F�o��#�?7@������`�^;�x������#uٚ�C;�����.@�j����}sP�'�"���[n��ç/������XbS�<��n<_��N���̱I`�}Έ���m��aj��uw��Z8UadV�OJ�,d*O�f��=��4��K�i�IT��
+���G�eb��r�:�>vO�� ��
ijk�Ls���
+}�0S����6I�� ,B�.r���iR�JT���D��'[������
�^�X:
�
+-��]����$����c}���I�)E��~�
+����:��#�<pd!���598����֔�6�9^ې�i[
���I�L�/>eY�T3��*K���K4�3[ê�	^%9QV�m�B�0��"����+���������Xf�^Z��D��7�U2��'�U�&!t�^Q��A���wߣ��2{���LIL(��"�3��Vh�b�h�u��f���|Lc+ӆU��2��C �q��SR�$«�a�nJ9�����Vtڜ>G��J�̾���~<�M1�7�Y�Tj��bc���s����T)��Cb�*߱��6XR�6_��"��!oX[���o����Нž0[�NZ���n�I
+������W�gI]��|%�������3�\y@B�?�u�|�Z��zm�h�����~�n/���N$�
\ No newline at end of file

[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux