@@ -663,8 +663,9 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
663
663
return NULL ;
664
664
}
665
665
666
- static __init struct zswap_pool * __zswap_pool_create_fallback (void )
666
+ static bool zswap_try_pool_create (void )
667
667
{
668
+ struct zswap_pool * pool ;
668
669
bool has_comp , has_zpool ;
669
670
670
671
has_comp = crypto_has_acomp (zswap_compressor , 0 , 0 );
@@ -700,9 +701,21 @@ static __init struct zswap_pool *__zswap_pool_create_fallback(void)
700
701
}
701
702
702
703
if (!has_comp || !has_zpool )
703
- return NULL ;
704
+ return false;
705
+
706
+ pool = zswap_pool_create (zswap_zpool_type , zswap_compressor );
704
707
705
- return zswap_pool_create (zswap_zpool_type , zswap_compressor );
708
+ if (pool ) {
709
+ pr_info ("loaded using pool %s/%s\n" , pool -> tfm_name ,
710
+ zpool_get_type (pool -> zpool ));
711
+ list_add (& pool -> list , & zswap_pools );
712
+ zswap_has_pool = true;
713
+ } else {
714
+ pr_err ("pool creation failed\n" );
715
+ zswap_enabled = false;
716
+ }
717
+
718
+ return zswap_enabled ;
706
719
}
707
720
708
721
static void zswap_pool_destroy (struct zswap_pool * pool )
@@ -875,16 +888,19 @@ static int zswap_zpool_param_set(const char *val,
875
888
static int zswap_enabled_param_set (const char * val ,
876
889
const struct kernel_param * kp )
877
890
{
891
+ int ret ;
892
+
878
893
if (zswap_init_failed ) {
879
894
pr_err ("can't enable, initialization failed\n" );
880
895
return - ENODEV ;
881
896
}
882
- if (!zswap_has_pool && zswap_init_started ) {
883
- pr_err ("can't enable, no pool configured\n" );
884
- return - ENODEV ;
885
- }
886
897
887
- return param_set_bool (val , kp );
898
+ ret = param_set_bool (val , kp );
899
+ if (!ret && zswap_enabled && zswap_init_started && !zswap_has_pool )
900
+ if (!zswap_try_pool_create ())
901
+ ret = - ENODEV ;
902
+
903
+ return ret ;
888
904
}
889
905
890
906
/*********************************
@@ -1476,7 +1492,6 @@ static int __init zswap_debugfs_init(void)
1476
1492
**********************************/
1477
1493
static int __init init_zswap (void )
1478
1494
{
1479
- struct zswap_pool * pool ;
1480
1495
int ret ;
1481
1496
1482
1497
zswap_init_started = true;
@@ -1500,33 +1515,23 @@ static int __init init_zswap(void)
1500
1515
if (ret )
1501
1516
goto hp_fail ;
1502
1517
1503
- pool = __zswap_pool_create_fallback ();
1504
- if (pool ) {
1505
- pr_info ("loaded using pool %s/%s\n" , pool -> tfm_name ,
1506
- zpool_get_type (pool -> zpool ));
1507
- list_add (& pool -> list , & zswap_pools );
1508
- zswap_has_pool = true;
1509
- } else {
1510
- pr_err ("pool creation failed\n" );
1511
- zswap_enabled = false;
1512
- }
1513
-
1514
1518
shrink_wq = create_workqueue ("zswap-shrink" );
1515
1519
if (!shrink_wq )
1516
- goto fallback_fail ;
1520
+ goto hp_fail ;
1517
1521
1518
1522
ret = frontswap_register_ops (& zswap_frontswap_ops );
1519
1523
if (ret )
1520
1524
goto destroy_wq ;
1521
1525
if (zswap_debugfs_init ())
1522
1526
pr_warn ("debugfs initialization failed\n" );
1527
+
1528
+ if (zswap_enabled )
1529
+ zswap_try_pool_create ();
1530
+
1523
1531
return 0 ;
1524
1532
1525
1533
destroy_wq :
1526
1534
destroy_workqueue (shrink_wq );
1527
- fallback_fail :
1528
- if (pool )
1529
- zswap_pool_destroy (pool );
1530
1535
hp_fail :
1531
1536
cpuhp_remove_state (CPUHP_MM_ZSWP_MEM_PREPARE );
1532
1537
dstmem_fail :
0 commit comments