Commit fe1d6d2b authored by Pavel Emelyanov's avatar Pavel Emelyanov

irmap: Try to load irmap cache from parent as well

If we make workdir coincide with images dir, the irmap
cache will be put in parent images for subsequent dump-s.
Try to load it from there.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent ab57e562
......@@ -347,20 +347,43 @@ static int irmap_cache_one(IrmapCacheEntry *ie)
return 0;
}
int irmap_load_cache(void)
static int open_irmap_cache(int *fd)
{
int fd, ret;
int dir = AT_FDCWD;
fd = open_image_at(AT_FDCWD, CR_FD_IRMAP_CACHE, O_RSTR);
if (fd < 0) {
if (errno == ENOENT) {
pr_info("No irmap cache\n");
return 0;
}
pr_info("Searching irmap cache in work dir\n");
in:
*fd = open_image_at(dir, CR_FD_IRMAP_CACHE, O_RSTR);
if (dir != AT_FDCWD)
close(dir);
return -1;
if (*fd >= 0) {
pr_info("... done\n");
return 1;
}
if (errno == ENOENT && dir == AT_FDCWD) {
pr_info("Searching irmap cache in parent\n");
dir = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);
if (dir >= 0)
goto in;
}
if (errno != ENOENT)
return -1;
pr_info("No irmap cache\n");
return 0;
}
int irmap_load_cache(void)
{
int fd, ret;
ret = open_irmap_cache(&fd);
if (ret <= 0)
return ret;
pr_info("Loading irmap cache\n");
while (1) {
IrmapCacheEntry *ic;
......@@ -378,5 +401,4 @@ int irmap_load_cache(void)
close(fd);
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment