Ejemplo n.º 1
0
libvchan_t *libvchan_server_init(int domain, int port, size_t read_min, size_t write_min) {
    char xs_path[255];
    libvchan_t *ctrl;

    ctrl = malloc(sizeof(*ctrl));
    if (!ctrl)
        return NULL;

    snprintf(xs_path, sizeof(xs_path), "data/vchan/%d/%d", domain, port);
    ctrl->xenvchan = libxenvchan_server_init(NULL, domain, xs_path, read_min, write_min);
    if (!ctrl->xenvchan) {
        free(ctrl);
        return NULL;
    }
    ctrl->xs_path = strdup(xs_path);
    ctrl->xenvchan->blocking = 1;
    ctrl->remote_domain = domain;
    ctrl->xc_handle = xc_interface_open(NULL, NULL, 0);
    if (!ctrl->xc_handle) {
        /* error already logged by xc_interface_open */
        libxenvchan_close(ctrl->xenvchan);
        free(ctrl);
        return NULL;
    }
    return ctrl;
}
Ejemplo n.º 2
0
/**
	Listens for connections and writes everything to /dev/null
*/
int main(int argc, char **argv)
{
	int my_domid = -1;
	int remote_domid = -1;
	char path[128];
	struct libxenvchan *ctrl = 0;
	if (argc < 4)
		usage(argv);

	bufsize = atoi(argv[1]);
	my_domid = atoi(argv[2]);
	buf = (char*)malloc(bufsize);
	if (!buf) {
		perror("malloc");
		exit(1);
	}
	remote_domid = atoi(argv[3]);
	sprintf(path, "/local/domain/%d/data/%d/0", my_domid, my_domid);
	fprintf(stderr, "Path: %s\n", path);

	ctrl = libxenvchan_server_init(NULL, remote_domid, path, 1024, 1024);
	if (!ctrl) {
		perror("libxenvchan_*_init");
		exit(1);
	}
	ctrl->blocking = 1;

	reader(ctrl);
	libxenvchan_close(ctrl);
	return 0;
}
Ejemplo n.º 3
0
/** Read the domainID of the subExp1 from the mgrExp1 over the
 * vChan.
 * This routine will block until the domainID is retrieved from 
 * the mgr.
 * return - the domainID. On any failure exit(1) is called.
 **/
int readSubExp1DomainID( xentoollog_logger * xc_logger, struct libxenvchan * ctrl) {
  char buf[DOMAIN_ID_CHAR_LEN + 1];
  int size = DOMAIN_ID_CHAR_LEN;
  char * invalidChar;
  int domainID;

  // Read the subExp1 domain ID from mgrExp1 vchan client.
  // The domainID has to be right justified for the following error
  // checking to work. So the domainID number must be preceeded with
  // white space or '0's.
  size = libxenvchan_recv(ctrl, buf, size);

  // Was there a system error?
  if (size < 0) {
    // There was a significant error. Abort.
    fprintf(stderr, "libxenvchan_read return=%d.\n", size);
    perror("readSubDomain: read failed for mgrExp1.");
    libxenvchan_close(ctrl);
    exit(1);
  }

  // Did we get all of the characters of the domainID number string?
  if (size != DOMAIN_ID_CHAR_LEN) {
    fprintf(stderr, "readSubDomain: We expected to read %d characters for the"
	    "subExp1 domain ID but got %d from mgrExp1\n",
	    DOMAIN_ID_CHAR_LEN, size);
    libxenvchan_close(ctrl);
    exit(1);
  }

  buf[DOMAIN_ID_CHAR_LEN] = 0; // put null at end of string so we have a valid C string.
  // Convert the string to an integer.
  domainID = strtol(buf, &invalidChar, 10);

  if ( *invalidChar != '\0' ) {
    fprintf(stderr, "readSubDomain: There was an invalid character in the domainID. The invalid portion of the domainID is '%s'.\n", invalidChar);
    libxenvchan_close(ctrl);
    exit(1);
    
  }

  return domainID;
}
Ejemplo n.º 4
0
Archivo: init.c Proyecto: Fantu/Xen
struct libxenvchan *libxenvchan_server_init(xentoollog_logger *logger, int domain, const char* xs_path, size_t left_min, size_t right_min)
{
	struct libxenvchan *ctrl;
	int ring_ref;
	if (left_min > MAX_RING_SIZE || right_min > MAX_RING_SIZE)
		return 0;

	ctrl = malloc(sizeof(*ctrl));
	if (!ctrl)
		return 0;

	ctrl->ring = NULL;
	ctrl->event = NULL;
	ctrl->is_server = 1;
	ctrl->server_persist = 0;

	ctrl->read.order = min_order(left_min);
	ctrl->write.order = min_order(right_min);

	// if we can avoid allocating extra pages by using in-page rings, do so
	if (left_min <= MAX_SMALL_RING && right_min <= MAX_LARGE_RING) {
		ctrl->read.order = SMALL_RING_SHIFT;
		ctrl->write.order = LARGE_RING_SHIFT;
	} else if (left_min <= MAX_LARGE_RING && right_min <= MAX_SMALL_RING) {
		ctrl->read.order = LARGE_RING_SHIFT;
		ctrl->write.order = SMALL_RING_SHIFT;
	} else if (left_min <= MAX_LARGE_RING) {
		ctrl->read.order = LARGE_RING_SHIFT;
	} else if (right_min <= MAX_LARGE_RING) {
		ctrl->write.order = LARGE_RING_SHIFT;
	}

	ctrl->gntshr = xc_gntshr_open(logger, 0);
	if (!ctrl->gntshr)
		goto out;

	if (init_evt_srv(ctrl, domain, logger))
		goto out;
	ring_ref = init_gnt_srv(ctrl, domain);
	if (ring_ref < 0)
		goto out;
	if (init_xs_srv(ctrl, domain, xs_path, ring_ref))
		goto out;
	return ctrl;
out:
	libxenvchan_close(ctrl);
	return 0;
}
Ejemplo n.º 5
0
void libvchan_close(libvchan_t *ctrl) {
    struct xs_handle *xs;

    libxenvchan_close(ctrl->xenvchan);
    if (ctrl->xs_path) {
        /* remove xenstore entry in case of no client connected */
        xs = xs_open(0);
        if (xs) {
            /* if xenstore connection failed just do not remove entries, but do
             * not abort whole function, especially still free the memory
             */
            xs_rm(xs, 0, ctrl->xs_path);
            xs_close(xs);
        }
        free(ctrl->xs_path);
    }
    free(ctrl);
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
  struct libxenvchan *chan = 0;
  int selfId; // domainID of this node;
  int otherId;
  int client= 0;
  xentoollog_logger_stdiostream * xc_logger;

  xc_logger = createDebugLogger();

  selfId =getDomId();
  fprintf(stdout,"Client: Domain Id: %d\n", selfId);

  if(argc != 3){
   fprintf(stderr,"Error: Usage ./Client [server-0, client-1] [other domId]\n");
   exit(1);
  }  

  sscanf(argv[1],"%d",&client);
  sscanf(argv[2],"%d",&otherId);

  if (!client){
     chan = vchan_server_init((xentoollog_logger *) xc_logger,otherId);
  }else{
     chan = vchan_client_init((xentoollog_logger *)xc_logger, otherId);
  }
   
  if (!client){
    sendForever(chan);

  }else{
    receiveForever(chan);
  } 
    
  
 

  libxenvchan_close(chan);


  return 0;
}
Ejemplo n.º 7
0
void reader(struct libxenvchan *ctrl)
{
	uint64_t nbytes = 0;
	int size;
	time_t start;
	time_t end;
	double nsecs;
	for (;;) {
		size = libxenvchan_read(ctrl, buf, bufsize);
		if (nbytes == 0)
			start = time(NULL);
/*		fprintf(stderr, "# %d\n", size); */
		if (size < 0) {
			end = time(NULL);
			nsecs = difftime(end, start);
			fprintf(stderr, "%Ld bytes in %.1f seconds\n", nbytes, nsecs);
			fprintf(stderr, "%d MiB/sec\n", (int) ( (double)(nbytes / (1024 * 1024)) /nsecs ));
			perror("read vchan");
			libxenvchan_close(ctrl);
			exit(1);
		}
		nbytes += size;
	}
}
Ejemplo n.º 8
0
Archivo: init.c Proyecto: Fantu/Xen
struct libxenvchan *libxenvchan_client_init(xentoollog_logger *logger, int domain, const char* xs_path)
{
	struct libxenvchan *ctrl = malloc(sizeof(struct libxenvchan));
	struct xs_handle *xs = NULL;
	char buf[64];
	char *ref;
	int ring_ref;
	unsigned int len;

	if (!ctrl)
		return 0;
	ctrl->ring = NULL;
	ctrl->event = NULL;
	ctrl->gnttab = NULL;
	ctrl->write.order = ctrl->read.order = 0;
	ctrl->is_server = 0;

	xs = xs_daemon_open();
	if (!xs)
		xs = xs_domain_open();
	if (!xs)
		goto fail;

// find xenstore entry
	snprintf(buf, sizeof buf, "%s/ring-ref", xs_path);
	ref = xs_read(xs, 0, buf, &len);
	if (!ref)
		goto fail;
	ring_ref = atoi(ref);
	free(ref);
	if (!ring_ref)
		goto fail;
	snprintf(buf, sizeof buf, "%s/event-channel", xs_path);
	ref = xs_read(xs, 0, buf, &len);
	if (!ref)
		goto fail;
	ctrl->event_port = atoi(ref);
	free(ref);
	if (!ctrl->event_port)
		goto fail;

	ctrl->gnttab = xc_gnttab_open(logger, 0);
	if (!ctrl->gnttab)
		goto fail;

// set up event channel
	if (init_evt_cli(ctrl, domain, logger))
		goto fail;

// set up shared page(s)
	if (init_gnt_cli(ctrl, domain, ring_ref))
		goto fail;

	ctrl->ring->cli_live = 1;
	ctrl->ring->srv_notify = VCHAN_NOTIFY_WRITE;

 out:
	if (xs)
		xs_daemon_close(xs);
	return ctrl;
 fail:
	libxenvchan_close(ctrl);
	ctrl = NULL;
	goto out;
}