79c331e0e3d3eadb38758eb81b71e7013f4201fa
[openafs.git] / src / volser / volser.p.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #ifndef _VOLSER_
11 #define _VOLSER_ 1
12
13 #ifdef AFS_PTHREAD_ENV
14 #include <pthread.h>
15 #endif
16
17 #include <afs/voldefs.h>
18 #include <ubik.h>
19
20 /* vflags, representing state of the volume */
21 #define VTDeleteOnSalvage       1       /* delete on next salvage */
22 #define VTOutOfService          2       /* never put this volume online */
23 #define VTDeleted               4       /* deleted, don't do anything else */
24
25 /* iflags, representing "attach mode" for this volume at the start of this transaction */
26 #define ITOffline       1       /* volume offline on server (returns VOFFLINE) */
27 #define ITBusy          2       /* volume busy on server (returns VBUSY) */
28 #define ITReadOnly      8       /* volume readonly on client, readwrite on server -DO NOT USE */
29 #define ITCreate        0x10    /* volume does not exist correctly yet */
30 #define ITCreateVolID   0x1000  /* create volid */
31
32 /* tflags, representing transaction state */
33 #define TTDeleted       1       /* delete transaction not yet freed due  to high refCount */
34
35 /* other names for volumes in voldefs.h */
36 #define volser_RW       0
37 #define volser_RO       1
38 #define volser_BACK     2
39 #define volser_RWREPL   3
40
41 #define THOLD(tt)       ((tt)->refCount++)
42
43 struct volser_trans {
44     struct volser_trans *next;  /* next ptr in active trans list */
45     afs_int32 tid;              /* transaction id */
46     afs_int32 time;             /* time transaction was last active (for timeouts) */
47     afs_int32 creationTime;     /* time the transaction started */
48     afs_int32 returnCode;       /* transaction error code */
49     struct Volume *volume;      /* pointer to open volume */
50     VolumeId volid;             /* open volume's id */
51     afs_int32 partition;        /* open volume's partition */
52     afs_int32 dumpTransId;      /* other side's trans id during a dump */
53     afs_int32 dumpSeq;          /* next sequence number to use during a dump */
54     short refCount;             /* reference count on this structure */
55     short iflags;               /* initial attach mode flags (IT*) */
56     char vflags;                /* current volume status flags (VT*) */
57     char tflags;                /* transaction flags (TT*) */
58     char incremental;           /* do an incremental restore */
59     /* the fields below are useful for debugging */
60     char lastProcName[30];      /* name of the last procedure which used transaction */
61     struct rx_call *rxCallPtr;  /* pointer to latest associated rx_call */
62 #ifdef AFS_PTHREAD_ENV
63     pthread_mutex_t lock;       /* per transaction lock */
64 #endif
65
66 };
67
68 /* This is how often the garbage collection thread wakes up and
69  * checks for transactions that have timed out: BKGLoop()
70  */
71 #define GCWAKEUP            30
72
73 #ifdef AFS_PTHREAD_ENV
74 #define VTRANS_OBJ_LOCK_INIT(tt) \
75   opr_mutex_init(&((tt)->lock));
76 #define VTRANS_OBJ_LOCK_DESTROY(tt) \
77   opr_mutex_destroy(&((tt)->lock))
78 #define VTRANS_OBJ_LOCK(tt) \
79   opr_mutex_enter(&((tt)->lock))
80 #define VTRANS_OBJ_UNLOCK(tt) \
81   opr_mutex_exit(&((tt)->lock))
82 #else
83 #define VTRANS_OBJ_LOCK_INIT(tt)
84 #define VTRANS_OBJ_LOCK_DESTROY(tt)
85 #define VTRANS_OBJ_LOCK(tt)
86 #define VTRANS_OBJ_UNLOCK(tt)
87 #endif /* AFS_PTHREAD_ENV */
88
89 #define MAXHELPERS          10
90 /* flags for vol helper busyFlags array.  First, VHIdle goes on when a server
91  * becomes idle.  Next, idle flag is cleared and VHRequest goes on when
92  * trans is queued.  Finally, VHRequest goes off (but VHIdle stays off) when
93  * helper is done.  VHIdle goes on again when an lwp waits for work.
94  */
95 #define VHIdle              1   /* vol helper is waiting for a request here */
96 #define VHRequest           2   /* a request has been queued here */
97 extern struct volser_trans *QI_GlobalWriteTrans;
98
99 /* the stuff below is from errors.h in vol directory */
100 #define VICE_SPECIAL_ERRORS     101     /* Lowest special error code */
101
102 #define VSALVAGE        101     /* Volume needs salvage */
103 #define VNOVNODE        102     /* Bad vnode number quoted */
104 #define VNOVOL          103     /* Volume not attached, doesn't exist,
105                                  * not created or not online */
106 #define VVOLEXISTS      104     /* Volume already exists */
107 #define VNOSERVICE      105     /* Volume is not in service (i.e. it's
108                                  * is out of funds, is obsolete, or somesuch). This
109                                  * error code is no longer used, but was previously
110                                  * used by the OpenAFS fileserver to kill "idle" calls,
111                                  * and OpenAFS clients may interpret it that way. */
112 #define VOFFLINE        106     /* Volume is off line, for the reason
113                                  * given in the offline message */
114 #define VONLINE         107     /* Volume is already on line */
115 #define VDISKFULL       108     /* Partition is "full", i.e. rougly within
116                                  * n% of full */
117 #define VOVERQUOTA      109     /* Volume max quota exceeded */
118 #define VBUSY           110     /* Volume temporarily unavailable; try again.
119                                  * The volume should be available again shortly; if
120                                  * it isn't something is wrong.  Not normally to be
121                                  * propagated to the application level */
122 #define VMOVED          111     /* Volume has moved to another server; do a VGetVolumeInfo
123                                  * to THIS server to find out where */
124
125 #define VLDB_MAXSERVERS 10
126 #define VOLSERVICE_ID 4
127 #define INVALID_BID 0
128 #define VOLSER_MAXVOLNAME 65
129 #define VOLSER_OLDMAXVOLNAME 32
130
131 /*flags used for interfacing with the  backup system */
132 struct volDescription {         /*used for interfacing with the backup system */
133     char volName[VOLSER_MAXVOLNAME];    /* should be VNAMESIZE as defined in volume.h */
134     afs_uint32 volId;
135     int volSize;
136     afs_int32 volFlags;
137     afs_uint32 volCloneId;
138 };
139
140 struct partList {               /*used by the backup system */
141     afs_int32 partId[VOLMAXPARTS];
142     afs_int32 partFlags[VOLMAXPARTS];
143 };
144
145 #define STDERR  stderr
146 #define STDOUT  stdout
147
148 #define ISNAMEVALID(name) (strlen(name) < (VOLSER_OLDMAXVOLNAME - 9))
149
150 #define PARTVALID 0x01
151 #define CLONEVALID 0x02
152 #define CLONEZAPPED 0x04
153 #define IDVALID 0x08
154 #define NAMEVALID 0x10
155 #define SIZEVALID 0x20
156 #define ENTRYVALID 0x40
157 #define REUSECLONEID 0x80
158 #define VOK 0x02
159
160 /* Values for the UV_RestoreVolume flags parameter */
161 /* Also used for UV_CopyVolume and UV_CloneVolume */
162 #define RV_FULLRST      0x000001
163 #define RV_OFFLINE      0x000002
164 #define RV_CRDUMP       0x000010
165 #define RV_CRKEEP       0x000020
166 #define RV_CRNEW        0x000040
167 #define RV_LUDUMP       0x000100
168 #define RV_LUKEEP       0x000200
169 #define RV_LUNEW        0x000400
170 #define RV_RDONLY       0x010000
171 #define RV_CPINCR       0x020000
172 #define RV_NOVLDB       0x040000
173 #define RV_NOCLONE      0x080000
174 #define RV_NODEL        0x100000
175 #define RV_RWONLY       0x200000
176
177 /* Values for the UV_ReleaseVolume flags parameters */
178 #define REL_COMPLETE    0x000001  /* force a complete release */
179 #define REL_FULLDUMPS   0x000002  /* force full dumps */
180 #define REL_STAYUP      0x000004  /* dump to clones to avoid offline time */
181
182 struct ubik_client;
183 extern afs_uint32 vsu_GetVolumeID(char *astring, struct ubik_client *acstruct, afs_int32 *errp);
184 extern int vsu_ExtractName(char rname[], char name[]);
185 extern afs_int32 vsu_ClientInit(const char *confDir, char *cellName,
186                                 int secFlags,
187                                 ugen_secproc_func secproc,
188                                 struct ubik_client **uclientp);
189 enum vol_s2s_crypt {
190     VS2SC_NEVER = 0,
191     VS2SC_INHERIT,
192     VS2SC_ALWAYS
193 };
194
195 #endif /* _VOLSER_ */