0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
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 <errno.h>
0040 #include <sys/sem.h>
0041
0042 #include <lcfint.h>
0043 #include <atmi.h>
0044 #include <atmi_shm.h>
0045 #include <ndrstandard.h>
0046 #include <ndebug.h>
0047 #include <ndrxdcmn.h>
0048 #include <userlog.h>
0049 #include <singlegrp.h>
0050 #include <Exfields.h>
0051 #include <ubfutil.h>
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 expublic long ndrx_tpsgislocked(int grpno, long flags, long *grp_flags)
0066 {
0067 long ret=EXSUCCEED;
0068 ndrx_sg_shm_t *p_shm, local;
0069 UBFH *p_ub=NULL;
0070
0071 NDRX_LOG(log_debug, "Checking if group %d is locked", grpno);
0072
0073
0074
0075
0076 if (0==grpno)
0077 {
0078 grpno = G_atmi_env.procgrp_no;
0079 }
0080
0081 NDRX_LOG(log_debug, "Checking if group %d is locked", grpno);
0082
0083 p_shm = ndrx_sg_get(grpno);
0084
0085 if (NULL==p_shm)
0086 {
0087
0088 ndrx_TPset_error_fmt(TPEINVAL, "Process group not found in shared memory %d",
0089 grpno);
0090 EXFAIL_OUT(ret);
0091 }
0092
0093 ndrx_sg_load(&local, p_shm);
0094
0095 if (NULL!=grp_flags)
0096 {
0097
0098 *grp_flags = ((long)local.flags & NDRX_SG_SINGLETON);
0099 }
0100
0101
0102 if (local.flags & NDRX_SG_SINGLETON)
0103 {
0104 if ( (local.flags & NDRX_SG_VERIFY) && (flags & TPPG_SGVERIFY) )
0105 {
0106 long tmp, rsplen;
0107 char svcnm[MAXTIDENT+1]={EXEOS};
0108
0109 snprintf(svcnm, sizeof(svcnm), NDRX_SVC_SGLOC, tpgetnodeid(), grpno);
0110
0111 p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0112
0113 if (NULL==p_ub)
0114 {
0115 NDRX_LOG(log_error, "Buffer alloc fail");
0116 EXFAIL_OUT(ret);
0117 }
0118
0119 tmp = grpno;
0120 if (EXSUCCEED!=Bchg(p_ub, EX_COMMAND, 0, NDRX_SGCMD_VERIFY, 0L)
0121 || EXSUCCEED!=Bchg(p_ub, EX_PROCGRP_NO, 0, (char *)&tmp, 0L))
0122 {
0123 NDRX_LOG(log_error, "Failed to setup request buffer: %s", Bstrerror(Berror));
0124 ndrx_TPset_error_fmt(TPESYSTEM, "Failed to setup request buffer: %s", Bstrerror(Berror));
0125 EXFAIL_OUT(ret);
0126 }
0127
0128 ndrx_debug_dump_UBF(log_info, "Request buffer:", p_ub);
0129 NDRX_LOG(log_debug, "Calling [%s]", svcnm);
0130
0131 ret = tpcall(svcnm, (char*)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTRAN);
0132
0133 if (EXSUCCEED!=ret)
0134 {
0135 NDRX_LOG(log_error, "Failed to call [%s]: %s",
0136 svcnm, tpstrerror(tperrno));
0137
0138
0139 if (TPESVCFAIL==tperrno)
0140 {
0141 char errmsg[MAX_TP_ERROR_LEN+1];
0142 BFLDLEN errmsglen;
0143 long err;
0144 ndrx_debug_dump_UBF(log_error, "reply buffer:", p_ub);
0145
0146 if (EXSUCCEED==Bget(p_ub, EX_TPERRNO, 0, (char *)&err, 0L)
0147 && EXSUCCEED==Bget(p_ub, EX_TPSTRERROR, 0, (char *)errmsg, &errmsglen))
0148 {
0149
0150 ndrx_TPunset_error();
0151
0152 ndrx_TPset_error_msg(err, errmsg);
0153 }
0154 }
0155
0156 EXFAIL_OUT(ret);
0157 }
0158 else
0159 {
0160 char lock_stat;
0161
0162 ndrx_debug_dump_UBF(log_info, "reply buffer:", p_ub);
0163
0164
0165 if (EXSUCCEED!=Bget(p_ub, EX_LCKSTATUS, 0, (char *)&lock_stat, 0L))
0166 {
0167 NDRX_LOG(log_error, "Missing EX_LCKSTATUS: %s", Bstrerror(Berror));
0168 ndrx_TPset_error_fmt(TPESYSTEM, "Missing EX_LCKSTATUS: %s", Bstrerror(Berror));
0169 EXFAIL_OUT(ret);
0170 }
0171
0172 ret=lock_stat;
0173
0174 if (EXTRUE==ret && EXSUCCEED!=Bget(p_ub, EX_SEQUENCE, 0, (char *)&ret, 0L))
0175 {
0176 NDRX_LOG(log_error, "Missing EX_SEQUENCE: %s", Bstrerror(Berror));
0177 ndrx_TPset_error_fmt(TPESYSTEM, "Missing EX_SEQUENCE: %s", Bstrerror(Berror));
0178 EXFAIL_OUT(ret);
0179 }
0180 }
0181 }
0182 else
0183 {
0184
0185 ret=ndrx_sg_is_locked_int(grpno, p_shm, NULL, 0);
0186
0187 if (EXFAIL==ret)
0188 {
0189 NDRX_LOG(log_error, "Local group %d check failed", grpno);
0190 goto out;
0191 }
0192
0193 if (EXTRUE==ret)
0194 {
0195
0196 ret=p_shm->sequence;
0197 }
0198 }
0199 }
0200 else if (flags & TPPG_NONSGSUCC)
0201 {
0202 NDRX_LOG(log_debug, "grpno=%d is not singleton", grpno);
0203 ret=EXSUCCEED;
0204 }
0205 else
0206 {
0207
0208 ndrx_TPset_error_fmt(TPEPROTO, "Process group %d is not singleton",
0209 grpno);
0210 EXFAIL_OUT(ret);
0211 }
0212
0213 out:
0214 if (NULL!=p_ub)
0215 {
0216 tpfree((char *)p_ub);
0217 }
0218 NDRX_LOG(log_info, "lock check grpno=%d ret = %ld", grpno, ret);
0219 return ret;
0220 }
0221
0222
0223