From: Vitaly Fertman Date: Mon, 4 Oct 2010 21:00:34 +0000 (+0400) Subject: b=20687 umount symbolic link device X-Git-Tag: 2.0.53.0~11 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=3f68a0c41ce531475f8a2f407c87d6ae4380c592;ds=sidebyside b=20687 umount symbolic link device i=vitaly --- diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index 6b7cfe5..8130da8 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -494,8 +494,12 @@ set_params: int main(int argc, char *const argv[]) { char default_options[] = ""; - char *usource, *source; + char *usource, *source, *ptr; char target[PATH_MAX] = {'\0'}; + char real_path[PATH_MAX] = {'\0'}; + char path[256], name[256]; + FILE *f; + size_t sz; char *options, *optcopy, *orig_options = default_options; int i, nargs = 3, opt, rc, flags, optlen; static struct option long_opt[] = { @@ -558,6 +562,27 @@ int main(int argc, char *const argv[]) usage(stderr); } + /** + * Try to get the real path to the device, in case it is a + * symbolic link for instance + */ + if (realpath(usource, real_path) != NULL) { + usource = real_path; + + ptr = strrchr(real_path, '/'); + if (ptr && strncmp(ptr, "/dm-", 4) == 0 && isdigit(*(ptr + 4))) { + snprintf(path, sizeof(path), "/sys/block/%s/dm/name", ptr+1); + if ((f = fopen(path, "r"))) { + /* read "\n" from sysfs */ + if (fgets(name, sizeof(name), f) && (sz = strlen(name)) > 1) { + name[sz - 1] = '\0'; + snprintf(real_path, sizeof(real_path), "/dev/mapper/%s", name); + } + fclose(f); + } + } + } + source = convert_hostnames(usource); if (!source) { usage(stderr);