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
|
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _BITMAP_H_
#define _BITMAP_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/errno.h>
/*
* This interface is designed to provide an abatract data type
* for manipulating in-core and on-disk bitmaps.
*
* When a bitmap is allocated, a descriptor to the bitmap is
* returned to the caller. The descriptor is an integer. All
* functions of the API use this descriptor to locate the
* bitmap.
*
* Each bitmap is divided into chunks (internally). Each chunk
* is BMAP_CHUNK_WORDS words (4K now). Chunks are kept in an
* LRU list for caching.
*
* There is also a hashing on the chunks for accessing them.
* Each hash is an MRU list.
*
* The interfaces are:
* bm_alloc: To allocate a new bitmap.
* bm_free: To release the bitmap.
* bm_getlen: To get the length of the bitmap.
* bm_getiov: To get the bits specified by the vectors.
* bm_setiov: To set the bits specified by the vectors.
* bm_apply_ifset: Calls a callback function on each set
* bit in the bitmap.
* bm_apply_ifunset: Calls a callback function on each
* clear bit in the bitmap.
*
* There are some other interface for simpilicty of programs:
* bm_get To get a range of bits.
* bm_set: To set a range of bits.
* bm_getone: To get one bit only.
* bm_setone: To set one bit only.
* bm_unsetone: To unset one bit only.
*
* The on-disk bitmap functions are the same except they start
* with dbm_*
*/
typedef u_longlong_t u_quad_t;
/*
* A vector for setting bits in the bitmap.
* - bmv_base: The starting bit number.
* - bmv_len: Lenght of the vector.
* - bmv_val: Pointer to the new value of bits.
*/
typedef struct bm_iovec {
u_quad_t bmv_base;
u_quad_t bmv_len;
uint_t *bmv_val;
} bm_iovec_t;
/*
* An array of vectors on which the set/get operations
* will take place.
* - bmio_iovcnt: Number of entries in the array.
* - bmio_iov: Array of vectors.
*/
typedef struct bm_io {
int bmio_iovcnt;
bm_iovec_t *bmio_iov;
} bm_io_t;
extern void bm_print(int);
/*
* External Interface.
*/
extern int bm_alloc(u_quad_t, int);
extern int dbm_alloc(char *, u_quad_t, int);
extern int bm_free(int);
extern int dbm_free(int);
extern int bm_realloc(int, u_quad_t);
extern int dbm_realloc(int, u_quad_t);
extern int bm_setiov(int, bm_io_t *);
extern int dbm_setiov(int, bm_io_t *);
extern int bm_getiov(int, bm_io_t *);
extern int dbm_getiov(int, bm_io_t *);
extern int bm_apply_ifset(int, int (*)(), void *);
extern int dbm_apply_ifset(int, int (*)(), void *);
extern int bm_apply_ifunset(int, int (*)(), void *);
extern int dbm_apply_ifunset(int, int (*)(), void *);
extern char *dbm_getfname(int);
extern u_quad_t bm_getlen(int);
extern u_quad_t dbm_getlen(int);
extern void dbm_print(int);
/*
* Statistical and debugging interface.
*/
extern void dbitmap_stats_clear(void);
/*
* Macros for setting and unsetting only one bit.
*/
#define bm_setone(bmd, bn) bm_set((bmd), (bn), 1, 1)
#define dbm_setone(bmd, bn) dbm_set((bmd), (bn), 1, 1)
#define bm_unsetone(bmd, bn) bm_set((bmd), (bn), 1, 0)
#define dbm_unsetone(bmd, bn) dbm_set((bmd), (bn), 1, 0)
extern int bm_set(int, u_quad_t, u_quad_t, uint_t);
extern int dbm_set(int, u_quad_t, u_quad_t, uint_t);
extern int bm_get(int, u_quad_t, u_quad_t, uint_t *);
extern int dbm_get(int, u_quad_t, u_quad_t, uint_t *);
extern int bm_getone(int, u_quad_t);
extern int dbm_getone(int, u_quad_t);
#ifdef __cplusplus
}
#endif
#endif /* _BITMAP_H_ */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Interface definition for the list based stack class. The stack only
* holds pointers/references to application objects. The objects are not
* copied and the stack never attempts to dereference or access the data
* objects. Applications should treat cstack_t references as opaque
* handles.
*/
#ifndef _CSTACK_H_
#define _CSTACK_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct cstack {
struct cstack *next;
void *data;
int len;
} cstack_t;
cstack_t *cstack_new(void);
void cstack_delete(cstack_t *);
int cstack_push(cstack_t *, void *, int);
int cstack_pop(cstack_t *, void **, int *);
int cstack_top(cstack_t *, void **, int *);
#ifdef __cplusplus
}
#endif
#endif /* _CSTACK_H_ */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _NDMPD_DOOR_H
#define _NDMPD_DOOR_H
#include <rpc/types.h>
#include <libndmp.h>
#include <atomic.h>
#define NDMP_DOOR_SVC "/var/run/ndmp_door_svc"
#define NDMP_DOOR_SIZE (8 * 1024)
#define NDMP_DOOR_SRV_SUCCESS 0
#define NDMP_DOOR_SRV_ERROR -1
#define NDMP_SESSION_DATA 1
#define NDMP_SESSION_NODATA 0
/* DOOR REQUESTS */
/* door status message */
#define NDMP_GET_DOOR_STATUS 0
/* set subcommand messages */
#define NDMP_SET_DEBUG_LEVEL 1
#define NDMP_SET_DEBUG_PATH 2
#define NDMP_SET_DUMP_PATHNODE 3
#define NDMP_SET_TAR_PATHNODE 4
#define NDMP_SET_IGNOR_CTIME 5
#define NDMP_SET_MAXSEQ 6
#define NDMP_SET_VERSION 7
#define NDMP_SET_DAR 8
#define NDMP_SET_BACKUP_QTN 9
#define NDMP_SET_RESTORE_QTN 10
#define NDMP_SET_OVERWRITE_QTN 11
/* get subcommand messages */
#define NDMP_GET_DEBUG_LEVEL 20
#define NDMP_GET_DEBUG_PATH 21
#define NDMP_GET_DUMP_PATHNODE 22
#define NDMP_GET_TAR_PATHNODE 23
#define NDMP_GET_IGNOR_CTIME 24
#define NDMP_GET_MAXSEQ 25
#define NDMP_GET_VERSION 26
#define NDMP_GET_DAR 27
#define NDMP_GET_BACKUP_QTN 28
#define NDMP_GET_RESTORE_QTN 29
#define NDMP_GET_OVERWRITE_QTN 30
#define NDMP_GET_ALL 31
#define NDMP_GET_DEV_CNT 32
/* ndmpstat messages */
#define NDMP_GET_STAT 33
/* device subcommand message */
#define NDMP_DEVICES_GET_INFO 40
/* show subcommand messages */
#define NDMP_SHOW 60
/* terminate subcommand messages */
#define NDMP_TERMINATE_SESSION_ID 80
#define NDMP_TERMINATE_SESSION_ALL 81
/*
* NDMP statistics
*/
extern ndmp_stat_t ndstat;
#define NS_INC(s) (atomic_inc_32((volatile uint32_t *)&ndstat.ns_##s))
#define NS_DEC(s) (atomic_dec_32((volatile uint32_t *)&ndstat.ns_##s))
#define NS_ADD(s, d) (atomic_add_64((volatile uint64_t *)&ndstat.ns_##s, \
(uint64_t)d))
#define NS_UPD(s, t) { \
atomic_inc_32((volatile uint32_t *)&ndstat.ns_##s); \
atomic_dec_32((volatile uint32_t *)&ndstat.ns_##t); \
}
#endif /* _NDMPD_DOOR_H */
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _NDMPD_PROP_H
#define _NDMPD_PROP_H
#include <sys/types.h>
#include <libscf.h>
#ifdef __cplusplus
extern "C" {
#endif
/* NDMP property parameter flags */
#define NDMP_CF_NOTINIT 0x00 /* Not initialized yet */
#define NDMP_CF_DEFINED 0x01 /* Defined/read from env */
#define NDMP_CF_MODIFIED 0x02 /* Has been modified */
typedef enum {
NDMP_DAR_SUPPORT = 0,
NDMP_MOVER_NIC,
/*
* Force backing up the directories leading to
* a modified object for 'dump' format backup.
*/
NDMP_DUMP_PATHNODE_ENV,
/*
* Force backing up the directories leading to
* a modified object for 'tar' format backup.
*/
NDMP_TAR_PATHNODE_ENV,
/*
* Force to send the file history node entries
* along with the file history dir entries for
* all directories containing the changed files
* to the client for incremental backup.
*
* Note: This variable is added to support BakBone
* Software's NetVault DMA which expects to get the
* FH ADD NODES for all upper directories which
* contain the changed files in incremental backup
* along with the FH ADD DIRS.
*/
NDMP_FHIST_INCR_ENV,
/* Ignore st_ctime when backing up. */
NDMP_IGNCTIME_ENV,
/* If we should check for the last modification time. */
NDMP_INCLMTIME_ENV,
/*
* Environment variable name for the maximum permitted
* token sequence for token-based backups.
*/
NDMP_MAXSEQ_ENV,
/* Environment variable name for the active version. */
NDMP_VERSION_ENV,
/*
* Environment variable name for restore path.
* Suppose that a dircetroy named "/d1/d11" is backed
* up and there is a file "/d1/d11/d111/f" under that
* directory and the restore path is "/d1/r1".
* If restore path mechanism is set to 0 which means
* partial path restore, then the result will be
* "/d1/r1/d111/f". If it is set to 1 which means full
* path restore, the result will be "/d1/r1/d1/d11/d111/f"
*/
NDMP_FULL_RESTORE_PATH,
NDMP_DEBUG_PATH,
NDMP_PLUGIN_PATH,
NDMP_SOCKET_CSS,
NDMP_SOCKET_CRS,
NDMP_MOVER_RECSIZE,
NDMP_RESTORE_WILDCARD_ENABLE,
NDMP_CRAM_MD5_USERNAME,
NDMP_CRAM_MD5_PASSWORD,
NDMP_CLEARTEXT_USERNAME,
NDMP_CLEARTEXT_PASSWORD,
NDMP_TCP_PORT,
NDMP_BACKUP_QTN,
NDMP_RESTORE_QTN,
NDMP_OVERWRITE_QTN,
NDMP_ZFS_FORCE_OVERRIDE,
NDMP_DRIVE_TYPE,
NDMP_DEBUG_MODE,
NDMP_MAXALL
} ndmpd_cfg_id_t;
extern int ndmpd_load_prop(void);
extern char *ndmpd_get_prop(ndmpd_cfg_id_t);
extern char *ndmpd_get_prop_default(ndmpd_cfg_id_t, char *);
extern int ndmpd_get_prop_yorn(ndmpd_cfg_id_t);
#ifdef __cplusplus
}
#endif
#endif /* _NDMPD_PROP_H */
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015 by Delphix. All rights reserved.
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _TLM_H_
#define _TLM_H_
#include <sys/types.h>
#include <synch.h>
#include <limits.h>
#include <cstack.h>
#include <sys/acl.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <strings.h>
#include <sys/stat.h>
#include <time.h>
#include <sys/queue.h>
#include <sys/fs/zfs.h>
#include <libzfs.h>
#define IS_SET(f, m) (((f) & (m)) != 0)
#define TLM_MAX_BACKUP_JOB_NAME 32 /* max size of a job's name */
#define TLM_TAPE_BUFFERS 10 /* number of rotating tape buffers */
#define TLM_LINE_SIZE 128 /* size of text messages */
#define TLM_BACKUP_RUN 0x00000001
#define TLM_RESTORE_RUN 0x00000002
#define TLM_STOP 0x00000009 /* graceful stop */
#define TLM_ABORT 0x99999999 /* abandon the run */
#define TLM_EXTRA_SPACE 64
#define TLM_MAX_PATH_NAME (PATH_MAX + TLM_EXTRA_SPACE)
#define ENTRYTYPELEN 14
#define PERMS 4
#define ID_STR_MAX 20
#define APPENDED_ID_MAX (ID_STR_MAX + 1)
#define ACL_ENTRY_SIZE (ENTRYTYPELEN + ID_STR_MAX + PERMS + APPENDED_ID_MAX)
#define TLM_MAX_ACL_TXT MAX_ACL_ENTRIES * ACL_ENTRY_SIZE
/* operation flags */
#define TLM_OP_CHOOSE_ARCHIVE 0x00000001 /* look for archive bit */
/*
* Synchronization flags used when launching the TLM threads.
*/
#define TLM_TAPE_READER 0x00000001
#define TLM_TAPE_WRITER 0x00000002
#define TLM_SOCK_READER 0x00000004
#define TLM_SOCK_WRITER 0x00000008
#define TLM_BUF_READER 0x00000010
#define TLM_BUF_WRITER 0x00000020
#define TLM_TAR_READER 0x00000040
#define TLM_TAR_WRITER 0x00000080
#define SCSI_SERIAL_PAGE 0x80
#define SCSI_DEVICE_IDENT_PAGE 0x83
#define SCMD_READ_ELEMENT_STATUS 0xB8
#define OCTAL7CHAR 07777777
#define SYSATTR_RDONLY "SUNWattr_ro"
#define SYSATTR_RW "SUNWattr_rw"
typedef int (*func_t)();
typedef struct scsi_serial {
int sr_flags;
char sr_num[16];
} scsi_serial_t;
typedef struct fs_fhandle {
int fh_fid;
char *fh_fpath;
} fs_fhandle_t;
typedef struct scsi_link {
struct scsi_link *sl_next;
struct scsi_link *sl_prev;
struct scsi_adapter *sl_sa;
unsigned int sl_sid;
unsigned int sl_lun;
unsigned int sl_requested_max_active;
unsigned int sl_granted_max_active;
unsigned int sl_n_active;
unsigned int sl_type; /* SCSI device type */
} scsi_link_t;
typedef struct scsi_adapter {
struct scsi_adapter *sa_next;
char sa_name[16];
struct scsi_link sa_link_head;
} scsi_adapter_t;
typedef struct sasd_drive {
char sd_name[256];
char sd_vendor[8 + 1];
char sd_id[16 + 1];
char sd_rev[4 + 1];
char sd_serial[16 + 1];
char sd_wwn[32 + 1];
} sasd_drive_t;
typedef struct scsi_sasd_drive {
sasd_drive_t ss_sd;
scsi_link_t ss_slink;
} scsi_sasd_drive_t;
#define DEFAULT_SLINK_MAX_XFER (64*1024)
typedef struct tlm_info {
int ti_init_done; /* initialization done ? */
int ti_library_count; /* number of libraries */
struct tlm_library *ti_library; /* first in chain */
struct tlm_chain_link *ti_job_stats; /* chain of job statistics */
} tlm_info_t;
typedef struct tlm_chain_link {
struct tlm_chain_link *tc_next; /* next blob of statistics */
struct tlm_chain_link *tc_prev; /* previous blob in the chain */
int tc_ref_count; /* number of routines */
void *tc_data; /* the data blob */
} tlm_chain_link_t;
typedef struct tlm_robot {
struct tlm_robot *tr_next;
struct tlm_library *tr_library;
int tr_number;
} tlm_robot_t;
typedef struct tlm_drive {
struct tlm_drive *td_next;
struct tlm_library *td_library;
char td_job_name[TLM_MAX_BACKUP_JOB_NAME];
int td_number; /* number of this tape drive */
int td_element; /* the library's number for the drive */
struct scsi_link *td_slink; /* because the drive may be connected */
/* to a different SCSI card than the */
/* library */
short td_scsi_id;
short td_lun;
short td_volume_number; /* for current job */
/* an index into the tape set */
int td_fd; /* I/O file descriptor */
int td_errno; /* system error number */
long td_exists : 1;
} tlm_drive_t;
typedef struct tlm_slot {
struct tlm_slot *ts_next;
struct tlm_library *ts_library;
int ts_number; /* number of this slot */
int ts_element;
short ts_use_count; /* number of times used since loaded */
long ts_status_full : 1;
} tlm_slot_t;
typedef struct tlm_library {
struct tlm_library *tl_next;
int tl_number; /* number of this tape library */
long tl_capability_robot : 1,
tl_capability_door : 1,
tl_capability_lock : 1,
tl_capability_slots : 1,
tl_capability_export : 1,
tl_capability_drives : 1,
tl_capability_barcodes : 1,
tl_ghost_drives : 1;
/*
* "ghost_drives" is used to make sure that
* all drives claimed by the library really
* exist ... libraries have been known to lie.
*/
struct scsi_link *tl_slink;
int tl_robot_count;
tlm_robot_t *tl_robot;
int tl_drive_count;
tlm_drive_t *tl_drive;
int tl_slot_count;
tlm_slot_t *tl_slot;
} tlm_library_t;
typedef struct {
#ifdef _BIG_ENDIAN
uint8_t di_peripheral_qual : 3,
di_peripheral_dev_type : 5;
uint8_t di_page_code;
uint16_t di_page_length;
#else
uint8_t di_peripheral_dev_type : 5,
di_peripheral_qual : 3;
uint8_t di_page_code;
uint16_t di_page_length;
#endif
} device_ident_header_t;
typedef struct {
#ifdef _BIG_ENDIAN
uint8_t ni_proto_ident : 4,
ni_code_set : 4;
uint8_t ni_PIV : 1,
: 1,
ni_asso : 2,
ni_ident_type : 4;
uint8_t ni_reserved;
uint8_t ni_ident_length;
#else
uint8_t ni_code_set : 4,
ni_proto_ident : 4;
uint8_t ni_ident_type : 4,
ni_asso : 2,
: 1,
ni_PIV : 1;
uint8_t ni_reserved;
uint8_t ni_ident_length;
#endif
} name_ident_t;
#define TLM_NO_ERRORS 0x00000000
#define TLM_ERROR_BUSY 0x00000001
#define TLM_ERROR_INTERNAL 0x00000002
#define TLM_ERROR_NO_ROBOTS 0x00000003
#define TLM_TIMEOUT 0x00000004
#define TLM_ERROR_RANGE 0x00000005
#define TLM_EMPTY 0x00000006
#define TLM_DRIVE_NOT_ASSIGNED 0x00000007
#define TLM_NO_TAPE_NAME 0x00000008
#define TLM_NO_BACKUP_DIR 0x00000009
#define TLM_NO_BACKUP_HARDWARE 0x0000000a
#define TLM_NO_SOURCE_FILE 0x0000000b
#define TLM_NO_FREE_TAPES 0x0000000c
#define TLM_EOT 0x0000000d
#define TLM_SERIAL_NOT_FOUND 0x0000000e
#define TLM_SMALL_READ 0x0000000f
#define TLM_NO_RESTORE_FILE 0x00000010
#define TLM_EOF 0x00000011
#define TLM_NO_DIRECTORY 0x00000012
#define TLM_NO_MEMORY 0x00000013
#define TLM_WRITE_ERROR 0x00000014
#define TLM_NO_SCRATCH_SPACE 0x00000015
#define TLM_INVALID 0x00000016
#define TLM_MOVE 0x00000017
#define TLM_SKIP 0x00000018
#define TLM_OPEN_ERR 0x00000019
#define TLM_MAX_TAPE_DRIVES 16
#define TLM_NAME_SIZE 100
#define TLM_MAX_TAR_IMAGE 017777777770
#define TLM_VOLNAME_MAX_LENGTH 255
#define NAME_MAX 255
#define TLM_MAGIC "ustar "
#define TLM_SNAPSHOT_PREFIX ".zfs"
#define TLM_SNAPSHOT_DIR ".zfs/snapshot"
#define RECORDSIZE 512
#define NAMSIZ 100
typedef struct tlm_tar_hdr {
char th_name[TLM_NAME_SIZE];
char th_mode[8];
char th_uid[8];
char th_gid[8];
char th_size[12];
char th_mtime[12];
char th_chksum[8];
char th_linkflag;
char th_linkname[TLM_NAME_SIZE];
char th_magic[8];
char th_uname[32];
char th_gname[32];
union {
struct {
char th_devmajor[8];
char th_devminor[8];
} th_dev;
char th_hlink_ino[12];
} th_shared;
} tlm_tar_hdr_t;
/*
* The linkflag defines the type of file
*/
#define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */
#define LF_NORMAL '0' /* Normal disk file */
#define LF_LINK '1' /* Link to previously dumped file */
#define LF_SYMLINK '2' /* Symbolic link */
#define LF_CHR '3' /* Character special file */
#define LF_BLK '4' /* Block special file */
#define LF_DIR '5' /* Directory */
#define LF_FIFO '6' /* FIFO special file */
#define LF_CONTIG '7' /* Contiguous file */
/* Further link types may be defined later. */
#define LF_DUMPDIR 'D'
/*
* This is a dir entry that contains
* the names of files that were in
* the dir at the time the dump
* was made
*/
#define LF_HUMONGUS 'H'
/*
* Identifies the NEXT file on the tape
* as a HUGE file
*/
#define LF_LONGLINK 'K'
/*
* Identifies the NEXT file on the tape
* as having a long linkname
*/
#define LF_LONGNAME 'L'
/*
* Identifies the NEXT file on the tape
* as having a long name.
*/
#define LF_MULTIVOL 'M'
/*
* This is the continuation
* of a file that began on another
* volume
*/
#define LF_VOLHDR 'V' /* This file is a tape/volume header */
/* Ignore it on extraction */
#define LF_ACL 'A' /* Access Control List */
#define LF_XATTR 'E' /* Extended attribute */
#define KILOBYTE 1024
/*
* ACL support structure
*/
typedef struct sec_attr {
char attr_type;
char attr_len[7];
char attr_info[TLM_MAX_ACL_TXT];
} sec_attr_t;
typedef struct tlm_acls {
int acl_checkpointed : 1, /* are checkpoints active ? */
acl_clear_archive : 1, /* clear archive bit ? */
acl_overwrite : 1, /* always overwrite ? */
acl_update : 1, /* only update ? */
acl_non_trivial : 1; /* real ACLs? */
/*
* The following fields are here to allow
* the backup reader to open a file one time
* and keep the information for ACL, ATTRs,
* and reading the file.
*/
sec_attr_t acl_info;
char acl_root_dir[TLM_VOLNAME_MAX_LENGTH]; /* name of root filesystem */
fs_fhandle_t acl_dir_fh; /* parent dir's info */
fs_fhandle_t acl_fil_fh; /* file's info */
struct stat64 acl_attr; /* file system attributes */
char uname[32];
char gname[32];
} tlm_acls_t;
/*
* Tape manager's data archiving ops vector
*
* This vector represents the granular operations for
* performing backup/restore. Each backend should provide
* such a vector interface in order to be invoked by NDMP
* server.
* The reserved callbacks are kept for different backup
* types which are volume-based rather than file-based
* e.g. zfs send.
*/
typedef struct tm_ops {
char *tm_name;
int (*tm_putfile)();
int (*tm_putdir)();
int (*tm_putvol)(); /* Reserved */
void * (*tm_getfile)(void *);
int (*tm_getdir)();
int (*tm_getvol)(); /* Reserved */
} tm_ops_t;
/* The checksum field is filled with this while the checksum is computed. */
#define CHKBLANKS " " /* 8 blanks, no null */
#define LONGNAME_PREFIX "././_LoNg_NaMe_"
extern void ndmp_log(ulong_t, char *, char *, ...);
extern char ndmp_log_info[256];
#define NDMP_LOG(p, ...) { \
(void) snprintf(ndmp_log_info, \
sizeof (ndmp_log_info), \
"[%d][%s:%d]", \
(int)pthread_self(), __func__, __LINE__); \
ndmp_log(p, ndmp_log_info, __VA_ARGS__); \
}
extern void *ndmp_malloc(size_t size);
/*
* ZFS metadata plug-in module structures
*/
#define ZFS_MAX_PROPS 100
#define ZFS_META_MAGIC "ZFSMETA"
#define ZFS_META_MAGIC_EXT "ZFSMETA2"
/* Add new major/minor for header changes */
typedef enum {
META_HDR_MAJOR_0, /* Original format */
META_HDR_MAJOR_1, /* Extended format */
} ndmp_metadata_header_major_t;
#define META_HDR_MAJOR_VERSION META_HDR_MAJOR_1
typedef enum {
META_HDR_MINOR_0,
} ndmp_metadata_header_minor_t;
#define META_HDR_MINOR_VERSION META_HDR_MINOR_0
/* To support older backups */
typedef struct ndmp_metadata_property {
char mp_name[NAME_MAX];
char mp_value[NAME_MAX];
char mp_source[NAME_MAX];
} ndmp_metadata_property_t;
typedef struct ndmp_metadata_property_ext {
char mp_name[ZFS_MAX_DATASET_NAME_LEN];
char mp_value[ZFS_MAXPROPLEN];
char mp_source[ZFS_MAXPROPLEN];
} ndmp_metadata_property_ext_t;
typedef struct ndmp_metadata_top_header {
char th_plname[100];
uint_t th_plversion;
char th_magic[10];
void *th_reserved_1;
int th_count;
} ndmp_metadata_top_header_t;
/* Original metadata format */
typedef struct ndmp_metadata_header {
ndmp_metadata_top_header_t nh_hdr;
char nh_dataset[NAME_MAX];
ndmp_metadata_property_t nh_property[1];
} ndmp_metadata_header_t;
/* Extended metadata format */
typedef struct ndmp_metadata_header_ext {
ndmp_metadata_top_header_t nh_hdr;
char nh_dataset[ZFS_MAX_DATASET_NAME_LEN];
int32_t nh_total_bytes;
int32_t nh_major;
int32_t nh_minor;
ndmp_metadata_property_ext_t nh_property[1];
} ndmp_metadata_header_ext_t;
#define nh_plname nh_hdr.th_plname
#define nh_plversion nh_hdr.th_plversion
#define nh_magic nh_hdr.th_magic
#define nh_count nh_hdr.th_count
typedef struct ndmp_metadata_handle {
void *ml_handle;
int32_t ml_quota_prop;
union {
ndmp_metadata_header_t *u_hdr;
ndmp_metadata_header_ext_t *u_xhdr;
} ml_hdr_u;
} ndmp_metadata_handle_t;
#define ml_hdr ml_hdr_u.u_hdr
#define ml_xhdr ml_hdr_u.u_xhdr
/*
* Node in struct hardlink_q
*
* inode: the inode of the hardlink
* path: the name of the hardlink, used during restore
* offset: tape offset of the data records for the hardlink, used during backup
* is_tmp: indicate whether the file was created temporarily for restoring
* other links during a non-DAR partial restore
*/
struct hardlink_node {
unsigned long inode;
char *path;
unsigned long long offset;
int is_tmp;
SLIST_ENTRY(hardlink_node) next_hardlink;
};
/*
* Hardlinks that have been backed up or restored.
*
* During backup, each node represents a file whose
* (1) inode has multiple links
* (2) data has been backed up
*
* When we run into a file with multiple links during backup,
* we first check the list to see whether a file with the same inode
* has been backed up. If yes, we backup an empty record, while
* making the file history of this file contain the data offset
* of the offset of the file that has been backed up. If no,
* we backup this file, and add an entry to the list.
*
* During restore, each node represents an LF_LINK type record whose
* data has been restored (v.s. a hard link has been created).
*
* During restore, when we run into a record of LF_LINK type, we
* first check the queue to see whether a file with the same inode
* has been restored. If yes, we create a hardlink to it.
* If no, we restore the data, and add an entry to the list.
*/
struct hardlink_q {
struct hardlink_node *slh_first;
};
/* Utility functions from handling hardlink */
extern struct hardlink_q *hardlink_q_init();
extern void hardlink_q_cleanup(struct hardlink_q *qhead);
extern int hardlink_q_get(struct hardlink_q *qhead, unsigned long inode,
unsigned long long *offset, char **path);
extern int hardlink_q_add(struct hardlink_q *qhead, unsigned long inode,
unsigned long long offset, char *path, int is_tmp);
#endif /* !_TLM_H_ */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This defines structures used to pass information between threads
* for both local-backup and NDMP.
*
*/
#ifndef _TLM_BUFFERS_H_
#define _TLM_BUFFERS_H_
#include <sys/types.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/stat.h>
#include <thread.h>
#include "tlm.h"
#ifndef RECORDSIZE
#define RECORDSIZE 512
#endif /* !RECORDSIZE */
#define DOTDOT_DIR ".."
#define IS_DOTDOT(s) (strcmp(s, DOTDOT_DIR) == 0)
#define SLASH '/'
#define NDMP_MAX_SELECTIONS 64
/*
* List of files/directories to be excluded from backup list.
*/
#define EXCL_PROC "/proc"
#define EXCL_TMP "/tmp"
typedef struct tlm_buffer {
char *tb_buffer_data; /* area to be used for I/O */
long tb_buffer_size; /* number of valid bytes in the buffer */
long tb_buffer_spot; /* current location in the I/O buffer */
longlong_t tb_seek_spot; /* for BACKUP */
/* where in the file this buffer stops. */
/* this is used for the Multi Volume */
/* Header record. */
longlong_t tb_file_size; /* for BACKUP */
/* how much of the file is left. */
long tb_full : 1,
tb_eot : 1,
tb_eof : 1;
int tb_errno; /* I/O error values */
} tlm_buffer_t;
/*
* Flags for tlm_buffers.
*/
#define TLM_BUF_IN_READY 0x00000001
#define TLM_BUF_OUT_READY 0x00000002
typedef struct tlm_buffers {
int tbs_ref; /* number of threads using this */
short tbs_buffer_in; /* buffer to be filled */
short tbs_buffer_out; /* buffer to be emptied */
/* these are indexes into tlm_buffers */
mutex_t tbs_mtx;
cond_t tbs_in_cv;
cond_t tbs_out_cv;
uint32_t tbs_flags;
long tbs_data_transfer_size; /* max size of read/write buffer */
longlong_t tbs_offset;
tlm_buffer_t tbs_buffer[TLM_TAPE_BUFFERS];
} tlm_buffers_t;
typedef struct tlm_cmd {
int tc_ref; /* number of threads using this */
mutex_t tc_mtx;
cond_t tc_cv;
uint32_t tc_flags;
int tc_reader; /* writer to reader */
int tc_writer; /* reader to writer */
char tc_file_name[TLM_MAX_PATH_NAME]; /* name of last file */
/* for restore */
tlm_buffers_t *tc_buffers; /* reader-writer speedup buffers */
} tlm_cmd_t;
typedef struct tlm_commands {
int tcs_reader; /* commands to all readers */
int tcs_writer; /* commands to all writers */
int tcs_reader_count; /* number of active readers */
int tcs_writer_count; /* number of active writers */
int tcs_error; /* worker errors */
char tcs_message[TLM_LINE_SIZE]; /* worker message back to user */
tlm_cmd_t *tcs_command; /* IPC area between read-write */
} tlm_commands_t;
typedef struct tlm_job_stats {
char js_job_name[TLM_MAX_BACKUP_JOB_NAME];
longlong_t js_bytes_total; /* tape bytes in or out so far */
longlong_t js_bytes_in_file; /* remaining data in a file */
longlong_t js_files_so_far; /* files backed up so far */
longlong_t js_files_total; /* number of files to be backed up */
int js_errors;
time_t js_start_time; /* start time (GMT time) */
time_t js_start_ltime; /* start time (local time) */
time_t js_stop_time; /* stop time (local time) */
time_t js_chkpnt_time; /* checkpoint creation (GMT time) */
void *js_callbacks;
} tlm_job_stats_t;
struct full_dir_info {
fs_fhandle_t fd_dir_fh;
char fd_dir_name[TLM_MAX_PATH_NAME];
};
/*
* For more info please refer to
* "Functional Specification Document: Usgin new LBR engine in NDMP",
* Revision: 0.2
* Document No.: 101438.
* the "File history of backup" section
*/
typedef struct lbr_fhlog_call_backs {
void *fh_cookie;
int (*fh_logpname)();
int (*fh_log_dir)();
int (*fh_log_node)();
} lbr_fhlog_call_backs_t;
typedef struct bk_selector {
void *bs_cookie;
int bs_level;
int bs_ldate;
boolean_t (*bs_fn)(struct bk_selector *bks, struct stat64 *s);
} bk_selector_t;
/*
* Call back structure to create new name for objects at restore time.
*/
struct rs_name_maker;
typedef char *(*rsm_fp_t)(struct rs_name_maker *,
char *buf,
int pos,
char *path);
struct rs_name_maker {
rsm_fp_t rn_fp;
void *rn_nlp;
};
/*
* RSFLG_OVR_*: overwriting policies. Refer to LBR FSD for more info.
* RSFLG_MATCH_WCARD: should wildcards be supported in the selection list.
* RSFLG_IGNORE_CASE: should the compare be case-insensetive. NDMP needs
* case-sensetive name comparison.
*/
#define RSFLG_OVR_ALWAYS 0x00000001
#define RSFLG_OVR_NEVER 0x00000002
#define RSFLG_OVR_UPDATE 0x00000004
#define RSFLG_MATCH_WCARD 0x00000008
#define RSFLG_IGNORE_CASE 0x00000010
/*
* Different cases where two paths can match with each other.
* Parent means that the current path, is parent of an entry in
* the selection list.
* Child means that the current path, is child of an entry in the
* selection list.
*/
#define PM_NONE 0
#define PM_EXACT 1
#define PM_PARENT 2
#define PM_CHILD 3
extern tlm_job_stats_t *tlm_new_job_stats(char *);
extern tlm_job_stats_t *tlm_ref_job_stats(char *);
extern void tlm_un_ref_job_stats(char *);
extern boolean_t tlm_is_excluded(char *, char *, char **);
extern char *tlm_build_snapshot_name(char *, char *, char *);
extern char *tlm_remove_checkpoint(char *, char *);
extern tlm_buffers_t *tlm_allocate_buffers(boolean_t, long);
extern tlm_buffer_t *tlm_buffer_advance_in_idx(tlm_buffers_t *);
extern tlm_buffer_t *tlm_buffer_advance_out_idx(tlm_buffers_t *);
extern tlm_buffer_t *tlm_buffer_in_buf(tlm_buffers_t *, int *);
extern tlm_buffer_t *tlm_buffer_out_buf(tlm_buffers_t *, int *);
extern void tlm_buffer_mark_empty(tlm_buffer_t *);
extern void tlm_buffer_release_in_buf(tlm_buffers_t *);
extern void tlm_buffer_release_out_buf(tlm_buffers_t *);
extern void tlm_buffer_in_buf_wait(tlm_buffers_t *);
extern void tlm_buffer_out_buf_wait(tlm_buffers_t *);
extern void tlm_buffer_in_buf_timed_wait(tlm_buffers_t *, unsigned);
extern void tlm_buffer_out_buf_timed_wait(tlm_buffers_t *, unsigned);
extern char *tlm_get_write_buffer(long, long *, tlm_buffers_t *, int);
extern char *tlm_get_read_buffer(int, int *, tlm_buffers_t *, int *);
extern void tlm_unget_read_buffer(tlm_buffers_t *, int);
extern void tlm_unget_write_buffer(tlm_buffers_t *, int);
extern void tlm_release_buffers(tlm_buffers_t *);
extern tlm_cmd_t *tlm_create_reader_writer_ipc(boolean_t, long);
extern void tlm_release_reader_writer_ipc(tlm_cmd_t *);
extern void tlm_cmd_wait(tlm_cmd_t *, uint32_t);
extern void tlm_cmd_signal(tlm_cmd_t *, uint32_t);
typedef int (*path_hist_func_t)(lbr_fhlog_call_backs_t *,
char *,
struct stat64 *,
u_longlong_t);
typedef int (*dir_hist_func_t)(lbr_fhlog_call_backs_t *,
char *,
struct stat64 *);
typedef int (*node_hist_func_t)(lbr_fhlog_call_backs_t *,
char *,
char *,
struct stat64 *,
u_longlong_t);
lbr_fhlog_call_backs_t *lbrlog_callbacks_init(void *,
path_hist_func_t,
dir_hist_func_t,
node_hist_func_t);
typedef struct {
tlm_commands_t *ba_commands;
tlm_cmd_t *ba_cmd;
char *ba_job;
char *ba_dir;
char *ba_sels[NDMP_MAX_SELECTIONS];
pthread_barrier_t ba_barrier;
} tlm_backup_restore_arg_t;
extern void lbrlog_callbacks_done(lbr_fhlog_call_backs_t *);
extern boolean_t tlm_cat_path(char *, char *, char *);
extern char *trim_name(char *);
extern struct full_dir_info *dup_dir_info(struct full_dir_info *);
extern void write_tar_eof(tlm_cmd_t *);
extern int tlm_get_chkpnt_time(char *, int, time_t *, char *);
extern struct full_dir_info *tlm_new_dir_info(fs_fhandle_t *,
char *,
char *);
extern void tlm_release_list(char **);
extern longlong_t tlm_get_data_offset(tlm_cmd_t *);
extern int tlm_tarhdr_size(void);
#endif /* _TLM_BUFFERS_H_ */
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This file defines macros and constants related to traversing file
* system hieratchy in post-order, pre-order and level-order ways.
*/
#ifndef _TRAVERSE_H_
#define _TRAVERSE_H_
#ifdef __cplusplus
extern "C" {
#endif
/*
* Library functions for traversing file system hierarchy in
* post-order, pre-order and level-order.
*
* This example will be used in the following descriptions.
* All alphabetical entries are directory and all the numerical
* entries are non-directory entries.
*
* AAA
* AAA/BBB
* AAA/BBB/1
* AAA/BBB/2
* AAA/BBB/3
* AAA/CCC
* AAA/CCC/EEE
* AAA/CCC/EEE/4
* AAA/CCC/EEE/5
* AAA/CCC/EEE/6
* AAA/CCC/EEE/7
* AAA/CCC/EEE/8
* AAA/CCC/9
* AAA/XXX
* AAA/ZZZ
* AAA/10
* AAA/11
* AAA/12
* AAA/13
*
* Each traversing function gets an argument of 'struct fs_traverse *'
* type. The fields of this structure are explained below.
*
* For each entry while traversing, the callback function is
* called and three arguments are passed to it. The argument
* specified in the struct fs_traverse, a struct fst_node for the
* path and a struct fst_node for the entry.
*
* For the root of the traversing, the fields of struct fst_node
* of the entry are all NULL.
*
* If the path to be traversed is not a directory, the callback
* function is called on it. The fields of the 'struct fst_node'
* argument for entry are all NULL.
*
*
* POST-ORDER:
* Post-order means that the directory is processed after all
* its children are processed. Post-order traversing of the above
* hierarchy will be like this:
*
* AAA/BBB, 1
* AAA/BBB, 2
* AAA/BBB, 3
* AAA, BBB
* AAA/CCC/EEE, 6
* AAA/CCC/EEE, 5
* AAA/CCC/EEE, 8
* AAA/CCC/EEE, 4
* AAA/CCC/EEE, 7
* AAA/CCC, EEE
* AAA/CCC, 9
* AAA, CCC
* AAA, XXX
* AAA, ZZZ
* AAA, 10
* AAA, 11
* AAA, 12
* AAA, 13
* AAA
*
* In post-order the callback function returns 0 on success
* or non-zero to stop further traversing the hierarchy.
*
* One of the applications of post-order traversing of a
* hierarchy can be deleting the hierarchy from the file system.
*
*
* PRE-ORDER:
* Pre-order means that the directory is processed before
* any of its children are processed. Pre-order traversing of
* the above hierarchy will be like this:
*
* AAA
* AAA, BBB
* AAA/BBB, 1
* AAA/BBB, 2
* AAA/BBB, 3
* AAA, CCC
* AAA/CCC, EEE
* AAA/CCC/EEE, 6
* AAA/CCC/EEE, 5
* AAA/CCC/EEE, 8
* AAA/CCC/EEE, 4
* AAA/CCC/EEE, 7
* AAA/CCC, 9
* AAA, XXX
* AAA, ZZZ
* AAA, 10
* AAA, 11
* AAA, 12
* AAA, 13
*
* In pre-order, the callback function can return 3 values:
* 0: means that the traversing should continue.
*
* < 0: means that the traversing should be stopped immediately.
*
* FST_SKIP: means that no further entries of this directory
* should be processed. Traversing continues with the
* next directory of the same level. For example, if
* callback returns FST_SKIP on AAA/BBB, the callback
* will not be called on 1, 2, 3 and traversing will
* continue with AAA/CCC.
*
*
* LEVEL-ORDER:
* This is a special case of pre-order. In this method,
* all the non-directory entries of a directory are processed
* and then come the directory entries. Level-order traversing
* of the above hierarchy will be like this:
*
* AAA
* AAA, 10
* AAA, 11
* AAA, 12
* AAA, 13
* AAA, BBB
* AAA/BBB, 1
* AAA/BBB, 2
* AAA/BBB, 3
* AAA, CCC
* AAA/CCC, 9
* AAA/CCC, EEE
* AAA/CCC/EEE, 6
* AAA/CCC/EEE, 5
* AAA/CCC/EEE, 8
* AAA/CCC/EEE, 4
* AAA/CCC/EEE, 7
* AAA, XXX
* AAA, ZZZ
*
* The rules of pre-order for the return value of callback
* function applies for level-order.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include "tlm.h"
/*
* To prune a directory when traversing it, this return
* value should be returned by the callback function in
* level-order and pre-order traversing.
*
* In level-order processing, this return value stops
* reading the rest of the directory and calling the callback
* function for them. Traversing will continue with the next
* directory of the same level. The children of the current
* directory will be pruned too. For example on this ,
*
*/
#define FST_SKIP 1
#define SKIP_ENTRY 2
/*
* Directives for traversing file system.
*
* FST_STOP_ONERR: Stop travergins when stat fails on an entry.
* FST_STOP_ONLONG: Stop on detecting long path.
* FST_VERBOSE: Verbose running.
*/
#define FST_STOP_ONERR 0x00000001
#define FST_STOP_ONLONG 0x00000002
#define FST_VERBOSE 0x80000000
typedef void (*ft_log_t)();
/*
* The arguments of traversing file system contains:
* path: The physical path to be traversed.
*
* lpath The logical path to be passed to the callback
* function as path.
* If this is set to NULL, the default value will be
* the 'path'.
*
* For example, traversing '/v1.chkpnt/backup/home' as
* physical path can have a logical path of '/v1/home'.
*
* flags Show how the traversing should be done.
* Values of this field are of FST_ constants.
*
* callbk The callback function pointer. The callback
* function is called like this:
* (*ft_callbk)(
* void *ft_arg,
* struct fst_node *path,
* struct fst_node *entry)
*
* arg The 'void *' argument to be passed to the call
* back function.
*
* logfp The log function pointer. This function
* is called to log the messages.
* Default is logf().
*/
typedef struct fs_traverse {
char *ft_path;
char *ft_lpath;
unsigned int ft_flags;
int (*ft_callbk)();
void *ft_arg;
ft_log_t ft_logfp;
} fs_traverse_t;
/*
* Traversing Nodes. For each path and node upon entry this
* structure is passed to the callback function.
*/
typedef struct fst_node {
char *tn_path;
fs_fhandle_t *tn_fh;
struct stat64 *tn_st;
} fst_node_t;
extern int traverse_post(fs_traverse_t *);
extern int traverse_pre(fs_traverse_t *);
extern int traverse_level(fs_traverse_t *);
#undef getdents
extern int getdents(int, struct dirent *, size_t);
#ifdef __cplusplus
}
#endif
#endif /* _TRAVERSE_H_ */
|