Skip to content

Commit 9737800

Browse files
mhiramatrostedt
authored andcommitted
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@devnote2 Reported-by: Michael Ellerman <[email protected]> Tested-by: Michael Ellerman <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent a91e4f1 commit 9737800

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

tools/bootconfig/main.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int load_xbc_from_initrd(int fd, char **buf)
140140
return 0;
141141

142142
if (lseek(fd, -8, SEEK_END) < 0) {
143-
printf("Failed to lseek: %d\n", -errno);
143+
pr_err("Failed to lseek: %d\n", -errno);
144144
return -errno;
145145
}
146146

@@ -155,7 +155,7 @@ int load_xbc_from_initrd(int fd, char **buf)
155155
return 0;
156156

157157
if (lseek(fd, stat.st_size - 8 - size, SEEK_SET) < 0) {
158-
printf("Failed to lseek: %d\n", -errno);
158+
pr_err("Failed to lseek: %d\n", -errno);
159159
return -errno;
160160
}
161161

@@ -166,7 +166,7 @@ int load_xbc_from_initrd(int fd, char **buf)
166166
/* Wrong Checksum, maybe no boot config here */
167167
rcsum = checksum((unsigned char *)*buf, size);
168168
if (csum != rcsum) {
169-
printf("checksum error: %d != %d\n", csum, rcsum);
169+
pr_err("checksum error: %d != %d\n", csum, rcsum);
170170
return 0;
171171
}
172172

@@ -185,13 +185,13 @@ int show_xbc(const char *path)
185185

186186
fd = open(path, O_RDONLY);
187187
if (fd < 0) {
188-
printf("Failed to open initrd %s: %d\n", path, fd);
188+
pr_err("Failed to open initrd %s: %d\n", path, fd);
189189
return -errno;
190190
}
191191

192192
ret = load_xbc_from_initrd(fd, &buf);
193193
if (ret < 0)
194-
printf("Failed to load a boot config from initrd: %d\n", ret);
194+
pr_err("Failed to load a boot config from initrd: %d\n", ret);
195195
else
196196
xbc_show_compact_tree();
197197

@@ -209,7 +209,7 @@ int delete_xbc(const char *path)
209209

210210
fd = open(path, O_RDWR);
211211
if (fd < 0) {
212-
printf("Failed to open initrd %s: %d\n", path, fd);
212+
pr_err("Failed to open initrd %s: %d\n", path, fd);
213213
return -errno;
214214
}
215215

@@ -222,7 +222,7 @@ int delete_xbc(const char *path)
222222
pr_output = 1;
223223
if (size < 0) {
224224
ret = size;
225-
printf("Failed to load a boot config from initrd: %d\n", ret);
225+
pr_err("Failed to load a boot config from initrd: %d\n", ret);
226226
} else if (size > 0) {
227227
ret = fstat(fd, &stat);
228228
if (!ret)
@@ -245,7 +245,7 @@ int apply_xbc(const char *path, const char *xbc_path)
245245

246246
ret = load_xbc_file(xbc_path, &buf);
247247
if (ret < 0) {
248-
printf("Failed to load %s : %d\n", xbc_path, ret);
248+
pr_err("Failed to load %s : %d\n", xbc_path, ret);
249249
return ret;
250250
}
251251
size = strlen(buf) + 1;
@@ -262,7 +262,7 @@ int apply_xbc(const char *path, const char *xbc_path)
262262
/* Check the data format */
263263
ret = xbc_init(buf);
264264
if (ret < 0) {
265-
printf("Failed to parse %s: %d\n", xbc_path, ret);
265+
pr_err("Failed to parse %s: %d\n", xbc_path, ret);
266266
free(data);
267267
free(buf);
268268
return ret;
@@ -279,20 +279,20 @@ int apply_xbc(const char *path, const char *xbc_path)
279279
/* Remove old boot config if exists */
280280
ret = delete_xbc(path);
281281
if (ret < 0) {
282-
printf("Failed to delete previous boot config: %d\n", ret);
282+
pr_err("Failed to delete previous boot config: %d\n", ret);
283283
return ret;
284284
}
285285

286286
/* Apply new one */
287287
fd = open(path, O_RDWR | O_APPEND);
288288
if (fd < 0) {
289-
printf("Failed to open %s: %d\n", path, fd);
289+
pr_err("Failed to open %s: %d\n", path, fd);
290290
return fd;
291291
}
292292
/* TODO: Ensure the @path is initramfs/initrd image */
293293
ret = write(fd, data, size + 8);
294294
if (ret < 0) {
295-
printf("Failed to apply a boot config: %d\n", ret);
295+
pr_err("Failed to apply a boot config: %d\n", ret);
296296
return ret;
297297
}
298298
close(fd);
@@ -334,12 +334,12 @@ int main(int argc, char **argv)
334334
}
335335

336336
if (apply && delete) {
337-
printf("Error: You can not specify both -a and -d at once.\n");
337+
pr_err("Error: You can not specify both -a and -d at once.\n");
338338
return usage();
339339
}
340340

341341
if (optind >= argc) {
342-
printf("Error: No initrd is specified.\n");
342+
pr_err("Error: No initrd is specified.\n");
343343
return usage();
344344
}
345345

tools/bootconfig/test-bootconfig.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ echo "File size check"
6464
new_size=$(stat -c %s $INITRD)
6565
xpass test $new_size -eq $initrd_size
6666

67+
echo "No error messge while applying"
68+
OUTFILE=`mktemp tempout-XXXX`
69+
dd if=/dev/zero of=$INITRD bs=4096 count=1
70+
printf " \0\0\0 \0\0\0" >> $INITRD
71+
$BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
72+
xfail grep -i "failed" $OUTFILE
73+
xfail grep -i "error" $OUTFILE
74+
rm $OUTFILE
75+
6776
echo "Max node number check"
6877

6978
echo -n > $TEMPCONF

0 commit comments

Comments
 (0)