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