Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

log_method.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1999-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: log_method.c,v 12.4 2005/07/21 18:21:25 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #endif
00018 
00019 #include "db_int.h"
00020 #include "dbinc/log.h"
00021 
00022 /*
00023  * __log_dbenv_create --
00024  *      Log specific initialization of the DB_ENV structure.
00025  *
00026  * PUBLIC: void __log_dbenv_create __P((DB_ENV *));
00027  */
00028 void
00029 __log_dbenv_create(dbenv)
00030         DB_ENV *dbenv;
00031 {
00032         /*
00033          * !!!
00034          * Our caller has not yet had the opportunity to reset the panic
00035          * state or turn off mutex locking, and so we can neither check
00036          * the panic state or acquire a mutex in the DB_ENV create path.
00037          */
00038         dbenv->lg_bsize = 0;
00039         dbenv->lg_regionmax = LG_BASE_REGION_SIZE;
00040 }
00041 
00042 /*
00043  * PUBLIC: int __log_get_lg_bsize __P((DB_ENV *, u_int32_t *));
00044  */
00045 int
00046 __log_get_lg_bsize(dbenv, lg_bsizep)
00047         DB_ENV *dbenv;
00048         u_int32_t *lg_bsizep;
00049 {
00050         ENV_NOT_CONFIGURED(dbenv,
00051             dbenv->lg_handle, "DB_ENV->get_lg_bsize", DB_INIT_LOG);
00052 
00053         if (LOGGING_ON(dbenv)) {
00054                 /* Cannot be set after open, no lock required to read. */
00055                 *lg_bsizep = ((LOG *)
00056                     ((DB_LOG *)dbenv->lg_handle)->reginfo.primary)->buffer_size;
00057         } else
00058                 *lg_bsizep = dbenv->lg_bsize;
00059         return (0);
00060 }
00061 
00062 /*
00063  * __log_set_lg_bsize --
00064  *      DB_ENV->set_lg_bsize.
00065  *
00066  * PUBLIC: int __log_set_lg_bsize __P((DB_ENV *, u_int32_t));
00067  */
00068 int
00069 __log_set_lg_bsize(dbenv, lg_bsize)
00070         DB_ENV *dbenv;
00071         u_int32_t lg_bsize;
00072 {
00073         ENV_ILLEGAL_AFTER_OPEN(dbenv, "DB_ENV->set_lg_bsize");
00074 
00075         dbenv->lg_bsize = lg_bsize;
00076         return (0);
00077 }
00078 
00079 /*
00080  * PUBLIC: int __log_get_lg_filemode __P((DB_ENV *, int *));
00081  */
00082 int
00083 __log_get_lg_filemode(dbenv, lg_modep)
00084         DB_ENV *dbenv;
00085         int *lg_modep;
00086 {
00087         DB_LOG *dblp;
00088 
00089         ENV_NOT_CONFIGURED(dbenv,
00090             dbenv->lg_handle, "DB_ENV->get_lg_filemode", DB_INIT_LOG);
00091 
00092         if (LOGGING_ON(dbenv)) {
00093                 dblp = dbenv->lg_handle;
00094                 LOG_SYSTEM_LOCK(dbenv);
00095                 *lg_modep = ((LOG *)dblp->reginfo.primary)->filemode;
00096                 LOG_SYSTEM_UNLOCK(dbenv);
00097         } else
00098                 *lg_modep = dbenv->lg_filemode;
00099 
00100         return (0);
00101 }
00102 
00103 /*
00104  * __log_set_lg_filemode --
00105  *      DB_ENV->set_lg_filemode.
00106  *
00107  * PUBLIC: int __log_set_lg_filemode __P((DB_ENV *, int));
00108  */
00109 int
00110 __log_set_lg_filemode(dbenv, lg_mode)
00111         DB_ENV *dbenv;
00112         int lg_mode;
00113 {
00114         DB_LOG *dblp;
00115         LOG *lp;
00116 
00117         ENV_NOT_CONFIGURED(dbenv,
00118             dbenv->lg_handle, "DB_ENV->set_lg_filemode", DB_INIT_LOG);
00119 
00120         if (LOGGING_ON(dbenv)) {
00121                 dblp = dbenv->lg_handle;
00122                 lp = dblp->reginfo.primary;
00123                 LOG_SYSTEM_LOCK(dbenv);
00124                 lp->filemode = lg_mode;
00125                 LOG_SYSTEM_UNLOCK(dbenv);
00126         } else
00127                 dbenv->lg_filemode = lg_mode;
00128 
00129         return (0);
00130 }
00131 
00132 /*
00133  * PUBLIC: int __log_get_lg_max __P((DB_ENV *, u_int32_t *));
00134  */
00135 int
00136 __log_get_lg_max(dbenv, lg_maxp)
00137         DB_ENV *dbenv;
00138         u_int32_t *lg_maxp;
00139 {
00140         DB_LOG *dblp;
00141 
00142         ENV_NOT_CONFIGURED(dbenv,
00143             dbenv->lg_handle, "DB_ENV->get_lg_max", DB_INIT_LOG);
00144 
00145         if (LOGGING_ON(dbenv)) {
00146                 dblp = dbenv->lg_handle;
00147                 LOG_SYSTEM_LOCK(dbenv);
00148                 *lg_maxp = ((LOG *)dblp->reginfo.primary)->log_nsize;
00149                 LOG_SYSTEM_UNLOCK(dbenv);
00150         } else
00151                 *lg_maxp = dbenv->lg_size;
00152 
00153         return (0);
00154 }
00155 
00156 /*
00157  * __log_set_lg_max --
00158  *      DB_ENV->set_lg_max.
00159  *
00160  * PUBLIC: int __log_set_lg_max __P((DB_ENV *, u_int32_t));
00161  */
00162 int
00163 __log_set_lg_max(dbenv, lg_max)
00164         DB_ENV *dbenv;
00165         u_int32_t lg_max;
00166 {
00167         DB_LOG *dblp;
00168         LOG *lp;
00169         int ret;
00170 
00171         ENV_NOT_CONFIGURED(dbenv,
00172             dbenv->lg_handle, "DB_ENV->set_lg_max", DB_INIT_LOG);
00173 
00174         if (LOGGING_ON(dbenv)) {
00175                 if ((ret = __log_check_sizes(dbenv, lg_max, 0)) != 0)
00176                         return (ret);
00177                 dblp = dbenv->lg_handle;
00178                 lp = dblp->reginfo.primary;
00179                 LOG_SYSTEM_LOCK(dbenv);
00180                 lp->log_nsize = lg_max;
00181                 LOG_SYSTEM_UNLOCK(dbenv);
00182         } else
00183                 dbenv->lg_size = lg_max;
00184 
00185         return (0);
00186 }
00187 
00188 /*
00189  * PUBLIC: int __log_get_lg_regionmax __P((DB_ENV *, u_int32_t *));
00190  */
00191 int
00192 __log_get_lg_regionmax(dbenv, lg_regionmaxp)
00193         DB_ENV *dbenv;
00194         u_int32_t *lg_regionmaxp;
00195 {
00196         ENV_NOT_CONFIGURED(dbenv,
00197             dbenv->lg_handle, "DB_ENV->get_lg_regionmax", DB_INIT_LOG);
00198 
00199         if (LOGGING_ON(dbenv)) {
00200                 /* Cannot be set after open, no lock required to read. */
00201                 *lg_regionmaxp = ((LOG *)
00202                     ((DB_LOG *)dbenv->lg_handle)->reginfo.primary)->regionmax;
00203         } else
00204                 *lg_regionmaxp = dbenv->lg_regionmax;
00205         return (0);
00206 }
00207 
00208 /*
00209  * __log_set_lg_regionmax --
00210  *      DB_ENV->set_lg_regionmax.
00211  *
00212  * PUBLIC: int __log_set_lg_regionmax __P((DB_ENV *, u_int32_t));
00213  */
00214 int
00215 __log_set_lg_regionmax(dbenv, lg_regionmax)
00216         DB_ENV *dbenv;
00217         u_int32_t lg_regionmax;
00218 {
00219         ENV_ILLEGAL_AFTER_OPEN(dbenv, "DB_ENV->set_lg_regionmax");
00220 
00221                                         /* Let's not be silly. */
00222         if (lg_regionmax != 0 && lg_regionmax < LG_BASE_REGION_SIZE) {
00223                 __db_err(dbenv,
00224                     "log file size must be >= %d", LG_BASE_REGION_SIZE);
00225                 return (EINVAL);
00226         }
00227 
00228         dbenv->lg_regionmax = lg_regionmax;
00229         return (0);
00230 }
00231 
00232 /*
00233  * PUBLIC: int __log_get_lg_dir __P((DB_ENV *, const char **));
00234  */
00235 int
00236 __log_get_lg_dir(dbenv, dirp)
00237         DB_ENV *dbenv;
00238         const char **dirp;
00239 {
00240         *dirp = dbenv->db_log_dir;
00241         return (0);
00242 }
00243 
00244 /*
00245  * __log_set_lg_dir --
00246  *      DB_ENV->set_lg_dir.
00247  *
00248  * PUBLIC: int __log_set_lg_dir __P((DB_ENV *, const char *));
00249  */
00250 int
00251 __log_set_lg_dir(dbenv, dir)
00252         DB_ENV *dbenv;
00253         const char *dir;
00254 {
00255         if (dbenv->db_log_dir != NULL)
00256                 __os_free(dbenv, dbenv->db_log_dir);
00257         return (__os_strdup(dbenv, dir, &dbenv->db_log_dir));
00258 }
00259 
00260 /*
00261  * __log_get_flags --
00262  *      DB_ENV->get_flags.
00263  *
00264  * PUBLIC: void __log_get_flags __P((DB_ENV *, u_int32_t *));
00265  */
00266 void
00267 __log_get_flags(dbenv, flagsp)
00268         DB_ENV *dbenv;
00269         u_int32_t *flagsp;
00270 {
00271         DB_LOG *dblp;
00272         LOG *lp;
00273         u_int32_t flags;
00274 
00275         if ((dblp = dbenv->lg_handle) == NULL)
00276                 return;
00277 
00278         lp = dblp->reginfo.primary;
00279 
00280         flags = *flagsp;
00281         if (lp->db_log_autoremove)
00282                 LF_SET(DB_LOG_AUTOREMOVE);
00283         else
00284                 LF_CLR(DB_LOG_AUTOREMOVE);
00285         if (lp->db_log_inmemory)
00286                 LF_SET(DB_LOG_INMEMORY);
00287         else
00288                 LF_CLR(DB_LOG_INMEMORY);
00289         *flagsp = flags;
00290 }
00291 
00292 /*
00293  * __log_set_flags --
00294  *      DB_ENV->set_flags.
00295  *
00296  * PUBLIC: void __log_set_flags __P((DB_ENV *, u_int32_t, int));
00297  */
00298 void
00299 __log_set_flags(dbenv, flags, on)
00300         DB_ENV *dbenv;
00301         u_int32_t flags;
00302         int on;
00303 {
00304         DB_LOG *dblp;
00305         LOG *lp;
00306 
00307         if ((dblp = dbenv->lg_handle) == NULL)
00308                 return;
00309 
00310         lp = dblp->reginfo.primary;
00311 
00312         if (LF_ISSET(DB_LOG_AUTOREMOVE))
00313                 lp->db_log_autoremove = on ? 1 : 0;
00314         if (LF_ISSET(DB_LOG_INMEMORY))
00315                 lp->db_log_inmemory = on ? 1 : 0;
00316 }
00317 
00318 /*
00319  * __log_check_sizes --
00320  *      Makes sure that the log file size and log buffer size are compatible.
00321  *
00322  * PUBLIC: int __log_check_sizes __P((DB_ENV *, u_int32_t, u_int32_t));
00323  */
00324 int
00325 __log_check_sizes(dbenv, lg_max, lg_bsize)
00326         DB_ENV *dbenv;
00327         u_int32_t lg_max;
00328         u_int32_t lg_bsize;
00329 {
00330         LOG *lp;
00331         int inmem;
00332 
00333         if (LOGGING_ON(dbenv)) {
00334                 lp = ((DB_LOG *)dbenv->lg_handle)->reginfo.primary;
00335                 inmem = lp->db_log_inmemory;
00336                 lg_bsize = lp->buffer_size;
00337         } else
00338                 inmem = (F_ISSET(dbenv, DB_ENV_LOG_INMEMORY) != 0);
00339 
00340         if (inmem) {
00341                 if (lg_bsize == 0)
00342                         lg_bsize = LG_BSIZE_INMEM;
00343                 if (lg_max == 0)
00344                         lg_max = LG_MAX_INMEM;
00345 
00346                 if (lg_bsize <= lg_max) {
00347                         __db_err(dbenv,
00348                   "in-memory log buffer must be larger than the log file size");
00349                         return (EINVAL);
00350                 }
00351         }
00352 
00353         return (0);
00354 }

Generated on Sun Dec 25 12:14:40 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2