1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <sys/types.h>
33 #include "syscall_AIX.h"
35 #include <sys/syscall.h>
37 #include <sys/utsname.h>
38 #ifdef HAVE_NETINET_IN_H
39 #include <netinet/in.h>
41 #include <sys/socket.h>
42 #ifdef HAVE_ARPA_INET_H
43 #include <arpa/inet.h>
45 #ifdef HAVE_CATAMOUNT_DATA_H
46 #include <catamount/data.h>
52 unsigned int libcfs_subsystem_debug = ~0 - (S_LNET | S_LND);
53 unsigned int libcfs_debug = 0;
55 struct task_struct *current;
57 void *inter_module_get(char *arg)
59 if (!strcmp(arg, "ldlm_cli_cancel_unused"))
60 return ldlm_cli_cancel_unused;
61 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
62 return ldlm_namespace_cleanup;
63 else if (!strcmp(arg, "ldlm_replay_locks"))
64 return ldlm_replay_locks;
65 #ifdef HAVE_QUOTA_SUPPORT
66 else if (!strcmp(arg, "osc_quota_interface"))
67 return &osc_quota_interface;
68 else if (!strcmp(arg, "mdc_quota_interface"))
69 return &mdc_quota_interface;
70 else if (!strcmp(arg, "lov_quota_interface"))
71 return &lov_quota_interface;
78 * random number generator stuff
81 #ifdef HAVE_GETHOSTBYNAME
82 static int get_ipv4_addr()
84 struct utsname myname;
88 if (uname(&myname) < 0)
91 hptr = gethostbyname(myname.nodename);
93 hptr->h_addrtype != AF_INET ||
94 *hptr->h_addr_list == NULL) {
95 CWARN("Warning: fail to get local IPv4 address\n");
99 ip = ntohl(*((int *) *hptr->h_addr_list));
105 void liblustre_init_random()
110 #ifdef LIBLUSTRE_USE_URANDOM
112 _rand_dev_fd = syscall(SYS_open, "/dev/urandom", O_RDONLY);
113 if (_rand_dev_fd >= 0) {
114 if (syscall(SYS_read, _rand_dev_fd,
115 &seed, sizeof(seed)) == sizeof(seed)) {
116 ll_srand(seed[0], seed[1]);
119 syscall(SYS_close, _rand_dev_fd);
121 #endif /* LIBLUSTRE_USE_URANDOM */
123 #ifdef HAVE_GETHOSTBYNAME
124 seed[0] = get_ipv4_addr();
128 gettimeofday(&tv, NULL);
129 ll_srand(tv.tv_sec ^ __swab32(seed[0]), tv.tv_usec ^__swab32(getpid()));
132 static void init_capability(__u32 *res)
136 cap_flag_value_t capval;
141 syscap = cap_get_proc();
143 CWARN("Warning: failed to get system capability, "
148 for (i = 0; i < sizeof(cap_value_t) * 8; i++) {
149 if (!cap_get_flag(syscap, i, CAP_EFFECTIVE, &capval)) {
150 if (capval == CAP_SET) {
157 * set fake cap flags to ship to linux server
158 * from client platforms that have none (eg. catamount)
159 * full capability for root
160 * no capability for anybody else
162 #define FAKE_ROOT_CAP 0x1ffffeff
163 #define FAKE_USER_CAP 0
165 *res = (current->fsuid == 0) ? FAKE_ROOT_CAP: FAKE_USER_CAP;
169 int in_group_p(gid_t gid)
173 if (gid == current->fsgid)
176 for (i = 0; i < current->ngroups; i++) {
177 if (gid == current->groups[i])
184 int liblustre_init_current(char *comm)
186 current = malloc(sizeof(*current));
188 CERROR("Not enough memory\n");
192 strncpy(current->comm, comm, sizeof(current->comm));
193 current->pid = getpid();
194 current->gid = getgid();
195 current->fsuid = geteuid();
196 current->fsgid = getegid();
197 memset(¤t->pending, 0, sizeof(current->pending));
199 current->max_groups = sysconf(_SC_NGROUPS_MAX);
200 current->groups = malloc(sizeof(gid_t) * current->max_groups);
201 if (!current->groups) {
202 CERROR("Not enough memory\n");
205 current->ngroups = getgroups(current->max_groups, current->groups);
206 if (current->ngroups < 0) {
207 perror("Error getgroups");
211 init_capability(¤t->cap_effective);
216 int init_lib_portals()
221 rc = libcfs_debug_init(5 * 1024 * 1024);
223 CERROR("libcfs_debug_init() failed: %d\n", rc);
229 CERROR("LNetInit() failed: %d\n", rc);
235 extern void ptlrpc_exit_portals(void);
236 void cleanup_lib_portals()
238 libcfs_debug_cleanup();
239 ptlrpc_exit_portals();