2 * Copyright 2000, International Business Machines Corporation and others.
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
12 #include <afsconfig.h>
13 #include <afs/param.h>
18 #include <sys/types.h>
21 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
25 #include "butc_xbsa.h"
28 #include "error_macros.h"
30 extern int debugLevel;
33 char resourceType[20] = "LFS FILE SYSTEM";
34 #define GOODSTR(s) ((s)?(s):"<NULL>")
36 BSA_Int16(*XBSAInit) (BSA_UInt32 *, SecurityToken *, ObjectOwner *, char **);
37 BSA_Int16(*XBSABeginTxn) (BSA_UInt32);
38 BSA_Int16(*XBSAEndTxn) (BSA_UInt32, Vote);
39 BSA_Int16(*XBSATerminate) (BSA_UInt32);
40 BSA_Int16(*XBSAQueryObject) (BSA_UInt32, QueryDescriptor *,
42 BSA_Int16(*XBSAGetObject) (BSA_UInt32, ObjectDescriptor *, DataBlock *);
43 BSA_Int16(*XBSAEndData) (BSA_UInt32);
44 BSA_Int16(*XBSACreateObject) (BSA_UInt32, ObjectDescriptor *, DataBlock *);
45 BSA_Int16(*XBSADeleteObject) (BSA_UInt32, CopyType, ObjectName *, CopyId *);
46 BSA_Int16(*XBSAMarkObjectInactive) (BSA_UInt32, ObjectName *);
47 BSA_Int16(*XBSASendData) (BSA_UInt32, DataBlock *);
48 BSA_Int16(*XBSAGetData) (BSA_UInt32, DataBlock *);
49 BSA_Int16(*XBSAQueryApiVersion) (ApiVersion *);
50 BSA_Int16(*XBSAGetEnvironment) (BSA_UInt32, ObjectOwner *, char **);
53 xbsa_error(int rc, struct butx_transactionInfo *info)
56 case BSA_RC_AUTHENTICATION_FAILURE:
57 ELog(0, " XBSA: Authentication failure\n");
59 case BSA_RC_INVALID_KEYWORD:
60 ELog(0, " XBSA: A specified keyword is invalid\n");
62 case BSA_RC_TOKEN_EXPIRED:
63 ELog(0, " XBSA: The security token has expired\n");
65 case ADSM_RC_PSWD_GEN:
66 if (XBSA_GET_SERVER_TYPE(info->serverType) == XBSA_SERVER_TYPE_ADSM) {
67 ELog(0, " XBSA: Password generation is not supported\n");
70 case BSA_RC_BAD_HANDLE:
71 ELog(0, " XBSA: The handle is invalid, %d\n", info->bsaHandle);
75 " XBSA: There were no matches found for the specified object\n");
77 case BSA_RC_MORE_DATA:
78 ELog(0, " XBSA: There were more matches found than expected\n");
80 case BSA_RC_NULL_OBJNAME:
81 ELog(0, " XBSA: The object name is null\n");
83 case BSA_RC_OBJNAME_TOO_LONG:
84 ELog(0, " XBSA: The object name was longer than expected\n");
86 case BSA_RC_DESC_TOO_LONG:
88 " XBSA: The description string was longer than expected\n");
90 case BSA_RC_OBJINFO_TOO_LONG:
92 " XBSA: The object info string was longer than expected\n");
94 case BSA_RC_ABORT_ACTIVE_NOT_FOUND:
95 ELog(0, " XBSA: The specified object was not found\n");
97 case BSA_RC_NULL_DATABLKPTR:
98 ELog(0, " XBSA: The dataBlockPtr is null\n");
100 case BSA_RC_INVALID_VOTE:
101 ELog(0, " XBSA: The vote variable is invalid\n");
107 * Hook into the correct XBSA shared library.
108 * Set up the function pointers.
109 * Get the library version.
110 * XBSAQueryApiVersion
113 xbsa_MountLibrary(struct butx_transactionInfo *info, afs_int32 serverType)
118 if (debugLevel > 98) {
119 printf("\nxbsa_MountLibraray\n");
122 switch (serverType) {
123 case XBSA_SERVER_TYPE_ADSM:
124 #if defined(AFS_AIX_ENV)
126 dlopen("/usr/lib/libXApi.a(bsashr10.o)",
127 RTLD_NOW | RTLD_LOCAL | RTLD_MEMBER);
128 if (dynlib == NULL) {
130 dlopen("/usr/lib/libXApi.a(xbsa.o)",
131 RTLD_NOW | RTLD_LOCAL | RTLD_MEMBER);
133 #elif defined(AFS_SUN5_ENV)
134 dynlib = dlopen("/usr/lib/libXApi.so", RTLD_NOW | RTLD_LOCAL);
140 ELog(0, "xbsa_MountLibrary: The serverType %d is not recognized\n",
142 return (BUTX_INVALIDSERVERTYPE);
146 if (dynlib == NULL) {
148 "xbsa_MountLibrary: The dlopen call to load the XBSA shared library failed\n");
149 return (BUTX_NOLIBRARY);
152 memset(info, 0, sizeof(struct butx_transactionInfo));
153 XBSA_SET_SERVER_TYPE(info->serverType, serverType);
155 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
156 XBSAInit = (BSA_Int16(*)
157 (BSA_UInt32 *, SecurityToken *, ObjectOwner *,
158 char **))dlsym((void *)dynlib, "BSAInit");
160 (BSA_Int16(*)(BSA_UInt32)) dlsym((void *)dynlib, "BSABeginTxn");
162 (BSA_Int16(*)(BSA_UInt32, Vote)) dlsym((void *)dynlib, "BSAEndTxn");
164 (BSA_Int16(*)(BSA_UInt32)) dlsym((void *)dynlib, "BSATerminate");
166 (BSA_Int16(*)(BSA_UInt32, QueryDescriptor *, ObjectDescriptor *))
167 dlsym((void *)dynlib, "BSAQueryObject");
169 (BSA_Int16(*)(BSA_UInt32, ObjectDescriptor *, DataBlock *))
170 dlsym((void *)dynlib, "BSAGetObject");
172 (BSA_Int16(*)(BSA_UInt32)) dlsym((void *)dynlib, "BSAEndData");
174 (BSA_Int16(*)(BSA_UInt32, ObjectDescriptor *, DataBlock *))
175 dlsym((void *)dynlib, "BSACreateObject");
176 XBSAMarkObjectInactive =
177 (BSA_Int16(*)(BSA_UInt32, ObjectName *)) dlsym((void *)dynlib,
178 "BSAMarkObjectInactive");
180 (BSA_Int16(*)(BSA_UInt32, CopyType, ObjectName *, CopyId *))
181 dlsym((void *)dynlib, "BSADeleteObject");
183 (BSA_Int16(*)(BSA_UInt32, DataBlock *)) dlsym((void *)dynlib,
186 (BSA_Int16(*)(BSA_UInt32, DataBlock *)) dlsym((void *)dynlib,
188 XBSAQueryApiVersion =
189 (BSA_Int16(*)(ApiVersion *)) dlsym((void *)dynlib,
190 "BSAQueryApiVersion");
192 (BSA_Int16(*)(BSA_UInt32, ObjectOwner *, char **))dlsym((void *)
194 "BSAGetEnvironment");
196 if (!XBSAInit || !XBSABeginTxn || !XBSAEndTxn || !XBSATerminate
197 || !XBSAQueryObject || !XBSAGetObject || !XBSAEndData
198 || !XBSACreateObject || !XBSADeleteObject || !XBSAMarkObjectInactive
199 || !XBSASendData || !XBSAGetData || !XBSAQueryApiVersion
200 || !XBSAGetEnvironment) {
202 "xbsa_MountLibrary: The dlopen call to load the XBSA shared library failed\n");
203 return (BUTX_NOLIBRARY);
206 XBSAQueryApiVersion(&(info->apiVersion));
210 * Verify the API version
212 if ((info->apiVersion.version == XBSA_TS_VERSION)
213 && (info->apiVersion.release == XBSA_TS_RELEASE)) {
214 /* XOPEN Techincal Standard Level!
215 * We are coded to the Preliminary Spec! Time to go boom!
218 "xbsa_MountLibrary: The XBSAQueryApiVersion call returned an incompatible version, %d %d %d\n",
219 info->apiVersion.version, info->apiVersion.release,
220 info->apiVersion.level);
221 return (BUTX_INVALIDVERSION);
224 switch (XBSA_GET_SERVER_TYPE(info->serverType)) {
225 case XBSA_SERVER_TYPE_ADSM:
226 if ((info->apiVersion.version > XBSA_ADSM_NO_MULT_SERVER_VERSION)
227 || (info->apiVersion.version == XBSA_ADSM_NO_MULT_SERVER_VERSION
228 && info->apiVersion.release >
229 XBSA_ADSM_NO_MULT_SERVER_RELEASE)
230 || (info->apiVersion.version == XBSA_ADSM_NO_MULT_SERVER_VERSION
231 && info->apiVersion.release ==
232 XBSA_ADSM_NO_MULT_SERVER_RELEASE
233 && info->apiVersion.level > XBSA_ADSM_NO_MULT_SERVER_LEVEL)) {
235 /* This version contains the fixes to allow multiple servers */
236 info->serverType |= XBSA_SERVER_FLAG_MULTIPLE;
238 /* This is an older version of ADSM prior to the fix to
239 * allow multiple servers.
241 info->serverType |= XBSA_SERVER_FLAG_NONE;
246 return (XBSA_SUCCESS);
251 * Set up the connection to the XBSA Server.
256 xbsa_Initialize(struct butx_transactionInfo * info, char *bsaObjectOwner,
257 char *appObjectOwner, char *secToken, char *serverName)
259 char envStrs[XBSA_NUM_ENV_STRS][BSA_MAX_DESC];
260 char *envP[XBSA_NUM_ENV_STRS + 1];
261 char *ADSMMaxObject = "MAXOBJ=";
262 char *ADSMServer = "DSMSRVR=";
267 if (debugLevel > 98) {
268 printf("\nxbsa_Initialize bsaObjectOwner='%s' appObjectOwner='%s' "
269 "secToken=xxxxxx servername='%s'\n", GOODSTR(bsaObjectOwner),
270 GOODSTR(appObjectOwner), GOODSTR(serverName));
273 if (info->bsaHandle != 0) {
274 /* We already have a handle */
276 "xbsa_Initialize: The dlopen call to load the XBSA shared library failed\n");
277 return (BUTX_ILLEGALINIT);
281 * The XBSAGetEnvironment function is supposed to return the
282 * the serverName to use. However, it is returning the tcpserveraddress
283 * instead. So, we can't count on this function to properly fill it
284 * in. So, until that get fixed. The serverName will have to be filled
285 * in by the callers of this function (butc).
288 /* Initialize the environment strings */
289 for (i = 0; i < XBSA_NUM_ENV_STRS; i++)
290 envP[i] = envStrs[i];
291 envP[XBSA_NUM_ENV_STRS] = NULL;
293 /* The environment variables are specific to the server type */
294 switch (XBSA_GET_SERVER_TYPE(info->serverType)) {
295 case XBSA_SERVER_TYPE_ADSM:
297 if (strlen(serverName) >= BSA_MAX_DESC) {
299 "xbsa_Initialize: The serverName was not specified\n");
300 return (BUTX_INVALIDSERVERNAME);
302 strcpy(info->serverName, serverName);
303 strcpy(envP[0], ADSMServer);
304 tempStrPtr = envP[0];
305 tempStrPtr = tempStrPtr + strlen(ADSMServer);
306 strcat(tempStrPtr, serverName);
310 ELog(0, "xbsa_Initialize: The serverName was not specified\n");
311 return (BUTX_INVALIDSERVERNAME);
315 ELog(0, "xbsa_Initialize: The serverType %d is not recognized\n",
316 XBSA_GET_SERVER_TYPE(info->serverType));
317 return (BUTX_INVALIDSERVERTYPE);
321 if (bsaObjectOwner) {
322 if (strlen(bsaObjectOwner) >= BSA_MAX_BSAOBJECT_OWNER) {
324 "xbsa_Initialize: The bsaObjectOwner is too long; size = %d; name = %s\n",
325 strlen(bsaObjectOwner), bsaObjectOwner);
326 return (BUTX_INVALIDBSANAME);
328 strcpy(info->objOwner.bsaObjectOwner, bsaObjectOwner);
330 info->objOwner.bsaObjectOwner[0] = NULL;
333 if (appObjectOwner) {
334 if (strlen(appObjectOwner) >= BSA_MAX_APPOBJECT_OWNER) {
336 "xbsa_Initialize: The appObjectOwner is too long; size = %d; name = %s\n",
337 strlen(appObjectOwner), appObjectOwner);
338 return (BUTX_INVALIDAPPNAME);
340 strcpy(info->objOwner.appObjectOwner, appObjectOwner);
342 info->objOwner.appObjectOwner[0] = NULL;
346 if (strlen(secToken) >= BSA_MAX_TOKEN_SIZE) {
348 "xbsa_Initialize: The secToken is too long; size = %d; name = %s\n",
349 strlen(secToken), secToken);
350 return (BUTX_INVALIDSECTOKEN);
352 strcpy(info->secToken, secToken);
354 info->secToken[0] = NULL;
357 rc = (int)XBSAInit(&(info->bsaHandle), &(info->secToken),
358 &(info->objOwner), envP);
359 if (rc != BSA_RC_SUCCESS) {
360 ELog(0, "xbsa_Initialize: The XBSAInit call failed with %d\n", rc);
361 xbsa_error(rc, info);
362 return (BUTX_INITFAIL);
365 /* Initialize the environment strings */
366 for (i = 0; i < XBSA_NUM_ENV_STRS; i++)
367 envP[i] = envStrs[i];
368 envP[XBSA_NUM_ENV_STRS] = NULL;
370 rc = (int)XBSAGetEnvironment(info->bsaHandle, &info->objOwner, envP);
371 if (rc != BSA_RC_SUCCESS) {
373 "xbsa_Initialize: The XBSAGetEnvironment call failed with %d\n",
375 xbsa_error(rc, info);
376 return (BUTX_GETENVFAIL);
379 switch (XBSA_GET_SERVER_TYPE(info->serverType)) {
380 case XBSA_SERVER_TYPE_ADSM:
381 for (i = 0; i < XBSA_NUM_ENV_STRS; i++) {
382 if (strncmp(envP[i], ADSMMaxObject, sizeof(ADSMMaxObject)) == 0) {
383 tempStrPtr = envP[i];
384 tempStrPtr = tempStrPtr + strlen(ADSMMaxObject);
385 info->maxObjects = strtol(tempStrPtr, NULL, 10);
386 if (info->maxObjects <= 0) {
388 "xbsa_Initialize: The XBSAGetEnvironment call returned an invalid value for MAXOBJ %d\n",
390 return (BUTX_GETENVFAIL);
394 if (info->maxObjects == 0) {
396 "xbsa_Initialize: The XBSAGetEnvironment call failed to return the MAXOBJ string\n");
397 return (BUTX_GETENVFAIL);
402 return (XBSA_SUCCESS);
406 * Create a transaction
410 xbsa_BeginTrans(struct butx_transactionInfo * info)
414 if (debugLevel > 98) {
415 printf("\nxbsa_BeginTrans\n");
417 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
418 GOODSTR(info->serverName),
419 GOODSTR(info->objOwner.bsaObjectOwner),
420 GOODSTR(info->objOwner.appObjectOwner));
423 if (info->bsaHandle == 0) {
424 /* We haven't initialized yet! */
425 ELog(0, "xbsa_BeginTrans: No current handle, butx not initialized\n");
426 return (BUTX_NOHANDLE);
429 rc = (int)XBSABeginTxn(info->bsaHandle);
430 if (rc != BSA_RC_SUCCESS) {
431 ELog(0, "xbsa_BeginTrans: The XBSABeginTxn call failed with %d\n",
433 xbsa_error(rc, info);
434 return (BUTX_BEGINTXNFAIL);
437 info->numObjects = 0;
438 return (XBSA_SUCCESS);
442 * End the current transaction
446 xbsa_EndTrans(struct butx_transactionInfo * info)
450 if (debugLevel > 98) {
451 printf("\nxbsa_EndTrans\n");
453 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
454 GOODSTR(info->serverName),
455 GOODSTR(info->objOwner.bsaObjectOwner),
456 GOODSTR(info->objOwner.appObjectOwner));
459 if (info->bsaHandle == 0) {
460 /* We haven't initialized yet! */
461 ELog(0, "xbsa_EndTrans: No current handle, butx not initialized\n");
462 return (BUTX_NOHANDLE);
465 /* terminate the transaction */
466 rc = (int)XBSAEndTxn(info->bsaHandle, BSAVote_COMMIT);
467 if (rc != BSA_RC_SUCCESS) {
468 ELog(0, "xbsa_EndTrans: The XBSAEndTxn call failed with %d\n", rc);
469 xbsa_error(rc, info);
470 return (BUTX_ENDTXNFAIL);
472 return (XBSA_SUCCESS);
476 * Terminate the connection to the XBSA Server.
477 * End the transaction.
481 xbsa_Finalize(struct butx_transactionInfo * info)
485 if (debugLevel > 98) {
486 printf("\nxbsa_Finalize\n");
488 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
489 GOODSTR(info->serverName),
490 GOODSTR(info->objOwner.bsaObjectOwner),
491 GOODSTR(info->objOwner.appObjectOwner));
494 if (info->bsaHandle == 0) {
495 /* We haven't initialized yet! */
496 ELog(0, "xbsa_Finalize: No current handle, butx not initialized\n");
497 return (BUTX_NOHANDLE);
500 /* terminate the session */
501 rc = (int)XBSATerminate(info->bsaHandle);
502 if (rc != BSA_RC_SUCCESS) {
503 ELog(0, "The XBSATerminate call failed with %d\n", rc);
504 xbsa_error(rc, info);
505 return (BUTX_TERMFAIL);
509 return (XBSA_SUCCESS);
513 * Query for the object we are looking for.
517 xbsa_QueryObject(struct butx_transactionInfo * info, char *objectSpaceName,
521 QueryDescriptor queryDescriptor;
523 if (debugLevel > 98) {
524 printf("\nxbsa_QueryObject objectSpaceName='%s' pathnName='%s'\n",
525 GOODSTR(objectSpaceName), GOODSTR(pathName));
527 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
528 GOODSTR(info->serverName),
529 GOODSTR(info->objOwner.bsaObjectOwner),
530 GOODSTR(info->objOwner.appObjectOwner));
533 if (info->bsaHandle == 0) {
534 /* We haven't initialized yet! */
536 "xbsa_QueryObject: No current handle, butx not initialized\n");
537 return (BUTX_NOHANDLE);
540 /* Initialize the query for our dump name */
542 if (objectSpaceName) {
543 if (strlen(objectSpaceName) >= BSA_MAX_OSNAME) {
545 "xbsa_QueryObject: The objectSpaceName is too long; size = %d; name = %s\n",
546 strlen(objectSpaceName), objectSpaceName);
547 return (BUTX_INVALIDOBJECTSPNAME);
549 strcpy(queryDescriptor.objName.objectSpaceName, objectSpaceName);
551 queryDescriptor.objName.objectSpaceName[0] = NULL;
555 if (strlen(pathName) >= BSA_MAX_PATHNAME) {
557 "xbsa_QueryObject: The pathName is too long; size = %d; name = %s\n",
558 strlen(pathName), pathName);
559 return (BUTX_INVALIDPATHNAME);
561 strcpy(queryDescriptor.objName.pathName, pathName);
563 queryDescriptor.objName.pathName[0] = NULL;
566 queryDescriptor.owner = info->objOwner;
567 queryDescriptor.copyType = BSACopyType_BACKUP;
568 strcpy(queryDescriptor.lGName, "");
569 strcpy(queryDescriptor.cGName, "");
570 strcpy(queryDescriptor.resourceType, "");
571 queryDescriptor.objectType = BSAObjectType_FILE;
572 queryDescriptor.status = BSAObjectStatus_ACTIVE;
573 strcpy(queryDescriptor.desc, "");
575 rc = (int)XBSAQueryObject(info->bsaHandle, &queryDescriptor,
577 if (rc == BSA_RC_NO_MORE_DATA)
578 rc = BSA_RC_SUCCESS; /* This is actually a success! */
579 if (rc != BSA_RC_SUCCESS) {
580 ELog(0, "xbsa_QueryObject: The xBSAQueryObject call failed with %d\n",
582 xbsa_error(rc, info);
583 return (BUTX_QUERYFAIL);
585 return (XBSA_SUCCESS);
589 * Locate the correct object on the server and then make the call to
590 * get the object descriptor so we can begin the transfer of data.
594 xbsa_ReadObjectBegin(struct butx_transactionInfo * info, char *dataBuffer,
595 afs_int32 bufferSize, afs_int32 * count,
596 afs_int32 * endOfData)
601 if (debugLevel > 98) {
602 printf("\nxbsa_ReadObjectBegin %d Bytes\n", bufferSize);
604 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
605 GOODSTR(info->serverName),
606 GOODSTR(info->objOwner.bsaObjectOwner),
607 GOODSTR(info->objOwner.appObjectOwner));
610 if (info->bsaHandle == 0) {
611 /* We haven't initialized yet! */
613 "xbsa_ReadObjectBegin: No current handle, butx not initialized\n");
614 return (BUTX_NOHANDLE);
617 if ((bufferSize < 0) || (bufferSize > XBSAMAXBUFFER)) {
618 ELog(0, "xbsa_ReadObjectBegin: The bufferSize %d is invalid\n",
620 return (BUTX_INVALIDBUFFERSIZE);
623 if (dataBuffer == NULL) {
624 ELog(0, "xbsa_ReadObjectBegin: The dataBuffer is NULL\n");
625 return (BUTX_INVALIDDATABUFFER);
628 dataBlock.bufferLen = (BSA_UInt16) bufferSize;
629 dataBlock.numBytes = (BSA_UInt16) 0;
630 dataBlock.bufferPtr = dataBuffer;
633 rc = (int)XBSAGetObject(info->bsaHandle, &info->curObject, &dataBlock);
634 if ((rc != BSA_RC_MORE_DATA) && (rc != BSA_RC_NO_MORE_DATA)) {
636 "xbsa_ReadObjectBegin: The XBSAGetObject call failed with %d\n",
638 xbsa_error(rc, info);
639 return (BUTX_GETOBJFAIL);
641 *count = dataBlock.numBytes;
642 if (rc == BSA_RC_NO_MORE_DATA)
644 return (XBSA_SUCCESS);
649 * Tell the XBSA Server that this is the end of Data for this object.
653 xbsa_ReadObjectEnd(struct butx_transactionInfo * info)
657 if (debugLevel > 98) {
658 printf("\nxbsa_ReadObjectEnd\n");
660 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
661 GOODSTR(info->serverName),
662 GOODSTR(info->objOwner.bsaObjectOwner),
663 GOODSTR(info->objOwner.appObjectOwner));
666 if (info->bsaHandle == 0) {
667 /* We haven't initialized yet! */
669 "xbsa_ReadObjectEnd: No current handle, butx not initialized\n");
670 return (BUTX_NOHANDLE);
672 rc = (int)XBSAEndData(info->bsaHandle);
673 if (rc != BSA_RC_SUCCESS) {
674 ELog(0, "xbsa_ReadObjectEnd: XBSAEndData call failed with %d\n", rc);
675 xbsa_error(rc, info);
676 return (BUTX_ENDDATAFAIL);
678 return (XBSA_SUCCESS);
683 * Create the XBSA Backup Copy Object.
687 xbsa_WriteObjectBegin(struct butx_transactionInfo * info,
688 char *objectSpaceName, char *pathName, char *lGName,
689 afs_hyper_t estimatedSize, char *objectDescription,
696 if (debugLevel > 98) {
698 ("\nxbsa_WriteObjectBegin objectSpacename='%s' pathName='%s' lGName='%s' "
699 "estimatesSize='0x%x%08x objectDescription='%s' objectInfo='%s'\n",
700 GOODSTR(objectSpaceName), GOODSTR(pathName), GOODSTR(lGName),
701 hgethi(estimatedSize), hgetlo(estimatedSize),
702 GOODSTR(objectDescription), GOODSTR(objectInfo));
704 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
705 GOODSTR(info->serverName),
706 GOODSTR(info->objOwner.bsaObjectOwner),
707 GOODSTR(info->objOwner.appObjectOwner));
710 if (info->bsaHandle == 0) {
711 /* We haven't initialized yet! */
713 "xbsa_WriteObjectBegin: No current handle, butx not initialized\n");
714 return (BUTX_NOHANDLE);
717 if (objectSpaceName) {
718 if (strlen(objectSpaceName) >= BSA_MAX_OSNAME) {
720 "xbsa_WriteObjectBegin: The objectSpaceName is too long; size = %d; name = %s\n",
721 strlen(objectSpaceName), objectSpaceName);
722 return (BUTX_INVALIDOBJECTSPNAME);
724 strcpy(info->curObject.objName.objectSpaceName, objectSpaceName);
726 info->curObject.objName.objectSpaceName[0] = NULL;
730 if (strlen(pathName) >= BSA_MAX_PATHNAME) {
732 "xbsa_WriteObjectBegin: The pathName is too long; size = %d; name = %s\n",
733 strlen(pathName), pathName);
734 return (BUTX_INVALIDPATHNAME);
736 strcpy(info->curObject.objName.pathName, pathName);
738 info->curObject.objName.pathName[0] = NULL;
742 if (strlen(lGName) >= BSA_MAX_LG_NAME) {
744 "xbsa_WriteObjectBegin: The lGName is too long; size = %d; name = %s\n",
745 strlen(lGName), lGName);
746 return (BUTX_INVALIDLGNAME);
748 strcpy(info->curObject.lGName, lGName);
750 info->curObject.lGName[0] = NULL;
753 if (objectDescription) {
754 if (((XBSA_GET_SERVER_TYPE(info->serverType) == XBSA_SERVER_TYPE_ADSM)
755 && (strlen(objectDescription) >= ADSM_MAX_DESC))
757 ((XBSA_GET_SERVER_TYPE(info->serverType) != XBSA_SERVER_TYPE_ADSM)
758 && (strlen(objectDescription) >= BSA_MAX_DESC))) {
760 "xbsa_WriteObjectBegin: The objectDescription is too long; size = %d; name = %s\n",
761 strlen(objectDescription), objectDescription);
762 return (BUTX_INVALIDOBJDESC);
764 strcpy(info->curObject.desc, objectDescription);
766 info->curObject.desc[0] = NULL;
770 if (((XBSA_GET_SERVER_TYPE(info->serverType) == XBSA_SERVER_TYPE_ADSM)
771 && (strlen(objectInfo) >= ADSM_MAX_OBJINFO))
773 ((XBSA_GET_SERVER_TYPE(info->serverType) != XBSA_SERVER_TYPE_ADSM)
774 && (strlen(objectInfo) >= BSA_MAX_OBJINFO))) {
776 "xbsa_WriteObjectBegin: The objectInfo is too long; size = %d; name = %s\n",
777 strlen(objectInfo), objectInfo);
778 return (BUTX_INVALIDOBJINFO);
780 strcpy(info->curObject.objectInfo, objectInfo);
782 info->curObject.objectInfo[0] = NULL;
785 if (info->numObjects == info->maxObjects) {
786 /* If we've used up Max Objects we must start a new transaction. */
787 rc = (int)xbsa_EndTrans(info);
788 if (rc != XBSA_SUCCESS) {
791 rc = (int)xbsa_BeginTrans(info);
792 if (rc != XBSA_SUCCESS) {
797 dataBlock.bufferLen = (BSA_UInt16) 0;
798 dataBlock.numBytes = (BSA_UInt16) 0;
799 dataBlock.bufferPtr = 0;
801 info->curObject.Owner = info->objOwner;
802 info->curObject.copyType = BSACopyType_BACKUP;
803 info->curObject.size.left = hgethi(estimatedSize);
804 info->curObject.size.right = hgetlo(estimatedSize);
805 info->curObject.objectType = BSAObjectType_FILE;
806 strcpy(info->curObject.resourceType, resourceType);
808 rc = (int)XBSACreateObject(info->bsaHandle, &info->curObject, &dataBlock);
809 if (rc != BSA_RC_SUCCESS) {
811 "xbsa_WriteObjectBegin: The XBSACreateObject call failed with %d\n",
813 xbsa_error(rc, info);
814 return (BUTX_CREATEOBJFAIL);
819 return (XBSA_SUCCESS);
823 * Delete a backup object from the server
824 * BSAMarkObjectInactive()
828 xbsa_DeleteObject(struct butx_transactionInfo * info, char *objectSpaceName,
832 ObjectName objectName;
834 if (debugLevel > 98) {
835 printf("\nxbsa_DeleteObject objectSpacename='%s' pathName='%s'\n",
836 GOODSTR(objectSpaceName), GOODSTR(pathName));
838 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
839 GOODSTR(info->serverName),
840 GOODSTR(info->objOwner.bsaObjectOwner),
841 GOODSTR(info->objOwner.appObjectOwner));
844 if (info->bsaHandle == 0) {
845 /* We haven't initialized yet! */
847 "xbsa_DeleteObject: No current handle, butx not initialized\n");
848 return (BUTX_NOHANDLE);
851 if (objectSpaceName) {
852 if (strlen(objectSpaceName) >= BSA_MAX_OSNAME) {
854 "xbsa_DeleteObject: The objectSpaceName is too long; size = %d; name = %s\n",
855 strlen(objectSpaceName), objectSpaceName);
856 return (BUTX_INVALIDOBJECTSPNAME);
858 strcpy(objectName.objectSpaceName, objectSpaceName);
860 objectName.objectSpaceName[0] = NULL;
864 if (strlen(pathName) >= BSA_MAX_PATHNAME) {
865 ELog(0, "xbsa_DeleteObject: strlen(pathName), pathName\n",
866 strlen(pathName), pathName);
867 return (BUTX_INVALIDPATHNAME);
869 strcpy(objectName.pathName, pathName);
871 objectName.pathName[0] = NULL;
874 rc = (int)XBSAMarkObjectInactive(info->bsaHandle, &objectName);
875 if (rc != BSA_RC_SUCCESS) {
877 "xbsa_DeleteObject: XBSAMarkObjectInactive call failed with %d\n",
879 xbsa_error(rc, info);
881 BSA_RC_ABORT_ACTIVE_NOT_FOUND) ? BUTX_DELETENOVOL :
885 return (XBSA_SUCCESS);
889 * Tell the XBSA Server that this is the end of Data for this object.
893 xbsa_WriteObjectEnd(struct butx_transactionInfo * info)
897 if (debugLevel > 98) {
898 printf("\nxbsa_WriteObjectEnd\n");
900 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
901 GOODSTR(info->serverName),
902 GOODSTR(info->objOwner.bsaObjectOwner),
903 GOODSTR(info->objOwner.appObjectOwner));
906 if (info->bsaHandle == 0) {
907 /* We haven't initialized yet! */
909 "xbsa_WriteObjectEnd: No current handle, butx not initialized\n");
910 return (BUTX_NOHANDLE);
912 rc = (int)XBSAEndData(info->bsaHandle);
913 if (rc != BSA_RC_SUCCESS) {
914 ELog(0, "xbsa_WriteObjectEnd: XBSAEndData call failed with %d\n", rc);
915 xbsa_error(rc, info);
916 return (BUTX_ENDDATAFAIL);
919 return (XBSA_SUCCESS);
924 * Write the fileset data to the XBSA server
928 xbsa_WriteObjectData(struct butx_transactionInfo * info, char *dataBuffer,
929 afs_int32 bufferSize, afs_int32 * count)
934 if (debugLevel > 98) {
935 printf("\nxbsa_WriteObjectData %d Bytes\n", bufferSize);
937 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
938 GOODSTR(info->serverName),
939 GOODSTR(info->objOwner.bsaObjectOwner),
940 GOODSTR(info->objOwner.appObjectOwner));
943 if (info->bsaHandle == 0) {
944 /* We haven't initialized yet! */
946 "xbsa_WriteObjectData: No current handle, butx not initialized\n");
947 return (BUTX_NOHANDLE);
950 if ((bufferSize < 0) || (bufferSize > XBSAMAXBUFFER)) {
951 ELog(0, "xbsa_WriteObjectData: The bufferSize %d is invalid\n",
953 return (BUTX_INVALIDBUFFERSIZE);
956 if (dataBuffer == NULL) {
957 ELog(0, "xbsa_WriteObjectData: The dataBuffer is NULL\n");
958 return (BUTX_INVALIDDATABUFFER);
961 dataBlock.bufferPtr = dataBuffer;
962 dataBlock.bufferLen = (BSA_UInt16) bufferSize;
963 dataBlock.numBytes = (BSA_UInt16) 0;
965 rc = (int)XBSASendData(info->bsaHandle, &dataBlock);
966 if (rc != BSA_RC_SUCCESS) {
967 ELog(0, "xbsa_WriteObjectData: XBSAEndData call failed with %d\n",
969 xbsa_error(rc, info);
970 return (BUTX_SENDDATAFAIL);
972 *count = dataBlock.numBytes;
973 return (XBSA_SUCCESS);
978 * Read the fileset data from the XBSA server
982 xbsa_ReadObjectData(struct butx_transactionInfo * info, char *dataBuffer,
983 afs_int32 bufferSize, afs_int32 * count,
984 afs_int32 * endOfData)
989 if (debugLevel > 98) {
990 printf("\nxbsa_ReadObjectData %d Bytes\n", bufferSize);
992 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
993 GOODSTR(info->serverName),
994 GOODSTR(info->objOwner.bsaObjectOwner),
995 GOODSTR(info->objOwner.appObjectOwner));
998 if (info->bsaHandle == 0) {
999 /* We haven't initialized yet! */
1001 "xbsa_ReadObjectData: No current handle, butx not initialized\n");
1002 return (BUTX_NOHANDLE);
1005 if ((bufferSize < 0) || (bufferSize > XBSAMAXBUFFER)) {
1006 ELog(0, "xbsa_ReadObjectData: The bufferSize %d is invalid\n",
1008 return (BUTX_INVALIDBUFFERSIZE);
1011 if (dataBuffer == NULL) {
1012 ELog(0, "xbsa_ReadObjectData: The dataBuffer is NULL\n");
1013 return (BUTX_INVALIDDATABUFFER);
1016 dataBlock.bufferLen = (BSA_UInt16) bufferSize;
1017 dataBlock.numBytes = (BSA_UInt16) 0;
1018 dataBlock.bufferPtr = dataBuffer;
1021 rc = (int)XBSAGetData(info->bsaHandle, &dataBlock);
1022 if ((rc != BSA_RC_MORE_DATA) && (rc != BSA_RC_NO_MORE_DATA)) {
1023 ELog(0, "xbsa_ReadObjectData: XBSAGetData call failed with %d\n", rc);
1024 xbsa_error(rc, info);
1025 return (BUTX_GETDATAFAIL);
1027 *count = dataBlock.numBytes;
1028 if (rc == BSA_RC_NO_MORE_DATA)
1030 return (XBSA_SUCCESS);