Convert from a string to memory policy This conversion function can only be called in the context of a task. FIXME: if the contextualization would be done somwhere else then mpol_to_str would be more useful. Syntax of textual representation: default preferred= bind= interleave= Signed-off-by: Christoph Lameter Index: linux-2.6.13-rc6/include/linux/mempolicy.h =================================================================== --- linux-2.6.13-rc6.orig/include/linux/mempolicy.h 2005-08-15 10:48:52.000000000 -0700 +++ linux-2.6.13-rc6/include/linux/mempolicy.h 2005-08-15 10:48:56.000000000 -0700 @@ -155,6 +155,7 @@ extern void numa_policy_init(void); /* Conversion functions */ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol); +struct mempolicy *str_to_mpol(char *buffer); #else Index: linux-2.6.13-rc6/mm/mempolicy.c =================================================================== --- linux-2.6.13-rc6.orig/mm/mempolicy.c 2005-08-15 10:48:52.000000000 -0700 +++ linux-2.6.13-rc6/mm/mempolicy.c 2005-08-15 10:57:14.000000000 -0700 @@ -1288,3 +1288,38 @@ int mpol_to_str(char *buffer, int maxlen return p - buffer; } +/* + * Convert a representation of a memory policy from text + * form to binary. This can only be done from the tasks that + * is using the memory policy since the nodes used by a policy + * may be restricted by the cpuset. + * + * Returns either a memory policy or NULL for error. + */ +struct mempolicy *str_to_mpol(char *buffer) +{ + nodemask_t nodes; + int mode; + int l; + + for (mode = 0; mode <= MPOL_MAX; mode++) { + l = strlen(policy_types[mode]); + if (strnicmp(policy_types[mode], buffer, l) + && (mode == MPOL_DEFAULT || buffer[l] == '=')) + break; + } + + if (mode > MPOL_MAX) + return NULL; + + if (mode == MPOL_DEFAULT) + return &default_policy; + + if (nodelist_parse(buffer + l + 1, nodes) || nodes_empty(nodes)) + return NULL; + + if (!contextualize_policy(mode, &nodes)) + return NULL; + + return mpol_new(mode, &nodes); +}