mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Introduce a new messaging system
This commit is contained in:
parent
fa5f31ddf9
commit
e56de653da
33 changed files with 1642 additions and 1518 deletions
|
|
@ -341,7 +341,7 @@ static dev_t devread(const char* path)
|
|||
f = open(path, O_RDONLY);
|
||||
if (f == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to open '%s'.\n", path);
|
||||
msg_error("Failed to open '%s'.\n", path);
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -350,14 +350,14 @@ static dev_t devread(const char* path)
|
|||
if (ret < 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
close(f);
|
||||
ferr("Failed to read '%s'.\n", path);
|
||||
msg_error("Failed to read '%s'.\n", path);
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
if (ret == sizeof(buf)) {
|
||||
/* LCOV_EXCL_START */
|
||||
close(f);
|
||||
ferr("Too long read '%s'.\n", path);
|
||||
msg_error("Too long read '%s'.\n", path);
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -368,7 +368,7 @@ static dev_t devread(const char* path)
|
|||
if (*e != ':') {
|
||||
/* LCOV_EXCL_START */
|
||||
close(f);
|
||||
ferr("Invalid format in '%s' for '%s'.\n", path, buf);
|
||||
msg_error("Invalid format in '%s' for '%s'.\n", path, buf);
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -377,7 +377,7 @@ static dev_t devread(const char* path)
|
|||
if (*e != 0 && !isspace(*e)) {
|
||||
/* LCOV_EXCL_START */
|
||||
close(f);
|
||||
ferr("Invalid format in '%s' for '%s'.\n", path, buf);
|
||||
msg_error("Invalid format in '%s' for '%s'.\n", path, buf);
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -385,7 +385,7 @@ static dev_t devread(const char* path)
|
|||
ret = close(f);
|
||||
if (ret != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to close '%s'.\n", path);
|
||||
msg_error("Failed to close '%s'.\n", path);
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -411,13 +411,13 @@ static int devresolve(dev_t device, char* path, size_t path_size)
|
|||
ret = readlink(path, buf, sizeof(buf));
|
||||
if (ret < 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to readlink '%s'.\n", path);
|
||||
msg_error("Failed to readlink '%s'.\n", path);
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
if (ret == sizeof(buf)) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Too long readlink '%s'.\n", path);
|
||||
msg_error("Too long readlink '%s'.\n", path);
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -426,7 +426,7 @@ static int devresolve(dev_t device, char* path, size_t path_size)
|
|||
|
||||
if (buf[0] != '.' || buf[1] != '.' || buf[2] != '/') {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Unexpected link '%s' at '%s'.\n", buf, path);
|
||||
msg_error("Unexpected link '%s' at '%s'.\n", buf, path);
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -437,13 +437,13 @@ static int devresolve(dev_t device, char* path, size_t path_size)
|
|||
/* check the device */
|
||||
if (stat(path, &st) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to stat '%s'.\n", path);
|
||||
msg_error("Failed to stat '%s'.\n", path);
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
if (st.st_rdev != device) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Unexpected device '%u:%u' instead of '%u:%u' for '%s'.\n", major(st.st_rdev), minor(st.st_rdev), major(device), minor(device), path);
|
||||
msg_error("Unexpected device '%u:%u' instead of '%u:%u' for '%s'.\n", major(st.st_rdev), minor(st.st_rdev), major(device), minor(device), path);
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -555,7 +555,7 @@ static int devscan(tommy_list* list)
|
|||
d = opendir(dir);
|
||||
if (d == 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to open dir '%s'.\n", dir);
|
||||
msg_error("Failed to open dir '%s'.\n", dir);
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -631,7 +631,7 @@ static int devsmart(dev_t device, uint64_t* smart, char* serial)
|
|||
f = popen(cmd, "r");
|
||||
if (!f) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to run smartctl -a on device '%u:%u' (from popen).\n", major(device), minor(device));
|
||||
msg_error("Failed to run smartctl -a on device '%u:%u' (from popen).\n", major(device), minor(device));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -646,13 +646,13 @@ static int devsmart(dev_t device, uint64_t* smart, char* serial)
|
|||
ret = pclose(f);
|
||||
if (!WIFEXITED(ret)) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to run smartctl -a on device '%u:%u' (not exited).\n", major(device), minor(device));
|
||||
msg_error("Failed to run smartctl -a on device '%u:%u' (not exited).\n", major(device), minor(device));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
if (WEXITSTATUS(ret) == 127) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to run smartctl -a on device '%u:%u' (from sh).\n", major(device), minor(device));
|
||||
msg_error("Failed to run smartctl -a on device '%u:%u' (from sh).\n", major(device), minor(device));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -677,25 +677,25 @@ static int devdown(dev_t device)
|
|||
ret = system(cmd);
|
||||
if (ret == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to run hdparm -y on device '%u:%u' (from system).\n", major(device), minor(device));
|
||||
msg_error("Failed to run hdparm -y on device '%u:%u' (from system).\n", major(device), minor(device));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
if (!WIFEXITED(ret)) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to run hdparm -y on device '%u:%u' (not exited).\n", major(device), minor(device));
|
||||
msg_error("Failed to run hdparm -y on device '%u:%u' (not exited).\n", major(device), minor(device));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
if (WEXITSTATUS(ret) == 127) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to run hdparm -y on device '%u:%u' (from sh).\n", major(device), minor(device));
|
||||
msg_error("Failed to run hdparm -y on device '%u:%u' (from sh).\n", major(device), minor(device));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
if (WEXITSTATUS(ret) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to run hdparm -y on device '%u:%u' with return code %xh.\n", major(device), minor(device), WEXITSTATUS(ret));
|
||||
msg_error("Failed to run hdparm -y on device '%u:%u' with return code %xh.\n", major(device), minor(device), WEXITSTATUS(ret));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -722,7 +722,7 @@ static int devup(const char* mount)
|
|||
ret = mkdir(path, 0);
|
||||
if (ret != 0 && errno != EEXIST) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to create dir '%s'.\n", path);
|
||||
msg_error("Failed to create dir '%s'.\n", path);
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -751,7 +751,7 @@ static void* thread_spinup(void* arg)
|
|||
/* first get the device number, this usually doesn't trigger a thread_spinup */
|
||||
if (stat(devinfo->mount, &st) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to stat device '%s'.\n", devinfo->mount);
|
||||
msg_error("Failed to stat device '%s'.\n", devinfo->mount);
|
||||
return (void*)-1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -772,7 +772,7 @@ static void* thread_spinup(void* arg)
|
|||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
fout("Spunup device '%s' for disk '%s' in %" PRIu64 " ms.\n", devinfo->file, devinfo->name, tick_ms() - start);
|
||||
msg_status("Spunup device '%s' for disk '%s' in %" PRIu64 " ms.\n", devinfo->file, devinfo->name, tick_ms() - start);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -794,7 +794,7 @@ static void* thread_spindown(void* arg)
|
|||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
fout("Spundown device '%s' for disk '%s' in %" PRIu64 " ms.\n", devinfo->file, devinfo->name, tick_ms() - start);
|
||||
msg_status("Spundown device '%s' for disk '%s' in %" PRIu64 " ms.\n", devinfo->file, devinfo->name, tick_ms() - start);
|
||||
|
||||
return 0;
|
||||
#else
|
||||
|
|
@ -831,7 +831,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg))
|
|||
|
||||
if (pthread_create(&devinfo->thread, 0, func, devinfo) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to create thread.\n");
|
||||
msg_error("Failed to create thread.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -844,7 +844,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg))
|
|||
|
||||
if (pthread_join(devinfo->thread, &retval) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to join thread.\n");
|
||||
msg_error("Failed to join thread.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -880,13 +880,13 @@ int devquery(tommy_list* high, tommy_list* low, int operation)
|
|||
/* sysfs and devfs interfaces are required */
|
||||
if (stat("/sys/dev/block", &st) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Missing interface /sys/dev/block.\n");
|
||||
msg_error("Missing interface /sys/dev/block.\n");
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
if (stat("/dev/block", &st) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Missing interface /dev/block.\n");
|
||||
msg_error("Missing interface /dev/block.\n");
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -898,7 +898,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation)
|
|||
/* get the device file */
|
||||
if (devresolve(devinfo->device, devinfo->file, sizeof(devinfo->file)) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to resolve device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device));
|
||||
msg_error("Failed to resolve device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -906,7 +906,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation)
|
|||
/* expand the tree of devices */
|
||||
if (devtree(devinfo->name, devinfo->device, devinfo, low) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to expand device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device));
|
||||
msg_error("Failed to expand device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -936,7 +936,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation)
|
|||
if (operation == DEVICE_SMART) {
|
||||
if (devscan(low) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
ferr("Failed to list other devices.\n");
|
||||
msg_error("Failed to list other devices.\n");
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue