lkml.org 
[lkml]   [2010]   [Sep]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH 4/8] Add mutex for adding/removing memory blocks
    Add a new mutex for use in adding and removing of memory blocks.  This
    is needed to avoid any race conditions in which the same memory block could
    be added and removed at the same time.

    Signed-off-by: Nathan Fontenot <nfont@austin.ibm.com>

    ---
    drivers/base/memory.c | 7 +++++++
    1 file changed, 7 insertions(+)

    Index: linux-next/drivers/base/memory.c
    ===================================================================
    --- linux-next.orig/drivers/base/memory.c 2010-09-21 12:36:45.000000000 -0500
    +++ linux-next/drivers/base/memory.c 2010-09-21 12:37:03.000000000 -0500
    @@ -27,6 +27,8 @@
    #include <asm/atomic.h>
    #include <asm/uaccess.h>

    +static DEFINE_MUTEX(mem_sysfs_mutex);
    +
    #define MEMORY_CLASS_NAME "memory"

    static struct sysdev_class memory_sysdev_class = {
    @@ -485,6 +487,8 @@ static int add_memory_block(int nid, str
    if (!mem)
    return -ENOMEM;

    + mutex_lock(&mem_sysfs_mutex);
    +
    mem->start_phys_index = __section_nr(section);
    mem->state = state;
    atomic_inc(&mem->section_count);
    @@ -508,6 +512,7 @@ static int add_memory_block(int nid, str
    ret = register_mem_sect_under_node(mem, nid);
    }

    + mutex_unlock(&mem_sysfs_mutex);
    return ret;
    }

    @@ -516,6 +521,7 @@ int remove_memory_block(unsigned long no
    {
    struct memory_block *mem;

    + mutex_lock(&mem_sysfs_mutex);
    mem = find_memory_block(section);

    if (atomic_dec_and_test(&mem->section_count)) {
    @@ -528,6 +534,7 @@ int remove_memory_block(unsigned long no
    unregister_memory(mem, section);
    }

    + mutex_unlock(&mem_sysfs_mutex);
    return 0;
    }



    \
     
     \ /
      Last update: 2010-09-22 16:35    [W:0.024 / U:0.056 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site