Windows: Protect against infinite VIO retries
[openafs.git] / src / WINNT / afsd / cm_conn.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 OPENAFS_WINNT_AFSD_CM_CONN_H
11 #define OPENAFS_WINNT_AFSD_CM_CONN_H 1
12
13 #define CM_CONN_DEFAULTRDRTIMEOUT       45
14 #ifndef CM_CONN_CONNDEADTIME
15 #define CM_CONN_CONNDEADTIME             0
16 #endif
17 #ifndef CM_CONN_HARDDEADTIME
18 #define CM_CONN_HARDDEADTIME             0
19 #endif
20 #ifndef CM_CONN_IDLEDEADTIME
21 #define CM_CONN_IDLEDEADTIME             0
22 #endif
23 #ifndef CM_CONN_IDLEDEADTIME_REP
24 #define CM_CONN_IDLEDEADTIME_REP         0
25 #endif
26 #ifndef CM_CONN_NATPINGINTERVAL
27 #define CM_CONN_NATPINGINTERVAL          0
28 #endif
29
30 #define CM_CONN_IFS_HARDDEADTIME       120
31 #define CM_CONN_IFS_CONNDEADTIME        60
32 #define CM_CONN_IFS_IDLEDEADTIME      1200
33 #define CM_CONN_IFS_IDLEDEADTIME_REP   180      /* must be larger than file server hard dead timeout = 120 */
34
35 extern unsigned short ConnDeadtimeout;
36 extern unsigned short HardDeadtimeout;
37 extern DWORD          RDRtimeout;
38 extern afs_uint32     rx_pmtu_discovery;
39
40 typedef struct cm_conn {
41         struct cm_conn *nextp;          /* locked by cm_connLock */
42         struct cm_server *serverp;      /* locked by cm_serverLock */
43         struct rx_connection *rxconnp;  /* locked by mx */
44         struct cm_user *userp;          /* locked by mx; a held reference */
45         osi_mutex_t mx;                 /* mutex for some of these fields */
46         afs_int32 refCount;             /* Interlocked */
47         int ucgen;                      /* ucellp's generation number */
48         afs_uint32 flags;               /* locked by mx */
49         int cryptlevel;                 /* encryption status */
50 } cm_conn_t;
51
52 #define CM_CONN_FLAG_FORCE_NEW          1
53 #define CM_CONN_FLAG_REPLICATION        2
54 #define CM_CONN_FLAG_NEW                4
55
56 /*
57  * structure used for tracking RPC progress
58  * and for passing path info from the smb layer
59  * to the cache manager functions.
60  */
61 typedef struct cm_req {
62     DWORD startTime;            /* GetTickCount() when this struct was initialized */
63     int rpcError;               /* RPC error code */
64     int volumeError;            /* volume error code */
65     int accessError;            /* access error code */
66     struct cm_server * errorServp;  /* server that reported a token/idle error other than expired */
67     int tokenError;
68     int idleError;
69     int vnovolError;
70     int volbusyCount;
71     int vioCount;
72     afs_uint32 flags;
73     clientchar_t * tidPathp;
74     clientchar_t * relPathp;
75 } cm_req_t;
76
77 /* flags in cm_req structure */
78 #define CM_REQ_NORETRY          0x01
79 #define CM_REQ_NEW_CONN_FORCED  0x02
80 #define CM_REQ_SOURCE_SMB       0x04
81 #define CM_REQ_VOLUME_UPDATED   0x08
82 #define CM_REQ_WOW64            0x10
83 #define CM_REQ_SOURCE_REDIR     0x20
84 #define CM_REQ_OFFLINE_VOL_CHK  0x40
85
86 /*
87  * Vice2 error codes
88  * 3/20/85
89  * Note:  all of the errors listed here are currently generated by the volume
90  * package.  Other vice error codes, should they be needed, could be included
91  * here also.
92  */
93
94 #define VREADONLY       EROFS   /* Attempt to write a read-only volume */
95
96 /* Special error codes, which may require special handling (other than just
97    passing them through directly to the end user) are listed below */
98
99 #define VICE_SPECIAL_ERRORS     101     /* Lowest special error code */
100
101 #define VSALVAGE        101     /* Volume needs salvage */
102 #define VNOVNODE        102     /* Bad vnode number quoted */
103 #define VNOVOL          103     /* Volume not attached, doesn't exist,
104                                    not created or not online */
105 #define VVOLEXISTS      104     /* Volume already exists */
106 #define VNOSERVICE      105     /* Volume is not in service (i.e. it's
107                                    is out of funds, is obsolete, or somesuch) */
108 #define VOFFLINE        106     /* Volume is off line, for the reason
109                                    given in the offline message */
110 #define VONLINE         107     /* Volume is already on line */
111 #define VDISKFULL       108     /* ENOSPC - Partition is "full",
112                                    i.e. roughly within n% of full */
113 #define VOVERQUOTA      109     /* EDQUOT - Volume max quota exceeded */
114 #define VBUSY           110     /* Volume temporarily unavailable; try again.
115                                    The volume should be available again shortly;
116                                    if it isn't something is wrong.
117                                    Not normally to be propagated to the
118                                    application level */
119 #define VMOVED          111     /* Volume has moved to another server;
120                                    do a VGetVolumeInfo to THIS server to find
121                                    out where */
122 #define VIO             112     /* Vnode temporarily unaccessible, but not known
123                                  * to be permanently bad. */
124 #define VRESTRICTED     120     /* Volume is restricted from using one or more
125                                  * of the given residencies; do a
126                                  * vos examine to find out the current
127                                  * restrictions. */
128
129 #define VRESTARTING     -100    /* server is restarting, otherwise similar to
130                                    VBUSY above.  This is negative so that old
131                                    cache managers treat it as "server is down"*/
132
133 #include "cm_server.h"
134 #ifndef AFS_PTHREAD_ENV
135 #define AFS_PTHREAD_ENV 1
136 #endif
137 #include "rx.h"
138
139 /*
140  * connp->serverp can be accessed without holding a lock because that
141  * never changes once the connection is created.
142  */
143 #define SERVERHAS64BIT(connp) (!((connp)->serverp->flags & CM_SERVERFLAG_NO64BIT))
144 #define SET_SERVERHASNO64BIT(connp) (cm_SetServerNo64Bit((connp)->serverp, TRUE))
145
146 #define SERVERHASINLINEBULK(connp) (!((connp)->serverp->flags & CM_SERVERFLAG_NOINLINEBULK))
147 #define SET_SERVERHASNOINLINEBULK(connp) (cm_SetServerNoInlineBulk((connp)->serverp, TRUE))
148
149 extern void cm_InitConn(void);
150
151 extern void cm_InitReq(cm_req_t *reqp);
152
153 extern int cm_Analyze(cm_conn_t *connp, struct cm_user *up, struct cm_req *reqp,
154                       struct cm_fid *fidp, struct cm_cell *cellp,
155                       afs_uint32 storeOp,
156                       struct AFSFetchStatus *statusp,
157                       struct AFSVolSync *volInfop,
158                       cm_serverRef_t ** vlServerspp,
159                       struct cm_callbackRequest *cbrp, long code);
160
161 extern long cm_ConnByMServers(struct cm_serverRef *, afs_uint32, struct cm_user *,
162         cm_req_t *, cm_conn_t **);
163
164 extern long cm_ConnByServer(struct cm_server *, struct cm_user *, afs_uint32, cm_conn_t **);
165
166 extern long cm_ConnFromFID(struct cm_fid *, struct cm_user *, struct cm_req *,
167         cm_conn_t **);
168
169 extern long cm_ConnFromVolume(struct cm_volume *volp, unsigned long volid,
170                               struct cm_user *userp, cm_req_t *reqp,
171                               cm_conn_t **connpp);
172
173 extern void cm_PutConn(cm_conn_t *connp);
174
175 extern void cm_GCConnections(cm_server_t *serverp);
176
177 extern struct rx_connection * cm_GetRxConn(cm_conn_t *connp);
178
179 extern void cm_ForceNewConnections(cm_server_t *serverp);
180
181 extern long cm_ServerAvailable(struct cm_fid *fidp, struct cm_user *userp);
182
183 extern long cm_GetServerList(struct cm_fid *fidp, struct cm_user *userp,
184                              struct cm_req *reqp, afs_uint32 *replicated,
185                              cm_serverRef_t ***serversppp);
186
187 extern long cm_GetVolServerList(struct cm_volume *volp, afs_uint32 volid,
188                                 struct cm_user *userp,
189                                 struct cm_req *reqp, afs_uint32 *replicated,
190                                 cm_serverRef_t ***serversppp);
191
192 #endif /*  OPENAFS_WINNT_AFSD_CM_CONN_H */