提交 9f2879d3 编写于 作者: E Eric Blake

util: reduce syscalls for virGetDeviceID

There's no need to do lots of readlink() calls to canonicalize
a name if we're only going to use stat() on it, since stat()
already chases symlinks.

* src/util/virutil.c (virGetDeviceID): Let stat() do the symlink
chasing.
上级 66b46932
/*
* virutil.c: common, generic utility functions
*
* Copyright (C) 2006-2012 Red Hat, Inc.
* Copyright (C) 2006-2013 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
* Copyright (C) 2006, 2007 Binary Karma
* Copyright (C) 2006 Shuveb Hussain
......@@ -3135,27 +3135,18 @@ int
virGetDeviceID(const char *path, int *maj, int *min)
{
struct stat sb;
char *canonical_path = NULL;
if (virFileResolveLink(path, &canonical_path) < 0)
if (stat(path, &sb) < 0)
return -errno;
if (stat(canonical_path, &sb) < 0) {
VIR_FREE(canonical_path);
return -errno;
}
if (!S_ISBLK(sb.st_mode)) {
VIR_FREE(canonical_path);
if (!S_ISBLK(sb.st_mode))
return -EINVAL;
}
if (maj)
*maj = major(sb.st_rdev);
if (min)
*min = minor(sb.st_rdev);
VIR_FREE(canonical_path);
return 0;
}
#else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册