diff options
author | Greg Hudson <ghudson@mit.edu> | 2014-01-24 16:52:47 -0500 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2014-02-20 20:42:47 -0500 |
commit | 6a4a4b7b5e3265e4a811a9fd72c2534e6c5f5fd4 (patch) | |
tree | c7dff9c0ec49836e715f901a97724d63088b8118 /src/lib/kdb/kdb_log.c | |
parent | 71d028f1054deb186807e7c8048218b82b478422 (diff) | |
download | krb5-6a4a4b7b5e3265e4a811a9fd72c2534e6c5f5fd4.tar.gz krb5-6a4a4b7b5e3265e4a811a9fd72c2534e6c5f5fd4.tar.xz krb5-6a4a4b7b5e3265e4a811a9fd72c2534e6c5f5fd4.zip |
Simplify ulog_map
Get rid of the caller parameter. The kproplog semantics (without -R)
for mapping the ulog are simple and almost completely different from
other users of the ulog, so implement them as a static helper in
kproplog. With hierarchical iprop, kpropd will need the same
semantics as FKCOMMAND and FKADMIND, which were already identical.
Get rid of the db_args parameter, since ulog_map no longer opens the
database after #7552.
Remove an inoperative lseek() call when creating a new ulog file.
Rename ulog_filesize to filesize and compute it from scratch each time
we use it, for easier analysis. If kdb_hmagic is zero, init the ulog
header but don't skip the rest of the function; it's possible that we
need to expand the ulog file. Remove an unneeded conditional before
calling extend_file_to for an existing ulog.
ticket: 7855
Diffstat (limited to 'src/lib/kdb/kdb_log.c')
-rw-r--r-- | src/lib/kdb/kdb_log.c | 95 |
1 files changed, 15 insertions, 80 deletions
diff --git a/src/lib/kdb/kdb_log.c b/src/lib/kdb/kdb_log.c index 378a497a31..6d60429989 100644 --- a/src/lib/kdb/kdb_log.c +++ b/src/lib/kdb/kdb_log.c @@ -445,60 +445,24 @@ ulog_init_header(krb5_context context) * Called by: if iprop_enabled then ulog_map(); * Assumes that the caller will terminate on ulog_map, hence munmap and * closing of the fd are implicitly performed by the caller. - * - * Semantics for various values of caller: - * - * - FKPROPLOG - * - * Don't create if it doesn't exist, map as MAP_PRIVATE. - * - * - FKPROPD - * - * Create and initialize if need be, map as MAP_SHARED. - * - * - FKCOMMAND - * - * Create and [re-]initialize if need be, size appropriately, map as - * MAP_SHARED. (Intended for kdb5_util create and kdb5_util load of - * non-iprop dump.) - * - * - FKADMIN - * - * Create and [re-]initialize if need be, size appropriately, map as - * MAP_SHARED, and check consistency and recover as necessary. (Intended - * for kadmind and kadmin.local.) - * - * Returns 0 on success else failure. */ krb5_error_code -ulog_map(krb5_context context, const char *logname, uint32_t ulogentries, - int caller, char **db_args) +ulog_map(krb5_context context, const char *logname, uint32_t ulogentries) { struct stat st; krb5_error_code retval; - uint32_t ulog_filesize; + uint32_t filesize; kdb_log_context *log_ctx; kdb_hlog_t *ulog = NULL; int ulogfd = -1; - ulog_filesize = sizeof(kdb_hlog_t); - if (stat(logname, &st) == -1) { - /* File doesn't exist so we exit with kproplog. */ - if (caller == FKPROPLOG) - return errno; - ulogfd = open(logname, O_RDWR | O_CREAT, 0600); if (ulogfd == -1) return errno; - if (lseek(ulogfd, 0L, SEEK_CUR) == -1) - return errno; - - if (caller == FKADMIND || caller == FKCOMMAND) - ulog_filesize += ulogentries * ULOG_BLOCK; - - if (extend_file_to(ulogfd, ulog_filesize) < 0) + filesize = sizeof(kdb_hlog_t) + ulogentries * ULOG_BLOCK; + if (extend_file_to(ulogfd, filesize) < 0) return errno; } else { ulogfd = open(logname, O_RDWR, 0600); @@ -506,21 +470,7 @@ ulog_map(krb5_context context, const char *logname, uint32_t ulogentries, return errno; } - if (caller == FKPROPLOG) { - if (fstat(ulogfd, &st) < 0) { - close(ulogfd); - return errno; - } - ulog_filesize = st.st_size; - - ulog = mmap(0, ulog_filesize, PROT_READ | PROT_WRITE, MAP_PRIVATE, - ulogfd, 0); - } else { - /* kadmind, kpropd, & kcommands should udpate stores. */ - ulog = mmap(0, MAXLOGLEN, PROT_READ | PROT_WRITE, MAP_SHARED, - ulogfd, 0); - } - + ulog = mmap(0, MAXLOGLEN, PROT_READ | PROT_WRITE, MAP_SHARED, ulogfd, 0); if (ulog == MAP_FAILED) { /* Can't map update log file to memory. */ close(ulogfd); @@ -544,27 +494,15 @@ ulog_map(krb5_context context, const char *logname, uint32_t ulogentries, if (retval) return retval; - if (ulog->kdb_hmagic != KDB_ULOG_HDR_MAGIC && ulog->kdb_hmagic != 0) { - unlock_ulog(context); - return KRB5_LOG_CORRUPT; - } - if (ulog->kdb_hmagic != KDB_ULOG_HDR_MAGIC) { + if (ulog->kdb_hmagic != 0) { + unlock_ulog(context); + return KRB5_LOG_CORRUPT; + } reset_header(ulog); - if (caller != FKPROPLOG) - sync_header(ulog); - unlock_ulog(context); - return 0; - } - - if (caller == FKPROPLOG || caller == FKPROPD) { - /* kproplog and kpropd don't need to do anything else. */ - unlock_ulog(context); - return 0; + sync_header(ulog); } - assert(caller == FKADMIND || caller == FKCOMMAND); - /* Reinit ulog if the log is being truncated or expanded after we have * circled. */ if (ulog->kdb_num != ulogentries) { @@ -575,14 +513,11 @@ ulog_map(krb5_context context, const char *logname, uint32_t ulogentries, sync_header(ulog); } - /* Expand ulog if we have specified a greater size. */ - if (ulog->kdb_num < ulogentries) { - ulog_filesize += ulogentries * ulog->kdb_block; - - if (extend_file_to(ulogfd, ulog_filesize) < 0) { - unlock_ulog(context); - return errno; - } + /* Expand the ulog file if it isn't big enough. */ + filesize = sizeof(kdb_hlog_t) + ulogentries * ulog->kdb_block; + if (extend_file_to(ulogfd, filesize) < 0) { + unlock_ulog(context); + return errno; } } unlock_ulog(context); |