summaryrefslogtreecommitdiffstats
path: root/misc-utils
diff options
context:
space:
mode:
authorKarel Zak2018-10-18 13:57:46 +0200
committerKarel Zak2018-12-07 12:33:34 +0100
commit10501add02abf12d41246c04a81ac599179266c7 (patch)
tree81e27d43a321e8a86b71930d61901472bf020b83 /misc-utils
parentlsblk: make device_get_data() more generic (diff)
downloadkernel-qcow2-util-linux-10501add02abf12d41246c04a81ac599179266c7.tar.gz
kernel-qcow2-util-linux-10501add02abf12d41246c04a81ac599179266c7.tar.xz
kernel-qcow2-util-linux-10501add02abf12d41246c04a81ac599179266c7.zip
lsblk: remember whole-disk, remove unused struct member
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils')
-rw-r--r--misc-utils/lsblk-devtree.c5
-rw-r--r--misc-utils/lsblk.c20
-rw-r--r--misc-utils/lsblk.h7
3 files changed, 18 insertions, 14 deletions
diff --git a/misc-utils/lsblk-devtree.c b/misc-utils/lsblk-devtree.c
index 9a6dba0e1..aab01d3e3 100644
--- a/misc-utils/lsblk-devtree.c
+++ b/misc-utils/lsblk-devtree.c
@@ -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);
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 5ce388b8b..35926a17d 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -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));
diff --git a/misc-utils/lsblk.h b/misc-utils/lsblk.h
index 9c311c4c2..6a2ad6aa2 100644
--- a/misc-utils/lsblk.h
+++ b/misc-utils/lsblk.h
@@ -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);