lsblk: remember whole-disk, remove unused struct member

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2018-10-18 13:57:46 +02:00
parent d81e32bde9
commit 10501add02
3 changed files with 18 additions and 14 deletions

View 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);

View 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));

View 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);