Tivoli Header

Tivoli Storage Manager Using the Application Program Interface

An Example

Figure 14 demonstrates the use of the API functions that send data to TSM storage. The dsmSendObj call appears inside a switch statement, so that different parameters can be called depending on whether a backup or archive operation is being performed. The dsmSendData call is called from inside a loop that repeatedly sends data until a flag is set that permits the program execution to exit the loop. The entire send operation is performed from within the transaction.

The third parameter on the dsmSendObj call is a buffer that contains the archive description. Because backup objects do not have a description, this parameter is NULL when backing up an object.

Figure 8 displays an example that shows the use of the dsmBindMC function call.

Figure 14. An Example of Sending Data to a Server

+--------------------------------------------------------------------------------+
|if ((rc = dsmBeginTxn(dsmHandle)) )       /* API session handle  */             |
|{                                                                               |
|   printf("*** dsmBeginTxn failed: ");                                          |
|   rcApiOut(dsmHandle, rc);                                                     |
|   return;                                                                      |
|}                                                                               |
|                                                                                |
|/*  Call dsmBindMC if not done previously */                                    |
|objAttr.sizeEstimate.hi = 0;       /* estimate of        */                     |
|objAttr.sizeEstimate.lo = 32000;   /*        object size */                     |
|switch (send_type)                                                              |
|{                                                                               |
|   case (Backup_Send) :                                                         |
|      rc = dsmSendObj(dsmHandle,stBackup,                                       |
|      NULL,&objName,&objAttr,NULL);                                             |
|      break;                                                                    |
|   case (Archive_Send) :                                                        |
|      archData.stVersion = sndArchiveDataVersion;                               |
|      archData.descr = desc;                                                    |
|      rc = dsmSendObj(dsmHandle,stArchive,                                      |
|   &archData,&objName,&objAttr,NULL);                                           |
|      break;                                                                    |
|   default : ;                                                                  |
|}                                                                               |
|if (rc)                                                                         |
|{                                                                               |
|   printf("*** dsmSendObj failed: ");                                           |
|   rcApiOut(dsmHandle, rc);                                                     |
|   return;                                                                      |
|}                                                                               |
|                                                                                |
|done = bFalse;                                                                  |
|while (!done)                                                                   |
|{                                                                               |
|   dataBlk.stVersion = DataBlkVersion;                                          |
|   dataBlk.bufferLen = send_amt;                                                |
|   dataBlk.numBytes  = 0;                                                       |
|   dataBlk.bufferPtr = bkup_buff;                                               |
|   rc = dsmSendData(dsmHandle,&dataBlk);                                        |
|   if (rc)                                                                      |
|   {                                                                            |
|      printf("*** dsmSendData failed: ");                                       |
|      rcApiOut(dsmHandle, rc);                                                  |
|      done = bTrue;                                                             |
|   }                                                                            |
|   /* Adjust the dataBlk buffer for the next piece to send */                   |
|}                                                                               |
|                                                                                |
+--------------------------------------------------------------------------------+
+--------------------------------------------------------------------------------+
|rc = dsmEndSendObj(dsmHandle);                                                  |
|if (rc)                                                                         |
|{                                                                               |
|   printf("*** dsmEndSendObj failed: ");                                        |
|   rcApiOut(dsmHandle, rc);                                                     |
|}                                                                               |
|txn_reason = 0;                                                                 |
|rc = dsmEndTxn(dsmHandle,           /* API session handle       */              |
|             DSM_VOTE_COMMIT,      /* Commit transaction       */               |
|             &txn_reason);         /* Reason if txn aborted    */               |
|if (rc || txn_reason)                                                           |
|{                                                                               |
|   printf("*** dsmEndTxn failed: rc = ");                                       |
|   rcApiOut(dsmHandle, rc);                                                     |
|   printf("   reason = %u\n",txn_reason);                                       |
|}                                                                               |
+--------------------------------------------------------------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]