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 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
22 #include <afs/tcdata.h>
23 #include "butc_xbsa.h"
25 #include <afs/bubasics.h>
27 #include "butc_internal.h"
28 #include "error_macros.h"
30 extern int debugLevel
;
33 char resourceType
[20] = "LFS FILE SYSTEM";
34 #define GOODSTR(s) ((s)?(s):"<NULL>")
37 BSA_Int16 (*XBSAInit
)(long *, SecurityToken
*, ObjectOwner
*, char **);
38 BSA_Int16 (*XBSABeginTxn
)(long);
39 BSA_Int16 (*XBSAEndTxn
)(long, Vote
);
40 BSA_Int16 (*XBSATerminate
)(long);
41 BSA_Int16 (*XBSAQueryObject
)(long, QueryDescriptor
*, ObjectDescriptor
*);
42 BSA_Int16 (*XBSAGetObject
)(long, ObjectDescriptor
*, DataBlock
*);
43 BSA_Int16 (*XBSAEndData
)(long);
44 BSA_Int16 (*XBSACreateObject
)(long, ObjectDescriptor
*, DataBlock
*);
45 BSA_Int16 (*XBSADeleteObject
)(long, CopyType
, ObjectName
*, CopyId
*);
46 BSA_Int16 (*XBSAMarkObjectInactive
)(long, ObjectName
*);
47 BSA_Int16 (*XBSASendData
)(long, DataBlock
*);
48 BSA_Int16 (*XBSAGetData
)(long, DataBlock
*);
49 void (*XBSAQueryApiVersion
)(ApiVersion
*);
50 BSA_Int16 (*XBSAGetEnvironment
)(long, ObjectOwner
*, char **);
52 BSA_Int16(*XBSAInit
) (BSA_UInt32
*, SecurityToken
*, ObjectOwner
*, char **);
53 BSA_Int16(*XBSABeginTxn
) (BSA_UInt32
);
54 BSA_Int16(*XBSAEndTxn
) (BSA_UInt32
, Vote
);
55 BSA_Int16(*XBSATerminate
) (BSA_UInt32
);
56 BSA_Int16(*XBSAQueryObject
) (BSA_UInt32
, QueryDescriptor
*,
58 BSA_Int16(*XBSAGetObject
) (BSA_UInt32
, ObjectDescriptor
*, DataBlock
*);
59 BSA_Int16(*XBSAEndData
) (BSA_UInt32
);
60 BSA_Int16(*XBSACreateObject
) (BSA_UInt32
, ObjectDescriptor
*, DataBlock
*);
61 BSA_Int16(*XBSADeleteObject
) (BSA_UInt32
, CopyType
, ObjectName
*, CopyId
*);
62 BSA_Int16(*XBSAMarkObjectInactive
) (BSA_UInt32
, ObjectName
*);
63 BSA_Int16(*XBSASendData
) (BSA_UInt32
, DataBlock
*);
64 BSA_Int16(*XBSAGetData
) (BSA_UInt32
, DataBlock
*);
65 BSA_Int16(*XBSAQueryApiVersion
) (ApiVersion
*);
66 BSA_Int16(*XBSAGetEnvironment
) (BSA_UInt32
, ObjectOwner
*, char **);
70 xbsa_error(int rc
, struct butx_transactionInfo
*info
)
73 case BSA_RC_AUTHENTICATION_FAILURE
:
74 ELog(0, " XBSA: Authentication failure\n");
76 case BSA_RC_INVALID_KEYWORD
:
77 ELog(0, " XBSA: A specified keyword is invalid\n");
79 case BSA_RC_TOKEN_EXPIRED
:
80 ELog(0, " XBSA: The security token has expired\n");
82 case ADSM_RC_PSWD_GEN
:
83 if (XBSA_GET_SERVER_TYPE(info
->serverType
) == XBSA_SERVER_TYPE_ADSM
) {
84 ELog(0, " XBSA: Password generation is not supported\n");
87 case BSA_RC_BAD_HANDLE
:
88 ELog(0, " XBSA: The handle is invalid, %d\n", info
->bsaHandle
);
92 " XBSA: There were no matches found for the specified object\n");
94 case BSA_RC_MORE_DATA
:
95 ELog(0, " XBSA: There were more matches found than expected\n");
97 case BSA_RC_NULL_OBJNAME
:
98 ELog(0, " XBSA: The object name is null\n");
100 case BSA_RC_OBJNAME_TOO_LONG
:
101 ELog(0, " XBSA: The object name was longer than expected\n");
103 case BSA_RC_DESC_TOO_LONG
:
105 " XBSA: The description string was longer than expected\n");
107 case BSA_RC_OBJINFO_TOO_LONG
:
109 " XBSA: The object info string was longer than expected\n");
111 case BSA_RC_ABORT_ACTIVE_NOT_FOUND
:
112 ELog(0, " XBSA: The specified object was not found\n");
114 case BSA_RC_NULL_DATABLKPTR
:
115 ELog(0, " XBSA: The dataBlockPtr is null\n");
117 case BSA_RC_INVALID_VOTE
:
118 ELog(0, " XBSA: The vote variable is invalid\n");
124 * Hook into the correct XBSA shared library.
125 * Set up the function pointers.
126 * Get the library version.
127 * XBSAQueryApiVersion
130 xbsa_MountLibrary(struct butx_transactionInfo
*info
, afs_int32 serverType
)
136 if (debugLevel
> 98) {
137 printf("\nxbsa_MountLibraray\n");
140 switch (serverType
) {
141 case XBSA_SERVER_TYPE_ADSM
:
143 #if defined(AFS_AIX_ENV)
145 dlopen("/usr/lib/libXApi.a(bsashr10.o)",
146 RTLD_NOW
| RTLD_LOCAL
| RTLD_MEMBER
);
147 if (dynlib
== NULL
) {
149 dlopen("/usr/lib/libXApi.a(xbsa.o)",
150 RTLD_NOW
| RTLD_LOCAL
| RTLD_MEMBER
);
152 #elif defined(AFS_SUN5_ENV)
153 dlopen ("/usr/lib/libCstd.so.1", RTLD_NOW
| RTLD_GLOBAL
);
154 dynlib
= dlopen("/usr/lib/libXApi.so", RTLD_NOW
| RTLD_GLOBAL
);
161 ELog(0, "xbsa_MountLibrary: The serverType %d is not recognized\n",
163 return (BUTX_INVALIDSERVERTYPE
);
168 if (dynlib
== NULL
) {
170 "xbsa_MountLibrary: The dlopen call to load the XBSA shared library failed\n");
171 return (BUTX_NOLIBRARY
);
175 memset(info
, 0, sizeof(struct butx_transactionInfo
));
176 XBSA_SET_SERVER_TYPE(info
->serverType
, serverType
);
179 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
180 XBSAInit
= (BSA_Int16(*)
181 (BSA_UInt32
*, SecurityToken
*, ObjectOwner
*,
182 char **))dlsym((void *)dynlib
, "BSAInit");
184 (BSA_Int16(*)(BSA_UInt32
)) dlsym((void *)dynlib
, "BSABeginTxn");
186 (BSA_Int16(*)(BSA_UInt32
, Vote
)) dlsym((void *)dynlib
, "BSAEndTxn");
188 (BSA_Int16(*)(BSA_UInt32
)) dlsym((void *)dynlib
, "BSATerminate");
190 (BSA_Int16(*)(BSA_UInt32
, QueryDescriptor
*, ObjectDescriptor
*))
191 dlsym((void *)dynlib
, "BSAQueryObject");
193 (BSA_Int16(*)(BSA_UInt32
, ObjectDescriptor
*, DataBlock
*))
194 dlsym((void *)dynlib
, "BSAGetObject");
196 (BSA_Int16(*)(BSA_UInt32
)) dlsym((void *)dynlib
, "BSAEndData");
198 (BSA_Int16(*)(BSA_UInt32
, ObjectDescriptor
*, DataBlock
*))
199 dlsym((void *)dynlib
, "BSACreateObject");
200 XBSAMarkObjectInactive
=
201 (BSA_Int16(*)(BSA_UInt32
, ObjectName
*)) dlsym((void *)dynlib
,
202 "BSAMarkObjectInactive");
204 (BSA_Int16(*)(BSA_UInt32
, CopyType
, ObjectName
*, CopyId
*))
205 dlsym((void *)dynlib
, "BSADeleteObject");
207 (BSA_Int16(*)(BSA_UInt32
, DataBlock
*)) dlsym((void *)dynlib
,
210 (BSA_Int16(*)(BSA_UInt32
, DataBlock
*)) dlsym((void *)dynlib
,
212 XBSAQueryApiVersion
=
213 (BSA_Int16(*)(ApiVersion
*)) dlsym((void *)dynlib
,
214 "BSAQueryApiVersion");
216 (BSA_Int16(*)(BSA_UInt32
, ObjectOwner
*, char **))dlsym((void *)
218 "BSAGetEnvironment");
220 if (!XBSAInit
|| !XBSABeginTxn
|| !XBSAEndTxn
|| !XBSATerminate
221 || !XBSAQueryObject
|| !XBSAGetObject
|| !XBSAEndData
222 || !XBSACreateObject
|| !XBSADeleteObject
|| !XBSAMarkObjectInactive
223 || !XBSASendData
|| !XBSAGetData
|| !XBSAQueryApiVersion
224 || !XBSAGetEnvironment
) {
226 "xbsa_MountLibrary: The dlopen call to load the XBSA shared library failed\n");
227 return (BUTX_NOLIBRARY
);
229 XBSAQueryApiVersion(&(info
->apiVersion
));
232 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX26_ENV)
234 XBSABeginTxn
= BSABeginTxn
;
235 XBSAEndTxn
= BSAEndTxn
;
236 XBSATerminate
= BSATerminate
;
237 XBSAQueryObject
= BSAQueryObject
;
238 XBSAGetObject
= BSAGetObject
;
239 XBSAEndData
= BSAEndData
;
240 XBSACreateObject
= BSACreateObject
;
241 XBSAMarkObjectInactive
= BSAMarkObjectInactive
;
242 XBSADeleteObject
= BSADeleteObject
;
243 XBSASendData
= BSASendData
;
244 XBSAGetData
= BSAGetData
;
245 XBSAQueryApiVersion
= BSAQueryApiVersion
;
246 XBSAGetEnvironment
= BSAGetEnvironment
;
248 if (!XBSAInit
|| !XBSABeginTxn
|| !XBSAEndTxn
|| !XBSATerminate
||
249 !XBSAQueryObject
|| !XBSAGetObject
|| !XBSAEndData
||
250 !XBSACreateObject
|| !XBSADeleteObject
|| !XBSAMarkObjectInactive
||
251 !XBSASendData
|| !XBSAGetData
|| !XBSAQueryApiVersion
||
252 !XBSAGetEnvironment
) {
253 ELog(0,"xbsa_MountLibrary: The dlopen call to load the XBSA shared library failed\n");
254 return(BUTX_NOLIBRARY
);
256 XBSAQueryApiVersion(&(info
->apiVersion
));
261 printf("xbsa_MountLibrary : XBSA function Pointers initialised. \n");
264 * Verify the API version
266 if ((info
->apiVersion
.version
== XBSA_TS_VERSION
)
267 && (info
->apiVersion
.release
== XBSA_TS_RELEASE
)) {
268 /* XOPEN Techincal Standard Level!
269 * We are coded to the Preliminary Spec! Time to go boom!
272 "xbsa_MountLibrary: The XBSAQueryApiVersion call returned an incompatible version, %d %d %d\n",
273 info
->apiVersion
.version
, info
->apiVersion
.release
,
274 info
->apiVersion
.level
);
275 return (BUTX_INVALIDVERSION
);
278 switch (XBSA_GET_SERVER_TYPE(info
->serverType
)) {
279 case XBSA_SERVER_TYPE_ADSM
:
280 if ((info
->apiVersion
.version
> XBSA_ADSM_NO_MULT_SERVER_VERSION
)
281 || (info
->apiVersion
.version
== XBSA_ADSM_NO_MULT_SERVER_VERSION
282 && info
->apiVersion
.release
>
283 XBSA_ADSM_NO_MULT_SERVER_RELEASE
)
284 || (info
->apiVersion
.version
== XBSA_ADSM_NO_MULT_SERVER_VERSION
285 && info
->apiVersion
.release
==
286 XBSA_ADSM_NO_MULT_SERVER_RELEASE
287 && info
->apiVersion
.level
> XBSA_ADSM_NO_MULT_SERVER_LEVEL
)) {
289 /* This version contains the fixes to allow multiple servers */
290 info
->serverType
|= XBSA_SERVER_FLAG_MULTIPLE
;
292 /* This is an older version of ADSM prior to the fix to
293 * allow multiple servers.
295 info
->serverType
|= XBSA_SERVER_FLAG_NONE
;
300 return (XBSA_SUCCESS
);
305 * Set up the connection to the XBSA Server.
310 xbsa_Initialize(struct butx_transactionInfo
* info
, char *bsaObjectOwner
,
311 char *appObjectOwner
, char *secToken
, char *serverName
)
313 char envStrs
[XBSA_NUM_ENV_STRS
][BSA_MAX_DESC
];
314 char *envP
[XBSA_NUM_ENV_STRS
+ 1];
315 char *ADSMMaxObject
= "TSMMAXOBJ=";
316 char *ADSMServer
= "TSMSRVR=";
321 if (debugLevel
> 98) {
322 printf("\nxbsa_Initialize bsaObjectOwner='%s' appObjectOwner='%s' "
323 "secToken=xxxxxx servername='%s'\n", GOODSTR(bsaObjectOwner
),
324 GOODSTR(appObjectOwner
), GOODSTR(serverName
));
327 if (info
->bsaHandle
!= 0) {
328 /* We already have a handle */
330 "xbsa_Initialize: The dlopen call to load the XBSA shared library failed\n");
331 return (BUTX_ILLEGALINIT
);
335 * The XBSAGetEnvironment function is supposed to return the
336 * the serverName to use. However, it is returning the tcpserveraddress
337 * instead. So, we can't count on this function to properly fill it
338 * in. So, until that get fixed. The serverName will have to be filled
339 * in by the callers of this function (butc).
342 /* Initialize the environment strings */
343 for (i
= 0; i
< XBSA_NUM_ENV_STRS
; i
++)
344 envP
[i
] = envStrs
[i
];
345 envP
[XBSA_NUM_ENV_STRS
] = NULL
;
347 /* The environment variables are specific to the server type */
348 switch (XBSA_GET_SERVER_TYPE(info
->serverType
)) {
349 case XBSA_SERVER_TYPE_ADSM
:
351 if (strlen(serverName
) >= BSA_MAX_DESC
) {
353 "xbsa_Initialize: The serverName was not specified\n");
354 return (BUTX_INVALIDSERVERNAME
);
356 strcpy(info
->serverName
, serverName
);
357 strcpy(envP
[0], ADSMServer
);
358 tempStrPtr
= envP
[0];
359 tempStrPtr
= tempStrPtr
+ strlen(ADSMServer
);
360 strcat(tempStrPtr
, serverName
);
362 envP
[0] = NULL
; /* Hack for TSM V5 */
365 ELog(0, "xbsa_Initialize: The serverName was not specified\n");
366 return (BUTX_INVALIDSERVERNAME
);
370 ELog(0, "xbsa_Initialize: The serverType %d is not recognized\n",
371 XBSA_GET_SERVER_TYPE(info
->serverType
));
372 return (BUTX_INVALIDSERVERTYPE
);
376 if (bsaObjectOwner
) {
377 if (strlen(bsaObjectOwner
) >= BSA_MAX_BSAOBJECT_OWNER
) {
379 "xbsa_Initialize: The bsaObjectOwner is too long; size = %d; name = %s\n",
380 strlen(bsaObjectOwner
), bsaObjectOwner
);
381 return (BUTX_INVALIDBSANAME
);
383 strcpy(info
->objOwner
.bsaObjectOwner
, bsaObjectOwner
);
385 info
->objOwner
.bsaObjectOwner
[0] = '\0';
388 if (appObjectOwner
) {
389 if (strlen(appObjectOwner
) >= BSA_MAX_APPOBJECT_OWNER
) {
391 "xbsa_Initialize: The appObjectOwner is too long; size = %d; name = %s\n",
392 strlen(appObjectOwner
), appObjectOwner
);
393 return (BUTX_INVALIDAPPNAME
);
395 strcpy(info
->objOwner
.appObjectOwner
, appObjectOwner
);
397 info
->objOwner
.appObjectOwner
[0] = '\0';
401 if (strlen(secToken
) >= BSA_MAX_TOKEN_SIZE
) {
403 "xbsa_Initialize: The secToken is too long; size = %d; name = %s\n",
404 strlen(secToken
), secToken
);
405 return (BUTX_INVALIDSECTOKEN
);
407 strcpy(info
->secToken
, secToken
);
409 info
->secToken
[0] = '\0';
412 rc
= (int)XBSAInit(&(info
->bsaHandle
), &(info
->secToken
),
413 &(info
->objOwner
), envP
);
414 if (rc
!= BSA_RC_SUCCESS
) {
415 ELog(0, "xbsa_Initialize: The XBSAInit call failed with %d\n", rc
);
416 xbsa_error(rc
, info
);
417 return (BUTX_INITFAIL
);
420 /* Initialize the environment strings */
421 for (i
= 0; i
< XBSA_NUM_ENV_STRS
; i
++)
422 envP
[i
] = envStrs
[i
];
423 envP
[XBSA_NUM_ENV_STRS
] = NULL
;
425 rc
= (int)XBSAGetEnvironment(info
->bsaHandle
, &info
->objOwner
, envP
);
426 if (rc
!= BSA_RC_SUCCESS
) {
428 "xbsa_Initialize: The XBSAGetEnvironment call failed with %d\n",
430 xbsa_error(rc
, info
);
431 return (BUTX_GETENVFAIL
);
434 info
->maxObjects
= 255; /* Hack for ADSM V5: unclear what this actually means... */
436 switch (XBSA_GET_SERVER_TYPE(info
->serverType
)) {
437 case XBSA_SERVER_TYPE_ADSM
:
438 for (i
= 0; i
< XBSA_NUM_ENV_STRS
; i
++) {
439 if (strncmp(envP
[i
], ADSMMaxObject
, strlen(ADSMMaxObject
)) == 0) {
440 tempStrPtr
= envP
[i
];
441 tempStrPtr
= tempStrPtr
+ strlen(ADSMMaxObject
);
442 info
->maxObjects
= strtol(tempStrPtr
, NULL
, 10);
443 if (info
->maxObjects
<= 0) {
445 "xbsa_Initialize: The XBSAGetEnvironment call returned an invalid value for MAXOBJ %d\n",
447 return (BUTX_GETENVFAIL
);
451 if (info
->maxObjects
== 0) {
453 "xbsa_Initialize: The XBSAGetEnvironment call failed to return the MAXOBJ string\n");
454 return (BUTX_GETENVFAIL
);
459 return (XBSA_SUCCESS
);
463 * Create a transaction
467 xbsa_BeginTrans(struct butx_transactionInfo
* info
)
471 if (debugLevel
> 98) {
472 printf("\nxbsa_BeginTrans\n");
474 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
475 GOODSTR(info
->serverName
),
476 GOODSTR(info
->objOwner
.bsaObjectOwner
),
477 GOODSTR(info
->objOwner
.appObjectOwner
));
480 if (info
->bsaHandle
== 0) {
481 /* We haven't initialized yet! */
482 ELog(0, "xbsa_BeginTrans: No current handle, butx not initialized\n");
483 return (BUTX_NOHANDLE
);
486 rc
= (int)XBSABeginTxn(info
->bsaHandle
);
487 if (rc
!= BSA_RC_SUCCESS
) {
488 ELog(0, "xbsa_BeginTrans: The XBSABeginTxn call failed with %d\n",
490 xbsa_error(rc
, info
);
491 return (BUTX_BEGINTXNFAIL
);
494 info
->numObjects
= 0;
495 return (XBSA_SUCCESS
);
499 * End the current transaction
503 xbsa_EndTrans(struct butx_transactionInfo
* info
)
507 if (debugLevel
> 98) {
508 printf("\nxbsa_EndTrans\n");
510 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
511 GOODSTR(info
->serverName
),
512 GOODSTR(info
->objOwner
.bsaObjectOwner
),
513 GOODSTR(info
->objOwner
.appObjectOwner
));
516 if (info
->bsaHandle
== 0) {
517 /* We haven't initialized yet! */
518 ELog(0, "xbsa_EndTrans: No current handle, butx not initialized\n");
519 return (BUTX_NOHANDLE
);
522 /* terminate the transaction */
523 rc
= (int)XBSAEndTxn(info
->bsaHandle
, BSAVote_COMMIT
);
524 if (rc
!= BSA_RC_SUCCESS
) {
525 ELog(0, "xbsa_EndTrans: The XBSAEndTxn call failed with %d\n", rc
);
526 xbsa_error(rc
, info
);
527 return (BUTX_ENDTXNFAIL
);
529 return (XBSA_SUCCESS
);
533 * Terminate the connection to the XBSA Server.
534 * End the transaction.
538 xbsa_Finalize(struct butx_transactionInfo
* info
)
542 if (debugLevel
> 98) {
543 printf("\nxbsa_Finalize\n");
545 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
546 GOODSTR(info
->serverName
),
547 GOODSTR(info
->objOwner
.bsaObjectOwner
),
548 GOODSTR(info
->objOwner
.appObjectOwner
));
551 if (info
->bsaHandle
== 0) {
552 /* We haven't initialized yet! */
553 ELog(0, "xbsa_Finalize: No current handle, butx not initialized\n");
554 return (BUTX_NOHANDLE
);
557 /* terminate the session */
558 rc
= (int)XBSATerminate(info
->bsaHandle
);
559 if (rc
!= BSA_RC_SUCCESS
) {
560 ELog(0, "The XBSATerminate call failed with %d\n", rc
);
561 xbsa_error(rc
, info
);
562 return (BUTX_TERMFAIL
);
566 return (XBSA_SUCCESS
);
570 * Query for the object we are looking for.
574 xbsa_QueryObject(struct butx_transactionInfo
* info
, char *objectSpaceName
,
578 QueryDescriptor queryDescriptor
;
580 if (debugLevel
> 98) {
581 printf("\nxbsa_QueryObject objectSpaceName='%s' pathnName='%s'\n",
582 GOODSTR(objectSpaceName
), GOODSTR(pathName
));
584 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
585 GOODSTR(info
->serverName
),
586 GOODSTR(info
->objOwner
.bsaObjectOwner
),
587 GOODSTR(info
->objOwner
.appObjectOwner
));
590 if (info
->bsaHandle
== 0) {
591 /* We haven't initialized yet! */
593 "xbsa_QueryObject: No current handle, butx not initialized\n");
594 return (BUTX_NOHANDLE
);
597 /* Initialize the query for our dump name */
599 if (objectSpaceName
) {
600 if (strlen(objectSpaceName
) >= BSA_MAX_OSNAME
) {
602 "xbsa_QueryObject: The objectSpaceName is too long; size = %d; name = %s\n",
603 strlen(objectSpaceName
), objectSpaceName
);
604 return (BUTX_INVALIDOBJECTSPNAME
);
606 strcpy(queryDescriptor
.objName
.objectSpaceName
, objectSpaceName
);
608 queryDescriptor
.objName
.objectSpaceName
[0] = '\0';
612 if (strlen(pathName
) >= BSA_MAX_PATHNAME
) {
614 "xbsa_QueryObject: The pathName is too long; size = %d; name = %s\n",
615 strlen(pathName
), pathName
);
616 return (BUTX_INVALIDPATHNAME
);
618 strcpy(queryDescriptor
.objName
.pathName
, pathName
);
620 queryDescriptor
.objName
.pathName
[0] = '\0';
623 queryDescriptor
.owner
= info
->objOwner
;
624 queryDescriptor
.copyType
= BSACopyType_BACKUP
;
625 strcpy(queryDescriptor
.lGName
, "");
626 strcpy(queryDescriptor
.cGName
, "");
627 strcpy(queryDescriptor
.resourceType
, "");
628 queryDescriptor
.objectType
= BSAObjectType_FILE
;
629 queryDescriptor
.status
= BSAObjectStatus_ACTIVE
;
630 strcpy(queryDescriptor
.desc
, "");
632 rc
= (int)XBSAQueryObject(info
->bsaHandle
, &queryDescriptor
,
634 if (rc
== BSA_RC_NO_MORE_DATA
)
635 rc
= BSA_RC_SUCCESS
; /* This is actually a success! */
636 if (rc
!= BSA_RC_SUCCESS
) {
637 ELog(0, "xbsa_QueryObject: The xBSAQueryObject call failed with %d\n",
639 xbsa_error(rc
, info
);
640 return (BUTX_QUERYFAIL
);
642 return (XBSA_SUCCESS
);
646 * Locate the correct object on the server and then make the call to
647 * get the object descriptor so we can begin the transfer of data.
651 xbsa_ReadObjectBegin(struct butx_transactionInfo
* info
, char *dataBuffer
,
652 afs_int32 bufferSize
, afs_int32
* count
,
653 afs_int32
* endOfData
)
658 if (debugLevel
> 98) {
659 printf("\nxbsa_ReadObjectBegin %d Bytes\n", bufferSize
);
661 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
662 GOODSTR(info
->serverName
),
663 GOODSTR(info
->objOwner
.bsaObjectOwner
),
664 GOODSTR(info
->objOwner
.appObjectOwner
));
667 if (info
->bsaHandle
== 0) {
668 /* We haven't initialized yet! */
670 "xbsa_ReadObjectBegin: No current handle, butx not initialized\n");
671 return (BUTX_NOHANDLE
);
674 if ((bufferSize
< 0) || (bufferSize
> XBSAMAXBUFFER
)) {
675 ELog(0, "xbsa_ReadObjectBegin: The bufferSize %d is invalid\n",
677 return (BUTX_INVALIDBUFFERSIZE
);
680 if (dataBuffer
== NULL
) {
681 ELog(0, "xbsa_ReadObjectBegin: The dataBuffer is NULL\n");
682 return (BUTX_INVALIDDATABUFFER
);
685 dataBlock
.bufferLen
= (BSA_UInt16
) bufferSize
;
686 dataBlock
.numBytes
= (BSA_UInt16
) 0;
687 dataBlock
.bufferPtr
= dataBuffer
;
690 rc
= (int)XBSAGetObject(info
->bsaHandle
, &info
->curObject
, &dataBlock
);
691 if ((rc
!= BSA_RC_MORE_DATA
) && (rc
!= BSA_RC_NO_MORE_DATA
)) {
693 "xbsa_ReadObjectBegin: The XBSAGetObject call failed with %d\n",
695 xbsa_error(rc
, info
);
696 return (BUTX_GETOBJFAIL
);
698 *count
= dataBlock
.numBytes
;
699 if (rc
== BSA_RC_NO_MORE_DATA
)
701 return (XBSA_SUCCESS
);
706 * Tell the XBSA Server that this is the end of Data for this object.
710 xbsa_ReadObjectEnd(struct butx_transactionInfo
* info
)
714 if (debugLevel
> 98) {
715 printf("\nxbsa_ReadObjectEnd\n");
717 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
718 GOODSTR(info
->serverName
),
719 GOODSTR(info
->objOwner
.bsaObjectOwner
),
720 GOODSTR(info
->objOwner
.appObjectOwner
));
723 if (info
->bsaHandle
== 0) {
724 /* We haven't initialized yet! */
726 "xbsa_ReadObjectEnd: No current handle, butx not initialized\n");
727 return (BUTX_NOHANDLE
);
729 rc
= (int)XBSAEndData(info
->bsaHandle
);
730 if (rc
!= BSA_RC_SUCCESS
) {
731 ELog(0, "xbsa_ReadObjectEnd: XBSAEndData call failed with %d\n", rc
);
732 xbsa_error(rc
, info
);
733 return (BUTX_ENDDATAFAIL
);
735 return (XBSA_SUCCESS
);
740 * Create the XBSA Backup Copy Object.
744 xbsa_WriteObjectBegin(struct butx_transactionInfo
* info
,
745 char *objectSpaceName
, char *pathName
, char *lGName
,
746 afs_hyper_t estimatedSize
, char *objectDescription
,
752 if (debugLevel
> 98) {
754 ("\nxbsa_WriteObjectBegin objectSpacename='%s' pathName='%s' lGName='%s' "
755 "estimatesSize='0x%x%08x objectDescription='%s' objectInfo='%s'\n",
756 GOODSTR(objectSpaceName
), GOODSTR(pathName
), GOODSTR(lGName
),
757 hgethi(estimatedSize
), hgetlo(estimatedSize
),
758 GOODSTR(objectDescription
), GOODSTR(objectInfo
));
760 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
761 GOODSTR(info
->serverName
),
762 GOODSTR(info
->objOwner
.bsaObjectOwner
),
763 GOODSTR(info
->objOwner
.appObjectOwner
));
766 if (info
->bsaHandle
== 0) {
767 /* We haven't initialized yet! */
769 "xbsa_WriteObjectBegin: No current handle, butx not initialized\n");
770 return (BUTX_NOHANDLE
);
773 if (objectSpaceName
) {
774 if (strlen(objectSpaceName
) >= BSA_MAX_OSNAME
) {
776 "xbsa_WriteObjectBegin: The objectSpaceName is too long; size = %d; name = %s\n",
777 strlen(objectSpaceName
), objectSpaceName
);
778 return (BUTX_INVALIDOBJECTSPNAME
);
780 strcpy(info
->curObject
.objName
.objectSpaceName
, objectSpaceName
);
782 info
->curObject
.objName
.objectSpaceName
[0] = '\0';
786 if (strlen(pathName
) >= BSA_MAX_PATHNAME
) {
788 "xbsa_WriteObjectBegin: The pathName is too long; size = %d; name = %s\n",
789 strlen(pathName
), pathName
);
790 return (BUTX_INVALIDPATHNAME
);
792 strcpy(info
->curObject
.objName
.pathName
, pathName
);
794 info
->curObject
.objName
.pathName
[0] = '\0';
798 if (strlen(lGName
) >= BSA_MAX_LG_NAME
) {
800 "xbsa_WriteObjectBegin: The lGName is too long; size = %d; name = %s\n",
801 strlen(lGName
), lGName
);
802 return (BUTX_INVALIDLGNAME
);
804 strcpy(info
->curObject
.lGName
, lGName
);
806 info
->curObject
.lGName
[0] = '\0';
809 if (objectDescription
) {
810 if (((XBSA_GET_SERVER_TYPE(info
->serverType
) == XBSA_SERVER_TYPE_ADSM
)
811 && (strlen(objectDescription
) >= ADSM_MAX_DESC
))
813 ((XBSA_GET_SERVER_TYPE(info
->serverType
) != XBSA_SERVER_TYPE_ADSM
)
814 && (strlen(objectDescription
) >= BSA_MAX_DESC
))) {
816 "xbsa_WriteObjectBegin: The objectDescription is too long; size = %d; name = %s\n",
817 strlen(objectDescription
), objectDescription
);
818 return (BUTX_INVALIDOBJDESC
);
820 strcpy(info
->curObject
.desc
, objectDescription
);
822 info
->curObject
.desc
[0] = '\0';
826 if (((XBSA_GET_SERVER_TYPE(info
->serverType
) == XBSA_SERVER_TYPE_ADSM
)
827 && (strlen(objectInfo
) >= ADSM_MAX_OBJINFO
))
829 ((XBSA_GET_SERVER_TYPE(info
->serverType
) != XBSA_SERVER_TYPE_ADSM
)
830 && (strlen(objectInfo
) >= BSA_MAX_OBJINFO
))) {
832 "xbsa_WriteObjectBegin: The objectInfo is too long; size = %d; name = %s\n",
833 strlen(objectInfo
), objectInfo
);
834 return (BUTX_INVALIDOBJINFO
);
836 strcpy(info
->curObject
.objectInfo
, objectInfo
);
838 info
->curObject
.objectInfo
[0] = '\0';
841 if (info
->numObjects
== info
->maxObjects
) {
842 /* If we've used up Max Objects we must start a new transaction. */
843 rc
= (int)xbsa_EndTrans(info
);
844 if (rc
!= XBSA_SUCCESS
) {
847 rc
= (int)xbsa_BeginTrans(info
);
848 if (rc
!= XBSA_SUCCESS
) {
853 dataBlock
.bufferLen
= (BSA_UInt16
) 0;
854 dataBlock
.numBytes
= (BSA_UInt16
) 0;
855 dataBlock
.bufferPtr
= 0;
857 info
->curObject
.Owner
= info
->objOwner
;
858 info
->curObject
.copyType
= BSACopyType_BACKUP
;
859 info
->curObject
.size
.left
= hgethi(estimatedSize
);
860 info
->curObject
.size
.right
= hgetlo(estimatedSize
);
861 info
->curObject
.objectType
= BSAObjectType_FILE
;
862 strcpy(info
->curObject
.resourceType
, resourceType
);
864 rc
= (int)XBSACreateObject(info
->bsaHandle
, &info
->curObject
, &dataBlock
);
865 if (rc
!= BSA_RC_SUCCESS
) {
867 "xbsa_WriteObjectBegin: The XBSACreateObject call failed with %d\n",
869 xbsa_error(rc
, info
);
870 return (BUTX_CREATEOBJFAIL
);
875 return (XBSA_SUCCESS
);
879 * Delete a backup object from the server
880 * BSAMarkObjectInactive()
884 xbsa_DeleteObject(struct butx_transactionInfo
* info
, char *objectSpaceName
,
888 ObjectName objectName
;
890 if (debugLevel
> 98) {
891 printf("\nxbsa_DeleteObject objectSpacename='%s' pathName='%s'\n",
892 GOODSTR(objectSpaceName
), GOODSTR(pathName
));
894 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
895 GOODSTR(info
->serverName
),
896 GOODSTR(info
->objOwner
.bsaObjectOwner
),
897 GOODSTR(info
->objOwner
.appObjectOwner
));
900 if (info
->bsaHandle
== 0) {
901 /* We haven't initialized yet! */
903 "xbsa_DeleteObject: No current handle, butx not initialized\n");
904 return (BUTX_NOHANDLE
);
907 if (objectSpaceName
) {
908 if (strlen(objectSpaceName
) >= BSA_MAX_OSNAME
) {
910 "xbsa_DeleteObject: The objectSpaceName is too long; size = %d; name = %s\n",
911 strlen(objectSpaceName
), objectSpaceName
);
912 return (BUTX_INVALIDOBJECTSPNAME
);
914 strcpy(objectName
.objectSpaceName
, objectSpaceName
);
916 objectName
.objectSpaceName
[0] = '\0';
920 if (strlen(pathName
) >= BSA_MAX_PATHNAME
) {
921 ELog(0, "xbsa_DeleteObject: strlen(pathName), pathName\n",
922 strlen(pathName
), pathName
);
923 return (BUTX_INVALIDPATHNAME
);
925 strcpy(objectName
.pathName
, pathName
);
927 objectName
.pathName
[0] = '\0';
930 rc
= (int)XBSAMarkObjectInactive(info
->bsaHandle
, &objectName
);
931 if (rc
!= BSA_RC_SUCCESS
) {
933 "xbsa_DeleteObject: XBSAMarkObjectInactive call failed with %d\n",
935 xbsa_error(rc
, info
);
937 BSA_RC_ABORT_ACTIVE_NOT_FOUND
) ? BUTX_DELETENOVOL
:
941 return (XBSA_SUCCESS
);
945 * Tell the XBSA Server that this is the end of Data for this object.
949 xbsa_WriteObjectEnd(struct butx_transactionInfo
* info
)
953 if (debugLevel
> 98) {
954 printf("\nxbsa_WriteObjectEnd\n");
956 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
957 GOODSTR(info
->serverName
),
958 GOODSTR(info
->objOwner
.bsaObjectOwner
),
959 GOODSTR(info
->objOwner
.appObjectOwner
));
962 if (info
->bsaHandle
== 0) {
963 /* We haven't initialized yet! */
965 "xbsa_WriteObjectEnd: No current handle, butx not initialized\n");
966 return (BUTX_NOHANDLE
);
968 rc
= (int)XBSAEndData(info
->bsaHandle
);
969 if (rc
!= BSA_RC_SUCCESS
) {
970 ELog(0, "xbsa_WriteObjectEnd: XBSAEndData call failed with %d\n", rc
);
971 xbsa_error(rc
, info
);
972 return (BUTX_ENDDATAFAIL
);
975 return (XBSA_SUCCESS
);
980 * Write the fileset data to the XBSA server
984 xbsa_WriteObjectData(struct butx_transactionInfo
* info
, char *dataBuffer
,
985 afs_int32 bufferSize
, afs_int32
* count
)
990 if (debugLevel
> 98) {
991 printf("\nxbsa_WriteObjectData %d Bytes\n", bufferSize
);
993 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
994 GOODSTR(info
->serverName
),
995 GOODSTR(info
->objOwner
.bsaObjectOwner
),
996 GOODSTR(info
->objOwner
.appObjectOwner
));
999 if (info
->bsaHandle
== 0) {
1000 /* We haven't initialized yet! */
1002 "xbsa_WriteObjectData: No current handle, butx not initialized\n");
1003 return (BUTX_NOHANDLE
);
1006 if ((bufferSize
< 0) || (bufferSize
> XBSAMAXBUFFER
)) {
1007 ELog(0, "xbsa_WriteObjectData: The bufferSize %d is invalid\n",
1009 return (BUTX_INVALIDBUFFERSIZE
);
1012 if (dataBuffer
== NULL
) {
1013 ELog(0, "xbsa_WriteObjectData: The dataBuffer is NULL\n");
1014 return (BUTX_INVALIDDATABUFFER
);
1017 dataBlock
.bufferPtr
= dataBuffer
;
1018 dataBlock
.bufferLen
= (BSA_UInt16
) bufferSize
;
1019 dataBlock
.numBytes
= (BSA_UInt16
) 0;
1021 rc
= (int)XBSASendData(info
->bsaHandle
, &dataBlock
);
1022 if (rc
!= BSA_RC_SUCCESS
) {
1023 ELog(0, "xbsa_WriteObjectData: XBSAEndData call failed with %d\n",
1025 xbsa_error(rc
, info
);
1026 return (BUTX_SENDDATAFAIL
);
1028 *count
= dataBlock
.numBytes
;
1029 return (XBSA_SUCCESS
);
1034 * Read the fileset data from the XBSA server
1038 xbsa_ReadObjectData(struct butx_transactionInfo
* info
, char *dataBuffer
,
1039 afs_int32 bufferSize
, afs_int32
* count
,
1040 afs_int32
* endOfData
)
1043 DataBlock dataBlock
;
1045 if (debugLevel
> 98) {
1046 printf("\nxbsa_ReadObjectData %d Bytes\n", bufferSize
);
1048 ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n",
1049 GOODSTR(info
->serverName
),
1050 GOODSTR(info
->objOwner
.bsaObjectOwner
),
1051 GOODSTR(info
->objOwner
.appObjectOwner
));
1054 if (info
->bsaHandle
== 0) {
1055 /* We haven't initialized yet! */
1057 "xbsa_ReadObjectData: No current handle, butx not initialized\n");
1058 return (BUTX_NOHANDLE
);
1061 if ((bufferSize
< 0) || (bufferSize
> XBSAMAXBUFFER
)) {
1062 ELog(0, "xbsa_ReadObjectData: The bufferSize %d is invalid\n",
1064 return (BUTX_INVALIDBUFFERSIZE
);
1067 if (dataBuffer
== NULL
) {
1068 ELog(0, "xbsa_ReadObjectData: The dataBuffer is NULL\n");
1069 return (BUTX_INVALIDDATABUFFER
);
1072 dataBlock
.bufferLen
= (BSA_UInt16
) bufferSize
;
1073 dataBlock
.numBytes
= (BSA_UInt16
) 0;
1074 dataBlock
.bufferPtr
= dataBuffer
;
1077 rc
= (int)XBSAGetData(info
->bsaHandle
, &dataBlock
);
1078 if ((rc
!= BSA_RC_MORE_DATA
) && (rc
!= BSA_RC_NO_MORE_DATA
)) {
1079 ELog(0, "xbsa_ReadObjectData: XBSAGetData call failed with %d\n", rc
);
1080 xbsa_error(rc
, info
);
1081 return (BUTX_GETDATAFAIL
);
1083 *count
= dataBlock
.numBytes
;
1084 if (rc
== BSA_RC_NO_MORE_DATA
)
1086 return (XBSA_SUCCESS
);