|
|
b394b9 |
From 75b6c0e045abb7e07773b924237c562ab9920c60 Mon Sep 17 00:00:00 2001
|
|
|
b394b9 |
From: Karel Zak <kzak@redhat.com>
|
|
|
b394b9 |
Date: Thu, 26 May 2016 12:02:12 +0200
|
|
|
b394b9 |
Subject: [PATCH 85/86] libblkid: store only canonical devnames to the cache
|
|
|
b394b9 |
|
|
|
b394b9 |
Let's try to use symlink:
|
|
|
b394b9 |
|
|
|
b394b9 |
# ls -la /dev/block/8\:1
|
|
|
b394b9 |
# lrwxrwxrwx 1 root root 7 May 25 16:42 /dev/block/8:1 -> ../sda1
|
|
|
b394b9 |
|
|
|
b394b9 |
# blkid /dev/block/8:1
|
|
|
b394b9 |
/dev/block/8:3: LABEL="HOME" UUID="196972ad-3b13-4bba-ac54-4cb3f7b409a4" TYPE="ext4" PARTUUID="6073277f-87bc-43ff-bcfd-724c4484a63a"
|
|
|
b394b9 |
|
|
|
b394b9 |
unfortunately the symlink is stored to the cache:
|
|
|
b394b9 |
|
|
|
b394b9 |
<device DEVNO="0x0803" TIME="1464253300.715279" LABEL="HOME" UUID="196972ad-3b13-4bba-ac54-4cb3f7b409a4" TYPE="ext4" PARTUUID="6073277f-87bc-43ff-bcfd-724c4484a63a">/dev/block/8:3</device>
|
|
|
b394b9 |
|
|
|
b394b9 |
next time if you ask for LABEL=HOME the answer will be /dev/block/8:3
|
|
|
b394b9 |
rather than /dev/sda3.
|
|
|
b394b9 |
|
|
|
b394b9 |
It seems better to canonicalize the paths we store to the cache.
|
|
|
b394b9 |
|
|
|
b394b9 |
Unfortunately if you ask for /dev/block/8:3 then you probably expect
|
|
|
b394b9 |
that blkid_dev_devname() returns the same path. This patch introduces
|
|
|
b394b9 |
dev->bid_xname, this is the path used by application (and never stored
|
|
|
b394b9 |
in the cache).
|
|
|
b394b9 |
|
|
|
b394b9 |
Upstream: http://github.com/karelzak/util-linux/commit/924c93d9df118338fd54cd73b4a45ccddc4ac103
|
|
|
b394b9 |
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1007734
|
|
|
b394b9 |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
b394b9 |
---
|
|
|
b394b9 |
libblkid/src/blkidP.h | 4 +++-
|
|
|
b394b9 |
libblkid/src/dev.c | 11 +++++++++--
|
|
|
b394b9 |
libblkid/src/devname.c | 43 +++++++++++++++++++++++++++++++++++++------
|
|
|
b394b9 |
3 files changed, 49 insertions(+), 9 deletions(-)
|
|
|
b394b9 |
|
|
|
b394b9 |
diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h
|
|
|
b394b9 |
index 7de84b4..8183c12 100644
|
|
|
b394b9 |
--- a/libblkid/src/blkidP.h
|
|
|
b394b9 |
+++ b/libblkid/src/blkidP.h
|
|
|
b394b9 |
@@ -44,7 +44,7 @@ struct blkid_struct_dev
|
|
|
b394b9 |
struct list_head bid_devs; /* All devices in the cache */
|
|
|
b394b9 |
struct list_head bid_tags; /* All tags for this device */
|
|
|
b394b9 |
blkid_cache bid_cache; /* Dev belongs to this cache */
|
|
|
b394b9 |
- char *bid_name; /* Device inode pathname */
|
|
|
b394b9 |
+ char *bid_name; /* Device real pathn (as used in cache) */
|
|
|
b394b9 |
char *bid_type; /* Preferred device TYPE */
|
|
|
b394b9 |
int bid_pri; /* Device priority */
|
|
|
b394b9 |
dev_t bid_devno; /* Device major/minor number */
|
|
|
b394b9 |
@@ -53,6 +53,8 @@ struct blkid_struct_dev
|
|
|
b394b9 |
unsigned int bid_flags; /* Device status bitflags */
|
|
|
b394b9 |
char *bid_label; /* Shortcut to device LABEL */
|
|
|
b394b9 |
char *bid_uuid; /* Shortcut to binary UUID */
|
|
|
b394b9 |
+
|
|
|
b394b9 |
+ char *bid_xname; /* Device path as used by application (maybe symlink..) */
|
|
|
b394b9 |
};
|
|
|
b394b9 |
|
|
|
b394b9 |
#define BLKID_BID_FL_VERIFIED 0x0001 /* Device data validated from disk */
|
|
|
b394b9 |
diff --git a/libblkid/src/dev.c b/libblkid/src/dev.c
|
|
|
b394b9 |
index a4b2aea..d2fd3f4 100644
|
|
|
b394b9 |
--- a/libblkid/src/dev.c
|
|
|
b394b9 |
+++ b/libblkid/src/dev.c
|
|
|
b394b9 |
@@ -60,16 +60,23 @@ void blkid_free_dev(blkid_dev dev)
|
|
|
b394b9 |
bit_tags);
|
|
|
b394b9 |
blkid_free_tag(tag);
|
|
|
b394b9 |
}
|
|
|
b394b9 |
+ free(dev->bid_xname);
|
|
|
b394b9 |
free(dev->bid_name);
|
|
|
b394b9 |
free(dev);
|
|
|
b394b9 |
}
|
|
|
b394b9 |
|
|
|
b394b9 |
/*
|
|
|
b394b9 |
- * Given a blkid device, return its name
|
|
|
b394b9 |
+ * Given a blkid device, return its name. The function returns the name
|
|
|
b394b9 |
+ * previously used for blkid_get_dev(). This name does not have to be canonical
|
|
|
b394b9 |
+ * (real path) name, but for example symlink.
|
|
|
b394b9 |
*/
|
|
|
b394b9 |
const char *blkid_dev_devname(blkid_dev dev)
|
|
|
b394b9 |
{
|
|
|
b394b9 |
- return dev ? dev->bid_name : NULL;
|
|
|
b394b9 |
+ if (!dev)
|
|
|
b394b9 |
+ return NULL;
|
|
|
b394b9 |
+ if (dev->bid_xname)
|
|
|
b394b9 |
+ return dev->bid_xname;
|
|
|
b394b9 |
+ return dev->bid_name;
|
|
|
b394b9 |
}
|
|
|
b394b9 |
|
|
|
b394b9 |
#ifdef CONFIG_BLKID_DEBUG
|
|
|
b394b9 |
diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c
|
|
|
b394b9 |
index 497deaf..55b9594 100644
|
|
|
b394b9 |
--- a/libblkid/src/devname.c
|
|
|
b394b9 |
+++ b/libblkid/src/devname.c
|
|
|
b394b9 |
@@ -51,28 +51,55 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
|
|
|
b394b9 |
{
|
|
|
b394b9 |
blkid_dev dev = NULL, tmp;
|
|
|
b394b9 |
struct list_head *p, *pnext;
|
|
|
b394b9 |
+ char *cn = NULL;
|
|
|
b394b9 |
|
|
|
b394b9 |
if (!cache || !devname)
|
|
|
b394b9 |
return NULL;
|
|
|
b394b9 |
|
|
|
b394b9 |
+ /* search by name */
|
|
|
b394b9 |
list_for_each(p, &cache->bic_devs) {
|
|
|
b394b9 |
tmp = list_entry(p, struct blkid_struct_dev, bid_devs);
|
|
|
b394b9 |
if (strcmp(tmp->bid_name, devname))
|
|
|
b394b9 |
continue;
|
|
|
b394b9 |
-
|
|
|
b394b9 |
- DBG(DEVNAME, blkid_debug("found devname %s in cache", tmp->bid_name));
|
|
|
b394b9 |
dev = tmp;
|
|
|
b394b9 |
break;
|
|
|
b394b9 |
}
|
|
|
b394b9 |
|
|
|
b394b9 |
+ /* try canonicalize the name */
|
|
|
b394b9 |
+ if (!dev && (cn = canonicalize_path(devname))) {
|
|
|
b394b9 |
+ if (strcmp(cn, devname) != 0) {
|
|
|
b394b9 |
+ DBG(DEVNAME, blkid_debug("search cannonical %s", cn));
|
|
|
b394b9 |
+ list_for_each(p, &cache->bic_devs) {
|
|
|
b394b9 |
+ tmp = list_entry(p, struct blkid_struct_dev, bid_devs);
|
|
|
b394b9 |
+ if (strcmp(tmp->bid_name, cn))
|
|
|
b394b9 |
+ continue;
|
|
|
b394b9 |
+ dev = tmp;
|
|
|
b394b9 |
+
|
|
|
b394b9 |
+ /* update name returned by blkid_dev_devname() */
|
|
|
b394b9 |
+ free(dev->bid_xname);
|
|
|
b394b9 |
+ dev->bid_xname = strdup(devname);
|
|
|
b394b9 |
+ break;
|
|
|
b394b9 |
+ }
|
|
|
b394b9 |
+ } else {
|
|
|
b394b9 |
+ free(cn);
|
|
|
b394b9 |
+ cn = NULL;
|
|
|
b394b9 |
+ }
|
|
|
b394b9 |
+ }
|
|
|
b394b9 |
+
|
|
|
b394b9 |
if (!dev && (flags & BLKID_DEV_CREATE)) {
|
|
|
b394b9 |
if (access(devname, F_OK) < 0)
|
|
|
b394b9 |
- return NULL;
|
|
|
b394b9 |
+ goto done;
|
|
|
b394b9 |
dev = blkid_new_dev();
|
|
|
b394b9 |
if (!dev)
|
|
|
b394b9 |
- return NULL;
|
|
|
b394b9 |
+ goto done;
|
|
|
b394b9 |
dev->bid_time = INT_MIN;
|
|
|
b394b9 |
- dev->bid_name = strdup(devname);
|
|
|
b394b9 |
+ if (cn) {
|
|
|
b394b9 |
+ dev->bid_name = cn;
|
|
|
b394b9 |
+ dev->bid_xname = strdup(devname);
|
|
|
b394b9 |
+ cn = NULL; /* see free() below */
|
|
|
b394b9 |
+ } else
|
|
|
b394b9 |
+ dev->bid_name = strdup(devname);
|
|
|
b394b9 |
+
|
|
|
b394b9 |
dev->bid_cache = cache;
|
|
|
b394b9 |
list_add_tail(&dev->bid_devs, &cache->bic_devs);
|
|
|
b394b9 |
cache->bic_flags |= BLKID_BIC_FL_CHANGED;
|
|
|
b394b9 |
@@ -81,7 +108,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
|
|
|
b394b9 |
if (flags & BLKID_DEV_VERIFY) {
|
|
|
b394b9 |
dev = blkid_verify(cache, dev);
|
|
|
b394b9 |
if (!dev || !(dev->bid_flags & BLKID_BID_FL_VERIFIED))
|
|
|
b394b9 |
- return dev;
|
|
|
b394b9 |
+ goto done;
|
|
|
b394b9 |
/*
|
|
|
b394b9 |
* If the device is verified, then search the blkid
|
|
|
b394b9 |
* cache for any entries that match on the type, uuid,
|
|
|
b394b9 |
@@ -112,6 +139,10 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
|
|
|
b394b9 |
blkid_free_dev(dev2);
|
|
|
b394b9 |
}
|
|
|
b394b9 |
}
|
|
|
b394b9 |
+done:
|
|
|
b394b9 |
+ if (dev)
|
|
|
b394b9 |
+ DBG(DEVNAME, blkid_debug("%s requested, found %s in cache", devname, dev->bid_name));
|
|
|
b394b9 |
+ free(cn);
|
|
|
b394b9 |
return dev;
|
|
|
b394b9 |
}
|
|
|
b394b9 |
|
|
|
b394b9 |
--
|
|
|
b394b9 |
2.7.4
|
|
|
b394b9 |
|