File: main.c

package info (click to toggle)
zfs-fuse 0.7.0-8
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,780 kB
  • sloc: ansic: 153,932; sh: 9,648; asm: 1,690; perl: 367; xml: 300; python: 269; makefile: 83
file content (90 lines) | stat: -rw-r--r-- 2,609 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2006 Ricardo Correia.
 * Use is subject to license terms.
 */

#include <sys/types.h>
#include <sys/debug.h>
#include <sys/policy.h>
#include <sys/kmem.h>
#include <sys/utsname.h>

#include <stdio.h>
#include <unistd.h>
#include <strings.h>

#include "vfs.h"

char hw_serial[11];

int ncpus;
uint64_t physmem;
unsigned long _pagesize;
unsigned int _pageshift;
kmem_cache_t *vnode_cache;
extern void system_taskq_init();

void libsolkerncompat_init()
{
	/* LINUX */
	ncpus = sysconf(_SC_NPROCESSORS_CONF);
	physmem = sysconf(_SC_PHYS_PAGES);
	_pagesize = sysconf(_SC_PAGESIZE);
	_pageshift = ffs(_pagesize) - 1;
	pwd_buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
	grp_buflen = sysconf(_SC_GETGR_R_SIZE_MAX);

	uname(&utsname);
	snprintf(hw_serial, sizeof(hw_serial), "%ld", gethostid());

	VERIFY(ncpus > 0 && physmem > 0);

#ifdef DEBUG
	printf("hostname = %s\n", utsname.nodename);
	printf("hw_serial = %s\n", hw_serial);
	printf("ncpus = %i\n", ncpus);
	printf("physmem = %llu pages (%.2f GB)\n", (unsigned long long) physmem, (double) physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));
	printf("pagesize = %li, pageshift: %i\n", _pagesize, _pageshift);
	printf("pwd_buflen = %li, grp_buflen = %li\n\n", pwd_buflen, grp_buflen);
#endif

	vnode_cache = kmem_cache_create("vnode_t", sizeof(vnode_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
	VERIFY(vnode_cache != NULL);

	vfs_init();

	/* Carefull here : umem_init is called on another core when using a multi core cpu
	 * but it must have finished when calling taskq_init.
	 * My tests with my dual core laptop is ok, but I am not sure it works everywhere */
	taskq_init();
	system_taskq_init();
}

void libsolkerncompat_exit()
{
	kmem_cache_destroy(vnode_cache);

	vfs_exit();
	taskq_destroy(system_taskq);
}