netfilter: nf_conntrack: pass template to l4proto ->error() handler
[safe/jmp/linux-2.6] / include / linux / nodemask.h
index ccee962..454997c 100644 (file)
@@ -14,6 +14,8 @@
  * bitmap_scnlistprintf() and bitmap_parselist(), also in bitmap.c.
  * For details of node_remap(), see bitmap_bitremap in lib/bitmap.c.
  * For details of nodes_remap(), see bitmap_remap in lib/bitmap.c.
+ * For details of nodes_onto(), see bitmap_onto in lib/bitmap.c.
+ * For details of nodes_fold(), see bitmap_fold in lib/bitmap.c.
  *
  * The available nodemask operations are:
  *
@@ -55,7 +57,9 @@
  * int nodelist_scnprintf(buf, len, mask) Format nodemask as list for printing
  * int nodelist_parse(buf, map)                Parse ascii string as nodelist
  * int node_remap(oldbit, old, new)    newbit = map(old, new)(oldbit)
- * int nodes_remap(dst, src, old, new) *dst = map(old, new)(dst)
+ * void nodes_remap(dst, src, old, new)        *dst = map(old, new)(src)
+ * void nodes_onto(dst, orig, relmap)  *dst = orig relative to relmap
+ * void nodes_fold(dst, orig, sz)      dst bits = orig bits mod sz
  *
  * for_each_node_mask(node, mask)      for-loop node over mask
  *
  *    to generate slightly worse code.  So use a simple one-line #define
  *    for node_isset(), instead of wrapping an inline inside a macro, the
  *    way we do the other calls.
+ *
+ * NODEMASK_SCRATCH
+ * When doing above logical AND, OR, XOR, Remap operations the callers tend to
+ * need temporary nodemask_t's on the stack. But if NODES_SHIFT is large,
+ * nodemask_t's consume too much stack space.  NODEMASK_SCRATCH is a helper
+ * for such situations. See below and CPUMASK_ALLOC also.
  */
 
 #include <linux/kernel.h>
@@ -235,14 +245,19 @@ static inline int __next_node(int n, const nodemask_t *srcp)
        return min_t(int,MAX_NUMNODES,find_next_bit(srcp->bits, MAX_NUMNODES, n+1));
 }
 
+static inline void init_nodemask_of_node(nodemask_t *mask, int node)
+{
+       nodes_clear(*mask);
+       node_set(node, *mask);
+}
+
 #define nodemask_of_node(node)                                         \
 ({                                                                     \
        typeof(_unused_nodemask_arg_) m;                                \
        if (sizeof(m) == sizeof(unsigned long)) {                       \
-               m.bits[0] = 1UL<<(node);                                \
+               m.bits[0] = 1UL << (node);                              \
        } else {                                                        \
-               nodes_clear(m);                                         \
-               node_set((node), m);                                    \
+               init_nodemask_of_node(&m, (node));                      \
        }                                                               \
        m;                                                              \
 })
@@ -326,6 +341,22 @@ static inline void __nodes_remap(nodemask_t *dstp, const nodemask_t *srcp,
        bitmap_remap(dstp->bits, srcp->bits, oldp->bits, newp->bits, nbits);
 }
 
+#define nodes_onto(dst, orig, relmap) \
+               __nodes_onto(&(dst), &(orig), &(relmap), MAX_NUMNODES)
+static inline void __nodes_onto(nodemask_t *dstp, const nodemask_t *origp,
+               const nodemask_t *relmapp, int nbits)
+{
+       bitmap_onto(dstp->bits, origp->bits, relmapp->bits, nbits);
+}
+
+#define nodes_fold(dst, orig, sz) \
+               __nodes_fold(&(dst), &(orig), sz, MAX_NUMNODES)
+static inline void __nodes_fold(nodemask_t *dstp, const nodemask_t *origp,
+               int sz, int nbits)
+{
+       bitmap_fold(dstp->bits, origp->bits, sz, nbits);
+}
+
 #if MAX_NUMNODES > 1
 #define for_each_node_mask(node, mask)                 \
        for ((node) = first_node(mask);                 \
@@ -349,6 +380,7 @@ enum node_states {
 #else
        N_HIGH_MEMORY = N_NORMAL_MEMORY,
 #endif
+       N_CPU,          /* The node has one or more cpus */
        NR_NODE_STATES
 };
 
@@ -387,6 +419,19 @@ static inline int num_node_state(enum node_states state)
 #define next_online_node(nid)  next_node((nid), node_states[N_ONLINE])
 
 extern int nr_node_ids;
+extern int nr_online_nodes;
+
+static inline void node_set_online(int nid)
+{
+       node_set_state(nid, N_ONLINE);
+       nr_online_nodes = num_node_state(N_ONLINE);
+}
+
+static inline void node_set_offline(int nid)
+{
+       node_clear_state(nid, N_ONLINE);
+       nr_online_nodes = num_node_state(N_ONLINE);
+}
 #else
 
 static inline int node_state(int node, enum node_states state)
@@ -413,7 +458,10 @@ static inline int num_node_state(enum node_states state)
 #define first_online_node      0
 #define next_online_node(nid)  (MAX_NUMNODES)
 #define nr_node_ids            1
+#define nr_online_nodes                1
 
+#define node_set_online(node)     node_set_state((node), N_ONLINE)
+#define node_set_offline(node)    node_clear_state((node), N_ONLINE)
 #endif
 
 #define node_online_map        node_states[N_ONLINE]
@@ -433,10 +481,33 @@ static inline int num_node_state(enum node_states state)
 #define node_online(node)      node_state((node), N_ONLINE)
 #define node_possible(node)    node_state((node), N_POSSIBLE)
 
-#define node_set_online(node)     node_set_state((node), N_ONLINE)
-#define node_set_offline(node)    node_clear_state((node), N_ONLINE)
-
 #define for_each_node(node)       for_each_node_state(node, N_POSSIBLE)
 #define for_each_online_node(node) for_each_node_state(node, N_ONLINE)
 
+/*
+ * For nodemask scrach area.
+ * NODEMASK_ALLOC(type, name) allocates an object with a specified type and
+ * name.
+ */
+#if NODES_SHIFT > 8 /* nodemask_t > 256 bytes */
+#define NODEMASK_ALLOC(type, name, gfp_flags)  \
+                       type *name = kmalloc(sizeof(*name), gfp_flags)
+#define NODEMASK_FREE(m)                       kfree(m)
+#else
+#define NODEMASK_ALLOC(type, name, gfp_flags)  type _name, *name = &_name
+#define NODEMASK_FREE(m)                       do {} while (0)
+#endif
+
+/* A example struture for using NODEMASK_ALLOC, used in mempolicy. */
+struct nodemask_scratch {
+       nodemask_t      mask1;
+       nodemask_t      mask2;
+};
+
+#define NODEMASK_SCRATCH(x)                                            \
+                       NODEMASK_ALLOC(struct nodemask_scratch, x,      \
+                                       GFP_KERNEL | __GFP_NORETRY)
+#define NODEMASK_SCRATCH_FREE(x)       NODEMASK_FREE(x)
+
+
 #endif /* __LINUX_NODEMASK_H */