diff options
author | Karel Zak | 2011-06-23 12:29:00 +0200 |
---|---|---|
committer | Karel Zak | 2011-06-23 12:29:00 +0200 |
commit | 679f59dde22ead560bfebdd7011d254ce12fce36 (patch) | |
tree | e1b5b501b07a91f35049eee4b54a0f7ddee78954 /libmount/src/cache.c | |
parent | libmount: rename in cache.c (diff) | |
download | kernel-qcow2-util-linux-679f59dde22ead560bfebdd7011d254ce12fce36.tar.gz kernel-qcow2-util-linux-679f59dde22ead560bfebdd7011d254ce12fce36.tar.xz kernel-qcow2-util-linux-679f59dde22ead560bfebdd7011d254ce12fce36.zip |
libmount: fix fstype caching
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/cache.c')
-rw-r--r-- | libmount/src/cache.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/libmount/src/cache.c b/libmount/src/cache.c index 4c37c5a9c..2738eee80 100644 --- a/libmount/src/cache.c +++ b/libmount/src/cache.c @@ -228,6 +228,27 @@ static const char *cache_find_tag(struct libmnt_cache *cache, return NULL; } +static char *cache_find_tag_value(struct libmnt_cache *cache, + const char *devname, const char *token) +{ + int i; + + assert(cache); + assert(devname); + assert(token); + + for (i = 0; i < cache->nents; i++) { + struct mnt_cache_entry *e = &cache->ents[i]; + if (!(e->flag & MNT_CACHE_ISTAG)) + continue; + if (strcmp(e->value, devname) == 0 && /* dev name */ + strcmp(token, e->key) == 0) /* tag name */ + return e->key + strlen(token) + 1; /* tag value */ + } + + return NULL; +} + /* * returns (in @res) blkid prober, the @cache argument is optional */ @@ -316,11 +337,13 @@ int mnt_cache_read_tags(struct libmnt_cache *cache, const char *devname) const char *data; char *dev; + if (cache_find_tag_value(cache, devname, tags[i])) { + DBG(CACHE, mnt_debug_h(cache, + "\ntag %s already cached", tags[i])); + continue; + } if (blkid_probe_lookup_value(cache->pr, tags[i], &data, NULL)) continue; - if (cache_find_tag(cache, tags[i], data)) - continue; /* already cached */ - dev = strdup(devname); if (!dev) goto error; @@ -370,24 +393,13 @@ int mnt_cache_device_has_tag(struct libmnt_cache *cache, const char *devname, char *mnt_cache_find_tag_value(struct libmnt_cache *cache, const char *devname, const char *token) { - int i; - if (!cache || !devname || !token) return NULL; if (mnt_cache_read_tags(cache, devname) != 0) return NULL; - for (i = 0; i < cache->nents; i++) { - struct mnt_cache_entry *e = &cache->ents[i]; - if (!(e->flag & MNT_CACHE_ISTAG)) - continue; - if (strcmp(e->value, devname) == 0 && /* dev name */ - strcmp(token, e->key) == 0) /* tag name */ - return e->key + strlen(token) + 1; /* tag value */ - } - - return NULL; + return cache_find_tag_value(cache, devname, token); } /** |