From: Eric Blake Date: Wed, 9 Jan 2013 23:34:15 +0000 (-0700) Subject: util: reduce syscalls for virGetDeviceID X-Git-Tag: v1.0.2-rc1~230 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f2879d3113e1ef177941f52df868f926b37ce5b;p=thirdparty%2Flibvirt.git 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. --- diff --git a/src/util/virutil.c b/src/util/virutil.c index 47ab17f542..7c54bea717 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1,7 +1,7 @@ /* * 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