Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Command's `shm_psvc' backend
0003  *
0004  * @file cmd_shm_psvc.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <ndrx_config.h>
0035 #include <string.h>
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <memory.h>
0039 #include <utlist.h>
0040 
0041 #include <ndrstandard.h>
0042 
0043 #include <ndebug.h>
0044 #include <userlog.h>
0045 #include <ndrxd.h>
0046 #include <ndrxdcmn.h>
0047 
0048 #include "cmd_processor.h"
0049 #include <atmi_shm.h>
0050 /*---------------------------Externs------------------------------------*/
0051 /*---------------------------Macros-------------------------------------*/
0052 /*---------------------------Enums--------------------------------------*/
0053 /*---------------------------Typedefs-----------------------------------*/
0054 /*---------------------------Globals------------------------------------*/
0055 /*---------------------------Statics------------------------------------*/
0056 /*---------------------------Prototypes---------------------------------*/
0057 
0058 /**
0059  * Modify reply according the data.
0060  * @param call
0061  * @param pm
0062  */
0063 expublic void shm_psvc_reply_mod(command_reply_t *reply, size_t *send_size, mod_param_t *params)
0064 {
0065     command_reply_shm_psvc_t * shm_psvc_info = (command_reply_shm_psvc_t *)reply;
0066     shm_svcinfo_t *p_shm = (shm_svcinfo_t *)params->mod_param1;
0067     int cnt;
0068     
0069     reply->msg_type = NDRXD_CALL_TYPE_PM_SHM_PSVC;
0070     /* calculate new send size */
0071     *send_size += (sizeof(command_reply_shm_psvc_t) - sizeof(command_reply_t));
0072 
0073     /* Copy data to reply structure */
0074     NDRX_STRCPY_SAFE(shm_psvc_info->service, p_shm->service);
0075     shm_psvc_info->flags = p_shm->flags;
0076     shm_psvc_info->slot = params->param2;
0077     shm_psvc_info->srvs = p_shm->srvs;
0078     /* cluster fields: */
0079     shm_psvc_info->csrvs = p_shm->csrvs;
0080     shm_psvc_info->resnr = p_shm->resnr;
0081     shm_psvc_info->totclustered = p_shm->totclustered;
0082     shm_psvc_info->cnodes_max_id = p_shm->cnodes_max_id;
0083     memcpy(shm_psvc_info->cnodes, p_shm->cnodes, sizeof(p_shm->cnodes));
0084     
0085     shm_psvc_info->resids[0].resid = 0;
0086     shm_psvc_info->resids[0].cnt = 0;
0087     
0088 #if defined(EX_USE_POLL) || defined(EX_USE_SYSVQ)
0089     /* copy the number of elements */
0090     cnt = p_shm->resnr;
0091     if (cnt > CONF_NDRX_MAX_SRVIDS_XADMIN)
0092     {
0093         cnt = CONF_NDRX_MAX_SRVIDS_XADMIN;
0094     }
0095     memcpy(shm_psvc_info->resids, p_shm->resids, cnt*sizeof(p_shm->resids[0]));
0096 #endif
0097     
0098     /*
0099     for (i=0; i< CONF_NDRX_NODEID_COUNT; i++)
0100     {
0101         NDRX_LOG(log_debug, "cnodes: %d=>%d", i, p_shm->cnodes[i].srvs);
0102         NDRX_LOG(log_debug, "shm_ps: %d=>%d", i, shm_psvc_info->cnodes[i].srvs);
0103     }
0104     */
0105     
0106     NDRX_LOG(log_debug, "magic: %ld", shm_psvc_info->rply.magic);
0107 }
0108 
0109 /**
0110  * Callback to report startup progress
0111  * @param call
0112  * @param pm
0113  * @return
0114  */
0115 exprivate void shm_psvc_progress(command_call_t * call, shm_svcinfo_t *p_shm, int slot)
0116 {
0117     int ret=EXSUCCEED;
0118     mod_param_t params;
0119     
0120     NDRX_LOG(log_debug, "startup_progress enter");
0121     memset(&params, 0, sizeof(mod_param_t));
0122 
0123     /* pass to reply process model node */
0124     params.mod_param1 = (void *)p_shm;
0125     params.param2 = slot;
0126 
0127     if (EXSUCCEED!=simple_command_reply(call, ret, NDRXD_CALL_FLAGS_RSPHAVE_MORE,
0128                             /* hook up the reply */
0129                             &params, shm_psvc_reply_mod, 0L, 0, NULL))
0130     {
0131         userlog("Failed to send progress back to [%s]", call->reply_queue);
0132     }
0133     
0134 
0135     NDRX_LOG(log_debug, "startup_progress exit");
0136 }
0137 
0138 /**
0139  * Call to psc command - print services
0140  * @param args
0141  * @return
0142  */
0143 expublic int cmd_shm_psvc (command_call_t * call, char *data, size_t len, int context)
0144 {
0145     int ret=EXSUCCEED;
0146     int i;
0147     shm_svcinfo_t *svcinfo = (shm_svcinfo_t *) G_svcinfo.mem;
0148     
0149     /* We assume shm is OK! */
0150     for (i=0; i<G_max_svcs; i++)
0151     {
0152         /* have some test on servs count so that we avoid any core dumps
0153          *  for un-init memory access of service string due to race conditions
0154          */
0155         if (SHM_SVCINFO_INDEX(svcinfo, i)->srvs>0 && 
0156                 EXEOS!=SHM_SVCINFO_INDEX(svcinfo, i)->service[0])
0157         {
0158             shm_psvc_progress(call, SHM_SVCINFO_INDEX(svcinfo, i), i);
0159         }
0160     }
0161 
0162     if (EXSUCCEED!=simple_command_reply(call, ret, 0L, NULL, NULL, 0L, 0, NULL))
0163     {
0164         userlog("Failed to send reply back to [%s]", call->reply_queue);
0165     }
0166     NDRX_LOG(log_warn, "cmd_shm_psvc returns with status %d", ret);
0167     
0168 out:
0169     return ret;
0170 }
0171 
0172 /* vim: set ts=4 sw=4 et smartindent: */