mem-hotplug: introduce MMOP_OFFLINE to replace the hard coding -1
authorTang Chen <tangchen@cn.fujitsu.com>
Wed, 6 Aug 2014 23:05:13 +0000 (16:05 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 7 Aug 2014 01:01:16 +0000 (18:01 -0700)
In store_mem_state(), we have:

  ...
  334         else if (!strncmp(buf, "offline", min_t(int, count, 7)))
  335                 online_type = -1;
  ...
  355         case -1:
  356                 ret = device_offline(&mem->dev);
  357                 break;
  ...

Here, "offline" is hard coded as -1.

This patch does the following renaming:

 ONLINE_KEEP     ->  MMOP_ONLINE_KEEP
 ONLINE_KERNEL   ->  MMOP_ONLINE_KERNEL
 ONLINE_MOVABLE  ->  MMOP_ONLINE_MOVABLE

and introduces MMOP_OFFLINE = -1 to avoid hard coding.

Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
Cc: Hu Tao <hutao@cn.fujitsu.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Cc: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/base/memory.c
include/linux/memory_hotplug.h
mm/memory_hotplug.c

index c6707dfb5284884e94b17460caaf695712b4b549..7c60ed27e711840108db1767c20e0666d9f9c496 100644 (file)
@@ -284,7 +284,7 @@ static int memory_subsys_online(struct device *dev)
         * attribute and need to set the online_type.
         */
        if (mem->online_type < 0)
-               mem->online_type = ONLINE_KEEP;
+               mem->online_type = MMOP_ONLINE_KEEP;
 
        ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
 
@@ -316,22 +316,22 @@ store_mem_state(struct device *dev,
                return ret;
 
        if (sysfs_streq(buf, "online_kernel"))
-               online_type = ONLINE_KERNEL;
+               online_type = MMOP_ONLINE_KERNEL;
        else if (sysfs_streq(buf, "online_movable"))
-               online_type = ONLINE_MOVABLE;
+               online_type = MMOP_ONLINE_MOVABLE;
        else if (sysfs_streq(buf, "online"))
-               online_type = ONLINE_KEEP;
+               online_type = MMOP_ONLINE_KEEP;
        else if (sysfs_streq(buf, "offline"))
-               online_type = -1;
+               online_type = MMOP_OFFLINE;
        else {
                ret = -EINVAL;
                goto err;
        }
 
        switch (online_type) {
-       case ONLINE_KERNEL:
-       case ONLINE_MOVABLE:
-       case ONLINE_KEEP:
+       case MMOP_ONLINE_KERNEL:
+       case MMOP_ONLINE_MOVABLE:
+       case MMOP_ONLINE_KEEP:
                /*
                 * mem->online_type is not protected so there can be a
                 * race here.  However, when racing online, the first
@@ -342,7 +342,7 @@ store_mem_state(struct device *dev,
                mem->online_type = online_type;
                ret = device_online(&mem->dev);
                break;
-       case -1:
+       case MMOP_OFFLINE:
                ret = device_offline(&mem->dev);
                break;
        default:
index 010d125bffbf5f41658878fe0dc6a25f062d1660..79dd9eca054fb720789f1c51fbf8c4a8532e5b2e 100644 (file)
@@ -26,11 +26,12 @@ enum {
        MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO,
 };
 
-/* Types for control the zone type of onlined memory */
+/* Types for control the zone type of onlined and offlined memory */
 enum {
-       ONLINE_KEEP,
-       ONLINE_KERNEL,
-       ONLINE_MOVABLE,
+       MMOP_OFFLINE = -1,
+       MMOP_ONLINE_KEEP,
+       MMOP_ONLINE_KERNEL,
+       MMOP_ONLINE_MOVABLE,
 };
 
 /*
index 3557e8c9e8de0cf3613eacf8d291879dc0807e96..a3797d3fd8a4b6ca3793c6e231222f08b884f428 100644 (file)
@@ -977,15 +977,18 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ
        zone = page_zone(pfn_to_page(pfn));
 
        ret = -EINVAL;
-       if ((zone_idx(zone) > ZONE_NORMAL || online_type == ONLINE_MOVABLE) &&
+       if ((zone_idx(zone) > ZONE_NORMAL ||
+           online_type == MMOP_ONLINE_MOVABLE) &&
            !can_online_high_movable(zone))
                goto out;
 
-       if (online_type == ONLINE_KERNEL && zone_idx(zone) == ZONE_MOVABLE) {
+       if (online_type == MMOP_ONLINE_KERNEL &&
+           zone_idx(zone) == ZONE_MOVABLE) {
                if (move_pfn_range_left(zone - 1, zone, pfn, pfn + nr_pages))
                        goto out;
        }
-       if (online_type == ONLINE_MOVABLE && zone_idx(zone) == ZONE_MOVABLE - 1) {
+       if (online_type == MMOP_ONLINE_MOVABLE &&
+           zone_idx(zone) == ZONE_MOVABLE - 1) {
                if (move_pfn_range_right(zone, zone + 1, pfn, pfn + nr_pages))
                        goto out;
        }
This page took 0.029707 seconds and 5 git commands to generate.