Exemplo n.º 1
0
/*
 * Logging system call.
 *
 * Write a message to the logging device.  The log function is
 * available only when kernel is built with debug option.
 */
int
sys_log(const char *str)
{
#ifdef DEBUG
    static char buf[SYSLOG_SIZE + MAXTHNAME];
    char *p;
    size_t len;
    static int eol;
    int err = 0;

    sched_lock();		/* as buf is static */
    if (eol && cur_thread->name[0] != '\0') {
        len = strlcpy(buf, cur_thread->name, MAXTHNAME);
        p = &buf[len];
        *p++ = ':';
    } else
        p = buf;

    if (umem_strnlen(str, SYSLOG_SIZE, &len))
        err = DERR(EFAULT);
    else if (len >= SYSLOG_SIZE)
        err = DERR(EINVAL);
    else if (umem_copyin(str, p, len + 1))
        err = DERR(EFAULT);
    else {
        eol = (p[len-1] == '\n');
        printf(buf);
    }
    sched_unlock();
    return err;
#else
    return ENOSYS;
#endif
}
Exemplo n.º 2
0
Arquivo: cond.c Projeto: AndrewD/prex
/*
 * Wait on a condition.
 *
 * If the thread receives any exception while waiting CV, this
 * routine returns immediately with EINTR in order to invoke
 * exception handler. However, an application assumes this call
 * does NOT return with an error. So, the stub routine in a
 * system call library must call cond_wait() again if it gets
 * EINTR as error.
 */
int
cond_wait(cond_t *cond, mutex_t *mtx, u_long timeout)
{
	cond_t c;
	int err, rc;

	if (umem_copyin(cond, &c, sizeof(cond)))
		return DERR(EFAULT);

	sched_lock();
	if (c == COND_INITIALIZER) {
		if ((err = cond_init(cond))) {
			sched_unlock();
			return err;
		}
		umem_copyin(cond, &c, sizeof(cond));
	} else {
		if (!cond_valid(c)) {
			sched_unlock();
			return DERR(EINVAL);
		}
	}
	ASSERT(c->signal >= 0 && c->signal <= c->wait);
	c->wait++;
	if ((err = mutex_unlock_count(mtx))) {
		if (err < 0) {
			/* mutex was recursively locked - would deadlock */
			mutex_lock(mtx);
			err = DERR(EDEADLK);
		}
		sched_unlock();
		return err;
	}

	rc = sched_tsleep(&c->event, timeout);
	err = mutex_lock(mtx);
	c->wait--;
	if (!err) {
		if (c->signal)
			c->signal--; /* > 1 thread may be waiting */
		else {
			switch (rc) {
			case SLP_TIMEOUT:
				err = ETIMEDOUT;
				break;

			case SLP_INTR:
				err = EINTR;
				break;

			default:		/* unexpected */
				err = DERR(EINVAL);
			}
		}
	}
	sched_unlock();
	return err;
}
Exemplo n.º 3
0
Arquivo: cond.c Projeto: AndrewD/prex
/*
 * cond_copyin - copy a condition variable from user space.
 *
 * It also checks if the passed CV is valid.
 */
static int
cond_copyin(cond_t *ucond, cond_t *kcond)
{
	cond_t c;

	if (umem_copyin(ucond, &c, sizeof(ucond)))
		return DERR(EFAULT);
	if (!cond_valid(c))
		return DERR(EINVAL);
	*kcond = c;
	return 0;
}
Exemplo n.º 4
0
/* Free an input */
static INLINE void free_input(input *inp) {
  ninputs--;
  switch(inp->type) {
  case NBIO_STR:
    DERR(fprintf(stderr, "Freeing string input 0x%x\n", (unsigned int)inp));
    free_string(inp->u.data);
    nstrings--;
    break;
#ifdef USE_MMAP
  case NBIO_MMAP:
    DERR(fprintf(stderr, "Freeing mmap input 0x%x\n", (unsigned int)inp));
    if(inp->u.mmap_storage->data != MAP_FAILED) {
      munmap(inp->u.mmap_storage->data, inp->u.mmap_storage->m_len);
      mmapped -= inp->u.mmap_storage->m_len;
    }
    push_int(0);    push_int(0);    push_int(0);
    apply_low(inp->u.mmap_storage->file, inp->set_nb_off, 3);
    apply_low(inp->u.mmap_storage->file, inp->set_b_off, 0);
    pop_n_elems(2);
    free_object(inp->u.mmap_storage->file);
    free(inp->u.mmap_storage);
    break;
#endif
  case NBIO_OBJ:
    push_int(0);    push_int(0);    push_int(0);
    apply_low(inp->u.file, inp->set_nb_off, 3);
    apply_low(inp->u.file, inp->set_b_off, 0);
    pop_n_elems(2);
    /* FALL THROUGH */
    
  case NBIO_BLOCK_OBJ:
    DERR(fprintf(stderr, "Freeing obj input 0x%x\n", (unsigned int)inp));
    free_object(inp->u.file);
    nobjects--;
    break;
    
  }
  if(THIS->last_input == inp)
    THIS->last_input = NULL;
  THIS->inputs = inp->next;
  if(!THIS->finished && THIS->inputs && THIS->inputs->type == NBIO_OBJ) {
    /* Aha! Set read callback here */
    DERR(fprintf(stderr, "Setting read/close callbacks for input 0x%x\n", (unsigned int)THIS->inputs));
    push_callback(input_read_cb_off);
    push_int(0);
    push_callback(input_close_cb_off);
    apply_low(THIS->inputs->u.file, THIS->inputs->set_nb_off, 3);
    THIS->inputs->mode = READING;    
  }
  free(inp);
}
Exemplo n.º 5
0
/*
 * Kernel debug service.
 */
int
sys_debug(int cmd, u_long arg)
{
#ifdef DEBUG
    int rc;

    switch (cmd) {
    case DCMD_DUMP:
        rc = debug_dump(arg);
        break;
    case DCMD_LOGSIZE:
        rc = LOGBUF_SIZE;
        break;
    case DCMD_GETLOG:
        rc = debug_getlog((void *)arg);
        break;
    default:
        rc = DERR(-EINVAL);
        break;
    }
    return rc;
#else
    return -ENOSYS;
#endif
}
Exemplo n.º 6
0
/* daemon wake up */
void
vntsd_daemon_wakeup(vntsd_t *vntsdp)
{

	vcc_response_t	inq_data;

	/* reason to wake up  */
	if (vntsd_vcc_ioctl(VCC_INQUIRY, 0, (void *)&inq_data) !=
	    VNTSD_SUCCESS) {
		vntsd_log(VNTSD_ERR_VCC_IOCTL, "vntsd_daemon_wakeup()");
		return;
	}

	D1(stderr, "t@%d vntsd_daemon_wakup:msg %d port %x\n", thr_self(),
	    inq_data.reason, inq_data.cons_no);

	switch (inq_data.reason) {

	case VCC_CONS_ADDED:
		do_add_cons(vntsdp, inq_data.cons_no);
		break;

	default:
		DERR(stderr, "t@%d daemon_wakeup:ioctl_unknown %d\n",
		    thr_self(), inq_data.reason);
		vntsd_log(VNTSD_ERR_UNKNOWN_CMD, "from vcc\n");
		break;
	}
}
Exemplo n.º 7
0
/*
 * vdds_create_new_node -- A common function to create NIU nexus/NIU node.
 */
static dev_info_t *
vdds_create_new_node(vdds_cb_arg_t *cbap, dev_info_t *pdip,
    int (*new_node_func)(dev_info_t *dip, void *arg, uint_t flags))
{
	devi_branch_t br;
	int rv;

	DBG1(NULL, "Called cookie=0x%lx", cbap->cookie);

	br.arg = (void *)cbap;
	br.type = DEVI_BRANCH_SID;
	br.create.sid_branch_create = new_node_func;
	br.devi_branch_callback = NULL;

	if (pdip == NULL) {
		pdip = ddi_root_node();
	}
	DBG1(NULL, "calling e_ddi_branch_create");
	if ((rv = e_ddi_branch_create(pdip, &br, NULL,
	    DEVI_BRANCH_CHILD | DEVI_BRANCH_CONFIGURE))) {
		DERR(NULL, "e_ddi_branch_create failed=%d", rv);
		return (NULL);
	}
	DBG1(NULL, "Returning(dip=0x%p", cbap->dip);
	return (cbap->dip);
}
static int als_read_lux(int *lux)
{
	int status = 0;
	int i = 0;
	D("enter %s \n", __func__);

	status = bh1721_chip_i2c_read_raw_lux(lux);
	if (status) {
		DERR("%s : REPORT_WORK error \n", __func__);
		return status;
	}

	D("%s raw lux value = %d\n", __func__, *lux);

#if defined (LED_LIGHT_REMOVAL)
		if(!the_data.blink_on)
			*lux -= the_data.led_value;
#endif
	D("%s raw lux value - led_value = %d\n", __func__, *lux);
	/* compensation in low luminance */
	if (*lux < 8)		/* X 1 */
		*lux *= 2;
	else if (*lux < 24) {	/* X 1.5 */
		*lux *= 3;
		*lux /= 2;
	}


	if(*lux < 0) {
		DERR("%s : lux is minus %d \n", __func__, *lux);
		*lux = 0;
	}

	*lux *= the_data.scail_m;
	if((*lux % the_data.scail_n) * 2 >= the_data.scail_n)
		i = 1;
	else
		i = 0;
	*lux =	*lux / the_data.scail_n + i;
	if((*lux % the_data.resol) * 2 >= the_data.resol)
		i=1;
	else
		i=0;
	*lux = *lux / the_data.resol + i;
	*lux *= the_data.resol;
	return status;
}
/* timer : first half work */
static void bh1721_poll_timer(unsigned long data)
{
	D("enter %s \n", __func__);
	if(!GET_STAT(IR)) {
		DERR("Enter %s during polling disabled\n", __func__);
		return;
	}
	schedule_work(&the_data.work);
}
Exemplo n.º 10
0
Arquivo: cond.c Projeto: AndrewD/prex
/*
 * Create and initialize a condition variable (CV).
 *
 * If an initialized condition variable is reinitialized,
 * undefined behavior results.
 */
int
cond_init(cond_t *cond)
{
	cond_t c;

	if ((c = kmem_alloc(sizeof(struct cond))) == NULL)
		return DERR(ENOMEM);

	event_init(&c->event, "condition");
	c->task = cur_task();
	c->magic = COND_MAGIC;
	c->wait = c->signal = 0;

	if (umem_copyout(&c, cond, sizeof(c))) {
		kmem_free(c);
		return DERR(EFAULT);
	}
	return 0;
}
Exemplo n.º 11
0
/* Our nb input close callback */
static void f__input_close_cb(INT32 args) {
  DERR(fprintf(stderr, "Input close callback.\n"));
  pop_n_elems(args);
  if(THIS->inputs) {
    free_input(THIS->inputs);
  }
  if(!THIS->buf_len && THIS->inputs == NULL) {
    finished();
  }
}
/* timer stop : timer unregister */
static void bh1721_poll_timer_stop(void)
{
	D("enter %s \n", __func__);
	if(!GET_STAT(IR)) {
		DERR("Enter %s during poll disabled\n", __func__);
		return;
	}
	del_timer_sync(&the_data.timer);
	flush_work(&the_data.work);
	CLR_STAT(IR);
}
/* timer start : timer register */
static void bh1721_poll_timer_start(void)
{
	D("enter %s \n", __func__);
	if(GET_STAT(IR)) {
		DERR("Enter %s during poll enabled\n", __func__);
		return;
	}
	SET_STAT(IR);
	setup_timer(&the_data.timer, bh1721_poll_timer,
						(unsigned long)&the_data);
	INIT_WORK(&the_data.work, bh1721_poll_timer_work);
	schedule_work(&the_data.work);
}
Exemplo n.º 14
0
static INLINE void set_outp_write_cb(output *outp) {
  /* Need to set_nonblocking again to trigger the write cb again.
   * FIXME: only call when there is more to write...
   */
  if(outp != NULL) {
    DERR(fprintf(stderr, "Setting output write callback.\n"));
    push_int(0);
    push_callback(output_write_cb_off);
    push_int(0);
    apply_low(outp->file, outp->set_nb_off, 3);
    pop_stack();
  }
}  
Exemplo n.º 15
0
/* Called when the sending is finished. Either due to broken connection
 * or no more data to send.
 */
static void finished(void)
{
  DERR(fprintf(stderr, "Done writing (%d sent)\n", (INT32)THIS->written));

  THIS->finished   = 1;
  while(THIS->inputs != NULL) {
    free_input(THIS->inputs);
  }

  if(THIS->outp != NULL) {
    free_output(THIS->outp);
    THIS->outp = NULL;
  }

  if(THIS->cb.type != T_INT)
  {
    DERR(fprintf(stderr, "Calling done callback\n"));
    push_svalue(&(THIS->args));
    apply_svalue(&(THIS->cb),1);
    pop_stack();
  }
}
Exemplo n.º 16
0
struct puffs_node *
perfuse_new_pn(struct puffs_usermount *pu, const char *name,
	struct puffs_node *parent)
{
	struct perfuse_state *ps = puffs_getspecific(pu);
	struct puffs_node *pn;
	struct perfuse_node_data *pnd;

	if ((pnd = malloc(sizeof(*pnd))) == NULL)
		DERR(EX_OSERR, "%s: malloc failed", __func__);

	if ((pn = puffs_pn_new(pu, pnd)) == NULL)
		DERR(EX_SOFTWARE, "%s: puffs_pn_new failed", __func__);

	(void)memset(pnd, 0, sizeof(*pnd));
	pnd->pnd_rfh = FUSE_UNKNOWN_FH;
	pnd->pnd_wfh = FUSE_UNKNOWN_FH;
	pnd->pnd_nodeid = PERFUSE_UNKNOWN_NODEID;
	if (parent != NULL) {
		pnd->pnd_parent_nodeid = PERFUSE_NODE_DATA(parent)->pnd_nodeid;
	} else {
		pnd->pnd_parent_nodeid = FUSE_ROOT_ID;
	}
	pnd->pnd_fuse_nlookup = 0;
	pnd->pnd_puffs_nlookup = 0;
	pnd->pnd_pn = (puffs_cookie_t)pn;
	if (strcmp(name, "..") != 0)
		(void)strlcpy(pnd->pnd_name, name, MAXPATHLEN);
	else
		pnd->pnd_name[0] = 0; /* anonymous for now */
	TAILQ_INIT(&pnd->pnd_pcq);

	puffs_pn_setpriv(pn, pnd);

	ps->ps_nodecount++;

	return pn;
}
Exemplo n.º 17
0
/*
 * vdds_release_range_prop -- cleanups an entry in the ranges property
 *	corresponding to a cookie.
 */
static void
vdds_release_range_prop(dev_info_t *nexus_dip, uint64_t cookie)
{
	vdds_ranges_t *prng;
	vdds_ranges_t *prp;
	int prnglen;
	int nrng;
	int rnum;
	boolean_t success = B_FALSE;
	int rv;

	if ((rv = ddi_getlongprop(DDI_DEV_T_ANY, nexus_dip, DDI_PROP_DONTPASS,
	    "ranges", (caddr_t)&prng, &prnglen)) != DDI_SUCCESS) {
		DERR(NULL,
		    "Failed to get nexus ranges property(dip=0x%p) rv=%d",
		    nexus_dip, rv);
		return;
	}
	nrng = prnglen/(sizeof (vdds_ranges_t));
	for (rnum = 0; rnum < nrng; rnum++) {
		prp = &prng[rnum];
		if (prp->child_hi == HVCOOKIE(cookie)) {
			prp->child_hi = 0;
			success = B_TRUE;
			break;
		}
	}
	if (success) {
		if (ndi_prop_update_int_array(DDI_DEV_T_NONE, nexus_dip,
		    "ranges", (int *)prng, (nrng * 6)) != DDI_SUCCESS) {
			DERR(NULL,
			    "Failed to update nexus ranges prop(dip=0x%p)",
			    nexus_dip);
		}
	}
}
Exemplo n.º 18
0
/* Free any allocated data in the struct */
static void free_nb_struct(struct object *obj) {
  DERR(fprintf(stderr, "Freeing storage.\n"));
  while(THIS->inputs != NULL) {
    free_input(THIS->inputs);
  }

  if(THIS->outp != NULL) {
    free_output(THIS->outp);
    THIS->outp = NULL;
  }
  free_data_buf();
  free_svalue(&THIS->args);
  free_svalue(&THIS->cb);
  THIS->cb.type = T_INT; 
  THIS->args.type = T_INT; 
}
static int bh1721_chip_i2c_write_cmd(char cmd)
{
	int status = 0;
	D("enter %s \n", __func__);
	status = i2c_master_send(the_data.client, &cmd, 1);
	if (status == 1) {
		status = 0;
	} else {
		DERR("%s wirte failed\n", __func__);
		status = -1;
	}
	if (cmd == I2C_PWON && status == 0)
		SET_STAT(CA);
	else if (cmd == I2C_PWDOWN && status == 0)
		CLR_STAT(CA);
	return status;
}
/* read data */
static int bh1721_chip_i2c_read_raw_lux(int *raw_lux)
{
	int status = 0;
	char buf[2];
	D("enter %s \n", __func__);
	status = i2c_master_recv(the_data.client, buf, 2);
	if(status == 2) {
		*raw_lux = (int)buf[0];
		*raw_lux <<= 8;
		*raw_lux += (int)buf[1];
		D("raw lux =  %d \n", *raw_lux);
		return 0;
	} else {
		DERR("%s read failed\n", __func__);
		return status;
	}
}
Exemplo n.º 21
0
/*
 * vntsd_que_pos() matches a handle and returns a handle located at "pos"
 * relative to the matched handle. pos supported are 1 or -1.
 */
void *
vntsd_que_pos(vntsd_que_t *que_hd, void *handle, int pos)
{
	vntsd_que_t *p = que_hd;

	assert((pos == 1) || (pos == -1));


	while (p != NULL) {
		if (p->handle == handle) {
			/* find match */
			if (pos == 1) {
				/* forward 1 */
				if (p->nextp != NULL) {
					return (p->nextp->handle);
				}

				/* last one go to first */
				return (que_hd->handle);

			} else {
				/* backward 1 */
				if (p->prevp != NULL) {
					return (p->prevp->handle);
				}

				/* first one, return last one */
				while (p->nextp != NULL) {
					p = p->nextp;
				}

				assert(p != NULL);
				assert(p->handle != NULL);
				return (p->handle);

			}
		}
		p = p->nextp;
	}

	DERR(stderr, "t@%d vntsd_que_pos can not find handle \n",
	    thr_self());

	return (NULL);
}
/* dvi gpio control */
static int dvi_high(int on)
{
	if (on != 0 && on != 1) {
		DERR("%s : on value : %dis not valid \n", __func__, on);
		return -1;
	}

	if(!GET_STAT(IR))
		msleep(2);

	if(on)
		SET_STAT(LG);
	else
		CLR_STAT(LG);

	gpio_set_value(DVI_GPIO_PIN, on);
	return 0;

}
Exemplo n.º 23
0
/* Set the output file (file object) */
static void f_output(INT32 args) {
  if(args) {
    if(ARG(1).type != T_OBJECT) {
      SIMPLE_BAD_ARG_ERROR("_Caudium.nbio()->output", 1, "object");
    } else {
      output *outp;
      if(THIS->outp != NULL) {
	free_output(THIS->outp);
	THIS->outp = NULL;
      }
      outp = malloc(sizeof(output));
      outp->file = ARG(1).u.object;
      outp->fd = fd_from_object(outp->file);

      outp->set_nb_off = find_identifier("set_nonblocking", outp->file->prog);
      outp->set_b_off  = find_identifier("set_blocking", outp->file->prog);
      outp->write_off  = find_identifier("write", outp->file->prog);

      if (outp->write_off < 0 || outp->set_nb_off < 0 || outp->set_b_off < 0) 
      {
	free(outp);
	Pike_error("_Caudium.nbio()->output: illegal file object%s%s%s\n",
		   ((outp->write_off < 0)?"; no write":""),
		   ((outp->set_nb_off < 0)?"; no set_nonblocking":""),
		   ((outp->set_b_off < 0)?"; no set_blocking":""));
      }

      DERR(fprintf(stderr, "New output (fd = %d)\n", outp->fd));
      outp->mode = ACTIVE;
      add_ref(outp->file);
      THIS->outp = outp;
      noutputs++;
      /* Set up the read callback. We don't need a close callback since
       * it never will be called w/o a read_callback (which we don't want one).
       */
      set_outp_write_cb(outp);
    }
  } else {
    SIMPLE_TOO_FEW_ARGS_ERROR("_Caudium.nbio()->output", 1);
  }
  pop_n_elems(args-1);
}
Exemplo n.º 24
0
Arquivo: cond.c Projeto: AndrewD/prex
/*
 * Destroy a condition variable.
 *
 * If there are any blocked thread waiting for the specified
 * CV, it returns EBUSY.
 */
int
cond_destroy(cond_t *cond)
{
	cond_t c;
	int err;

	sched_lock();
	if ((err = cond_copyin(cond, &c))) {
		sched_unlock();
		return err;
	}
	if (event_waiting(&c->event)) {
		sched_unlock();
		return DERR(EBUSY);
	}
	c->magic = 0;
	kmem_free(c);
	sched_unlock();
	return 0;
}
Exemplo n.º 25
0
/* Our nb input read callback */
static void f__input_read_cb(INT32 args)
{
  int avail_size = 0, len;
  struct pike_string *str;
  input *inp = THIS->inputs;
  if(inp == NULL) {
    Pike_error("Input read callback without inputs.");
  }    
  if(args != 2)
    Pike_error("Invalid number of arguments to read callback.");
  if(ARG(2).type != T_STRING) {
    SIMPLE_BAD_ARG_ERROR("_Caudium.nbio()->_input_read_cb", 2, "string");
  }
  str = ARG(2).u.string;
  len = str->len << str->size_shift;
  inp->pos += len;
  if(inp->len != -1 && inp->pos >= inp->len) {
    len -= inp->pos - inp->len; /* Don't "read" too much */
    DERR(fprintf(stderr, "Read all wanted input data.\n"));
    free_input(inp);
  }
  DERR(fprintf(stderr, "Input read callback (got %d bytes).\n", len));
  if(THIS->buf_size) {
    avail_size = THIS->buf_size - (THIS->buf_len + THIS->buf_pos);
  } 
  if(avail_size < len) {
    alloc_data_buf(THIS->buf_size + (len - avail_size));
  }
  DERR(fprintf(stderr, "Copying %d bytes to buf starting at 0x%x (pos %d).\n",
	       len, (int)(THIS->buf + THIS->buf_pos + THIS->buf_len), THIS->buf_pos + THIS->buf_len));
  memcpy(THIS->buf + THIS->buf_pos + THIS->buf_len, str->str, len);
  THIS->buf_len += len;
  if((THIS->buf_len + THIS->buf_pos) > READ_BUFFER_SIZE) {
    DERR(fprintf(stderr, "Read buffer full (%d bytes).\n", THIS->buf_size));
    push_int(0);   push_int(0);  push_int(0);
    apply_low(inp->u.file, inp->set_nb_off, 3);
    pop_stack();
    inp->mode = SLEEPING;
  }
  pop_n_elems(args);
  
  if(THIS->outp->mode == IDLE) {
    DERR(fprintf(stderr, "Waking up output.\n"));
    THIS->outp->mode = ACTIVE;
    f__output_write_cb(0);
  } else {
    DERR(fprintf(stderr, "Output is awake.\n"));
  }
}
Exemplo n.º 26
0
static INLINE int do_write(char *buf, int buf_len) {
  int fd, written = 0;
  fd = THIS->outp->fd;
 write_retry:
  if(fd != -1) {
    DERR(fprintf(stderr, "do_write() to real fd\n"));
    THREADS_ALLOW();
    written = fd_write(fd, buf, buf_len);
    THREADS_DISALLOW();  
  } else {
    DERR(fprintf(stderr, "do_write() to fake fd\n"));
    push_string(make_shared_binary_string(buf, buf_len));
    apply_low(THIS->outp->file, THIS->outp->write_off, 1);
    if(Pike_sp[-1].type != T_INT) {
      written = -1;
    } else {
      written = Pike_sp[-1].u.integer;
    }
    pop_stack();
  }

  if(written < 0)
  { 
    DERR(fprintf(stderr, "write returned -1...\n"));
    switch(errno)
    {      
    default:
      DERR(perror("Error while writing"));
      finished();
      return -1; /* -1 == write failed and that's it */
    case EINTR: /* interrupted by signal - try again */
      DERR(fprintf(stderr, "write -> EINTR = retry.\n"));
      goto write_retry;
    case EWOULDBLOCK:
      DERR(fprintf(stderr, "would block.\n"));
      return 0; /* Treat this as if we wrote no data */      
    }
  } else {
    DERR(fprintf(stderr, "Wrote %d bytes of %d\n", written, buf_len));
    THIS->written += written;
  }
  return written;
}
Exemplo n.º 27
0
/*
 * Use mac client for layer 2 switching .
 */
static void
vsw_switch_l2_frame_mac_client(vsw_t *vswp, mblk_t *mp, int caller,
    vsw_port_t *port, mac_resource_handle_t mrh)
{
	_NOTE(ARGUNUSED(mrh))

	mblk_t		*ret_m;

	/*
	 * This switching function is expected to be called by
	 * the ports or the interface only. The packets from
	 * physical interface already switched.
	 */
	ASSERT((caller == VSW_VNETPORT) || (caller == VSW_LOCALDEV));

	if ((ret_m = vsw_tx_msg(vswp, mp, caller, port)) != NULL) {
		DERR(vswp, "%s: drop mblks to "
		    "phys dev", __func__);
		freemsgchain(ret_m);
	}
}
Exemplo n.º 28
0
/*
 * vdds_destroy_niu_node -- Destroy the NIU node.
 */
int
vdds_destroy_niu_node(dev_info_t *niu_dip, uint64_t cookie)
{
	int rv;
	dev_info_t *fdip = NULL;
	dev_info_t *nexus_dip = ddi_get_parent(niu_dip);


	DBG1(NULL, "Called");
	ASSERT(nexus_dip != NULL);
	mutex_enter(&vdds_dev_lock);

	if (!e_ddi_branch_held(niu_dip))
		e_ddi_branch_hold(niu_dip);
	/*
	 * As we are destroying now, release the
	 * hold that was done in during the creation.
	 */
	ddi_release_devi(niu_dip);
	rv = e_ddi_branch_destroy(niu_dip, &fdip, 0);
	if (rv != 0) {
		DERR(NULL, "Failed to destroy niumx/network node dip=0x%p",
		    niu_dip);
		if (fdip != NULL) {
			ddi_release_devi(fdip);
		}
		rv = EBUSY;
		goto dest_exit;
	}
	/*
	 * Cleanup the parent's ranges property set
	 * for this Hybrid device.
	 */
	vdds_release_range_prop(nexus_dip, cookie);

dest_exit:
	mutex_exit(&vdds_dev_lock);
	DBG1(NULL, "returning rv=%d", rv);
	return (rv);
}
Exemplo n.º 29
0
/*
 * Setup the required switching mode.
 * Returns:
 *  0 on success.
 *  EAGAIN if retry is needed.
 *  1 on all other failures.
 */
int
vsw_setup_switching(vsw_t *vswp)
{
	int	rv = 1;

	D1(vswp, "%s: enter", __func__);

	/*
	 * Select best switching mode.
	 * This is done as this routine can be called from the timeout
	 * handler to retry setting up a specific mode. Currently only
	 * the function which sets up layer2/promisc mode returns EAGAIN
	 * if the underlying network device is not available yet, causing
	 * retries.
	 */
	if (vswp->smode & VSW_LAYER2) {
		rv = vsw_setup_layer2(vswp);
	} else if (vswp->smode & VSW_LAYER3) {
		rv = vsw_setup_layer3(vswp);
	} else {
		DERR(vswp, "unknown switch mode");
		rv = 1;
	}

	if (rv && (rv != EAGAIN)) {
		cmn_err(CE_WARN, "!vsw%d: Unable to setup specified "
		    "switching mode", vswp->instance);
	} else if (rv == 0) {
		(void) atomic_swap_32(&vswp->switching_setup_done, B_TRUE);
	}

	D2(vswp, "%s: Operating in mode %d", __func__,
	    vswp->smode);

	D1(vswp, "%s: exit", __func__);

	return (rv);
}
Exemplo n.º 30
0
void BaseClient::threadproc_activate(int index)
{
   if ( boost::get_system_time() < this->m_activate_stamp )
   {
      this->m_proxy_index = index; // For activation we do not seek randomness, so we pick the particular.
      std::string epz = this->remote_hostname() + ":" + mylib::to_string(this->remote_port()) + "(" + mylib::to_string(this->m_activate_port) + ")";
      try
      {
         DOUT("Activate: " << index << " starting");
         boost::asio::io_service io_service;
         boost::asio::io_service::work session_work(io_service);
         boost::asio::ip::tcp::socket socket(io_service);

         this->dolog("Activate Performing remote connection to: " + epz );
         boost::asio::sockect_connect(socket, io_service, this->remote_hostname(), this->m_activate_port);

         RemoteEndpoint &ep = this->m_proxy_endpoints[index];
         std::error_code err;
         this->dolog("Activate Attempting to perform certificate exchange with " + ep.m_name );
         this->m_activate_stamp = boost::get_system_time(); // Reset to current time to avoid double attempts.
         std::vector<std::string> certnames;
         certnames.push_back(ep.m_name);
         if (global.SetupCertificatesClient(socket, certnames.front()) &&
            !global.SetupCertificatesServer( socket, certnames).empty() )
         {
            this->dolog("Succeeded in exchanging certificates with " + certnames.front());
         }
         else
         {
            this->dolog("Failed to exchange certificate: " + err.message() );
         }
      }        
      catch(std::exception &exc)
      {
         DERR("Failed to connect for activation: " << epz << " " << exc.what());
      }
   }
}