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

xa_map.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: xa_map.c,v 12.4 2005/10/13 20:42:34 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 
00015 #include <string.h>
00016 #endif
00017 
00018 #include "db_int.h"
00019 #include "dbinc/txn.h"
00020 
00021 /*
00022  * This file contains all the mapping information that we need to support
00023  * the DB/XA interface.
00024  */
00025 
00026 /*
00027  * __db_rmid_to_env
00028  *      Return the environment associated with a given XA rmid.
00029  *
00030  * PUBLIC: int __db_rmid_to_env __P((int rmid, DB_ENV **envp));
00031  */
00032 int
00033 __db_rmid_to_env(rmid, dbenvp)
00034         int rmid;
00035         DB_ENV **dbenvp;
00036 {
00037         DB_ENV *dbenv;
00038 
00039         dbenv = TAILQ_FIRST(&DB_GLOBAL(db_envq));
00040         if (dbenv != NULL && dbenv->xa_rmid == rmid) {
00041                 *dbenvp = dbenv;
00042                 return (0);
00043         }
00044 
00045         /*
00046          * When we map an rmid, move that environment to be the first one in
00047          * the list of environments, so we acquire the correct environment
00048          * in DB->open.
00049          */
00050         for (; dbenv != NULL; dbenv = TAILQ_NEXT(dbenv, links))
00051                 if (dbenv->xa_rmid == rmid) {
00052                         TAILQ_REMOVE(&DB_GLOBAL(db_envq), dbenv, links);
00053                         TAILQ_INSERT_HEAD(&DB_GLOBAL(db_envq), dbenv, links);
00054                         *dbenvp = dbenv;
00055                         return (0);
00056                 }
00057 
00058         return (1);
00059 }
00060 
00061 /*
00062  * __db_xid_to_txn
00063  *      Return the txn that corresponds to this XID.
00064  *
00065  * PUBLIC: int __db_xid_to_txn __P((DB_ENV *, XID *, roff_t *));
00066  */
00067 int
00068 __db_xid_to_txn(dbenv, xid, offp)
00069         DB_ENV *dbenv;
00070         XID *xid;
00071         roff_t *offp;
00072 {
00073         struct __txn_detail *td;
00074 
00075         return (__txn_map_gid(dbenv, (u_int8_t *)xid->data, &td, offp));
00076 }
00077 
00078 /*
00079  * __db_map_rmid
00080  *      Create a mapping between the specified rmid and environment.
00081  *
00082  * PUBLIC: int __db_map_rmid __P((int, DB_ENV *));
00083  */
00084 int
00085 __db_map_rmid(rmid, dbenv)
00086         int rmid;
00087         DB_ENV *dbenv;
00088 {
00089         dbenv->xa_rmid = rmid;
00090         TAILQ_INSERT_TAIL(&DB_GLOBAL(db_envq), dbenv, links);
00091         return (0);
00092 }
00093 
00094 /*
00095  * __db_unmap_rmid
00096  *      Destroy the mapping for the given rmid.
00097  *
00098  * PUBLIC: int __db_unmap_rmid __P((int));
00099  */
00100 int
00101 __db_unmap_rmid(rmid)
00102         int rmid;
00103 {
00104         DB_ENV *e;
00105 
00106         for (e = TAILQ_FIRST(&DB_GLOBAL(db_envq));
00107             e->xa_rmid != rmid;
00108             e = TAILQ_NEXT(e, links))
00109             ;
00110 
00111         if (e == NULL)
00112                 return (EINVAL);
00113 
00114         TAILQ_REMOVE(&DB_GLOBAL(db_envq), e, links);
00115         return (0);
00116 }
00117 
00118 /*
00119  * __db_map_xid
00120  *      Create a mapping between this XID and the transaction
00121  *      "td" in the shared region.
00122  *
00123  * PUBLIC: int __db_map_xid __P((DB_ENV *, XID *, TXN_DETAIL *));
00124  */
00125 int
00126 __db_map_xid(dbenv, xid, td)
00127         DB_ENV *dbenv;
00128         XID *xid;
00129         TXN_DETAIL *td;
00130 {
00131         TXN_SYSTEM_LOCK(dbenv);
00132         memcpy(td->xid, xid->data, XIDDATASIZE);
00133         td->bqual = (u_int32_t)xid->bqual_length;
00134         td->gtrid = (u_int32_t)xid->gtrid_length;
00135         td->format = (int32_t)xid->formatID;
00136         TXN_SYSTEM_UNLOCK(dbenv);
00137 
00138         return (0);
00139 }
00140 
00141 /*
00142  * __db_unmap_xid
00143  *      Destroy the mapping for the specified XID.
00144  *
00145  * PUBLIC: void __db_unmap_xid __P((DB_ENV *, XID *, size_t));
00146  */
00147 
00148 void
00149 __db_unmap_xid(dbenv, xid, off)
00150         DB_ENV *dbenv;
00151         XID *xid;
00152         size_t off;
00153 {
00154         TXN_DETAIL *td;
00155 
00156         COMPQUIET(xid, NULL);
00157 
00158         td = R_ADDR(&((DB_TXNMGR *)dbenv->tx_handle)->reginfo, off);
00159         memset(td->xid, 0, sizeof(td->xid));
00160 }

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