@@ -212,6 +212,7 @@ static bool zswap_has_pool;
212
212
static int zswap_writeback_entry (struct zpool * pool , unsigned long handle );
213
213
static int zswap_pool_get (struct zswap_pool * pool );
214
214
static void zswap_pool_put (struct zswap_pool * pool );
215
+ static int init_zswap (void );
215
216
216
217
static const struct zpool_ops zswap_zpool_ops = {
217
218
.evict = zswap_writeback_entry
@@ -243,13 +244,13 @@ static void zswap_update_total_size(void)
243
244
**********************************/
244
245
static struct kmem_cache * zswap_entry_cache ;
245
246
246
- static int __init zswap_entry_cache_create (void )
247
+ static int zswap_entry_cache_create (void )
247
248
{
248
249
zswap_entry_cache = KMEM_CACHE (zswap_entry , 0 );
249
250
return zswap_entry_cache == NULL ;
250
251
}
251
252
252
- static void __init zswap_entry_cache_destroy (void )
253
+ static void zswap_entry_cache_destroy (void )
253
254
{
254
255
kmem_cache_destroy (zswap_entry_cache );
255
256
}
@@ -573,7 +574,7 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
573
574
return NULL ;
574
575
}
575
576
576
- static __init struct zswap_pool * __zswap_pool_create_fallback (void )
577
+ static struct zswap_pool * __zswap_pool_create_fallback (void )
577
578
{
578
579
bool has_comp , has_zpool ;
579
580
@@ -770,28 +771,30 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp,
770
771
static int zswap_compressor_param_set (const char * val ,
771
772
const struct kernel_param * kp )
772
773
{
773
- return __zswap_param_set (val , kp , zswap_zpool_type , NULL );
774
+ return __zswap_param_set (val , kp , NULL , zswap_compressor );
774
775
}
775
776
776
777
static int zswap_zpool_param_set (const char * val ,
777
778
const struct kernel_param * kp )
778
779
{
779
- return __zswap_param_set (val , kp , NULL , zswap_compressor );
780
+ return __zswap_param_set (val , kp , zswap_zpool_type , NULL );
780
781
}
781
782
782
783
static int zswap_enabled_param_set (const char * val ,
783
784
const struct kernel_param * kp )
784
785
{
786
+ int ret ;
787
+
785
788
if (zswap_init_failed ) {
786
789
pr_err ("can't enable, initialization failed\n" );
787
790
return - ENODEV ;
788
791
}
789
- if (!zswap_has_pool && zswap_init_started ) {
790
- pr_err ("can't enable, no pool configured\n" );
791
- return - ENODEV ;
792
- }
793
792
794
- return param_set_bool (val , kp );
793
+ ret = param_set_bool (val , kp );
794
+ if (!ret && zswap_enabled && zswap_init_started && !zswap_has_pool )
795
+ ret = init_zswap ();
796
+
797
+ return ret ;
795
798
}
796
799
797
800
/*********************************
@@ -1256,7 +1259,7 @@ static struct frontswap_ops zswap_frontswap_ops = {
1256
1259
1257
1260
static struct dentry * zswap_debugfs_root ;
1258
1261
1259
- static int __init zswap_debugfs_init (void )
1262
+ static int zswap_debugfs_init (void )
1260
1263
{
1261
1264
if (!debugfs_initialized ())
1262
1265
return - ENODEV ;
@@ -1294,7 +1297,7 @@ static void __exit zswap_debugfs_exit(void)
1294
1297
debugfs_remove_recursive (zswap_debugfs_root );
1295
1298
}
1296
1299
#else
1297
- static int __init zswap_debugfs_init (void )
1300
+ static int zswap_debugfs_init (void )
1298
1301
{
1299
1302
return 0 ;
1300
1303
}
@@ -1305,13 +1308,16 @@ static void __exit zswap_debugfs_exit(void) { }
1305
1308
/*********************************
1306
1309
* module init and exit
1307
1310
**********************************/
1308
- static int __init init_zswap (void )
1311
+ static int init_zswap (void )
1309
1312
{
1310
1313
struct zswap_pool * pool ;
1311
1314
int ret ;
1312
1315
1313
1316
zswap_init_started = true;
1314
1317
1318
+ if (!zswap_enabled )
1319
+ return 0 ;
1320
+
1315
1321
if (zswap_entry_cache_create ()) {
1316
1322
pr_err ("entry cache creation failed\n" );
1317
1323
goto cache_fail ;
@@ -1340,6 +1346,7 @@ static int __init init_zswap(void)
1340
1346
} else {
1341
1347
pr_err ("pool creation failed\n" );
1342
1348
zswap_enabled = false;
1349
+ zswap_init_failed = true;
1343
1350
}
1344
1351
1345
1352
frontswap_register_ops (& zswap_frontswap_ops );
0 commit comments