Exemplo n.º 1
0
static char *
_ctl_get_connections (void *a)
{
	Npsrv *srv = (Npsrv *)a;
	Npconn *cc;
	char *s = NULL;
	int len = 0;

	xpthread_mutex_lock(&srv->lock);
	for (cc = srv->conns; cc != NULL; cc = cc->next) {
		xpthread_mutex_lock(&cc->lock);
		if (aspf (&s, &len, "%s %"PRIu64" %"PRIu64" %d\n",
				np_conn_get_client_id(cc),
				cc->reqs_in, cc->reqs_out,
				np_fidpool_count (cc->fidpool)) < 0) {
			np_uerror (ENOMEM);
			goto error_unlock;
		}
		xpthread_mutex_unlock(&cc->lock);
	}
	xpthread_mutex_unlock(&srv->lock);
	return s;
error_unlock:
	xpthread_mutex_unlock(&cc->lock);
	xpthread_mutex_unlock(&srv->lock);
	if (s)
		free(s);
	return NULL;
}
Exemplo n.º 2
0
Arquivo: user.c Projeto: blochl/diod
static char *
_get_usercache (char *name, void *a)
{
	Npsrv *srv = (Npsrv *)a;
	Npusercache *uc = srv->usercache;
	Npuser *u;
	time_t now = time (NULL);
	char *s = NULL;
	int len = 0;

	xpthread_mutex_lock (&uc->lock);
	_usercache_expire (srv);
	for (u = uc->users; u != NULL; u = u->next) {
		int ttl = uc->ttl - (now - u->t);

		if (aspf (&s, &len, "%s(%d,%d+%d) %d\n", u->uname,
			  u->uid, u->gid, u->nsg, u->uid ? ttl : 0) < 0) {
			np_uerror (ENOMEM);
			xpthread_mutex_unlock (&uc->lock);
			goto error;
		}
	}
	xpthread_mutex_unlock (&uc->lock);
	return s;
error:
	if (s)
		free (s);
	return NULL;
}
Exemplo n.º 3
0
static char *
_ctl_get_version (void *a)
{
	char *s = NULL;
	int len = 0;

	if (aspf (&s, &len, "%s\n", META_ALIAS) < 0)
                np_uerror (ENOMEM);
        return s;
}
Exemplo n.º 4
0
Arquivo: ioctx.c Projeto: chaos/diod
static int
_get_one_file (Path path, char *s, DynStr *ds)
{
    int unique, shared;

    xpthread_mutex_lock (&path->lock);
    _count_ioctx (path->ioctx, &shared, &unique);
    aspf (&ds->s, &ds->len, "%d %d %d %s\n", path->refcount, shared, unique, s);
    xpthread_mutex_unlock (&path->lock);
    return 0;
}
Exemplo n.º 5
0
char *
diod_get_exports (char *name, void *a)
{
    List exports = diod_conf_get_exports ();
    List seen = NULL;
    ListIterator itr = NULL;
    Export *x;
    int len = 0;
    char *s = NULL;
    char *ret = NULL;

    NP_ASSERT (exports != NULL);

    if (!(seen = list_create (NULL))) {
        np_uerror (ENOMEM);
        goto done;
    }
    if (!(itr = list_iterator_create (exports))) {
        np_uerror (ENOMEM);
        goto done;
    }
    while ((x = list_next (itr))) {
        if (list_find_first (seen, (ListFindF)_strmatch, x->path))
            continue;
        if (!list_append (seen, x->path)) {
            np_uerror (ENOMEM);
            goto done;
        }
        if (!(x->oflags & XFLAGS_SUPPRESS)) {
            if (aspf (&s, &len, "%s %s %s %s\n",
                      x->path,
                      x->opts ? x->opts : "-",
                      x->users ? x->users : "-",
                      x->hosts ? x->hosts : "-") < 0) { 
                np_uerror (ENOMEM);
                goto done;
            }
        }
    }
    if (diod_conf_get_exportall ())
        if (!_get_mounts (&s, &len, seen))
            goto done;
    ret = s;
done:
    if (itr)
        list_iterator_destroy (itr);
    if (seen)
        list_destroy (seen);
    return ret;
}
Exemplo n.º 6
0
static char *
_get_one_request (char **sp, int *lp, Npreq *req)
{
	char *uname = req->fid ? req->fid->user->uname : "-";
	char *aname = req->fid && req->fid->aname ? req->fid->aname : "-";
	char reqstr[40];

	np_snprintfcall (reqstr, sizeof (reqstr), req->tcall);
	if (aspf (sp, lp, "%-10.10s %-10.10s %-10.10s %s...\n",
		 			np_conn_get_client_id (req->conn),
					aname, uname, reqstr) < 0) {
		np_uerror (ENOMEM);
		return NULL;
	}
	return *sp;
}
Exemplo n.º 7
0
static char *
_get_mounts (char **sp, int *lp, List seen)
{
    List exports = diod_conf_get_mounts ();
    ListIterator itr = NULL;
    Export *x;
    char *ret = NULL;

    if (!exports) {
        np_uerror (ENOMEM);
        goto done;
    }
    if (!(itr = list_iterator_create (exports))) {
        np_uerror (ENOMEM);
        goto done;
    }
    while ((x = list_next (itr))) {
        if (list_find_first (seen, (ListFindF)_strmatch, x->path))
            continue;
        if (!list_append (seen, x->path)) {
            np_uerror (ENOMEM);
            goto done;
        }
        if (aspf (sp, lp, "%s %s %s %s\n",
                  x->path,
                  x->opts ? x->opts : "-",
                  x->users ? x->users : "-",
                  x->hosts ? x->hosts : "-") < 0) { 
            np_uerror (ENOMEM);
            goto done;
        }
    }
    ret = *sp;
done:
    if (itr)
        list_iterator_destroy (itr);
    if (exports)
        list_destroy (exports);
    return ret;
}
Exemplo n.º 8
0
Arquivo: npstring.c Projeto: 8l/diod
int
np_encode_tpools_str (char **s, int *len, Npstats *stats)
{
	return aspf (s, len, "%s %d %d " \
		"%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" " \
		"%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" " \
		"%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" " \
		"%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" " \
		"%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" " \
		"%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" " \
		"%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" " \
		"%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" " \
		"%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" " \
		"\n",
			stats->name, stats->numreqs, stats->numfids,
			stats->rbytes, stats->wbytes,
			stats->nreqs[P9_TSTATFS],
			stats->nreqs[P9_TLOPEN],
			stats->nreqs[P9_TLCREATE],
			stats->nreqs[P9_TSYMLINK],
			stats->nreqs[P9_TMKNOD],
			stats->nreqs[P9_TRENAME],
			stats->nreqs[P9_TREADLINK],
			stats->nreqs[P9_TGETATTR],
			stats->nreqs[P9_TSETATTR],
			stats->nreqs[P9_TXATTRWALK],
			stats->nreqs[P9_TXATTRCREATE],
			stats->nreqs[P9_TREADDIR],
			stats->nreqs[P9_TFSYNC],
			stats->nreqs[P9_TLOCK],
			stats->nreqs[P9_TGETLOCK],
			stats->nreqs[P9_TLINK],
			stats->nreqs[P9_TMKDIR],
			stats->nreqs[P9_TVERSION],
			stats->nreqs[P9_TAUTH],
			stats->nreqs[P9_TATTACH],
			stats->nreqs[P9_TFLUSH],
			stats->nreqs[P9_TWALK],
			stats->nreqs[P9_TREAD],
			stats->nreqs[P9_TWRITE],
			stats->nreqs[P9_TCLUNK],
			stats->nreqs[P9_TREMOVE],
			stats->rcount[0],
			stats->rcount[1],
			stats->rcount[2],
			stats->rcount[3],
			stats->rcount[4],
			stats->rcount[5],
			stats->rcount[6],
			stats->rcount[7],
			stats->rcount[8],
			stats->rcount[9],
			stats->rcount[10],
			stats->rcount[11],
			stats->wcount[0],
			stats->wcount[1],
			stats->wcount[2],
			stats->wcount[3],
			stats->wcount[4],
			stats->wcount[5],
			stats->wcount[6],
			stats->wcount[7],
			stats->wcount[8],
			stats->wcount[9],
			stats->wcount[10],
			stats->wcount[11]);
}