Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Common/shared data structures between server & client.
0003  *
0004  * @file ndrxdcmn.h
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 #ifndef NDRXDCMN_H
0035 #define NDRXDCMN_H
0036 
0037 #ifdef  __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /*---------------------------Includes-----------------------------------*/
0042 #include <atmi_int.h>
0043 #include <sys/param.h>
0044 #include <nstopwatch.h>
0045 #include <atmi_int.h>
0046 /*---------------------------Externs------------------------------------*/
0047 /*---------------------------Macros-------------------------------------*/
0048 
0049 /* Unsigned long */
0050 #define NDRX_MAGIC                              0x62327700L
0051 
0052 #define CMD_ARG_MAX                             2048
0053 #define RPLY_ERR_MSG_MAX                        256
0054 
0055 /* Client/server commands */
0056 #define NDRXD_COM_MIN               0
0057 #define NDRXD_COM_LDCF_RQ           0    /**< load config req        */
0058 #define NDRXD_COM_LDCF_RP           1    /**< load config replay     */
0059 #define NDRXD_COM_START_RQ          2    /**< start app domain req   */
0060 #define NDRXD_COM_START_RP          3    /**< start app domain reply */
0061 #define NDRXD_COM_SVCINFO_RQ        4    /**< service info from svc  */
0062 #define NDRXD_COM_SVCINFO_RP        5    /**< not used               */
0063 #define NDRXD_COM_PMNTIFY_RQ        6    /**< Process notification   */
0064 #define NDRXD_COM_PMNTIFY_RP        7    /**< not used               */
0065 #define NDRXD_COM_PSC_RQ            8    /**< Print services req     */
0066 #define NDRXD_COM_PSC_RP            9    /**< Print services rsp     */
0067 #define NDRXD_COM_STOP_RQ           10   /**< stop app domain req    */
0068 #define NDRXD_COM_STOP_RP           11   /**< stop app domain reply  */
0069 #define NDRXD_COM_SRVSTOP_RQ        12   /**< server stop req        */
0070 #define NDRXD_COM_SRVSTOP_RP        13   /**< server stop reply      */
0071 #define NDRXD_COM_AT_RQ             14   /**< attach to server req   */
0072 #define NDRXD_COM_AT_RP             15   /**< attach to server reply */
0073 #define NDRXD_COM_RELOAD_RQ         16   /**< reload config req      */
0074 #define NDRXD_COM_RELOAD_RP         17   /**< reload config reply    */
0075 #define NDRXD_COM_TESTCFG_RQ        18   /**< test config req        */
0076 #define NDRXD_COM_TESTCFG_RP        19   /**< test config reply      */
0077 #define NDRXD_COM_SRVINFO_RQ        20   /**< Server info request    */
0078 #define NDRXD_COM_SRVINFO_RP        21   /**< Server info req/rsp    */
0079     
0080 /*
0081  * Un Advertise from xadmin console:
0082  * 
0083  * xadmin--24-->ndrxd--26-->server
0084  *              A              |
0085  *              |              |
0086  *              +------22------+
0087  */
0088 /* Server performs un-advertise operation, informs server about this thing      */
0089 #define NDRXD_COM_SRVUNADV_RQ       22   /**< Server unadvertise request        */
0090 #define NDRXD_COM_SRVUNADV_RP       23   /**< Server unadvertise response       */
0091 /* xadmin requests unadvertise */
0092 #define NDRXD_COM_XADUNADV_RQ       24   /**< xadmin request for unadvertise, req */
0093 #define NDRXD_COM_XADUNADV_RP       25   /**< xadmin request for unadvertise, resp*/
0094 /* ndrxd forwards xadmin request to server */
0095 #define NDRXD_COM_NXDUNADV_RQ       26   /**< ndrxd request for unadvertise, req*/
0096 #define NDRXD_COM_NXDUNADV_RP       27   /**< ndrxd request for unadvertise, resp*/
0097 
0098 #define NDRXD_COM_SRVADV_RQ         28   /**< server requests advertise, req    */
0099 #define NDRXD_COM_SRVADV_RP         29   /**< server reqeusts un-advertise, resp*/
0100     
0101 #define NDRXD_COM_XAPPM_RQ          30   /**< print process model, req          */
0102 #define NDRXD_COM_XAPPM_RP          31   /**< print process model, resp         */
0103     
0104 #define NDRXD_COM_XASHM_PSVC_RQ     32   /**< print SHM services, req           */
0105 #define NDRXD_COM_XASHM_PSVC_RP     33   /**< print SHM services, resp          */
0106     
0107 #define NDRXD_COM_XASHM_PSRV_RQ     34   /**< print SHM servers, req            */
0108 #define NDRXD_COM_XASHM_PSRV_RP     35   /**< print SHM servers, resp           */
0109 
0110 #define NDRXD_COM_NXDREADV_RQ       36   /**< ndrxd request for readvertise, req */
0111 #define NDRXD_COM_NXDREADV_RP       37   /**< ndrxd request for readvertise, resp*/
0112     
0113 #define NDRXD_COM_XADREADV_RQ       38   /**< xadmin request for readvertise, req*/
0114 #define NDRXD_COM_XADREADV_RP       39   /**< xadmin request for readvertise, resp*/
0115 
0116 #define NDRXD_COM_XACABORT_RQ        40  /**< xadmin request for abort, req     */
0117 #define NDRXD_COM_XAABORT_RP        41   /**< xadmin request for abort, resp    */
0118 
0119 #define NDRXD_COM_BRCON_RQ          42   /**< bridge, connected, req            */
0120 #define NDRXD_COM_BRCON_RP          43   /**< bridge, connected, resp           */
0121     
0122 #define NDRXD_COM_BRDISCON_RQ       44   /**< bridge, disconnected, req         */
0123 #define NDRXD_COM_BRDISCON_RP       45   /**< bridge, disconnected, resp        */
0124 
0125 #define NDRXD_COM_BRREFERSH_RQ      46   /**< bridge, refersh, req              */
0126 #define NDRXD_COM_BRREFERSH_RP      47   /**< bridge, refersh, resp             */
0127     
0128 #define NDRXD_COM_BRCLOCK_RQ        48   /**< bridge, monotonic clock exchange, req*/
0129 #define NDRXD_COM_BRCLOCK_RP        49   /**< bridge, monotonic clock exchange, rsp*/
0130 
0131 #define NDRXD_COM_SRVGETBRS_RQ      50   /**< Get bridges, request from server  */
0132 #define NDRXD_COM_SRVGETBRS_RP      51   /**< Get bridges, response from ndrxd  */
0133 
0134 #define NDRXD_COM_SRVPING_RQ        52   /**< Server ping request               */
0135 #define NDRXD_COM_SRVPING_RP        53   /**< Server ping response              */
0136 
0137 #define NDRXD_COM_SRELOAD_RQ        54   /**< xadmin request for server reload, req*/
0138 #define NDRXD_COM_SRELOAD_RP        55   /**< xadmin request for server reload, resp*/
0139 
0140 #define NDRXD_COM_XAPQ_RQ           56   /**< xadmin print service queue, req   */
0141 #define NDRXD_COM_XAPQ_RP           57   /**< xadmin print service queue, resp  */
0142     
0143 #define NDRXD_COM_PE_RQ             58   /**< xadmin print env, req             */
0144 #define NDRXD_COM_PE_RP             59   /**< xadmin print env, resp            */
0145     
0146 #define NDRXD_COM_SET_RQ            60   /**< xadmin set env, req               */
0147 #define NDRXD_COM_SET_RP            61   /**< xadmin set env, resp              */
0148     
0149 #define NDRXD_COM_UNSET_RQ          62   /**< xadmin unset env, req             */
0150 #define NDRXD_COM_UNSET_RP          63   /**< xadmin unset env, resp            */
0151 
0152 #define NDRXD_COM_SRELOADI_RQ       64   /**< ndrxd request for server reload, req, internal  */
0153 #define NDRXD_COM_SRELOADI_RP       65   /**< ndrxd request for server reload, resp, internal */
0154     
0155 #define NDRXD_COM_APPCONFIG_RQ      66   /**< ndrxd appconfig, req, internal    */
0156 #define NDRXD_COM_APPCONFIG_RP      67   /**< ndrxd appconfig, rsp, internal    */
0157     
0158 #define NDRXD_COM_DPING_RQ          68   /**< tprecover ndrxd ping, req, int    */
0159 #define NDRXD_COM_DPING_RP          69   /**< tprecover ndrxd ping, req, int    */
0160     
0161 #define NDRXD_COM_DSLEEP_RQ         70   /**< tprecover ndrxd ping, req, int    */
0162 #define NDRXD_COM_DSLEEP_RP         71   /**< tprecover ndrxd ping, req, int    */
0163     
0164 #define NDRXD_COM_BLIST_RQ          72   /**< bridge admin queue listing, req, int */
0165 #define NDRXD_COM_BLIST_RP          73   /**< bridge admin queue listing, rsp int  */
0166     
0167 #define NDRXD_COM_BRCONINFO_RQ      74   /**< return bridge connection infos, req int */
0168 #define NDRXD_COM_BRCONINFO_RP      75   /**< return bridge connection infos, rsp int */
0169 
0170 #define NDRXD_COM_MAX               75
0171     
0172 /** This is sqv admin thread shutdown priv */
0173 #define NDRXD_COM_SVQADMIN_PRIV     NDRX_COM_SVQ_PRIV
0174 
0175 /* Command contexts */
0176 #define NDRXD_CTX_ANY               -1   /**< Any context...                    */
0177 #define NDRXD_CTX_NOCHG             NDRXD_CTX_ANY   /**< Do not change context! */
0178 #define NDRXD_CTX_ZERO              0    /**< Zero context, no command running  */
0179 #define NDRXD_CTX_START             1    /**< Start command is running          */
0180 #define NDRXD_CTX_STOP              2    /**< Stop context/command is running   */
0181 
0182 /* Max number of services can be advertised by servers! */
0183 #define MAX_SVC_PER_SVR             50
0184 
0185 #define MAX_NDRXD_ERROR_LEN         2048
0186 /* NDRXD Error sesction */
0187 #define NDRXD_EMINVAL            0
0188 #define NDRXD_ESRVCIDDUP         1          /**< Duplicat service ID          */
0189 #define NDRXD_ESRVCIDINV         2          /**< Invalid service ID           */
0190 #define NDRXD_EOS                3          /**< Operating System failure     */
0191 #define NDRXD_ECFGLDED           4          /**< Configuration already loaded */
0192 #define NDRXD_ECFGINVLD          5          /**< Invalid configuration file   */
0193 #define NDRXD_EPMOD              6          /**< Process model failed         */
0194 #define NDRXD_ESHMINIT           7          /**< Shared memory not initialized*/
0195 #define NDRXD_NOTSTARTED         8          /**< App domain not started       */
0196 #define NDRXD_ECMDNOTFOUND       9          /**< Command not found            */
0197 #define NDRXD_ENONICONTEXT       10         /**< Non interractive context     */
0198 #define NDRXD_EREBBINARYRUN      11         /**< Renamed binary in run state  */
0199 #define NDRXD_EBINARYRUN         12         /**< Removed binary in run state  */
0200 #define NDRXD_ECONTEXT           13         /**< Invalid command context      */
0201 #define NDRXD_EINVPARAM          14         /**< Invalid paramters            */
0202 #define NDRXD_EABORT             15         /**< Abort requested              */
0203 #define NDRXD_EENVFAIL           16         /**< putenv failed                */
0204 #define NDRXD_EINVAL             17         /**< Invalid argument             */
0205 #define NDRXD_ENORMAL            18         /**< Normal state expected        */
0206 #define NDRXD_ECFGDEFAULTS       19         /**< Invalid defaults             */
0207 #define NDRXD_ECFGSERVER         20         /**< Invalid server settigns      */
0208 #define NDRXD_ECFGAPPCONFIG      21         /**< Invalid appconfig settings   */
0209 #define NDRXD_EACCES             22         /**< No access to file            */
0210 #define NDRXD_ESYNTAX            23         /**< Syntax error during parsing  */
0211 #define NDRXD_ESYSTEM            24         /**< E/X system failure           */
0212 #define NDRXD_ENOCFGLD           25         /**< Configuartion not loaded     */
0213 #define NDRXD_ENOENT             26         /**< No entry found               */
0214 #define NDRXD_EMAXVAL            26
0215 
0216 /* This section list call types */
0217 #define NDRXD_CALL_TYPE_GENERIC         0   /**< Generic call type        */
0218 #define NDRXD_CALL_TYPE_PM_INFO         1   /**< Process model info       */
0219 #define NDRXD_CALL_TYPE_SVCINFO         2   /**< Service info             */
0220 #define NDRXD_CALL_TYPE_PM_STARTING     3   /**< Process model info (starting process)*/
0221 #define NDRXD_CALL_TYPE_PM_STARTED      4   /**< Process model info  (started)*/
0222 #define NDRXD_CALL_TYPE_PM_STOPPING     5   /**< Process model info  (stop initiated)*/
0223 #define NDRXD_CALL_TYPE_PM_STOPPED      6   /**< Process model info  (stopped)*/
0224 #define NDRXD_CALL_TYPE_PM_RELERR       7   /**< Reload error                 */
0225 #define NDRXD_CALL_TYPE_PM_PPM          8   /**< Print process model          */
0226 #define NDRXD_CALL_TYPE_PM_SHM_PSVC     9   /**< Print services from SHM      */
0227 #define NDRXD_CALL_TYPE_PM_SHM_PSRV     10  /**< Print servers from SHM       */
0228 #define NDRXD_CALL_TYPE_BRIDGEINFO      11  /**< Bridge info command          */
0229 #define NDRXD_CALL_TYPE_BRIDGESVCS      12  /**< Bridge services command      */
0230 #define NDRXD_CALL_TYPE_BRBCLOCK        13  /**< Bridge clock info            */
0231 #define NDRXD_CALL_TYPE_GETBRS          14  /**< Get connected bridges        */
0232 #define NDRXD_CALL_TYPE_PQ              15  /**< Response struct for `pq' cmd */
0233 #define NDRXD_CALL_TYPE_PE              16  /**< Response struct for `pe' cmd */
0234 #define NDRXD_CALL_TYPE_APPCONFIG       17  /**< Response to appconfig command*/
0235 #define NDRXD_CALL_TYPE_DPING           18  /**< NDRXD ping response type     */
0236 #define NDRXD_CALL_TYPE_DSLEEP          19  /**< Put NDRXD in sleep mode      */
0237 #define NDRXD_CALL_TYPE_BLIST           20  /**< List bridge admin queues     */
0238 #define NDRXD_CALL_TYPE_BRCONINFO       21  /**< Connection info messages     */
0239 
0240 #define NDRXD_SRC_NDRXD                 0   /**< Call source is daemon       */
0241 #define NDRXD_SRC_ADMIN                 1   /**< Call source is admin utility*/
0242 #define NDRXD_SRC_SERVER                2   /**< EnduroX server              */
0243 #define NDRXD_SRC_BRIDGE                3   /**< EnduroX bridge server       */
0244 
0245 /**
0246  * NDRXD flags/state:
0247  */
0248 #define NDRXD_STATE_CFG_OK      0x00000001  /**< Configuration loaded       */
0249 #define NDRXD_STATE_SHUTDOWN    0x00000002  /**< About to shutdown          */
0250 #define NDRXD_STATE_DOMSTART    0x00000004  /**< Domain startup in progress */
0251 #define NDRXD_STATE_DOMSTARTED  0x00000008  /**< Domain started             */
0252 #define NDRXD_STATE_SHUTDOWNED  0x00000010  /**< Domain shutdowned          */
0253     
0254 /**
0255  * Process state flags
0256  */
0257 #define NDRXD_PM_MIN_EXIT           0       /**< Minimum dead process       */
0258 #define NDRXD_PM_NOT_STARTED        0       /**< process not started (used for req state too)*/
0259 #define NDRXD_PM_DIED               1       /**< process died for some reason */
0260 #define NDRXD_PM_EXIT               2       /**< normal exit, shutdown      */
0261 #define NDRXD_PM_ENOENT             3       /**< Binary not found           */
0262 #define NDRXD_PM_EACCESS            4       /**< Access denied to execute   */
0263 #define NDRXD_PM_EBADFILE           5       /**< Bad executable             */
0264 #define NDRXD_PM_ELIMIT             6       /**< Limits exceeded            */
0265 #define NDRXD_PM_EENV               7       /**< Failed to prepare env      */
0266 #define NDRXD_PM_EARGSLIM           8       /**< Arguments or env too long  */
0267 #define NDRXD_PM_ESYSTEM            9       /**< Bad executable             */
0268 #define NDRXD_PM_RESTART            10      /**< stop & start back again    */
0269 #define NDRXD_PM_WAIT               11      /**< Process waits on group     */
0270 #define NDRXD_PM_MAX_EXIT           19      /**< Maximum dead process       */
0271     
0272 #define NDRXD_PM_MIN_RUNNING        20      /**< Minimum running process    */
0273 #define NDRXD_PM_STARTING           20      /**< startup in progres...      */
0274 #define NDRXD_PM_RUNNING_OK         21      /**< process running OK (used for req state too!)*/
0275 #define NDRXD_PM_STOPPING           22      /**< About to shutdown          */
0276 #define NDRXD_PM_MAX_RUNNING        39      /**< Max running process        */
0277     
0278 /* Macro for testing not-running process */
0279 #define PM_NOT_RUNNING(X)       (NDRXD_PM_MIN_EXIT <= ( X ) && ( X ) <= NDRXD_PM_MAX_EXIT)
0280 #define PM_RUNNING(X)       (NDRXD_PM_MIN_RUNNING <= ( X ) && ( X ) <= NDRXD_PM_MAX_RUNNING)
0281     
0282 /**
0283  * Flags for shm_svcinfo_t.flags
0284  * Indicates service info entry state.
0285  */
0286 #define NDRXD_SVCINFO_INIT              0x00000001  /**< initialized          */
0287 
0288 
0289 #define NDRXD_SVC_STATUS_AVAIL          0       /**< Service is available     */
0290 #define NDRXD_SVC_STATUS_BUSY           1       /**< Service is busy          */
0291 
0292     
0293 #define NDRXD_CALL_FLAGS_DEADQ          0x0001  /**< Reply queue is dead....!   */
0294 #define NDRXD_CALL_FLAGS_PAGE2          0x0002  /**< Second page from call      */
0295 #define NDRXD_CALL_FLAGS_RSPHAVE_MORE   0x0004  /**< Have more stuff to wait for*/
0296 #define NDRXD_CALL_FLAGS_PAGE3          0x0008  /**< Third page                 */
0297 #define NDRXD_CALL_FLAGS_LP2GRP         0x0010  /**< Lock provider bind to group*/
0298 
0299 #define SRV_KEY_FLAGS_BRIDGE            0x0001  /**< This server is bridge server                 */
0300 #define SRV_KEY_FLAGS_SENDREFERSH       0x0002  /**< Bridge requires that we send refersh to them */
0301 #define SRV_KEY_FLAGS_CONNECTED         0x0004  /**< Is bridge connected?                         */
0302 #define SRV_KEY_FLAGS_PROCGRPLP         0x0008  /**< Singleton group lock providers               */   
0303     
0304 /*
0305  *  values for bridge_refresh_svc_t.mode
0306  */
0307 #define BRIDGE_REFRESH_MODE_FULL        'F' /**< Full replacement arrived.      */
0308 #define BRIDGE_REFRESH_MODE_DIFF        'D' /**< Contains diff +count or -count */
0309 
0310 /*
0311  * Values for cmd_br_net_call_t.msg_type
0312  */
0313 #define BR_NET_CALL_MSG_TYPE_ATMI       'A' /**< This is ATMI call                */
0314 #define BR_NET_CALL_MSG_TYPE_NOTIF      'N' /**< This is ATMI, notif/broadcast    */
0315 #define BR_NET_CALL_MSG_TYPE_NDRXD      'X' /**< This is EnduroX call             */
0316 
0317 #define BR_NET_CALL_MAGIC               0x6A12CC51L /**< Magic of the netcall  */
0318     
0319     
0320 #define PING_MAX_SEQ                    65536    /**< Max sequence number of ping */
0321     
0322     
0323 /* Data types describing bellow data structures */
0324 #define EXF_MIN         0       /**< Minimum suported type */
0325 #define EXF_SHORT   0   /**< short int */
0326 #define EXF_LONG    1   /**< long int */
0327 #define EXF_CHAR    2   /**< character */
0328 #define EXF_FLOAT   3   /**< single-precision float */
0329 #define EXF_DOUBLE  4   /**< double-precision float */
0330 #define EXF_STRING  5   /**< string - null terminated */
0331 #define EXF_CARRAY  6   /**< character array */
0332 #define EXF_NONE        7       /**< Data type - none */ 
0333     
0334 #define EXF_INT         8       /**< Data type - int */ 
0335 #define EXF_ULONG       9       /**< Data type - unsigned long */ 
0336 #define EXF_UINT        10      /**< Data type - unsigned */ 
0337 #define EXF_NTIMER      11      /**< Data type - n_timer_t */ 
0338 #define EXF_TIMET       12      /**< Data type - time_t */ 
0339 #define EXF_USHORT      13      /**< Data type - unsigned short */ 
0340 #define EXF_CARRAYFIX   14      /**< Fixed length carray, use MIN len */ 
0341 #define EXF_MAX         14      /**< Maximum suported type */
0342 
0343 
0344 #define PQ_LEN                  12        /**< The len of last print queue data */    
0345 #define EX_ENV_MAX              4096      /**< max env name/value size */
0346     
0347 
0348 #define NDRX_BRCLOCK_MODE_ASYNC       1   /**< Async clock data               */
0349 #define NDRX_BRCLOCK_MODE_REQ         2   /**< Request for clock data         */
0350 #define NDRX_BRCLOCK_MODE_RSP         3   /**< Response clock data            */
0351 
0352     
0353 #define NDRX_CONMODE_ACTIVE         'A'         /**< This is client */
0354 #define NDRX_CONMODE_PASSIVE        'P'         /**< This is server */
0355 
0356 /*---------------------------Enums--------------------------------------*/
0357 /*---------------------------Typedefs-----------------------------------*/
0358 
0359 /**
0360  * Shared memory entry for server ID
0361  */
0362 typedef struct shm_srvinfo shm_srvinfo_t;
0363 struct shm_srvinfo
0364 {
0365     int srvid;
0366 
0367     unsigned svc_fail[MAX_SVC_PER_SVR];
0368     unsigned svc_succeed[MAX_SVC_PER_SVR];
0369 
0370     unsigned min_rsp_msec[MAX_SVC_PER_SVR];
0371     unsigned max_rsp_msec[MAX_SVC_PER_SVR];
0372     unsigned last_rsp_msec[MAX_SVC_PER_SVR];
0373     short svc_status[MAX_SVC_PER_SVR];     /**< The status of the service     */
0374 
0375     char last_reply_q[NDRX_MAX_Q_SIZE+1];  /**< Last queue on it should reply */
0376     /** See NDRXD_PM_E error codes */
0377     unsigned execerr;                      /**< Last exec error               */
0378     short status;                          /**< Global status, avail or busy  */
0379     short last_command_id;                 /**< Last command ID received      */
0380 };
0381 
0382 /**
0383  * Basic cluster node info
0384  */
0385 typedef struct cnodeinfo cnodeinfo_t;
0386 struct cnodeinfo
0387 {
0388     int latency;        /**< Latency in ms */
0389     int srvs;           /**< Number of serves on this cluster node */
0390 };
0391 
0392 
0393 /**
0394  * Shared memory resource id
0395  */
0396 typedef struct ndrx_shm_resid ndrx_shm_resid_t;
0397 struct ndrx_shm_resid
0398 {
0399     short cnt;                          /**< number of instances installed  */
0400     int resid;                          /**< Resource id                    */
0401 };
0402 
0403 /**
0404  * Shared memory entry for service
0405  */
0406 typedef struct shm_svcinfo shm_svcinfo_t;
0407 struct shm_svcinfo
0408 {
0409     char service[MAXTIDENT+1];          /**< name of the service                  */
0410     volatile int srvs;                           /**< Count of servers advertising this service*/
0411     volatile int flags;                          /**< service flags                        */
0412     volatile int csrvs;                          /**< Number of advertises in cluster      */
0413     volatile int totclustered;                   /**< Total clustered nodes                */
0414     volatile int cnodes_max_id;                  /**< Max id of cluster nodes in list (for fast search) */
0415     cnodeinfo_t cnodes[CONF_NDRX_NODEID_COUNT];    /**< List of cluster nodes */
0416     /**
0417      * Number of resources, because there could be rqaddr servers, where
0418      * srvs is large number, but there is only on queue.
0419      */
0420     volatile short resnr;                          
0421     volatile unsigned int resrr;                          /**< round robin server */
0422     
0423     /* THIST MUST BE LAST IN STRUCT (AS IT WILL SCALE DEPENDING ON SERVERS): */
0424     ndrx_shm_resid_t resids[0];         /**<  Servers id's offering this service */
0425 };
0426 
0427 /* Macros for shm service size */
0428 #define SHM_SVCINFO_SIZEOF  (sizeof(shm_svcinfo_t) + sizeof(ndrx_shm_resid_t)*G_atmi_env.maxsvcsrvs)
0429 
0430 /* memory access index: */
0431 #define SHM_SVCINFO_INDEX(MEM, IDX) ((shm_svcinfo_t*)(((char*)MEM)+(int)(SHM_SVCINFO_SIZEOF*IDX)))
0432 
0433 /*
0434  * Generic command request structure
0435  */
0436 typedef struct
0437 {
0438     /* <standard comms header:> */
0439 #if defined(EX_USE_SYSVQ) || defined(EX_USE_SVAPOLL)
0440     long mtype; /* mandatory for System V queues */
0441 #endif
0442     short command_id;
0443     char proto_ver[4];
0444     int proto_magic;
0445     /* </standard comms header> */
0446     
0447     unsigned long magic;                /**< Packed magic                     */
0448     int command;                        /**< Request command                  */
0449     short msg_type;                     /**< Message type                     */
0450     short msg_src;                      /**< Message source                   */
0451     char reply_queue[NDRX_MAX_Q_SIZE+1];/**< Queue (str) on which to pass back reply*/
0452     int flags;                          /**< Flags for command call           */
0453     int caller_nodeid;                  /**< Node id of the caller            */
0454 } command_call_t;
0455 
0456 /**
0457  * Special structure for stop command.
0458  */
0459 typedef struct
0460 {
0461     command_call_t call;
0462 
0463     /* some additional attribs */
0464     short complete_shutdown;            /**< Id of the server */
0465     int srvid;
0466     char binary_name[MAXTIDENT+1];
0467     char procgrp[MAXTIDENT+1];  /**< process group to shutdown        */
0468     long flags;                 /**< Additional flags for the command */
0469 
0470 } command_startstop_t;
0471 
0472 
0473 /**
0474  * Set/unset call
0475  */
0476 typedef struct
0477 {
0478     command_call_t call;
0479     char env[EX_ENV_MAX+1];
0480 } command_setenv_t;
0481 
0482 /**
0483  * Configure appconfig, dynamically
0484  */
0485 typedef struct
0486 {
0487     command_call_t call;            /**< Standard command call              */
0488     char setting[MAXTIDENT+1];      /**< Setting name                       */
0489     char svalue[MAXTIDENT+1];       /**< Request/Response value             */
0490 } command_appconfig_t;
0491 
0492 
0493 /**
0494  * Configure ndrxd daemon sleep, for debug
0495  */
0496 typedef struct
0497 {
0498     command_call_t call;            /**< Standard command call              */
0499     int secs;                       /**< Sleep seconds                      */
0500 } command_dsleep_t;
0501 
0502 /**
0503  * Dynamic un/advertise structure
0504  */
0505 typedef struct
0506 {
0507     command_call_t call;
0508     
0509     int srvid;
0510     char svc_nm[MAXTIDENT+1];       /**< Service name                       */
0511     char fn_nm[MAXTIDENT+1];        /**< Function name                      */
0512     ndrx_stopwatch_t   qopen_time;  /**< Timer when q was open              */
0513 
0514 } command_dynadvertise_t;
0515 
0516 /**
0517  * Server ping structure
0518  */
0519 typedef struct
0520 {
0521     command_call_t call;
0522     int srvid;                      /**< server ID to be pinged             */
0523     int seq;                        /**< sequence number in ping            */
0524 } command_srvping_t;
0525 
0526 /**
0527  * Generic command reply structure
0528  * If changing, see ndrx_thstop_command_call_t. The command_id must match.
0529  */
0530 typedef struct
0531 {
0532     /* <standard comms header:> */
0533 #if defined(EX_USE_SYSVQ) || defined(EX_USE_SVAPOLL)
0534     long mtype;             /**< mandatory for System V queues              */
0535 #endif
0536     short command_id;
0537     char proto_ver[4];
0538     int proto_magic;
0539     /* </standard comms header> */
0540     unsigned long magic;    /**< Packed macking...                          */
0541     int command;            /**< replay command                             */
0542     short msg_type;         /**< Message source                             */
0543     short msg_src;          /**< Message source                             */
0544     long flags;             /**< Response flags                             */
0545     int status;             /**< Reply status                               */
0546     int error_code;         /**< Error code, if status if is faulty         */
0547     long userfld1;          /**< User field                                 */
0548     char error_msg[RPLY_ERR_MSG_MAX];/**< Error message in reply            */
0549     char subtype[0];        /**< Pointer to subtype                         */
0550 } command_reply_t;
0551 
0552 /*
0553  * Generic bridge to ndrxd command.
0554  * Actually now command_call have already nodeid inside, but ok...
0555  */
0556 typedef struct
0557 {
0558     command_call_t call;
0559     int nodeid;
0560 } bridge_info_t;
0561 
0562 /**
0563  * Entry of the refresh
0564  */
0565 typedef struct
0566 {
0567     char mode; /**< This is diff (+X, -X) or full */
0568     char svc_nm[MAXTIDENT+1];
0569     int count;
0570 } bridge_refresh_svc_t;
0571 
0572 /**
0573  * Refresh call.
0574  * Probably this can be directly forwarded to other node via bridge.
0575  */
0576 typedef struct
0577 {
0578     command_call_t call;
0579     char mode;   /**< Refresh mode, full or partial??? */
0580     int count; /**< count of bellow entries */
0581     bridge_refresh_svc_t svcs[0]; /**< The entries. */
0582 } bridge_refresh_t;
0583 
0584 
0585 /**
0586  * When connection is established, both nodes exchanges with their
0587  * monotonic clocks.
0588  */
0589 typedef struct
0590 {
0591     /* Clock sync */
0592     command_call_t call;
0593     ndrx_stopwatch_t time;
0594     int mode;           /**< 1 - async, 2 - request, 3 - reply                      */
0595     long orig_seq;           /**< sequence number for the request (if with reply         */
0596     int orig_nodeid;    /**< originator of the message (or caller in case of reply  */
0597     time_t orig_timestamp;/**< Originatic clock (for the reply match)               */
0598 } cmd_br_time_sync_t;
0599 
0600 /**
0601  * Generic handler for bridge message
0602  */
0603 typedef struct
0604 {
0605     long br_magic;
0606     char msg_type;  /**< A - ATMI, X - NDRX                                 */
0607     int command_id; /**< either ATMI or NDRX command_id/command             */
0608     long len;
0609     char buf[0];
0610 } cmd_br_net_call_t;
0611 
0612 /***************** List of reply types/subtypes ***************************/
0613 
0614 
0615 /**
0616  * This is used only for ndrxd responses
0617  * reply struct to ndrxd pings...
0618  */
0619 typedef struct
0620 {
0621     command_reply_t rply;           /**< Reply record                       */
0622     int srvid;                      /**< server ID to be pinged             */
0623     int seq;                        /**< sequence number in ping            */
0624 } command_reply_srvping_t;
0625 
0626 /**
0627  * Reply command of the appconfig
0628  */
0629 typedef struct
0630 {
0631     command_reply_t rply;           /**< Reply record                       */
0632     char setting[MAXTIDENT+1];      /**< Setting name                       */
0633     char svalue[MAXTIDENT+1];       /**< Request/Response value             */
0634 } command_reply_appconfig_t;
0635 
0636 /**
0637  * Reply for start/stop processing...
0638  */
0639 typedef struct
0640 {
0641     command_reply_t rply;
0642     /* list some process ifo */
0643     char binary_name[MAXTIDENT+1];  /**< Name of the binary                 */
0644     int srvid;
0645     char clopt[PATH_MAX];
0646     long state;                     /**< process state code                 */
0647     pid_t pid;                      /**< PID of the process                 */
0648 } command_reply_pm_t;
0649 
0650 /**
0651  * Details entry about services
0652  */
0653 typedef struct
0654 {
0655     char svc_nm[MAXTIDENT+1];       /**< Service name                       */
0656     char fn_nm[MAXTIDENT+1];        /**< Function name                      */
0657     long done;                      /**< how many requests are finished     */
0658     long fail;                      /**< how many requests are finished     */
0659     long min;                       /**< min response time                  */
0660     long max;                       /**< max response time                  */
0661     long last;                      /**< last response time                 */
0662     short status;                   /**< service status                     */
0663 } command_reply_psc_det_t;
0664 
0665 /**
0666  * Reply for psc (print services) command
0667  */
0668 typedef struct
0669 {
0670     command_reply_t rply;
0671     /* list some process info */
0672     char binary_name[MAXTIDENT+1]; /**< Name of the binary          */
0673     int nodeid;           /**< Other node id of the bridge          */
0674     int srvid;
0675     pid_t pid;            /**< PID of the process                   */
0676     long state;           /**< process state code                   */
0677     int svc_count;        /**< count of services (for belloow array)*/
0678     command_reply_psc_det_t svcdet[0];
0679 } command_reply_psc_t;
0680 
0681 /**
0682  * Queue list 
0683  */
0684 typedef struct
0685 {
0686     command_reply_t rply;
0687     char qstr[NDRX_MAX_Q_SIZE+1];  /**< Queueu name                    */
0688 } command_reply_blist_t;
0689 
0690 
0691 /**
0692  * Bridge infos
0693  */
0694 typedef struct
0695 {
0696     command_reply_t rply;
0697     long locnodeid; /**< local node id                      */
0698     int srvid;      /**< Server id generating resposne      */
0699     long remnodeid; /**< remove node id                     */
0700     char mode;      /**< Connection mode                    */   
0701     int fd;         /**< socket FD number                   */
0702     
0703     long time;      /**< local monotonic time sec           */
0704     long timems;    /**< local monotonic time ms            */
0705     
0706     /* Clock infos: */
0707     long lastsync;  /**< last sync time ago (seconds)       */
0708     long timediffs; /**< time diff in seconds between hosts */
0709     long timediffms; /**< time diff in milliseconds between hosts */
0710     long roundtrip; /**< roundtrip in milliseconds          */
0711     
0712 } command_reply_brconinfo_t;
0713 
0714 
0715 /**
0716  * Reply for ppm (print process model) command
0717  * Data fields really are taken from pm_node_t/ndrxd.h!!
0718  */
0719 typedef struct
0720 {
0721     command_reply_t rply;
0722     /** list some process ifo */
0723     char binary_name[MAXTIDENT+1]; /**< Name of the binary*/
0724     
0725     /** Real binary name (reported by server it self */
0726     char binary_name_real[MAXTIDENT+1];
0727     
0728     /** request address, used by system v */
0729     char rqaddress[NDRX_MAX_Q_SIZE+1];
0730     
0731     int srvid;
0732     long state;             /**< process state code (current)  */
0733     long reqstate;          /**< Requested state               */
0734     short autostart;        /**< Start automatically after "start" cmd */
0735     int exec_seq_try;       /**< Sequental start try           */
0736     long last_startup;      /**< Cycle count for last start   */
0737 
0738     int num_term_sigs;      /**< Number of times to send term sig, before -9 */
0739     long last_sig;          /**< Time when signal was sent     */
0740     int autokill;           /**< Kill the process if not started in time */
0741     /** Parent process PID (or if server if only process then it is real PID */
0742     pid_t pid;
0743     /** Server process PID (if parent is script, then this is real one) */
0744     pid_t svpid;
0745     long state_changed;     /**< Timer for state changed       */
0746     int flags;              /**< Flags sent by server info     */
0747     short   nodeid;         /**< other node id, if this is bridge */
0748     int procgrp_no;         /**< Sinlegron group of the process */
0749     int procgrp_lp_no;      /**< Defined lock provider for group no */
0750     int procgrp_lp_no_act;  /**< Actual number of lock provider (reported) */
0751     char procgrp[MAXTIDENT+1];   /**< Sinlegron group of the process, name */
0752     char procgrp_lp[MAXTIDENT+1];/**< Defined lock provider for group name*/
0753 
0754 } command_reply_ppm_t;
0755 
0756 /**
0757  * Packet for shm_psvc, fields from shm_svcinfo_t
0758  */
0759 typedef struct
0760 {
0761     command_reply_t rply;
0762     int slot;                       /**< Position in SHM                      */
0763     char service[MAXTIDENT+1];      /**< name of the service                  */
0764     int srvs;                       /**< Count of servers advertising this service*/
0765     int flags;                      /**< service flags                        */
0766     
0767     int csrvs;                      /**< Number of advertises in cluster      */
0768     int totclustered;               /**< Total clustered nodes                */
0769     int cnodes_max_id;              /**< Max id of cluster nodes in list (for fast search) */
0770     cnodeinfo_t cnodes[CONF_NDRX_NODEID_COUNT]; /**< List of cluster nodes */
0771     /**< Server ID (fixed number xadmin output) */
0772     ndrx_shm_resid_t resids[CONF_NDRX_MAX_SRVIDS_XADMIN];
0773     int resnr;                                  /**< Number of local resources              */
0774     
0775 } command_reply_shm_psvc_t;
0776 
0777 
0778 /**
0779  * Packet for shm_psvc, fields from shm_svcinfo_t
0780  */
0781 typedef struct
0782 {
0783     command_reply_t rply;
0784     char service[MAXTIDENT+1];  /**< name of the service                    */
0785     int pq_info[PQ_LEN];        /**< Print queues,  statistics              */
0786 } command_reply_pq_t;
0787 
0788 /**
0789  * Packet for shm_psrv, fields from shm_srvinfo_t
0790  */
0791 typedef struct
0792 {
0793     command_reply_t rply;
0794     int slot;                              /**< Position in shm.              */
0795     int srvid;
0796     unsigned execerr;                      /**< Flags for last call           */
0797     short status;                          /**< Glboal status, avail or busy  */
0798     short last_command_id;                 /**< Last command ID received      */
0799     char last_reply_q[NDRX_MAX_Q_SIZE+1];  /**< Last queue on it should reply */
0800     
0801 } command_reply_shm_psrv_t;
0802 
0803 /**
0804  * This reply contains additional info about configuration loading process & errors
0805  */
0806 typedef struct
0807 {
0808     command_reply_t rply;
0809     int srvid;                      /**< Server ID with problem  */
0810     char old_binary[MAXTIDENT+1];   /**< Old binary in config    */
0811     char new_binary[MAXTIDENT+1];   /**< New binary in config    */
0812     int error;                      /**< Associated error code   */
0813     char msg[256];                  /**< additional errro msg    */
0814 } command_reply_reload_t;
0815 
0816 /**
0817  * Reply to command getbrs - GETBRIDGES
0818  */
0819 typedef struct
0820 {
0821     command_reply_t rply;
0822     char nodes[CONF_NDRX_NODEID_COUNT+1];
0823 } command_reply_getbrs_t;
0824 
0825 /**
0826  * Packet for print environment (limited to: FILENAME_MAX)
0827  */
0828 typedef struct
0829 {
0830     command_reply_t rply;
0831     char env[EX_ENV_MAX+1];         /* Env value */
0832 } command_reply_pe_t;
0833 
0834 /***************** List of request types/subtypes ***********************/
0835 /**
0836  * Service entry
0837  */
0838 typedef struct
0839 {
0840     char svc_nm[MAXTIDENT+1];       /**< Service name                   */
0841     char fn_nm[MAXTIDENT+1];        /**< Function name                  */
0842     ndrx_stopwatch_t   qopen_time;  /**< Timer when q was open          */
0843 } svc_inf_t;
0844 
0845 /**
0846  * Server Key structure - key to identify server sending the info to us!
0847  */
0848 typedef struct
0849 {
0850    int srvid;              /**< server id sending this info                   */
0851    pid_t  pid;             /**< server's process id (for crosscheck alarming) */
0852    /** real server PID */
0853    pid_t svpid;
0854    /** Real name of server process */
0855    char binary_name_real[MAXTIDENT+1];
0856    int state;              /**< server's state (the same as for process       */
0857    int flags;              /**< servers flags                                 */
0858    int nodeid;             /**< Other node id of the bridge                   */
0859    /** 
0860     * Have a request address of the server so that we do not zap them during
0861     * housekeeping
0862     */
0863    char rqaddress[NDRX_MAX_Q_SIZE+1];
0864    
0865    int resid;               /**< Resource id server id for poll, qid for sysv   */
0866    int procgrp_lp_no;       /**< Singleton process group lock provider          */
0867    
0868 } srv_key_t;
0869 
0870 /**
0871  * Server status type.
0872  * Also lists all services advertised.
0873  */
0874 typedef struct
0875 {
0876    command_call_t call;    /**< Generic call data                           */
0877    srv_key_t srvinfo;      /**< Server key                                  */
0878    short svc_count;        /**< Service count                               */
0879    svc_inf_t svcs[0];      /**< Service names, should be in proper order!   */
0880 } srv_status_t;
0881 /*---------------------------Globals------------------------------------*/
0882 /*---------------------------Statics------------------------------------*/
0883 /*---------------------------Prototypes---------------------------------*/
0884 
0885 /* ATMI helpers here (to avoid header recursion): */
0886 extern NDRX_API int cmd_generic_call(int ndrxd_cmd, int msg_src, int msg_type,
0887                             command_call_t *call, size_t call_size,
0888                             char *reply_q,
0889                             mqd_t reply_queue, /* listen for answer on this! */
0890                             mqd_t admin_queue, /* this might be FAIL! */
0891                             char *admin_q_str, /* should be set! */
0892                             int argc, char **argv,
0893                             int *p_have_next,
0894                             int (*p_rsp_process)(command_reply_t *reply, size_t reply_len),
0895                             void (*p_put_output)(char *text),
0896                             int need_reply);
0897 
0898 extern NDRX_API int cmd_generic_call_2(int ndrxd_cmd, int msg_src, int msg_type,
0899                             command_call_t *call, size_t call_size,
0900                             char *reply_q,
0901                             mqd_t reply_queue, /* listen for answer on this! */
0902                             mqd_t admin_queue, /* this might be FAIL! */
0903                             char *admin_q_str, /* should be set! */
0904                             int argc, char **argv,
0905                             int *p_have_next,
0906                             int (*p_rsp_process)(command_reply_t *reply, size_t reply_len),
0907                             void (*p_put_output)(char *text),
0908                             int need_reply,
0909                             int reply_only,
0910                             char *rply_buf_out,             /* might be a null  */
0911                             int *rply_buf_out_len,          /* if above is set, then must not be null */
0912                             int flags,
0913                             int (*p_rply_request)(char **buf, long len)
0914 );
0915 
0916 extern NDRX_API int cmd_generic_bufcall(int ndrxd_cmd, int msg_src, int msg_type,
0917                             command_call_t *call, size_t call_size,
0918                             char *reply_q,
0919                             mqd_t reply_queue, /* listen for answer on this! */
0920                             mqd_t admin_queue, /* this might be FAIL! */
0921                             char *admin_q_str, /* should be set! */
0922                             int argc, char **argv,
0923                             int *p_have_next,
0924                             int (*p_rsp_process)(command_reply_t *reply, size_t reply_len),
0925                             void (*p_put_output)(char *text),
0926                             int need_reply,
0927                             int reply_only,
0928                             char *rply_buf_out,             /* might be a null  */
0929                             int *rply_buf_out_len,          /* if above is set, then must not be null */
0930                             int flags,
0931                             int (*p_rply_request)(char **buf, long len));
0932 
0933 extern NDRX_API int cmd_generic_callfl(int ndrxd_cmd, int msg_src, int msg_type,
0934                             command_call_t *call, size_t call_size,
0935                             char *reply_q,
0936                             mqd_t reply_queue, /* listen for answer on this! */
0937                             mqd_t admin_queue, /* this might be FAIL! */
0938                             char *admin_q_str, /* should be set! */
0939                             int argc, char **argv,
0940                             int *p_have_next,
0941                             int (*p_rsp_process)(command_reply_t *reply, size_t reply_len),
0942                             void (*p_put_output)(char *text),
0943                             int need_reply,
0944                             int flags);
0945 extern NDRX_API void cmd_generic_init(int ndrxd_cmd, int msg_src, int msg_type,
0946                             command_call_t *call, char *reply_q);
0947 #ifdef  __cplusplus
0948 }
0949 #endif
0950 
0951 #endif  /* NDRXDCMN_H */
0952 
0953 /* vim: set ts=4 sw=4 et smartindent: */