summaryrefslogtreecommitdiff
path: root/0051-refactor-remote-ro-code.patch
blob: c9269cb837909d1b4b4978b25592664157fe6237 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
From d4816441dc5ad67cc8cbab565e5ddc0eaf838611 Mon Sep 17 00:00:00 2001
From: "Neil.wrz" <wangrunze13@huawei.com>
Date: Mon, 6 Mar 2023 17:43:17 -0800
Subject: [PATCH 51/53] refactor remote ro code

Signed-off-by: Neil.wrz <wangrunze13@huawei.com>
---
 CI/make-and-install.sh                        |   2 +-
 .../oci/storage/image_store/CMakeLists.txt    |   3 -
 .../oci/storage/image_store/image_store.c     |  37 +--
 .../oci/storage/image_store/image_store.h     |  13 +-
 .../oci/storage/layer_store/CMakeLists.txt    |   3 -
 .../graphdriver/overlay2/CMakeLists.txt       |   3 -
 .../graphdriver/overlay2/driver_overlay2.h    |   8 -
 .../oci/storage/layer_store/layer_store.c     | 230 +++++++++---------
 .../oci/storage/layer_store/layer_store.h     |   9 +-
 .../image_remote_impl.c                       |  61 +++--
 .../layer_remote_impl.c                       |  71 +++---
 .../overlay_remote_impl.c                     | 103 +++++---
 .../remote_layer_support/remote_support.c     | 141 ++++++-----
 .../remote_layer_support/remote_support.h     |  62 +++--
 .../ro_symlink_maintain.c                     | 124 +---------
 .../ro_symlink_maintain.h                     |  19 +-
 .../modules/image/oci/storage/storage.c       |   4 +-
 src/utils/cutils/map/rb_tree.c                |   1 +
 test/image/oci/registry/CMakeLists.txt        |   2 +
 test/image/oci/storage/CMakeLists.txt         |   3 +
 test/image/oci/storage/images/CMakeLists.txt  |   2 +
 test/image/oci/storage/layers/CMakeLists.txt  |   4 +
 .../remote_layer_support/CMakeLists.txt       |  44 ++++
 .../remote_layer_support/remote_layer_ut.cc   |  93 +++++++
 test/image/oci/storage/rootfs/CMakeLists.txt  |   2 +
 test/mocks/remote_store_mock.cc               |  68 ++++++
 test/mocks/remote_store_mock.h                |  40 +++
 27 files changed, 683 insertions(+), 469 deletions(-)
 rename src/daemon/modules/image/oci/storage/{image_store => remote_layer_support}/image_remote_impl.c (71%)
 rename src/daemon/modules/image/oci/storage/{layer_store => remote_layer_support}/layer_remote_impl.c (76%)
 rename src/daemon/modules/image/oci/storage/{layer_store/graphdriver/overlay2 => remote_layer_support}/overlay_remote_impl.c (72%)
 create mode 100644 test/image/oci/storage/remote_layer_support/CMakeLists.txt
 create mode 100644 test/image/oci/storage/remote_layer_support/remote_layer_ut.cc
 create mode 100644 test/mocks/remote_store_mock.cc
 create mode 100644 test/mocks/remote_store_mock.h

diff --git a/CI/make-and-install.sh b/CI/make-and-install.sh
index faeaf005..fa9c2250 100755
--- a/CI/make-and-install.sh
+++ b/CI/make-and-install.sh
@@ -103,7 +103,7 @@ rm -rf build
 mkdir build
 cd build
 if [[ ${enable_gcov} -ne 0 ]]; then
-  cmake -DLIB_INSTALL_DIR=${builddir}/lib -DCMAKE_INSTALL_PREFIX=${builddir} -DCMAKE_INSTALL_SYSCONFDIR=${builddir}/etc -DCMAKE_BUILD_TYPE=Debug -DGCOV=ON -DENABLE_EMBEDDED=ON -DENABLE_COVERAGE=ON -DENABLE_UT=ON -DENABLE_METRICS=ON ..
+  cmake -DLIB_INSTALL_DIR=${builddir}/lib -DCMAKE_INSTALL_PREFIX=${builddir} -DCMAKE_INSTALL_SYSCONFDIR=${builddir}/etc -DCMAKE_BUILD_TYPE=Debug -DGCOV=ON -DENABLE_EMBEDDED=ON -DENABLE_COVERAGE=ON -DENABLE_UT=ON -DENABLE_METRICS=ON -DENABLE_REMOTE_LAYER_STORE=ON ..
 else
   cmake -DLIB_INSTALL_DIR=${builddir}/lib -DCMAKE_INSTALL_PREFIX=${builddir} -DCMAKE_INSTALL_SYSCONFDIR=${builddir}/etc -DENABLE_EMBEDDED=ON -DENABLE_METRICS=ON -DENABLE_REMOTE_LAYER_STORE=ON ..
 fi
diff --git a/src/daemon/modules/image/oci/storage/image_store/CMakeLists.txt b/src/daemon/modules/image/oci/storage/image_store/CMakeLists.txt
index 7d4fb77c..ecf21caa 100644
--- a/src/daemon/modules/image/oci/storage/image_store/CMakeLists.txt
+++ b/src/daemon/modules/image/oci/storage/image_store/CMakeLists.txt
@@ -1,8 +1,5 @@
 # get current directory sources files
 aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_image_store_srcs)
-IF (NOT ENABLE_REMOTE_LAYER_STORE)
-list(REMOVE_ITEM local_image_store_srcs "${CMAKE_CURRENT_SOURCE_DIR}/image_remote_impl.c")
-ENDIF()
 
 set(IMAGE_STORE_SRCS
     ${local_image_store_srcs}
diff --git a/src/daemon/modules/image/oci/storage/image_store/image_store.c b/src/daemon/modules/image/oci/storage/image_store/image_store.c
index 84187ded..9a32b247 100644
--- a/src/daemon/modules/image/oci/storage/image_store/image_store.c
+++ b/src/daemon/modules/image/oci/storage/image_store/image_store.c
@@ -132,7 +132,7 @@ static void free_image_store(image_store_t *store)
     (void)map_free(store->bydigest);
     store->bydigest = NULL;
 
-    linked_list_for_each_safe(item, &(store->images_list), next) {
+    linked_list_for_each_safe (item, &(store->images_list), next) {
         linked_list_del(item);
         image_ref_dec((image_t *)item->elem);
         free(item);
@@ -164,7 +164,7 @@ static void image_store_digest_field_kvfree(void *key, void *value)
 
     free(key);
     if (val != NULL) {
-        linked_list_for_each_safe(item, &(val->images_list), next) {
+        linked_list_for_each_safe (item, &(val->images_list), next) {
             linked_list_del(item);
             free(item);
             item = NULL;
@@ -500,7 +500,7 @@ static void digest_image_slice_without_value(digest_image_t *digest_filter_image
         return;
     }
 
-    linked_list_for_each_safe(item, &(digest_filter_images->images_list), next) {
+    linked_list_for_each_safe (item, &(digest_filter_images->images_list), next) {
         tmp = (image_t *)item->elem;
         if (strcmp(tmp->simage->id, img->simage->id) == 0) {
             linked_list_del(item);
@@ -581,7 +581,7 @@ static int remove_image_from_memory(const char *id)
         goto out;
     }
 
-    linked_list_for_each_safe(item, &(g_image_store->images_list), next) {
+    linked_list_for_each_safe (item, &(g_image_store->images_list), next) {
         image_t *tmp = (image_t *)item->elem;
         if (strcmp(tmp->simage->id, id) != 0) {
             continue;
@@ -680,7 +680,7 @@ static void free_digest_image(digest_image_t *ptr)
         return;
     }
 
-    linked_list_for_each_safe(item, &(ptr->images_list), next) {
+    linked_list_for_each_safe (item, &(ptr->images_list), next) {
         linked_list_del(item);
         free(item);
         item = NULL;
@@ -2678,7 +2678,7 @@ int image_store_get_all_images(imagetool_images_list *images_list)
         goto unlock;
     }
 
-    linked_list_for_each_safe(item, &(g_image_store->images_list), next) {
+    linked_list_for_each_safe (item, &(g_image_store->images_list), next) {
         imagetool_image_summary *imginfo = NULL;
         image_t *img = (image_t *)item->elem;
         imginfo = get_image_summary(img);
@@ -3099,7 +3099,7 @@ out:
     return ret;
 }
 
-int validate_manifest_schema_version_1(const char *path, bool *valid)
+int image_store_validate_manifest_schema_version_1(const char *path, bool *valid)
 {
     int ret = 0;
     int nret;
@@ -3506,7 +3506,7 @@ static int get_images_from_json()
             continue;
         }
 
-        if (validate_manifest_schema_version_1(image_path, &valid_v1_image) != 0) {
+        if (image_store_validate_manifest_schema_version_1(image_path, &valid_v1_image) != 0) {
             ERROR("Failed to validate manifest schema version 1 format");
             continue;
         }
@@ -3543,7 +3543,7 @@ static void image_store_check_all_images()
         return;
     }
 
-    linked_list_for_each_safe(item, &(g_image_store->images_list), next) {
+    linked_list_for_each_safe (item, &(g_image_store->images_list), next) {
         image_t *img = (image_t *)item->elem;
         if (img->spec == NULL) {
             ERROR("Failed to check spec info of image: %s, try to delete", img->simage->id);
@@ -3657,18 +3657,23 @@ out:
 }
 
 #ifdef ENABLE_REMOTE_LAYER_STORE
-int append_image_by_directory_with_lock(const char *id)
+int remote_append_image_by_directory_with_lock(const char *id)
 {
     int ret = 0;
     int nret = 0;
     char image_path[PATH_MAX] = { 0x00 };
 
+    if (id == NULL) {
+        ERROR("can't add NULL remote image");
+        return -1;
+    }
+
     if (!image_store_lock(EXCLUSIVE)) {
         ERROR("Failed to lock remote image store when handle: %s", id);
         return -1;
     }
 
-    if (map_search(g_image_store->byid, (void *)id) != NULL ) {
+    if (map_search(g_image_store->byid, (void *)id) != NULL) {
         DEBUG("remote image already exist, not added: %s", id);
         goto out;
     }
@@ -3687,10 +3692,15 @@ out:
     return ret;
 }
 
-int remove_image_from_memory_with_lock(const char *id)
+int remote_remove_image_from_memory_with_lock(const char *id)
 {
     int ret = 0;
 
+    if (id == NULL) {
+        ERROR("can't remove NULL remote image");
+        return -1;
+    }
+
     if (!image_store_lock(EXCLUSIVE)) {
         ERROR("Failed to lock remote image store when handle: %s", id);
         return -1;
@@ -3709,9 +3719,8 @@ out:
     return ret;
 }
 
-char *get_top_layer_from_json(const char *img_id)
+char *remote_image_get_top_layer_from_json(const char *img_id)
 {
-
     char *ret = NULL;
     int nret = 0;
     char image_path[PATH_MAX] = { 0x00 };
diff --git a/src/daemon/modules/image/oci/storage/image_store/image_store.h b/src/daemon/modules/image/oci/storage/image_store/image_store.h
index c3cb50e3..5164cc73 100644
--- a/src/daemon/modules/image/oci/storage/image_store/image_store.h
+++ b/src/daemon/modules/image/oci/storage/image_store/image_store.h
@@ -28,9 +28,6 @@
 #include "isula_libutils/imagetool_image.h"
 #include "isula_libutils/imagetool_images_list.h"
 #include "isula_libutils/imagetool_image_summary.h"
-#ifdef ENABLE_REMOTE_LAYER_STORE
-#include "remote_support.h"
-#endif
 
 struct storage_module_init_options;
 
@@ -112,11 +109,11 @@ void image_store_free();
 imagetool_image_summary *image_store_get_image_summary(const char *id);
 
 #ifdef ENABLE_REMOTE_LAYER_STORE
-remote_support *image_store_impl_remote_support();
-int validate_manifest_schema_version_1(const char *path, bool *valid);
-int append_image_by_directory_with_lock(const char *image_dir);
-int remove_image_from_memory_with_lock(const char *id);
-char *get_top_layer_from_json(const char *img_id); /* return top layer id */
+int image_store_validate_manifest_schema_version_1(const char *path, bool *valid);
+int remote_append_image_by_directory_with_lock(const char *image_dir);
+int remote_remove_image_from_memory_with_lock(const char *id);
+// return top layer id
+char *remote_image_get_top_layer_from_json(const char *img_id);
 #endif
 
 #ifdef __cplusplus
diff --git a/src/daemon/modules/image/oci/storage/layer_store/CMakeLists.txt b/src/daemon/modules/image/oci/storage/layer_store/CMakeLists.txt
index e04b4ad7..c218a7c0 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/CMakeLists.txt
+++ b/src/daemon/modules/image/oci/storage/layer_store/CMakeLists.txt
@@ -1,8 +1,5 @@
 # get current directory sources files
 aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_layer_store_srcs)
-IF (NOT ENABLE_REMOTE_LAYER_STORE)
-list(REMOVE_ITEM local_layer_store_srcs "${CMAKE_CURRENT_SOURCE_DIR}/layer_remote_impl.c")
-ENDIF()
 add_subdirectory(graphdriver)
 
 set(LAYER_STORE_SRCS
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/CMakeLists.txt b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/CMakeLists.txt
index dd4e82aa..ceed16b7 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/CMakeLists.txt
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/CMakeLists.txt
@@ -1,8 +1,5 @@
 # get current directory sources files
 aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_overlay2_srcs)
-IF (NOT ENABLE_REMOTE_LAYER_STORE)
-list(REMOVE_ITEM local_overlay2_srcs "${CMAKE_CURRENT_SOURCE_DIR}/overlay_remote_impl.c")
-ENDIF()
 
 set(OVERLAY2_SRCS
     ${local_overlay2_srcs}
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
index 5c1d93fb..e14271b1 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
@@ -22,9 +22,6 @@
 #include <stdint.h>
 
 #include "driver.h"
-#ifdef ENABLE_REMOTE_LAYER_STORE
-#include "remote_support.h"
-#endif
 
 struct driver_create_opts;
 struct driver_mount_opts;
@@ -71,11 +68,6 @@ int overlay2_repair_lowers(const char *id, const char *parent, const struct grap
 
 int overlay2_get_layer_fs_info(const char *id, const struct graphdriver *driver, imagetool_fs_info *fs_info);
 
-#ifdef ENABLE_REMOTE_LAYER_STORE
-remote_support *overlay_driver_impl_remote_support(void);
-bool overlay_remote_layer_valid(const char *layer_id);
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
index 4edd0cad..79339757 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
@@ -1789,119 +1789,6 @@ out:
     return ret;
 }
 
-static layer_t *load_one_layer_from_json(const char *id)
-{
-    int nret = 0;
-    char *mount_point_path = NULL;
-    char tmpdir[PATH_MAX] = { 0 };
-    char *rpath = NULL;
-    layer_t *l = NULL;
-    bool layer_valid = false;
-
-    nret = snprintf(tmpdir, PATH_MAX, "%s/%s", g_root_dir, id);
-    if (nret < 0 || nret >= PATH_MAX) {
-        ERROR("Sprintf: %s failed", id);
-        goto free_out;
-    }
-
-    mount_point_path = mountpoint_json_path(id);
-    if (mount_point_path == NULL) {
-        ERROR("Out of Memory");
-        goto free_out;
-    }
-
-    rpath = layer_json_path(id);
-    if (rpath == NULL) {
-        ERROR("%s is invalid layer", id);
-        goto free_out;
-    }
-
-    l = load_layer(rpath, mount_point_path);
-    if (l == NULL) {
-        ERROR("load layer: %s failed, remove it", id);
-        goto free_out;
-    }
-
-    if (do_validate_image_layer(tmpdir, l) != 0) {
-        ERROR("%s is invalid image layer", id);
-        goto free_out;
-    }
-
-    if (do_validate_rootfs_layer(l) != 0) {
-        ERROR("%s is invalid rootfs layer", id);
-        goto free_out;
-    }
-
-    layer_valid = true;
-
-free_out:
-    free(rpath);
-    free(mount_point_path);
-    if (!layer_valid) {
-        free_layer_t(l);
-        l = NULL;
-    }
-    // always return true;
-    // if load layer failed, just remove it
-    return l;
-}
-
-int load_one_layer(const char *id)
-{
-    int ret = 0;
-    layer_t *tl = NULL;
-    int i = 0;
-
-    if (!layer_store_lock(true)) {
-        return -1;
-    }
-
-    if (map_search(g_metadata.by_id, (void *)id) != NULL) {
-        DEBUG("remote layer already exist, not added: %s", id);
-        goto unlock_out;
-    }
-
-    tl = load_one_layer_from_json(id);
-    if (tl == NULL) {
-        ret = -1;
-        goto unlock_out;
-    }
-
-    if (!map_insert(g_metadata.by_id, (void *)tl->slayer->id, (void *)tl)) {
-        ERROR("Insert id: %s for layer failed", tl->slayer->id);
-        ret = -1;
-        goto unlock_out;
-    }
-
-    for (; i < tl->slayer->names_len; i++) {
-        // this should be done by master isulad
-        // if (remove_name(tl->slayer->names[i])) {
-        //     should_save = true;
-        // }
-        if (!map_insert(g_metadata.by_name, (void *)tl->slayer->names[i], (void *)tl)) {
-            ret = -1;
-            ERROR("Insert name: %s for layer failed", tl->slayer->names[i]);
-            goto unlock_out;
-        }
-    }
-    ret = insert_digest_into_map(g_metadata.by_compress_digest, tl->slayer->compressed_diff_digest, tl->slayer->id);
-    if (ret != 0) {
-        ERROR("update layer: %s compress failed", tl->slayer->id);
-        goto unlock_out;
-    }
-
-    ret = insert_digest_into_map(g_metadata.by_uncompress_digest, tl->slayer->diff_digest, tl->slayer->id);
-    if (ret != 0) {
-        ERROR("update layer: %s uncompress failed", tl->slayer->id);
-        goto unlock_out;
-    }
-
-    ret = 0;
-unlock_out:
-    layer_store_unlock();
-    return ret;
-}
-
 static bool load_layer_json_cb(const char *path_name, const struct dirent *sub_dir, void *context)
 {
 #define LAYER_NAME_LEN 64
@@ -2483,7 +2370,7 @@ container_inspect_graph_driver *layer_store_get_metadata_by_layer_id(const char
 }
 
 #ifdef ENABLE_REMOTE_LAYER_STORE
-int remove_memory_stores_with_lock(const char *id)
+int remote_layer_remove_memory_stores_with_lock(const char *id)
 {
     int ret = 0;
 
@@ -2496,6 +2383,11 @@ int remove_memory_stores_with_lock(const char *id)
         goto unlock_out;
     }
 
+    if (map_search(g_metadata.by_id, (void *)id) == NULL) {
+        DEBUG("remote layer already removed, don't delete: %s", id);
+        goto unlock_out;
+    }
+
     ret = remove_memory_stores(id);
 
 unlock_out:
@@ -2503,4 +2395,114 @@ unlock_out:
 
     return ret;
 }
+
+static layer_t *load_one_layer_from_json(const char *id)
+{
+    int nret = 0;
+    char *mount_point_path = NULL;
+    char tmpdir[PATH_MAX] = { 0 };
+    char *rpath = NULL;
+    layer_t *l = NULL;
+    bool layer_valid = false;
+
+    nret = snprintf(tmpdir, PATH_MAX, "%s/%s", g_root_dir, id);
+    if (nret < 0 || nret >= PATH_MAX) {
+        ERROR("Sprintf: %s failed", id);
+        goto free_out;
+    }
+
+    mount_point_path = mountpoint_json_path(id);
+    if (mount_point_path == NULL) {
+        ERROR("Out of Memory");
+        goto free_out;
+    }
+
+    rpath = layer_json_path(id);
+    if (rpath == NULL) {
+        ERROR("%s is invalid layer", id);
+        goto free_out;
+    }
+
+    l = load_layer(rpath, mount_point_path);
+    if (l == NULL) {
+        ERROR("load layer: %s failed, remove it", id);
+        goto free_out;
+    }
+
+    if (do_validate_image_layer(tmpdir, l) != 0) {
+        ERROR("%s is invalid image layer", id);
+        goto free_out;
+    }
+
+    if (do_validate_rootfs_layer(l) != 0) {
+        ERROR("%s is invalid rootfs layer", id);
+        goto free_out;
+    }
+
+    layer_valid = true;
+
+free_out:
+    free(rpath);
+    free(mount_point_path);
+    if (!layer_valid) {
+        free_layer_t(l);
+        l = NULL;
+    }
+    // always return true;
+    // if load layer failed, just remove it
+    return l;
+}
+
+int remote_load_one_layer(const char *id)
+{
+    int ret = 0;
+    layer_t *tl = NULL;
+    int i = 0;
+
+    if (!layer_store_lock(true)) {
+        return -1;
+    }
+
+    if (map_search(g_metadata.by_id, (void *)id) != NULL) {
+        DEBUG("remote layer already exist, not added: %s", id);
+        goto unlock_out;
+    }
+
+    tl = load_one_layer_from_json(id);
+    if (tl == NULL) {
+        ret = -1;
+        goto unlock_out;
+    }
+
+    if (!map_insert(g_metadata.by_id, (void *)tl->slayer->id, (void *)tl)) {
+        ERROR("Insert id: %s for layer failed", tl->slayer->id);
+        ret = -1;
+        goto unlock_out;
+    }
+
+    for (; i < tl->slayer->names_len; i++) {
+        // this should be done by master isulad
+        if (!map_insert(g_metadata.by_name, (void *)tl->slayer->names[i], (void *)tl)) {
+            ret = -1;
+            ERROR("Insert name: %s for layer failed", tl->slayer->names[i]);
+            goto unlock_out;
+        }
+    }
+    ret = insert_digest_into_map(g_metadata.by_compress_digest, tl->slayer->compressed_diff_digest, tl->slayer->id);
+    if (ret != 0) {
+        ERROR("update layer: %s compress failed", tl->slayer->id);
+        goto unlock_out;
+    }
+
+    ret = insert_digest_into_map(g_metadata.by_uncompress_digest, tl->slayer->diff_digest, tl->slayer->id);
+    if (ret != 0) {
+        ERROR("update layer: %s uncompress failed", tl->slayer->id);
+        goto unlock_out;
+    }
+
+    ret = 0;
+unlock_out:
+    layer_store_unlock();
+    return ret;
+}
 #endif
diff --git a/src/daemon/modules/image/oci/storage/layer_store/layer_store.h b/src/daemon/modules/image/oci/storage/layer_store/layer_store.h
index 44bd297e..4677e5ee 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/layer_store.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/layer_store.h
@@ -24,9 +24,6 @@
 #include "storage.h"
 #include "io_wrapper.h"
 #include "map.h"
-#ifdef ENABLE_REMOTE_LAYER_STORE
-#include "remote_support.h"
-#endif
 
 struct io_read_wrapper;
 struct layer_list;
@@ -84,10 +81,8 @@ int layer_store_check(const char *id);
 container_inspect_graph_driver *layer_store_get_metadata_by_layer_id(const char *id);
 
 #ifdef ENABLE_REMOTE_LAYER_STORE
-remote_support *layer_store_impl_remote_support();
-bool layer_remote_layer_valid(const char *layer_id);
-int load_one_layer(const char *id);
-int remove_memory_stores_with_lock(const char *id);
+int remote_load_one_layer(const char *id);
+int remote_layer_remove_memory_stores_with_lock(const char *id);
 #endif
 
 #ifdef __cplusplus
diff --git a/src/daemon/modules/image/oci/storage/image_store/image_remote_impl.c b/src/daemon/modules/image/oci/storage/remote_layer_support/image_remote_impl.c
similarity index 71%
rename from src/daemon/modules/image/oci/storage/image_store/image_remote_impl.c
rename to src/daemon/modules/image/oci/storage/remote_layer_support/image_remote_impl.c
index 20da8116..a822ea81 100644
--- a/src/daemon/modules/image/oci/storage/image_store/image_remote_impl.c
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/image_remote_impl.c
@@ -13,27 +13,23 @@
  * Description: provide remote image store functions
  ******************************************************************************/
 #define _GNU_SOURCE
-#include "image_store.h"
+#include "remote_support.h"
 
 #include <isula_libutils/log.h>
 #include <stdio.h>
 
-#include "remote_support.h"
 #include "ro_symlink_maintain.h"
 #include "map.h"
 #include "utils_file.h"
 #include "utils.h"
 #include "layer_store.h"
+#include "image_store.h"
 #include "utils_array.h"
 
-struct remote_image_data {
-    const char *image_home;
-};
-
 static map_t *image_byid_old = NULL;
 static map_t *image_byid_new = NULL;
 
-static void *remote_support_create(const char *remote_home, const char *remote_ro)
+struct remote_image_data *remote_image_create(const char *remote_home, const char *remote_ro)
 {
     struct remote_image_data *data = util_common_calloc_s(sizeof(struct remote_image_data));
     if (data == NULL) {
@@ -46,7 +42,7 @@ static void *remote_support_create(const char *remote_home, const char *remote_r
     return data;
 }
 
-static void remote_support_destroy(void *data)
+void remote_image_destroy(struct remote_image_data *data)
 {
     if (data == NULL) {
         return;
@@ -59,7 +55,7 @@ static void remote_support_destroy(void *data)
     return;
 }
 
-static int remote_support_scan(void *data)
+static int remote_dir_scan(void *data)
 {
     int ret = 0;
     int nret;
@@ -79,7 +75,7 @@ static int remote_support_scan(void *data)
     image_dirs_num = util_array_len((const char **)image_dirs);
 
     for (i = 0; i < image_dirs_num; i++) {
-        bool valid_v1_image = false;
+        bool is_v1_image = false;
 
         if (util_reg_match(id_patten, image_dirs[i]) != 0) {
             DEBUG("Image's json is placed inside image's data directory, so skip any other file or directory: %s",
@@ -93,12 +89,14 @@ static int remote_support_scan(void *data)
             continue;
         }
 
-        if (validate_manifest_schema_version_1(image_path, &valid_v1_image) != 0) {
+        if (image_store_validate_manifest_schema_version_1(image_path, &is_v1_image) != 0) {
             ERROR("Failed to validate manifest schema version 1 format");
             continue;
         }
 
-        if (!valid_v1_image) {
+        // for refresh, we don't care v1 image, cause image should be handled by master isulad
+        // when master isulad pull images
+        if (!is_v1_image) {
             map_insert(image_byid_new, util_strdup_s(image_dirs[i]), (void *)&exist);
         }
     }
@@ -108,12 +106,13 @@ out:
     return ret;
 }
 
-static int remote_support_add(void *data)
+static int remote_image_add(void *data)
 {
     char **array_added = NULL;
     char **array_deleted = NULL;
     char *top_layer = NULL;
     map_t *tmp_map = NULL;
+    bool exist = true;
     int i = 0;
     int ret = 0;
 
@@ -121,26 +120,28 @@ static int remote_support_add(void *data)
         return -1;
     }
 
-    array_added = added_layers(image_byid_old, image_byid_new);
-    array_deleted = deleted_layers(image_byid_old, image_byid_new);
+    array_added = remote_added_layers(image_byid_old, image_byid_new);
+    array_deleted = remote_deleted_layers(image_byid_old, image_byid_new);
 
     for (i = 0; i < util_array_len((const char **)array_added); i++) {
-        top_layer = get_top_layer_from_json(array_added[i]);
-        if (top_layer != NULL && !layer_remote_layer_valid(top_layer)) {
-            ERROR("ERROR not find valid under layer, remoet image:%s not added", array_added[i]);
+        top_layer = remote_image_get_top_layer_from_json(array_added[i]);
+        if (top_layer != NULL && !remote_layer_layer_valid(top_layer)) {
+            WARN("Current not find valid under layer, remoet image:%s not added", array_added[i]);
             map_remove(image_byid_new, (void *)array_added[i]);
             continue;
         }
 
-        if (append_image_by_directory_with_lock(array_added[i]) != 0) {
+        if (remote_append_image_by_directory_with_lock(array_added[i]) != 0) {
             ERROR("Failed to load image into memrory: %s", array_added[i]);
+            map_remove(image_byid_new, (void *)array_added[i]);
             ret = -1;
         }
     }
 
     for (i = 0; i < util_array_len((const char **)array_deleted); i++) {
-        if (remove_image_from_memory_with_lock(array_deleted[i]) != 0) {
+        if (remote_remove_image_from_memory_with_lock(array_deleted[i]) != 0) {
             ERROR("Failed to remove remote memory store");
+            map_insert(image_byid_new, array_deleted[i], (void *)&exist);
             ret = -1;
         }
     }
@@ -148,7 +149,7 @@ static int remote_support_add(void *data)
     tmp_map = image_byid_old;
     image_byid_old = image_byid_new;
     image_byid_new = tmp_map;
-    empty_map(image_byid_new);
+    map_clear(image_byid_new);
 
     util_free_array(array_added);
     util_free_array(array_deleted);
@@ -157,17 +158,13 @@ static int remote_support_add(void *data)
     return ret;
 }
 
-remote_support *image_store_impl_remote_support(void)
-{
-    remote_support *rs = util_common_calloc_s(sizeof(remote_support));
-    if (rs == NULL) {
-        return NULL;
+void remote_image_refresh(struct remote_image_data *data) {
+    if (remote_dir_scan(data) != 0) {
+        ERROR("remote overlay failed to scan dir, skip refresh");
+        return;
     }
 
-    rs->create = remote_support_create;
-    rs->destroy = remote_support_destroy;
-    rs->scan_remote_dir = remote_support_scan;
-    rs->load_item = remote_support_add;
-
-    return rs;
+    if (remote_image_add(data) != 0) {
+        ERROR("refresh overlay failed");
+    }
 }
diff --git a/src/daemon/modules/image/oci/storage/layer_store/layer_remote_impl.c b/src/daemon/modules/image/oci/storage/remote_layer_support/layer_remote_impl.c
similarity index 76%
rename from src/daemon/modules/image/oci/storage/layer_store/layer_remote_impl.c
rename to src/daemon/modules/image/oci/storage/remote_layer_support/layer_remote_impl.c
index d676458c..3e3afff6 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/layer_remote_impl.c
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/layer_remote_impl.c
@@ -13,7 +13,7 @@
  * Description: remote layer store implementation
  ******************************************************************************/
 #define _GNU_SOURCE
-#include "layer_store.h"
+#include "remote_support.h"
 
 #include <pthread.h>
 #include <isula_libutils/log.h>
@@ -21,20 +21,15 @@
 
 #include "map.h"
 #include "utils.h"
-#include "remote_support.h"
 #include "ro_symlink_maintain.h"
+#include "layer_store.h"
 #include "path.h"
 #include "driver_overlay2.h"
 
-struct remote_layer_data {
-    const char *layer_home;
-    const char *layer_ro;
-};
-
 static map_t *layer_byid_old = NULL;
 static map_t *layer_byid_new = NULL;
 
-static void *remote_support_create(const char *layer_home, const char *layer_ro)
+struct remote_layer_data *remote_layer_create(const char *layer_home, const char *layer_ro)
 {
     struct remote_layer_data *data = util_common_calloc_s(sizeof(struct remote_layer_data));
     if (data == NULL) {
@@ -49,7 +44,7 @@ static void *remote_support_create(const char *layer_home, const char *layer_ro)
     return data;
 };
 
-static void remote_support_destroy(void *data)
+void remote_layer_destroy(struct remote_layer_data *data)
 {
     if (data == NULL) {
         return;
@@ -72,10 +67,9 @@ static bool layer_walk_dir_cb(const char *path_name, const struct dirent *sub_di
     return true;
 }
 
-static int remote_support_scan(void *data)
+static int remote_dir_scan(struct remote_layer_data *data)
 {
-    struct remote_layer_data *remote_data = data;
-    return util_scan_subdirs(remote_data->layer_ro, layer_walk_dir_cb, data);
+    return util_scan_subdirs(data->layer_ro, layer_walk_dir_cb, data);
 }
 
 static int remove_one_remote_layer(struct remote_layer_data *data, char *layer_id)
@@ -85,6 +79,11 @@ static int remove_one_remote_layer(struct remote_layer_data *data, char *layer_i
     int nret = 0;
     int ret = 0;
 
+    if (layer_id == NULL) {
+        ERROR("can't delete NULL remote layer");
+        return -1;
+    }
+
     nret = asprintf(&ro_symlink, "%s/%s", data->layer_home, layer_id);
     if (nret < 0 || nret > PATH_MAX) {
         SYSERROR("Create layer symbol link path failed");
@@ -98,11 +97,14 @@ static int remove_one_remote_layer(struct remote_layer_data *data, char *layer_i
         goto out;
     }
 
+    // return 0 if path already removed
     if (util_path_remove(clean_path) != 0) {
         SYSERROR("Failed to remove link path %s", clean_path);
+        ret = -1;
+        goto out;
     }
 
-    if (remove_memory_stores_with_lock(layer_id) != 0) {
+    if (remote_layer_remove_memory_stores_with_lock(layer_id) != 0) {
         ERROR("Failed to remove remote layer store memory");
         ret = -1;
     }
@@ -110,7 +112,6 @@ static int remove_one_remote_layer(struct remote_layer_data *data, char *layer_i
 out:
     free(ro_symlink);
     return ret;
-
 }
 
 static int add_one_remote_layer(struct remote_layer_data *data, char *layer_id)
@@ -119,6 +120,11 @@ static int add_one_remote_layer(struct remote_layer_data *data, char *layer_id)
     char *layer_dir = NULL;
     int ret = 0;
 
+    if (layer_id == NULL) {
+        ERROR("can't add NULL remote layer");
+        return -1;
+    }
+
     ro_symlink = util_path_join(data->layer_home, layer_id);
     layer_dir = util_path_join(data->layer_ro, layer_id);
 
@@ -140,7 +146,7 @@ static int add_one_remote_layer(struct remote_layer_data *data, char *layer_id)
         goto free_out;
     }
     // insert layer into memory
-    if (load_one_layer(layer_id) != 0) {
+    if (remote_load_one_layer(layer_id) != 0) {
         ERROR("Failed to load new layer: %s into memory", layer_id);
         ret = -1;
     }
@@ -152,30 +158,32 @@ free_out:
     return ret;
 }
 
-static int remote_support_add(void *data)
+static int remote_layer_add(struct remote_layer_data *data)
 {
     int ret = 0;
     char **array_added = NULL;
     char **array_deleted = NULL;
     map_t *tmp_map = NULL;
+    bool exist = true;
     int i = 0;
 
     if (data == NULL) {
         return -1;
     }
 
-    array_added = added_layers(layer_byid_old, layer_byid_new);
-    array_deleted = deleted_layers(layer_byid_old, layer_byid_new);
+    array_added = remote_added_layers(layer_byid_old, layer_byid_new);
+    array_deleted = remote_deleted_layers(layer_byid_old, layer_byid_new);
 
     for (i = 0; i < util_array_len((const char **)array_added); i++) {
-        if (!overlay_remote_layer_valid(array_added[i]) != 0) {
+        if (!remote_overlay_layer_valid(array_added[i]) != 0) {
+            WARN("remote overlay layer current not valid: %s", array_added[i]);
             map_remove(layer_byid_new, (void *)array_added[i]);
-            ERROR("remote overlay layer current not valid: %s", array_added[i]);
             continue;
         }
 
         if (add_one_remote_layer(data, array_added[i]) != 0) {
             ERROR("Failed to add remote layer: %s", array_added[i]);
+            map_remove(layer_byid_new, (void *)array_added[i]);
             ret = -1;
         }
     }
@@ -183,6 +191,7 @@ static int remote_support_add(void *data)
     for (i = 0; i < util_array_len((const char **)array_deleted); i++) {
         if (remove_one_remote_layer(data, array_deleted[i]) != 0) {
             ERROR("Failed to delete remote overlay layer: %s", array_deleted[i]);
+            map_insert(layer_byid_new, array_deleted[i], (void *)&exist);
             ret = -1;
         }
     }
@@ -190,7 +199,7 @@ static int remote_support_add(void *data)
     tmp_map = layer_byid_old;
     layer_byid_old = layer_byid_new;
     layer_byid_new = tmp_map;
-    empty_map(layer_byid_new);
+    map_clear(layer_byid_new);
 
     util_free_array(array_added);
     util_free_array(array_deleted);
@@ -198,22 +207,20 @@ static int remote_support_add(void *data)
     return ret;
 }
 
-remote_support *layer_store_impl_remote_support()
+void remote_layer_refresh(struct remote_layer_data *data)
 {
-    remote_support *rs = util_common_calloc_s(sizeof(remote_support));
-    if (rs == NULL) {
-        return NULL;
+    if (remote_dir_scan(data) != 0) {
+        ERROR("remote layer failed to scan dir, skip refresh");
+        return;
     }
 
-    rs->create = remote_support_create;
-    rs->destroy = remote_support_destroy;
-    rs->scan_remote_dir = remote_support_scan;
-    rs->load_item = remote_support_add;
-
-    return rs;
+    if (remote_layer_add(data) != 0) {
+        ERROR("refresh overlay failed");
+    }
 }
 
-bool layer_remote_layer_valid(const char *layer_id)
+
+bool remote_layer_layer_valid(const char *layer_id)
 {
     return map_search(layer_byid_old, (void *)layer_id) != NULL;
 }
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/overlay_remote_impl.c b/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c
similarity index 72%
rename from src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/overlay_remote_impl.c
rename to src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c
index a674a00f..de2e583c 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/overlay_remote_impl.c
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c
@@ -13,13 +13,13 @@
  * Description: provide remote implementation for driver overlay
  ******************************************************************************/
 #define _GNU_SOURCE
-#include "driver_overlay2.h"
+#include "remote_support.h"
 
 #include <stdio.h>
 
 #include "map.h"
-#include "remote_support.h"
 #include "ro_symlink_maintain.h"
+#include "driver_overlay2.h"
 #include "isula_libutils/log.h"
 #include "utils.h"
 #include "utils_array.h"
@@ -29,15 +29,13 @@
 #define OVERLAY_LINK_DIR "l"
 #define OVERLAY_LAYER_LINK "link"
 
-struct remote_overlay_data {
-    const char *overlay_home;
-    const char *overlay_ro;
-};
-
+// key: id, value: short id in 'l' dir
+// store short id to delete symbol link in 'l' dir
 static map_t *overlay_byid_old = NULL;
 static map_t *overlay_byid_new = NULL;
+static map_t *overlay_id_link = NULL;
 
-static void *remote_support_create(const char *remote_home, const char *remote_ro)
+struct remote_overlay_data *remote_overlay_create(const char *remote_home, const char *remote_ro)
 {
     struct remote_overlay_data *data = util_common_calloc_s(sizeof(struct remote_overlay_data));
     if (data == NULL) {
@@ -48,11 +46,12 @@ static void *remote_support_create(const char *remote_home, const char *remote_r
     data->overlay_ro = remote_ro;
     overlay_byid_old = map_new(MAP_STR_BOOL, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
     overlay_byid_new = map_new(MAP_STR_BOOL, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
+    overlay_id_link = map_new(MAP_STR_STR, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
 
     return data;
 }
 
-static void remote_support_destroy(void *data)
+void remote_overlay_destroy(struct remote_overlay_data *data)
 {
     if (data == NULL) {
         return;
@@ -60,6 +59,7 @@ static void remote_support_destroy(void *data)
 
     map_free(overlay_byid_old);
     map_free(overlay_byid_new);
+    map_free(overlay_id_link);
     free(data);
 }
 
@@ -74,10 +74,9 @@ static bool overlay_walk_dir_cb(const char *path_name, const struct dirent *sub_
     return true;
 }
 
-static int remote_support_scan(void *data)
+static int remote_dir_scan(struct remote_overlay_data *data)
 {
-    struct remote_overlay_data *remote_data = data;
-    return util_scan_subdirs(remote_data->overlay_ro, overlay_walk_dir_cb, data);
+    return util_scan_subdirs(data->overlay_ro, overlay_walk_dir_cb, data);
 }
 
 static int do_diff_symlink(const char *id, char *link_id, const char *driver_home)
@@ -128,10 +127,17 @@ out:
 static int remove_one_remote_overlay_layer(struct remote_overlay_data *data, const char *overlay_id)
 {
     char *ro_symlink = NULL;
+    char *link_path = NULL;
+    char *link_id = NULL;
     char clean_path[PATH_MAX] = { 0 };
     int nret = 0;
     int ret = 0;
 
+    if (overlay_id == NULL) {
+        ERROR("can't remove NULL remote layer");
+        return -1;
+    }
+
     nret = asprintf(&ro_symlink, "%s/%s", data->overlay_home, overlay_id);
     if (nret < 0 || nret > PATH_MAX) {
         SYSERROR("Create layer symbol link path failed");
@@ -149,8 +155,40 @@ static int remove_one_remote_overlay_layer(struct remote_overlay_data *data, con
         SYSERROR("Failed to remove link path %s", clean_path);
     }
 
+    link_id = (char *)map_search(overlay_id_link, (void *)overlay_id);
+
+    if (link_id == NULL) {
+        ERROR("Failed to find link id for overlay layer: %s", overlay_id);
+        ret = -1;
+        goto out;
+    }
+
+    nret = asprintf(&link_path, "%s/%s/%s", data->overlay_home, OVERLAY_LINK_DIR, link_id);
+    if (nret < 0 || nret > PATH_MAX) {
+        SYSERROR("Create link path failed");
+        ret = -1;
+        goto out;
+    }
+
+    if (util_clean_path(link_path, clean_path, sizeof(clean_path)) == NULL) {
+        ERROR("Failed to clean path: %s", ro_symlink);
+        ret = -1;
+        goto out;
+    }
+
+    if (util_path_remove(clean_path) != 0) {
+        SYSERROR("Failed to remove link path %s", clean_path);
+    }
+
+    if (!map_remove(overlay_id_link, (void *)overlay_id)) {
+        ERROR("Failed to remove link id for overlay layers: %s", overlay_id);
+        ret = -1;
+        goto out;
+    }
+
 out:
     free(ro_symlink);
+    free(link_path);
     return ret;
 }
 
@@ -162,6 +200,11 @@ static int add_one_remote_overlay_layer(struct remote_overlay_data *data, const
     char *diff_symlink = NULL;
     int ret = 0;
 
+    if (overlay_id == NULL) {
+        ERROR("can't add NULL remote layer");
+        return -1;
+    }
+
     ro_symlink = util_path_join(data->overlay_home, overlay_id);
     if (ro_symlink == NULL) {
         ERROR("Failed to join ro symlink path: %s", overlay_id);
@@ -211,6 +254,11 @@ static int add_one_remote_overlay_layer(struct remote_overlay_data *data, const
         ret = -1;
     }
 
+    if (!map_insert(overlay_id_link, util_strdup_s(overlay_id), (void *)diff_symlink)) {
+        ERROR("can't insert remote layer into map");
+        ret = -1;
+    }
+
 free_out:
     free(ro_symlink);
     free(layer_dir);
@@ -220,24 +268,26 @@ free_out:
     return ret;
 }
 
-static int remote_support_add(void *data)
+static int remote_image_add(struct remote_overlay_data *data)
 {
     int ret = 0;
     char **array_added = NULL;
     char **array_deleted = NULL;
     map_t *tmp_map = NULL;
+    bool exist = true;
     int i = 0;
 
     if (data == NULL) {
         return -1;
     }
 
-    array_added = added_layers(overlay_byid_old, overlay_byid_new);
-    array_deleted = deleted_layers(overlay_byid_old, overlay_byid_new);
+    array_added = remote_added_layers(overlay_byid_old, overlay_byid_new);
+    array_deleted = remote_deleted_layers(overlay_byid_old, overlay_byid_new);
 
     for (i = 0; i < util_array_len((const char **)array_added); i++) {
         if (add_one_remote_overlay_layer(data, array_added[i]) != 0) {
             ERROR("Failed to add remote overlay layer: %s", array_added[i]);
+            map_remove(overlay_byid_new, (void *)array_added[i]);
             ret = -1;
         }
     }
@@ -245,6 +295,7 @@ static int remote_support_add(void *data)
     for (i = 0; i < util_array_len((const char **)array_deleted); i++) {
         if (remove_one_remote_overlay_layer(data, array_deleted[i]) != 0) {
             ERROR("Failed to delete remote overlay layer: %s", array_deleted[i]);
+            map_insert(overlay_byid_new, array_deleted[i], (void *)&exist);
             ret = -1;
         }
     }
@@ -252,7 +303,7 @@ static int remote_support_add(void *data)
     tmp_map = overlay_byid_old;
     overlay_byid_old = overlay_byid_new;
     overlay_byid_new = tmp_map;
-    empty_map(overlay_byid_new);
+    map_clear(overlay_byid_new);
 
     util_free_array(array_added);
     util_free_array(array_deleted);
@@ -260,23 +311,19 @@ static int remote_support_add(void *data)
     return ret;
 }
 
-remote_support *overlay_driver_impl_remote_support(void)
+void remote_overlay_refresh(struct remote_overlay_data *data)
 {
-    remote_support *rs = util_common_calloc_s(sizeof(remote_support));
-    if (rs == NULL) {
-        ERROR("Failed to calloc overlay supporter");
-        return NULL;
+    if (remote_dir_scan(data) != 0) {
+        ERROR("remote overlay failed to scan dir, skip refresh");
+        return;
     }
 
-    rs->create = remote_support_create;
-    rs->destroy = remote_support_destroy;
-    rs->scan_remote_dir = remote_support_scan;
-    rs->load_item = remote_support_add;
-
-    return rs;
+    if (remote_image_add(data) != 0) {
+        ERROR("refresh overlay failed");
+    }
 }
 
-bool overlay_remote_layer_valid(const char *layer_id)
+bool remote_overlay_layer_valid(const char *layer_id)
 {
     return map_search(overlay_byid_old, (void *)layer_id) != NULL;
 }
diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
index 9dc096f7..3c7d0f54 100644
--- a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
@@ -15,108 +15,107 @@
 
 #include "remote_support.h"
 
-#include "layer_store.h"
-#include "image_store.h"
+#include <pthread.h>
+
 #include "isula_libutils/log.h"
-#include "driver_overlay2.h"
 #include "utils.h"
 
-remote_supporter *create_layer_supporter(const char *remote_home, const char *remote_ro)
-{
-    remote_support *handlers = layer_store_impl_remote_support();
-    if (handlers == NULL || handlers->create == NULL) {
-        return NULL;
-    }
+struct supporters {
+    struct remote_image_data *image_data;
+    struct remote_layer_data *layer_data;
+    struct remote_overlay_data *overlay_data;
+};
 
-    remote_supporter *supporter = (remote_supporter *)util_common_calloc_s(sizeof(remote_supporter));
-    if (supporter == NULL) {
-        goto err_out;
-    }
+static struct supporters supporters;
+
+static void *remote_refresh_ro_symbol_link(void *arg)
+{
+    struct supporters *refresh_supporters = (struct supporters *)arg;
+    prctl(PR_SET_NAME, "RoLayerRefresh");
 
-    supporter->handlers = handlers;
-    supporter->data = handlers->create(remote_home, remote_ro);
+    while (true) {
+        util_usleep_nointerupt(5 * 1000 * 1000);
+        DEBUG("remote refresh start\n");
 
-    return supporter;
+        remote_overlay_refresh(refresh_supporters->overlay_data);
+        remote_layer_refresh(refresh_supporters->layer_data);
+        remote_image_refresh(refresh_supporters->image_data);
 
-err_out:
-    free(handlers);
-    free(supporter);
+        DEBUG("remote refresh end\n");
+    }
     return NULL;
 }
 
-remote_supporter *create_image_supporter(const char *remote_home, const char *remote_ro)
+int remote_start_refresh_thread(void)
 {
-    remote_support *handlers = image_store_impl_remote_support();
-    if (handlers == NULL || handlers->create == NULL) {
-        return NULL;
-    }
+    int res = 0;
+    pthread_t a_thread;
+    maintain_context ctx = get_maintain_context();
 
-    remote_supporter *supporter = (remote_supporter *)util_common_calloc_s(sizeof(remote_supporter));
-    if (supporter == NULL) {
-        goto err_out;
+    supporters.image_data = remote_image_create(ctx.image_home, NULL);
+    if (supporters.image_data == NULL) {
+        goto free_out;
     }
 
-    supporter->handlers = handlers;
-    supporter->data = handlers->create(remote_home, remote_ro);
-
-    return supporter;
-
-err_out:
-    free(handlers);
-    free(supporter);
-    return NULL;
-}
+    supporters.layer_data = remote_layer_create(ctx.layer_home, ctx.layer_ro_dir);
+    if (supporters.layer_data == NULL) {
+        goto free_out;
+    }
 
-remote_supporter *create_overlay_supporter(const char *remote_home, const char *remote_ro)
-{
-    remote_support *handlers = overlay_driver_impl_remote_support();
-    if (handlers == NULL || handlers->create == NULL) {
-        return NULL;
+    supporters.overlay_data = remote_overlay_create(ctx.overlay_home, ctx.overlay_ro_dir);
+    if (supporters.overlay_data == NULL) {
+        goto free_out;
     }
 
-    remote_supporter *supporter = (remote_supporter *)util_common_calloc_s(sizeof(remote_supporter));
-    if (supporter == NULL) {
-        goto err_out;
+    res = pthread_create(&a_thread, NULL, remote_refresh_ro_symbol_link, (void *)&supporters);
+    if (res != 0) {
+        CRIT("Thread creation failed");
+        return -1;
     }
 
-    supporter->handlers = handlers;
-    supporter->data = handlers->create(remote_home, remote_ro);
+    if (pthread_detach(a_thread) != 0) {
+        SYSERROR("Failed to detach 0x%lx", a_thread);
+        return -1;
+    }
 
-    return supporter;
+    return 0;
 
-err_out:
-    free(handlers);
-    free(supporter);
-    return NULL;
+free_out:
+    remote_image_destroy(supporters.image_data);
+    remote_layer_destroy(supporters.layer_data);
+    remote_overlay_destroy(supporters.overlay_data);
 
+    return -1;
 }
 
-void destroy_suppoter(remote_supporter *supporter)
+// this function calculate map_a - map_b => diff_list
+// diff_list contains keys inside map_a but not inside map_b
+static char **map_diff(const map_t *map_a, const map_t *map_b)
 {
-    if (supporter->handlers->destroy == NULL) {
-        ERROR("destroy_supporter operation not supported");
-        return;
+    char **array = NULL;
+    map_itor *itor = map_itor_new(map_a);
+    bool *found = NULL;
+
+    // iter new_map, every item not in old, append them to new_layers
+    for (; map_itor_valid(itor); map_itor_next(itor)) {
+        char *id = map_itor_key(itor);
+        found = map_search(map_b, id);
+        if (found == NULL) {
+            util_array_append(&array, util_strdup_s(id));
+        }
     }
 
-    supporter->handlers->destroy(supporter->data);
-    free(supporter->handlers);
-    free(supporter);
+    map_itor_free(itor);
+
+    return array;
 }
 
-int scan_remote_dir(remote_supporter *supporter)
+char **remote_deleted_layers(const map_t *old, const map_t *new)
 {
-    if (supporter->handlers->scan_remote_dir == NULL) {
-        ERROR("scan_remote_dir operation not supported");
-        return -1;
-    }
-    return supporter->handlers->scan_remote_dir(supporter->data);
+    return map_diff(old, new);
 }
 
-int load_item(remote_supporter *supporter)
+char **remote_added_layers(const map_t *old, const map_t *new)
 {
-    if (supporter->handlers->scan_remote_dir == NULL) {
-        ERROR("load_item operation not supported");
-        return -1;
-    }
-    return supporter->handlers->load_item(supporter->data);
+    return map_diff(new, old);
 }
diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.h b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.h
index d1f7af35..892a9155 100644
--- a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.h
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.h
@@ -17,39 +17,59 @@
 #define DAEMON_MODULES_IMAGE_OCI_STORAGE_LAYER_STORE_REMOTE_LAYER_SUPPORT_REMOTE_SUPPORT_H
 
 #include "linked_list.h"
-#define REMOTE_RO_LAYER_DIR "RO"
-#define OVERLAY_RO_DIR "RO"
+#include "map.h"
+#include "ro_symlink_maintain.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-typedef struct {
-    void *(*create)(const char *remote_home, const char *remote_ro);
-    void (*destroy)(void *data);
-    // populate the list contains all dirs
-    int (*scan_remote_dir)(void *data);
-    // consume the list contains all dirs
-    int (*load_item)(void *data);
-} remote_support;
+struct remote_overlay_data {
+    const char *overlay_home;
+    const char *overlay_ro;
+};
 
-typedef struct {
-    void *data;
-    remote_support *handlers;
-} remote_supporter;
+struct remote_layer_data {
+    const char *layer_home;
+    const char *layer_ro;
+};
 
-// RemoteSupport *impl_remote_support();
-remote_supporter *create_image_supporter(const char *remote_home, const char *remote_ro);
+struct remote_image_data {
+    const char *image_home;
+};
 
-remote_supporter *create_layer_supporter(const char *remote_home, const char *remote_ro);
+// image impl
+struct remote_image_data *remote_image_create(const char *image_home, const char *image_ro);
 
-remote_supporter *create_overlay_supporter(const char *remote_home, const char *remote_ro);
+void remote_image_destroy(struct remote_image_data *data);
 
-void destroy_suppoter(remote_supporter *supporter);
+void remote_image_refresh(struct remote_image_data *data);
 
-int scan_remote_dir(remote_supporter *supporter);
+// layer impl
+struct remote_layer_data *remote_layer_create(const char *layer_home, const char *layer_ro);
 
-int load_item(remote_supporter *supporter);
+void remote_layer_destroy(struct remote_layer_data *data);
+
+void remote_layer_refresh(struct remote_layer_data *data);
+
+bool remote_layer_layer_valid(const char *layer_id);
+
+// overlay impl
+struct remote_overlay_data *remote_overlay_create(const char *overlay_home, const char *overlay_ro);
+
+void remote_overlay_destroy(struct remote_overlay_data *data);
+
+void remote_overlay_refresh(struct remote_overlay_data *data);
+
+bool remote_overlay_layer_valid(const char *layer_id);
+
+// start refresh remote
+int remote_start_refresh_thread(void);
+
+// extra map utils
+char **remote_deleted_layers(const map_t *old, const map_t *new_l);
+
+char **remote_added_layers(const map_t *old, const map_t *new_l);
 
 #ifdef __cplusplus
 }
diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c b/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c
index 7df7a221..a3aa3aa4 100644
--- a/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c
@@ -17,19 +17,15 @@
 
 #include <sys/prctl.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <pthread.h>
 #include <unistd.h>
-#include "map.h"
+
 #include "path.h"
 #include "linked_list.h"
-#include "layer_store.h"
-#include "layer.h"
 #include "isula_libutils/log.h"
-#include "image_store.h"
-#include "remote_support.h"
 #include "utils.h"
 #include "utils_file.h"
-#include "stdlib.h"
 
 #define REMOTE_RO_LAYER_DIR "RO"
 
@@ -43,14 +39,6 @@ static char *layer_home;
 static char *overlay_ro_dir;
 static char *overlay_home;
 
-struct supporters {
-    remote_supporter *image_supporter;
-    remote_supporter *layer_supporter;
-    remote_supporter *overlay_supporter;
-};
-
-static struct supporters supporters;
-
 int remote_image_init(const char *root_dir)
 {
     if (root_dir == NULL) {
@@ -134,75 +122,11 @@ void remote_maintain_cleanup(void)
     overlay_ro_dir = NULL;
 }
 
-// to maintain the symbol links, add new symbol link and delete invalid symbol link
-// arg is const char *driver_home
-// scanning driver->home/RO/ directory, build symlink in driver->home
-static void *remote_refresh_ro_symbol_link(void *arg)
-{
-    struct supporters *supporters = (struct supporters *)arg;
-    prctl(PR_SET_NAME, "RoLayerRefresh");
-
-    while (true) {
-        util_usleep_nointerupt(5 * 1000 * 1000);
-        DEBUG("remote refresh start\n");
-        scan_remote_dir(supporters->overlay_supporter);
-        load_item(supporters->overlay_supporter);
-        scan_remote_dir(supporters->layer_supporter);
-        load_item(supporters->layer_supporter);
-        scan_remote_dir(supporters->image_supporter);
-        load_item(supporters->image_supporter);
-        DEBUG("remote refresh end\n");
-    }
-    return NULL;
-}
-
-int start_refresh_thread(void)
-{
-    int res = 0;
-    pthread_t a_thread;
-
-    supporters.image_supporter = create_image_supporter(image_home, NULL);
-    if (supporters.image_supporter == NULL) {
-        goto free_out;
-    }
-
-    supporters.layer_supporter = create_layer_supporter(layer_home, layer_ro_dir);
-    if (supporters.layer_supporter == NULL) {
-        goto free_out;
-    }
-
-    supporters.overlay_supporter = create_overlay_supporter(overlay_home, overlay_ro_dir);
-    if (supporters.overlay_supporter == NULL) {
-        goto free_out;
-    }
-
-    res = pthread_create(&a_thread, NULL, remote_refresh_ro_symbol_link, (void *)&supporters);
-    if (res != 0) {
-        CRIT("Thread creation failed");
-        return -1;
-    }
-
-    if (pthread_detach(a_thread) != 0) {
-        SYSERROR("Failed to detach 0x%lx", a_thread);
-        return -1;
-    }
-
-    return 0;
-
-free_out:
-    destroy_suppoter(supporters.image_supporter);
-    destroy_suppoter(supporters.layer_supporter);
-    destroy_suppoter(supporters.overlay_supporter);
-
-    return -1;
-}
-
 static int do_build_ro_dir(const char *home, const char *id)
 {
     char *ro_symlink = NULL;
     char *ro_layer_dir = NULL;
     int nret = 0;
-    // bool ret = true;
     int ret = 0;
 
     nret = asprintf(&ro_symlink, "%s/%s", home, id);
@@ -305,43 +229,15 @@ int remote_overlay_remove_ro_dir(const char *id)
     return do_remove_ro_dir(overlay_home, id);
 }
 
-static char **map_diff(map_t *map_a, map_t *map_b)
-{
-    char **array = NULL;
-    map_itor *itor = map_itor_new(map_a);
-    bool *found = NULL;
-
-    // iter new_map, every item not in old, append them to new_layers
-    for (; map_itor_valid(itor); map_itor_next(itor)) {
-        char *id = map_itor_key(itor);
-        found = map_search(map_b, id);
-        if (found == NULL) {
-            util_array_append(&array, util_strdup_s(id));
-        }
-    }
-
-    map_itor_free(itor);
-
-    return array;
-}
-
-char **deleted_layers(map_t *old, map_t *new)
-{
-    return map_diff(old, new);
-}
-
-char **added_layers(map_t *old, map_t *new)
+maintain_context get_maintain_context(void)
 {
-    return map_diff(new, old);
-}
+    maintain_context ctx = {0x0};
 
-int empty_map(map_t *mp)
-{
-    if (mp == NULL) {
-        return -1;
-    }
+    ctx.image_home = image_home;
+    ctx.layer_ro_dir = layer_ro_dir;
+    ctx.layer_home = layer_home;
+    ctx.overlay_ro_dir = overlay_ro_dir;
+    ctx.overlay_home = overlay_home;
 
-    map_clear(mp);
-    mp->store->root = mp->store->nil;
-    return 0;
+    return ctx;
 }
diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.h b/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.h
index 25712d40..aa2036ea 100644
--- a/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.h
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.h
@@ -15,12 +15,21 @@
 #ifndef DAEMON_MODULES_IMAGE_OCI_STORAGE_LAYER_STORE_REMOTE_LAYER_SUPPORT_RO_SYMLINK_MAINTAIN_H
 #define DAEMON_MODULES_IMAGE_OCI_STORAGE_LAYER_STORE_REMOTE_LAYER_SUPPORT_RO_SYMLINK_MAINTAIN_H
 
-#include "map.h"
+#define REMOTE_RO_LAYER_DIR "RO"
+#define OVERLAY_RO_DIR "RO"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+typedef struct {
+    const char *image_home;
+    const char *layer_ro_dir;
+    const char *layer_home;
+    const char *overlay_ro_dir;
+    const char *overlay_home;
+} maintain_context;
+
 int remote_image_init(const char *root_dir);
 
 int remote_layer_init(const char *root_dir);
@@ -29,8 +38,6 @@ int remote_overlay_init(const char *driver_home);
 
 void remote_maintain_cleanup(void);
 
-int start_refresh_thread(void);
-
 int remote_layer_build_ro_dir(const char *id);
 
 int remote_overlay_build_ro_dir(const char *id);
@@ -39,11 +46,7 @@ int remote_layer_remove_ro_dir(const char *id);
 
 int remote_overlay_remove_ro_dir(const char *id);
 
-char **deleted_layers(map_t *old, map_t *new);
-
-char **added_layers(map_t *old, map_t *new);
-
-int empty_map(map_t *mp);
+maintain_context get_maintain_context(void);
 
 #ifdef __cplusplus
 }
diff --git a/src/daemon/modules/image/oci/storage/storage.c b/src/daemon/modules/image/oci/storage/storage.c
index 31812a22..f9830ac3 100644
--- a/src/daemon/modules/image/oci/storage/storage.c
+++ b/src/daemon/modules/image/oci/storage/storage.c
@@ -43,7 +43,7 @@
 #include "utils_verify.h"
 #include "sha256.h"
 #ifdef ENABLE_REMOTE_LAYER_STORE
-#include "ro_symlink_maintain.h"
+#include "remote_support.h"
 #endif
 
 static pthread_rwlock_t g_storage_rwlock;
@@ -1874,7 +1874,7 @@ int storage_module_init(struct storage_module_init_options *opts)
     }
 
 #ifdef ENABLE_REMOTE_LAYER_STORE
-    if (opts->enable_remote_layer && start_refresh_thread() != 0) {
+    if (opts->enable_remote_layer && remote_start_refresh_thread() != 0) {
         ERROR("Failed to start remote refresh thread");
     }
 #endif
diff --git a/src/utils/cutils/map/rb_tree.c b/src/utils/cutils/map/rb_tree.c
index e933003a..b85371e3 100644
--- a/src/utils/cutils/map/rb_tree.c
+++ b/src/utils/cutils/map/rb_tree.c
@@ -134,6 +134,7 @@ void rbtree_clear(rb_tree_t *tree)
         return;
     }
     rbtree_destroy_all(tree, tree->root);
+    tree->root = tree->nil;
 }
 
 void rbtree_free(rb_tree_t *tree)
diff --git a/test/image/oci/registry/CMakeLists.txt b/test/image/oci/registry/CMakeLists.txt
index 13ed95b2..5475b7b5 100644
--- a/test/image/oci/registry/CMakeLists.txt
+++ b/test/image/oci/registry/CMakeLists.txt
@@ -26,6 +26,7 @@ add_executable(${EXE}
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry_type.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common/sysinfo.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/storage/image_store/image_store.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/registry.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/registry_apiv2.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/registry_apiv1.c
@@ -57,6 +58,7 @@ target_include_directories(${EXE} PUBLIC
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/storage
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/storage/image_store
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/storage/remote_layer_support
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../mocks
     )
diff --git a/test/image/oci/storage/CMakeLists.txt b/test/image/oci/storage/CMakeLists.txt
index feb81b14..7a9d77fe 100644
--- a/test/image/oci/storage/CMakeLists.txt
+++ b/test/image/oci/storage/CMakeLists.txt
@@ -3,3 +3,6 @@ project(iSulad_UT)
 add_subdirectory(images)
 add_subdirectory(rootfs)
 add_subdirectory(layers)
+IF (ENABLE_REMOTE_LAYER_STORE)
+add_subdirectory(remote_layer_support)
+ENDIF()
diff --git a/test/image/oci/storage/images/CMakeLists.txt b/test/image/oci/storage/images/CMakeLists.txt
index 3e6b69a4..8446ebba 100644
--- a/test/image/oci/storage/images/CMakeLists.txt
+++ b/test/image/oci/storage/images/CMakeLists.txt
@@ -21,6 +21,7 @@ add_executable(${EXE}
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/image_store/image_type.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/registry_type.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/image_store/image_store.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks/storage_mock.cc
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks/isulad_config_mock.cc
     storage_images_ut.cc)
@@ -39,6 +40,7 @@ target_include_directories(${EXE} PUBLIC
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/image_store
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/registry
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks
     )
diff --git a/test/image/oci/storage/layers/CMakeLists.txt b/test/image/oci/storage/layers/CMakeLists.txt
index 952e9483..ae0ac9c3 100644
--- a/test/image/oci/storage/layers/CMakeLists.txt
+++ b/test/image/oci/storage/layers/CMakeLists.txt
@@ -30,6 +30,7 @@ add_executable(${DRIVER_EXE}
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/metadata_store.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota/project_quota.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks/driver_quota_mock.cc
     storage_driver_ut.cc)
@@ -52,6 +53,7 @@ target_include_directories(${DRIVER_EXE} PUBLIC
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks
     )
@@ -105,6 +107,7 @@ add_executable(${LAYER_EXE}
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota/project_quota.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks/driver_quota_mock.cc
     storage_layers_ut.cc)
 
@@ -129,6 +132,7 @@ target_include_directories(${LAYER_EXE} PUBLIC
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks
     )
 
diff --git a/test/image/oci/storage/remote_layer_support/CMakeLists.txt b/test/image/oci/storage/remote_layer_support/CMakeLists.txt
new file mode 100644
index 00000000..c36d9049
--- /dev/null
+++ b/test/image/oci/storage/remote_layer_support/CMakeLists.txt
@@ -0,0 +1,44 @@
+project(iSulad_UT)
+
+SET(EXE remote_layer_support_ut)
+
+add_executable(${EXE}
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks/remote_store_mock.cc
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils/map/map.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/image_remote_impl.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/layer_remote_impl.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils/utils_file.c
+    remote_layer_ut.cc
+    )
+
+target_include_directories(${EXE} PUBLIC
+    ${GTEST_INCLUDE_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../include
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/config
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/common
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/api
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/image_store
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks
+    )
+
+target_link_libraries(${EXE} 
+    ${GTEST_BOTH_LIBRARIES} 
+    ${GMOCK_LIBRARY} 
+    ${GMOCK_MAIN_LIBRARY} 
+    ${CMAKE_THREAD_LIBS_INIT} 
+    ${ISULA_LIBUTILS_LIBRARY} 
+    -lgtest -lgtest_main libutils_ut -lcrypto -lyajl -lz)
+
+add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
+set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
diff --git a/test/image/oci/storage/remote_layer_support/remote_layer_ut.cc b/test/image/oci/storage/remote_layer_support/remote_layer_ut.cc
new file mode 100644
index 00000000..5f5e92fb
--- /dev/null
+++ b/test/image/oci/storage/remote_layer_support/remote_layer_ut.cc
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
+ * iSulad licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *     http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: wangrunze
+ * Create: 2023-03-16
+ * Description: provide remote layer support ut
+ ******************************************************************************/
+#include <gtest/gtest.h>
+
+#include "remote_store_mock.h"
+#include "ro_symlink_maintain.h"
+#include "remote_support.h"
+#include "map.h"
+
+using ::testing::Invoke;
+
+bool invokeOverlayRemoteLayerValid(const char *id)
+{
+    return true; /* currently always valid overlay layer */
+}
+
+bool invokeLayerRemoteLayerValid(const char *id)
+{
+    return true;
+}
+
+int invokeLayerLoadOneLayer(const char *id)
+{
+    return 0;
+}
+
+int invokeLayerRemoveOneLayer(const char *id)
+{
+    return 0;
+}
+
+int invokeImageAppendOneImage(const char *id)
+{
+    return 0;
+}
+
+int invokeImageRemoveOneImage(const char *id)
+{
+    return 0;
+}
+
+char *invokeImageGetTopLayer(const char *id)
+{
+    return NULL;
+}
+
+int invokeImageValidSchemaV1(const char *path, bool *valid)
+{
+    return 0;
+}
+
+void mockCommonAll(MockRemoteStore *mock)
+{
+    EXPECT_CALL(*mock, LayerLoadOneLayer(::testing::_)).WillRepeatedly(Invoke(invokeLayerLoadOneLayer));
+    EXPECT_CALL(*mock, LayerRemoveOneLayer(::testing::_)).WillRepeatedly(Invoke(invokeLayerRemoveOneLayer));
+
+    EXPECT_CALL(*mock, ImageAppendOneImage(::testing::_)).WillRepeatedly(Invoke(invokeImageAppendOneImage));
+    EXPECT_CALL(*mock, ImageRemoveOneImage(::testing::_)).WillRepeatedly(Invoke(invokeImageRemoveOneImage));
+    EXPECT_CALL(*mock, ImageGetTopLayer(::testing::_)).WillRepeatedly(Invoke(invokeImageGetTopLayer));
+    EXPECT_CALL(*mock, ImageValidSchemaV1(::testing::_, ::testing::_)).WillRepeatedly(Invoke(invokeImageValidSchemaV1));
+}
+
+TEST(remote_Layer_ut, test_map_diff)
+{
+    // old: a b x 
+    // new: x b c
+    map_t *old_one = map_new(MAP_STR_BOOL, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
+    map_t *new_one = map_new(MAP_STR_BOOL, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
+    bool exist = true;
+
+    map_insert(old_one, (void *)"a", (void *)&exist);
+    map_insert(old_one, (void *)"b", (void *)&exist);
+    map_insert(new_one, (void *)"b", (void *)&exist);
+    map_insert(new_one, (void *)"c", (void *)&exist);
+
+    char **added = remote_added_layers(old_one, new_one);
+    char **deleted = remote_deleted_layers(old_one, new_one);
+
+    ASSERT_EQ(added[0][0], 'c');
+    ASSERT_EQ(deleted[0][0], 'a');
+}
diff --git a/test/image/oci/storage/rootfs/CMakeLists.txt b/test/image/oci/storage/rootfs/CMakeLists.txt
index 4d7d3533..5383fbac 100644
--- a/test/image/oci/storage/rootfs/CMakeLists.txt
+++ b/test/image/oci/storage/rootfs/CMakeLists.txt
@@ -22,6 +22,7 @@ add_executable(${EXE}
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/utils_images.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/rootfs_store/rootfs.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks/storage_mock.cc
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks/isulad_config_mock.cc
     storage_rootfs_ut.cc)
@@ -41,6 +42,7 @@ target_include_directories(${EXE} PUBLIC
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/rootfs_store
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/remote_layer_support
     )
 
 target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
diff --git a/test/mocks/remote_store_mock.cc b/test/mocks/remote_store_mock.cc
new file mode 100644
index 00000000..c6428623
--- /dev/null
+++ b/test/mocks/remote_store_mock.cc
@@ -0,0 +1,68 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
+ * iSulad licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *     http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: wangrunze
+ * Create: 2023-03-09
+ * Description: provide mock for image store, layer store and driver overlay
+ ******************************************************************************/
+
+#include "remote_store_mock.h"
+
+namespace {
+MockRemoteStore *g_remote_store_mock = nullptr;
+}
+
+int remote_load_one_layer(const char *id)
+{
+    if (g_remote_store_mock != nullptr) {
+        return g_remote_store_mock->LayerLoadOneLayer(id);
+    }
+    return -1;
+}
+
+int remote_layer_remove_memory_stores_with_lock(const char *id)
+{
+    if (g_remote_store_mock != nullptr) {
+        return g_remote_store_mock->LayerRemoveOneLayer(id);
+    }
+    return -1;
+}
+
+int image_store_validate_manifest_schema_version_1(const char *path, bool *valid)
+{
+    if (g_remote_store_mock != nullptr) {
+        return g_remote_store_mock->ImageValidSchemaV1(path, valid);
+    }
+    return -1;
+}
+
+int remote_append_image_by_directory_with_lock(const char *image_dir)
+{
+    if (g_remote_store_mock != nullptr) {
+        return g_remote_store_mock->ImageAppendOneImage(image_dir);
+    }
+    return -1;
+}
+
+int remote_remove_image_from_memory_with_lock(const char *id)
+{
+    if (g_remote_store_mock != nullptr) {
+        return g_remote_store_mock->ImageRemoveOneImage(id);
+    }
+    return -1;
+}
+
+char *remote_image_get_top_layer_from_json(const char *img_id)
+{
+    if (g_remote_store_mock != nullptr) {
+        return g_remote_store_mock->ImageGetTopLayer(img_id);
+    }
+    return nullptr;
+}
diff --git a/test/mocks/remote_store_mock.h b/test/mocks/remote_store_mock.h
new file mode 100644
index 00000000..e8d73ef1
--- /dev/null
+++ b/test/mocks/remote_store_mock.h
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
+ * iSulad licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *     http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: wangrunze
+ * Create: 2023-03-09
+ * Description: provide mock for image store, layer store and driver overlay
+ ******************************************************************************/
+
+#ifndef _ISULAD_TEST_MOCKS_REMOTE_STORE_MOCK_H
+#define _ISULAD_TEST_MOCKS_REMOTE_STORE_MOCK_H
+
+#include <gmock/gmock.h>
+
+#include "image_store.h"
+#include "layer_store.h"
+#include "driver_overlay2.h"
+
+class MockRemoteStore {
+public:
+    virtual ~MockRemoteStore() = default;
+    // MOCK_METHOD1(OverlayRemoteLayerValid, bool(const char *));
+
+    // MOCK_METHOD1(LayerRemoteLayerValid, bool(const char *));
+    MOCK_METHOD1(LayerLoadOneLayer, int(const char *));
+    MOCK_METHOD1(LayerRemoveOneLayer, int(const char *));
+
+    MOCK_METHOD1(ImageAppendOneImage, int(const char *));
+    MOCK_METHOD1(ImageRemoveOneImage, int(const char *));
+    MOCK_METHOD1(ImageGetTopLayer, char *(const char *));
+    MOCK_METHOD2(ImageValidSchemaV1, int(const char *, bool *));
+};
+
+#endif // _ISULAD_TEST_MOCKS_IMAGE_MOCK_H
-- 
2.25.1