]>
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" |
2556c98b | 29 | #include "radix-tree.h" |
2814f3d6 MV |
30 | #include <sys/resource.h> |
31 | ||
32 | static pthread_key_t dirbuf_key; | |
33 | static pthread_key_t dir_freemap_key; | |
34 | static pthread_key_t attr_freemap_key; | |
35 | ||
36 | static void | |
37 | ts_alloc(pthread_key_t key, unsigned n, size_t size) | |
38 | { | |
39 | void *voidp; | |
40 | voidp = malloc((n)*(size)); | |
41 | if (voidp == NULL) { | |
42 | do_error(_("ts_alloc: cannot allocate thread specific storage\n")); | |
43 | /* NO RETURN */ | |
44 | return; | |
45 | } | |
46 | pthread_setspecific(key, voidp); | |
47 | } | |
48 | ||
49 | static void | |
3b6ac903 | 50 | ts_create(void) |
2814f3d6 MV |
51 | { |
52 | /* create thread specific keys */ | |
53 | pthread_key_create(&dirbuf_key, NULL); | |
54 | pthread_key_create(&dir_freemap_key, NULL); | |
55 | pthread_key_create(&attr_freemap_key, NULL); | |
3b6ac903 MV |
56 | } |
57 | ||
58 | void | |
59 | ts_init(void) | |
60 | { | |
2814f3d6 MV |
61 | |
62 | /* allocate thread specific storage */ | |
63 | ts_alloc(dirbuf_key, 1, ts_dirbuf_size); | |
64 | ts_alloc(dir_freemap_key, 1, ts_dir_freemap_size); | |
65 | ts_alloc(attr_freemap_key, 1, ts_attr_freemap_size); | |
66 | } | |
67 | ||
68 | void * | |
69 | ts_dirbuf(void) | |
70 | { | |
71 | return pthread_getspecific(dirbuf_key); | |
72 | } | |
73 | ||
74 | void * | |
75 | ts_dir_freemap(void) | |
76 | { | |
77 | return pthread_getspecific(dir_freemap_key); | |
78 | } | |
79 | ||
80 | void * | |
81 | ts_attr_freemap(void) | |
82 | { | |
83 | return pthread_getspecific(attr_freemap_key); | |
84 | } | |
85 | ||
86 | static void | |
87 | increase_rlimit(void) | |
88 | { | |
89 | struct rlimit rl; | |
90 | ||
91 | /* Increase limits */ | |
92 | if (getrlimit(RLIMIT_FSIZE, &rl) == -1) { | |
93 | perror("getrlimit"); | |
9ee7055c | 94 | fprintf(stderr, _("getrlimit(RLIMIT_FSIZE) failed!\n")); |
2814f3d6 MV |
95 | exit(1); |
96 | } | |
97 | if (rl.rlim_cur != RLIM_INFINITY) { | |
98 | rl.rlim_max = rl.rlim_cur = RLIM_INFINITY; | |
99 | if (setrlimit(RLIMIT_FSIZE, &rl) == -1) { | |
100 | perror("setrlimit"); | |
101 | fprintf(stderr, | |
9ee7055c | 102 | _("setrlimit failed - current: %lld, max: %lld\n"), |
6b43dc31 NS |
103 | (unsigned long long)rl.rlim_cur, |
104 | (unsigned long long)rl.rlim_max); | |
2814f3d6 MV |
105 | exit(1); |
106 | } | |
107 | } | |
108 | } | |
2bd0ea18 NS |
109 | |
110 | void | |
111 | xfs_init(libxfs_init_t *args) | |
112 | { | |
113 | memset(args, 0, sizeof(libxfs_init_t)); | |
114 | ||
115 | if (isa_file) { | |
116 | args->disfile = 1; | |
117 | args->dname = fs_name; | |
118 | args->volname = NULL; | |
119 | } else { | |
120 | args->disfile = 0; | |
121 | args->volname = fs_name; | |
122 | args->dname = NULL; | |
123 | } | |
124 | ||
125 | if (log_spec) { /* External log specified */ | |
126 | args->logname = log_name; | |
127 | args->lisfile = (isa_file?1:0); | |
128 | /* XXX assume data file also means log file */ | |
129 | /* REVISIT: Need to do fs sanity / log validity checking */ | |
130 | } | |
131 | ||
42a564ab ES |
132 | if (rt_spec) { /* RT device specified */ |
133 | args->rtname = rt_name; | |
134 | args->risfile = (isa_file?1:0); | |
135 | /* XXX assume data file also means rt file */ | |
136 | } | |
137 | ||
d0572de5 | 138 | args->usebuflock = do_prefetch; |
6089b6f0 | 139 | args->setblksize = !dangerously; |
b74a1f6a | 140 | args->isdirect = LIBXFS_DIRECT; |
2bd0ea18 NS |
141 | if (no_modify) |
142 | args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE); | |
6089b6f0 | 143 | else if (dangerously) |
c781939c | 144 | args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY); |
2bd0ea18 NS |
145 | |
146 | if (!libxfs_init(args)) | |
507f4e33 | 147 | do_error(_("couldn't initialize XFS library\n")); |
2814f3d6 | 148 | |
3b6ac903 | 149 | ts_create(); |
2814f3d6 MV |
150 | ts_init(); |
151 | increase_rlimit(); | |
2556c98b | 152 | radix_tree_init(); |
2bd0ea18 | 153 | } |