/* * Tell the XBSA Server that this is the end of Data for this object. * BSAEndData() */ afs_int32 xbsa_WriteObjectEnd(struct butx_transactionInfo * info) { int rc; if (debugLevel > 98) { printf("\nxbsa_WriteObjectEnd\n"); printf ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n", GOODSTR(info->serverName), GOODSTR(info->objOwner.bsaObjectOwner), GOODSTR(info->objOwner.appObjectOwner)); } if (info->bsaHandle == 0) { /* We haven't initialized yet! */ ELog(0, "xbsa_WriteObjectEnd: No current handle, butx not initialized\n"); return (BUTX_NOHANDLE); } rc = (int)XBSAEndData(info->bsaHandle); if (rc != BSA_RC_SUCCESS) { ELog(0, "xbsa_WriteObjectEnd: XBSAEndData call failed with %d\n", rc); xbsa_error(rc, info); return (BUTX_ENDDATAFAIL); } return (XBSA_SUCCESS); }
/* * Terminate the connection to the XBSA Server. * End the transaction. * BSATerminate */ afs_int32 xbsa_Finalize(struct butx_transactionInfo * info) { int rc; if (debugLevel > 98) { printf("\nxbsa_Finalize\n"); printf ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n", GOODSTR(info->serverName), GOODSTR(info->objOwner.bsaObjectOwner), GOODSTR(info->objOwner.appObjectOwner)); } if (info->bsaHandle == 0) { /* We haven't initialized yet! */ ELog(0, "xbsa_Finalize: No current handle, butx not initialized\n"); return (BUTX_NOHANDLE); } /* terminate the session */ rc = (int)XBSATerminate(info->bsaHandle); if (rc != BSA_RC_SUCCESS) { ELog(0, "The XBSATerminate call failed with %d\n", rc); xbsa_error(rc, info); return (BUTX_TERMFAIL); } info->bsaHandle = 0; return (XBSA_SUCCESS); }
/* * Delete a backup object from the server * BSAMarkObjectInactive() * BSADeleteObject() */ afs_int32 xbsa_DeleteObject(struct butx_transactionInfo * info, char *objectSpaceName, char *pathName) { int rc; ObjectName objectName; if (debugLevel > 98) { printf("\nxbsa_DeleteObject objectSpacename='%s' pathName='%s'\n", GOODSTR(objectSpaceName), GOODSTR(pathName)); printf ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n", GOODSTR(info->serverName), GOODSTR(info->objOwner.bsaObjectOwner), GOODSTR(info->objOwner.appObjectOwner)); } if (info->bsaHandle == 0) { /* We haven't initialized yet! */ ELog(0, "xbsa_DeleteObject: No current handle, butx not initialized\n"); return (BUTX_NOHANDLE); } if (objectSpaceName) { if (strlen(objectSpaceName) >= BSA_MAX_OSNAME) { ELog(0, "xbsa_DeleteObject: The objectSpaceName is too long; size = %d; name = %s\n", strlen(objectSpaceName), objectSpaceName); return (BUTX_INVALIDOBJECTSPNAME); } strcpy(objectName.objectSpaceName, objectSpaceName); } else { objectName.objectSpaceName[0] = NULL; } if (pathName) { if (strlen(pathName) >= BSA_MAX_PATHNAME) { ELog(0, "xbsa_DeleteObject: strlen(pathName), pathName\n", strlen(pathName), pathName); return (BUTX_INVALIDPATHNAME); } strcpy(objectName.pathName, pathName); } else { objectName.pathName[0] = NULL; } rc = (int)XBSAMarkObjectInactive(info->bsaHandle, &objectName); if (rc != BSA_RC_SUCCESS) { ELog(0, "xbsa_DeleteObject: XBSAMarkObjectInactive call failed with %d\n", rc); xbsa_error(rc, info); return ((rc == BSA_RC_ABORT_ACTIVE_NOT_FOUND) ? BUTX_DELETENOVOL : BUTX_DELETEOBJFAIL); } return (XBSA_SUCCESS); }
/* * Create a transaction * BSABeginTxn */ afs_int32 xbsa_BeginTrans(struct butx_transactionInfo * info) { int rc; if (debugLevel > 98) { printf("\nxbsa_BeginTrans\n"); printf ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n", GOODSTR(info->serverName), GOODSTR(info->objOwner.bsaObjectOwner), GOODSTR(info->objOwner.appObjectOwner)); } if (info->bsaHandle == 0) { /* We haven't initialized yet! */ ELog(0, "xbsa_BeginTrans: No current handle, butx not initialized\n"); return (BUTX_NOHANDLE); } rc = (int)XBSABeginTxn(info->bsaHandle); if (rc != BSA_RC_SUCCESS) { ELog(0, "xbsa_BeginTrans: The XBSABeginTxn call failed with %d\n", rc); xbsa_error(rc, info); return (BUTX_BEGINTXNFAIL); } info->numObjects = 0; return (XBSA_SUCCESS); }
/* * Locate the correct object on the server and then make the call to * get the object descriptor so we can begin the transfer of data. * BSAGetObject */ afs_int32 xbsa_ReadObjectBegin(struct butx_transactionInfo * info, char *dataBuffer, afs_int32 bufferSize, afs_int32 * count, afs_int32 * endOfData) { int rc; DataBlock dataBlock; if (debugLevel > 98) { printf("\nxbsa_ReadObjectBegin %d Bytes\n", bufferSize); printf ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n", GOODSTR(info->serverName), GOODSTR(info->objOwner.bsaObjectOwner), GOODSTR(info->objOwner.appObjectOwner)); } if (info->bsaHandle == 0) { /* We haven't initialized yet! */ ELog(0, "xbsa_ReadObjectBegin: No current handle, butx not initialized\n"); return (BUTX_NOHANDLE); } if ((bufferSize < 0) || (bufferSize > XBSAMAXBUFFER)) { ELog(0, "xbsa_ReadObjectBegin: The bufferSize %d is invalid\n", bufferSize); return (BUTX_INVALIDBUFFERSIZE); } if (dataBuffer == NULL) { ELog(0, "xbsa_ReadObjectBegin: The dataBuffer is NULL\n"); return (BUTX_INVALIDDATABUFFER); } dataBlock.bufferLen = (BSA_UInt16) bufferSize; dataBlock.numBytes = (BSA_UInt16) 0; dataBlock.bufferPtr = dataBuffer; *endOfData = 0; rc = (int)XBSAGetObject(info->bsaHandle, &info->curObject, &dataBlock); if ((rc != BSA_RC_MORE_DATA) && (rc != BSA_RC_NO_MORE_DATA)) { ELog(0, "xbsa_ReadObjectBegin: The XBSAGetObject call failed with %d\n", rc); xbsa_error(rc, info); return (BUTX_GETOBJFAIL); } *count = dataBlock.numBytes; if (rc == BSA_RC_NO_MORE_DATA) *endOfData = 1; return (XBSA_SUCCESS); }
VixMntMsgQue::VixMntMsgQue(const char *msg_name, bool readOnly) { // readOnly is unused now. this->readOnly = readOnly; if (!msg_name) { this->vixMntMsgMapFileName = VixMntMsgQue::vixMntMsgName; } else { this->vixMntMsgMapFileName = msg_name; } this->vixMntMsgID = mq_open(this->vixMntMsgMapFileName.c_str(), O_CREAT | O_RDWR, 0644, NULL); if (this->vixMntMsgID < 0) { if (errno == EEXIST) { WLog("exist mqid : %d | mq_name : %s", this->getVixMntMsgID(), vixMntMsgMapFileName.c_str()); } else { ELog("open mesage queue error %s ", strerror(errno)); } } assert(this->vixMntMsgID > 0); VixMntMsgQue::vixMntMsgMap[this->vixMntMsgMapFileName] = this->vixMntMsgID; }
VixMntMmap::VixMntMmap(size_t mmap_datasize, bool isRoot) { try { if (isRoot) { this->file_name = VixMntMmap::fileRoot; } else this->file_name = "/vmware_mnt_tmp"; } catch (std::exception &e) { ELog("set file_name error"); this->file_name = "/vmware_mnt_shm"; } this->fid = shm_open(this->file_name.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0666); if (this->fid > 0) { ILog("open share memory %d %s", this->fid, this->file_name.c_str()); } else { ILog("open share memory faild, map to file%d", this->fid); } this->mmap_datasize = mmap_datasize > 0 ? mmap_datasize : MMAP_PAGE_SIZE; this->mmap_pagenum = this->mmap_datasize / MMAP_PAGE_SIZE + 1; int sh_result = ftruncate(this->fid, this->mmap_pagenum * MMAP_PAGE_SIZE); if (sh_result < 0) { ELog("shm ftruncate error "); } if (this->fid == -1) { this->mmap_data = (char *)mmap(NULL, this->mmap_pagenum * MMAP_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); } else { this->mmap_data = (char *)mmap(NULL, this->mmap_pagenum * MMAP_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, this->fid, 0); } ILog("shm mmap addr : %x", this->mmap_data); }
void VixMntMsgQue::receiveMsg(VixMntMsgData *msg_data, unsigned *msg_prio) { mq_attr tempAttr; this->getattr(&tempAttr); assert(8192 >= tempAttr.mq_msgsize && tempAttr.mq_msgsize > 0); char *buf = new char[tempAttr.mq_msgsize]; if (receive(buf, tempAttr.mq_msgsize, msg_prio) < 0) { ELog("receive error"); msg_data->msg_op = VixMntOp(ERROR); throw VixMntException("Receive Error"); } else { memcpy(msg_data, buf, sizeof(VixMntMsgData)); } delete[] buf; }
/* * Create the XBSA Backup Copy Object. * BSACreateObject */ afs_int32 xbsa_WriteObjectBegin(struct butx_transactionInfo * info, char *objectSpaceName, char *pathName, char *lGName, afs_hyper_t estimatedSize, char *objectDescription, char *objectInfo) { int rc; int length; DataBlock dataBlock; if (debugLevel > 98) { printf ("\nxbsa_WriteObjectBegin objectSpacename='%s' pathName='%s' lGName='%s' " "estimatesSize='0x%x%08x objectDescription='%s' objectInfo='%s'\n", GOODSTR(objectSpaceName), GOODSTR(pathName), GOODSTR(lGName), hgethi(estimatedSize), hgetlo(estimatedSize), GOODSTR(objectDescription), GOODSTR(objectInfo)); printf ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n", GOODSTR(info->serverName), GOODSTR(info->objOwner.bsaObjectOwner), GOODSTR(info->objOwner.appObjectOwner)); } if (info->bsaHandle == 0) { /* We haven't initialized yet! */ ELog(0, "xbsa_WriteObjectBegin: No current handle, butx not initialized\n"); return (BUTX_NOHANDLE); } if (objectSpaceName) { if (strlen(objectSpaceName) >= BSA_MAX_OSNAME) { ELog(0, "xbsa_WriteObjectBegin: The objectSpaceName is too long; size = %d; name = %s\n", strlen(objectSpaceName), objectSpaceName); return (BUTX_INVALIDOBJECTSPNAME); } strcpy(info->curObject.objName.objectSpaceName, objectSpaceName); } else { info->curObject.objName.objectSpaceName[0] = NULL; } if (pathName) { if (strlen(pathName) >= BSA_MAX_PATHNAME) { ELog(0, "xbsa_WriteObjectBegin: The pathName is too long; size = %d; name = %s\n", strlen(pathName), pathName); return (BUTX_INVALIDPATHNAME); } strcpy(info->curObject.objName.pathName, pathName); } else { info->curObject.objName.pathName[0] = NULL; } if (lGName) { if (strlen(lGName) >= BSA_MAX_LG_NAME) { ELog(0, "xbsa_WriteObjectBegin: The lGName is too long; size = %d; name = %s\n", strlen(lGName), lGName); return (BUTX_INVALIDLGNAME); } strcpy(info->curObject.lGName, lGName); } else { info->curObject.lGName[0] = NULL; } if (objectDescription) { if (((XBSA_GET_SERVER_TYPE(info->serverType) == XBSA_SERVER_TYPE_ADSM) && (strlen(objectDescription) >= ADSM_MAX_DESC)) || ((XBSA_GET_SERVER_TYPE(info->serverType) != XBSA_SERVER_TYPE_ADSM) && (strlen(objectDescription) >= BSA_MAX_DESC))) { ELog(0, "xbsa_WriteObjectBegin: The objectDescription is too long; size = %d; name = %s\n", strlen(objectDescription), objectDescription); return (BUTX_INVALIDOBJDESC); } strcpy(info->curObject.desc, objectDescription); } else { info->curObject.desc[0] = NULL; } if (objectInfo) { if (((XBSA_GET_SERVER_TYPE(info->serverType) == XBSA_SERVER_TYPE_ADSM) && (strlen(objectInfo) >= ADSM_MAX_OBJINFO)) || ((XBSA_GET_SERVER_TYPE(info->serverType) != XBSA_SERVER_TYPE_ADSM) && (strlen(objectInfo) >= BSA_MAX_OBJINFO))) { ELog(0, "xbsa_WriteObjectBegin: The objectInfo is too long; size = %d; name = %s\n", strlen(objectInfo), objectInfo); return (BUTX_INVALIDOBJINFO); } strcpy(info->curObject.objectInfo, objectInfo); } else { info->curObject.objectInfo[0] = NULL; } if (info->numObjects == info->maxObjects) { /* If we've used up Max Objects we must start a new transaction. */ rc = (int)xbsa_EndTrans(info); if (rc != XBSA_SUCCESS) { return (rc); } rc = (int)xbsa_BeginTrans(info); if (rc != XBSA_SUCCESS) { return (rc); } } dataBlock.bufferLen = (BSA_UInt16) 0; dataBlock.numBytes = (BSA_UInt16) 0; dataBlock.bufferPtr = 0; info->curObject.Owner = info->objOwner; info->curObject.copyType = BSACopyType_BACKUP; info->curObject.size.left = hgethi(estimatedSize); info->curObject.size.right = hgetlo(estimatedSize); info->curObject.objectType = BSAObjectType_FILE; strcpy(info->curObject.resourceType, resourceType); rc = (int)XBSACreateObject(info->bsaHandle, &info->curObject, &dataBlock); if (rc != BSA_RC_SUCCESS) { ELog(0, "xbsa_WriteObjectBegin: The XBSACreateObject call failed with %d\n", rc); xbsa_error(rc, info); return (BUTX_CREATEOBJFAIL); } info->numObjects++; return (XBSA_SUCCESS); }
xbsa_error(int rc, struct butx_transactionInfo *info) { switch (rc) { case BSA_RC_AUTHENTICATION_FAILURE: ELog(0, " XBSA: Authentication failure\n"); break; case BSA_RC_INVALID_KEYWORD: ELog(0, " XBSA: A specified keyword is invalid\n"); break; case BSA_RC_TOKEN_EXPIRED: ELog(0, " XBSA: The security token has expired\n"); break; case ADSM_RC_PSWD_GEN: if (XBSA_GET_SERVER_TYPE(info->serverType) == XBSA_SERVER_TYPE_ADSM) { ELog(0, " XBSA: Password generation is not supported\n"); } break; case BSA_RC_BAD_HANDLE: ELog(0, " XBSA: The handle is invalid, %d\n", info->bsaHandle); break; case BSA_RC_NO_MATCH: ELog(0, " XBSA: There were no matches found for the specified object\n"); break; case BSA_RC_MORE_DATA: ELog(0, " XBSA: There were more matches found than expected\n"); break; case BSA_RC_NULL_OBJNAME: ELog(0, " XBSA: The object name is null\n"); break; case BSA_RC_OBJNAME_TOO_LONG: ELog(0, " XBSA: The object name was longer than expected\n"); break; case BSA_RC_DESC_TOO_LONG: ELog(0, " XBSA: The description string was longer than expected\n"); break; case BSA_RC_OBJINFO_TOO_LONG: ELog(0, " XBSA: The object info string was longer than expected\n"); break; case BSA_RC_ABORT_ACTIVE_NOT_FOUND: ELog(0, " XBSA: The specified object was not found\n"); break; case BSA_RC_NULL_DATABLKPTR: ELog(0, " XBSA: The dataBlockPtr is null\n"); break; case BSA_RC_INVALID_VOTE: ELog(0, " XBSA: The vote variable is invalid\n"); break; } }
/* * Query for the object we are looking for. * BSAQueryObject */ afs_int32 xbsa_QueryObject(struct butx_transactionInfo * info, char *objectSpaceName, char *pathName) { int rc; QueryDescriptor queryDescriptor; if (debugLevel > 98) { printf("\nxbsa_QueryObject objectSpaceName='%s' pathnName='%s'\n", GOODSTR(objectSpaceName), GOODSTR(pathName)); printf ("serverName='%s' ; bsaObjectOwner='%s' ; appObjectOwner='%s' ; sectoken=xxxxxx\n", GOODSTR(info->serverName), GOODSTR(info->objOwner.bsaObjectOwner), GOODSTR(info->objOwner.appObjectOwner)); } if (info->bsaHandle == 0) { /* We haven't initialized yet! */ ELog(0, "xbsa_QueryObject: No current handle, butx not initialized\n"); return (BUTX_NOHANDLE); } /* Initialize the query for our dump name */ if (objectSpaceName) { if (strlen(objectSpaceName) >= BSA_MAX_OSNAME) { ELog(0, "xbsa_QueryObject: The objectSpaceName is too long; size = %d; name = %s\n", strlen(objectSpaceName), objectSpaceName); return (BUTX_INVALIDOBJECTSPNAME); } strcpy(queryDescriptor.objName.objectSpaceName, objectSpaceName); } else { queryDescriptor.objName.objectSpaceName[0] = NULL; } if (pathName) { if (strlen(pathName) >= BSA_MAX_PATHNAME) { ELog(0, "xbsa_QueryObject: The pathName is too long; size = %d; name = %s\n", strlen(pathName), pathName); return (BUTX_INVALIDPATHNAME); } strcpy(queryDescriptor.objName.pathName, pathName); } else { queryDescriptor.objName.pathName[0] = NULL; } queryDescriptor.owner = info->objOwner; queryDescriptor.copyType = BSACopyType_BACKUP; strcpy(queryDescriptor.lGName, ""); strcpy(queryDescriptor.cGName, ""); strcpy(queryDescriptor.resourceType, ""); queryDescriptor.objectType = BSAObjectType_FILE; queryDescriptor.status = BSAObjectStatus_ACTIVE; strcpy(queryDescriptor.desc, ""); rc = (int)XBSAQueryObject(info->bsaHandle, &queryDescriptor, &info->curObject); if (rc == BSA_RC_NO_MORE_DATA) rc = BSA_RC_SUCCESS; /* This is actually a success! */ if (rc != BSA_RC_SUCCESS) { ELog(0, "xbsa_QueryObject: The xBSAQueryObject call failed with %d\n", rc); xbsa_error(rc, info); return (BUTX_QUERYFAIL); } return (XBSA_SUCCESS); }
/* * Set up the connection to the XBSA Server. * BSAInit * BSAGetEnvironment */ afs_int32 xbsa_Initialize(struct butx_transactionInfo * info, char *bsaObjectOwner, char *appObjectOwner, char *secToken, char *serverName) { char envStrs[XBSA_NUM_ENV_STRS][BSA_MAX_DESC]; char *envP[XBSA_NUM_ENV_STRS + 1]; char *ADSMMaxObject = "TSMMAXOBJ="; char *ADSMServer = "TSMSRVR="; char *tempStrPtr; int i; int rc; if (debugLevel > 98) { printf("\nxbsa_Initialize bsaObjectOwner='%s' appObjectOwner='%s' " "secToken=xxxxxx servername='%s'\n", GOODSTR(bsaObjectOwner), GOODSTR(appObjectOwner), GOODSTR(serverName)); } if (info->bsaHandle != 0) { /* We already have a handle */ ELog(0, "xbsa_Initialize: The dlopen call to load the XBSA shared library failed\n"); return (BUTX_ILLEGALINIT); } /* * The XBSAGetEnvironment function is supposed to return the * the serverName to use. However, it is returning the tcpserveraddress * instead. So, we can't count on this function to properly fill it * in. So, until that get fixed. The serverName will have to be filled * in by the callers of this function (butc). */ /* Initialize the environment strings */ for (i = 0; i < XBSA_NUM_ENV_STRS; i++) envP[i] = envStrs[i]; envP[XBSA_NUM_ENV_STRS] = NULL; /* The environment variables are specific to the server type */ switch (XBSA_GET_SERVER_TYPE(info->serverType)) { case XBSA_SERVER_TYPE_ADSM: if (serverName) { if (strlen(serverName) >= BSA_MAX_DESC) { ELog(0, "xbsa_Initialize: The serverName was not specified\n"); return (BUTX_INVALIDSERVERNAME); } strcpy(info->serverName, serverName); strcpy(envP[0], ADSMServer); tempStrPtr = envP[0]; tempStrPtr = tempStrPtr + strlen(ADSMServer); strcat(tempStrPtr, serverName); envP[1] = NULL; envP[0] = NULL; /* Hack for TSM V5 */ } else { envP[0] = NULL; ELog(0, "xbsa_Initialize: The serverName was not specified\n"); return (BUTX_INVALIDSERVERNAME); } break; default: ELog(0, "xbsa_Initialize: The serverType %d is not recognized\n", XBSA_GET_SERVER_TYPE(info->serverType)); return (BUTX_INVALIDSERVERTYPE); break; } if (bsaObjectOwner) { if (strlen(bsaObjectOwner) >= BSA_MAX_BSAOBJECT_OWNER) { ELog(0, "xbsa_Initialize: The bsaObjectOwner is too long; size = %d; name = %s\n", strlen(bsaObjectOwner), bsaObjectOwner); return (BUTX_INVALIDBSANAME); } strcpy(info->objOwner.bsaObjectOwner, bsaObjectOwner); } else { info->objOwner.bsaObjectOwner[0] = NULL; } if (appObjectOwner) { if (strlen(appObjectOwner) >= BSA_MAX_APPOBJECT_OWNER) { ELog(0, "xbsa_Initialize: The appObjectOwner is too long; size = %d; name = %s\n", strlen(appObjectOwner), appObjectOwner); return (BUTX_INVALIDAPPNAME); } strcpy(info->objOwner.appObjectOwner, appObjectOwner); } else { info->objOwner.appObjectOwner[0] = NULL; } if (secToken) { if (strlen(secToken) >= BSA_MAX_TOKEN_SIZE) { ELog(0, "xbsa_Initialize: The secToken is too long; size = %d; name = %s\n", strlen(secToken), secToken); return (BUTX_INVALIDSECTOKEN); } strcpy(info->secToken, secToken); } else { info->secToken[0] = NULL; } rc = (int)XBSAInit(&(info->bsaHandle), &(info->secToken), &(info->objOwner), envP); if (rc != BSA_RC_SUCCESS) { ELog(0, "xbsa_Initialize: The XBSAInit call failed with %d\n", rc); xbsa_error(rc, info); return (BUTX_INITFAIL); } /* Initialize the environment strings */ for (i = 0; i < XBSA_NUM_ENV_STRS; i++) envP[i] = envStrs[i]; envP[XBSA_NUM_ENV_STRS] = NULL; rc = (int)XBSAGetEnvironment(info->bsaHandle, &info->objOwner, envP); if (rc != BSA_RC_SUCCESS) { ELog(0, "xbsa_Initialize: The XBSAGetEnvironment call failed with %d\n", rc); xbsa_error(rc, info); return (BUTX_GETENVFAIL); } info->maxObjects = 255; /* Hack for ADSM V5: unclear what this actually means... */ switch (XBSA_GET_SERVER_TYPE(info->serverType)) { case XBSA_SERVER_TYPE_ADSM: for (i = 0; i < XBSA_NUM_ENV_STRS; i++) { if (strncmp(envP[i], ADSMMaxObject, sizeof(ADSMMaxObject)) == 0) { tempStrPtr = envP[i]; tempStrPtr = tempStrPtr + strlen(ADSMMaxObject); info->maxObjects = strtol(tempStrPtr, NULL, 10); if (info->maxObjects <= 0) { ELog(0, "xbsa_Initialize: The XBSAGetEnvironment call returned an invalid value for MAXOBJ %d\n", info->maxObjects); return (BUTX_GETENVFAIL); } } } if (info->maxObjects == 0) { ELog(0, "xbsa_Initialize: The XBSAGetEnvironment call failed to return the MAXOBJ string\n"); return (BUTX_GETENVFAIL); } break; } return (XBSA_SUCCESS); }
/* * Hook into the correct XBSA shared library. * Set up the function pointers. * Get the library version. * XBSAQueryApiVersion */ afs_int32 xbsa_MountLibrary(struct butx_transactionInfo *info, afs_int32 serverType) { void *dynlib; int rc; if (debugLevel > 98) { printf("\nxbsa_MountLibraray\n"); } switch (serverType) { case XBSA_SERVER_TYPE_ADSM: #ifndef NEW_XBSA #if defined(AFS_AIX_ENV) dynlib = dlopen("/usr/lib/libXApi.a(bsashr10.o)", RTLD_NOW | RTLD_LOCAL | RTLD_MEMBER); if (dynlib == NULL) { dynlib = dlopen("/usr/lib/libXApi.a(xbsa.o)", RTLD_NOW | RTLD_LOCAL | RTLD_MEMBER); } #elif defined(AFS_SUN5_ENV) dlopen ("/usr/lib/libCstd.so.1", RTLD_NOW | RTLD_GLOBAL); dynlib = dlopen("/usr/lib/libXApi.so", RTLD_NOW | RTLD_GLOBAL); #else dynlib = NULL; #endif #endif break; default: ELog(0, "xbsa_MountLibrary: The serverType %d is not recognized\n", serverType); return (BUTX_INVALIDSERVERTYPE); break; } #ifndef NEW_XBSA if (dynlib == NULL) { ELog(0, "xbsa_MountLibrary: The dlopen call to load the XBSA shared library failed\n"); return (BUTX_NOLIBRARY); } #endif memset(info, 0, sizeof(struct butx_transactionInfo)); XBSA_SET_SERVER_TYPE(info->serverType, serverType); #ifndef NEW_XBSA #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) XBSAInit = (BSA_Int16(*) (BSA_UInt32 *, SecurityToken *, ObjectOwner *, char **))dlsym((void *)dynlib, "BSAInit"); XBSABeginTxn = (BSA_Int16(*)(BSA_UInt32)) dlsym((void *)dynlib, "BSABeginTxn"); XBSAEndTxn = (BSA_Int16(*)(BSA_UInt32, Vote)) dlsym((void *)dynlib, "BSAEndTxn"); XBSATerminate = (BSA_Int16(*)(BSA_UInt32)) dlsym((void *)dynlib, "BSATerminate"); XBSAQueryObject = (BSA_Int16(*)(BSA_UInt32, QueryDescriptor *, ObjectDescriptor *)) dlsym((void *)dynlib, "BSAQueryObject"); XBSAGetObject = (BSA_Int16(*)(BSA_UInt32, ObjectDescriptor *, DataBlock *)) dlsym((void *)dynlib, "BSAGetObject"); XBSAEndData = (BSA_Int16(*)(BSA_UInt32)) dlsym((void *)dynlib, "BSAEndData"); XBSACreateObject = (BSA_Int16(*)(BSA_UInt32, ObjectDescriptor *, DataBlock *)) dlsym((void *)dynlib, "BSACreateObject"); XBSAMarkObjectInactive = (BSA_Int16(*)(BSA_UInt32, ObjectName *)) dlsym((void *)dynlib, "BSAMarkObjectInactive"); XBSADeleteObject = (BSA_Int16(*)(BSA_UInt32, CopyType, ObjectName *, CopyId *)) dlsym((void *)dynlib, "BSADeleteObject"); XBSASendData = (BSA_Int16(*)(BSA_UInt32, DataBlock *)) dlsym((void *)dynlib, "BSASendData"); XBSAGetData = (BSA_Int16(*)(BSA_UInt32, DataBlock *)) dlsym((void *)dynlib, "BSAGetData"); XBSAQueryApiVersion = (BSA_Int16(*)(ApiVersion *)) dlsym((void *)dynlib, "BSAQueryApiVersion"); XBSAGetEnvironment = (BSA_Int16(*)(BSA_UInt32, ObjectOwner *, char **))dlsym((void *) dynlib, "BSAGetEnvironment"); if (!XBSAInit || !XBSABeginTxn || !XBSAEndTxn || !XBSATerminate || !XBSAQueryObject || !XBSAGetObject || !XBSAEndData || !XBSACreateObject || !XBSADeleteObject || !XBSAMarkObjectInactive || !XBSASendData || !XBSAGetData || !XBSAQueryApiVersion || !XBSAGetEnvironment) { ELog(0, "xbsa_MountLibrary: The dlopen call to load the XBSA shared library failed\n"); return (BUTX_NOLIBRARY); } XBSAQueryApiVersion(&(info->apiVersion)); #endif #else #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX26_ENV) XBSAInit = BSAInit; XBSABeginTxn = BSABeginTxn; XBSAEndTxn = BSAEndTxn; XBSATerminate = BSATerminate; XBSAQueryObject = BSAQueryObject; XBSAGetObject = BSAGetObject; XBSAEndData = BSAEndData; XBSACreateObject = BSACreateObject; XBSAMarkObjectInactive = BSAMarkObjectInactive; XBSADeleteObject = BSADeleteObject; XBSASendData = BSASendData; XBSAGetData = BSAGetData; XBSAQueryApiVersion = BSAQueryApiVersion; XBSAGetEnvironment = BSAGetEnvironment; if (!XBSAInit || !XBSABeginTxn || !XBSAEndTxn || !XBSATerminate || !XBSAQueryObject || !XBSAGetObject || !XBSAEndData || !XBSACreateObject || !XBSADeleteObject || !XBSAMarkObjectInactive || !XBSASendData || !XBSAGetData || !XBSAQueryApiVersion || !XBSAGetEnvironment) { ELog(0,"xbsa_MountLibrary: The dlopen call to load the XBSA shared library failed\n"); return(BUTX_NOLIBRARY); } XBSAQueryApiVersion(&(info->apiVersion)); #endif #endif #ifdef DEBUG_BUTC printf("xbsa_MountLibrary : XBSA function Pointers initialised. \n"); #endif /* * Verify the API version */ if ((info->apiVersion.version == XBSA_TS_VERSION) && (info->apiVersion.release == XBSA_TS_RELEASE)) { /* XOPEN Techincal Standard Level! * We are coded to the Preliminary Spec! Time to go boom! */ ELog(0, "xbsa_MountLibrary: The XBSAQueryApiVersion call returned an incompatible version, %d %d %d\n", info->apiVersion.version, info->apiVersion.release, info->apiVersion.level); return (BUTX_INVALIDVERSION); } switch (XBSA_GET_SERVER_TYPE(info->serverType)) { case XBSA_SERVER_TYPE_ADSM: if ((info->apiVersion.version > XBSA_ADSM_NO_MULT_SERVER_VERSION) || (info->apiVersion.version == XBSA_ADSM_NO_MULT_SERVER_VERSION && info->apiVersion.release > XBSA_ADSM_NO_MULT_SERVER_RELEASE) || (info->apiVersion.version == XBSA_ADSM_NO_MULT_SERVER_VERSION && info->apiVersion.release == XBSA_ADSM_NO_MULT_SERVER_RELEASE && info->apiVersion.level > XBSA_ADSM_NO_MULT_SERVER_LEVEL)) { /* This version contains the fixes to allow multiple servers */ info->serverType |= XBSA_SERVER_FLAG_MULTIPLE; } else { /* This is an older version of ADSM prior to the fix to * allow multiple servers. */ info->serverType |= XBSA_SERVER_FLAG_NONE; } break; } return (XBSA_SUCCESS); }
int main() { ILog("Info"); vixMntIPC_InitMmap(0x100, 0); const char msg[12] = "mmap test 1"; size_t msg_len = strlen(msg); char *buf = new char[msg_len]; /* * test same process whether mmap is works vixMntIPC_WriteMmap(msg,0,msg_len); vixMntIPC_ReadMmap(buf,0,msg_len); vixMntIPC_CleanMmap(); ILog("buf len %d -- (%s)",msg_len,buf); printf("%s\n",buf); */ /* * test mmap between two processes */ sem_t *semaphore = sem_open("/sema", O_CREAT, 0777, 0); pid_t pid = fork(); if (!pid) { vixMntIPC_WriteMmap(msg, 10, msg_len); sem_post(semaphore); sem_close(semaphore); exit(0); } sem_wait(semaphore); vixMntIPC_ReadMmap(buf, 10, msg_len); sem_close(semaphore); sem_unlink("/sema"); vixMntIPC_CleanMmap(); ILog("buf len %d -- (%s)", msg_len, buf); delete[] buf; pthread_t pid_t = listening(); pthread_t pid_t2 = listening(); VixMntMsgQue *msgque = VixMntMsgQue::getMsgQueInstance(); ILog("size of msgque instance %u", sizeof(*msgque)); VixMntMsgQue *msgque2 = new VixMntMsgQue("/test2"); VixMntMsgQue *msgque3 = new VixMntMsgQue("/test3"); ILog("size of msgque instance %u", sizeof(VixMntMsgQue)); delete msgque3; delete msgque2; if (!pid_t) { ELog("error goto clean"); goto clean; } /* * TODO : * will received ERROR when send HALT */ msgque->sendMsgOp(VixMntOp(MntInit)); msgque->sendMsgOp(VixMntOp(MntWrite)); msgque->sendMsgOp(VixMntOp(MntReadDone)); msgque->sendMsgOp(VixMntOp(MntRead)); msgque->sendMsgOp(VixMntOp(HALT)); msgque->sendMsgOp(VixMntOp(HALT)); // sleep(4); pthread_join(pid_t, NULL); pthread_join(pid_t2, NULL); msgque->unlink(); VixMntMsgQue::releaseMsgQueInstance(); clean: ILog("end all"); return 0; }