]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/init.c
repair: use a btree instead of a radix tree for the prefetch queue
[thirdparty/xfsprogs-dev.git] / repair / init.c
1 /*
2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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
7 * published by the Free Software Foundation.
8 *
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.
13 *
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
17 */
18
19 #include <libxfs.h>
20 #include "globals.h"
21 #include "agheader.h"
22 #include "protos.h"
23 #include "err_protos.h"
24 #include "pthread.h"
25 #include "avl.h"
26 #include "dir.h"
27 #include "incore.h"
28 #include "prefetch.h"
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
49 ts_create(void)
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);
55 }
56
57 void
58 ts_init(void)
59 {
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");
93 fprintf(stderr, _("getrlimit(RLIMIT_FSIZE) failed!\n"));
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,
101 _("setrlimit failed - current: %lld, max: %lld\n"),
102 (unsigned long long)rl.rlim_cur,
103 (unsigned long long)rl.rlim_max);
104 exit(1);
105 }
106 }
107 }
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
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
137 args->usebuflock = do_prefetch;
138 args->setblksize = !dangerously;
139 args->isdirect = LIBXFS_DIRECT;
140 if (no_modify)
141 args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE);
142 else if (dangerously)
143 args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY);
144 else
145 args->isreadonly = LIBXFS_EXCLUSIVELY;
146
147 if (!libxfs_init(args))
148 do_error(_("couldn't initialize XFS library\n"));
149
150 ts_create();
151 ts_init();
152 increase_rlimit();
153 }