]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
dfc130f3 | 4 | * |
da23017d NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
2bd0ea18 | 7 | * published by the Free Software Foundation. |
dfc130f3 | 8 | * |
da23017d NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
dfc130f3 | 13 | * |
da23017d NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2bd0ea18 NS |
17 | */ |
18 | ||
19 | #include <libxfs.h> | |
20 | #include "globals.h" | |
21 | #include "agheader.h" | |
22 | #include "protos.h" | |
23 | #include "err_protos.h" | |
2814f3d6 | 24 | #include "pthread.h" |
2556c98b BN |
25 | #include "avl.h" |
26 | #include "dir.h" | |
27 | #include "incore.h" | |
cb5b3ef4 | 28 | #include "prefetch.h" |
2814f3d6 MV |
29 | #include <sys/resource.h> |
30 | ||
31 | static pthread_key_t dirbuf_key; | |
32 | static pthread_key_t dir_freemap_key; | |
33 | static pthread_key_t attr_freemap_key; | |
34 | ||
35 | static void | |
36 | ts_alloc(pthread_key_t key, unsigned n, size_t size) | |
37 | { | |
38 | void *voidp; | |
39 | voidp = malloc((n)*(size)); | |
40 | if (voidp == NULL) { | |
41 | do_error(_("ts_alloc: cannot allocate thread specific storage\n")); | |
42 | /* NO RETURN */ | |
43 | return; | |
44 | } | |
45 | pthread_setspecific(key, voidp); | |
46 | } | |
47 | ||
48 | static void | |
3b6ac903 | 49 | ts_create(void) |
2814f3d6 MV |
50 | { |
51 | /* create thread specific keys */ | |
52 | pthread_key_create(&dirbuf_key, NULL); | |
53 | pthread_key_create(&dir_freemap_key, NULL); | |
54 | pthread_key_create(&attr_freemap_key, NULL); | |
3b6ac903 MV |
55 | } |
56 | ||
57 | void | |
58 | ts_init(void) | |
59 | { | |
2814f3d6 MV |
60 | |
61 | /* allocate thread specific storage */ | |
62 | ts_alloc(dirbuf_key, 1, ts_dirbuf_size); | |
63 | ts_alloc(dir_freemap_key, 1, ts_dir_freemap_size); | |
64 | ts_alloc(attr_freemap_key, 1, ts_attr_freemap_size); | |
65 | } | |
66 | ||
67 | void * | |
68 | ts_dirbuf(void) | |
69 | { | |
70 | return pthread_getspecific(dirbuf_key); | |
71 | } | |
72 | ||
73 | void * | |
74 | ts_dir_freemap(void) | |
75 | { | |
76 | return pthread_getspecific(dir_freemap_key); | |
77 | } | |
78 | ||
79 | void * | |
80 | ts_attr_freemap(void) | |
81 | { | |
82 | return pthread_getspecific(attr_freemap_key); | |
83 | } | |
84 | ||
85 | static void | |
86 | increase_rlimit(void) | |
87 | { | |
88 | struct rlimit rl; | |
89 | ||
90 | /* Increase limits */ | |
91 | if (getrlimit(RLIMIT_FSIZE, &rl) == -1) { | |
92 | perror("getrlimit"); | |
9ee7055c | 93 | fprintf(stderr, _("getrlimit(RLIMIT_FSIZE) failed!\n")); |
2814f3d6 MV |
94 | exit(1); |
95 | } | |
96 | if (rl.rlim_cur != RLIM_INFINITY) { | |
97 | rl.rlim_max = rl.rlim_cur = RLIM_INFINITY; | |
98 | if (setrlimit(RLIMIT_FSIZE, &rl) == -1) { | |
99 | perror("setrlimit"); | |
100 | fprintf(stderr, | |
9ee7055c | 101 | _("setrlimit failed - current: %lld, max: %lld\n"), |
6b43dc31 NS |
102 | (unsigned long long)rl.rlim_cur, |
103 | (unsigned long long)rl.rlim_max); | |
2814f3d6 MV |
104 | exit(1); |
105 | } | |
106 | } | |
107 | } | |
2bd0ea18 NS |
108 | |
109 | void | |
110 | xfs_init(libxfs_init_t *args) | |
111 | { | |
112 | memset(args, 0, sizeof(libxfs_init_t)); | |
113 | ||
114 | if (isa_file) { | |
115 | args->disfile = 1; | |
116 | args->dname = fs_name; | |
117 | args->volname = NULL; | |
118 | } else { | |
119 | args->disfile = 0; | |
120 | args->volname = fs_name; | |
121 | args->dname = NULL; | |
122 | } | |
123 | ||
124 | if (log_spec) { /* External log specified */ | |
125 | args->logname = log_name; | |
126 | args->lisfile = (isa_file?1:0); | |
127 | /* XXX assume data file also means log file */ | |
128 | /* REVISIT: Need to do fs sanity / log validity checking */ | |
129 | } | |
130 | ||
42a564ab ES |
131 | if (rt_spec) { /* RT device specified */ |
132 | args->rtname = rt_name; | |
133 | args->risfile = (isa_file?1:0); | |
134 | /* XXX assume data file also means rt file */ | |
135 | } | |
136 | ||
d0572de5 | 137 | args->usebuflock = do_prefetch; |
6089b6f0 | 138 | args->setblksize = !dangerously; |
b74a1f6a | 139 | args->isdirect = LIBXFS_DIRECT; |
2bd0ea18 NS |
140 | if (no_modify) |
141 | args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE); | |
6089b6f0 | 142 | else if (dangerously) |
c781939c | 143 | args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY); |
84306032 NT |
144 | else |
145 | args->isreadonly = LIBXFS_EXCLUSIVELY; | |
2bd0ea18 NS |
146 | |
147 | if (!libxfs_init(args)) | |
507f4e33 | 148 | do_error(_("couldn't initialize XFS library\n")); |
2814f3d6 | 149 | |
3b6ac903 | 150 | ts_create(); |
2814f3d6 MV |
151 | ts_init(); |
152 | increase_rlimit(); | |
2bd0ea18 | 153 | } |