Coda Distributed File System
hdb.h
Go to the documentation of this file.
1/* BLURB gpl
2
3 Coda File System
4 Release 8
5
6 Copyright (c) 1987-2025 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU General Public Licence Version 2, as shown in the
11file LICENSE. The technical and financial contributors to Coda are
12listed in the file CREDITS.
13
14 Additional copyrights
15 none currently
16
17#*/
18
19/*
20 * Hoard database management: first part used by Venus & hoard, latter only by Venus
21 */
22
23#ifndef _VENUS_HDB_H_
24#define _VENUS_HDB_H_ 1
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <stdio.h>
31#include <sys/param.h>
32#include <time.h>
33#include <netdb.h>
34
35#ifdef __cplusplus
36}
37#endif
38
39/* interfaces */
40#include <vice.h>
41#include <coda.h>
42
43#define HDB_ASSERT(ex) \
44 { \
45 if (!(ex)) { \
46 CHOKE("Assertion failed: file \"%s\", line %d\n", __FILE__, \
47 __LINE__); \
48 } \
49 }
50
51/* Hoard priority range. */
52#define H_MAX_PRI 1000
53#define H_DFLT_PRI 10
54#define H_MIN_PRI 1
55
56/* Hoard attribute flags. */
57#define H_INHERIT 1 /* New children inherit their parent's hoard status. */
58#define H_CHILDREN 2 /* Meta-expand directory to include its children. */
59#define H_DESCENDENTS \
60 4 /* Meta-expand directory to include all its descendents. */
61#define H_DFLT_ATTRS 0
62
63/* ***** Definition of pioctl message structures. ***** */
64
65/* Should be in venusioctl.h! -JJK */
66
68 uid_t cuid;
69 int spare;
70};
71
73 VolumeId vid;
74 char realm[MAXHOSTNAMELEN + 1];
78};
79
81 VolumeId vid;
82 char realm[MAXHOSTNAMELEN + 1];
84};
85
88 uid_t luid;
89 int spare;
90};
91
93 int spare;
94};
95
98 uid_t luid;
99 int spare;
101};
102
103/* **************************************** */
104
105#ifdef VENUS /* Portion below here not used in vtools/hoard.c */
106
107/* from util */
108#include <bstree.h>
109#include <olist.h>
110#include <rec_olist.h>
111#include <ohash.h>
112#include <rec_ohash.h>
113
114/* from venus */
115#include "fso.h"
116#include "venusrecov.h"
117#include "venus.private.h"
118
119/*
120 * Allocated HDB entries are linked into a hash table, keyed by <vid, name>.
121 * Unallocated entries are linked into a free-list.
122 *
123 * A transient "name-context" is associated with each allocated entry.
124 * A name-context may be linked into one of two priority queues, depending on its state.
125 * There are "suspect" and "indigent" queues for name-context's of those
126 * two states. Name-context's in the third state, "valid," are not in a priority queue.
127 * An HDB entry which has been meta-expanded will have additional name-contexts
128 * associated with it.
129 *
130 */
131
132/* Forward declarations. */
133class hdb;
134class hdb_key;
135class hdbent;
136class hdb_iterator;
137class namectxt;
138
139/* ***** Constants ***** */
140
141#define HDB (rvg->recov_HDB)
142const int HDB_MagicNumber = 5551212;
143const int HDB_NBUCKETS = 2048;
144const int HDBENT_MagicNumber = 8204933;
145const int HDBMaxFreeEntries = 32;
146
147/* ***** Types ***** */
148
149enum hdbd_request
150{
151 HdbAdd,
152 HdbDelete,
153 HdbClear,
154 HdbList,
155 HdbWalk,
156 HdbVerify,
157 HdbEnable,
158 HdbDisable
159};
160
161/*
162 * Allow user to specify if periodic hoard walks should happen. I put this outside
163 * of the hdb class to avoid the necessity of a reinit. -- DCS 5/5/94
164 */
165
166extern char PeriodicWalksAllowed;
167
168/* used to be member of class hdb (Satya 3/31/95) */
170
171class hdb {
172 friend void HDB_Init(void);
173 friend void HDBD_Init(void);
174 friend void HDBDaemon(void);
175 friend class hdbent;
176 friend class hdb_iterator;
177 friend class namectxt;
178 friend void RecovInit();
179
180 int MagicNumber;
181
182 /* Size parameters. */
183 int MaxHDBEs;
184
185 /* The table. */
186 rec_ohashtab htab;
187
188 /* The free list. */
189 rec_olist freelist;
190
191 /* The priority queue. */
192 /*T*/ bstree *prioq;
193
194 /* Advice Information */
195 long TimeOfLastDemandWalk;
196 int NumHoardWalkAdvice;
197 int SolicitAdvice;
198
199 /* Constructors, destructors. */
200 void *operator new(size_t) REQUIRES_TRANSACTION;
201 void operator delete(void *);
202 hdb();
203 void ResetTransient();
204 ~hdb() { abort(); }
205
206 /* Allocation/Deallocation routines. */
207 hdbent *Create(VolumeId, char *realm, char *name, uid_t, int, int,
209
210public:
211 hdbent *Find(VolumeId, char *realm, char *name);
212
213 /* The external interface. */
214 int Add(hdb_add_msg *, uid_t local_id) EXCLUDES_TRANSACTION;
215 int Delete(hdb_delete_msg *, uid_t local_id) EXCLUDES_TRANSACTION;
216 int Clear(hdb_clear_msg *, uid_t local_id) EXCLUDES_TRANSACTION;
217 int List(hdb_list_msg *, uid_t local_id);
218 int Walk(hdb_walk_msg *, uid_t local_id) EXCLUDES_TRANSACTION;
219 int Verify(hdb_verify_msg *, uid_t local_id);
220 int Enable(hdb_walk_msg *, uid_t local_id);
221 int Disable(hdb_walk_msg *, uid_t local_id);
222
223 void ResetUser(uid_t);
224
225 /* Helper Routines hdb::Walk */
226 void ValidateCacheStatus(vproc *, int *, int *) EXCLUDES_TRANSACTION;
227 void ListPriorityQueue();
228 void WalkPriorityQueue(vproc *, int *, int *) EXCLUDES_TRANSACTION;
229 int CalculateTotalBytesToFetch();
230 void StatusWalk(vproc *, int *, int *) EXCLUDES_TRANSACTION;
231 void DataWalk(vproc *, int, int) EXCLUDES_TRANSACTION;
232 void PostWalkStatus();
233
234 /* Advice Related*/
235 void SetSolicitAdvice(int uid)
236 {
237 LOG(0, ("SetSolicitAdvice: uid=%d\n", uid));
238 SolicitAdvice = uid;
239 }
240
241 void SetDemandWalkTime() EXCLUDES_TRANSACTION;
242 long GetDemandWalkTime();
243
244 void print() { print(stdout); }
245 void print(FILE *fp)
246 {
247 fflush(fp);
248 print(fileno(fp));
249 }
250 void print(int, int = 0);
251};
252
253class hdb_key {
254public:
255 VolumeId vid;
256 char *realm;
257 char *name;
258
259 hdb_key(VolumeId, char *realm, char *name);
260};
261
262class hdbent {
263 friend void HDB_Init();
264 friend class hdb;
265 friend class hdb_iterator;
266 friend class fsobj;
267
268 int MagicNumber;
269
270 /* Key. */
271 VolumeId vid;
272 char *realm;
273 char *name;
274
275 /* Assoc(key). */
276 uid_t uid;
277 int priority;
278 unsigned expand_children : 1; /* meta-expand children */
279 unsigned expand_descendents : 1; /* meta-expand descendents */
280 unsigned time : 30; /* currently unused! */
281 /*T*/ namectxt *nc; /* pre-computed path expansion */
282
283 /* Linkage. */
284 rec_olink tbl_handle; /* link for {allocated-table, free-list} */
285
286 /* Constructors, destructors. */
287 void *operator new(size_t) REQUIRES_TRANSACTION;
288 hdbent(VolumeId, char *, char *, uid_t, int, int, int) REQUIRES_TRANSACTION;
289 void ResetTransient() EXCLUDES_TRANSACTION;
290 ~hdbent() REQUIRES_TRANSACTION;
291 void operator delete(void *);
292
293public:
294 void print() { print(stdout); }
295 void print(FILE *fp)
296 {
297 fflush(fp);
298 print(fileno(fp));
299 }
300 void print(int);
301 void printsuspect(int, int);
302};
303
304class hdb_iterator : public rec_ohashtab_iterator {
305 uid_t uid;
306
307public:
308 hdb_iterator();
309 hdb_iterator(uid_t);
310 hdb_iterator(hdb_key *);
311 hdbent *operator()();
312};
313
314enum pestate
315{
316 PeValid, /* expansion need not be checked */
317 PeSuspect, /* expansion must be checked at next walk */
318 PeIndigent, /* expansion is impeded due to resource shortage */
319 PeInconsistent /* expansion is impeded due to inconsistency */
320};
321
322class namectxt {
323 friend class fsobj;
324 friend class hdb;
325 friend class hdbent;
326 friend class hdb_iterator;
327 friend int MetaExpand(PDirEntry de, void *hook);
328 friend int NC_PriorityFN(bsnode *, bsnode *);
329 friend void NotifyUsersOfKillEvent(dlist *, int);
330
331 /* Key. */
332 VenusFid cdir; /* starting directory of expansion */
333 char *path; /* subsequent components */
334
335 /* Assoc(key). */
336 uid_t uid; /* owner of this context */
337 int priority; /* priority to be used for resource allocation */
338 enum pestate state; /* {Valid, Suspect, Indigent} */
339 unsigned inuse : 1; /* state cannot change when inuse */
340 unsigned dying : 1; /* commit suicide when next !inuse */
341 unsigned demote_pending : 1; /* transit to "suspect" state when next !inuse */
342 unsigned
343 meta_expanded : 1; /* this context was created due to meta-expansion */
344 unsigned expand_children : 1; /* meta-expand the children of bound object */
345 unsigned
346 expand_descendents : 1; /* meta-expand the descendents of bound object */
347 unsigned depth : 10; /* depth of meta-expansion (0 if not meta-expanded) */
348 unsigned random : 16; /* for binary-tree balancing */
349 dlist expansion; /* ordered set of bindings */
350 dlist_iterator *next; /* shadow list for validation */
351
352 /* Expander info. */
353 dlist *children; /* list of expanded children */
354 VenusFid expander_fid; /* Fid of expanded directory */
355 ViceVersionVector expander_vv; /* VersionVector of expanded directory */
356 unsigned long expander_dv; /* DataVersion of expanded directory */
357
358 /* Expandee info. */
359 namectxt *parent; /* back pointer to expander */
360 dlink child_link; /* link for expander's children list */
361
362 /* Linkage. */
363 bsnode prio_handle; /* link for HDB priority queues */
364 dlink fl_handle; /* link for freelist */
365
366 /* Private member functions. */
367 void hold(); /* inhibit state transitions */
368 void release(); /* permit state transitions */
369 void Transit(enum pestate); /* transit to specified state */
370 void Kill(); /* delete this context at first opportunity */
371 void KillChildren(); /* delete children contexts at first opportunity */
372 pestate CheckExpansion() EXCLUDES_TRANSACTION; /* return next state */
374
375public:
376 void *operator new(size_t);
377 namectxt(VenusFid *, char *, uid_t, int, int, int);
378 namectxt(namectxt *, char *);
379 namectxt(namectxt &); /* not supported! */
380 int operator=(namectxt &); /* not supported! */
381 ~namectxt();
382 void operator delete(void *);
383
384 void
385 Demote(int recursive =
386 0); /* --> immediate or eventual transition to suspect state */
387 void CheckComponent(fsobj *);
388
389 int GetPriority() { return (priority); }
390 uid_t GetUid() { return (uid); }
391
392 void print(void * = 0) { print(stdout); }
393 void print(FILE *fp, void * = 0)
394 {
395 fflush(fp);
396 print(fileno(fp));
397 }
398 void print(int, void * = 0);
399 void printsuspect(int, int);
400 void getpath(char *);
401 void putmsg(int fd, const char *reason, int include_modifier);
402};
403
404#ifdef VENUSDEBUG
405/* Too many problems in trying to keep these variables static member of class namectxt */
406extern int NameCtxt_allocs;
407extern int NameCtxt_deallocs;
408#endif /* VENUSDEBUG */
409
410/* ***** Variables ***** */
411
412extern int HDBEs;
413extern int IndigentCount;
414
415/* ***** Functions/Procedures ***** */
416
417/* hdb.c */
419extern int NC_PriorityFN(bsnode *, bsnode *);
420
421/* hdb_daemon.c */
422extern void HDBD_Init(void);
423extern int HDBD_Request(hdbd_request, void *,
424 struct uarea *u) EXCLUDES_TRANSACTION;
425extern long HDBD_GetNextHoardWalkTime();
426
427#define PRINT_HDBDREQTYPE(type) \
428 ((type) == HdbAdd ? "Add" : \
429 (type) == HdbDelete ? "Delete" : \
430 (type) == HdbClear ? "Clear" : \
431 (type) == HdbList ? "List" : \
432 (type) == HdbWalk ? "Walk" : \
433 (type) == HdbVerify ? "Verify" : \
434 (type) == HdbEnable ? "Enable" : \
435 (type) == HdbDisable ? "Disable" : \
436 "???")
437
438#define PRINT_PESTATE(state) \
439 ((state) == PeValid ? "Valid" : \
440 (state) == PeSuspect ? "Suspect" : \
441 (state) == PeIndigent ? "Indigent" : \
442 (state) == PeInconsistent ? "Inconsistent" : \
443 "???")
444
445#endif /* VENUS */
446
447#endif /* _VENUS_HDB_H_ */
Definition: bstree.h:80
Definition: bstree.h:49
Definition: dlist.h:80
Definition: dlist.h:50
Definition: fso.h:343
friend class namectxt
Definition: fso.h:350
void print()
Definition: fso.h:699
Definition: rec_ohash.h:85
rec_olink * operator()()
Definition: rec_ohash.cc:248
Definition: rec_ohash.h:47
Definition: rec_olist.h:46
Definition: vproc.h:151
#define CODA_MAXPATHLEN
Definition: coda.h:115
int Create(long *, char *, long *)
int Delete(long *, char *)
#define REQUIRES_TRANSACTION
Definition: coda_tsa.h:107
#define EXCLUDES_TRANSACTION
Definition: coda_tsa.h:108
void HDB_Init()
Definition: hdb.cc:115
int MetaExpand(struct DirEntry *entry, long hook)
int NC_PriorityFN(bsnode *b1, bsnode *b2)
Definition: hdb.cc:2271
char PeriodicWalksAllowed
Definition: hdb.cc:90
int HDBEs
Definition: hdb.cc:86
int IndigentCount
Definition: hdb.cc:105
int HDBD_Request(hdbd_request type, void *request, struct uarea *u)
Definition: hdb_daemon.cc:133
void HDBDaemon(void)
Definition: hdb_daemon.cc:92
long HDBD_GetNextHoardWalkTime()
Definition: hdb_daemon.cc:84
void HDBD_Init(void)
Definition: hdb_daemon.cc:78
name
Definition: pwdtopdbtool.py:40
uid
Definition: pwdtopdbtool.py:40
stdout
Definition: volusage.py:12
void path(char *pathname, char *direc, char *file)
Definition: path.c:53
PROCESS parent
Definition: smon2.c:80
Definition: codadir.h:66
Definition: venusfid.h:24
Definition: hdb.h:72
char realm[MAXHOSTNAMELEN+1]
Definition: hdb.h:74
int attributes
Definition: hdb.h:77
int priority
Definition: hdb.h:76
char name[CODA_MAXPATHLEN]
Definition: hdb.h:75
VolumeId vid
Definition: hdb.h:73
Definition: hdb.h:67
uid_t cuid
Definition: hdb.h:68
int spare
Definition: hdb.h:69
Definition: hdb.h:80
char name[CODA_MAXPATHLEN]
Definition: hdb.h:83
char realm[MAXHOSTNAMELEN+1]
Definition: hdb.h:82
VolumeId vid
Definition: hdb.h:81
Definition: hdb.h:86
uid_t luid
Definition: hdb.h:88
int spare
Definition: hdb.h:89
char outfile[CODA_MAXPATHLEN]
Definition: hdb.h:87
Definition: hdb.h:96
int verbosity
Definition: hdb.h:100
uid_t luid
Definition: hdb.h:98
char outfile[CODA_MAXPATHLEN]
Definition: hdb.h:97
int spare
Definition: hdb.h:99
Definition: hdb.h:92
int spare
Definition: hdb.h:93
Definition: vproc.h:118
dlink * Find(int priority, uid_t uid)
Definition: tallyent.cc:140
#define LOG(level, stmt)
Definition: venus.private.h:164
void RecovInit(void)
Definition: venusrecov.cc:227