/* * Handle an incoming "put" command */ static int fPMI_Handle_put(PMIProcess * pentry) { int rc = 0; PMIKVSpace *kvs; char kvsname[MAXKVSNAME]; char message[PMIU_MAXLINE], outbuf[PMIU_MAXLINE]; char key[MAXKEYLEN], val[MAXVALLEN]; PMIU_getval("kvsname", kvsname, MAXKVSNAME); DBG_PRINTFCOND(pmidebug, ("Put: Finding kvs %s\n", kvsname)); kvs = fPMIKVSFindSpace(kvsname); if (kvs) { /* should check here for duplicate key and raise error */ PMIU_getval("key", key, MAXKEYLEN); PMIU_getval("value", val, MAXVALLEN); rc = fPMIKVSAddPair(kvs, key, val); if (rc == 1) { rc = -1; /* no duplicate keys allowed */ MPL_snprintf(message, PMIU_MAXLINE, "duplicate_key %s", key); } else if (rc == -1) { rc = -1; MPL_snprintf(message, PMIU_MAXLINE, "no_room_in_kvs_%s", kvsname); } else { rc = 0; MPL_strncpy(message, "success", PMIU_MAXLINE); } } else { rc = -1; MPL_snprintf(message, PMIU_MAXLINE, "kvs_%s_not_found", kvsname); } MPL_snprintf(outbuf, PMIU_MAXLINE, "cmd=put_result rc=%d msg=%s\n", rc, message); PMIWriteLine(pentry->fd, outbuf); return 0; }
/* * Handle incoming "getbyidx" command */ static int fPMI_Handle_getbyidx( PMIProcess *pentry ) { int j, jNext, rc=0; PMIKVSpace *kvs; char kvsname[MAXKVSNAME], j_char[8], outbuf[PMIU_MAXLINE]; PMIKVPair *p; PMIU_getval( "kvsname", kvsname, MAXKVSNAME ); kvs = fPMIKVSFindSpace( kvsname ); if (kvs) { PMIU_getval( "idx", j_char, sizeof(j_char) ); j = atoi( j_char ); jNext = j+1; if (kvs->lastIdx >= 0 && j >= kvs->lastIdx) { for (p = kvs->lastByIdx, j-= kvs->lastIdx; j-- > 0 && p; p = p->nextPair ); } else { for (p = kvs->pairs; j-- > 0 && p; p = p->nextPair) ; } if (p) { MPIU_Snprintf( outbuf, PMIU_MAXLINE, "cmd=getbyidx_results " "rc=0 nextidx=%d key=%s val=%s\n", jNext, p->key, p->val ); kvs->lastIdx = jNext-1; kvs->lastByIdx = p; } else { MPIU_Snprintf( outbuf, PMIU_MAXLINE, "cmd=getbyidx_results rc=-1 " "reason=no_more_keyvals\n" ); kvs->lastIdx = -1; kvs->lastByIdx = 0; } } else { rc = -1; MPIU_Snprintf( outbuf, PMIU_MAXLINE, "cmd=getbyidx_results rc=-1 " "reason=kvs_%s_not_found\n", kvsname ); } PMIWriteLine( pentry->fd, outbuf ); DBG_PRINTFCOND(pmidebug,( "%s", outbuf )); return rc; }
/* * Handle an incoming "destroy_kvs" command */ static int fPMI_Handle_destroy_kvs(PMIProcess * pentry) { int rc = 0; PMIKVSpace *kvs; char kvsname[MAXKVSNAME]; char message[PMIU_MAXLINE], outbuf[PMIU_MAXLINE]; PMIU_getval("kvsname", kvsname, MAXKVSNAME); kvs = fPMIKVSFindSpace(kvsname); if (kvs) { PMIKVSFree(kvs); MPL_snprintf(message, PMIU_MAXLINE, "KVS_%s_successfully_destroyed", kvsname); } else { MPL_snprintf(message, PMIU_MAXLINE, "KVS %s not found", kvsname); rc = -1; } MPL_snprintf(outbuf, PMIU_MAXLINE, "cmd=kvs_destroyed rc=%d msg=%s\n", rc, message); PMIWriteLine(pentry->fd, outbuf); return 0; }
/* * Handle incoming "get" command */ static int fPMI_Handle_get( PMIProcess *pentry ) { PMIKVSpace *kvs; int rc=0; char kvsname[MAXKVSNAME]; char message[PMIU_MAXLINE], key[PMIU_MAXLINE], value[PMIU_MAXLINE]; char outbuf[PMIU_MAXLINE]; PMIU_getval( "kvsname", kvsname, MAXKVSNAME ); DBG_PRINTFCOND(pmidebug,( "Get: Finding kvs %s\n", kvsname ) ); kvs = fPMIKVSFindSpace( kvsname ); if (kvs) { PMIU_getval( "key", key, PMIU_MAXLINE ); /* Here we could intercept internal keys, e.g., pmiPrivate keys. */ rc = fPMIKVSFindKey( kvs, key, value, sizeof(value) ); if (rc == 0) { rc = 0; MPIU_Strncpy( message, "success", PMIU_MAXLINE ); } else if (rc) { rc = -1; MPIU_Strncpy( value, "unknown", PMIU_MAXLINE ); MPIU_Snprintf( message, PMIU_MAXLINE, "key_%s_not_found", kvsname ); } } else { rc = -1; MPIU_Strncpy( value, "unknown", PMIU_MAXLINE ); MPIU_Snprintf( message, PMIU_MAXLINE, "kvs_%s_not_found", kvsname ); } MPIU_Snprintf( outbuf, PMIU_MAXLINE, "cmd=get_result rc=%d msg=%s value=%s\n", rc, message, value ); PMIWriteLine( pentry->fd, outbuf ); DBG_PRINTFCOND( pmidebug, ("%s", outbuf )); return rc; }