From 84f7a623aba59775498ac7a014974289cc6392ef Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 5 Jan 2016 23:35:55 +0100 Subject: [PATCH] Be more verbose in log and messages about UUID --- HISTORY | 4 +++- cmdline/scan.c | 4 ++++ cmdline/unix.c | 21 +++++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index b798af88..95d633bb 100644 --- a/HISTORY +++ b/HISTORY @@ -17,7 +17,9 @@ SnapRAID HISTORY correctly detecting files that have not a physical offset, for whatever reason. * Adds UUID support to Btrfs filesystems. It's present only if the - 'libblkid' library is available on the system. + 'libblkid' development library is available on the system. + Usually this requires to install the libblkid-dev or libblkid-devel + package. * Added a new --no-warnings option to disable some repetitive warnings that could be annoying to power users. * Improves the error reporting, printing a complete stack trace, that can diff --git a/cmdline/scan.c b/cmdline/scan.c index e25b0ea1..6cb403bd 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -1747,6 +1747,10 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) } if (done) { log_fatal(". Move operations won't be optimal.\n"); +#if defined(_linux) && !HAVE_BLKID + log_fatal("The 'blkid' library is not linked in SnapRAID!\n"); + log_fatal("Try rebuilding it after installing the libblkid-dev/devel package.\n"); +#endif } total.count_equal = 0; diff --git a/cmdline/unix.c b/cmdline/unix.c index 3c06cbb4..6f9d1f28 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -92,6 +92,7 @@ static int devuuid_dev(uint64_t device, char* uuid, size_t uuid_size) /* scan the UUID directory searching for the device */ d = opendir("/dev/disk/by-uuid"); if (!d) { + log_tag("uuid:by-uuidd:%u:%u: opendir(/dev/disk/by-uuid) failed\n", major(device), minor(device)); /* directory missing?, likely we are not in Linux */ return -1; } @@ -103,16 +104,30 @@ static int devuuid_dev(uint64_t device, char* uuid, size_t uuid_size) ret = fstatat(dirfd(d), dd->d_name, &st, 0); if (ret != 0) { + log_tag("uuid:by-uuidd:%u:%u: fstatat(%s) failed\n", major(device), minor(device), dd->d_name); /* generic error, ignore and continue the search */ continue; } /* if it matches, we have the uuid */ if (S_ISBLK(st.st_mode) && st.st_rdev == (dev_t)device) { + char buf[PATH_MAX]; + char path[PATH_MAX]; + + /* resolve the link */ + pathprint(path, sizeof(path), "/dev/disk/by-uuid/%s", dd->d_name); + ret = readlink(path, buf, sizeof(buf)); + if (ret < 0 || ret == sizeof(buf)) { + log_tag("uuid:by-uuidd:%u:%u: readlink(/dev/disk/by-uuid/%s) failed\n", major(device), minor(device), dd->d_name); + /* generic error, ignore and continue the search */ + continue; + } + buf[ret] = 0; + /* found */ pathcpy(uuid, uuid_size, dd->d_name); - log_tag("uuid:dev:%u:%u:%s:\n", major(device), minor(device), uuid); + log_tag("uuid:by-uuid:%u:%u:%s: found %s\n", major(device), minor(device), uuid, buf); closedir(d); return 0; @@ -141,12 +156,14 @@ static int devuuid_blkid(uint64_t device, char* uuid, size_t uuid_size) devname = blkid_devno_to_devname(device); if (!devname) { + log_tag("uuid:blkid:%u:%u: blkid_devno_to_devname() failed\n", major(device), minor(device)); /* device mapping failed */ return -1; } uuidname = blkid_get_tag_value(cache, "UUID", devname); if (!uuidname) { + log_tag("uuid:blkid:%u:%u: blkid_get_tag_value(%s) failed\n", major(device), minor(device), devname); /* uuid mapping failed */ free(devname); return -1; @@ -154,7 +171,7 @@ static int devuuid_blkid(uint64_t device, char* uuid, size_t uuid_size) pathcpy(uuid, uuid_size, uuidname); - log_tag("uuid:dev:%u:%u:%s:\n", major(device), minor(device), uuid); + log_tag("uuid:blkid:%u:%u:%s: found %s\n", major(device), minor(device), uuid, devname); free(devname); free(uuidname);