File: common.c

package info (click to toggle)
evms 2.5.2-1.sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 14,248 kB
  • ctags: 15,488
  • sloc: ansic: 201,340; perl: 12,421; sh: 4,262; makefile: 1,516; yacc: 316; sed: 16
file content (2978 lines) | stat: -rw-r--r-- 73,565 bytes parent folder | download
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
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
/*
 *
 *   (C) Copyright IBM Corp. 2001, 2003
 *
 *   This program is free software;  you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 *   the GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program;  if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Module: common.c
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

#include "fullengine.h"
#include "common.h"
#include "lists.h"
#include "engine.h"
#include "discover.h"
#include "handlemgr.h"
#include "volume.h"
#include "memman.h"
#include "internalAPI.h"
#include "message.h"
#include "cluster.h"
#include "remote.h"


boolean is_top_object(storage_object_t * obj) {

	boolean result = FALSE;

	LOG_PROC_ENTRY();

	LOG_DEBUG("Examining object %s.\n", obj->name);

	/* The object must not be part of a volume. */
	if (obj->volume == NULL) {

		/* The object must not be part of a container. */
		if (obj->consuming_container == NULL) {

			/* The object must have no parent objects. */
			if (list_empty(obj->parent_objects)) {
				result = TRUE;

			} else {
				LOG_DEBUG("Object %s has parent object(s).\n", obj->name);
			}

		} else {
			LOG_DEBUG("Object %s is part of container %s.\n", obj->name, obj->consuming_container->name);
		}

	} else {
		LOG_DEBUG("Object %s is part of volume %s.\n", obj->name, obj->volume->name);
	}

	LOG_PROC_EXIT_BOOLEAN(result);
	return result;
}


int evms_can_delete(object_handle_t thing) {
	int rc = 0;
	void * object;
	object_type_t type;

	LOG_PROC_ENTRY();

	rc = check_engine_write_access();
	if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_can_delete(thing);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	rc = translate_handle(thing,
			      &object,
			      &type);

	if (rc == HANDLE_MANAGER_NO_ERROR) {
		switch (type) {
		case VOLUME:
			{
				logical_volume_t * volume = (logical_volume_t *) object;

				if (volume->flags & VOLFLAG_COMPATIBILITY) {
					if (is_kernel_volume_mounted(volume, DETAILS)) {
						rc = EBUSY;
                                        }
				}
				
				if (rc == 0) {
					/* Check if the volume is opened. */
					if (!is_volume_opened(volume)) {

						if ((volume->file_system_manager != NULL) &&
						    !(volume->flags & VOLFLAG_UNMKFS)) {
							rc = volume->file_system_manager->functions.fsim->can_unmkfs(volume);

							if (rc != 0) {
								LOG_DETAILS("Volume %s cannot be deleted because the file system %s cannot be removed.  Reason code is %d.\n", volume->name, volume->file_system_manager->short_name, rc);
							}
						}

						if (rc == 0) {
							rc = volume->object->plugin->functions.plugin->can_set_volume(volume->object, FALSE);
						}

					} else {
						LOG_DETAILS("Volume %s cannot be deleted because it is opened.\n", volume->name);
						if (volume->mount_point) {
							LOG_DETAILS("Volume %s is mounted on %s.\n", volume->name, volume->mount_point);
						}
						rc = EBUSY;
					}
				}
			}
			break;

		case CONTAINER:
			{
				storage_container_t * container = (storage_container_t *) object;

				rc = container->plugin->container_functions->can_delete_container(container);
			}
			break;

		case EVMS_OBJECT:
		case REGION:
		case SEGMENT:
		case DISK:
			{
				storage_object_t * storage_object = (storage_object_t *) object;

				/*
				 * Make sure the object is a top level object.  We
				 * can't delete objects in the middle of a feature
				 * stack.  A top level object has no parent.
				 */
				if (is_top_object(storage_object)) {

					/*
					 * Ask the feature if the object can be
					 * deleted.
					 */
					rc = storage_object->plugin->functions.plugin->can_delete(storage_object);

				} else {
					/* The object is not a top level object. */
					LOG_DETAILS("Object %s cannot be deleted because it is not a top level object.\n", storage_object->name);
					rc = EINVAL;
				}
			}
			break;

		default:
			/* We can't delete a thing of this type. */
			LOG_DETAILS("A thing of type %#x cannot be deleted.\n", type);
			rc = EINVAL;
			break;
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int can_destroy_object(storage_object_t * obj) {

	int rc = 0;

	LOG_PROC_ENTRY();

	/* Disks cannot be destroyed, they must be deleted.  Return 0 if this is a
	 * DISK so that the can_destroy_object() will not fail if this is a DISK.
	 * The disk will not be destroyed on a evms_destroy(), but anything stacked
	 * on top of the disk will.
	 */

	if (obj->object_type != DISK) {
		rc = obj->plugin->functions.plugin->can_delete(obj);

		if (rc == 0) {
			/*
			 * If the object is not produced by a container
			 * do a recursive check to see if all
			 * of its children can be deleted.
			 */
			if (obj->producing_container == NULL) {
				list_element_t iter;
				storage_object_t * child;

				LIST_FOR_EACH(obj->child_objects, iter, child) {
					rc = can_destroy_object(child);
					if (rc != 0) {
						break;
					}
				}
			}
		}
	}

	/* If the object is a DISK, we return 0 so that the recursive check doesn't
	 * fail and the recursion ends.
	 * can_destroy_object() might be called initially on a DISK (e.g., an EVMS
	 * volume is made from a DISK and the volume is being destroyed).  In that
	 * case, can_destroy_object() will return 0, but a subsequent call to
	 * evms_destroy() will destroy the volume but leave the disk.
	 */

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


int evms_can_destroy(object_handle_t thing) {

	int rc;
	void * object;
	object_type_t type;

	LOG_PROC_ENTRY();

	rc = check_engine_write_access();
	if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_can_destroy(thing);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	rc = translate_handle(thing,
			      &object,
			      &type);

	if (rc == HANDLE_MANAGER_NO_ERROR) {
		switch (type) {
			case VOLUME:
				{
					logical_volume_t * volume = (logical_volume_t *) object;

					if (volume->flags & VOLFLAG_COMPATIBILITY) {
						if (is_kernel_volume_mounted(volume, DETAILS)) {
							rc = EBUSY;
						}
					}
					
					if (rc == 0) {
						/* Check if the volume is opened. */
						if (!is_volume_opened(volume)) {

							if ((volume->file_system_manager != NULL) &&
							    !(volume->flags & VOLFLAG_UNMKFS)) {
								rc = volume->file_system_manager->functions.fsim->can_unmkfs(volume);

								if (rc != 0) {
									LOG_DETAILS("Volume %s cannot be destroyed because the file system %s cannot be removed.  Reason code is %d.\n", volume->name, volume->file_system_manager->short_name, rc);
								}
							}

							if (rc == 0) {
								rc = can_destroy_object(volume->object);
							}

						} else {
							LOG_DETAILS("Volume %s cannot be destroyed because it is opened.\n", volume->name);
							if (volume->mount_point != NULL) {
								LOG_DETAILS("Volume %s is mounted on %s.\n", volume->name, volume->mount_point);
							}
							rc = EBUSY;
						}
					}
				}
				break;

			case CONTAINER:
				{
					storage_container_t * container = (storage_container_t *) object;
					list_element_t iter;
					storage_object_t * obj;

					rc = container->plugin->container_functions->can_delete_container(container);

					if (rc == 0) {
						LIST_FOR_EACH(container->objects_consumed, iter, obj) {
							rc = can_destroy_object(obj);
							if (rc != 0) {
								break;
							}
						}
					}
				}
				break;

			case EVMS_OBJECT:
			case REGION:
			case SEGMENT:
				{
					storage_object_t * obj = object;

					if (is_top_object(obj)) {

						rc = can_destroy_object(obj);

					} else {
						LOG_DETAILS("Object %s cannot be destroyed because it is not a top level object.\n", obj->name);
						rc = EINVAL;
					}
				}
				break;

			case DISK:
				{
					storage_object_t * obj = object;

					LOG_DETAILS("Disk %s cannot be destroyed because disks cannot be destroyed.  Disks must be deleted.\n", obj->name);
					rc = EINVAL;
				}
				break;

			default:
				rc = EINVAL;
				break;
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int find_top_objects(storage_object_t * obj,
			    list_anchor_t      top_object_list) {

	int rc = 0;

	if (list_empty(obj->parent_objects)) {
		list_element_t el;

		el = insert_thing(top_object_list,
				  obj,
				  INSERT_AFTER,
				  NULL);

		if (el == NULL) {
			LOG_CRITICAL("Error inserting object %s into the top object list.\n", obj->name);
			rc = ENOMEM;
		}

	} else {
		list_element_t iter;
		storage_object_t * parent;

		LIST_FOR_EACH(obj->parent_objects, iter, parent) {
			rc = find_top_objects(parent, top_object_list);

			if (rc != 0) {
				break;
			}
		}
	}

	return rc;
}


static int can_replace(object_handle_t source_handle,
		       object_handle_t target_handle,
		       debug_level_t   log_level) {

	int rc = 0;
	int src_rc = 0;
	int trg_rc = 0;
	object_type_t type;
	void  * thing = NULL;
	list_anchor_t top_objects = NULL;
	storage_object_t * source = NULL;
	storage_object_t * target = NULL;

	LOG_PROC_ENTRY();

	/* Check for valid source and target. */
	src_rc = translate_handle(source_handle, &thing, &type);
	if (src_rc == HANDLE_MANAGER_NO_ERROR) {
		switch (type) {
		case DISK:
		case SEGMENT:
		case REGION:
		case EVMS_OBJECT:
			source = (storage_object_t *) thing;
			break;

		case CONTAINER:
			LOG(log_level, "Containers cannot be replaced.\n");
			src_rc = EINVAL;
			break;

		case VOLUME:
			LOG(log_level, "Volumes cannot be replaced.\n");
			src_rc = EINVAL;
			break;

		case PLUGIN:
			LOG(log_level, "Plug-ins cannot be replaced.\n");
			src_rc = EINVAL;
			break;

		default:
			LOG(log_level, "Source handle %d maps to an unknown thing of type %#x.\n", source_handle, type);
			src_rc = EINVAL;
		}
	}

	if (src_rc == 0) {
		int tmp_rc;
		logical_volume_t * vol;

		LOG_DEBUG("Can object %s be replaced?\n", source->name);

		/*
		 * Top objects cannot be replaced.  What is the use of replacing
		 * an object that is not in use with another object that is not
		 * in use?  This also prevents the use of any target objects
		 * created by plug-ins for their own internal moves as the target
		 * will be a top level object.
		 */
		if (is_top_object(source)) {
			LOG(log_level, "Object %s is a top level object.  Top level objects cannot be replaced.\n",
				       source->name);
			src_rc = EINVAL;
		}

		/*
		 * Is the object a volume's object?  Certain rules apply to
		 * volume objects.
		 */
		if (list_empty(source->parent_objects) && (source->volume != NULL)) {
			if (source->volume->flags & VOLFLAG_COMPATIBILITY) {
				LOG(log_level, "%s is the object for compatiblity volume %s.  Compatibility volume objects cannot be replaced.\n",
					       source->name, source->volume->name);
				src_rc = EINVAL;

			} else {
				/* It's an EVMS volume.
				 * A "raw" EVMS volume (one made on top of a
				 * nonEVMS object) has its own device-mapper
				 * mapping.  The volume can have its object
				 * replaced since we can change the mapping of
				 * the volume.
				 * A non-raw EVMS volume simply uses the
				 * device-mapper device of the EVMS object.
				 * Non-raw EVSM volumes can only be replaced if
				 * the volume is not mounted, since the
				 * major:minor of the volume will change due to
				 * it using a differnt object.
				 */
				if (source->object_type == EVMS_OBJECT) {
					if (is_volume_mounted(source->volume)) {
						LOG(log_level, "%s is the object for volume %s.  The object can only be replaced if the volume is not mounted.\n",
							       source->name, source->volume->name);
						src_rc = EBUSY;
					}
				}
			}
		}

		/* Can't move non-data objects. */
		if (source->data_type != DATA_TYPE) {
			LOG(log_level, "Object %s is not a data object.  Only data objects can be replaced.\n",
				       source->name);
			src_rc = EINVAL;
		}

		/* Can't move "must-be-top" objects (e.g. snapshots and snap-origins). */
		if (source->flags & SOFLAG_MUST_BE_TOP) {
			LOG(log_level, "Object %s must be a top object - cannot be replaced.\n",
			    source->name);
			src_rc = EINVAL;
		}

		if (!engine_can_online_copy()) {
			if (!engine_is_offline(source, &vol)) {
				LOG(log_level, "Object %s is part of volume %s which is currently opened.  Replace must be done off-line.\n",
					       source->name, vol->name);
				src_rc = EINVAL;
			}
		}

		/* Can't replace if there are no available targets. */
		tmp_rc = engine_get_object_list(0, DATA_TYPE, NULL, NULL, VALID_INPUT_OBJECT, &top_objects);
		if (tmp_rc == 0) {
			if (list_empty(top_objects)) {
				LOG(log_level, "There are no available target objects for the replace.\n");
				src_rc = EINVAL;
			}

			destroy_list(top_objects);

		} else {
			src_rc = tmp_rc;
		}
	}

	if (target_handle != 0) {
		trg_rc = translate_handle(target_handle, &thing, &type);
		if (trg_rc == HANDLE_MANAGER_NO_ERROR) {
			switch (type) {
			case DISK:
			case SEGMENT:
			case REGION:
			case EVMS_OBJECT:
				target = (storage_object_t *) thing;
				if (!is_top_object(target)) {
					LOG_DEBUG("Target %s is not a top level object.\n", target->name);
					trg_rc = EINVAL;
				}
				break;

			case CONTAINER:
				LOG(log_level, "Containers cannot be the target of a replace.\n");
				trg_rc = EINVAL;
				break;

			case VOLUME:
				LOG(log_level, "Volumes cannot be the target of a replace.\n");
				trg_rc = EINVAL;
				break;

			case PLUGIN:
				LOG(log_level, "Plug-ins cannot be the target of a replace.\n");
				trg_rc = EINVAL;
				break;

			default:
				LOG(log_level, "Target handle %d maps to an unknown thing of type %#x.\n",
					       target_handle, type);
				trg_rc = EINVAL;
			}

			if (trg_rc == 0) {
				/* Can't move to non-data objects. */
				if (target->data_type != DATA_TYPE) {
					LOG(log_level, "Object %s is not a data object.  Only data objects can be the target of a replace.\n",
						       target->name);
					trg_rc = EINVAL;
				}

			}
		}
	}

	rc = (src_rc != 0) ? src_rc : trg_rc;

	if ((rc == 0) && (target != NULL)) {

		LOG_DEBUG("Can object %s be replaced with object %s?\n", source->name, target->name);

		/* An object cannot replace itself. */
		if (source == target) {
			LOG(log_level, "Object %s cannot replace itself.\n", source->name);
			rc = EINVAL;

		} else {
			/* The source and target must be in the same disk group. */
			if (source->disk_group == target->disk_group) {

				/*
				 * The source object cannot be one of the
				 * objects that comprises the target object.
				 */
				STATIC_LIST_DECL(top_objects);
				list_element_t iter;
				storage_object_t * obj;

				LIST_FOR_EACH(source->parent_objects, iter, obj) {
					rc = find_top_objects(obj, &top_objects);

					if (rc != 0) {
						break;
					}
				}

				if (rc == 0) {
					LIST_FOR_EACH(&top_objects, iter, obj) {
						if (obj == target) {
							LOG(log_level, "Target object %s comprises source object %s.\n",
								       target->name, source->name);
							rc = EINVAL;
							break;
						}
					}
				}

				if (list_empty(source->parent_objects)) {
					if ((source->object_type == EVMS_OBJECT) &&
					    (target->object_type != EVMS_OBJECT)) {
						if (target->size < source->size + EVMS_FEATURE_HEADER_SECTORS * 2) {
							LOG(log_level, "Target %s is smaller than source %s.\n",
								       target->name, source->name);
							rc = EINVAL;
						}
					} else {
						if (target->size < source->size) {
							LOG(log_level, "Target %s is smaller than source %s.\n",
								       target->name, source->name);
							rc = EINVAL;
						}
					}

					/*
					 * We can't do an online move of a raw
					 * EVMS volume object to an EVMS object
					 * because that would cause the volume's
					 * major:minor to change to use that of
					 * the EVMS object instead of the
					 * mapping used to make the raw EVMS
					 * volume.  Swapping of a major:minor
					 * can't be done while the volume is
					 * mounted.
					 */
					if ((source->volume != NULL) &&
					    is_volume_mounted(source->volume) &&
					    (source->object_type != EVMS_OBJECT) &&
					    (target->object_type == EVMS_OBJECT)) {
						LOG(log_level, "non-EVMS object %s cannot be replaced with EVMS object %s while volume %s is mounted.\n",
							       source->name, target->name, source->volume->name);
						rc = EBUSY;
					}
				}

			} else {
				LOG(log_level, "Source %s and target %s are not in the same disk group.\n",
					       source->name, target->name);
				LOG(log_level, "%s is in disk group %s.\n", source->name,
					       (source->disk_group == NULL) ? "(local)" : source->disk_group->name);
				LOG(log_level, "%s is in disk group %s.\n", target->name,
					       (target->disk_group == NULL) ? "(local)" : target->disk_group->name);
				rc = EINVAL;
			}
		}
	}

	if (rc == 0) {
		if (!list_empty(source->parent_objects)) {
			storage_object_t * parent;

			/*
			 * Ask the parent if it can replace its child.  Any
			 * parent will do.  If there are multiple, parents they
			 * should all be managed by the same plug-in.
			 */
			parent = first_thing(source->parent_objects, NULL);
			rc = parent->plugin->functions.plugin->can_replace_child(parent, source, target);
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


int evms_can_replace(object_handle_t source_handle, object_handle_t target_handle) {

	int rc = 0;

	LOG_PROC_ENTRY();

	rc = check_engine_write_access();
	if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_can_replace(source_handle, target_handle);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (replace_plugin == NULL) {
		LOG_PROC_EXIT_INT(ENOSYS);
		return ENOSYS;
	}

	rc = can_replace(source_handle, target_handle, DETAILS);

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


/*
 * evms_can_set_info will determine if a thing's information can be set.
 */
int evms_can_set_info(object_handle_t thing_handle) {

	int rc = 0;
	object_type_t type;
	void  * thing = NULL;
	task_handle_t task_handle;

	LOG_PROC_ENTRY();

	rc = check_engine_write_access();
	if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_can_set_info(thing_handle);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	rc = translate_handle(thing_handle, &thing, &type);

	if (rc == HANDLE_MANAGER_NO_ERROR) {

		/*
		 * Check if the plug-in supports setting of object information
		 * by getting the option count for EVMS_Task_Set_Info.  If the
		 * option count is 0 or less, then the plug-in does not support
		 * the setting of object information.
		 */
		switch (type) {
			case DISK:
			case SEGMENT:
			case REGION:
			case EVMS_OBJECT:
				rc = evms_create_task(thing_handle, EVMS_Task_Set_Info, &task_handle);
				if (rc == 0) {
					evms_destroy_task(task_handle);
				}
				break;

			case CONTAINER:
				rc = evms_create_task(thing_handle, EVMS_Task_Set_Container_Info, &task_handle);
				if (rc == 0) {
					evms_destroy_task(task_handle);
				}
				break;

			case VOLUME:
				{
					logical_volume_t * vol = (logical_volume_t *) thing;

					if (vol->flags & VOLFLAG_COMPATIBILITY) {
						if (is_kernel_volume_mounted(vol, DETAILS)) {
							rc = EBUSY;
						}
					}

					if (rc == 0) {
						if (vol->file_system_manager != NULL) {
							rc = evms_create_task(thing_handle,EVMS_Task_Set_Info,&task_handle);
							if (rc == 0) {
								evms_destroy_task(task_handle);
							}

						} else {
							LOG_DETAILS("Volume %s does not have a file system interface module.\n", vol->name);
							rc = ENOSYS;
						}
					}
				}
				break;

			default:
				LOG_ERROR("Cannot set info on a thing of type %#x.\n", type);
				rc = EINVAL;
				break;
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static inline int get_plugin_extended_info(plugin_record_t         * plugin,
					   char                    * descriptor_name,
					   extended_info_array_t * * info) {
	int rc = 0;

	LOG_PROC_ENTRY();

	switch (GetPluginType(plugin->id)) {
	case EVMS_DEVICE_MANAGER:
	case EVMS_SEGMENT_MANAGER:
	case EVMS_REGION_MANAGER:
	case EVMS_FEATURE:
	case EVMS_ASSOCIATIVE_FEATURE:

		rc = plugin->functions.plugin->get_plugin_info(descriptor_name, info);
		break;

	case EVMS_FILESYSTEM_INTERFACE_MODULE:
		rc = plugin->functions.fsim->get_plugin_info(descriptor_name, info);
		break;

	case EVMS_CLUSTER_MANAGER_INTERFACE_MODULE:
		rc = plugin->functions.cluster->get_plugin_info(descriptor_name, info);
		break;

	default:
		LOG_ERROR("We don't get info for %d plug-in types.\n", GetPluginType(plugin->id) );
		rc = EINVAL;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


void free_extended_info_array_contents(void * object) {

	int i, j;
	extended_info_array_t * eia = (extended_info_array_t *) object;
	extended_info_t       * ei;

	LOG_PROC_ENTRY();

	for (i = 0; i < eia->count; i++) {
		ei = &eia->info[i];

		if (ei->name != NULL) {
			engine_free(ei->name);
		}
		if (ei->title != NULL) {
			engine_free(ei->title);
		}
		if (ei->desc != NULL) {
			engine_free(ei->desc);
		}

		switch (ei->collection_type) {
		case EVMS_Collection_List:
			if (ei->collection.list != NULL) {
				if (ei->type == EVMS_Type_String) {
					for (j = 0; j < ei->collection.list->count; j++) {
						if (ei->collection.list->value[j].s != NULL) {
							engine_free(ei->collection.list->value[j].s);
						}
					}
				}
				engine_free(ei->collection.list);

			} else {
				LOG_WARNING("Collection says it has a list but the list pointer is NULL.\n");
			}
			break;

		case EVMS_Collection_Range:
			if (ei->collection.range != NULL) {
				engine_free((void *) ei->collection.range);

			} else {
				LOG_WARNING("Collection says it has a range but the range pointer is NULL.\n");
			}

		default:
			break;
		}

		if ((ei->group.group_number != 0) && (ei->group.group_name != NULL)) {
			engine_free(ei->group.group_name);
		}
	}

	LOG_PROC_EXIT_VOID();
}


int evms_get_extended_info(object_handle_t thing, char * descriptor_name, extended_info_array_t * * user_info) {
	int rc = 0;
	void * object;
	object_type_t type;
	extended_info_array_t * info = NULL;

	LOG_PROC_ENTRY();

	rc = check_engine_read_access();
        if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_get_extended_info(thing, descriptor_name, user_info);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	LOG_DEBUG("Get extended info for handle %d.\n", thing);
	rc = translate_handle(thing,
			      &object,
			      &type);

	if (rc == HANDLE_MANAGER_NO_ERROR) {
		switch (type) {
			case PLUGIN:{
					plugin_record_t * plugin = (plugin_record_t *) object;

					LOG_DEBUG("Handle %d maps to plug-in %s.\n", thing, plugin->short_name);
					rc = get_plugin_extended_info(plugin, descriptor_name, &info);
				}
				break;

			case DISK:
			case SEGMENT:
			case REGION:
			case EVMS_OBJECT:{
					storage_object_t * obj = (storage_object_t *) object;

					LOG_DEBUG("Handle %d maps to storage object %s.\n", thing, obj->name);
					rc = obj->plugin->functions.plugin->get_info(obj, descriptor_name, &info);
				}
				break;


			case CONTAINER:{
					storage_container_t * container = (storage_container_t *) object;

					LOG_DEBUG("Handle %d maps to container %s.\n", thing, container->name);
					rc = container->plugin->container_functions->get_container_info(container, descriptor_name, &info);
				}
				break;

			case VOLUME:{
					logical_volume_t * volume = (logical_volume_t *) object;

					LOG_DEBUG("Handle %d maps to volume %s.\n", thing, volume->name);
					if (volume->file_system_manager != NULL) {
						rc = volume->file_system_manager->functions.fsim->get_volume_info(volume, descriptor_name, &info);

					} else {
						/*
						 * The volume doesn't have an FSIM.
						 * Return an empty info array.
						 */
						info = engine_alloc(sizeof(extended_info_array_t));

						if (info == NULL) {
							rc = ENOMEM;
						}
					}
				}
				break;

			default:
				LOG_DEBUG("Handle %d maps to unknown object type %d.\n", thing, type);
				rc = EINVAL;
				break;
		}

		if ((rc == 0) && (info != NULL)) {

			/*
			 * Copy the extended info that was returned from the plug-in
			 * into an application memory object suitable for returning
			 * to the API caller.
			 */
			if (info->count == 0) {

				*user_info = alloc_app_struct(sizeof(info->count), NULL);
				if (*user_info != NULL) {
					/* Fill in the structure returned to the app. */
					(*user_info)->count = 0;

					/*
					 * Free the structure that was returned by the plug-in.
					 */
					engine_free(info);

				} else {
					rc = ENOMEM;
				}

			} else {
				/* The extended info array has at least one entry. */
				uint size = sizeof(extended_info_array_t) + (sizeof(extended_info_t) * info->count);

				*user_info = alloc_app_struct(size, free_extended_info_array_contents);

				if (*user_info != NULL) {
					/* Fill in the structure returned to the app. */
					memcpy(*user_info, info, size);

					/*
					 * Free the structure that was returned by the plug-in.
					 */
					engine_free(info);

				} else {
					rc = ENOMEM;
				}
			}
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


void update_all_stop_data_states() {

	list_element_t iter;
	storage_object_t * obj;

	LOG_PROC_ENTRY();

	/*
	 * Objects that are no longer top level objects cannot be guaranteed
	 * to have stop data on them.  Once they are consumed by another
	 * object or container, the consumer can write anything to the object
	 * anywhere on the object, including the stop data area.
	 */
	LIST_FOR_EACH(&disks_list, iter, obj) {
		if (!is_top_object(obj)) {
			obj->flags &= ~SOFLAG_HAS_STOP_DATA;
		}
	}
	LIST_FOR_EACH(&segments_list, iter, obj) {
		if (!is_top_object(obj)) {
			obj->flags &= ~SOFLAG_HAS_STOP_DATA;
		}
	}
	LIST_FOR_EACH(&regions_list, iter, obj) {
		if (!is_top_object(obj)) {
			obj->flags &= ~SOFLAG_HAS_STOP_DATA;
		}
	}

	LOG_PROC_EXIT_VOID();
	return;
}


/*
 * evms_set_info will set information, specified in options, for a thing.
 */
int evms_set_info(engine_handle_t  thing_handle,
		  option_array_t * options) {

	int rc = 0;
	object_type_t type;
	void *        thing;

	LOG_PROC_ENTRY();

	rc = check_engine_write_access();
        if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_set_info(thing_handle, options);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

		rc = translate_handle(thing_handle, &thing, &type);

		if (rc != HANDLE_MANAGER_NO_ERROR) {
			LOG_PROC_EXIT_INT(rc);
			return rc;
		}

	switch (type) {
		case DISK:
		case SEGMENT:
		case REGION:
		case EVMS_OBJECT:
			{
				storage_object_t * obj = (storage_object_t *) thing;
				char * old_object_name[sizeof(obj->name)] = {'\0'};

				rc = engine_can_rename(obj);

				if (rc == 0) {
					/* Check if it's part of a compatibility volume. */
					if ((obj->volume != NULL) &&
					    (obj->object_type != EVMS_OBJECT) &&
					    (obj->feature_header == NULL)) {

						/*
						 * Check if it's the top object of the
						 * compatibility volume.
						 */
						if (list_empty(obj->parent_objects)) {
							/*
							 * This is the top object of a compatibility
							 * volume.  If the object's name changes,
							 * the volume name must change as well.
							 * save the current volume name so that
							 * we can check if it changed during the
							 * call to the plug-in's set_info().
							 */
							memcpy(old_object_name, obj->name, sizeof(obj->name));
						}
					}

					rc = obj->plugin->functions.plugin->set_info(obj, options);

					/*
					 * Check if we need to handle a possible name
					 * change.
					 */
					if (old_object_name[0] != '\0') {
						if (memcmp(old_object_name, obj->name, sizeof(obj->name)) != 0) {

							char * pVolName = obj->name;
							list_element_t el;

							/*
							 * The object is a top level object of a
							 * compatibility volume and its name has
							 * changed.  Delete the old volume and
							 * create a new one with the new name.
							 */

							/* Unregister the current volume name. */
							engine_unregister_name(obj->volume->name);

							/* Delete the volume from the volumes_list. */
							remove_thing(&volumes_list, obj->volume);

							if (!(obj->volume->flags & VOLFLAG_NEW)) {
								/* Put it on the volume_delete_list. */
								el = insert_thing(&volume_delete_list,
										  obj->volume,
										  INSERT_AFTER,
										  NULL);

								if (el == NULL) {
									LOG_CRITICAL("Error putting volume %s on the volume_delete_list.\n", obj->volume->name);
									rc = 0;
								}
							}

							/*
							 * Build a new volume name for the object.
							 */
							if (strncmp(pVolName, EVMS_DEV_NODE_PATH, strlen(EVMS_DEV_NODE_PATH)) != 0) {
								pVolName = engine_alloc(strlen(pVolName) + strlen(EVMS_DEV_NODE_PATH) + 1);
								if (pVolName != NULL) {
									strcpy(pVolName, EVMS_DEV_NODE_PATH);
									strcat(pVolName, obj->name);
								} else {
									LOG_CRITICAL("Could not get memory for building a volume name for object %s.\n", obj->name);
									rc = ENOMEM;
								}
							}

							if (rc == 0) {

								/*
								 * Make a new volume patterned after the
								 * old one.
								 */
								logical_volume_t * old_vol = obj->volume;
								rc = make_volume(obj, pVolName);

								if (rc == 0) {
									obj->volume->dev_major     = old_vol->dev_major;
									obj->volume->dev_minor     = old_vol->dev_minor;
									obj->volume->serial_number = old_vol->serial_number;
									obj->volume->flags        |= old_vol->flags;
									obj->volume->flags        |= (VOLFLAG_NEW | VOLFLAG_DIRTY | VOLFLAG_NEEDS_ACTIVATE);
								}

								engine_free(pVolName);
							}
						}
					}
				}
			}
			break;

		case CONTAINER:
			{
				storage_container_t * con = (storage_container_t *) thing;
				rc = con->plugin->container_functions->set_container_info(con, options);
			}
			break;

		case VOLUME:
			{
				logical_volume_t * vol = (logical_volume_t *) thing;

				if (vol->flags & VOLFLAG_COMPATIBILITY) {
					if (is_kernel_volume_mounted(vol, DETAILS)) {
						rc = EBUSY;
                                        }
				}
				
				if (rc == 0) {
					if (vol->file_system_manager != NULL) {
						rc = vol->file_system_manager->functions.fsim->set_volume_info(vol, options);

					} else {
						LOG_DEBUG("Volume %s does not have a file system interface module.\n", vol->name);
						rc = ENOSYS;
					}
				}
			}
			break;

		default:
			LOG_ERROR("Cannot set info on a thing of type %#x.\n", type);
			rc = EINVAL;
			break;
	}

	if (rc == 0) {
		/*
		 * A plug-in can (ab)use set_info() to add or remove child
		 * objects to/from the given object.  Since we don't know
		 * what went on inside the set_info() and how it affected
		 * other objects, update the stop data state on all the
		 * objects that can have stop data.
		 */
		update_all_stop_data_states();
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


/*
 * Remove this object's feature headers and add the feature header sectors to
 * the kill list.
 */
int remove_feature_headers(storage_object_t * obj) {

	int rc = 0;

	LOG_PROC_ENTRY();

	if (obj->feature_header != NULL) {
		LOG_DEBUG("Removing feature headers from object %s.\n", obj->name);

		engine_free(obj->feature_header);
		obj->feature_header = NULL;

		/* Wipe out both feature headers. */
		obj->plugin->functions.plugin->add_sectors_to_kill_list(obj, obj->size - (EVMS_FEATURE_HEADER_SECTORS * 2), EVMS_FEATURE_HEADER_SECTORS * 2);

		/*
		 * If the object had stop data on it, it will be wiped out by
		 * the kill sectors.
		 */
		obj->flags &= ~SOFLAG_HAS_STOP_DATA;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


/*
 * Mark this object's feature header(s) dirty.  The feature header(s) for this
 * object is/are in this object's child objects.
 */
int set_feature_header_dirty(storage_object_t * obj) {

	int rc = 0;

	LOG_PROC_ENTRY();

	/* Only EVMS objects have feature headers. */
	if (obj->object_type == EVMS_OBJECT) {
		list_element_t iter;
		storage_object_t * child;

		LIST_FOR_EACH(obj->child_objects, iter, child) {
			if (child->feature_header != NULL) {
				child->flags |= SOFLAG_FEATURE_HEADER_DIRTY;
				set_feature_header_dirty(child);
			}
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int do_volume_delete_warnings(logical_volume_t * vol) {

	int rc = 0;

	LOG_PROC_ENTRY();

	/*
	 * If the volume is new then it really doesn't have an FSIM associated with
	 * it and it's not already a compatibility volume so there are no warnings
	 * to post.
	 */
	if (vol->flags & VOLFLAG_NEW) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	/*
	 * The volume has an FSIM, notify the user that unmkfs will be run on the
	 * volume.
	 */
	if (vol->file_system_manager != NULL) {

		/* Check if the FSIM can unmkfs. */
		rc = vol->file_system_manager->functions.fsim->can_unmkfs(vol);
		if (rc == 0) {
			/*
			 * Only need to ask the user to run unmkfs if the current FSIM is
			 * the original FSIM, it isn't already marked for unmkfs, and the
			 * volume is not read-only.
			 */
			if ((vol->file_system_manager == vol->original_fsim) &&
			    !(vol->flags & (VOLFLAG_UNMKFS | VOLFLAG_READ_ONLY))) {

				char * choices[] = {"Continue", "Cancel", NULL};
				int answer = 0;	    /* Default is "Continue". */

				engine_user_message(&answer, choices,
						    _("Volume \"%s\" has the %s file system on it.  "
						    "The file system will be removed along with the volume.\n"),
						    vol->name, vol->file_system_manager->short_name);
				switch (answer) {
				case 0:
					break;

				default:
					/* Any other answer is a cancel. */
					rc = E_CANCELED;
					break;
				}
			}

		} else {
			LOG_ERROR("FSIM %s will not allow the file system to be removed from volume %s.  Error code is %d.\n", vol->file_system_manager->short_name, vol->name, rc);
		}

	} else {
		/*
		 * The volume does not have an FSIM assigned to it.  If it did not
		 * originally have and FSIM assigned to it, it may have a file system on
		 * it for which we have no FSIM.  If the volume is not marked read-only
		 * ask the user if we should run a crude "unmkfs" that wipes out the
		 * first 1MB of the disk.
		 */
		if ((vol->original_fsim == NULL) &&
		    !(vol->flags & VOLFLAG_READ_ONLY)) {
			char * choices[] = {"Write zeros", "Do not write zeros", "Cancel", NULL};
			int answer = 0;	    /* Default is "Write zeroes". */

			sector_count_t one_meg_in_sectors = (1024 * 1024) >> EVMS_VSECTOR_SIZE_SHIFT;

			if (vol->object->size > one_meg_in_sectors) {
				engine_user_message(&answer, choices,
						    _("Volume \"%s\" does not have a File System Interface Module (FSIM) assigned to it.  "
						    "The volume may have a file system on it, but none of the installed FSIM plug-ins recognizes it.  "
						    "Do you want to write zeros to the first 1MB of the volume to potentially disable any file system "
						    "that may be on the volume?\n"),
						    vol->name);
			} else {
				engine_user_message(&answer, choices,
						    _("Volume \"%s\" does not have a File System Interface Module (FSIM) assigned to it.  "
						    "The volume may have a file system on it, but none of the installed FSIM plug-ins recognizes it.  "
						    "Do you want to write zeros to the volume to disable any file system that may be on the volume?\n"),
						    vol->name);
			}
			switch (answer) {
			case 0:
				rc = vol->object->plugin->functions.plugin->add_sectors_to_kill_list(vol->object, 0, min(vol->vol_size, (1024 * 1024) >> EVMS_VSECTOR_SIZE_SHIFT));
				break;

			case 1:
				/* Nothing to do. */
				break;

			case 2:
				rc = E_CANCELED;
			default:
				break;

			}
		}
	}

	if (rc == 0) {
		/*
		 * If this is a compatibility volume and we did not schedule an unmkfs,
		 * warn the user that the last few sectors will have metadata written
		 * to them.
		 */
		if ((vol->flags & VOLFLAG_COMPATIBILITY) &&
		    !(vol->flags & VOLFLAG_UNMKFS)) {
			char * choices[] = {"Continue", "Cancel", NULL};
			int answer = 0;	    /* Default is "Continue". */

			engine_user_message(&answer, choices,
					    _("Volume \"%s\" is not an EVMS volume.  "
					    "Removing a non-EVMS volume requires writing %zd bytes of metadata at the end of the volume. "
					    "The metadata will overwrite any data that may be at the end of the volume.  "
					    "Do you want to continue with the delete?\n"),
					    vol->name, (EVMS_FEATURE_HEADER_SECTORS * 2) << EVMS_VSECTOR_SIZE_SHIFT);

			if (answer != 0) {
				/* An answer other than "Continue" is considered a cancel. */
				rc = E_CANCELED;
			}
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int delete_volume(logical_volume_t * vol) {

	int rc = 0;
	storage_object_t * obj = vol->object;

	LOG_PROC_ENTRY();

	/* The volume must not be opened. */
	if (is_volume_opened(vol)) {
		LOG_ERROR("Volume %s cannot be deleted because it is opened.\n", vol->name);
		if (vol->mount_point != NULL) {
			LOG_ERROR("Volume %s is mounted on %s.\n", vol->name, vol->mount_point);
		}
		LOG_PROC_EXIT_INT(EBUSY);
		return EBUSY;
	}

	rc = obj->plugin->functions.plugin->can_set_volume(obj, FALSE);

	if (rc != 0) {
		LOG_ERROR("Object %s does not allow volume %s to be deleted.  Reason code is %d.\n", obj->name, vol->name, rc);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	/*
	 * Display any warning message(s) for the removal of this volume.
	 * do_volume_delete_warning() can return E_CANCELED if the user selects
	 * to cancel the removal.
	 */
	rc = do_volume_delete_warnings(vol);

	if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	destroy_handle(vol->app_handle);

	engine_unregister_name(vol->name);
	if (vol->flags & VOLFLAG_HAS_OWN_DEVICE) {
		engine_unregister_name(vol->name + EVMS_DEV_NODE_PATH_LEN);
	}

	/*
	 * Clear out the volume pointer on this object and on all the child
	 * objects in the tree.  Notify all the objects that the volume has been
	 * deleted.
	 */
	set_volume_in_object(obj,
			     NULL);    /* volume pointer */

	remove_thing(&volumes_list, vol);

	if (vol->flags & VOLFLAG_NEW) {

		/*
		 * This volume hasn't been committed yet.  Just throw away the
		 * volume structure.
		 */
		LOG_DEBUG("Volume is new, so just toss it out.\n");
		engine_free(vol);

	} else {
		list_element_t el;

		/*
		 * If the volume is not read-only, the FSIM is the original
		 * FSIM for the volume, do the setup for unmkfs.
		 */
		if (!(vol->flags & VOLFLAG_READ_ONLY) &&
		    (vol->file_system_manager == vol->original_fsim) &&
		    vol->original_fsim != NULL) {
			rc = vol->original_fsim->functions.fsim->unmkfs_setup(vol);

			if (rc != 0) {
				LOG_WARNING("Call to the unmkfs_setup() function of the %s FSIM returned arror code %d: %s\n",
					    vol->original_fsim->short_name, rc, evms_strerror(rc));
				LOG_PROC_EXIT_INT(rc);
				return rc;
			}

			/*
			 * Turn on the VOLFLAG_UNMKFS flag so that unmkfs will
			 * be run at commit time.  If the volume's VOLFLAG_MKFS
			 * is set we don't care.  The volume will be deleted and
			 * so won't have the chance to run mkfs.
			 */
			vol->flags |= VOLFLAG_UNMKFS;
		}

		/* Mark that this volume has no FSIM. */
		vol->file_system_manager = NULL;

		/* If the volume is active, it needs to be deactivated. */
		if (vol->flags & VOLFLAG_ACTIVE) {
			vol->flags |= VOLFLAG_NEEDS_DEACTIVATE;
		}

		/*
		 * If the object has a feature header attached, it is one for making the
		 * object into an EVMS volume.  Remove the feature header and kill the
		 * sectors so that it won't be found again.  Mark that the volume needs
		 * to be deactivated.
		 */
		if (obj->feature_header != NULL) {
			LOG_DEBUG("Removing feature headers from object %s.\n", obj->name);
			rc = obj->plugin->functions.plugin->add_sectors_to_kill_list(obj, obj->size - (EVMS_FEATURE_HEADER_SECTORS * 2), EVMS_FEATURE_HEADER_SECTORS * 2);

			if (rc == 0) {
				engine_free(obj->feature_header);
				obj->feature_header = NULL;

			} else {
				LOG_SERIOUS("add_sectors_to_kill_list() returned error code %d when called to wipe out volume feature header on volume %s.\n", rc, vol->name);
				LOG_PROC_EXIT_INT(rc);
				return rc;
			}
		}

		LOG_DEBUG("Volume exists.  Put it on the delete list.\n");
		el = insert_thing(&volume_delete_list,
				  vol,
				  INSERT_AFTER,
                                  NULL);

		if (el == NULL) {
			LOG_CRITICAL("Error putting volume %s on the volume delete list.\n", vol->name);
			LOG_PROC_EXIT_INT(ENOMEM);
			return ENOMEM;
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


storage_object_t * get_working_top_object(storage_object_t * obj) {

	storage_object_t * working_top_obj = obj;

	LOG_PROC_ENTRY();

	if (debug_level <= DEBUG) {
		if (obj->volume != NULL) {
			LOG_DEBUG("Find working top object for volume %s.\n", obj->volume->name);

		} else {
			LOG_DEBUG("Find working top object for obj %s.\n", obj->name);
		}
	}

	while ((working_top_obj != NULL) &&
	       (GetPluginType(working_top_obj->plugin->id) == EVMS_ASSOCIATIVE_FEATURE) &&
	       (list_empty(working_top_obj->associated_children))) {

		working_top_obj = first_thing(working_top_obj->child_objects, NULL);
	}

	LOG_DEBUG("Top object is %s.\n", working_top_obj->name);

	LOG_PROC_EXIT_PTR(working_top_obj);
	return working_top_obj;
}


/*
 * sync_volumes() will make sure that compatibility volumes have the
 * correct name, i.e., the EVMS_DEV_NODE_PATH prefix followed by the object
 * name.  (In the case where a segment is deleted or added to the disk, the
 * compatibility names of the objects may shift and hence the name of the
 * volume may change.)  It also makes sure that non-native EVMS volumes have
 * the same major:minor as the volume's object.
 */
void sync_volumes(void) {
	
	list_element_t iter;
	logical_volume_t * vol;

	LOG_PROC_ENTRY();

	LIST_FOR_EACH(&volumes_list, iter, vol) {
		storage_object_t * working_top_obj;

		working_top_obj = get_working_top_object(vol->object);

		if (working_top_obj != NULL) {
			if (vol->flags & VOLFLAG_COMPATIBILITY) {
				/*
				 * Compatibility volumes must have their name
				 * derived from the volume's working object.
				 */
				if ((strcmp(vol->name + EVMS_DEV_NODE_PATH_LEN, working_top_obj->name) != 0)) {
					engine_user_message(NULL, NULL,
							    _("Volume name %s has shifted to %s%s.\n"),
							    vol->name, EVMS_DEV_NODE_PATH, working_top_obj->name);

					engine_unregister_name(vol->name);

					/* Give the volume its new name. */
					memset(vol->name, 0, sizeof(vol->name));
					strcpy(vol->name, EVMS_DEV_NODE_PATH);
					strcat(vol->name, working_top_obj->name);
					engine_register_name(vol->name);
				}
			}

			/*
			 * For volumes that are not featureless EVMS volumes, make sure
			 * the volume has the same major:minor as its object.  (Its
			 * immediate object, not the first object that is not an
			 * associative feature.)
			 */
			if (working_top_obj->feature_header == NULL) {
				if ((vol->dev_major != vol->object->dev_major) ||
				    (vol->dev_minor != vol->object->dev_minor)) {
					vol->dev_major = vol->object->dev_major;
					vol->dev_minor = vol->object->dev_minor;

					if (ensure_dev_node(vol->name, vol->dev_major, vol->dev_minor) == 0) {
						vol->flags |= VOLFLAG_ACTIVE;
						vol->flags &= ~VOLFLAG_NEEDS_ACTIVATE;
					}
				}
			}

		} else {
			LOG_SERIOUS("Failed to get the working top object.\n");
		}
	}

	LOG_PROC_EXIT_VOID();
	return;
}


static int delete_object(storage_object_t * obj) {

	int rc = 0;
	STATIC_LIST_DECL(child_list);

	LOG_PROC_ENTRY();

	/*
	 * Make sure the object is a top level object.  We can't delete objects
	 * in the middle of a feature stack or under a volume has no parent.
	 */
	if (!is_top_object(obj)) {
		LOG_ERROR("Object %s is not a top level object.\n", obj->name);
		LOG_PROC_EXIT_INT(EINVAL);
		return EINVAL;
	}

	/* If the object has stop data on it, delete it. */
	if (obj->flags & SOFLAG_HAS_STOP_DATA) {
		LOG_DEBUG("Removing stop data from object %s.\n", obj->name);
		rc = obj->plugin->functions.plugin->add_sectors_to_kill_list(obj, obj->size - (EVMS_FEATURE_HEADER_SECTORS * 2), EVMS_FEATURE_HEADER_SECTORS * 2);

		if (rc == 0) {
			obj->flags &= ~SOFLAG_HAS_STOP_DATA;

		} else {
			LOG_SERIOUS("add_sectors_to_kill_list() returned error code %d when called to wipe out stop data on object %s.\n", rc, obj->name);
		}
	}

	rc = obj->plugin->functions.plugin->delete(obj, &child_list);

	if (rc == 0) {
		list_element_t iter;
		storage_object_t * child_obj;

		LIST_FOR_EACH(&child_list, iter, child_obj) {

			/*
			 * Now that the child objects are top objects, they will
			 * not contain feature headers.  Remove the feature
			 * headers from the child objects.
			 */
			remove_feature_headers(child_obj);

			/*
			 * Mark the children's child objects' feature headers
			 * dirty so that the volume complete flag will be set
			 * correctly on commit.
			 */
			set_feature_header_dirty(child_obj);

			/*
			 * The parent object may have written over the stop data
			 * when it owned the child.  Forget that the child had
			 * stop data.
			 */
			child_obj->flags &= ~SOFLAG_HAS_STOP_DATA;
		}

		/* Make sure the compatibility volume names are in sync. */
		sync_volumes();
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


int evms_delete(object_handle_t thing_handle) {
	int rc = 0;
	void * thing;
	object_type_t type;

	LOG_PROC_ENTRY();

	rc = check_engine_write_access();

	if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_delete(thing_handle);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	rc = translate_handle(thing_handle,
			      &thing,
			      &type);

	if (rc != HANDLE_MANAGER_NO_ERROR) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	switch (type) {
		case VOLUME:
			{
				logical_volume_t * volume = (logical_volume_t *) thing;

				LOG_DEBUG("Request to delete volume %s.\n", volume->name);

				if (volume->flags & VOLFLAG_COMPATIBILITY) {
					if (is_kernel_volume_mounted(volume, DETAILS)) {
						rc = EBUSY;
                                        }
				}
				
				if (rc == 0) {
					rc = delete_volume(volume);
				}
			}
			break;

		case CONTAINER:
			{
				storage_container_t * container = (storage_container_t *) thing;
				STATIC_LIST_DECL(objects_consumed);

				LOG_DEBUG("Request to destroy container %s.\n", container->name);

				rc = container->plugin->container_functions->delete_container(container, &objects_consumed);
				LOG_DEBUG("Return code from delete_container() is %d: %s.\n",  rc, evms_strerror(rc));
			}
			break;

		case EVMS_OBJECT:
		case REGION:
		case SEGMENT:
		case DISK:
			{
				storage_object_t * obj = (storage_object_t *) thing;

				LOG_DEBUG("Request to delete object %s.\n", obj->name);

				rc = delete_object(obj);
			}
			break;

		default:
			LOG_ERROR("A thing with a type of %#x cannot be deleted.\n", type);
			rc = EINVAL;
			break;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


/*
 * Delete an object and all of its children.
 * This function is a service function for evms_destroy() below.
 * This function calls itself recursively to delete its children.
 */
static int destroy_object(storage_object_t * obj) {

	int rc = 0;
	STATIC_LIST_DECL(child_list);

	LOG_PROC_ENTRY();

	/* Disks are not deleted on a destroy. */

	if (obj->object_type == DISK) {
		/*
		 * When the disk was consumed the stop data may have been
		 * trashed.  Forget that it has stop data.  It will be
		 * rewritten on commit.
		 */
		obj->flags &= ~SOFLAG_HAS_STOP_DATA;

	} else {
		/*
		 * Save the producing container so we can check it after the
		 * object is deleted.
		 */
		storage_container_t * producing_container = obj->producing_container;

		/* If the object has stop data on it, delete it. */
		if (obj->flags & SOFLAG_HAS_STOP_DATA) {
			LOG_DEBUG("Removing stop data from object %s.\n", obj->name);
			rc = obj->plugin->functions.plugin->add_sectors_to_kill_list(obj, obj->size - (EVMS_FEATURE_HEADER_SECTORS * 2), EVMS_FEATURE_HEADER_SECTORS * 2);

			if (rc == 0) {
				obj->flags &= ~SOFLAG_HAS_STOP_DATA;

			} else {
				LOG_SERIOUS("add_sectors_to_kill_list() returned error code %d when called to wipe out stop data on object %s.\n", rc, obj->name);
			}
		}

		rc = obj->plugin->functions.plugin->delete(obj, &child_list);

		if (rc == 0) {
			list_element_t iter;
			storage_object_t * child;

			/*
			 * Now that the child objects are top objects, they will
			 * not contain feature headers.  Remove the feature
			 * headers from the child objects.
			 */
			LIST_FOR_EACH(&child_list, iter, child) {
				remove_feature_headers(child);
			}

			/*
			 * If the object was not produced by a container, do a recursive
			 * deletion of its children.
			 */
			if (producing_container == NULL) {
				LIST_FOR_EACH(&child_list, iter, child) {
					destroy_object(child);
				}
			}
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int destroy_volume(logical_volume_t * volume) {

	int rc = 0;
	storage_object_t * obj = volume->object;

	LOG_PROC_ENTRY();

	/*
	 * Ask the object below the volume if it can handle
	 * being deleted.
	 */
	rc = can_destroy_object(obj);

	if (rc == 0) {

		rc = delete_volume(volume);

		if (rc == 0) {
			rc = destroy_object(obj);
		}

	} else {
		LOG_ERROR("Object %s does not allow volume %s to be deleted.  Reason code is %d.\n", obj->name, volume->name, rc);
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


/*
 * evms_destroy() deletes an object and all the child objects in the tree
 * beneath the object.
 */
int evms_destroy(object_handle_t thing) {

	int rc = 0;
	void * object;
	object_type_t type;

	LOG_PROC_ENTRY();

	rc = check_engine_write_access();
        if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_destroy(thing);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	rc = translate_handle(thing,
			      &object,
			      &type);

	if (rc != HANDLE_MANAGER_NO_ERROR) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	switch (type) {
		case VOLUME:
			{
				logical_volume_t * volume = (logical_volume_t *) object;

				LOG_DEBUG("Request to destroy volume %s.\n", volume->name);

				if (volume->flags & VOLFLAG_COMPATIBILITY) {
					if (is_kernel_volume_mounted(volume, DETAILS)) {
						rc = EBUSY;
                                        }
				}
				
				if (rc == 0) {
					rc = destroy_volume(volume);

					if (rc == 0) {
						/*
						 * Make sure the compatibility volume names
						 * are in sync.
						 */
						sync_volumes();
					}
				}
			}
			break;

		case CONTAINER:
			{
				storage_container_t * container = (storage_container_t *) object;
				STATIC_LIST_DECL(objects_consumed);

				LOG_DEBUG("Request to destroy container %s.\n", container->name);

			       	rc = container->plugin->container_functions->delete_container(container, &objects_consumed);
			       	LOG_DEBUG("Return code from call to %s plug-in's delete_container() is %d.\n", container->plugin->short_name, rc);

			       	if (rc == 0) {
			       		/* Destroy the objects that were in the container. */
			       		list_element_t iter;
			       		storage_object_t * child;
			       		LIST_FOR_EACH(&objects_consumed, iter, child) {
			       			destroy_object(child);
			       		}
			       	}
			}
			break;

		case EVMS_OBJECT:
		case REGION:
		case SEGMENT:
			{
				storage_object_t * obj = (storage_object_t *) object;

				LOG_DEBUG("Request to destroy storage object %s.\n", obj->name);

				/*
				 * Make sure the object is a top level object.  We can't
				 * destroy objects in the middle of a feature stack.  A
				 * top level object has no parent.
				 */
				if (is_top_object(obj)) {

					rc = destroy_object(obj);
					if (rc == 0) {
						/*
						 * Make sure the compatibility volume names
						 * are in sync.
						 */
						sync_volumes();
					}

				} else {
					/* The object is not a top level object. */

					LOG_ERROR("Object %s is not a top level object.\n", obj->name);
					rc = EINVAL;
				}
			}
			break;

		case DISK:
			{
				storage_object_t * obj = object;

				LOG_ERROR("Disk %s cannot be destroyed because disks cannot be destroyed.  Disks must be deleted.\n", obj->name);
				rc = EINVAL;
			}
			break;

		default:
			LOG_ERROR("A thing with a type of %#x cannot be destroyed.\n", type);
			rc = EINVAL;
			break;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int create_replace_object(storage_object_t   * source,
				 storage_object_t   * target,
				 storage_object_t * * replace_object) {
	int rc = 0;
	STATIC_LIST_DECL(input_list);
	STATIC_LIST_DECL(output_list);
	list_element_t el;

	LOG_PROC_ENTRY();

	/*
	 * Order is important here.  The Replace feature takes
	 * the first object as the source and the second object
	 * as the target.
	 */
	el = insert_thing(&input_list,
			  source,
			  INSERT_BEFORE,
			  NULL);

	if (el != NULL) {
		el = insert_thing(&input_list,
				  target,
				  INSERT_AFTER,
				  NULL);

		if (el != NULL) {
			rc = replace_plugin->functions.plugin->create(&input_list, NULL, &output_list);

			if (rc == 0) {

				/*
				 * Any stop data on the target may get
				 * trashed by a parent object.  Forget
				 * that it is there.
				 */
				target->flags &= ~SOFLAG_HAS_STOP_DATA;

				/*
				 * Return the new replace object to the
				 * caller.
				 */
				*replace_object = first_thing(&output_list, NULL);
			}

		} else {
			LOG_CRITICAL("Error when putting target object %s into the input list.\n", target->name);
			rc = ENOMEM;
		}

	} else {
		LOG_WARNING("Error when putting source object %s into the input list.\n", source->name);
		rc = ENOMEM;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


int evms_replace(object_handle_t source_handle, object_handle_t target_handle) {

	int rc = 0;
	storage_object_t * source;
	storage_object_t * target;
	storage_object_t * replace_obj;
	object_type_t type;
	list_anchor_t source_parents = NULL;

	LOG_PROC_ENTRY();

	rc = check_engine_write_access();
	if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_replace(source_handle, target_handle);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	rc = can_replace(source_handle, target_handle, ERROR);
	if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	/*
	 * No need to check the return codes from translate_handle()
	 * since can_replace() translated the handles and got good
	 * return codes.
	 */
	translate_handle(source_handle,
			 (void *) &source,
			 &type);

	translate_handle(target_handle,
			 (void *) &target,
			 &type);

	if (!list_empty(source->parent_objects)) {

		/* Get a copy of the source's parent list so
		 * we can insert the replace object after it
		 * has been created.  When the replace object
		 * is created it changes the source's parent
		 * list to point to the new replace object.
		 */

		source_parents = copy_list(source->parent_objects);
		if (source_parents == NULL) {
			LOG_SERIOUS("Error making a copy of the parent list.\n");
			LOG_PROC_EXIT_INT(ENOMEM);
			return ENOMEM;
		}
	}

	rc = create_replace_object(source, target, &replace_obj);

	if (rc == 0) {
		if (source_parents != NULL) {
			list_element_t iter;
			storage_object_t * parent;

			LIST_FOR_EACH(source_parents, iter, parent) {
				rc = parent->plugin->functions.plugin->replace_child(parent, source, replace_obj);

				if (rc != 0) {
					list_element_t tmp_iter;
					LOG_WARNING("Parent object %s failed to replace child object %s with new child object %s.  Error code was %d: %s\n",
						    parent->name, source->name, replace_obj->name, rc, evms_strerror(rc));

					/* Undo any replaces that succeeded. */
					LIST_FOR_EACH(source_parents, tmp_iter, parent) {
						parent->plugin->functions.plugin->replace_child(parent, replace_obj, source);
					}
					break;
				}
			}

		} else {
			source->volume->object = replace_obj;
			source->volume->flags |= VOLFLAG_NEEDS_ACTIVATE;
		}
	}

	if (source_parents != NULL) {
		destroy_list(source_parents);
	}

	if (rc == 0) {
		/*
		 * Some plug-ins NULL out the source's volume pointer
		 * when they abandon the source as a child.  However, in this
		 * case, the source has not really been abandoned; it is still
		 * part of the volume.
		 */
		source->volume = replace_obj->volume;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


int make_list(handle_array_t * ha, list_anchor_t list) {

	int rc = 0;
	int i;
	void * object;
	object_type_t type;

	LOG_PROC_ENTRY();

	/* If handle array pointer is NULL, just return the empty list_anchor_t. */
	if (ha != NULL) {
		for (i = 0; (rc == 0) && (i < ha->count); i++) {
			rc = translate_handle(ha->handle[i],
					      &object,
					      &type);

			if (rc == HANDLE_MANAGER_NO_ERROR) {
				list_element_t el;

				el = insert_thing(list,
						  object,
						  INSERT_AFTER,
						  NULL);

				if (el == NULL) {
					LOG_CRITICAL("Error inserting thing into the list.\n");
					rc = ENOMEM;
				}
			}
		}
	}

	if (rc != 0) {
		delete_all_elements(list);
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


void free_info_object_contents(void * object) {

	handle_object_info_t * info = (handle_object_info_t *) object;

	LOG_PROC_ENTRY();

	switch (info->type) {
	case PLUGIN:
		break;

	case DISK:
	case SEGMENT:
	case REGION:
	case EVMS_OBJECT:
		if (info->info.object.parent_objects != NULL) {
			engine_free(info->info.object.parent_objects);
		}

		if (info->info.object.child_objects != NULL) {
			engine_free(info->info.object.child_objects);
		}

		break;

	case CONTAINER:
		if (info->info.container.objects_consumed != NULL) {
			engine_free(info->info.container.objects_consumed);
		}
		if (info->info.container.objects_produced != NULL) {
			engine_free(info->info.container.objects_produced);
		}

		break;

	case VOLUME:
		if (info->info.volume.mount_point != NULL) {
			engine_free(info->info.volume.mount_point);
		}

		break;

	default:
		break;
	}

	LOG_PROC_EXIT_VOID();
}


int evms_get_handle_object_type(object_handle_t handle,
				object_type_t * type) {
	int rc = 0;
	void * object;

	LOG_PROC_ENTRY();

	*type = 0;

	rc = check_engine_read_access();
        if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_get_handle_object_type(handle, type);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	rc = translate_handle(handle,
			      &object,
			      type);

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


/*
 * Make an array of handles (handle_array_t) for the objects in list.
 */
int make_handle_array(list_anchor_t      list,
		      handle_array_t * * ha) {

	int rc = 0;
	uint count;
	uint size;

	LOG_PROC_ENTRY();

	count = list_count(list);

		LOG_DEBUG("Number of objects in the list:  %d\n", count);
		size = sizeof(handle_array_t) + (count * sizeof(object_handle_t));

		*ha = engine_alloc(size);
		if (*ha != NULL) {
			list_element_t iter;
			void * thing;

			LIST_FOR_EACH(list, iter, thing) {
				make_handle_entry(thing, *ha);
			}

		} else {
			LOG_CRITICAL("Error allocating memory for a handle array.\n");
			rc = ENOMEM;
		}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


int evms_get_info(object_handle_t thing, handle_object_info_t * * user_info) {
	
	int rc = 0;
	void * object;
	object_type_t type;
	handle_object_info_t * info = NULL;

	LOG_PROC_ENTRY();

	*user_info = NULL;

	rc = check_engine_read_access();
	if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_get_info(thing, user_info);

		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	info = alloc_app_struct(sizeof(handle_object_info_t), free_info_object_contents);

	if (info != NULL) {
		LOG_DEBUG("Get info for handle %d.\n", thing);
		rc = translate_handle(thing,
				      &object,
				      &type);

		if (rc == HANDLE_MANAGER_NO_ERROR) {
			switch (type) {
				case PLUGIN:
					{
						plugin_record_t * plugin = (plugin_record_t *) object;

						LOG_DEBUG("Handle %d maps to plug-in %s.\n", thing, plugin->short_name);
						info->type = PLUGIN;

						rc = ensure_app_handle(plugin);
						if (rc == 0) {
							info->info.plugin.handle                             = plugin->app_handle;
							info->info.plugin.id                                 = plugin->id;
							info->info.plugin.version.major                      = plugin->version.major;
							info->info.plugin.version.minor                      = plugin->version.minor;
							info->info.plugin.version.patchlevel                 = plugin->version.patchlevel;
							info->info.plugin.required_engine_api_version        = plugin->required_engine_api_version;
							info->info.plugin.required_plugin_api_version.plugin = plugin->required_plugin_api_version.plugin;
							info->info.plugin.required_container_api_version     = plugin->required_container_api_version;
							info->info.plugin.short_name                         = plugin->short_name;
							info->info.plugin.long_name                          = plugin->long_name;
							info->info.plugin.oem_name                           = plugin->oem_name;
							info->info.plugin.supports_containers                = (plugin->container_functions != NULL);
						}
					}
					break;

				case DISK:
				case SEGMENT:
				case REGION:
				case EVMS_OBJECT:
					{
						storage_object_t * obj = (storage_object_t *) object;

						LOG_DEBUG("Handle %d maps to storage object %s.\n", thing, obj->name);
						info->type = obj->object_type;

						rc = make_handle_array(obj->parent_objects, &info->info.object.parent_objects);
						if (rc == 0) {

							rc = make_handle_array(obj->child_objects, &info->info.object.child_objects);
							if (rc == 0) {

								rc = ensure_app_handle(obj);
								if (rc == 0) {
									info->info.object.handle = obj->app_handle;
									info->info.object.object_type = obj->object_type;
									info->info.object.data_type = obj->data_type;
								}

								if (rc == 0) {
									if (obj->plugin != NULL) {
										rc = ensure_app_handle(obj->plugin);
										if (rc == 0) {
											info->info.object.plugin = obj->plugin->app_handle;
										}

									} else {
										info->info.object.plugin = 0;
									}
								}

								if (rc == 0) {
									if (obj->producing_container != NULL) {

										rc = ensure_app_handle(obj->producing_container);
										if (rc == 0) {
											info->info.object.producing_container = obj->producing_container->app_handle;
										}
									} else {
										info->info.object.producing_container = 0;
									}
								}

								if (rc == 0) {
									if (obj->consuming_container != NULL) {

										rc = ensure_app_handle(obj->consuming_container);
										if (rc == 0) {
											info->info.object.consuming_container = obj->consuming_container->app_handle;
										}
									} else {
										info->info.object.consuming_container = 0;
									}
								}

								if (rc == 0) {
									if (obj->volume != NULL) {

										rc = ensure_app_handle(obj->volume);
										if (rc == 0) {
											info->info.object.volume = obj->volume->app_handle;
										}
									} else {
										info->info.object.volume = 0;
									}
								}

								if (rc == 0) {
									if (obj->disk_group != NULL) {

										rc = ensure_app_handle(obj->disk_group);
										if (rc == 0) {
											info->info.object.disk_group = obj->disk_group->app_handle;
										}
									} else {
										info->info.object.disk_group = 0;
									}
								}

								if (rc == 0) {
									info->info.object.dev_major = obj->dev_major;
									info->info.object.dev_minor = obj->dev_minor;
									info->info.object.flags = obj->flags;
									memcpy(info->info.object.name, obj->name, sizeof(obj->name));
									info->info.object.start = obj->start;
									info->info.object.size = obj->size;
									info->info.object.geometry = obj->geometry;
								}
							}
						}
					}
					break;

				case CONTAINER:
					{
						storage_container_t * con = (storage_container_t *) object;

						LOG_DEBUG("Handle %d maps to container %s.\n", thing, con->name);
						info->type = CONTAINER;

						rc = make_handle_array(con->objects_consumed, &info->info.container.objects_consumed);
						if (rc == 0) {
							rc = make_handle_array(con->objects_produced, &info->info.container.objects_produced);
							if (rc == 0) {

								rc = ensure_app_handle(con);
								if (rc == 0) {
									info->info.container.handle = con->app_handle;
								}

								if (rc == 0) {
									if (con->plugin != NULL) {
										rc = ensure_app_handle(con->plugin);
										if (rc == 0) {
											info->info.container.plugin = con->plugin->app_handle;
										}
									} else {
										info->info.container.plugin = 0;
									}
								}

								if (rc == 0) {
									if (con->disk_group != NULL) {

										rc = ensure_app_handle(con->disk_group);
										if (rc == 0) {
											info->info.container.disk_group = con->disk_group->app_handle;
										}
									} else {
										info->info.container.disk_group = 0;
									}
								}

								if (rc == 0) {
									info->info.container.flags = con->flags;
									memcpy(info->info.container.name, con->name, sizeof(con->name));
									info->info.container.size = con->size;
								}
							}
						}
					}
					break;

				case VOLUME:
					{
						logical_volume_t * vol = (logical_volume_t *) object;

						LOG_DEBUG("Handle %d maps to volume %s.\n", thing, vol->name);
						info->type = VOLUME;

						rc = ensure_app_handle(vol);
						if (rc == 0) {
							info->info.volume.handle = vol->app_handle;
						}

						if (rc == 0) {
							if (vol->file_system_manager != NULL) {
								rc = ensure_app_handle(vol->file_system_manager);
								if (rc == 0) {
									info->info.volume.file_system_manager = vol->file_system_manager->app_handle;
								}
							} else {
								info->info.volume.file_system_manager = 0;
							}
						}

						if (rc == 0) {
							if (vol->object != NULL) {
								rc = ensure_app_handle(vol->object);
								if (rc == 0) {
									info->info.volume.object = vol->object->app_handle;
								}
							} else {
								info->info.volume.object = 0;
							}
						}

						if (rc == 0) {
							if (vol->disk_group != NULL) {

								rc = ensure_app_handle(vol->disk_group);
								if (rc == 0) {
									info->info.volume.disk_group = vol->disk_group->app_handle;
								}
							} else {
								info->info.volume.disk_group = 0;
							}
						}

						if (rc == 0) {
							if (vol->mount_point != NULL) {
								info->info.volume.mount_point = engine_alloc(strlen(vol->mount_point) + 1);
								strcpy(info->info.volume.mount_point, vol->mount_point);
							} else {
								info->info.volume.mount_point = NULL;
							}

							/*
							 * Reget volume limits since things like
							 * min_fs_size can change if the volume is live.
							 */
							get_volume_sizes_and_limits(vol);

							info->info.volume.fs_size       = vol->fs_size;
							info->info.volume.min_fs_size   = vol->min_fs_size;
							info->info.volume.max_fs_size   = vol->max_fs_size;
							info->info.volume.vol_size      = vol->vol_size;
							info->info.volume.max_vol_size  = vol->max_vol_size;
							info->info.volume.dev_major     = vol->dev_major;
							info->info.volume.dev_minor     = vol->dev_minor;
							info->info.volume.serial_number = vol->serial_number;
							info->info.volume.flags         = vol->flags;
							memcpy(info->info.volume.name, vol->name, sizeof(vol->name));
							memcpy(info->info.volume.dev_node, vol->dev_node, sizeof(vol->dev_node));
						}
					}
					break;

				default:
					LOG_DEBUG("Handle %d maps to unknown object type %d.\n", thing, type);
					rc = EINVAL;
					break;
			}
		}

		if ((rc != 0) && (info != NULL)) {
			evms_free(info);
			info = NULL;
		}


	} else {
		rc = ENOMEM;
	}

	*user_info = info;

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int add_plugin_to_list(storage_object_t * obj,
			      list_anchor_t      plugin_list) {

	int rc = 0;
	list_element_t iter;
	plugin_record_t * pPlugRec;

	LOG_PROC_ENTRY();

	/* Only get the plug-in (feature) if this is an EVMS storage object. */
	if (obj->object_type == EVMS_OBJECT) {

		/* Make sure the plug-in isn't already on the list. */
		LIST_FOR_EACH(&plugins_list, iter, pPlugRec) {
			if (pPlugRec == obj->plugin) {
				break;
			}
		}

		if (pPlugRec == NULL) {
			list_element_t el;
			/*
			 * This plug-in record is not in the list.  Insert it into the
			 * list.
			 */
			el = insert_thing(plugin_list,
					  obj->plugin,
					  INSERT_AFTER,
					  NULL);

			if (el == NULL) {
				LOG_CRITICAL("Error inserting plugin %s into the plugin list.\n", obj->plugin->short_name);
				rc = ENOMEM;
			}
		}

		if (rc == 0) {
			/* Get the feature(s) for the child object(s). */
			storage_object_t * child;

			LIST_FOR_EACH(obj->child_objects, iter, child) {
				rc = add_plugin_to_list(child, plugin_list);
				if (rc != 0) {
					break;
				}
			}
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


int evms_get_feature_list(object_handle_t    thing,
			  handle_array_t * * plugin_handles) {
	int rc = 0;
	void * object;
	object_type_t type;
	handle_array_t * plugins;

	LOG_PROC_ENTRY();

	rc = check_engine_read_access();
        if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_get_feature_list(thing, plugin_handles);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	rc = translate_handle(thing,
			      &object,
			      &type);

	if (rc != HANDLE_MANAGER_NO_ERROR) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if ((type == VOLUME) ||
	    (type == EVMS_OBJECT)) {
		STATIC_LIST_DECL(feature_list);
		storage_object_t * storage_object;

		if (type == VOLUME) {
			logical_volume_t * volume = (logical_volume_t *) object;

			storage_object = volume->object;
		} else {
			storage_object = (storage_object_t *) object;
		}

		rc = add_plugin_to_list(storage_object,
					&feature_list);

		if (rc == 0) {
			rc = make_user_handle_array(&feature_list, &plugins);
		}

	} else {
		/* The thing is not a volume or object. */
		rc = EINVAL;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int find_object_handle_by_name(list_anchor_t list, char * name, object_handle_t * handle) {

	int rc = 0;
	list_element_t iter;
	storage_object_t * obj;

	LOG_PROC_ENTRY();

	LIST_FOR_EACH(list, iter, obj) {
		if (strcmp(obj->name, name) == 0) {
			break;
		}
	}

	if (obj != NULL) {
		rc = ensure_app_handle(obj);

		if (rc == 0) {
			*handle = obj->app_handle;
		}

	} else {
		rc = ENOENT;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int find_container_handle_by_name(char * name, object_handle_t * handle) {

	int rc = 0;
	list_element_t iter;
	storage_container_t * con;

	LIST_FOR_EACH(&containers_list, iter, con) {
		if (strcmp(con->name, name) == 0) {
			break;
		}
	}

	if (con != NULL) {
		rc = ensure_app_handle(con);
		if (rc == 0) {
			*handle = con->app_handle;
		}

	} else {
		rc = ENOENT;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


static int find_volume_handle_by_name(char * name, object_handle_t * handle) {

	int rc = 0;
	list_element_t iter;
	logical_volume_t * vol;

	LIST_FOR_EACH(&volumes_list, iter, vol) {
		if (strcmp(vol->name, name) == 0) {
			break;
		}
	}

	if (vol != NULL) {
		rc = ensure_app_handle(vol);
		if (rc == 0) {
			*handle = vol->app_handle;
		}

	} else {
		rc = ENOENT;
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}


int evms_get_object_handle_for_name(object_type_t type, char * name, object_handle_t * object_handle) {

	int rc = 0;

	LOG_PROC_ENTRY();

	rc = check_engine_read_access();
        if (rc != 0) {
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	if (!local_focus) {
		rc = remote_get_object_handle_for_name(type, name, object_handle);
		LOG_PROC_EXIT_INT(rc);
		return rc;
	}

	LOG_DEBUG("Lookup handle for thing of type %#x and name \"%s\".\n", type, name);

	rc = ENOENT;

	if (type & DISK) {
		rc = find_object_handle_by_name(&disks_list, name, object_handle);
		if (rc == 0) {
			LOG_DEBUG("Found %s in the disks list.  It has handle %d.\n",
				  name, *object_handle);
		}
	}

	if ((rc == ENOENT) && (type & SEGMENT)) {
		rc = find_object_handle_by_name(&segments_list, name, object_handle);
		if (rc == 0) {
			LOG_DEBUG("Found %s in the segments list.  It has handle %d.\n",
				  name, *object_handle);
		}
	}

	if ((rc == ENOENT) && (type & REGION)) {
		rc = find_object_handle_by_name(&regions_list, name, object_handle);
		if (rc == 0) {
			LOG_DEBUG("Found %s in the regions list.  It has handle %d.\n",
				  name, *object_handle);
		}
	}

	if ((rc == ENOENT) && (type & EVMS_OBJECT)) {
		rc = find_object_handle_by_name(&EVMS_objects_list, name, object_handle);
		if (rc == 0) {
			LOG_DEBUG("Found %s in the EVMS objects list.  It has handle %d.\n",
				  name, *object_handle);
		}
	}

	if ((rc == ENOENT) && (type & CONTAINER)) {
		rc = find_container_handle_by_name(name, object_handle);
		if (rc == 0) {
			LOG_DEBUG("Found %s in the containers list.  It has handle %d.\n",
				  name, *object_handle);
		}
	}

	if ((rc == ENOENT) && (type & VOLUME)) {
		rc = find_volume_handle_by_name(name, object_handle);
		if (rc == 0) {
			LOG_DEBUG("Found %s in the volumes list.  It has handle %d.\n",
				  name, *object_handle);
		}
	}

	LOG_PROC_EXIT_INT(rc);
	return rc;
}