"Fossies" - the Fresh Open Source Software Archive

Member "opensaf-5.21.09/src/ntf/ntfd/ntfs_mds.c" (14 Sep 2021, 37353 Bytes) of package /linux/misc/opensaf-5.21.09.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ntfs_mds.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.21.06_vs_5.21.09.

    1 /*      -*- OpenSAF  -*-
    2  *
    3  * (C) Copyright 2008 The OpenSAF Foundation
    4  *
    5  * This program is distributed in the hope that it will be useful, but
    6  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    7  * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed
    8  * under the GNU Lesser General Public License Version 2.1, February 1999.
    9  * The complete license can be accessed from the following location:
   10  * http://opensource.org/licenses/lgpl-license.php
   11  * See the Copying file included with the OpenSAF distribution for full
   12  * licensing terms.
   13  *
   14  * Author(s): Ericsson AB
   15  *
   16  */
   17 
   18 #include "base/ncsencdec_pub.h"
   19 #include "ntf/common/ntfsv_enc_dec.h"
   20 #include "ntf/ntfd/ntfs.h"
   21 #include "ntf/ntfd/ntfs_com.h"
   22 
   23 #define NTFS_SVC_PVT_SUBPART_VERSION 1
   24 #define NTFS_WRT_NTFA_SUBPART_VER_AT_MIN_MSG_FMT 1
   25 #define NTFS_WRT_NTFA_SUBPART_VER_AT_MAX_MSG_FMT 1
   26 #define NTFS_WRT_NTFA_SUBPART_VER_RANGE                                        \
   27     (NTFS_WRT_NTFA_SUBPART_VER_AT_MAX_MSG_FMT -                            \
   28      NTFS_WRT_NTFA_SUBPART_VER_AT_MIN_MSG_FMT + 1)
   29 
   30 static MDS_CLIENT_MSG_FORMAT_VER
   31     NTFS_WRT_NTFA_MSG_FMT_ARRAY[NTFS_WRT_NTFA_SUBPART_VER_RANGE] = {
   32     1 /*msg format version for NTFA subpart version 1 */
   33 };
   34 
   35 /****************************************************************************
   36  * Name          : ntfs_evt_destroy
   37  *
   38  * Description   : This is the function which is called to destroy an event.
   39  *
   40  * Arguments     : NTFSV_NTFS_EVT *
   41  *
   42  * Return Values : NONE
   43  *
   44  * Notes         : None.
   45  *
   46  * @param evt
   47  */
   48 void ntfs_evt_destroy(ntfsv_ntfs_evt_t *evt)
   49 {
   50     osafassert(evt != NULL);
   51     free(evt);
   52 }
   53 
   54 /****************************************************************************
   55   Name          : dec_initialize_msg
   56 
   57   Description   : This routine decodes an initialize API msg
   58 
   59   Arguments     : NCS_UBAID *msg,
   60           NTFSV_MSG *msg
   61 
   62   Return Values : uns32
   63 
   64   Notes         : None.
   65 ******************************************************************************/
   66 static uint32_t dec_initialize_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
   67 {
   68     uint8_t *p8;
   69     ntfsv_initialize_req_t *param = &msg->info.api_info.param.init;
   70     uint8_t local_data[3];
   71 
   72     /* releaseCode, majorVersion, minorVersion */
   73     p8 = ncs_dec_flatten_space(uba, local_data, 3);
   74     param->version.releaseCode = ncs_decode_8bit(&p8);
   75     param->version.majorVersion = ncs_decode_8bit(&p8);
   76     param->version.minorVersion = ncs_decode_8bit(&p8);
   77     ncs_dec_skip_space(uba, 3);
   78 
   79     TRACE_8("NTFSV_INITIALIZE_REQ");
   80     return NCSCC_RC_SUCCESS;
   81 }
   82 
   83 /****************************************************************************
   84   Name          : dec_finalize_msg
   85 
   86   Description   : This routine decodes a finalize API msg
   87 
   88   Arguments     : NCS_UBAID *msg,
   89           NTFSV_MSG *msg
   90 
   91   Return Values : uns32
   92 
   93   Notes         : None.
   94 ******************************************************************************/
   95 static uint32_t dec_finalize_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
   96 {
   97     uint8_t *p8;
   98     ntfsv_finalize_req_t *param = &msg->info.api_info.param.finalize;
   99     uint8_t local_data[4];
  100 
  101     /* client_id */
  102     p8 = ncs_dec_flatten_space(uba, local_data, 4);
  103     param->client_id = ncs_decode_32bit(&p8);
  104     ncs_dec_skip_space(uba, 4);
  105 
  106     TRACE_8("NTFSV_FINALIZE_REQ");
  107     return NCSCC_RC_SUCCESS;
  108 }
  109 
  110 /****************************************************************************
  111   Name          : dec_subscribe_msg
  112 
  113   Description   : This routine decodes a ntf subscribe  API msg
  114 
  115   Arguments     : NCS_UBAID *msg,
  116           NTFSV_MSG *msg
  117 
  118   Return Values : uns32
  119 
  120   Notes         : None.
  121 ******************************************************************************/
  122 static uint32_t dec_subscribe_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  123 {
  124     ntfsv_subscribe_req_t *param = &msg->info.api_info.param.subscribe;
  125     return ntfsv_dec_subscribe_msg(uba, param);
  126 }
  127 
  128 /****************************************************************************
  129   Name          : dec_unsubscribe_msg
  130 
  131   Description   : This routine decodes a ntf unsubscribe API msg
  132 
  133   Arguments     : NCS_UBAID *uba,
  134           NTFSV_MSG *msg
  135 
  136   Return Values : uns32
  137 
  138   Notes         : None.
  139 ******************************************************************************/
  140 static uint32_t dec_unsubscribe_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  141 {
  142     ntfsv_unsubscribe_req_t *param = &msg->info.api_info.param.unsubscribe;
  143     return ntfsv_dec_unsubscribe_msg(uba, param);
  144 }
  145 
  146 /****************************************************************************
  147   Name          : dec_write_ntf_async_msg
  148 
  149   Description   : This routine decodes a notificaton API msg
  150 
  151   Arguments     : NCS_UBAID *msg,
  152           NTFSV_MSG *msg
  153 
  154   Return Values : uns32
  155 
  156   Notes         : None.
  157 ******************************************************************************/
  158 static uint32_t dec_send_not_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  159 {
  160     ntfsv_send_not_req_t *param;
  161     /* deallocated in NtfNotification class */
  162     param = calloc(1, sizeof(ntfsv_send_not_req_t));
  163     if (param == NULL) {
  164         return SA_AIS_ERR_NO_MEMORY;
  165     }
  166     msg->info.api_info.param.send_notification = param;
  167     return ntfsv_dec_not_msg(uba, param);
  168 }
  169 
  170 /****************************************************************************
  171   Name          : dec_reader_initialize_msg
  172 
  173   Description   : This routine decodes an reader_initialize API msg
  174 
  175   Arguments     : NCS_UBAID *msg,
  176           NTFSV_MSG *msg
  177 
  178   Return Values : uns32
  179 
  180   Notes         : None.
  181 ******************************************************************************/
  182 static uint32_t dec_reader_initialize_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  183 {
  184     return ntfsv_dec_reader_initialize_msg(uba,
  185         &msg->info.api_info.param.reader_init);
  186 }
  187 
  188 /****************************************************************************
  189   Name          : dec_reader_initialize_2_msg
  190 
  191   Description   : This routine decodes an reader_initialize API msg
  192           filter is added in reader_initialize_2_msg
  193 
  194   Arguments     : NCS_UBAID *msg,
  195           NTFSV_MSG *msg
  196 
  197   Return Values : uint32_t
  198 
  199   Notes         : None.
  200 ******************************************************************************/
  201 static uint32_t dec_reader_initialize_2_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  202 {
  203     return ntfsv_dec_reader_initialize_2_msg(uba,
  204         &msg->info.api_info.param.reader_init_2);
  205 }
  206 
  207 /****************************************************************************
  208   Name          : dec_reader_finalize_msg
  209 
  210   Description   : This routine decodes an reader_finalize API msg
  211 
  212   Arguments     : NCS_UBAID *msg,
  213           NTFSV_MSG *msg
  214 
  215   Return Values : uns32
  216 
  217   Notes         : None.
  218 ******************************************************************************/
  219 static uint32_t dec_reader_finalize_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  220 {
  221     return ntfsv_dec_read_finalize_msg(uba, &msg->info.api_info.param.reader_finalize);
  222 }
  223 
  224 /****************************************************************************
  225   Name          : dec_read_next_msg
  226 
  227   Description   : This routine decodes an read_next API msg
  228 
  229   Arguments     : NCS_UBAID *msg,
  230           NTFSV_MSG *msg
  231 
  232   Return Values : uns32
  233 
  234   Notes         : None.
  235 ******************************************************************************/
  236 static uint32_t dec_read_next_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  237 {
  238     return ntfsv_dec_read_next_msg(uba, &msg->info.api_info.param.read_next);
  239 }
  240 
  241 /****************************************************************************
  242   Name          : enc_initialize_rsp_msg
  243 
  244   Description   : This routine encodes an initialize resp msg
  245 
  246   Arguments     : NCS_UBAID *msg,
  247           NTFSV_MSG *msg
  248 
  249   Return Values : uns32
  250 
  251   Notes         : None.
  252 ******************************************************************************/
  253 static uint32_t enc_initialize_rsp_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  254 {
  255     uint8_t *p8;
  256     ntfsv_initialize_rsp_t *param = &msg->info.api_resp_info.param.init_rsp;
  257     uint32_t rc = NCSCC_RC_SUCCESS;
  258     /* client_id */
  259     p8 = ncs_enc_reserve_space(uba, 4);
  260     if (p8 == NULL) {
  261         TRACE("ncs_enc_reserve_space failed");
  262         rc = NCSCC_RC_OUT_OF_MEM;
  263         goto done;
  264     }
  265 
  266     ncs_encode_32bit(&p8, param->client_id);
  267     ncs_enc_claim_space(uba, 4);
  268 
  269 done:
  270     TRACE_8("NTFSV_INITIALIZE_RSP");
  271     return rc;
  272 }
  273 
  274 /****************************************************************************
  275   Name          : enc_subscribe_rsp_msg
  276 
  277   Description   : This routine decodes a ntf subscribe msg
  278 
  279   Arguments     : NCS_UBAID *msg,
  280           NTFSV_MSG *msg
  281 
  282   Return Values : uns32
  283 
  284   Notes         : None.
  285 ******************************************************************************/
  286 static uint32_t enc_subscribe_rsp_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  287 {
  288     uint8_t *p8;
  289     ntfsv_subscribe_rsp_t *param =
  290         &msg->info.api_resp_info.param.subscribe_rsp;
  291     uint32_t rc = NCSCC_RC_SUCCESS;
  292 
  293     /* lstr_id */
  294     p8 = ncs_enc_reserve_space(uba, 8);
  295     if (p8 == NULL) {
  296         TRACE("ncs_enc_reserve_space failed");
  297         rc = NCSCC_RC_OUT_OF_MEM;
  298         goto done;
  299     }
  300     ncs_encode_32bit(&p8, param->subscriptionId);
  301     ncs_enc_claim_space(uba, 4);
  302 
  303 done:
  304     TRACE_8("NTFSV_SUBSCRIBE_RSP");
  305     return rc;
  306 }
  307 
  308 /****************************************************************************
  309   Name          : enc_send_not_rsp_msg
  310 
  311   Description   : This routine decodes a ntf notification resp msg
  312 
  313   Arguments     : NCS_UBAID *msg,
  314           NTFSV_MSG *msg
  315 
  316   Return Values : uns32
  317 
  318   Notes         : None.
  319 ******************************************************************************/
  320 static uint32_t enc_send_not_rsp_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  321 {
  322     uint8_t *p8;
  323     ntfsv_send_not_rsp_t *param =
  324         &msg->info.api_resp_info.param.send_not_rsp;
  325     uint32_t rc = NCSCC_RC_SUCCESS;
  326     /* lstr_id */
  327     p8 = ncs_enc_reserve_space(uba, 8);
  328     if (p8 == NULL) {
  329         TRACE("ncs_enc_reserve_space failed");
  330         rc = NCSCC_RC_OUT_OF_MEM;
  331         goto done;
  332     }
  333     ncs_encode_64bit(&p8, param->notificationId);
  334     ncs_enc_claim_space(uba, 8);
  335 
  336 done:
  337     TRACE_8("NTFSV_SEND_NOT_RSP");
  338     return rc;
  339 }
  340 
  341 /****************************************************************************
  342   Name          : enc_send_not_cbk_msg
  343 
  344   Description   : This routine encodes a notification callback API msg
  345 
  346   Arguments     : NCS_UBAID *msg,
  347           NTFSV_MSG *msg
  348 
  349   Return Values : uns32
  350 
  351   Notes         : None.
  352 ******************************************************************************/
  353 static uint32_t enc_send_not_cbk_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  354 {
  355     ntfsv_send_not_req_t *param = msg->info.cbk_info.param.notification_cbk;
  356     return ntfsv_enc_not_msg(uba, param);
  357 }
  358 
  359 /****************************************************************************
  360   Name          : enc_send_discard_cbk_msg
  361 
  362   Description   : This routine encodes discarded callback API msg
  363 
  364   Arguments     : NCS_UBAID *msg,
  365           NTFSV_MSG *msg
  366 
  367   Return Values : uns32
  368 
  369   Notes         : None.
  370 ******************************************************************************/
  371 static uint32_t enc_send_discard_cbk_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  372 {
  373     ntfsv_discarded_info_t *param = &msg->info.cbk_info.param.discarded_cbk;
  374     return ntfsv_enc_discard_msg(uba, param);
  375 }
  376 
  377 /****************************************************************************
  378   Name          : enc_reader_initialize_rsp_msg
  379 
  380   Description   : This routine encodes an reader_initialize resp msg
  381 
  382   Arguments     : NCS_UBAID *msg,
  383           NTFSV_MSG *msg
  384 
  385   Return Values : uns32
  386 
  387   Notes         : None.
  388 ******************************************************************************/
  389 static uint32_t enc_reader_initialize_rsp_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  390 {
  391     uint8_t *p8;
  392     ntfsv_reader_init_rsp_t *param =
  393         &msg->info.api_resp_info.param.reader_init_rsp;
  394     uint32_t rc = NCSCC_RC_SUCCESS;
  395 
  396     /* client_id */
  397     p8 = ncs_enc_reserve_space(uba, 4);
  398     if (p8 == NULL) {
  399         TRACE("ncs_enc_reserve_space failed");
  400         rc = NCSCC_RC_OUT_OF_MEM;
  401         goto done;
  402     }
  403 
  404     ncs_encode_32bit(&p8, param->readerId);
  405     ncs_enc_claim_space(uba, 4);
  406 
  407 done:
  408     TRACE_8("NTFSV_reader_initialize_RSP");
  409     return rc;
  410 }
  411 
  412 /****************************************************************************
  413   Name          : enc_reader_finalize_rsp_msg
  414 
  415   Description   : This routine encodes an reader_finalize resp msg
  416 
  417   Arguments     : NCS_UBAID *msg,
  418           NTFSV_MSG *msg
  419 
  420   Return Values : uns32
  421 
  422   Notes         : None.
  423 ******************************************************************************/
  424 static uint32_t enc_reader_finalize_rsp_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  425 {
  426     uint8_t *p8;
  427     ntfsv_reader_finalize_rsp_t *param =
  428         &msg->info.api_resp_info.param.reader_finalize_rsp;
  429     uint32_t rc = NCSCC_RC_SUCCESS;
  430 
  431     /* client_id */
  432     p8 = ncs_enc_reserve_space(uba, 4);
  433     if (p8 == NULL) {
  434         TRACE("ncs_enc_reserve_space failed");
  435         rc = NCSCC_RC_OUT_OF_MEM;
  436         goto done;
  437     }
  438 
  439     ncs_encode_32bit(&p8, param->reader_id);
  440     ncs_enc_claim_space(uba, 4);
  441 
  442 done:
  443     TRACE_8("NTFSV_reader_finalize_RSP");
  444     return rc;
  445 }
  446 
  447 /****************************************************************************
  448   Name          : enc_read_next_rsp_msg
  449 
  450   Description   : This routine encodes an read_next resp msg
  451 
  452   Arguments     : NCS_UBAID *msg,
  453           NTFSV_MSG *msg
  454 
  455   Return Values : uns32
  456 
  457   Notes         : None.
  458 ******************************************************************************/
  459 static uint32_t enc_read_next_rsp_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
  460 {
  461     ntfsv_read_next_rsp_t *param =
  462         &msg->info.api_resp_info.param.read_next_rsp;
  463     TRACE_8("NTFSV_read_next_RSP");
  464     if (msg->info.api_resp_info.rc != SA_AIS_OK) {
  465         return NCSCC_RC_SUCCESS;
  466     }
  467     return ntfsv_enc_not_msg(uba, param->readNotification);
  468 }
  469 
  470 /**
  471  * @brief Encodes CLM node status callback msg.
  472  *
  473  * @param  ptr to NCS_UBAID.
  474  * @param  ptr to ntfsv_msg_t.
  475  *
  476  * @return NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
  477  */
  478 static uint32_t enc_send_clm_node_status_cbk_msg(NCS_UBAID *uba,
  479                          ntfsv_msg_t *msg)
  480 {
  481     ntfsv_ntfa_clm_status_cbk_t *param =
  482         &msg->info.cbk_info.param.clm_node_status_cbk;
  483     uint8_t *p8;
  484     uint32_t rc = NCSCC_RC_SUCCESS;
  485 
  486     p8 = ncs_enc_reserve_space(uba, 2);
  487     if (p8 == NULL) {
  488         TRACE("ncs_enc_reserve_space failed");
  489         rc = NCSCC_RC_OUT_OF_MEM;
  490         goto done;
  491     }
  492     ncs_encode_16bit(&p8, param->clm_node_status);
  493     ncs_enc_claim_space(uba, 2);
  494 
  495 done:
  496     TRACE_8("Encode CLM node status msg");
  497     return rc;
  498 }
  499 
  500 /****************************************************************************
  501  * Name          : mds_cpy
  502  *
  503  * Description   : MDS copy.
  504  *
  505  * Arguments     : pointer to ncsmds_callback_info
  506  *
  507  * Return Values : NCSCC_RC_SUCCESS/Error Code.
  508  *
  509  * Notes         : None.
  510  *****************************************************************************/
  511 
  512 static uint32_t mds_cpy(struct ncsmds_callback_info *info)
  513 {
  514     /* TODO; */
  515     return NCSCC_RC_FAILURE;
  516 }
  517 
  518 /****************************************************************************
  519  * Name          : mds_enc
  520  *
  521  * Description   : MDS encode.
  522  *
  523  * Arguments     : pointer to ncsmds_callback_info
  524  *
  525  * Return Values : NCSCC_RC_SUCCESS/Error Code.
  526  *
  527  * Notes         : None.
  528  *****************************************************************************/
  529 
  530 static uint32_t mds_enc(struct ncsmds_callback_info *info)
  531 {
  532     ntfsv_msg_t *msg;
  533     NCS_UBAID *uba;
  534     uint8_t *p8;
  535     uint32_t rc = NCSCC_RC_SUCCESS;
  536 
  537     MDS_CLIENT_MSG_FORMAT_VER msg_fmt_version;
  538 
  539     msg_fmt_version =
  540         m_NCS_ENC_MSG_FMT_GET(info->info.enc.i_rem_svc_pvt_ver,
  541                   NTFS_WRT_NTFA_SUBPART_VER_AT_MIN_MSG_FMT,
  542                   NTFS_WRT_NTFA_SUBPART_VER_AT_MAX_MSG_FMT,
  543                   NTFS_WRT_NTFA_MSG_FMT_ARRAY);
  544     if (0 == msg_fmt_version) {
  545         LOG_ER("msg_fmt_version FAILED!");
  546         return NCSCC_RC_FAILURE;
  547     }
  548     info->info.enc.o_msg_fmt_ver = msg_fmt_version;
  549 
  550     msg = (ntfsv_msg_t *)info->info.enc.i_msg;
  551     uba = info->info.enc.io_uba;
  552 
  553     if (uba == NULL) {
  554         LOG_ER("uba == NULL");
  555         rc = NCSCC_RC_FAILURE;
  556         goto done;
  557     }
  558 
  559     /** encode the type of message **/
  560     p8 = ncs_enc_reserve_space(uba, 4);
  561     if (p8 == NULL) {
  562         TRACE("ncs_enc_reserve_space failed");
  563         rc = NCSCC_RC_OUT_OF_MEM;
  564         goto done;
  565     }
  566     ncs_encode_32bit(&p8, msg->type);
  567     ncs_enc_claim_space(uba, 4);
  568 
  569     if (NTFSV_NTFA_API_RESP_MSG == msg->type) {
  570         /** encode the API RSP msg subtype **/
  571         p8 = ncs_enc_reserve_space(uba, 4);
  572         if (!p8) {
  573             TRACE("ncs_enc_reserve_space failed");
  574             rc = NCSCC_RC_OUT_OF_MEM;
  575             goto done;
  576         }
  577         ncs_encode_32bit(&p8, msg->info.api_resp_info.type);
  578         ncs_enc_claim_space(uba, 4);
  579 
  580         /* rc */
  581         p8 = ncs_enc_reserve_space(uba, 4);
  582         if (!p8) {
  583             TRACE("ncs_enc_reserve_space failed");
  584             rc = NCSCC_RC_OUT_OF_MEM;
  585             goto done;
  586         }
  587         ncs_encode_32bit(&p8, msg->info.api_resp_info.rc);
  588         ncs_enc_claim_space(uba, 4);
  589 
  590         switch (msg->info.api_resp_info.type) {
  591         case NTFSV_INITIALIZE_RSP:
  592             rc = enc_initialize_rsp_msg(uba, msg);
  593             break;
  594         case NTFSV_SUBSCRIBE_RSP:
  595             rc = enc_subscribe_rsp_msg(uba, msg);
  596             break;
  597         case NTFSV_UNSUBSCRIBE_RSP:
  598             rc = NCSCC_RC_SUCCESS;
  599             break;
  600         case NTFSV_SEND_NOT_RSP:
  601             rc = enc_send_not_rsp_msg(uba, msg);
  602             break;
  603         case NTFSV_READER_INITIALIZE_RSP:
  604             rc = enc_reader_initialize_rsp_msg(uba, msg);
  605             break;
  606         case NTFSV_READER_FINALIZE_RSP:
  607             rc = enc_reader_finalize_rsp_msg(uba, msg);
  608             break;
  609         case NTFSV_READ_NEXT_RSP:
  610             rc = enc_read_next_rsp_msg(uba, msg);
  611             break;
  612         case NTFSV_FINALIZE_RSP:
  613             break;
  614         default:
  615             TRACE("Unknown API RSP type = %d",
  616                   msg->info.api_resp_info.type);
  617             rc = NCSCC_RC_FAILURE;
  618             break;
  619         }
  620     } else if (NTFSV_NTFS_CBK_MSG == msg->type) {
  621         /** encode the API RSP msg subtype **/
  622         p8 = ncs_enc_reserve_space(uba, 12);
  623         if (!p8) {
  624             TRACE("ncs_enc_reserve_space failed");
  625             rc = NCSCC_RC_OUT_OF_MEM;
  626             goto done;
  627         }
  628         ncs_encode_32bit(&p8, msg->info.cbk_info.type);
  629         ncs_encode_32bit(&p8, msg->info.cbk_info.ntfs_client_id);
  630         ncs_encode_32bit(&p8, msg->info.cbk_info.subscriptionId);
  631         ncs_enc_claim_space(uba, 12);
  632         if (msg->info.cbk_info.type == NTFSV_NOTIFICATION_CALLBACK) {
  633             rc = enc_send_not_cbk_msg(uba, msg);
  634         } else if (msg->info.cbk_info.type ==
  635                NTFSV_DISCARDED_CALLBACK) {
  636             rc = enc_send_discard_cbk_msg(uba, msg);
  637         } else if (msg->info.cbk_info.type ==
  638                NTFSV_CLM_NODE_STATUS_CALLBACK) {
  639             rc = enc_send_clm_node_status_cbk_msg(uba, msg);
  640         } else {
  641             TRACE("unknown callback type %d",
  642                   msg->info.cbk_info.type);
  643             rc = NCSCC_RC_FAILURE;
  644             goto done;
  645         }
  646         TRACE_8("enc NTFSV_NTFS_CBK_MSG");
  647     } else {
  648         TRACE("unknown msg type %d", msg->type);
  649         rc = NCSCC_RC_FAILURE;
  650         goto done;
  651     }
  652 done:
  653     if (rc != NCSCC_RC_SUCCESS) {
  654         TRACE_2("enc mgs type %d, api type %d, returned err rc = %u",
  655             msg->type, msg->info.api_resp_info.type, rc);
  656     }
  657     return rc;
  658 }
  659 
  660 /****************************************************************************
  661  * Name          : mds_dec
  662  *
  663  * Description   : MDS decode
  664  *
  665  * Arguments     : pointer to ncsmds_callback_info
  666  *
  667  * Return Values : NCSCC_RC_SUCCESS/Error Code.
  668  *
  669  * Notes         : None.
  670  *****************************************************************************/
  671 
  672 static uint32_t mds_dec(struct ncsmds_callback_info *info)
  673 {
  674     uint8_t *p8;
  675     ntfsv_ntfs_evt_t *evt = NULL;
  676     NCS_UBAID *uba = info->info.dec.io_uba;
  677     uint8_t local_data[20];
  678     uint32_t rc;
  679 
  680     if (0 ==
  681         m_NCS_MSG_FORMAT_IS_VALID(info->info.dec.i_msg_fmt_ver,
  682                       NTFS_WRT_NTFA_SUBPART_VER_AT_MIN_MSG_FMT,
  683                       NTFS_WRT_NTFA_SUBPART_VER_AT_MAX_MSG_FMT,
  684                       NTFS_WRT_NTFA_MSG_FMT_ARRAY)) {
  685         TRACE("Wrong format version");
  686         rc = NCSCC_RC_FAILURE;
  687         goto done;
  688     }
  689 
  690     /** allocate an NTFSV_NTFS_EVENT now **/
  691     if (NULL == (evt = calloc(1, sizeof(ntfsv_ntfs_evt_t)))) {
  692         TRACE("calloc failed");
  693         rc = NCSCC_RC_OUT_OF_MEM;
  694         goto done;
  695     }
  696 
  697     /* Assign the allocated event */
  698     info->info.dec.o_msg = (uint8_t *)evt;
  699 
  700     p8 = ncs_dec_flatten_space(uba, local_data, 4);
  701     evt->info.msg.type = ncs_decode_32bit(&p8);
  702     ncs_dec_skip_space(uba, 4);
  703 
  704     if (NTFSV_NTFA_API_MSG == evt->info.msg.type) {
  705         p8 = ncs_dec_flatten_space(uba, local_data, 4);
  706         evt->info.msg.info.api_info.type = ncs_decode_32bit(&p8);
  707         ncs_dec_skip_space(uba, 4);
  708 
  709         /* FIX error handling for dec functions */
  710         switch (evt->info.msg.info.api_info.type) {
  711         case NTFSV_INITIALIZE_REQ:
  712             rc = dec_initialize_msg(uba, &evt->info.msg);
  713             break;
  714         case NTFSV_FINALIZE_REQ:
  715             rc = dec_finalize_msg(uba, &evt->info.msg);
  716             break;
  717         case NTFSV_SUBSCRIBE_REQ:
  718             rc = dec_subscribe_msg(uba, &evt->info.msg);
  719             break;
  720         case NTFSV_UNSUBSCRIBE_REQ:
  721             rc = dec_unsubscribe_msg(uba, &evt->info.msg);
  722             break;
  723         case NTFSV_SEND_NOT_REQ:
  724             rc = dec_send_not_msg(uba, &evt->info.msg);
  725             break;
  726         case NTFSV_READER_INITIALIZE_REQ:
  727             rc = dec_reader_initialize_msg(uba, &evt->info.msg);
  728             break;
  729         case NTFSV_READER_INITIALIZE_REQ_2:
  730             rc = dec_reader_initialize_2_msg(uba, &evt->info.msg);
  731             break;
  732         case NTFSV_READER_FINALIZE_REQ:
  733             rc = dec_reader_finalize_msg(uba, &evt->info.msg);
  734             break;
  735         case NTFSV_READ_NEXT_REQ:
  736             rc = dec_read_next_msg(uba, &evt->info.msg);
  737             break;
  738         default:
  739             TRACE("Unknown API type = %d",
  740                   evt->info.msg.info.api_info.type);
  741             rc = NCSCC_RC_FAILURE;
  742             break;
  743         }
  744     } else {
  745         TRACE("unknown msg type = %d", (int)evt->info.msg.type);
  746         rc = NCSCC_RC_FAILURE;
  747     }
  748 
  749     if (rc != NCSCC_RC_SUCCESS) {
  750         TRACE_2("dec mgs type %d, api type %d, returned err rc = %u",
  751             evt->info.msg.type, evt->info.msg.info.api_info.type,
  752             rc);
  753     }
  754 done:
  755     return rc;
  756 }
  757 
  758 /****************************************************************************
  759  * Name          : mds_enc_flat
  760  *
  761  * Description   : MDS encode and flatten
  762  *
  763  * Arguments     : pointer to ncsmds_callback_info
  764  *
  765  * Return Values : NCSCC_RC_SUCCESS/Error Code.
  766  *
  767  * Notes         : None.
  768  *****************************************************************************/
  769 
  770 static uint32_t mds_enc_flat(struct ncsmds_callback_info *info)
  771 {
  772     uint32_t rc;
  773 
  774     /* Retrieve info from the enc_flat */
  775     MDS_CALLBACK_ENC_INFO enc = info->info.enc_flat;
  776     /* Modify the MDS_INFO to populate enc */
  777     info->info.enc = enc;
  778     /* Invoke the regular mds_enc routine */
  779     rc = mds_enc(info);
  780     if (rc != NCSCC_RC_SUCCESS) {
  781         TRACE("mds_enc FAILED");
  782     }
  783     return rc;
  784 }
  785 
  786 /****************************************************************************
  787  * Name          : mds_dec_flat
  788  *
  789  * Description   : MDS decode and flatten
  790  *
  791  * Arguments     : pointer to ncsmds_callback_info
  792  *
  793  * Return Values : NCSCC_RC_SUCCESS/Error Code.
  794  *
  795  * Notes         : None.
  796  *****************************************************************************/
  797 
  798 static uint32_t mds_dec_flat(struct ncsmds_callback_info *info)
  799 {
  800     uint32_t rc = NCSCC_RC_SUCCESS;
  801     /* Retrieve info from the dec_flat */
  802     MDS_CALLBACK_DEC_INFO dec = info->info.dec_flat;
  803     /* Modify the MDS_INFO to populate dec */
  804     info->info.dec = dec;
  805     /* Invoke the regular mds_dec routine */
  806     rc = mds_dec(info);
  807     if (rc != NCSCC_RC_SUCCESS) {
  808         TRACE("mds_dec FAILED ");
  809     }
  810     return rc;
  811 }
  812 
  813 /****************************************************************************
  814  * Name          : mds_rcv
  815  *
  816  * Description   : MDS rcv evt.
  817  *
  818  * Arguments     : pointer to ncsmds_callback_info
  819  *
  820  * Return Values : NCSCC_RC_SUCCESS/Error Code.
  821  *
  822  * Notes         : None.
  823  *****************************************************************************/
  824 
  825 static uint32_t mds_rcv(struct ncsmds_callback_info *mds_info)
  826 {
  827     ntfsv_ntfs_evt_t *ntfsv_evt =
  828         (ntfsv_ntfs_evt_t *)mds_info->info.receive.i_msg;
  829     uint32_t rc = NCSCC_RC_SUCCESS;
  830 
  831     ntfsv_evt->evt_type = NTFSV_NTFS_NTFSV_MSG;
  832     ntfsv_evt->cb_hdl = (uint32_t)mds_info->i_yr_svc_hdl;
  833     ntfsv_evt->fr_node_id = mds_info->info.receive.i_node_id;
  834     ntfsv_evt->fr_dest = mds_info->info.receive.i_fr_dest;
  835     ntfsv_evt->rcvd_prio = mds_info->info.receive.i_priority;
  836     ntfsv_evt->mds_ctxt = mds_info->info.receive.i_msg_ctxt;
  837 
  838     /* Send the message to ntfs */
  839     rc = m_NCS_IPC_SEND(&ntfs_cb->mbx, ntfsv_evt,
  840                 mds_info->info.receive.i_priority);
  841     if (rc != NCSCC_RC_SUCCESS)
  842         TRACE("IPC send failed %d", rc);
  843 
  844     return rc;
  845 }
  846 
  847 /****************************************************************************
  848  * Name          : mds_quiesced_ack
  849  *
  850  * Description   : MDS quised ack.
  851  *
  852  * Arguments     : pointer to ncsmds_callback_info
  853  *
  854  * Return Values : NCSCC_RC_SUCCESS/Error Code.
  855  *
  856  * Notes         : None.
  857  *****************************************************************************/
  858 
  859 static uint32_t mds_quiesced_ack(struct ncsmds_callback_info *mds_info)
  860 {
  861     ntfsv_ntfs_evt_t *ntfsv_evt;
  862 
  863     /** allocate an NTFSV_NTFS_EVENT now **/
  864     if (NULL == (ntfsv_evt = calloc(1, sizeof(ntfsv_ntfs_evt_t)))) {
  865         TRACE("memory alloc FAILED");
  866         goto err;
  867     }
  868 
  869     if (ntfs_cb->is_quisced_set == true) {
  870         /** Initialize the Event here **/
  871         ntfsv_evt->evt_type = NTFSV_EVT_QUIESCED_ACK;
  872         ntfsv_evt->cb_hdl = (uint32_t)mds_info->i_yr_svc_hdl;
  873 
  874         /* Push the event and we are done */
  875         if (NCSCC_RC_FAILURE ==
  876             m_NCS_IPC_SEND(&ntfs_cb->mbx, ntfsv_evt,
  877                    NCS_IPC_PRIORITY_NORMAL)) {
  878             TRACE("ipc send failed");
  879             ntfs_evt_destroy(ntfsv_evt);
  880             goto err;
  881         }
  882     } else {
  883         ntfs_evt_destroy(ntfsv_evt);
  884     }
  885 
  886     return NCSCC_RC_SUCCESS;
  887 
  888 err:
  889     return NCSCC_RC_FAILURE;
  890 }
  891 
  892 /****************************************************************************
  893  * Name          : mds_svc_event
  894  *
  895  * Description   : MDS subscription evt.
  896  *
  897  * Arguments     : pointer to ncsmds_callback_info
  898  *
  899  * Return Values : NCSCC_RC_SUCCESS/Error Code.
  900  *
  901  * Notes         : None.
  902  *****************************************************************************/
  903 
  904 static uint32_t mds_svc_event(struct ncsmds_callback_info *info)
  905 {
  906     ntfsv_ntfs_evt_t *evt = NULL;
  907     uint32_t rc = NCSCC_RC_SUCCESS;
  908 
  909     TRACE("MDS SVC event.");
  910     /* First make sure that this event is indeed for us */
  911     if (info->info.svc_evt.i_your_id != NCSMDS_SVC_ID_NTFS) {
  912         TRACE("event not NCSMDS_SVC_ID_NTFS");
  913         rc = NCSCC_RC_FAILURE;
  914         goto done;
  915     }
  916 
  917     /* If this evt was sent from NTFA act on this */
  918     if (info->info.svc_evt.i_svc_id == NCSMDS_SVC_ID_NTFA) {
  919         if (info->info.svc_evt.i_change == NCSMDS_DOWN) {
  920             TRACE_8("MDS DOWN dest: %" PRIx64
  921                 ", node ID: %x, svc_id: %d",
  922                 info->info.svc_evt.i_dest,
  923                 info->info.svc_evt.i_node_id,
  924                 info->info.svc_evt.i_svc_id);
  925 
  926             /* As of now we are only interested in NTFA events */
  927             if (NULL ==
  928                 (evt = calloc(1, sizeof(ntfsv_ntfs_evt_t)))) {
  929                 rc = NCSCC_RC_FAILURE;
  930                 TRACE("mem alloc FAILURE  ");
  931                 goto done;
  932             }
  933 
  934             evt->evt_type = NTFSV_NTFS_EVT_NTFA_DOWN;
  935 
  936             /** Initialize the Event Header **/
  937             evt->cb_hdl = 0;
  938             evt->internal_event = false;
  939             evt->fr_node_id = info->info.svc_evt.i_node_id;
  940             evt->fr_dest = info->info.svc_evt.i_dest;
  941 
  942             /** Initialize the MDS portion of the header **/
  943             evt->info.mds_info.node_id =
  944                 info->info.svc_evt.i_node_id;
  945             evt->info.mds_info.mds_dest_id =
  946                 info->info.svc_evt.i_dest;
  947 
  948             // Set flag for client down at standby node then ntfd
  949             // just removes only the downed clients. This is helpful
  950             // in some cases ntfd receives this event after
  951             // checkpoint of initializing new client in standby or
  952             // checking if client has already downed in active.
  953             SearchAndSetClientsDownFlag(evt->fr_dest);
  954 
  955             /* Push the event and we are done */
  956             if (m_NCS_IPC_SEND(&ntfs_cb->mbx, evt,
  957                        NCS_IPC_PRIORITY_HIGH) !=
  958                 NCSCC_RC_SUCCESS) {
  959                 TRACE("ipc send failed");
  960                 ntfs_evt_destroy(evt);
  961                 rc = NCSCC_RC_FAILURE;
  962                 goto done;
  963             }
  964         }
  965     } else if (info->info.svc_evt.i_svc_id == NCSMDS_SVC_ID_AVD) {
  966         if (info->info.svc_evt.i_change == NCSMDS_UP) {
  967             TRACE_8("MDS UP dest: %" PRIx64
  968                 ", node ID: %x, svc_id: %d",
  969                 info->info.svc_evt.i_dest,
  970                 info->info.svc_evt.i_node_id,
  971                 info->info.svc_evt.i_svc_id);
  972             // Subscribed for only INTRA NODE, only one ADEST will
  973             // come.
  974             if (m_MDS_DEST_IS_AN_ADEST(info->info.svc_evt.i_dest)) {
  975                 TRACE_8("AVD ADEST UP");
  976                 ncs_sel_obj_ind(&ntfs_cb->usr2_sel_obj);
  977             }
  978         }
  979     }
  980 
  981 done:
  982     return rc;
  983 }
  984 
  985 /****************************************************************************
  986  * Name          : mds_sys_evt
  987  *
  988  * Description   : MDS sys evt .
  989  *
  990  * Arguments     : pointer to ncsmds_callback_info
  991  *
  992  * Return Values : NCSCC_RC_SUCCESS/Error Code.
  993  *
  994  * Notes         : None.
  995  *****************************************************************************/
  996 
  997 static uint32_t mds_sys_event(struct ncsmds_callback_info *mds_info)
  998 {
  999     /* Not supported now */
 1000     TRACE("FAILED");
 1001     return NCSCC_RC_FAILURE;
 1002 }
 1003 
 1004 /****************************************************************************
 1005  * Name          : mds_callback
 1006  *
 1007  * Description   : Callback Dispatcher for various MDS operations.
 1008  *
 1009  * Arguments     : cb   : NTFS control Block pointer.
 1010  *
 1011  * Return Values : NCSCC_RC_SUCCESS/Error Code.
 1012  *
 1013  * Notes         : None.
 1014  *****************************************************************************/
 1015 
 1016 static uint32_t mds_callback(struct ncsmds_callback_info *info)
 1017 {
 1018     uint32_t rc;
 1019     static NCSMDS_CALLBACK_API cb_set[MDS_CALLBACK_SVC_MAX] = {
 1020         mds_cpy,     /* MDS_CALLBACK_COPY      */
 1021         mds_enc,     /* MDS_CALLBACK_ENC       */
 1022         mds_dec,     /* MDS_CALLBACK_DEC       */
 1023         mds_enc_flat,    /* MDS_CALLBACK_ENC_FLAT  */
 1024         mds_dec_flat,    /* MDS_CALLBACK_DEC_FLAT  */
 1025         mds_rcv,     /* MDS_CALLBACK_RECEIVE   */
 1026         mds_svc_event,   /* MDS_CALLBACK_SVC_EVENT */
 1027         mds_sys_event,   /* MDS_CALLBACK_SYS_EVENT */
 1028         mds_quiesced_ack /* MDS_CALLBACK_QUIESCED_ACK */
 1029     };
 1030 
 1031     if (info->i_op <= MDS_CALLBACK_QUIESCED_ACK) {
 1032         rc = (*cb_set[info->i_op])(info);
 1033         if (rc == NCSCC_RC_OUT_OF_MEM) {
 1034             LOG_ER("Exiting: out of memory");
 1035             exit(EXIT_FAILURE);
 1036         }
 1037         return rc;
 1038     } else {
 1039         TRACE("mds callback out of range op: %d", info->i_op);
 1040         rc = NCSCC_RC_FAILURE;
 1041     }
 1042     return rc;
 1043 }
 1044 
 1045 /****************************************************************************
 1046  * Name          : mds_vdest_create
 1047  *
 1048  * Description   : This function created the VDEST for NTFS
 1049  *
 1050  * Arguments     :
 1051  *
 1052  * Return Values : NCSCC_RC_SUCCESS/Error Code.
 1053  *
 1054  * Notes         : None.
 1055  *****************************************************************************/
 1056 static uint32_t mds_vdest_create(ntfs_cb_t *ntfs_cb)
 1057 {
 1058     NCSVDA_INFO vda_info;
 1059     uint32_t rc = NCSCC_RC_SUCCESS;
 1060 
 1061     memset(&vda_info, 0, sizeof(NCSVDA_INFO));
 1062     ntfs_cb->vaddr = NTFS_VDEST_ID;
 1063     vda_info.req = NCSVDA_VDEST_CREATE;
 1064     vda_info.info.vdest_create.i_create_type = NCSVDA_VDEST_CREATE_SPECIFIC;
 1065     vda_info.info.vdest_create.i_persistent =
 1066         false; /* Up-to-the application */
 1067     vda_info.info.vdest_create.i_policy = NCS_VDEST_TYPE_DEFAULT;
 1068     vda_info.info.vdest_create.info.specified.i_vdest = ntfs_cb->vaddr;
 1069 
 1070     /* Create the VDEST address */
 1071     if (NCSCC_RC_SUCCESS != (rc = ncsvda_api(&vda_info))) {
 1072         LOG_ER("VDEST_CREATE_FAILED");
 1073         return rc;
 1074     }
 1075 
 1076     /* Store the info returned by MDS */
 1077     ntfs_cb->mds_hdl = vda_info.info.vdest_create.o_mds_pwe1_hdl;
 1078 
 1079     return rc;
 1080 }
 1081 
 1082 /****************************************************************************
 1083  * Name          : ntfs_mds_init
 1084  *
 1085  * Description   : This function creates the VDEST for ntfs and
 1086  *installs/suscribes into MDS.
 1087  *
 1088  * Arguments     : cb   : NTFS control Block pointer.
 1089  *
 1090  * Return Values : NCSCC_RC_SUCCESS/Error Code.
 1091  *
 1092  * Notes         : None.
 1093  *****************************************************************************/
 1094 uint32_t ntfs_mds_init(ntfs_cb_t *cb, SaAmfHAStateT ha_state)
 1095 {
 1096     NCSMDS_INFO mds_info;
 1097     uint32_t rc;
 1098     MDS_SVC_ID svc = NCSMDS_SVC_ID_NTFA;
 1099 
 1100     TRACE_ENTER();
 1101 
 1102     /* Create the VDEST for NTFS */
 1103     if (NCSCC_RC_SUCCESS != (rc = mds_vdest_create(cb))) {
 1104         LOG_ER(" ntfs_mds_init: named vdest create FAILED\n");
 1105         return rc;
 1106     }
 1107 
 1108     /* Set the role of MDS */
 1109     if (ha_state == SA_AMF_HA_ACTIVE)
 1110         cb->mds_role = V_DEST_RL_ACTIVE;
 1111 
 1112     if (ha_state == SA_AMF_HA_STANDBY)
 1113         cb->mds_role = V_DEST_RL_STANDBY;
 1114 
 1115     if (NCSCC_RC_SUCCESS != (rc = ntfs_mds_change_role())) {
 1116         LOG_ER("MDS role change to %d FAILED\n", cb->mds_role);
 1117         return rc;
 1118     }
 1119 
 1120     /* Install your service into MDS */
 1121     memset(&mds_info, '\0', sizeof(NCSMDS_INFO));
 1122     mds_info.i_mds_hdl = cb->mds_hdl;
 1123     mds_info.i_svc_id = NCSMDS_SVC_ID_NTFS;
 1124     mds_info.i_op = MDS_INSTALL;
 1125     mds_info.info.svc_install.i_yr_svc_hdl = 0;
 1126     mds_info.info.svc_install.i_install_scope = NCSMDS_SCOPE_NONE;
 1127     mds_info.info.svc_install.i_svc_cb = mds_callback;
 1128     mds_info.info.svc_install.i_mds_q_ownership = false;
 1129     mds_info.info.svc_install.i_mds_svc_pvt_ver =
 1130         NTFS_SVC_PVT_SUBPART_VERSION;
 1131 
 1132     if (NCSCC_RC_SUCCESS != (rc = ncsmds_api(&mds_info))) {
 1133         LOG_ER("MDS Install FAILED");
 1134         return rc;
 1135     }
 1136 
 1137     /* Now subscribe for NTFS events in MDS, TODO: WHy this? */
 1138     memset(&mds_info, '\0', sizeof(NCSMDS_INFO));
 1139     mds_info.i_mds_hdl = cb->mds_hdl;
 1140     mds_info.i_svc_id = NCSMDS_SVC_ID_NTFS;
 1141     mds_info.i_op = MDS_SUBSCRIBE;
 1142     mds_info.info.svc_subscribe.i_scope = NCSMDS_SCOPE_NONE;
 1143     mds_info.info.svc_subscribe.i_num_svcs = 1;
 1144     mds_info.info.svc_subscribe.i_svc_ids = &svc;
 1145 
 1146     rc = ncsmds_api(&mds_info);
 1147     if (rc != NCSCC_RC_SUCCESS) {
 1148         LOG_ER("MDS subscribe FAILED");
 1149         return rc;
 1150     }
 1151 
 1152     svc = NCSMDS_SVC_ID_AVD;
 1153     /* Now subscribe for AVD events in MDS. This will be
 1154        used for CLM registration.*/
 1155     memset(&mds_info, '\0', sizeof(NCSMDS_INFO));
 1156     mds_info.i_mds_hdl = cb->mds_hdl;
 1157     mds_info.i_svc_id = NCSMDS_SVC_ID_NTFS;
 1158     mds_info.i_op = MDS_SUBSCRIBE;
 1159     mds_info.info.svc_subscribe.i_scope = NCSMDS_SCOPE_INTRANODE;
 1160     mds_info.info.svc_subscribe.i_num_svcs = 1;
 1161     mds_info.info.svc_subscribe.i_svc_ids = &svc;
 1162 
 1163     rc = ncsmds_api(&mds_info);
 1164     if (rc != NCSCC_RC_SUCCESS) {
 1165         LOG_ER("MDS subscribe FAILED");
 1166         return rc;
 1167     }
 1168 
 1169     TRACE_LEAVE();
 1170     return rc;
 1171 }
 1172 
 1173 /****************************************************************************
 1174  * Name          : ntfs_mds_change_role
 1175  *
 1176  * Description   : This function informs mds of our vdest role change
 1177  *
 1178  * Arguments     : cb   : NTFS control Block pointer.
 1179  *
 1180  * Return Values : NCSCC_RC_SUCCESS/Error Code.
 1181  *
 1182  * Notes         : None.
 1183  *****************************************************************************/
 1184 uint32_t ntfs_mds_change_role()
 1185 {
 1186     NCSVDA_INFO arg;
 1187 
 1188     memset(&arg, 0, sizeof(NCSVDA_INFO));
 1189 
 1190     arg.req = NCSVDA_VDEST_CHG_ROLE;
 1191     arg.info.vdest_chg_role.i_vdest = ntfs_cb->vaddr;
 1192     arg.info.vdest_chg_role.i_new_role = ntfs_cb->mds_role;
 1193 
 1194     return ncsvda_api(&arg);
 1195 }
 1196 
 1197 /****************************************************************************
 1198  * Name          : mds_vdest_destroy
 1199  *
 1200  * Description   : This function Destroys the Virtual destination of NTFS
 1201  *
 1202  * Arguments     : cb   : NTFS control Block pointer.
 1203  *
 1204  * Return Values : NCSCC_RC_SUCCESS/Error Code.
 1205  *
 1206  * Notes         : None.
 1207  *****************************************************************************/
 1208 static uint32_t mds_vdest_destroy(ntfs_cb_t *ntfs_cb)
 1209 {
 1210     NCSVDA_INFO vda_info;
 1211     uint32_t rc;
 1212 
 1213     memset(&vda_info, 0, sizeof(NCSVDA_INFO));
 1214     vda_info.req = NCSVDA_VDEST_DESTROY;
 1215     vda_info.info.vdest_destroy.i_vdest = ntfs_cb->vaddr;
 1216 
 1217     if (NCSCC_RC_SUCCESS != (rc = ncsvda_api(&vda_info))) {
 1218         LOG_ER("NCSVDA_VDEST_DESTROY failed");
 1219         return rc;
 1220     }
 1221 
 1222     return rc;
 1223 }
 1224 
 1225 /****************************************************************************
 1226  * Name          : ntfs_mds_finalize
 1227  *
 1228  * Description   : This function un-registers the NTFS Service with MDS.
 1229  *
 1230  * Arguments     : Uninstall NTFS from MDS.
 1231  *
 1232  * Return Values : NCSCC_RC_SUCCESS/Error Code.
 1233  *
 1234  * Notes         : None.
 1235  *****************************************************************************/
 1236 uint32_t ntfs_mds_finalize(ntfs_cb_t *cb)
 1237 {
 1238     NCSMDS_INFO mds_info;
 1239     uint32_t rc;
 1240 
 1241     /* Un-install NTFS service from MDS */
 1242     memset(&mds_info, 0, sizeof(NCSMDS_INFO));
 1243     mds_info.i_mds_hdl = cb->mds_hdl;
 1244     mds_info.i_svc_id = NCSMDS_SVC_ID_NTFS;
 1245     mds_info.i_op = MDS_UNINSTALL;
 1246 
 1247     rc = ncsmds_api(&mds_info);
 1248 
 1249     if (rc != NCSCC_RC_SUCCESS) {
 1250         LOG_ER("MDS_UNINSTALL_FAILED");
 1251         return rc;
 1252     }
 1253 
 1254     /* Destroy the virtual Destination of NTFS */
 1255     rc = mds_vdest_destroy(cb);
 1256     return rc;
 1257 }
 1258 
 1259 /****************************************************************************
 1260   Name          : ntfs_mds_msg_send
 1261 
 1262   Description   : This routine sends a message to NTFA. The send
 1263           operation may be a 'normal' send or a synchronous call that
 1264           blocks until the response is received from NTFA.
 1265 
 1266   Arguments     : cb  - ptr to the NTFA CB
 1267           i_msg - ptr to the NTFSv message
 1268           dest  - MDS destination to send to.
 1269           mds_ctxt - ctxt for synch mds req-resp.
 1270 
 1271   Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE/timeout
 1272 
 1273   Notes         : None.
 1274 ******************************************************************************/
 1275 
 1276 uint32_t ntfs_mds_msg_send(ntfs_cb_t *cb, ntfsv_msg_t *msg, MDS_DEST *dest,
 1277                MDS_SYNC_SND_CTXT *mds_ctxt,
 1278                MDS_SEND_PRIORITY_TYPE prio)
 1279 {
 1280     NCSMDS_INFO mds_info;
 1281     MDS_SEND_INFO *send_info = &mds_info.info.svc_send;
 1282     uint32_t rc = NCSCC_RC_SUCCESS;
 1283 
 1284     /* populate the mds params */
 1285     memset(&mds_info, '\0', sizeof(NCSMDS_INFO));
 1286 
 1287     mds_info.i_mds_hdl = cb->mds_hdl;
 1288     mds_info.i_svc_id = NCSMDS_SVC_ID_NTFS;
 1289     mds_info.i_op = MDS_SEND;
 1290 
 1291     send_info->i_msg = msg;
 1292     send_info->i_to_svc = NCSMDS_SVC_ID_NTFA;
 1293     send_info->i_priority = prio; /* Discuss the priority assignments TBD */
 1294 
 1295     if (NULL == mds_ctxt || 0 == mds_ctxt->length) {
 1296         /* regular send */
 1297         MDS_SENDTYPE_SND_INFO *send = &send_info->info.snd;
 1298 
 1299         send_info->i_sendtype = MDS_SENDTYPE_SND;
 1300         send->i_to_dest = *dest;
 1301     } else {
 1302         /* response message (somebody is waiting for it) */
 1303         MDS_SENDTYPE_RSP_INFO *resp = &send_info->info.rsp;
 1304 
 1305         send_info->i_sendtype = MDS_SENDTYPE_RSP;
 1306         resp->i_sender_dest = *dest;
 1307         resp->i_msg_ctxt = *mds_ctxt;
 1308     }
 1309 
 1310     /* send the message */
 1311     rc = ncsmds_api(&mds_info);
 1312     if (rc != NCSCC_RC_SUCCESS) {
 1313         LOG_WA("ntfs_mds_msg_send FAILED:%u", rc);
 1314     }
 1315     return rc;
 1316 }