From 2238214ddc81d8ecab386d9e38d68f9357e2ad74 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 24 Mar 2016 11:51:12 +0100 Subject: libmount: try absolute target before canonicalize The path canonicalization is expensive and in many cases unwanted due to problems with readlink() on unreachable NFS and automounters. This patch add a possibility to search also by $(CWD)/ if the is relative to reduce number of situation when we convert the path to the canonical absolute path. The common use-case: # cd /some/long/path # umount ./mountpoint old version: 15543: libmount: TAB: [0x560a99a54230]: lookup TARGET: './test' 15543: libmount: CACHE: [0x560a99a54290]: canonicalize path ./test 15543: libmount: CACHE: [0x560a99a54290]: add entry [ 1] (path): /mnt/test: ./test 15543: libmount: TAB: [0x560a99a54230]: lookup canonical TARGET: '/mnt/test' 15543: libmount: CXT: [0x560a99a54050]: umount fs: /mnt/test new version: 15597: libmount: TAB: [0xabf230]: lookup TARGET: './test' 15597: libmount: TAB: [0xabf230]: lookup absolute TARGET: '/mnt/test' 15597: libmount: CXT: [0xabf050]: umount fs: /mnt/test Signed-off-by: Karel Zak --- libmount/src/tab.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libmount/src/tab.c') diff --git a/libmount/src/tab.c b/libmount/src/tab.c index d7a633cba..a8d835e04 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -867,6 +867,20 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat if (mnt_fs_streq_target(fs, path)) return fs; } + + /* try absolute path */ + if (is_relative_path(path) && (cn = absolute_path(path))) { + DBG(TAB, ul_debugobj(tb, "lookup absolute TARGET: '%s'", cn)); + mnt_reset_iter(&itr, direction); + while (mnt_table_next_fs(tb, &itr, &fs) == 0) { + if (mnt_fs_streq_target(fs, cn)) { + free(cn); + return fs; + } + } + free(cn); + } + if (!tb->cache || !(cn = mnt_resolve_path(path, tb->cache))) return NULL; -- cgit v1.2.3-55-g7522