Commit 97378001 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Steven Rostedt (VMware)

tools/bootconfig: Suppress non-error messages

Suppress non-error messages when applying new bootconfig
to initrd image. To enable it, replace printf for error
message with pr_err() macro.
This also adds a testcase for this fix.

Link: http://lkml.kernel.org/r/158125351377.16911.13283712972275131160.stgit@devnote2Reported-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Tested-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent a91e4f12
...@@ -140,7 +140,7 @@ int load_xbc_from_initrd(int fd, char **buf) ...@@ -140,7 +140,7 @@ int load_xbc_from_initrd(int fd, char **buf)
return 0; return 0;
if (lseek(fd, -8, SEEK_END) < 0) { if (lseek(fd, -8, SEEK_END) < 0) {
printf("Failed to lseek: %d\n", -errno); pr_err("Failed to lseek: %d\n", -errno);
return -errno; return -errno;
} }
...@@ -155,7 +155,7 @@ int load_xbc_from_initrd(int fd, char **buf) ...@@ -155,7 +155,7 @@ int load_xbc_from_initrd(int fd, char **buf)
return 0; return 0;
if (lseek(fd, stat.st_size - 8 - size, SEEK_SET) < 0) { if (lseek(fd, stat.st_size - 8 - size, SEEK_SET) < 0) {
printf("Failed to lseek: %d\n", -errno); pr_err("Failed to lseek: %d\n", -errno);
return -errno; return -errno;
} }
...@@ -166,7 +166,7 @@ int load_xbc_from_initrd(int fd, char **buf) ...@@ -166,7 +166,7 @@ int load_xbc_from_initrd(int fd, char **buf)
/* Wrong Checksum, maybe no boot config here */ /* Wrong Checksum, maybe no boot config here */
rcsum = checksum((unsigned char *)*buf, size); rcsum = checksum((unsigned char *)*buf, size);
if (csum != rcsum) { if (csum != rcsum) {
printf("checksum error: %d != %d\n", csum, rcsum); pr_err("checksum error: %d != %d\n", csum, rcsum);
return 0; return 0;
} }
...@@ -185,13 +185,13 @@ int show_xbc(const char *path) ...@@ -185,13 +185,13 @@ int show_xbc(const char *path)
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd < 0) { if (fd < 0) {
printf("Failed to open initrd %s: %d\n", path, fd); pr_err("Failed to open initrd %s: %d\n", path, fd);
return -errno; return -errno;
} }
ret = load_xbc_from_initrd(fd, &buf); ret = load_xbc_from_initrd(fd, &buf);
if (ret < 0) if (ret < 0)
printf("Failed to load a boot config from initrd: %d\n", ret); pr_err("Failed to load a boot config from initrd: %d\n", ret);
else else
xbc_show_compact_tree(); xbc_show_compact_tree();
...@@ -209,7 +209,7 @@ int delete_xbc(const char *path) ...@@ -209,7 +209,7 @@ int delete_xbc(const char *path)
fd = open(path, O_RDWR); fd = open(path, O_RDWR);
if (fd < 0) { if (fd < 0) {
printf("Failed to open initrd %s: %d\n", path, fd); pr_err("Failed to open initrd %s: %d\n", path, fd);
return -errno; return -errno;
} }
...@@ -222,7 +222,7 @@ int delete_xbc(const char *path) ...@@ -222,7 +222,7 @@ int delete_xbc(const char *path)
pr_output = 1; pr_output = 1;
if (size < 0) { if (size < 0) {
ret = size; ret = size;
printf("Failed to load a boot config from initrd: %d\n", ret); pr_err("Failed to load a boot config from initrd: %d\n", ret);
} else if (size > 0) { } else if (size > 0) {
ret = fstat(fd, &stat); ret = fstat(fd, &stat);
if (!ret) if (!ret)
...@@ -245,7 +245,7 @@ int apply_xbc(const char *path, const char *xbc_path) ...@@ -245,7 +245,7 @@ int apply_xbc(const char *path, const char *xbc_path)
ret = load_xbc_file(xbc_path, &buf); ret = load_xbc_file(xbc_path, &buf);
if (ret < 0) { if (ret < 0) {
printf("Failed to load %s : %d\n", xbc_path, ret); pr_err("Failed to load %s : %d\n", xbc_path, ret);
return ret; return ret;
} }
size = strlen(buf) + 1; size = strlen(buf) + 1;
...@@ -262,7 +262,7 @@ int apply_xbc(const char *path, const char *xbc_path) ...@@ -262,7 +262,7 @@ int apply_xbc(const char *path, const char *xbc_path)
/* Check the data format */ /* Check the data format */
ret = xbc_init(buf); ret = xbc_init(buf);
if (ret < 0) { if (ret < 0) {
printf("Failed to parse %s: %d\n", xbc_path, ret); pr_err("Failed to parse %s: %d\n", xbc_path, ret);
free(data); free(data);
free(buf); free(buf);
return ret; return ret;
...@@ -279,20 +279,20 @@ int apply_xbc(const char *path, const char *xbc_path) ...@@ -279,20 +279,20 @@ int apply_xbc(const char *path, const char *xbc_path)
/* Remove old boot config if exists */ /* Remove old boot config if exists */
ret = delete_xbc(path); ret = delete_xbc(path);
if (ret < 0) { if (ret < 0) {
printf("Failed to delete previous boot config: %d\n", ret); pr_err("Failed to delete previous boot config: %d\n", ret);
return ret; return ret;
} }
/* Apply new one */ /* Apply new one */
fd = open(path, O_RDWR | O_APPEND); fd = open(path, O_RDWR | O_APPEND);
if (fd < 0) { if (fd < 0) {
printf("Failed to open %s: %d\n", path, fd); pr_err("Failed to open %s: %d\n", path, fd);
return fd; return fd;
} }
/* TODO: Ensure the @path is initramfs/initrd image */ /* TODO: Ensure the @path is initramfs/initrd image */
ret = write(fd, data, size + 8); ret = write(fd, data, size + 8);
if (ret < 0) { if (ret < 0) {
printf("Failed to apply a boot config: %d\n", ret); pr_err("Failed to apply a boot config: %d\n", ret);
return ret; return ret;
} }
close(fd); close(fd);
...@@ -334,12 +334,12 @@ int main(int argc, char **argv) ...@@ -334,12 +334,12 @@ int main(int argc, char **argv)
} }
if (apply && delete) { if (apply && delete) {
printf("Error: You can not specify both -a and -d at once.\n"); pr_err("Error: You can not specify both -a and -d at once.\n");
return usage(); return usage();
} }
if (optind >= argc) { if (optind >= argc) {
printf("Error: No initrd is specified.\n"); pr_err("Error: No initrd is specified.\n");
return usage(); return usage();
} }
......
...@@ -64,6 +64,15 @@ echo "File size check" ...@@ -64,6 +64,15 @@ echo "File size check"
new_size=$(stat -c %s $INITRD) new_size=$(stat -c %s $INITRD)
xpass test $new_size -eq $initrd_size xpass test $new_size -eq $initrd_size
echo "No error messge while applying"
OUTFILE=`mktemp tempout-XXXX`
dd if=/dev/zero of=$INITRD bs=4096 count=1
printf " \0\0\0 \0\0\0" >> $INITRD
$BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
xfail grep -i "failed" $OUTFILE
xfail grep -i "error" $OUTFILE
rm $OUTFILE
echo "Max node number check" echo "Max node number check"
echo -n > $TEMPCONF echo -n > $TEMPCONF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment