]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2bd0ea18 | 2 | /* |
da23017d NS |
3 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
2bd0ea18 NS |
5 | */ |
6 | ||
6b803e5a | 7 | #include "libxfs.h" |
2bd0ea18 NS |
8 | #include "globals.h" |
9 | #include "agheader.h" | |
10 | #include "protos.h" | |
11 | #include "err_protos.h" | |
2814f3d6 | 12 | #include "pthread.h" |
2556c98b | 13 | #include "avl.h" |
610f3285 | 14 | #include "bmap.h" |
2556c98b | 15 | #include "incore.h" |
cb5b3ef4 | 16 | #include "prefetch.h" |
2814f3d6 MV |
17 | #include <sys/resource.h> |
18 | ||
2814f3d6 | 19 | static void |
3b6ac903 | 20 | ts_create(void) |
2814f3d6 | 21 | { |
610f3285 BN |
22 | pthread_key_create(&dblkmap_key, NULL); |
23 | pthread_key_create(&ablkmap_key, NULL); | |
3b6ac903 MV |
24 | } |
25 | ||
2814f3d6 MV |
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"); | |
9ee7055c | 34 | fprintf(stderr, _("getrlimit(RLIMIT_FSIZE) failed!\n")); |
2814f3d6 MV |
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, | |
9ee7055c | 42 | _("setrlimit failed - current: %lld, max: %lld\n"), |
6b43dc31 NS |
43 | (unsigned long long)rl.rlim_cur, |
44 | (unsigned long long)rl.rlim_max); | |
2814f3d6 MV |
45 | exit(1); |
46 | } | |
47 | } | |
48 | } | |
2bd0ea18 NS |
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 | ||
42a564ab ES |
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 | ||
d0572de5 | 78 | args->usebuflock = do_prefetch; |
29622975 | 79 | args->setblksize = 0; |
b74a1f6a | 80 | args->isdirect = LIBXFS_DIRECT; |
2bd0ea18 NS |
81 | if (no_modify) |
82 | args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE); | |
6089b6f0 | 83 | else if (dangerously) |
c781939c | 84 | args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY); |
84306032 NT |
85 | else |
86 | args->isreadonly = LIBXFS_EXCLUSIVELY; | |
2bd0ea18 | 87 | |
03091fc2 ES |
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 | } | |
507f4e33 | 97 | do_error(_("couldn't initialize XFS library\n")); |
03091fc2 | 98 | } |
2814f3d6 | 99 | |
3b6ac903 | 100 | ts_create(); |
2814f3d6 | 101 | increase_rlimit(); |
4c0a98ae | 102 | pftrace_init(); |
2bd0ea18 | 103 | } |