blkid detection for ZFS
PATCH 1/1 blkid detection for ZFS
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.
lib/blkid/probe.c +20 -12
@@ -647,6 +647,21 @@ static int probe_jfs(struct blkid_probereturn 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)); }
lib/blkid/probe.h +10 -0
@@ -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 ];
lib/blkid/tests/zfs.results new file +1 -0
@@ -0,0 +1 @@ +TYPE='zfs'
lib/blkid/tests/zfs.img.bz2 new file +18 -0
@@ -0,0 +1,18 @@ +BZh91AY&SYg�� +=0�'��M2z��bL2i���i�i��� dz��3di��LOL�SL��B#Rz�执�Jy��&��M1�4�i0 +m 2L��O4���SPz���I�<����� COS�&&��Lhd�T�I���'�5<��M2z���j'��� �M�h������M�����ɓ'�h��Q���M�cDɍO)�L26�#M2i�����=LL� 4�P�OD�2=OP�@e�SƧ�E?H��5�OiI��&�#Q����S�ڧ�4�F�� +z�6hS�fSS�~���OҞ�?T���)�ڧ�j�(���=(=OhҞ��S4�4�I�?T�ɦ��M6�<M��h2OF�4Lh�D�S�xSzS�<��f�OP�I?Tڞi5M'���y �=5=��4�����z�S��=�<�a�)�Q�OS��f�ا�P�S�4� �!�F��� 4� 4dѦ�22z��Bl���4d`�h�hɠ4ѠF������ѧ�h��h�(�Ⱳ]&�Z@X�_E�rQg*rtLm��a�j��$�f6~GQ�W�Z�"�!���p6�wm��q���Oq�TO��B!�m9�fN�6t��РPh����/[���~���>��l7���e���1�������3'�e��'ڪB������j������U�"<��/��ϘY �?K�}�uC���W6l�a>E����'���z��;5��������9�ˑ䂂6 +��]H�S0�bd�lt�&�T�l����ͷN??+;Lx"�6$$ۈH%Ӱ@Q��SEK@���.���I*L�*M�Q)=��\�@���+�xhBI!W�$��X4���0� ,�g$�}[����f�� +���|�8X�2��4�ƍJ��#�8_p<rK٦��K� +�w!?C?���a��RT8L`m�$�E)ME�=Җ�1�*_&_�b�w�YQ���U@�ݶ��U<�ݼ�<���ƑA���t��nŽ�J8���#�I��ܲ�x��3�Yf*I��h��$3�=sh!��>i�>Ӆ����!X����u�2{��A��t�O�}� +E�~�֟������TWjޛ���'9u+�+��㿆D�,���َUl]ࣺZ��*8/����D0���֫w��h�*ފC �ӗ�6N[n B�}�IA��κXQ�<(������yZ!e��(�����À�k��\�G%Z@�wݡ��I��#�!Ƌ�.n�<��O������z@�`�N��D�;�G`�+�� ���tY�_?��q�����K�d6Sa�L����ٽvʃ�FU����K��q����~ � +0(�F�T��}Ku����x�4 +�47����=L�p[���Zv���b�kP���H��t,�d��X�e�K��� +#����9U��=WT�r���"c����q���Y�:#�f) +=����M��/5]/\A{�~Cz|gN:F�o��#�[?7@��5���?�`�lQ^;�x���T������ek�#uٚ�C;����ž.@�j����}sP�+'�"��\�[n��ç/��h�iXbS�T<�����n<_��N���̱I`�}Έ���m��aj�Q���uw��Z8UadV��OJ�,d*O��%�|f��a��=��4��K�i�IT�� +���G�eb��r�6J^:�>vO�i� �@j��� ijk��30Ls���� +}�0S�I�D��i6I�� ,B�.r����iR����JT��z���D�P�'[���P��u� �^�X: � +-��]��-�G��$���ΰ�c}���$RI�)E��~� +���d0��:��I�#�<pd!�����598�m���֔�6�9^ې�i[ ���?�I��WUL�/>eY��6T3� �2�� *K��h��K4��3[ê��� ^%9QV��m�B�mo0�q�"��"�Z�(»��$ ++��]�8�����X�Pd��F��Xf�^Z�W�w�D��7��U2��5�'�U�Yٯ�&!t�^Q�YêA�ģ�wߣ��U2{����LIL(��m?��"�3�Z[H#��Vh�gb��h�u��f�jZ�~�|Lc+ӆU���=�2���,C ��q��O�SR�$«��!���a���nJ9�����}Vtڜ>G����J�̾���~<�M1�>7�)OY��+�Tj��-�bc��i�s�$������T)���Cb�K*߱����6XR�6_��"��!oX[���o����~�Нž0[�NZ��dY�`�"�n�I +���'w�����h�W��gI]��r|%���t��4���3����\y@B��?�u�W|�Z���zm�h�g�E�%]�ο���ݎ~�n/�Ͷ���ܑN$���
Quoted 5 lines · Andreas Dilger
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.
Are there devices for that are made available for the vdev and the pool? I assume not for the pool since that's a filesystem entity, but what about the vdev?
In general, blkid is all about mapping the UUID of what lives on the device to the device filename, for the benefit of programs like mount and fsck.
I don't know enough about ZFS in terms of how you would mount a filesystem which is part of a pool. How is the filesystem specified to the "mount" command?
Quoted 5 lines
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.
What I did with the freshly checked in code to identify LVM2 volumes is that if /dev/sda1 is part of a physical volume, then blkid returns the UUID for the PV for /dev/sda1. The filesystem UUID's end up getting associated via blkid entries for /dev/mapper/FOO, and we don't bother trying to associate the UUID for the raidset with anything, since it's not really associated with a physical block device.
So it would seem to me that it would be better to make the UUID be for a particular ZFS physical disk be the UUID for that disk, and not for the whole pool. The question really, though, is what actually would be most useful --- who is going to actually use blkid on a Solaris system with ZFS? It may be that the right answer is to put the pool UUID as a separate tag; blkid supports more than just the standard LABEL, UUID, TYPE, etc. tags. You could easily stash the pool UUID in a POOL_GUID tag, if it would be useful for some blkid callers.
Quoted 3 lines
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)?
What do you mean by not identifying the GPT partition table? At the moment we haven't been identifying the whole disk partition tables, mainly becuase there isn't much use for it especially for the DOS MBR (no uuid or label to speak of).
I just checked in a patch from Eric to detect LVM2 PV's, because it was useful for the Anaconda developers. I wouldn't have any objections accepting a patch which detected the whole-disk device and returned the GPT label/UUID information, but I probably wouldn't code it myself. Still, if it someone thought it was *useful* and would use it, and thus felt called to write a patch, I'd certainly accept it.
Regards,
- Ted
Quoted 11 lines · Theodore Ts'o
Quoted 5 lines · Andreas Dilger
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.
Are there devices for that are made available for the vdev and the pool? I assume not for the pool since that's a filesystem entity, but what about the vdev?
Quoted 7 lines
In general, blkid is all about mapping the UUID of what lives on the device to the device filename, for the benefit of programs like mount and fsck.
I don't know enough about ZFS in terms of how you would mount a filesystem which is part of a pool. How is the filesystem specified to the "mount" command?
Good question. For Lustre (linux or Solaris), we want to be able to find the pool by name, and then use ZFS tools to "import" the pool and make the filesystems available to Lustre. The current ZFS tools (as ported to Linux) scan all of /dev/* directly, but I'd much prefer to use libblkid for that since it knows about PVs, RAID devices, etc.
Filesystems in a ZFS pool are specified via "{poolname}/{fsname}", but to get "fsname" from disk is much more involved than I want to get, since it almost involves importing the pool and parsing a whole tree of parameters and indexes.
I'd be pretty happy to just know from "blkid" that a given device is used by ZFS for "lustrepool" or "fusepool" or whatever it is called.
Quoted 8 lines
So it would seem to me that it would be better to make the UUID be for a particular ZFS physical disk be the UUID for that disk, and not for the whole pool. The question really, though, is what actually would be most useful --- who is going to actually use blkid on a Solaris system with ZFS? It may be that the right answer is to put the pool UUID as a separate tag; blkid supports more than just the standard LABEL, UUID, TYPE, etc. tags. You could easily stash the pool UUID in a
POOL_GUIDtag, if it would be useful for some blkid callers.
OK, maybe I'll go that route, since I won't stricly be having UUIDs or LABELs that directly map to filesystems.
Quoted 10 lines
Quoted 4 lines
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)?
What do you mean by not identifying the GPT partition table? At the moment we haven't been identifying the whole disk partition tables, mainly becuase there isn't much use for it especially for the DOS MBR (no uuid or label to speak of).
Quoted 6 lines
I just checked in a patch from Eric to detect LVM2 PV's, because it was useful for the Anaconda developers. I wouldn't have any objections accepting a patch which detected the whole-disk device and returned the GPT label/UUID information, but I probably wouldn't code it myself. Still, if it someone thought it was *useful* and would use it, and thus felt called to write a patch, I'd certainly accept it.
That was my question. I didn't see the LVM2 identification patch until after my email, but this makes it fairly clear that identification of block devices isn't verboten.
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.