rpm  5.4.15
rpmtxn.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #include <rpmiotypes.h>
8 #include <rpmtypes.h>
9 
10 #include <rpmtag.h>
11 #define _RPMDB_INTERNAL
12 #include <rpmdb.h>
13 #include <rpmtxn.h>
14 
15 #include "debug.h"
16 
17 /*@access rpmdb @*/
18 /*@access dbiIndex @*/
19 
20 int _rpmtxn_debug = 0;
21 
22 uint32_t rpmtxnId(rpmtxn txn)
23 {
24  DB_TXN * _txn = (DB_TXN *) txn;
25  uint32_t rc = (_txn ? _txn->id(_txn) : 0);
26  return rc;
27 }
28 
29 const char * rpmtxnName(rpmtxn txn)
30 {
31  DB_TXN * _txn = (DB_TXN *) txn;
32  const char * N = NULL;
33  int rc = (_txn ? _txn->get_name(_txn, &N) : ENOTSUP);
34  rc = rc;
35  return N;
36 }
37 
38 int rpmtxnSetName(rpmtxn txn, const char * N)
39 {
40  DB_TXN * _txn = (DB_TXN *) txn;
41  int rc = (_txn ? _txn->set_name(_txn, N) : ENOTSUP);
42 if (_rpmtxn_debug)
43 fprintf(stderr, "<-- %s(%p,%s) rc %d\n", "txn->set_name", _txn, N, rc);
44  return rc;
45 }
46 
48 {
49  DB_TXN * _txn = (DB_TXN *) txn;
50  int rc = (_txn ? _txn->abort(_txn) : ENOTSUP);
51 if (_rpmtxn_debug)
52 fprintf(stderr, "<-- %s(%p) rc %d\n", "txn->abort", _txn, rc);
53  return rc;
54 }
55 
56 int rpmtxnBegin(rpmdb rpmdb, rpmtxn parent, rpmtxn * txnp)
57 {
58  DB_ENV * dbenv = (DB_ENV *) (rpmdb ? rpmdb->db_dbenv : NULL);
59  DB_TXN * _parent = (DB_TXN *) parent;
60  DB_TXN * _txn = NULL;
61  u_int32_t _flags = 0;
62  int rc = (dbenv && rpmdb->_dbi[0]->dbi_eflags & DB_INIT_TXN)
63  ? dbenv->txn_begin(dbenv, _parent, &_txn, _flags) : ENOTSUP;
64  if (!rc) {
65  if (txnp != NULL)
66  *txnp = _txn;
67  else
68  rpmdb->db_txn = _txn;
69  }
70 if (_rpmtxn_debug)
71 fprintf(stderr, "<-- %s(%p,%p,%p,0x%x) txn %p rc %d\n", "dbenv->txn_begin", dbenv, _parent, &_txn, (unsigned)_flags, _txn, rc);
72  return rc;
73 }
74 
76 {
77  DB_TXN * _txn = (DB_TXN *) txn;
78  u_int32_t _flags = 0;
79  int rc = (_txn ? _txn->commit(_txn, _flags) : ENOTSUP);
80 if (_rpmtxn_debug)
81 fprintf(stderr, "<-- %s(%p,0x%x) rc %d\n", "txn->commit", _txn, (unsigned)_flags, rc);
82  return rc;
83 }
84 
86 {
87  DB_ENV * dbenv = (DB_ENV *) (rpmdb ? rpmdb->db_dbenv : NULL);
88  u_int32_t _kbytes = 0;
89  u_int32_t _minutes = 0;
90  u_int32_t _flags = 0;
91  int rc = (dbenv && rpmdb->_dbi[0]->dbi_eflags & DB_INIT_TXN)
92  ? dbenv->txn_checkpoint(dbenv, _kbytes, _minutes, _flags) : ENOTSUP;
93 if (_rpmtxn_debug)
94 fprintf(stderr, "<-- %s(%p,%u,%u,0x%x) rc %d\n", "dbenv->txn_checkpoint", dbenv, (unsigned)_kbytes, (unsigned)_minutes, (unsigned)_flags, rc);
95  return rc;
96 }
97 
98 #ifdef NOTYET
99 int rpmtxnDiscard(rpmtxn txn)
100 {
101  DB_TXN * _txn = (DB_TXN *) txn;
102  uint32_t _flags = 0;
103  int rc = (_txn ? _txn->discard(_txn, _flags) : ENOTSUP);
104  return rc;
105 }
106 
107 int rpmtxnPrepare(rpmtxn txn)
108 {
109  DB_TXN * _txn = (DB_TXN *) txn;
110  uint8_t _gid[DB_GID_SIZE] = {0};
111  int rc = (_txn ? _txn->prepare(_txn, _gid) : ENOTSUP);
112  return rc;
113 }
114 
115 int rpmtxnRecover(rpmdb rpmdb)
116 {
117  DB_ENV * dbenv = (DB_ENV *) rpmdb->db_dbenv;
118  DB_PREPLIST _preplist[32];
119  long _count = (sizeof(_preplist) / sizeof(_preplist[0]));
120  long _got = 0;
121  uint32_t _flags = DB_FIRST;
122  int rc = 0;
123  int i;
124 
125  while (1) {
126  rc = dbenv->txn_recover(dbenv, _preplist, _count, &_got, _flags);
127  _flags = DB_NEXT;
128  if (rc || _got == 0)
129  break;
130  for (i = 0; i < _got; i++) {
131  DB_TXN * _txn = _preplist[i].txn;
132  uint32_t _tflags = 0;
133  (void) _txn->discard(_txn, _tflags);
134  }
135  }
136  return rc;
137 }
138 
139 #endif /* NOTYET */
uint32_t(* id)(DB_TXN *)
Definition: db_emu.h:80
int rpmtxnBegin(rpmdb rpmdb, rpmtxn parent, rpmtxn *txnp)
Definition: rpmtxn.c:56
int rpmtxnCheckpoint(rpmdb rpmdb)
Definition: rpmtxn.c:85
int rpmtxnSetName(rpmtxn txn, const char *N)
Definition: rpmtxn.c:38
int rpmtxnCommit(rpmtxn txn)
Definition: rpmtxn.c:75
int(* set_name)(DB_TXN *, const char *)
Definition: db_emu.h:81
const char * rpmtxnName(rpmtxn txn)
Definition: rpmtxn.c:29
int(* txn_begin)(DB_ENV *, DB_TXN *, DB_TXN **, uint32_t)
Definition: db_emu.h:48
int(* commit)(DB_TXN *, uint32_t)
Definition: db_emu.h:78
#define DB_INIT_TXN
Definition: db_emu.h:117
struct rpmdb_s * rpmdb
Database of headers and tag value indices.
Definition: rpmtypes.h:43
#define DB_NEXT
Definition: db_emu.h:86
uint32_t rpmtxnId(rpmtxn txn)
Definition: rpmtxn.c:22
int(* get_name)(DB_TXN *, const char **)
Definition: db_emu.h:79
void * rpmtxn
Definition: rpmtxn.h:14
const char const int i
Definition: bson.h:778
int(* txn_checkpoint)(DB_ENV *, uint32_t, uint32_t, uint32_t)
Definition: db_emu.h:49
int _rpmtxn_debug
Definition: rpmtxn.c:20
Database transaction wrappers.
int(* abort)(DB_TXN *)
Definition: db_emu.h:77
Access RPM indices using Berkeley DB interface(s).
int rpmtxnAbort(rpmtxn txn)
Definition: rpmtxn.c:47