|
xrootd
|
00001 #ifndef __XPROTOCOL_H 00002 #define __XPROTOCOL_H 00003 00004 //#ifndef __GNUC__ 00005 //#define __attribute__(x) 00006 //#ifdef SUNCC 00007 //#pragma pack(4) 00008 //#endif 00009 //#endif 00010 00011 #ifdef __CINT__ 00012 #define __attribute__(x) 00013 #endif 00014 00015 // The following is the binary representation of the protocol version here. 00016 // Protocol version is repesented as three base10 digits x.y.z with x having no 00017 // upper limit (i.e. n.9.9 + 1 -> n+1.0.0). 00018 // 00019 #define kXR_PROTOCOLVERSION 0x00000297 00020 #define kXR_PROTOCOLVSTRING "2.9.7" 00021 00022 #include "XProtocol/XPtypes.hh" 00023 00024 // KINDS of SERVERS 00025 // 00026 // 00027 #define kXR_DataServer 1 00028 #define kXR_LBalServer 0 00029 00030 // The below are defined for protocol version 2.9.7 or higher 00031 // 00032 #define kXR_isManager 0x00000002 00033 #define kXR_isServer 0x00000001 00034 #define kXR_attrMeta 0x00000100 00035 #define kXR_attrProxy 0x00000200 00036 #define kXR_attrSuper 0x00000400 00037 00038 #define kXR_maxReqRetry 10 00039 00040 // 00041 // Kind of error inside a XTNetFile's routine (temporary) 00042 // 00043 enum XReqErrorType { 00044 kGENERICERR = 0, // Generic error 00045 kREAD, // Error while reading from stream 00046 kWRITE, // Error while writing to stream 00047 kREDIRCONNECT, // Error redirecting to a given host 00048 kOK, // Everything seems ok 00049 kNOMORESTREAMS // No more available stream IDs for 00050 // async processing 00051 }; 00052 00053 //______________________________________________ 00054 // PROTOCOL DEFINITION: CLIENT'S REQUESTS TYPES 00055 //______________________________________________ 00056 // 00057 enum XRequestTypes { 00058 kXR_auth = 3000, 00059 kXR_query, // 3001 00060 kXR_chmod, // 3002 00061 kXR_close, // 3003 00062 kXR_dirlist, // 3004 00063 kXR_getfile, // 3005 00064 kXR_protocol,// 3006 00065 kXR_login, // 3007 00066 kXR_mkdir, // 3008 00067 kXR_mv, // 3009 00068 kXR_open, // 3010 00069 kXR_ping, // 3011 00070 kXR_putfile, // 3012 00071 kXR_read, // 3013 00072 kXR_rm, // 3014 00073 kXR_rmdir, // 3015 00074 kXR_sync, // 3016 00075 kXR_stat, // 3017 00076 kXR_set, // 3018 00077 kXR_write, // 3019 00078 kXR_admin, // 3020 00079 kXR_prepare, // 3021 00080 kXR_statx, // 3022 00081 kXR_endsess, // 3023 00082 kXR_bind, // 3024 00083 kXR_readv, // 3025 00084 kXR_verifyw, // 3026 00085 kXR_locate, // 3027 00086 kXR_truncate // 3028 00087 }; 00088 00089 // OPEN MODE FOR A REMOTE FILE 00090 enum XOpenRequestMode { 00091 kXR_ur = 0x100, 00092 kXR_uw = 0x080, 00093 kXR_ux = 0x040, 00094 kXR_gr = 0x020, 00095 kXR_gw = 0x010, 00096 kXR_gx = 0x008, 00097 kXR_or = 0x004, 00098 kXR_ow = 0x002, 00099 kXR_ox = 0x001 00100 }; 00101 00102 enum XMkdirOptions { 00103 kXR_mknone = 0, 00104 kXR_mkdirpath = 1 00105 }; 00106 00107 // this is a bitmask 00108 enum XLoginCapVer { 00109 kXR_lcvnone = 0, 00110 kXR_vermask = 63, 00111 kXR_asyncap = 128 00112 }; 00113 00114 // this is a single number that goes into capver as the version 00115 // 00116 enum XLoginVersion { 00117 kXR_ver000 = 0, // Old clients predating history 00118 kXR_ver001 = 1, // Generally implemented 2005 protocol 00119 kXR_ver002 = 2 // Same as 1 but adds asyncresp recognition 00120 }; 00121 00122 enum XStatRequestOption { 00123 kXR_vfs = 1 00124 }; 00125 00126 enum XStatRespFlags { 00127 kXR_file = 0, 00128 kXR_xset = 1, 00129 kXR_isDir = 2, 00130 kXR_other = 4, 00131 kXR_offline = 8, 00132 kXR_readable=16, 00133 kXR_writable=32, 00134 kXR_poscpend=64 00135 }; 00136 00137 enum XDirlistRequestOption { 00138 kXR_online = 1 00139 }; 00140 00141 enum XOpenRequestOption { 00142 kXR_compress = 1, 00143 kXR_delete = 2, 00144 kXR_force = 4, 00145 kXR_new = 8, 00146 kXR_open_read= 16, 00147 kXR_open_updt= 32, 00148 kXR_async = 64, 00149 kXR_refresh = 128, 00150 kXR_mkpath = 256, 00151 kXR_open_apnd= 512, 00152 kXR_retstat = 1024, 00153 kXR_replica = 2048, 00154 kXR_posc = 4096, 00155 kXR_nowait = 8192, 00156 kXR_seqio =16384 00157 }; 00158 00159 enum XQueryType { 00160 kXR_QStats = 1, 00161 kXR_QPrep = 2, 00162 kXR_Qcksum = 3, 00163 kXR_Qxattr = 4, 00164 kXR_Qspace = 5, 00165 kXR_Qckscan= 6, 00166 kXR_Qconfig= 7, 00167 kXR_Qvisa = 8, 00168 kXR_Qopaque=16, 00169 kXR_Qopaquf=32 00170 }; 00171 00172 enum XVerifyType { 00173 kXR_nocrc = 0, 00174 kXR_crc32 = 1 00175 }; 00176 00177 enum XLogonType { 00178 kXR_useruser = 0, 00179 kXR_useradmin = 1 00180 }; 00181 00182 // Andy's request for async/unsolicited 00183 enum XPrepRequestOption { 00184 kXR_cancel = 1, 00185 kXR_notify = 2, 00186 kXR_noerrs = 4, 00187 kXR_stage = 8, 00188 kXR_wmode = 16, 00189 kXR_coloc = 32, 00190 kXR_fresh = 64 00191 }; 00192 00193 //_______________________________________________ 00194 // PROTOCOL DEFINITION: SERVER'S RESPONSES TYPES 00195 //_______________________________________________ 00196 // 00197 enum XResponseType { 00198 kXR_ok = 0, 00199 kXR_oksofar = 4000, 00200 kXR_attn, 00201 kXR_authmore, 00202 kXR_error, 00203 kXR_redirect, 00204 kXR_wait, 00205 kXR_waitresp, 00206 kXR_noResponsesYet = 10000 00207 }; 00208 00209 //_______________________________________________ 00210 // PROTOCOL DEFINITION: SERVER"S ATTN CODES 00211 //_______________________________________________ 00212 00213 enum XActionCode { 00214 kXR_asyncab = 5000, 00215 kXR_asyncdi, 00216 kXR_asyncms, 00217 kXR_asyncrd, 00218 kXR_asyncwt, 00219 kXR_asyncav, 00220 kXR_asynunav, 00221 kXR_asyncgo, 00222 kXR_asynresp 00223 }; 00224 00225 //_______________________________________________ 00226 // PROTOCOL DEFINITION: SERVER'S ERROR CODES 00227 //_______________________________________________ 00228 // 00229 enum XErrorCode { 00230 kXR_ArgInvalid = 3000, 00231 kXR_ArgMissing, 00232 kXR_ArgTooLong, 00233 kXR_FileLocked, 00234 kXR_FileNotOpen, 00235 kXR_FSError, 00236 kXR_InvalidRequest, 00237 kXR_IOError, 00238 kXR_NoMemory, 00239 kXR_NoSpace, 00240 kXR_NotAuthorized, 00241 kXR_NotFound, 00242 kXR_ServerError, 00243 kXR_Unsupported, 00244 kXR_noserver, 00245 kXR_NotFile, 00246 kXR_isDirectory, 00247 kXR_Cancelled, 00248 kXR_ChkLenErr, 00249 kXR_ChkSumErr, 00250 kXR_inProgress, 00251 kXR_noErrorYet = 10000 00252 }; 00253 00254 00255 //______________________________________________ 00256 // PROTOCOL DEFINITION: CLIENT'S REQUESTS STRUCTS 00257 //______________________________________________ 00258 // 00259 // We need to pack structures sent all over the net! 00260 // __attribute__((packed)) assures no padding bytes. 00261 // 00262 // Nice bodies of the headers for the client requests. 00263 // Note that the protocol specifies these values to be in network 00264 // byte order when sent 00265 // 00266 // G.Ganis: use of flat structures to avoid packing options 00267 00268 struct ClientAdminRequest { 00269 kXR_char streamid[2]; 00270 kXR_unt16 requestid; 00271 kXR_char reserved[16]; 00272 kXR_int32 dlen; 00273 }; 00274 struct ClientAuthRequest { 00275 kXR_char streamid[2]; 00276 kXR_unt16 requestid; 00277 kXR_char reserved[12]; 00278 kXR_char credtype[4]; 00279 kXR_int32 dlen; 00280 }; 00281 struct ClientBindRequest { 00282 kXR_char streamid[2]; 00283 kXR_unt16 requestid; 00284 kXR_char sessid[16]; 00285 kXR_int32 dlen; 00286 }; 00287 struct ClientChmodRequest { 00288 kXR_char streamid[2]; 00289 kXR_unt16 requestid; 00290 kXR_char reserved[14]; 00291 kXR_unt16 mode; 00292 kXR_int32 dlen; 00293 }; 00294 struct ClientCloseRequest { 00295 kXR_char streamid[2]; 00296 kXR_unt16 requestid; 00297 kXR_char fhandle[4]; 00298 kXR_int64 fsize; 00299 kXR_char reserved[4]; 00300 kXR_int32 dlen; 00301 }; 00302 struct ClientDirlistRequest { 00303 kXR_char streamid[2]; 00304 kXR_unt16 requestid; 00305 kXR_char reserved[15]; 00306 kXR_char options[1]; 00307 kXR_int32 dlen; 00308 }; 00309 struct ClientEndsessRequest { 00310 kXR_char streamid[2]; 00311 kXR_unt16 requestid; 00312 kXR_char sessid[16]; 00313 kXR_int32 dlen; 00314 }; 00315 struct ClientGetfileRequest { 00316 kXR_char streamid[2]; 00317 kXR_unt16 requestid; 00318 kXR_int32 options; 00319 kXR_char reserved[8]; 00320 kXR_int32 buffsz; 00321 kXR_int32 dlen; 00322 }; 00323 struct ClientLocateRequest { 00324 kXR_char streamid[2]; 00325 kXR_unt16 requestid; 00326 kXR_unt16 options; 00327 kXR_char reserved[14]; 00328 kXR_int32 dlen; 00329 }; 00330 struct ClientLoginRequest { 00331 kXR_char streamid[2]; 00332 kXR_unt16 requestid; 00333 kXR_int32 pid; 00334 kXR_char username[8]; 00335 kXR_char reserved[2]; 00336 kXR_char capver[1]; 00337 kXR_char role[1]; 00338 kXR_int32 dlen; 00339 }; 00340 struct ClientMkdirRequest { 00341 kXR_char streamid[2]; 00342 kXR_unt16 requestid; 00343 kXR_char options[1]; 00344 kXR_char reserved[13]; 00345 kXR_unt16 mode; 00346 kXR_int32 dlen; 00347 }; 00348 struct ClientMvRequest { 00349 kXR_char streamid[2]; 00350 kXR_unt16 requestid; 00351 kXR_char reserved[16]; 00352 kXR_int32 dlen; 00353 }; 00354 struct ClientOpenRequest { 00355 kXR_char streamid[2]; 00356 kXR_unt16 requestid; 00357 kXR_unt16 mode; 00358 kXR_unt16 options; 00359 kXR_char reserved[12]; 00360 kXR_int32 dlen; 00361 }; 00362 struct ClientPingRequest { 00363 kXR_char streamid[2]; 00364 kXR_unt16 requestid; 00365 kXR_char reserved[16]; 00366 kXR_int32 dlen; 00367 }; 00368 struct ClientProtocolRequest { 00369 kXR_char streamid[2]; 00370 kXR_unt16 requestid; 00371 kXR_int32 clientpv; // 2.9.7 or higher 00372 kXR_char reserved[12]; 00373 kXR_int32 dlen; 00374 }; 00375 struct ClientPrepareRequest { 00376 kXR_char streamid[2]; 00377 kXR_unt16 requestid; 00378 kXR_char options; 00379 kXR_char prty; 00380 kXR_char reserved[14]; 00381 kXR_int32 dlen; 00382 }; 00383 struct ClientPutfileRequest { 00384 kXR_char streamid[2]; 00385 kXR_unt16 requestid; 00386 kXR_int32 options; 00387 kXR_char reserved[8]; 00388 kXR_int32 buffsz; 00389 kXR_int32 dlen; 00390 }; 00391 struct ClientQueryRequest { 00392 kXR_char streamid[2]; 00393 kXR_unt16 requestid; 00394 kXR_unt16 infotype; 00395 kXR_char reserved1[2]; 00396 kXR_char fhandle[4]; 00397 kXR_char reserved2[8]; 00398 kXR_int32 dlen; 00399 }; 00400 struct ClientReadRequest { 00401 kXR_char streamid[2]; 00402 kXR_unt16 requestid; 00403 kXR_char fhandle[4]; 00404 kXR_int64 offset; 00405 kXR_int32 rlen; 00406 kXR_int32 dlen; 00407 }; 00408 struct ClientReadVRequest { 00409 kXR_char streamid[2]; 00410 kXR_unt16 requestid; 00411 kXR_char reserved[16]; 00412 kXR_int32 dlen; 00413 }; 00414 struct ClientRmRequest { 00415 kXR_char streamid[2]; 00416 kXR_unt16 requestid; 00417 kXR_char reserved[16]; 00418 kXR_int32 dlen; 00419 }; 00420 struct ClientRmdirRequest { 00421 kXR_char streamid[2]; 00422 kXR_unt16 requestid; 00423 kXR_char reserved[16]; 00424 kXR_int32 dlen; 00425 }; 00426 struct ClientSetRequest { 00427 kXR_char streamid[2]; 00428 kXR_unt16 requestid; 00429 kXR_char reserved[16]; 00430 kXR_int32 dlen; 00431 }; 00432 struct ClientStatRequest { 00433 kXR_char streamid[2]; 00434 kXR_unt16 requestid; 00435 kXR_char options; 00436 kXR_char reserved[11]; 00437 kXR_char fhandle[4]; 00438 kXR_int32 dlen; 00439 }; 00440 struct ClientSyncRequest { 00441 kXR_char streamid[2]; 00442 kXR_unt16 requestid; 00443 kXR_char fhandle[4]; 00444 kXR_char reserved[12]; 00445 kXR_int32 dlen; 00446 }; 00447 struct ClientTruncateRequest { 00448 kXR_char streamid[2]; 00449 kXR_unt16 requestid; 00450 kXR_char fhandle[4]; 00451 kXR_int64 offset; 00452 kXR_char reserved[4]; 00453 kXR_int32 dlen; 00454 }; 00455 struct ClientWriteRequest { 00456 kXR_char streamid[2]; 00457 kXR_unt16 requestid; 00458 kXR_char fhandle[4]; 00459 kXR_int64 offset; 00460 kXR_char pathid; 00461 kXR_char reserved[3]; 00462 kXR_int32 dlen; 00463 }; 00464 struct ClientVerifywRequest { 00465 kXR_char streamid[2]; 00466 kXR_unt16 requestid; 00467 kXR_char fhandle[4]; 00468 kXR_int64 offset; 00469 kXR_char pathid; 00470 kXR_char vertype; // One of XVerifyType 00471 kXR_char reserved[2]; 00472 kXR_int32 dlen; // Includes crc length 00473 }; 00474 00475 struct ClientRequestHdr { 00476 kXR_char streamid[2]; 00477 kXR_unt16 requestid; 00478 kXR_char body[16]; 00479 kXR_int32 dlen; 00480 }; 00481 00482 typedef union { 00483 struct ClientRequestHdr header; 00484 struct ClientAdminRequest admin; 00485 struct ClientAuthRequest auth; 00486 struct ClientBindRequest bind; 00487 struct ClientChmodRequest chmod; 00488 struct ClientCloseRequest close; 00489 struct ClientDirlistRequest dirlist; 00490 struct ClientEndsessRequest endsess; 00491 struct ClientGetfileRequest getfile; 00492 struct ClientLocateRequest locate; 00493 struct ClientLoginRequest login; 00494 struct ClientMkdirRequest mkdir; 00495 struct ClientMvRequest mv; 00496 struct ClientOpenRequest open; 00497 struct ClientPingRequest ping; 00498 struct ClientPrepareRequest prepare; 00499 struct ClientProtocolRequest protocol; 00500 struct ClientPutfileRequest putfile; 00501 struct ClientQueryRequest query; 00502 struct ClientReadRequest read; 00503 struct ClientReadVRequest readv; 00504 struct ClientRmRequest rm; 00505 struct ClientRmdirRequest rmdir; 00506 struct ClientSetRequest set; 00507 struct ClientStatRequest stat; 00508 struct ClientSyncRequest sync; 00509 struct ClientTruncateRequest truncate; 00510 struct ClientWriteRequest write; 00511 } ClientRequest; 00512 00513 struct readahead_list { 00514 kXR_char fhandle[4]; 00515 kXR_int32 rlen; 00516 kXR_int64 offset; 00517 }; 00518 00519 struct read_args { 00520 kXR_char pathid; 00521 kXR_char reserved[7]; 00522 // his struct is followed by an array of readahead_list 00523 }; 00524 00525 //_____________________________________________________________________ 00526 // PROTOCOL DEFINITION: SERVER'S RESPONSE 00527 //_____________________________________________________________________ 00528 // 00529 00530 // Nice header for the server response. 00531 // Note that the protocol specifies these values to be in network 00532 // byte order when sent 00533 // 00534 // G.Ganis: The following structures never need padding bytes: 00535 // no need of packing options 00536 00537 struct ServerResponseHeader { 00538 kXR_char streamid[2]; 00539 kXR_unt16 status; 00540 kXR_int32 dlen; 00541 }; 00542 00543 // Body for the kXR_bind response... useful 00544 struct ServerResponseBody_Bind { 00545 kXR_char substreamid; 00546 }; 00547 00548 // Body for the kXR_open response... useful 00549 struct ServerResponseBody_Open { 00550 kXR_char fhandle[4]; 00551 kXR_int32 cpsize; // cpsize & cptype returned if kXR_compress *or* 00552 kXR_char cptype[4]; // kXR_retstat is specified 00553 }; // info will follow if kXR_retstat is specified 00554 00555 // Body for the kXR_protocol response... useful 00556 struct ServerResponseBody_Protocol { 00557 kXR_int32 pval; 00558 kXR_int32 flags; 00559 }; 00560 00561 struct ServerResponseBody_Redirect { 00562 kXR_int32 port; 00563 char host[4096]; // Should be sufficient for every use 00564 }; 00565 00566 struct ServerResponseBody_Error { 00567 kXR_int32 errnum; 00568 char errmsg[4096]; // Should be sufficient for every use 00569 }; 00570 00571 struct ServerResponseBody_Wait { 00572 kXR_int32 seconds; 00573 char infomsg[4096]; // Should be sufficient for every use 00574 }; 00575 00576 struct ServerResponseBody_Attn { 00577 kXR_int32 actnum; 00578 char parms[4096]; // Should be sufficient for every use 00579 }; 00580 00581 struct ServerResponseBody_Attn_asyncrd { 00582 kXR_int32 actnum; 00583 kXR_int32 port; 00584 char host[4092]; 00585 }; 00586 00587 struct ServerResponseBody_Attn_asynresp { 00588 kXR_int32 actnum; 00589 char reserved[4]; 00590 ServerResponseHeader resphdr; 00591 char respdata[4096]; 00592 }; 00593 00594 struct ServerResponseBody_Attn_asyncwt { 00595 kXR_int32 actnum; 00596 kXR_int32 wsec; 00597 }; 00598 00599 struct ServerResponseBody_Attn_asyncdi { 00600 kXR_int32 actnum; 00601 kXR_int32 wsec; 00602 kXR_int32 msec; 00603 }; 00604 00605 void ServerResponseHeader2NetFmt(struct ServerResponseHeader *srh); 00606 00607 // The fields to be sent as initial handshake 00608 struct ClientInitHandShake { 00609 kXR_int32 first; 00610 kXR_int32 second; 00611 kXR_int32 third; 00612 kXR_int32 fourth; 00613 kXR_int32 fifth; 00614 }; 00615 00616 // The body received after the first handshake's header 00617 struct ServerInitHandShake { 00618 kXR_int32 msglen; 00619 kXR_int32 protover; 00620 kXR_int32 msgval; 00621 }; 00622 00623 00624 00625 typedef kXR_int32 ServerResponseType; 00626 00627 struct ALIGN_CHECK {char chkszreq[25-sizeof(ClientRequest)]; 00628 char chkszrsp[ 9-sizeof(ServerResponseHeader)]; 00629 }; 00630 00631 /******************************************************************************/ 00632 /* X P r o t o c o l U t i l i t i e s */ 00633 /******************************************************************************/ 00634 00635 #include <errno.h> 00636 #if defined(WIN32) 00637 #if !defined(ENOTBLK) 00638 # define ENOTBLK 15 00639 #endif 00640 #if !defined(ETXTBSY) 00641 #define ETXTBSY 26 00642 #endif 00643 #if !defined(ENOBUFS) 00644 #define ENOBUFS 105 00645 #endif 00646 #if !defined(ENETUNREACH) 00647 #define ENETUNREACH 114 00648 #endif 00649 #endif 00650 00651 class XProtocol 00652 { 00653 public: 00654 00655 // mapError() is the occicial mapping from errno to xrootd protocol error. 00656 // 00657 static int mapError(int rc) 00658 {if (rc < 0) rc = -rc; 00659 switch(rc) 00660 {case ENOENT: return kXR_NotFound; 00661 case EPERM: return kXR_NotAuthorized; 00662 case EACCES: return kXR_NotAuthorized; 00663 case EIO: return kXR_IOError; 00664 case ENOMEM: return kXR_NoMemory; 00665 case ENOBUFS: return kXR_NoMemory; 00666 case ENOSPC: return kXR_NoSpace; 00667 case ENAMETOOLONG: return kXR_ArgTooLong; 00668 case ENETUNREACH: return kXR_noserver; 00669 case ENOTBLK: return kXR_NotFile; 00670 case EISDIR: return kXR_isDirectory; 00671 case EEXIST: return kXR_InvalidRequest; 00672 case ETXTBSY: return kXR_inProgress; 00673 default: return kXR_FSError; 00674 } 00675 } 00676 }; 00677 #endif
1.7.5