xref: /netbsd-src/external/bsd/openldap/dist/servers/slapd/back-wt/config.c (revision 549b59ed3ccf0d36d3097190a0db27b770f3a839)
1*549b59edSchristos /*	$NetBSD: config.c,v 1.2 2021/08/14 16:15:02 christos Exp $	*/
2e670fd5cSchristos 
3e670fd5cSchristos /* OpenLDAP WiredTiger backend */
4e670fd5cSchristos /* $OpenLDAP$ */
5e670fd5cSchristos /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6e670fd5cSchristos  *
7e670fd5cSchristos  * Copyright 2002-2021 The OpenLDAP Foundation.
8e670fd5cSchristos  * All rights reserved.
9e670fd5cSchristos  *
10e670fd5cSchristos  * Redistribution and use in source and binary forms, with or without
11e670fd5cSchristos  * modification, are permitted only as authorized by the OpenLDAP
12e670fd5cSchristos  * Public License.
13e670fd5cSchristos  *
14e670fd5cSchristos  * A copy of this license is available in the file LICENSE in the
15e670fd5cSchristos  * top-level directory of the distribution or, alternatively, at
16e670fd5cSchristos  * <http://www.OpenLDAP.org/license.html>.
17e670fd5cSchristos  */
18e670fd5cSchristos /* ACKNOWLEDGEMENTS:
19e670fd5cSchristos  * This work was developed by HAMANO Tsukasa <hamano@osstech.co.jp>
20e670fd5cSchristos  * based on back-bdb for inclusion in OpenLDAP Software.
21e670fd5cSchristos  * WiredTiger is a product of MongoDB Inc.
22e670fd5cSchristos  */
23e670fd5cSchristos 
24e670fd5cSchristos #include <sys/cdefs.h>
25*549b59edSchristos __RCSID("$NetBSD: config.c,v 1.2 2021/08/14 16:15:02 christos Exp $");
26e670fd5cSchristos 
27e670fd5cSchristos #include "portable.h"
28e670fd5cSchristos 
29e670fd5cSchristos #include <stdio.h>
30e670fd5cSchristos #include <ac/string.h>
31e670fd5cSchristos #include "back-wt.h"
32e670fd5cSchristos #include "slap-config.h"
33e670fd5cSchristos 
34e670fd5cSchristos #include "lutil.h"
35e670fd5cSchristos #include "ldap_rq.h"
36e670fd5cSchristos 
37e670fd5cSchristos static ConfigDriver wt_cf_gen;
38e670fd5cSchristos 
39e670fd5cSchristos enum {
40e670fd5cSchristos 	WT_DIRECTORY = 1,
41e670fd5cSchristos 	WT_CONFIG,
42e670fd5cSchristos 	WT_INDEX,
43e670fd5cSchristos };
44e670fd5cSchristos 
45e670fd5cSchristos static ConfigTable wtcfg[] = {
46e670fd5cSchristos     { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|WT_DIRECTORY,
47e670fd5cSchristos 	  wt_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
48e670fd5cSchristos 	  "DESC 'Directory for database content' "
49e670fd5cSchristos 	  "EQUALITY caseIgnoreMatch "
50e670fd5cSchristos 	  "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
51e670fd5cSchristos     { "wtconfig", "config", 2, 2, 0, ARG_STRING|ARG_MAGIC|WT_CONFIG,
52e670fd5cSchristos 	  wt_cf_gen, "( OLcfgDbAt:13.1 NAME 'olcWtConfig' "
53e670fd5cSchristos 	  "DESC 'Configuration for WiredTiger' "
54e670fd5cSchristos 	  "EQUALITY caseIgnoreMatch "
55e670fd5cSchristos 	  "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
56e670fd5cSchristos 	{ "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|WT_INDEX,
57e670fd5cSchristos 	  wt_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
58e670fd5cSchristos 	  "DESC 'Attribute index parameters' "
59e670fd5cSchristos 	  "EQUALITY caseIgnoreMatch "
60e670fd5cSchristos 	  "SYNTAX OMsDirectoryString )", NULL, NULL },
61e670fd5cSchristos 	{ NULL, NULL, 0, 0, 0, ARG_IGNORED,
62e670fd5cSchristos 		NULL, NULL, NULL, NULL }
63e670fd5cSchristos };
64e670fd5cSchristos 
65e670fd5cSchristos static ConfigOCs wtocs[] = {
66e670fd5cSchristos 	{ "( OLcfgDbOc:9.1 "
67e670fd5cSchristos 	  "NAME 'olcWtConfig' "
68e670fd5cSchristos 	  "DESC 'Wt backend configuration' "
69e670fd5cSchristos 	  "SUP olcDatabaseConfig "
70e670fd5cSchristos 	  "MUST olcDbDirectory "
71e670fd5cSchristos 	  "MAY ( olcWtConfig $ olcDbIndex ) )",
72e670fd5cSchristos 	  Cft_Database, wtcfg },
73e670fd5cSchristos 	{ NULL, 0, NULL }
74e670fd5cSchristos };
75e670fd5cSchristos 
76e670fd5cSchristos /* reindex entries on the fly */
77e670fd5cSchristos static void *
wt_online_index(void * ctx,void * arg)78e670fd5cSchristos wt_online_index( void *ctx, void *arg )
79e670fd5cSchristos {
80e670fd5cSchristos 	// Not implement yet
81e670fd5cSchristos }
82e670fd5cSchristos 
83e670fd5cSchristos /* Cleanup loose ends after Modify completes */
84e670fd5cSchristos static int
wt_cf_cleanup(ConfigArgs * c)85e670fd5cSchristos wt_cf_cleanup( ConfigArgs *c )
86e670fd5cSchristos {
87e670fd5cSchristos 	// Not implement yet
88e670fd5cSchristos 	return 0;
89e670fd5cSchristos }
90e670fd5cSchristos 
91e670fd5cSchristos static int
wt_cf_gen(ConfigArgs * c)92e670fd5cSchristos wt_cf_gen( ConfigArgs *c )
93e670fd5cSchristos {
94e670fd5cSchristos 	struct wt_info *wi = (struct wt_info *) c->be->be_private;
95e670fd5cSchristos 	int rc;
96e670fd5cSchristos 
97e670fd5cSchristos 	if(c->op == SLAP_CONFIG_EMIT) {
98e670fd5cSchristos 		rc = 0;
99e670fd5cSchristos 		// not implement yet
100e670fd5cSchristos 		return rc;
101e670fd5cSchristos 	}
102e670fd5cSchristos 
103e670fd5cSchristos 	switch( c->type ) {
104e670fd5cSchristos 	case WT_DIRECTORY:
105e670fd5cSchristos 		ch_free( wi->wi_dbenv_home );
106e670fd5cSchristos 		wi->wi_dbenv_home = c->value_string;
107e670fd5cSchristos 		break;
108e670fd5cSchristos 	case WT_CONFIG:
109e670fd5cSchristos 		ch_free( wi->wi_dbenv_config );
110e670fd5cSchristos 		wi->wi_dbenv_config = c->value_string;
111e670fd5cSchristos 		break;
112e670fd5cSchristos 
113e670fd5cSchristos 	case WT_INDEX:
114e670fd5cSchristos 		rc = wt_attr_index_config( wi, c->fname, c->lineno,
115e670fd5cSchristos 								   c->argc - 1, &c->argv[1], &c->reply);
116e670fd5cSchristos 
117e670fd5cSchristos 		if( rc != LDAP_SUCCESS ) return 1;
118e670fd5cSchristos 		wi->wi_flags |= WT_OPEN_INDEX;
119e670fd5cSchristos 
120e670fd5cSchristos 		if ( wi->wi_flags & WT_IS_OPEN ) {
121e670fd5cSchristos 			config_push_cleanup( c, wt_cf_cleanup );
122e670fd5cSchristos 
123e670fd5cSchristos 			if ( !wi->wi_index_task ) {
124e670fd5cSchristos 				/* Start the task as soon as we finish here. Set a long
125e670fd5cSchristos                  * interval (10 hours) so that it only gets scheduled once.
126e670fd5cSchristos                  */
127e670fd5cSchristos 				if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
128e670fd5cSchristos 					fprintf( stderr, "%s: "
129e670fd5cSchristos 							 "\"index\" must occur after \"suffix\".\n",
130e670fd5cSchristos 							 c->log );
131e670fd5cSchristos 					return 1;
132e670fd5cSchristos 				}
133e670fd5cSchristos 				ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
134e670fd5cSchristos 				wi->wi_index_task = ldap_pvt_runqueue_insert(&slapd_rq, 36000,
135e670fd5cSchristos 															 wt_online_index, c->be,
136e670fd5cSchristos 															 LDAP_XSTRING(wt_online_index),
137e670fd5cSchristos 															 c->be->be_suffix[0].bv_val );
138e670fd5cSchristos 				ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
139e670fd5cSchristos 			}
140e670fd5cSchristos 		}
141e670fd5cSchristos 		break;
142e670fd5cSchristos 
143e670fd5cSchristos 	}
144e670fd5cSchristos 	return LDAP_SUCCESS;
145e670fd5cSchristos }
146e670fd5cSchristos 
wt_back_init_cf(BackendInfo * bi)147e670fd5cSchristos int wt_back_init_cf( BackendInfo *bi )
148e670fd5cSchristos {
149e670fd5cSchristos 	int rc;
150e670fd5cSchristos 	bi->bi_cf_ocs = wtocs;
151e670fd5cSchristos 
152e670fd5cSchristos 	rc = config_register_schema( wtcfg, wtocs );
153e670fd5cSchristos 	if ( rc ) return rc;
154e670fd5cSchristos 	return 0;
155e670fd5cSchristos }
156e670fd5cSchristos 
157e670fd5cSchristos /*
158e670fd5cSchristos  * Local variables:
159e670fd5cSchristos  * indent-tabs-mode: t
160e670fd5cSchristos  * tab-width: 4
161e670fd5cSchristos  * c-basic-offset: 4
162e670fd5cSchristos  * End:
163e670fd5cSchristos  */
164