Coda Distributed File System
cvnode.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 * cvnode.h *
21 ********************************/
22
23#ifndef _CVNODE_H_
24#define _CVNODE_H_ 1
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <lwp/lwp.h>
31#include <lwp/lock.h>
32#include <rpc2/errors.h>
33#include <util.h>
34#include <codadir.h>
35#include <prs.h>
36#include <al.h>
37
38#ifdef __cplusplus
39}
40#endif
41
42#include <coda_tsa.h>
43#include <voltypes.h>
44#include <inconsist.h>
45#include <rec_smolist.h>
46#include <rec_dlist.h>
47#include "vicelock.h"
48#include "lka.h"
49#define ROOTVNODE 1
50
51typedef int VnodeType;
52
53/* more lock types -- leave small #s for lock.h */
54#define TRY_READ_LOCK 16
55#define TRY_WRITE_LOCK 32
56
57/*typedef enum {vNull=0, vFile=1, vDirectory=2, vSymlink=3} VnodeType;*/
58#define vNull 0
59#define vFile 1
60#define vDirectory 2
61#define vSymlink 3
62
63/*typedef enum {vLarge=0,vSmall=1} VnodeClass;*/
64#define vLarge 0
65#define vSmall 1
66
67typedef int VnodeClass;
68#define VNODECLASSWIDTH 1
69#define VNODECLASSMASK ((1 << VNODECLASSWIDTH) - 1)
70#define nVNODECLASSES (VNODECLASSMASK + 1)
71
73 struct Vnode *lruHead; /* Head of list of vnodes of this class */
74 int diskSize; /* size of vnode disk object, power of 2 */
75 int residentSize; /* resident size of vnode */
76 int cacheSize; /* Vnode cache size */
77 bit32 magic; /* Magic number for this type of vnode,
78 for as long as we're using vnode magic
79 numbers */
80 int allocs; /* Total number of successful allocation
81 requests; this is the same as the number
82 of sanity checks on the vnode index */
83 int gets, reads; /* Number of VGetVnodes and corresponding
84 reads */
85 int writes; /* Number of vnode writes */
86};
87
89
90#define vnodeTypeToClass(type) ((type) == vDirectory ? vLarge : vSmall)
91#define vnodeIdToClass(vnodeId) ((vnodeId - 1) & VNODECLASSMASK)
92#define vnodeIdToBitNumber(v) (((v) - 1) >> VNODECLASSWIDTH)
93#define bitNumberToVnodeNumber(b, vclass) \
94 (((b) << VNODECLASSWIDTH) + (vclass) + 1)
95#define vnodeIsDirectory(vnodeNumber) (vnodeIdToClass(vnodeNumber) == vLarge)
96
97/* VnodeDiskObject: Structure of vnode stored in RVM */
98typedef struct VnodeDiskObjectStruct {
99 VnodeType type : 3; /* Vnode is file, directory, symbolic link
100 or not allocated */
101 unsigned cloned : 1; /* This vnode was cloned--therefore the inode
102 is copy-on-write; only set for directories*/
103 unsigned modeBits : 12; /* Unix mode bits */
104 bit16 linkCount; /* Number of directory references to vnode (from single
105 directory only!) */
106 bit32 length; /* Number of bytes in this file */
107 Unique_t uniquifier; /* Uniquifier for the vnode; assigned from the volume
108 uniquifier (actually from nextVnodeUnique in the
109 Volume structure) */
110 FileVersion dataVersion; /* version number of the data */
111
112/* inode number for a vnode allocated but not used for creation */
113#define NEWVNODEINODE ((PDirInode) - 1)
114
115 union {
116 Inode inodeNumber; /* container file containing file/symlink data */
117 PDirInode dirNode; /* pointer to RVM copy of the directory data. */
119 /* version vector is updated atomically with the data */
120 ViceVersionVector versionvector; /* Coda file version vector for this vnode */
121 int vol_index; /* index of vnode's volume in recoverable volume array */
122 Date_t unixModifyTime; /* set by user */
123 UserId author; /* Userid of the last user storing the file */
124 UserId owner; /* Userid of the user who created the file */
125 VnodeId vparent; /* Parent directory vnode */
126 Unique_t uparent; /* Parent directory uniquifier */
127 bit32 vnodeMagic; /* Magic number--mainly for file server
128 paranoia checks */
129#define SMALLVNODEMAGIC 0xda8c041F
130#define LARGEVNODEMAGIC 0xad8765fe
131 /* Vnode magic can be removed, someday, if we run need the room. Simply
132 have to be sure that the thing we replace can be VNODEMAGIC, rather
133 than 0 (in an old file system). Or go through and zero the fields,
134 when we notice a version change (the index version number) */
135 ViceLock lock; /* Advisory lock */
136 Date_t serverModifyTime; /* Used only by the server;
137 for incremental backup purposes */
138 struct rec_smolink nextvn; /* link to next vnode with same vnodeindex */
139 rec_dlist *log; /* resolution log in RVM */
140 /* Missing:
141 archiving/migration
142 encryption key
143 */
145
146#if UINT_MAX == ULONG_MAX
147#define SIZEOF_SMALLDISKVNODE 112 /* used to be 64 */
148#else
149#define SIZEOF_SMALLDISKVNODE 128
150#endif
151#define CHECKSIZE_SMALLVNODE (sizeof(VnodeDiskObject) == SIZEOF_SMALLDISKVNODE)
152/* must be a power of 2! */
153#define SIZEOF_LARGEDISKVNODE 512 /* used to be 256 */
154
155typedef struct Vnode {
156 struct Vnode *hashNext; /* Next vnode on hash conflict chain */
157 struct Vnode *lruNext; /* Less recently used vnode than this one */
158 struct Vnode *lruPrev; /* More recently used vnode than this one */
159 /* The lruNext, lruPrev fields are not meaningful if the vnode is in use */
160 bit16 hashIndex; /* Hash table index */
161 unsigned short changed : 1; /* 1 if the vnode has been changed */
162 unsigned short delete_me : 1; /* 1 if the vnode should be deleted; in
163 this case, changed must also be 1 */
164 VnodeId vnodeNumber;
165 struct Volume *volumePtr; /* Pointer to the volume containing this file*/
166 PDCEntry dh; /* Directory cache handle (used for dirs) */
167 int dh_refc; /* Refcount of this vnode to dh */
168 byte nUsers; /* Number of lwp's who have done a VGetVnode */
169 bit16 cacheCheck; /* Must equal the value in the volume Header
170 for the cache entry to be valid */
171 struct Lock lock; /* Internal lock */
172 PROCESS writer; /* Process id having write lock */
173
174 /* SHA160, there is no room in the VnodeDiskObject, but we don't
175 really want to recalculate it for every GetAttr. Eventually this
176 should end up in the VnodeDiskObject. */
177 unsigned char SHA[SHA_DIGEST_LENGTH];
178
179 VnodeDiskObject disk; /* The actual disk data for the vnode */
180 /* The VnodeDiskObject needs to be the last one in the Vnode structure,
181 * because the ACLs are dangling off the end... */
183
184#define Vnode_vv(vptr) ((vptr)->disk.versionvector)
185
186#define SIZEOF_LARGEVNODE \
187 (sizeof(struct Vnode) - sizeof(VnodeDiskObject) + SIZEOF_LARGEDISKVNODE)
188#define SIZEOF_SMALLVNODE (sizeof(struct Vnode))
189
190#define VVnodeDiskACL(v) /* Only call this with large (dir) vnode!! */ \
191 ((AL_AccessList *)(((byte *)(v)) + SIZEOF_SMALLDISKVNODE))
192#define VVnodeACL(vnp) (VVnodeDiskACL(&(vnp)->disk))
193
194#define VAclSize(vnp) (SIZEOF_LARGEVNODE - SIZEOF_SMALLVNODE)
195#define VAclDiskSize(v) (SIZEOF_LARGEDISKVNODE - SIZEOF_SMALLDISKVNODE)
196#define VnLog(vnp) ((vnp)->disk.log)
197#define VnSHA(vnp) ((vnp)->SHA)
198
200int VolumeHashOffset();
201void VInitVnodes(VnodeClass, int);
202Vnode *VGetVnode(Error *, Volume *, VnodeId, Unique_t, int, int,
203 int = 0) REQUIRES_TRANSACTION;
206int VAllocFid(Volume *vp, VnodeType type, ViceFidRange *Range, int stride = 1,
207 int ix = 0) EXCLUDES_TRANSACTION;
208int VAllocFid(Volume *vp, VnodeType type, VnodeId vnode,
209 Unique_t unique) EXCLUDES_TRANSACTION;
210Vnode *VAllocVnode(Error *ec, Volume *vp, VnodeType type, int stride = 1,
211 int ix = 0) EXCLUDES_TRANSACTION;
212Vnode *VAllocVnode(Error *ec, Volume *vp, VnodeType type, VnodeId vnode,
213 Unique_t unique) EXCLUDES_TRANSACTION;
214int ObjectExists(int, int, VnodeId, Unique_t, ViceFid * = NULL);
215
217int VN_DAbort(Vnode *vnp);
219void VN_PutDirHandle(struct Vnode *vn);
220void VN_DropDirHandle(struct Vnode *vn);
221void VN_CopyOnWrite(struct Vnode *vptr);
222
223void VN_VN2Fid(struct Vnode *, struct Volume *, struct ViceFid *);
224void VN_VN2PFid(struct Vnode *, struct Volume *, struct ViceFid *);
225
226/* make this debugging print routine visible everywhere (Satya 5/04) */
227void PrintVnodeDiskObject(FILE *, VnodeDiskObject *, VnodeId);
228
229#endif /* _CVNODE_H_ */
Definition: rec_dlist.h:49
#define SHA_DIGEST_LENGTH
Definition: coda_hash.h:71
#define REQUIRES_TRANSACTION
Definition: coda_tsa.h:107
#define EXCLUDES_TRANSACTION
Definition: coda_tsa.h:108
int ObjectExists(int, int, VnodeId, Unique_t, ViceFid *=NULL)
Definition: recovb.cc:132
int VN_DCommit(Vnode *vnp) REQUIRES_TRANSACTION
Definition: dirvnode.cc:69
struct VnodeClassInfo VnodeClassInfo_Array[nVNODECLASSES]
Definition: cvnode.cc:74
void VN_VN2Fid(struct Vnode *, struct Volume *, struct ViceFid *)
Definition: cvnode.cc:859
void VN_CopyOnWrite(struct Vnode *vptr)
Definition: dirvnode.cc:201
int VnodeClass
Definition: cvnode.h:67
void PrintVnodeDiskObject(FILE *, VnodeDiskObject *, VnodeId)
Definition: vol-debug.cc:74
PDirHandle SetDirHandle(struct Vnode *)
void VFlushVnode(Error *, Vnode *) REQUIRES_TRANSACTION
Definition: cvnode.cc:750
int VnodeType
Definition: cvnode.h:51
void VPutVnode(Error *ec, Vnode *vnp) REQUIRES_TRANSACTION
Definition: cvnode.cc:656
Vnode * VAllocVnode(Error *ec, Volume *vp, VnodeType type, int stride=1, int ix=0) EXCLUDES_TRANSACTION
Definition: cvnode.cc:337
void VN_PutDirHandle(struct Vnode *vn)
Definition: dirvnode.cc:163
PDirHandle VN_SetDirHandle(struct Vnode *vn)
Definition: dirvnode.cc:126
struct VnodeDiskObjectStruct VnodeDiskObject
struct Vnode Vnode
int VN_DAbort(Vnode *vnp)
Definition: dirvnode.cc:102
void VInitVnodes(VnodeClass, int)
Definition: cvnode.cc:148
void VN_DropDirHandle(struct Vnode *vn)
Definition: dirvnode.cc:179
#define nVNODECLASSES
Definition: cvnode.h:70
Vnode * VGetVnode(Error *, Volume *, VnodeId, Unique_t, int, int, int=0) REQUIRES_TRANSACTION
Definition: cvnode.cc:471
int VolumeHashOffset()
Definition: cvnode.cc:122
int VAllocFid(Volume *vp, VnodeType type, ViceFidRange *Range, int stride=1, int ix=0) EXCLUDES_TRANSACTION
Definition: cvnode.cc:230
void VN_VN2PFid(struct Vnode *, struct Volume *, struct ViceFid *)
Definition: cvnode.cc:866
void(* type)()
Definition: rp2main.c:424
Definition: dhcache.c:38
Definition: codadir.h:45
Definition: codadir.h:173
Definition: lock.h:68
Definition: vicelock.h:45
Definition: cvnode.h:72
int cacheSize
Definition: cvnode.h:76
int writes
Definition: cvnode.h:85
int allocs
Definition: cvnode.h:80
struct Vnode * lruHead
Definition: cvnode.h:73
bit32 magic
Definition: cvnode.h:77
int residentSize
Definition: cvnode.h:75
int gets
Definition: cvnode.h:83
int diskSize
Definition: cvnode.h:74
int reads
Definition: cvnode.h:83
Definition: cvnode.h:98
Date_t serverModifyTime
Definition: cvnode.h:136
Unique_t uparent
Definition: cvnode.h:126
PDirInode dirNode
Definition: cvnode.h:117
VnodeId vparent
Definition: cvnode.h:125
bit32 vnodeMagic
Definition: cvnode.h:127
unsigned cloned
Definition: cvnode.h:101
UserId author
Definition: cvnode.h:123
UserId owner
Definition: cvnode.h:124
unsigned modeBits
Definition: cvnode.h:103
int vol_index
Definition: cvnode.h:121
ViceVersionVector versionvector
Definition: cvnode.h:120
bit32 length
Definition: cvnode.h:106
Date_t unixModifyTime
Definition: cvnode.h:122
rec_dlist * log
Definition: cvnode.h:139
struct rec_smolink nextvn
Definition: cvnode.h:138
bit16 linkCount
Definition: cvnode.h:104
Inode inodeNumber
Definition: cvnode.h:116
FileVersion dataVersion
Definition: cvnode.h:110
Unique_t uniquifier
Definition: cvnode.h:107
VnodeType type
Definition: cvnode.h:99
ViceLock lock
Definition: cvnode.h:135
union VnodeDiskObjectStruct::@30 node
Definition: cvnode.h:155
int dh_refc
Definition: cvnode.h:167
struct Vnode * lruPrev
Definition: cvnode.h:158
struct Vnode * lruNext
Definition: cvnode.h:157
struct Lock lock
Definition: cvnode.h:171
PROCESS writer
Definition: cvnode.h:172
VnodeId vnodeNumber
Definition: cvnode.h:164
byte nUsers
Definition: cvnode.h:168
unsigned char SHA[SHA_DIGEST_LENGTH]
Definition: cvnode.h:177
bit16 cacheCheck
Definition: cvnode.h:169
PDCEntry dh
Definition: cvnode.h:166
VnodeDiskObject disk
Definition: cvnode.h:179
unsigned short changed
Definition: cvnode.h:161
struct Volume * volumePtr
Definition: cvnode.h:165
unsigned short delete_me
Definition: cvnode.h:162
bit16 hashIndex
Definition: cvnode.h:160
struct Vnode * hashNext
Definition: cvnode.h:156
Definition: volume.h:234
Definition: lwp.private_pt.h:33
uint16_t bit16
Definition: voltypes.h:57
uint32_t bit32
Definition: voltypes.h:56
#define NULL
Definition: voltypes.h:44
bit32 Inode
Definition: voltypes.h:61
bit32 Error
Definition: voltypes.h:62