]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/init.c
libxfs: refactor manage_zones()
[thirdparty/xfsprogs-dev.git] / repair / init.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include "libxfs.h"
8 #include "globals.h"
9 #include "agheader.h"
10 #include "protos.h"
11 #include "err_protos.h"
12 #include "pthread.h"
13 #include "avl.h"
14 #include "bmap.h"
15 #include "incore.h"
16 #include "prefetch.h"
17 #include <sys/resource.h>
18
19 static void
20 ts_create(void)
21 {
22 pthread_key_create(&dblkmap_key, NULL);
23 pthread_key_create(&ablkmap_key, NULL);
24 }
25
26 static void
27 increase_rlimit(void)
28 {
29 struct rlimit rl;
30
31 /* Increase limits */
32 if (getrlimit(RLIMIT_FSIZE, &rl) == -1) {
33 perror("getrlimit");
34 fprintf(stderr, _("getrlimit(RLIMIT_FSIZE) failed!\n"));
35 exit(1);
36 }
37 if (rl.rlim_cur != RLIM_INFINITY) {
38 rl.rlim_max = rl.rlim_cur = RLIM_INFINITY;
39 if (setrlimit(RLIMIT_FSIZE, &rl) == -1) {
40 perror("setrlimit");
41 fprintf(stderr,
42 _("setrlimit failed - current: %lld, max: %lld\n"),
43 (unsigned long long)rl.rlim_cur,
44 (unsigned long long)rl.rlim_max);
45 exit(1);
46 }
47 }
48 }
49
50 void
51 xfs_init(libxfs_init_t *args)
52 {
53 memset(args, 0, sizeof(libxfs_init_t));
54
55 if (isa_file) {
56 args->disfile = 1;
57 args->dname = fs_name;
58 args->volname = NULL;
59 } else {
60 args->disfile = 0;
61 args->volname = fs_name;
62 args->dname = NULL;
63 }
64
65 if (log_spec) { /* External log specified */
66 args->logname = log_name;
67 args->lisfile = (isa_file?1:0);
68 /* XXX assume data file also means log file */
69 /* REVISIT: Need to do fs sanity / log validity checking */
70 }
71
72 if (rt_spec) { /* RT device specified */
73 args->rtname = rt_name;
74 args->risfile = (isa_file?1:0);
75 /* XXX assume data file also means rt file */
76 }
77
78 args->usebuflock = do_prefetch;
79 args->setblksize = 0;
80 args->isdirect = LIBXFS_DIRECT;
81 if (no_modify)
82 args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE);
83 else if (dangerously)
84 args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY);
85 else
86 args->isreadonly = LIBXFS_EXCLUSIVELY;
87
88 if (!libxfs_init(args)) {
89 /* would -d be an option? */
90 if (!no_modify && !dangerously) {
91 args->isreadonly = (LIBXFS_ISINACTIVE |
92 LIBXFS_DANGEROUSLY);
93 if (libxfs_init(args))
94 fprintf(stderr,
95 _("Unmount or use the dangerous (-d) option to repair a read-only mounted filesystem\n"));
96 }
97 do_error(_("couldn't initialize XFS library\n"));
98 }
99
100 ts_create();
101 increase_rlimit();
102 pftrace_init();
103 }