当前位置: 首页>>代码示例>>C++>>正文


C++ LIBCFS_ALLOC函数代码示例

本文整理汇总了C++中LIBCFS_ALLOC函数的典型用法代码示例。如果您正苦于以下问题:C++ LIBCFS_ALLOC函数的具体用法?C++ LIBCFS_ALLOC怎么用?C++ LIBCFS_ALLOC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LIBCFS_ALLOC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: num_parse

/**
 * Parses \<numaddr_range\> token of the syntax.
 *
 * \retval 1 if \a str parses to \<number\> | \<expr_list\>
 * \retval 0 otherwise
 */
static int
num_parse(char *str, int len,
          cfs_list_t *list, unsigned min, unsigned max)
{
    __u32 num;
    struct lstr src;
    struct numaddr_range *numaddr;

    src.ls_str = str;
    src.ls_len = len;

    LIBCFS_ALLOC(numaddr, sizeof(struct numaddr_range));
    if (numaddr == NULL)
        return 0;
    cfs_list_add_tail(&numaddr->nar_link, list);
    CFS_INIT_LIST_HEAD(&numaddr->nar_range_exprs);

    if (libcfs_str2num_check(src.ls_str, src.ls_len, &num, min, max)) {
        /* <number> */
        struct range_expr *expr;

        LIBCFS_ALLOC(expr, sizeof(struct range_expr));
        if (expr == NULL)
            return 0;

        expr->re_lo = expr->re_hi = num;
        expr->re_stride = 1;
        cfs_list_add_tail(&expr->re_link, &numaddr->nar_range_exprs);
        return 1;
    }

    return parse_expr_list(&src, &numaddr->nar_range_exprs, min, max);
}
开发者ID:raghavyadav01,项目名称:lustre,代码行数:39,代码来源:nidstrings.c

示例2: lst_batch_add_ioctl

int
lst_batch_add_ioctl(lstio_batch_add_args_t *args)
{
        int             rc;
        char           *name;

        if (args->lstio_bat_key != console_session.ses_key)
                return -EACCES;

        if (args->lstio_bat_namep == NULL ||
            args->lstio_bat_nmlen <= 0 ||
            args->lstio_bat_nmlen > LST_NAME_SIZE)
                return -EINVAL;

        LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
        if (name == NULL)
                return -ENOMEM;

        if (cfs_copy_from_user(name,
                               args->lstio_bat_namep,
                               args->lstio_bat_nmlen)) {
                LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
                return -EFAULT;
        }

        name[args->lstio_bat_nmlen] = 0;

        rc = lstcon_batch_add(name);

        LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);

        return rc;
}
开发者ID:DCteam,项目名称:lustre,代码行数:33,代码来源:conctl.c

示例3: lnet_selftest_init

static int
lnet_selftest_init(void)
{
	int nscheds;
	int rc;
	int i;

	rc = cfs_wi_sched_create("lst_s", lnet_cpt_table(), CFS_CPT_ANY,
				 1, &lst_sched_serial);
	if (rc != 0) {
		CERROR("Failed to create serial WI scheduler for LST\n");
		return rc;
	}
	lst_init_step = LST_INIT_WI_SERIAL;

	nscheds = cfs_cpt_number(lnet_cpt_table());
	LIBCFS_ALLOC(lst_sched_test, sizeof(lst_sched_test[0]) * nscheds);
	if (lst_sched_test == NULL)
		goto error;

	lst_init_step = LST_INIT_WI_TEST;
	for (i = 0; i < nscheds; i++) {
		int nthrs = cfs_cpt_weight(lnet_cpt_table(), i);

		/* reserve at least one CPU for LND */
		nthrs = max(nthrs - 1, 1);
		rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
					 nthrs, &lst_sched_test[i]);
		if (rc != 0) {
			CERROR("Failed to create CPT affinity WI scheduler %d for LST\n",
			       i);
			goto error;
		}
	}

	rc = srpc_startup();
	if (rc != 0) {
		CERROR("LST can't startup rpc\n");
		goto error;
	}
	lst_init_step = LST_INIT_RPC;

	rc = sfw_startup();
	if (rc != 0) {
		CERROR("LST can't startup framework\n");
		goto error;
	}
	lst_init_step = LST_INIT_FW;

	rc = lstcon_console_init();
	if (rc != 0) {
		CERROR("LST can't startup console\n");
		goto error;
	}
	lst_init_step = LST_INIT_CONSOLE;
	return 0;
error:
	lnet_selftest_fini();
	return rc;
}
开发者ID:Chong-Li,项目名称:cse522,代码行数:60,代码来源:module.c

示例4: lst_batch_run_ioctl

static int
lst_batch_run_ioctl(lstio_batch_run_args_t *args)
{
	int rc;
	char *name;

	if (args->lstio_bat_key != console_session.ses_key)
		return -EACCES;

	if (!args->lstio_bat_namep ||
	    args->lstio_bat_nmlen <= 0 ||
	    args->lstio_bat_nmlen > LST_NAME_SIZE)
		return -EINVAL;

	LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
	if (!name)
		return -ENOMEM;

	if (copy_from_user(name, args->lstio_bat_namep,
			   args->lstio_bat_nmlen)) {
		LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
		return -EFAULT;
	}

	name[args->lstio_bat_nmlen] = 0;

	rc = lstcon_batch_run(name, args->lstio_bat_timeout,
			      args->lstio_bat_resultp);

	LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);

	return rc;
}
开发者ID:513855417,项目名称:linux,代码行数:33,代码来源:conctl.c

示例5: usocklnd_handle_zc_req

/* Handle incoming ZC request from sender.
 * NB: it's called only from read_handler, so we're sure that
 * the conn cannot become zombie in the middle of processing */
int
usocklnd_handle_zc_req(usock_peer_t *peer, __u64 cookie)
{
        usock_conn_t   *conn;
        usock_zc_ack_t *zc_ack;
        int             type;
        int             rc;
        int             dummy;

        LIBCFS_ALLOC (zc_ack, sizeof(*zc_ack));
        if (zc_ack == NULL)
                return -ENOMEM;
        zc_ack->zc_cookie = cookie;

        /* Let's assume that CONTROL is the best type for zcack,
         * but userspace clients don't use typed connections */
        if (the_lnet.ln_pid & LNET_PID_USERFLAG)
                type = SOCKLND_CONN_ANY;
        else
                type = SOCKLND_CONN_CONTROL;

        rc = usocklnd_find_or_create_conn(peer, type, &conn, NULL, zc_ack,
                                          &dummy);
        if (rc != 0) {
                LIBCFS_FREE (zc_ack, sizeof(*zc_ack));
                return rc;
        }
        usocklnd_conn_decref(conn);

        return 0;
}
开发者ID:Lezval,项目名称:lustre,代码行数:34,代码来源:handlers.c

示例6: lst_group_del_ioctl

static int
lst_group_del_ioctl(lstio_group_del_args_t *args)
{
	int rc;
	char *name;

	if (args->lstio_grp_key != console_session.ses_key)
		return -EACCES;

	if (!args->lstio_grp_namep ||
	    args->lstio_grp_nmlen <= 0 ||
	    args->lstio_grp_nmlen > LST_NAME_SIZE)
		return -EINVAL;

	LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
	if (!name)
		return -ENOMEM;

	if (copy_from_user(name, args->lstio_grp_namep,
			   args->lstio_grp_nmlen)) {
		LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
		return -EFAULT;
	}

	name[args->lstio_grp_nmlen] = 0;

	rc = lstcon_group_del(name);

	LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);

	return rc;
}
开发者ID:513855417,项目名称:linux,代码行数:32,代码来源:conctl.c

示例7: cfs_wi_startup

int
cfs_wi_startup (void)
{
        int i;
        int n;
        int rc;

        cfs_wi_data.wi_nthreads = 0;
        cfs_wi_data.wi_nsched   = CFS_WI_NSCHED;
        LIBCFS_ALLOC(cfs_wi_data.wi_scheds,
                     cfs_wi_data.wi_nsched * sizeof(cfs_wi_sched_t));
        if (cfs_wi_data.wi_scheds == NULL)
                return -ENOMEM;

        cfs_spin_lock_init(&cfs_wi_data.wi_glock);
        for (i = 0; i < cfs_wi_data.wi_nsched; i++)
                cfs_wi_sched_init(&cfs_wi_data.wi_scheds[i]);

#ifdef __KERNEL__
        n = cfs_num_online_cpus();
        for (i = 0; i <= n; i++) {
                rc = cfs_wi_start_thread(cfs_wi_scheduler,
                                         (void *)(long_ptr_t)(i == n ? -1 : i));
                if (rc != 0) {
                        CERROR ("Can't spawn workitem scheduler: %d\n", rc);
                        cfs_wi_shutdown();
                        return rc;
                }
        }
#else
        n = rc = 0;
#endif

        return 0;
}
开发者ID:DCteam,项目名称:lustre,代码行数:35,代码来源:workitem.c

示例8: lst_group_update_ioctl

static int
lst_group_update_ioctl(lstio_group_update_args_t *args)
{
	int     rc;
	char   *name;

	if (args->lstio_grp_key != console_session.ses_key)
		return -EACCES;

	if (args->lstio_grp_resultp == NULL ||
	    args->lstio_grp_namep == NULL ||
	    args->lstio_grp_nmlen <= 0 ||
	    args->lstio_grp_nmlen > LST_NAME_SIZE)
		return -EINVAL;

	LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
	if (name == NULL)
		return -ENOMEM;

	if (copy_from_user(name,
			   args->lstio_grp_namep,
			   args->lstio_grp_nmlen)) {
		LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
		return -EFAULT;
	}

	name[args->lstio_grp_nmlen] = 0;

	switch (args->lstio_grp_opc) {
	case LST_GROUP_CLEAN:
		rc = lstcon_group_clean(name, args->lstio_grp_args);
		break;

	case LST_GROUP_REFRESH:
		rc = lstcon_group_refresh(name, args->lstio_grp_resultp);
		break;

	case LST_GROUP_RMND:
		if (args->lstio_grp_count  <= 0 ||
		    args->lstio_grp_idsp == NULL) {
			rc = -EINVAL;
			break;
		}
		rc = lstcon_nodes_remove(name, args->lstio_grp_count,
					 args->lstio_grp_idsp,
					 args->lstio_grp_resultp);
		break;

	default:
		rc = -EINVAL;
		break;
	}

	LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);

	return rc;
}
开发者ID:a2hojsjsjs,项目名称:linux,代码行数:57,代码来源:conctl.c

示例9: LNetEQAlloc

int
LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback,
            lnet_handle_eq_t *handle)
{
        lnet_eq_t     *eq;

        LASSERT (the_lnet.ln_init);
        LASSERT (the_lnet.ln_refcount > 0);

        /* We need count to be a power of 2 so that when eq_{enq,deq}_seq
         * overflow, they don't skip entries, so the queue has the same
         * apparant capacity at all times */

        if (count != LOWEST_BIT_SET(count)) {   /* not a power of 2 already */
                do {                    /* knock off all but the top bit... */
                        count &= ~LOWEST_BIT_SET (count);
                } while (count != LOWEST_BIT_SET(count));

                count <<= 1;                             /* ...and round up */
        }

        if (count == 0)        /* catch bad parameter / overflow on roundup */
                return (-EINVAL);

        eq = lnet_eq_alloc();
        if (eq == NULL)
                return (-ENOMEM);

        LIBCFS_ALLOC(eq->eq_events, count * sizeof(lnet_event_t));
        if (eq->eq_events == NULL) {
                LNET_LOCK();
                lnet_eq_free (eq);
                LNET_UNLOCK();

                return -ENOMEM;
        }

        /* NB this resets all event sequence numbers to 0, to be earlier
         * than eq_deq_seq */
        memset(eq->eq_events, 0, count * sizeof(lnet_event_t));

        eq->eq_deq_seq = 1;
        eq->eq_enq_seq = 1;
        eq->eq_size = count;
        eq->eq_refcount = 0;
        eq->eq_callback = callback;

        LNET_LOCK();

        lnet_initialise_handle (&eq->eq_lh, LNET_COOKIE_TYPE_EQ);
        list_add (&eq->eq_list, &the_lnet.ln_active_eqs);

        LNET_UNLOCK();

        lnet_eq2handle(handle, eq);
        return (0);
}
开发者ID:pscedu,项目名称:slash2-stable,代码行数:57,代码来源:lib-eq.c

示例10: lwt_init

int
lwt_init ()
{
	int     i;
        int     j;

        for (i = 0; i < cfs_num_online_cpus(); i++)
                if (lwt_cpus[i].lwtc_current_page != NULL)
                        return (-EALREADY);

        LASSERT (!lwt_enabled);

	/* NULL pointers, zero scalars */
	memset (lwt_cpus, 0, sizeof (lwt_cpus));
	lwt_pages_per_cpu =
		LWT_MEMORY / (cfs_num_online_cpus() * PAGE_CACHE_SIZE);

	for (i = 0; i < cfs_num_online_cpus(); i++)
		for (j = 0; j < lwt_pages_per_cpu; j++) {
			struct page *page = alloc_page(GFP_KERNEL);
			lwt_page_t  *lwtp;

			if (page == NULL) {
				CERROR ("Can't allocate page\n");
                                lwt_fini ();
				return (-ENOMEM);
			}

                        LIBCFS_ALLOC(lwtp, sizeof (*lwtp));
			if (lwtp == NULL) {
				CERROR ("Can't allocate lwtp\n");
                                __free_page(page);
				lwt_fini ();
				return (-ENOMEM);
			}

                        lwtp->lwtp_page = page;
                        lwtp->lwtp_events = page_address(page);
			memset(lwtp->lwtp_events, 0, PAGE_CACHE_SIZE);

			if (j == 0) {
				CFS_INIT_LIST_HEAD (&lwtp->lwtp_list);
				lwt_cpus[i].lwtc_current_page = lwtp;
			} else {
				cfs_list_add (&lwtp->lwtp_list,
				    &lwt_cpus[i].lwtc_current_page->lwtp_list);
			}
                }

        lwt_enabled = 1;
        cfs_mb();

        LWT_EVENT(0,0,0,0);

        return (0);
}
开发者ID:girishshilamkar,项目名称:lustre-release,代码行数:56,代码来源:lwt.c

示例11: lx_new

struct lnet_xport *
lx_new(struct lnet_xport_int *lxi)
{
	struct lnet_xport *lx;

	LIBCFS_ALLOC(lx, sizeof(*lx));
	if (lx)
		lx->lx_tab = lxi;
	return (lx);
}
开发者ID:pscedu,项目名称:pfl,代码行数:10,代码来源:user-tcpip.c

示例12: libcfs_socketpair

int
libcfs_socketpair(cfs_socket_t **sockp)
{
        int rc, i, fdp[2];

        LIBCFS_ALLOC(sockp[0], sizeof(cfs_socket_t));
        if (sockp[0] == NULL) {
                CERROR ("Can't alloc memory for cfs_socket_t (1)\n");
                return -ENOMEM;
        }

        LIBCFS_ALLOC(sockp[1], sizeof(cfs_socket_t));
        if (sockp[1] == NULL) {
                CERROR ("Can't alloc memory for cfs_socket_t (2)\n");
                LIBCFS_FREE(sockp[0], sizeof(cfs_socket_t));
                return -ENOMEM;
        }

        rc = socketpair(AF_UNIX, SOCK_STREAM, 0, fdp);
        if (rc != 0) {
                rc = -errno;
                CERROR ("Cannot create socket pair\n");
                LIBCFS_FREE(sockp[0], sizeof(cfs_socket_t));
                LIBCFS_FREE(sockp[1], sizeof(cfs_socket_t));
                return rc;
        }

        sockp[0]->s_fd = fdp[0];
        sockp[1]->s_fd = fdp[1];

        for (i = 0; i < 2; i++) {
                rc = libcfs_fcntl_nonblock(sockp[i]);
                if (rc) {
                        libcfs_sock_release(sockp[0]);
                        libcfs_sock_release(sockp[1]);
                        return rc;
                }
        }

        return 0;
}
开发者ID:Lezval,项目名称:lustre,代码行数:41,代码来源:user-tcpip.c

示例13: add_nidrange

/**
 * Finds or creates struct nidrange.
 *
 * Checks if \a src is a valid network name, looks for corresponding
 * nidrange on the ist of nidranges (\a nidlist), creates new struct
 * nidrange if it is not found.
 *
 * \retval pointer to struct nidrange matching network specified via \a src
 * \retval NULL if \a src does not match any network
 */
static struct nidrange *
add_nidrange(const struct lstr *src,
             cfs_list_t *nidlist)
{
    struct netstrfns *nf;
    struct nidrange *nr;
    int endlen;
    unsigned netnum;

    if (src->ls_len >= LNET_NIDSTR_SIZE)
        return NULL;

    nf = libcfs_namenum2netstrfns(src->ls_str);
    if (nf == NULL)
        return NULL;
    endlen = src->ls_len - strlen(nf->nf_name);
    if (endlen == 0)
        /* network name only, e.g. "elan" or "tcp" */
        netnum = 0;
    else {
        /* e.g. "elan25" or "tcp23", refuse to parse if
         * network name is not appended with decimal or
         * hexadecimal number */
        if (!libcfs_str2num_check(src->ls_str + strlen(nf->nf_name),
                                  endlen, &netnum,
                                  0, MAX_NUMERIC_VALUE))
            return NULL;
    }

    cfs_list_for_each_entry(nr, nidlist, nr_link) {
        if (nr->nr_netstrfns != nf)
            continue;
        if (nr->nr_netnum != netnum)
            continue;
        return nr;
    }

    LIBCFS_ALLOC(nr, sizeof(struct nidrange));
    if (nr == NULL)
        return NULL;
    cfs_list_add_tail(&nr->nr_link, nidlist);
    CFS_INIT_LIST_HEAD(&nr->nr_addrranges);
    nr->nr_netstrfns = nf;
    nr->nr_all = 0;
    nr->nr_netnum = netnum;

    return nr;
}
开发者ID:raghavyadav01,项目名称:lustre,代码行数:58,代码来源:nidstrings.c

示例14: libcfs_psdev_open

/* called when opening /dev/device */
static int libcfs_psdev_open(unsigned long flags, void *args)
{
	struct libcfs_device_userstate *ldu;
	ENTRY;

	try_module_get(THIS_MODULE);

	LIBCFS_ALLOC(ldu, sizeof(*ldu));
	if (ldu != NULL) {
		ldu->ldu_memhog_pages = 0;
		ldu->ldu_memhog_root_page = NULL;
	}
	*(struct libcfs_device_userstate **)args = ldu;

	RETURN(0);
}
开发者ID:walgenbach,项目名称:lustre-release,代码行数:17,代码来源:module.c

示例15: parse_range_expr

/**
 * Parses \<range_expr\> token of the syntax.
 *
 * \retval pointer to allocated range_expr and initialized
 * range_expr::re_lo, range_expr::re_hi and range_expr:re_stride if \a
 `* src parses to
 * \<number\> |
 * \<number\> '-' \<number\> |
 * \<number\> '-' \<number\> '/' \<number\>
 * \retval NULL othersize
 */
static struct range_expr *
parse_range_expr(struct lstr *src, unsigned min, unsigned max)
{
    struct lstr tok;
    struct range_expr *expr;

    LIBCFS_ALLOC(expr, sizeof(struct range_expr));
    if (expr == NULL)
        return NULL;

    if (libcfs_str2num_check(src->ls_str, src->ls_len, &expr->re_lo,
                             min, max)) {
        /* <number> is parsed */
        expr->re_hi = expr->re_lo;
        expr->re_stride = 1;
        return expr;
    }

    if (!gettok(src, '-', &tok))
        goto failed;
    if (!libcfs_str2num_check(tok.ls_str, tok.ls_len, &expr->re_lo,
                              min, max))
        goto failed;
    /* <number> - */
    if (libcfs_str2num_check(src->ls_str, src->ls_len, &expr->re_hi,
                             min, max)) {
        /* <number> - <number> is parsed */
        expr->re_stride = 1;
        return expr;
    }

    /* go to check <number> '-' <number> '/' <number> */
    if (gettok(src, '/', &tok)) {
        if (!libcfs_str2num_check(tok.ls_str, tok.ls_len,
                                  &expr->re_hi, min, max))
            goto failed;
        /* <number> - <number> / ... */
        if (libcfs_str2num_check(src->ls_str, src->ls_len,
                                 &expr->re_stride, min, max))
            /* <number> - <number> / <number> is parsed */
            return expr;
    }

failed:
    LIBCFS_FREE(expr, sizeof(struct range_expr));
    return NULL;
}
开发者ID:raghavyadav01,项目名称:lustre,代码行数:58,代码来源:nidstrings.c


注:本文中的LIBCFS_ALLOC函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。