]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: remember whole-disk, remove unused struct member
authorKarel Zak <kzak@redhat.com>
Thu, 18 Oct 2018 11:57:46 +0000 (13:57 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Dec 2018 11:33:34 +0000 (12:33 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk-devtree.c
misc-utils/lsblk.c
misc-utils/lsblk.h

index 9a6dba0e18ba3cca7da0758801ba98ef4c5f0c28..aab01d3e3489c97766bb03b5881aabf92724954f 100644 (file)
@@ -12,7 +12,7 @@ void lsblk_reset_iter(struct lsblk_iter *itr, int direction)
        itr->direction = direction;
 }
 
-struct lsblk_device *lsblk_new_device(struct lsblk_devtree *tree)
+struct lsblk_device *lsblk_new_device()
 {
        struct lsblk_device *dev;
 
@@ -23,7 +23,6 @@ struct lsblk_device *lsblk_new_device(struct lsblk_devtree *tree)
        dev->refcount = 1;
        dev->removable = -1;
        dev->discard_granularity = (uint64_t) -1;
-       dev->tree = tree;
 
         INIT_LIST_HEAD(&dev->deps);
        INIT_LIST_HEAD(&dev->ls_roots);
@@ -77,6 +76,8 @@ void lsblk_unref_device(struct lsblk_device *dev)
                device_remove_dependences(dev);
                lsblk_device_free_properties(dev->properties);
 
+               lsblk_unref_device(dev->wholedisk);
+
                free(dev->name);
                free(dev->dm_name);
                free(dev->filename);
index 5ce388b8b94fac93b5d42a92abea23e99096cced..35926a17d71876e209a96324953dfd78c125694a 100644 (file)
@@ -861,7 +861,7 @@ static char *device_get_data(
                ul_path_read_string(dev->sysfs, &str, "queue/add_random");
                break;
        case COL_MODEL:
-               if (!dev->partition && dev->nslaves == 0) {
+               if (!device_is_partition(dev) && dev->nslaves == 0) {
                        prop = lsblk_device_get_properties(dev);
                        if (prop && prop->model)
                                str = xstrdup(prop->model);
@@ -870,7 +870,7 @@ static char *device_get_data(
                }
                break;
        case COL_SERIAL:
-               if (!dev->partition && dev->nslaves == 0) {
+               if (!device_is_partition(dev) && dev->nslaves == 0) {
                        prop = lsblk_device_get_properties(dev);
                        if (prop && prop->serial)
                                str = xstrdup(prop->serial);
@@ -879,11 +879,11 @@ static char *device_get_data(
                }
                break;
        case COL_REV:
-               if (!dev->partition && dev->nslaves == 0)
+               if (!device_is_partition(dev) && dev->nslaves == 0)
                        ul_path_read_string(dev->sysfs, &str, "device/rev");
                break;
        case COL_VENDOR:
-               if (!dev->partition && dev->nslaves == 0)
+               if (!device_is_partition(dev) && dev->nslaves == 0)
                        ul_path_read_string(dev->sysfs, &str, "device/vendor");
                break;
        case COL_SIZE:
@@ -897,7 +897,7 @@ static char *device_get_data(
                        *sortdata = dev->size;
                break;
        case COL_STATE:
-               if (!dev->partition && !dev->dm_name)
+               if (!device_is_partition(dev) && !dev->dm_name)
                        ul_path_read_string(dev->sysfs, &str, "device/state");
                else if (dev->dm_name) {
                        int x = 0;
@@ -1098,7 +1098,11 @@ static int initialize_device(struct lsblk_device *dev,
                        name, wholedisk, wholedisk ? wholedisk->name : ""));
 
        dev->name = xstrdup(name);
-       dev->partition = wholedisk != NULL;
+
+       if (wholedisk) {
+               dev->wholedisk = wholedisk;
+               lsblk_ref_device(wholedisk);
+       }
 
        dev->filename = get_device_path(dev);
        if (!dev->filename) {
@@ -1163,7 +1167,7 @@ static struct lsblk_device *devtree_get_device_or_new(struct lsblk_devtree *tr,
        struct lsblk_device *dev = lsblk_devtree_get_device(tr, name);
 
        if (!dev) {
-               dev = lsblk_new_device(tr);
+               dev = lsblk_new_device();
                if (!dev)
                        err(EXIT_FAILURE, _("failed to allocate device"));
 
@@ -1198,7 +1202,7 @@ static int process_partitions(struct lsblk_devtree *tr, struct lsblk_device *dis
         * Do not process further if there are no partitions for
         * this device or the device itself is a partition.
         */
-       if (!disk->npartitions || disk->partition)
+       if (!disk->npartitions || device_is_partition(disk))
                return -EINVAL;
 
        DBG(DEV, ul_debugobj(disk, "%s: probe whole-disk for partitions", disk->name));
index 9c311c4c2057197fe17b70e87f52c5af4fbb409b..6a2ad6aa24496309bafe54bc2c6bc306ed180483 100644 (file)
@@ -82,7 +82,7 @@ struct lsblk_device {
        struct list_head        ls_roots;       /* item in devtree->roots list */
        struct list_head        ls_devices;     /* item in devtree->devices list */
 
-       struct lsblk_devtree    *tree;
+       struct lsblk_device     *wholedisk;     /* for partitions */
 
        struct lsblk_devprop    *properties;
        struct stat     st;
@@ -94,8 +94,6 @@ struct lsblk_device {
 
        struct path_cxt *sysfs;
 
-       int partition;          /* is partition? TRUE/FALSE */
-
        char *mountpoint;       /* device mountpoint */
        struct statvfs fsstat;  /* statvfs() result */
 
@@ -116,6 +114,7 @@ struct lsblk_device {
                        blkid_requested : 1;
 };
 
+#define device_is_partition(_x)                ((_x)->wholedisk != NULL)
 
 /*
  * Note that lsblk tree uses botton devices (devices without slaves) as root
@@ -178,7 +177,7 @@ extern void lsblk_properties_deinit(void);
 
 /* lsblk-devtree.c */
 void lsblk_reset_iter(struct lsblk_iter *itr, int direction);
-struct lsblk_device *lsblk_new_device(struct lsblk_devtree *tree);
+struct lsblk_device *lsblk_new_device(void);
 void lsblk_ref_device(struct lsblk_device *dev);
 void lsblk_unref_device(struct lsblk_device *dev);
 int lsblk_device_new_dependence(struct lsblk_device *parent, struct lsblk_device *child);