forked from jcnelson/vdev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
111 lines (79 loc) · 2.73 KB
/
main.cpp
File metadata and controls
111 lines (79 loc) · 2.73 KB
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
/*
vdev: a virtual device manager for *nix
Copyright (C) 2014 Jude Nelson
This program is dual-licensed: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 or later as
published by the Free Software Foundation. For the terms of this
license, see LICENSE.LGPLv3+ or <http://www.gnu.org/licenses/>.
You are free to use this program under the terms of the GNU General
Public License, 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.
Alternatively, you are free to use this program under the terms of the
Internet Software Consortium License, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For the terms of this license, see LICENSE.ISC or
<http://www.isc.org/downloads/software-support-policy/isc-license/>.
*/
#include "main.h"
// run!
int main( int argc, char** argv ) {
int rc = 0;
pid_t pid = 0;
struct vdev_state vdev;
memset( &vdev, 0, sizeof(struct vdev_state) );
// set up global vdev state
rc = vdev_init( &vdev, argc, argv );
if( rc != 0 ) {
vdev_error("vdev_init rc = %d\n", rc );
exit(1);
}
// load back-end info so we can fail fast before mounting
rc = vdev_backend_init( &vdev );
if( rc != 0 ) {
vdev_error("vdev_backend_init rc = %d\n", rc );
vdev_free( &vdev );
exit(1);
}
pid = fork();
if( pid == 0 ) {
// child: filesystem front-end
rc = vdev_frontend_init( &vdev );
if( rc != 0 ) {
vdev_error("vdev_frontend_init rc = %d\n", rc );
vdev_free( &vdev );
exit(1);
}
// run
rc = vdev_frontend_main( &vdev );
if( rc != 0 ) {
vdev_error("vdev_frontend_main rc = %d\n", rc );
vdev_free( &vdev );
exit(1);
}
// clean up
vdev_frontend_stop( &vdev );
}
else if( pid > 0 ) {
// start
rc = vdev_backend_start( &vdev );
if( rc != 0 ) {
vdev_error("vdev_backend_init rc = %d\n", rc );
vdev_backend_stop( &vdev );
vdev_free( &vdev );
exit(1);
}
// run
rc = vdev_backend_main( &vdev );
if( rc != 0 ) {
vdev_error("vdev_backend_main rc = %d\n", rc );
vdev_backend_stop( &vdev );
vdev_free( &vdev );
exit(1);
}
// clean up
vdev_backend_stop( &vdev );
}
vdev_free( &vdev );
return 0;
}