[PATCH parted 2/7] linux: save blkid topology in arch_specific data for later use

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

 



This is a preparation patch for adding get_minimum_alignment
and get_optimum_alignment functions to linux's _PedDeviceArchOps.
* libparted/arch/linux.h (struct_LinuxSpecific) [probe, topology]:
Add members.
* libparted/arch/linux.c (linux_new): initialize
arch_specific->probe and arch_specific->topology to NULL,
(linux_destroy): Free arch_specific->probe.
(get_minimum_io_size): Remove function.
(get_blkid_topology): New function.
(_device_set_sector_size): Call get_blkid_topology() instead of
get_minimum_io_size() and retrieve minimum io size from the cached
topology.
---
 libparted/arch/linux.c |   79 +++++++++++++++++++-----------------------------
 libparted/arch/linux.h |    8 +++++
 2 files changed, 39 insertions(+), 48 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index d084b93..a03c80d 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -52,10 +52,6 @@
 #  define _(String) (String)
 #endif /* ENABLE_NLS */
 
-#if HAVE_BLKID_BLKID_H
-# include <blkid/blkid.h>
-#endif
-
 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
 
 #ifndef __NR__llseek
@@ -598,47 +594,22 @@ _have_kern26 ()
         return have_kern26 = kver >= KERNEL_VERSION (2,6,0) ? 1 : 0;
 }
 
-/* Use libblkid to determine the kernel's idea of the
-   minimum_io_size for the device on which FD is open.
-   Upon success, store that value in *SZ and return 0.
-   Otherwise, don't modify *SZ, set errno and return -1.  */
-static int
-get_minimum_io_size (int fd, unsigned long *sz)
-{
-        int ret = -1;
-
 #if USE_BLKID
-        blkid_probe pr = blkid_new_probe ();
-        if (!pr)
-                goto free_and_return;
-
-        int saved_errno;
-        if (blkid_probe_set_device (pr, fd, 0, 0)) {
-                saved_errno = errno;
-                blkid_free_probe (pr);
-                goto free_and_return;
-        }
-
-        blkid_topology tp = blkid_probe_get_topology (pr);
-        if (!tp) {
-                saved_errno = errno;
-                goto free_and_return;
-        }
-
-        *sz = blkid_topology_get_minimum_io_size (tp);
-        ret = 0;
-
-free_and_return:
+static void
+get_blkid_topology (LinuxSpecific *arch_specific)
+{
+        arch_specific->probe = blkid_new_probe ();
+        if (!arch_specific->probe)
+                return;
 
-        blkid_free_probe (pr);
-        if (ret)
-                errno = saved_errno;
-#else
-        errno = ENOSYS;
-#endif
+        if (blkid_probe_set_device(arch_specific->probe,
+                                   arch_specific->fd, 0, 0))
+                return;
 
-        return ret;
+        arch_specific->topology =
+                blkid_probe_get_topology(arch_specific->probe);
 }
+#endif
 
 static void
 _device_set_sector_size (PedDevice* dev)
@@ -667,19 +638,21 @@ _device_set_sector_size (PedDevice* dev)
                 dev->sector_size = (long long)sector_size;
         }
 
-        unsigned long min_io_size;
-        int err = get_minimum_io_size (arch_specific->fd, &min_io_size);
-
-        if (err) {
+#if USE_BLKID
+        get_blkid_topology(arch_specific);
+        if (!arch_specific->topology) {
                 ped_exception_throw (
                         PED_EXCEPTION_WARNING,
                         PED_EXCEPTION_OK,
                         _("Could not determine minimum io size for %s: %s.\n"
                           "Using the default size (%lld)."),
                         dev->path, strerror (errno), PED_SECTOR_SIZE_DEFAULT);
-                min_io_size = PED_SECTOR_SIZE_DEFAULT;
+        } else {
+                dev->phys_sector_size =
+                        blkid_topology_get_minimum_io_size(
+                                arch_specific->topology);
         }
-        dev->phys_sector_size = min_io_size;
+#endif
 
         /* Return PED_SECTOR_SIZE_DEFAULT for DASDs. */
         if (dev->type == PED_DEVICE_DASD) {
@@ -1274,6 +1247,10 @@ linux_new (const char* path)
                 goto error_free_path;
         arch_specific = LINUX_SPECIFIC (dev);
         arch_specific->dmtype = NULL;
+#if USE_BLKID
+        arch_specific->probe = NULL;
+        arch_specific->topology = NULL;
+#endif
 
         dev->open_count = 0;
         dev->read_only = 0;
@@ -1394,7 +1371,13 @@ error:
 static void
 linux_destroy (PedDevice* dev)
 {
-        void *p = ((LinuxSpecific*)dev->arch_specific)->dmtype;
+        LinuxSpecific *arch_specific = LINUX_SPECIFIC(dev);
+        void *p = arch_specific->dmtype;
+
+#if USE_BLKID
+        if (arch_specific->probe)
+                blkid_free_probe(arch_specific->probe);
+#endif
         free (p);
         free (dev->arch_specific);
         free (dev->path);
diff --git a/libparted/arch/linux.h b/libparted/arch/linux.h
index 9c08f40..b3693e9 100644
--- a/libparted/arch/linux.h
+++ b/libparted/arch/linux.h
@@ -22,6 +22,10 @@
 #  include <parted/fdasd.h>
 #endif
 
+#if HAVE_BLKID_BLKID_H
+#  include <blkid/blkid.h>
+#endif
+
 #define LINUX_SPECIFIC(dev)	((LinuxSpecific*) (dev)->arch_specific)
 
 typedef	struct _LinuxSpecific	LinuxSpecific;
@@ -36,6 +40,10 @@ struct _LinuxSpecific {
 	/* IBM internal dasd structure (i guess ;), required. */
 	struct fdasd_anchor *anchor;
 #endif
+#if USE_BLKID
+        blkid_probe probe;
+        blkid_topology topology;
+#endif
 };
 
 #endif /* PED_ARCH_LINUX_H_INCLUDED */
-- 
1.6.5.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux