1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 1999,2008 Oracle. All rights reserved. 5 * 6 * $Id: hash_meta.c,v 12.13 2008/01/08 20:58:34 bostic Exp $ 7 */ 8 9#include "db_config.h" 10 11#include "db_int.h" 12#include "dbinc/db_page.h" 13#include "dbinc/hash.h" 14#include "dbinc/lock.h" 15#include "dbinc/mp.h" 16 17/* 18 * Acquire the meta-data page. 19 * 20 * PUBLIC: int __ham_get_meta __P((DBC *)); 21 */ 22int 23__ham_get_meta(dbc) 24 DBC *dbc; 25{ 26 DB *dbp; 27 DB_MPOOLFILE *mpf; 28 HASH *hashp; 29 HASH_CURSOR *hcp; 30 int ret; 31 32 dbp = dbc->dbp; 33 mpf = dbp->mpf; 34 hashp = dbp->h_internal; 35 hcp = (HASH_CURSOR *)dbc->internal; 36 37 if ((ret = __db_lget(dbc, 0, 38 hashp->meta_pgno, DB_LOCK_READ, 0, &hcp->hlock)) != 0) 39 return (ret); 40 41 if ((ret = __memp_fget(mpf, &hashp->meta_pgno, 42 dbc->thread_info, dbc->txn, DB_MPOOL_CREATE, &hcp->hdr)) != 0) 43 (void)__LPUT(dbc, hcp->hlock); 44 45 return (ret); 46} 47 48/* 49 * Release the meta-data page. 50 * 51 * PUBLIC: int __ham_release_meta __P((DBC *)); 52 */ 53int 54__ham_release_meta(dbc) 55 DBC *dbc; 56{ 57 DB_MPOOLFILE *mpf; 58 HASH_CURSOR *hcp; 59 int ret; 60 61 mpf = dbc->dbp->mpf; 62 hcp = (HASH_CURSOR *)dbc->internal; 63 64 if (hcp->hdr != NULL) { 65 if ((ret = __memp_fput(mpf, 66 dbc->thread_info, hcp->hdr, dbc->priority)) != 0) 67 return (ret); 68 hcp->hdr = NULL; 69 } 70 71 return (__TLPUT(dbc, hcp->hlock)); 72} 73 74/* 75 * Mark the meta-data page dirty. 76 * 77 * PUBLIC: int __ham_dirty_meta __P((DBC *, u_int32_t)); 78 */ 79int 80__ham_dirty_meta(dbc, flags) 81 DBC *dbc; 82 u_int32_t flags; 83{ 84 DB *dbp; 85 HASH *hashp; 86 HASH_CURSOR *hcp; 87 int ret; 88 89 dbp = dbc->dbp; 90 hashp = dbp->h_internal; 91 hcp = (HASH_CURSOR *)dbc->internal; 92 93 if ((ret = __db_lget(dbc, LCK_COUPLE, 94 hashp->meta_pgno, DB_LOCK_WRITE, 0, &hcp->hlock)) != 0) 95 return (ret); 96 97 return (__memp_dirty(dbp->mpf, 98 &hcp->hdr, dbc->thread_info, dbc->txn, dbc->priority, flags)); 99} 100