@@ -77,14 +77,24 @@ static DEFINE_SPINLOCK(pstore_lock);
77
77
struct pstore_info * psinfo ;
78
78
79
79
static char * backend ;
80
+ static char * compress =
81
+ #ifdef CONFIG_PSTORE_COMPRESS_DEFAULT
82
+ CONFIG_PSTORE_COMPRESS_DEFAULT ;
83
+ #else
84
+ NULL ;
85
+ #endif
80
86
81
87
/* Compression parameters */
82
88
#ifdef CONFIG_PSTORE_ZLIB_COMPRESS
83
89
#define COMPR_LEVEL 6
84
90
#define WINDOW_BITS 12
85
91
#define MEM_LEVEL 4
86
92
static struct z_stream_s stream ;
87
- #else
93
+ #endif
94
+ #if defined(CONFIG_PSTORE_LZO_COMPRESS ) || \
95
+ defined(CONFIG_PSTORE_LZ4_COMPRESS ) || \
96
+ defined(CONFIG_PSTORE_LZ4HC_COMPRESS ) || \
97
+ defined(CONFIG_PSTORE_842_COMPRESS )
88
98
static unsigned char * workspace ;
89
99
#endif
90
100
@@ -268,14 +278,6 @@ static void free_zlib(void)
268
278
big_oops_buf = NULL ;
269
279
big_oops_buf_sz = 0 ;
270
280
}
271
-
272
- static const struct pstore_zbackend backend_zlib = {
273
- .compress = compress_zlib ,
274
- .decompress = decompress_zlib ,
275
- .allocate = allocate_zlib ,
276
- .free = free_zlib ,
277
- .name = "zlib" ,
278
- };
279
281
#endif
280
282
281
283
#ifdef CONFIG_PSTORE_LZO_COMPRESS
@@ -329,14 +331,6 @@ static void free_lzo(void)
329
331
big_oops_buf = NULL ;
330
332
big_oops_buf_sz = 0 ;
331
333
}
332
-
333
- static const struct pstore_zbackend backend_lzo = {
334
- .compress = compress_lzo ,
335
- .decompress = decompress_lzo ,
336
- .allocate = allocate_lzo ,
337
- .free = free_lzo ,
338
- .name = "lzo" ,
339
- };
340
334
#endif
341
335
342
336
#if defined(CONFIG_PSTORE_LZ4_COMPRESS ) || defined(CONFIG_PSTORE_LZ4HC_COMPRESS )
@@ -396,14 +390,6 @@ static void allocate_lz4(void)
396
390
workspace = NULL ;
397
391
}
398
392
}
399
-
400
- static const struct pstore_zbackend backend_lz4 = {
401
- .compress = compress_lz4 ,
402
- .decompress = decompress_lz4 ,
403
- .allocate = allocate_lz4 ,
404
- .free = free_lz4 ,
405
- .name = "lz4" ,
406
- };
407
393
#endif
408
394
409
395
#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS
@@ -438,14 +424,6 @@ static void allocate_lz4hc(void)
438
424
workspace = NULL ;
439
425
}
440
426
}
441
-
442
- static const struct pstore_zbackend backend_lz4hc = {
443
- .compress = compress_lz4hc ,
444
- .decompress = decompress_lz4 ,
445
- .allocate = allocate_lz4hc ,
446
- .free = free_lz4 ,
447
- .name = "lz4hc" ,
448
- };
449
427
#endif
450
428
451
429
#ifdef CONFIG_PSTORE_842_COMPRESS
@@ -508,30 +486,58 @@ static void free_842(void)
508
486
big_oops_buf = NULL ;
509
487
big_oops_buf_sz = 0 ;
510
488
}
511
-
512
- static const struct pstore_zbackend backend_842 = {
513
- .compress = compress_842 ,
514
- .decompress = decompress_842 ,
515
- .allocate = allocate_842 ,
516
- .free = free_842 ,
517
- .name = "842" ,
518
- };
519
489
#endif
520
490
521
- static const struct pstore_zbackend * zbackend =
522
- #if defined(CONFIG_PSTORE_ZLIB_COMPRESS )
523
- & backend_zlib ;
524
- #elif defined(CONFIG_PSTORE_LZO_COMPRESS )
525
- & backend_lzo ;
526
- #elif defined(CONFIG_PSTORE_LZ4_COMPRESS )
527
- & backend_lz4 ;
528
- #elif defined(CONFIG_PSTORE_LZ4HC_COMPRESS )
529
- & backend_lz4hc ;
530
- #elif defined(CONFIG_PSTORE_842_COMPRESS )
531
- & backend_842 ;
532
- #else
533
- NULL ;
491
+ static const struct pstore_zbackend * zbackend __ro_after_init ;
492
+
493
+ static const struct pstore_zbackend zbackends [] = {
494
+ #ifdef CONFIG_PSTORE_ZLIB_COMPRESS
495
+ {
496
+ .compress = compress_zlib ,
497
+ .decompress = decompress_zlib ,
498
+ .allocate = allocate_zlib ,
499
+ .free = free_zlib ,
500
+ .name = "zlib" ,
501
+ },
502
+ #endif
503
+ #ifdef CONFIG_PSTORE_LZO_COMPRESS
504
+ {
505
+ .compress = compress_lzo ,
506
+ .decompress = decompress_lzo ,
507
+ .allocate = allocate_lzo ,
508
+ .free = free_lzo ,
509
+ .name = "lzo" ,
510
+ },
511
+ #endif
512
+ #ifdef CONFIG_PSTORE_LZ4_COMPRESS
513
+ {
514
+ .compress = compress_lz4 ,
515
+ .decompress = decompress_lz4 ,
516
+ .allocate = allocate_lz4 ,
517
+ .free = free_lz4 ,
518
+ .name = "lz4" ,
519
+ },
520
+ #endif
521
+ #ifdef CONFIG_PSTORE_LZ4HC_COMPRESS
522
+ {
523
+ .compress = compress_lz4hc ,
524
+ .decompress = decompress_lz4 ,
525
+ .allocate = allocate_lz4hc ,
526
+ .free = free_lz4 ,
527
+ .name = "lz4hc" ,
528
+ },
534
529
#endif
530
+ #ifdef CONFIG_PSTORE_842_COMPRESS
531
+ {
532
+ .compress = compress_842 ,
533
+ .decompress = decompress_842 ,
534
+ .allocate = allocate_842 ,
535
+ .free = free_842 ,
536
+ .name = "842" ,
537
+ },
538
+ #endif
539
+ { }
540
+ };
535
541
536
542
static int pstore_compress (const void * in , void * out ,
537
543
size_t inlen , size_t outlen )
@@ -553,7 +559,6 @@ static int pstore_decompress(void *in, void *out, size_t inlen, size_t outlen)
553
559
static void allocate_buf_for_compression (void )
554
560
{
555
561
if (zbackend ) {
556
- pr_info ("using %s compression\n" , zbackend -> name );
557
562
zbackend -> allocate ();
558
563
} else {
559
564
pr_err ("allocate compression buffer error!\n" );
@@ -1022,5 +1027,24 @@ static void pstore_timefunc(struct timer_list *unused)
1022
1027
jiffies + msecs_to_jiffies (pstore_update_ms ));
1023
1028
}
1024
1029
1030
+ void __init pstore_choose_compression (void )
1031
+ {
1032
+ const struct pstore_zbackend * step ;
1033
+
1034
+ if (!compress )
1035
+ return ;
1036
+
1037
+ for (step = zbackends ; step -> name ; step ++ ) {
1038
+ if (!strcmp (compress , step -> name )) {
1039
+ zbackend = step ;
1040
+ pr_info ("using %s compression\n" , zbackend -> name );
1041
+ return ;
1042
+ }
1043
+ }
1044
+ }
1045
+
1046
+ module_param (compress , charp , 0444 );
1047
+ MODULE_PARM_DESC (compress , "Pstore compression to use" );
1048
+
1025
1049
module_param (backend , charp , 0444 );
1026
1050
MODULE_PARM_DESC (backend , "Pstore backend to use" );
0 commit comments