- Extend interface of ng_getqblk(), so that malloc wait flags are

specified by caller.
- Change ng_send_item() interface - use 'flags' argument instead of
  boolean 'queue'.
- Extend ng_send_fn(), ng_package_data() and ng_package_msg()
  interface - add possibility to pass flags. Rename ng_send_fn() to
  ng_send_fn1(). Create macro for ng_send_fn().
- Update all macros, that use ng_package_data() and ng_package_msg().

Reviewed by:	julian
This commit is contained in:
Gleb Smirnoff 2005-05-16 17:07:03 +00:00
parent 02fa4220cd
commit 42282202ee
2 changed files with 34 additions and 36 deletions

View File

@ -836,7 +836,7 @@ _ngi_hook(item_p item, char *file, int line)
#define NG_SEND_DATA_ONLY(error, hook, m) \
do { \
item_p _item; \
if ((_item = ng_package_data((m), NULL))) { \
if ((_item = ng_package_data((m), NG_NOFLAGS))) { \
NG_FWD_ITEM_HOOK(error, _item, hook); \
} else { \
(error) = ENOMEM; \
@ -869,7 +869,7 @@ _ngi_hook(item_p item, char *file, int line)
#define NG_SEND_MSG_HOOK(error, here, msg, hook, retaddr) \
do { \
item_p _item; \
if ((_item = ng_package_msg(msg)) == NULL) { \
if ((_item = ng_package_msg(msg, NG_NOFLAGS)) == NULL) {\
(msg) = NULL; \
(error) = ENOMEM; \
break; \
@ -885,7 +885,7 @@ _ngi_hook(item_p item, char *file, int line)
#define NG_SEND_MSG_PATH(error, here, msg, path, retaddr) \
do { \
item_p _item; \
if ((_item = ng_package_msg(msg)) == NULL) { \
if ((_item = ng_package_msg(msg, NG_NOFLAGS)) == NULL) {\
(msg) = NULL; \
(error) = ENOMEM; \
break; \
@ -901,7 +901,7 @@ _ngi_hook(item_p item, char *file, int line)
#define NG_SEND_MSG_ID(error, here, msg, ID, retaddr) \
do { \
item_p _item; \
if ((_item = ng_package_msg(msg)) == NULL) { \
if ((_item = ng_package_msg(msg, NG_NOFLAGS)) == NULL) {\
(msg) = NULL; \
(error) = ENOMEM; \
break; \
@ -1063,23 +1063,28 @@ int ng_make_node_common(struct ng_type *typep, node_p *nodep);
int ng_name_node(node_p node, const char *name);
int ng_newtype(struct ng_type *tp);
ng_ID_t ng_node2ID(node_p node);
item_p ng_package_data(struct mbuf *m, void *dummy);
item_p ng_package_msg(struct ng_mesg *msg);
item_p ng_package_data(struct mbuf *m, int flags);
item_p ng_package_msg(struct ng_mesg *msg, int flags);
item_p ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg);
void ng_replace_retaddr(node_p here, item_p item, ng_ID_t retaddr);
int ng_rmhook_self(hook_p hook); /* if a node wants to kill a hook */
int ng_rmnode_self(node_p here); /* if a node wants to suicide */
int ng_rmtype(struct ng_type *tp);
int ng_snd_item(item_p item, int queue);
int ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn,
void *arg1, int arg2);
int ng_queue_fn(node_p node, hook_p hook, ng_item_fn *fn,
void *arg1, int arg2);
int ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn,
void *arg1, int arg2, int flags);
#define ng_send_fn(node, hook, fn, arg1, arg2) \
ng_send_fn1(node, hook, fn, arg1, arg2, NG_NOFLAGS)
int ng_uncallout(struct callout *c, node_p node);
int ng_callout(struct callout *c, node_p node, hook_p hook, int ticks,
ng_item_fn *fn, void * arg1, int arg2);
#define ng_callout_init(c) callout_init(c, CALLOUT_MPSAFE)
/* Flags for netgraph functions. */
#define NG_NOFLAGS 0x00000000 /* no special options */
#define NG_QUEUE 0x00000001 /* enqueue item, don't dispatch */
#define NG_WAITOK 0x00000002 /* use M_WAITOK, etc. */
/*
* prototypes the user should DEFINITELY not use directly
*/

View File

@ -2095,11 +2095,11 @@ ng_flush_input_queue(struct ng_queue * ngq)
*/
int
ng_snd_item(item_p item, int queue)
ng_snd_item(item_p item, int flags)
{
hook_p hook = NGI_HOOK(item);
node_p node = NGI_NODE(item);
int rw;
int queue, rw;
int error = 0, ierror;
item_p oitem;
struct ng_queue * ngq = &node->nd_input_queue;
@ -2108,6 +2108,8 @@ ng_snd_item(item_p item, int queue)
_ngi_check(item, __FILE__, __LINE__);
#endif
queue = (flags & NG_QUEUE) ? 1 : 0;
if (item == NULL) {
TRAP_ERROR();
return (EINVAL); /* failed to get queue element */
@ -2902,11 +2904,14 @@ static int allocated; /* number of items malloc'd */
* an interrupt.
*/
static __inline item_p
ng_getqblk(void)
ng_getqblk(int flags)
{
item_p item = NULL;
int wait;
item = uma_zalloc(ng_qzone, M_NOWAIT | M_ZERO);
wait = (flags & NG_WAITOK) ? M_WAITOK : M_NOWAIT;
item = uma_zalloc(ng_qzone, wait | M_ZERO);
#ifdef NETGRAPH_DEBUG
if (item) {
@ -3331,11 +3336,11 @@ ng_setisr(node_p node)
* This is possibly in the critical path for new data.
*/
item_p
ng_package_data(struct mbuf *m, void *dummy)
ng_package_data(struct mbuf *m, int flags)
{
item_p item;
if ((item = ng_getqblk()) == NULL) {
if ((item = ng_getqblk(flags)) == NULL) {
NG_FREE_M(m);
return (NULL);
}
@ -3354,11 +3359,11 @@ ng_package_data(struct mbuf *m, void *dummy)
* (or equivalent)
*/
item_p
ng_package_msg(struct ng_mesg *msg)
ng_package_msg(struct ng_mesg *msg, int flags)
{
item_p item;
if ((item = ng_getqblk()) == NULL) {
if ((item = ng_getqblk(flags)) == NULL) {
NG_FREE_MSG(msg);
return (NULL);
}
@ -3494,7 +3499,7 @@ ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg)
* If there is a HOOK argument, then use that in preference
* to the address.
*/
if ((item = ng_getqblk()) == NULL) {
if ((item = ng_getqblk(NG_NOFLAGS)) == NULL) {
NG_FREE_MSG(msg);
return (NULL);
}
@ -3513,13 +3518,13 @@ ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg)
return (item);
}
static __inline int
int
ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2,
int queue)
int flags)
{
item_p item;
if ((item = ng_getqblk()) == NULL) {
if ((item = ng_getqblk(flags)) == NULL) {
return (ENOMEM);
}
item->el_flags = NGQF_FN | NGQF_WRITER;
@ -3532,19 +3537,7 @@ ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2,
NGI_FN(item) = fn;
NGI_ARG1(item) = arg1;
NGI_ARG2(item) = arg2;
return(ng_snd_item(item, queue));
}
int
ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2)
{
return (ng_send_fn1(node, hook, fn, arg1, arg2, 0));
}
int
ng_queue_fn(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2)
{
return (ng_send_fn1(node, hook, fn, arg1, arg2, 1));
return(ng_snd_item(item, flags));
}
/*
@ -3565,7 +3558,7 @@ ng_callout(struct callout *c, node_p node, hook_p hook, int ticks,
{
item_p item;
if ((item = ng_getqblk()) == NULL)
if ((item = ng_getqblk(NG_NOFLAGS)) == NULL)
return (ENOMEM);
item->el_flags = NGQF_FN | NGQF_WRITER;