Beispiel #1
0
static int
as_read_users(aerospike* as, const as_policy_admin* policy, uint8_t* buffer, uint8_t* end, as_vector* /*<as_user_roles*>*/ users)
{
	int timeout_ms = (policy)? policy->timeout : as->config.policies.admin.timeout;
	if (timeout_ms <= 0) {
		timeout_ms = DEFAULT_TIMEOUT;
	}
	uint64_t deadline_ms = cf_getms() + timeout_ms;
	as_node* node = as_node_get_random(as->cluster);
	
	if (! node) {
		return CITRUSLEAF_FAIL_CLIENT;
	}
	
	int fd;
	int status = as_node_get_connection(node, &fd);
	
	if (status) {
		as_node_release(node);
		return status;
	}
	
	if (as_send(fd, buffer, end, deadline_ms, timeout_ms)) {
		cf_close(fd);
		as_node_release(node);
		return CITRUSLEAF_FAIL_TIMEOUT;
	}
	
	status = as_read_user_blocks(fd, buffer, deadline_ms, timeout_ms, users);
	
	if (status >= 0) {
		as_node_put_connection(node, fd);
	}
	else {
		cf_close(fd);
	}
	as_node_release(node);
	return status;
}
Beispiel #2
0
static int
as_execute(aerospike* as, const as_policy_admin* policy, uint8_t* buffer, uint8_t* end)
{
	int timeout_ms = (policy)? policy->timeout : as->config.policies.admin.timeout;
	if (timeout_ms <= 0) {
		timeout_ms = DEFAULT_TIMEOUT;
	}
	uint64_t deadline_ms = cf_getms() + timeout_ms;
	as_node* node = as_node_get_random(as->cluster);
	
	if (! node) {
		return CITRUSLEAF_FAIL_CLIENT;
	}
	
	int fd;
	int status = as_node_get_connection(node, &fd);
	
	if (status) {
		as_node_release(node);
		return status;
	}

	if (as_send(fd, buffer, end, deadline_ms, timeout_ms)) {
		cf_close(fd);
		as_node_release(node);
		return CITRUSLEAF_FAIL_TIMEOUT;
	}
	
	if (cf_socket_read_timeout(fd, buffer, HEADER_SIZE, deadline_ms, timeout_ms)) {
		cf_close(fd);
		as_node_release(node);
		return CITRUSLEAF_FAIL_TIMEOUT;
	}
	
	as_node_put_connection(node, fd);
	as_node_release(node);
	return buffer[RESULT_CODE];
}
Beispiel #3
0
int
as_authenticate(int fd, const char* user, const char* credential, int timeout_ms)
{
	uint8_t buffer[STACK_BUF_SZ];
	uint8_t* p = buffer + 8;

	p = write_header(p, AUTHENTICATE, 2);
	p = write_field_string(p, USER, user);
	p = write_field_string(p, CREDENTIAL, credential);
	
	if (timeout_ms == 0) {
		timeout_ms = DEFAULT_TIMEOUT;
	}
	uint64_t deadline_ms = cf_getms() + timeout_ms;
	
	if (as_send(fd, buffer, p, deadline_ms, timeout_ms)) {
		return CITRUSLEAF_FAIL_TIMEOUT;
	}

	if (cf_socket_read_timeout(fd, buffer, HEADER_SIZE, deadline_ms, timeout_ms)) {
		return CITRUSLEAF_FAIL_TIMEOUT;
	}
	return buffer[RESULT_CODE];
}
Beispiel #4
0
int main (uint64_t speid, uint64_t argp)
{
  DPRINTF ("+(spu)main (%lld, %lld)\n", speid, argp);

  // -- reserve DMA tag ID for this SPU ---------------------------------------
  if ((tag = mfc_tag_reserve()) == MFC_TAG_INVALID)
    as_exitf ("ERROR - can't reserve a tag\n");
  DPRINTF (" [%lld] mfc_tag_reserve() = %d\n", speid, tag);

  // -- get CBE and problem information from system memory. -------------------
  DPRINTF (" [%lld] mfc_get (0x%x, 0x%llx, %d, %lu, 0, 0)\n", speid,
	   (unsigned) &sd, argp, sizeof(sd), (int) tag);
  mfc_getb (&sd, argp, sizeof(sd), tag, 0, 0);
  DPRINTF (" [%lld] waittag (%d)\n", speid, (int) tag);
  waittag (tag);

  sd.sd_ea = argp;		// save PPE address of sd block
  sd.value = sd.ad.sol;		// save PPE address of solution vector
  sd.size = ROUND_UP_128 (sd.ad.size_in_bytes);
  sd.ad.sol = memalign (16, sd.size); // allocate LS block
  if (sd.ad.sol == NULL) {
    fprintf (stderr,
	     "%s:%d: malloc failed in SPU %d\n", __FILE__, __LINE__, sd.num);
    exit(1);
  }


#if defined(DEBUG) && (DEBUG & 16)
  printf ("spe%d: &sd=0x%x, sd.value=0x%x, sd.ad.sol=0x%x\n",
	  sd.num, &sd, sd.value, sd.ad.sol);
#endif
  // -- *TBD* -- does sd.value need to be remapped (EA?)
  // -- get value vector from system memory into new LS block -----------------
  DPRINTF (" [%lld] mfc_get (0x%x, 0x%x, %d, %lu, 0, 0)\n", speid,
	   (unsigned) sd.ad.sol, (unsigned) sd.value,
	   sd.size, tag);
  

  // -- fix pb with DMA limitation (max = 16 KB) ------------------------------
  {
    int nbytes = sd.size;
    char *addr_ls = (char *) sd.ad.sol;
    char *addr_ea = (char *) sd.value;

    do {
      int sz = (nbytes < SPU_MAX_DMA)? nbytes: SPU_MAX_DMA;

      mfc_getb (addr_ls, (uint32_t) addr_ea, sz, tag, 0, 0);
      waittag (tag);

      nbytes -= sz;
      addr_ls += sz;
      addr_ea += sz;
    } while (nbytes > 0);
  }

#if defined(DEBUG) && (DEBUG & 8)
  printf (" [%lld] as_init dump:", speid);
  printf ("   sd.num = %d", sd.num);
  printf ("   sd.ctx = %d", (int) sd.ctx);
  printf ("   sd.thr = %d\n", (int) sd.thr);
#endif

#if defined(DEBUG) && (DEBUG & 2)
  if (sd.ad.do_not_init) {
    printf ("(SPU %d: received data (do_not_init=1):\n", sd.num);
    Ad_Display(sd.ad.sol, &sd.ad, NULL);
    printf(")\n");
  }
#endif
  
  Randomize_Seed (sd.ad.seed ^ sd.num);

  // -- call the benchmark-specific solver
  Solve (&sd.ad);
  
  // -- put the solution back on main memory for the PPE to read
  as_send ();

  //  printf ("SPU main returning\n");
  return 0;
}