]> err.no Git - util-linux/commitdiff
libblkid: topology - add logical and physical sector size
authorKarel Zak <kzak@redhat.com>
Fri, 30 Oct 2009 11:08:01 +0000 (12:08 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 30 Oct 2009 11:08:01 +0000 (12:08 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/docs/libblkid-sections.txt
shlibs/blkid/samples/topology.c
shlibs/blkid/src/blkid.sym
shlibs/blkid/src/blkidP.h
shlibs/blkid/src/topology/ioctl.c
shlibs/blkid/src/topology/sysfs.c
shlibs/blkid/src/topology/topology.c
shlibs/blkid/src/topology/topology.h

index 8f643d8b2aef5379b9c106bb0797f17572aa591e..c8b0045d47aa6ececb0f9d92e3554cd19ae9267a 100644 (file)
@@ -117,8 +117,10 @@ blkid_probe_enable_topology
 <SUBSECTION>
 blkid_probe_get_topology
 blkid_topology_get_alignment_offset
+blkid_topology_get_logical_sector_size
 blkid_topology_get_minimum_io_size
 blkid_topology_get_optimal_io_size
+blkid_topology_get_physical_sector_size
 </SECTION>
 
 <SECTION>
index 4adaa31a1b5e48faa823ce1c356ac787da115798..e73cd9e4518e2ec78527e4b55a67c154f7f7f97b 100644 (file)
@@ -42,12 +42,16 @@ int main(int argc, char *argv[])
        tp = blkid_probe_get_topology(pr);
        if (tp) {
                printf("----- binary interface:\n");
-               printf("\talignment offset : %lu\n",
+               printf("\talignment offset     : %lu\n",
                                blkid_topology_get_alignment_offset(tp));
-               printf("\tminimum io size  : %lu\n",
+               printf("\tminimum io size      : %lu\n",
                                blkid_topology_get_minimum_io_size(tp));
-               printf("\toptimal io size  : %lu\n",
+               printf("\toptimal io size      : %lu\n",
                                blkid_topology_get_optimal_io_size(tp));
+               printf("\tlogical sector size  : %lu\n",
+                               blkid_topology_get_logical_sector_size(tp));
+               printf("\tphysical sector size : %lu\n",
+                               blkid_topology_get_physical_sector_size(tp));
        }
 
        /*
index 992d4e9fe85e9a031bb536280c4deac80b2727d0..972555266db94d6dd1768e47770ee75a0323b22c 100644 (file)
@@ -109,6 +109,8 @@ global:
        blkid_probe_set_partitions_flags;
        blkid_probe_set_superblocks_flags;
        blkid_topology_get_alignment_offset;
+       blkid_topology_get_logical_sector_size;
        blkid_topology_get_minimum_io_size;
        blkid_topology_get_optimal_io_size;
+       blkid_topology_get_physical_sector_size;
 } BLKID_2.15;
index 0cad69c0733c0e3078bd1b867ff93ad9b3ae4aab..6e9c21e8efd41f7a03fa9cd95141f2c68a3e49db 100644 (file)
@@ -116,7 +116,7 @@ struct blkid_chaindrv {
 #define BLKID_PROBVAL_BUFSIZ   64
 
 #define BLKID_NVALS_SUBLKS     14
-#define BLKID_NVALS_TOPLGY     3
+#define BLKID_NVALS_TOPLGY     5
 #define BLKID_NVALS_PARTS      1
 
 /* Max number of all values in probing result */
index 962b58ac4bf0a694cdd455bd14a17680738389e0..709b2f458a4505b701fb61d90344fcf1e591d19c 100644 (file)
@@ -33,6 +33,8 @@ static struct topology_val {
        { BLKALIGNOFF, blkid_topology_set_alignment_offset },
        { BLKIOMIN, blkid_topology_set_minimum_io_size },
        { BLKIOOPT, blkid_topology_set_optimal_io_size },
+       { BLKPBSZGET, blkid_topology_set_physical_sector_size }
+       /* we read BLKSSZGET in topology.c */
 };
 
 static int probe_ioctl_tp(blkid_probe pr, const struct blkid_idmag *mag)
index 1fb825e4fcc11be2013ff0d4c6d0e0dc4dc108c8..20c507f13aeeb56486095aa6dd38129cb5d896a7 100644 (file)
@@ -6,6 +6,7 @@
  * This file may be redistributed under the terms of the
  * GNU Lesser General Public License.
  *
+ * For more information see Linux kernel Documentation/ABI/testing/sysfs-block.
  */
 #include <stdio.h>
 #include <string.h>
@@ -78,7 +79,7 @@ err:
 }
 
 /*
- * Sysfs topology values
+ * Sysfs topology values (since 2.6.31, May 2009).
  */
 static struct topology_val {
 
@@ -92,6 +93,7 @@ static struct topology_val {
        { "alignment_offset", blkid_topology_set_alignment_offset },
        { "queue/minimum_io_size", blkid_topology_set_minimum_io_size },
        { "queue/optimal_io_size", blkid_topology_set_optimal_io_size },
+       { "queue/physical_block_size", blkid_topology_set_physical_sector_size },
 };
 
 static int probe_sysfs_tp(blkid_probe pr, const struct blkid_idmag *mag)
index d1fb86f53a74a190449ce37db45128a710e5fbcd..db97c5fb2ac8b37009ca15325a5d1fe118a81da1 100644 (file)
  * NAME=value (tags) interface is enabled by blkid_probe_enable_topology(),
  * and provides:
  *
+ * @LOGICAL_SECTOR_SIZE: this is the smallest unit the storage device can
+ *                       address. It is typically 512 bytes.
+ *
+ * @PHYSICAL_SECTOR_SIZE: this is the smallest unit a physical storage device
+ *                        can write atomically. It is usually the same as the
+ *                        logical sector size but may be bigger.
+ *
  * @MINIMUM_IO_SIZE: minimum size which is the device's preferred unit of I/O.
  *                   For RAID arrays it is often the stripe chunk size.
  *
@@ -44,6 +51,8 @@
  */
 static int topology_probe(blkid_probe pr, struct blkid_chain *chn);
 static void topology_free(blkid_probe pr, void *data);
+static int topology_is_complete(blkid_probe pr);
+static int topology_set_logical_sector_size(blkid_probe pr);
 
 /*
  * Binary interface
@@ -52,6 +61,8 @@ struct blkid_struct_topology {
        unsigned long   alignment_offset;
        unsigned long   minimum_io_size;
        unsigned long   optimal_io_size;
+       unsigned long   logical_sector_size;
+       unsigned long   physical_sector_size;
 };
 
 /*
@@ -173,6 +184,12 @@ static int topology_probe(blkid_probe pr, struct blkid_chain *chn)
                                continue;
                }
 
+               if (!topology_is_complete(pr))
+                       continue;
+
+               /* generic for all probing drivers */
+               topology_set_logical_sector_size(pr);
+
                DBG(DEBUG_LOWPROBE,
                        printf("<-- leaving probing loop (type=%s) [TOPOLOGY idx=%d]\n",
                        id->name, chn->idx));
@@ -207,6 +224,24 @@ static int topology_set_value(blkid_probe pr, const char *name,
        return blkid_probe_sprintf_value(pr, name, "%llu", data);
 }
 
+/* the topology info is complete when we have at least "minimum_io_size" which
+ * is provides by all blkid topology drivers */
+static int topology_is_complete(blkid_probe pr)
+{
+       struct blkid_chain *chn = blkid_probe_get_chain(pr);
+
+       if (!chn)
+               return FALSE;
+
+       if (chn->binary && chn->data) {
+               blkid_topology tp = (blkid_topology) chn->data;
+               if (tp->minimum_io_size)
+                       return TRUE;
+       }
+
+       return __blkid_probe_lookup_value(pr, "MINIMUM_IO_SIZE") ? TRUE : FALSE;
+}
+
 int blkid_topology_set_alignment_offset(blkid_probe pr, unsigned long val)
 {
        return topology_set_value(pr,
@@ -231,6 +266,30 @@ int blkid_topology_set_optimal_io_size(blkid_probe pr, unsigned long val)
                        val);
 }
 
+/* BLKSSZGET is provided on all systems since 2.3.3 -- so we don't have to
+ * waste time with sysfs or or.
+ */
+static int topology_set_logical_sector_size(blkid_probe pr)
+{
+       unsigned long val = blkid_probe_get_sectorsize(pr);
+
+       if (!val)
+               return -1;
+
+       return topology_set_value(pr,
+                       "LOGICAL_SECTOR_SIZE",
+                       offsetof(struct blkid_struct_topology, logical_sector_size),
+                       val);
+}
+
+int blkid_topology_set_physical_sector_size(blkid_probe pr, unsigned long val)
+{
+       return topology_set_value(pr,
+                       "PHYSICAL_SECTOR_SIZE",
+                       offsetof(struct blkid_struct_topology, physical_sector_size),
+                       val);
+}
+
 /**
  * blkid_topology_get_alignment_offset:
  * @tp: topology
@@ -264,3 +323,25 @@ unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
        return tp ? tp->optimal_io_size : 0;
 }
 
+/**
+ * blkid_topology_get_logical_sector_size
+ * @tp: topology
+ *
+ * Returns: logical sector size (BLKSSZGET ioctl) in bytes or 0.
+ */
+unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
+{
+       return tp ? tp->logical_sector_size : 0;
+}
+
+/**
+ * blkid_topology_get_physical_sector_size
+ * @tp: topology
+ *
+ * Returns: logical sector size (BLKSSZGET ioctl) in bytes or 0.
+ */
+unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
+{
+       return tp ? tp->physical_sector_size : 0;
+}
+
index fc3fb7340d0b2247750d53e57928098d5ebd6197..d4879204d722b9ebaf1de6ddc68916c2d26bce6e 100644 (file)
@@ -6,6 +6,7 @@
 extern int blkid_topology_set_alignment_offset(blkid_probe pr, unsigned long val);
 extern int blkid_topology_set_minimum_io_size(blkid_probe pr, unsigned long val);
 extern int blkid_topology_set_optimal_io_size(blkid_probe pr, unsigned long val);
+extern int blkid_topology_set_physical_sector_size(blkid_probe pr, unsigned long val);
 
 /*
  * topology probers