1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright (c) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27#ifndef	DSVCD_DATASTORE_H
28#define	DSVCD_DATASTORE_H
29
30#pragma ident	"%Z%%M%	%I%	%E% SMI"
31
32#include <sys/types.h>
33#include <synch.h>
34#include <door.h>
35
36#include "container.h"
37
38/*
39 * Datastore-related data structures, functions and constants.  See
40 * comments in datastore.c for a description of how to use the exported
41 * functions.
42 */
43
44#ifdef	__cplusplus
45extern "C" {
46#endif
47
48#define	DSVCD_DS_HASH_SIZE	100
49
50/*
51 * A linked list of dsvcd_container_t structures.  Contains a lock,
52 * `cl_lock', which is used for controlling manipulation of `cl_head'.
53 */
54typedef struct {
55	mutex_t			cl_lock;	/* protects the list */
56	dsvcd_container_t	*cl_head;	/* linked list of containers */
57	uint8_t			cl_pad[8];	/* prevent false sharing */
58} dsvcd_container_list_t;
59
60/*
61 * Describes the underlying datastore itself.  There is exactly one
62 * dsvcd_datastore_t per datastore using doors (so currently, there are
63 * two: one for `ds_files' and one for `ds_data').  Contains per-datastore
64 * information, like the door descriptor being used by dsvclockd to listen
65 * to requests for this datastore, the datastore name, and a list of all
66 * open containers for this datastore.  Instances of this data structure
67 * are allocated when dsvclockd is started.
68 */
69typedef struct dsvcd_datastore {
70	char			*ds_name;	/* datastore name */
71	int			ds_doorfd;	/* datastore door */
72
73	/*
74	 * This hash is used to speed up the open() routine so that a given
75	 * container can be located quicker.  Hash based on the filename,
76	 * and use it as an index into the array..
77	 */
78	dsvcd_container_list_t	ds_hash[DSVCD_DS_HASH_SIZE];
79} dsvcd_datastore_t;
80
81typedef void dsvcd_svc_t(void *, dsvcd_request_t *, size_t, door_desc_t *,
82	uint_t);
83
84extern dsvcd_datastore_t *ds_create(const char *, dsvcd_svc_t *);
85extern void ds_destroy(dsvcd_datastore_t *);
86extern unsigned int ds_reap_containers(dsvcd_datastore_t *, unsigned int);
87extern void ds_release_container(dsvcd_datastore_t *, dsvcd_container_t *);
88extern dsvcd_container_t *ds_get_container(dsvcd_datastore_t *, const char *,
89    boolean_t);
90
91#ifdef	__cplusplus
92}
93#endif
94
95#endif	/* DSVCD_DATASTORE_H */
96