[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1424959843-20409-7-git-send-email-sergey.senozhatsky@gmail.com>
Date: Thu, 26 Feb 2015 23:10:41 +0900
From: Sergey Senozhatsky <sergey.senozhatsky@...il.com>
To: Andrew Morton <akpm@...ux-foundation.org>,
Minchan Kim <minchan@...nel.org>
Cc: Jerome Marchand <jmarchan@...hat.com>,
Nitin Gupta <ngupta@...are.org>,
Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>,
linux-kernel@...r.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>
Subject: [PATCH 6/8] zram: allow automatic new zram device_id assignment
If no particular device_id was requested (passed -1 to zram_add()) during new zram
device creation, generate one automatically and return it back. So, schematically,
device creation can be done as:
dev_id = ioctl ZRAM_CTL_ADD -1
# dev_id == 1 or error code
init device zram1
dev_id = ioctl ZRAM_CTL_ADD -1
# dev_id == 2 or error code
init device zram2
...
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@...il.com>
---
drivers/block/zram/zram_drv.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 0154c2d4..5804dda 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1090,8 +1090,15 @@ static int zram_add(int device_id)
if (!zram)
return ret;
- ret = idr_alloc(&zram_index_idr, zram, device_id,
+ if (device_id < 0) {
+ /* generate new device_id */
+ ret = idr_alloc(&zram_index_idr, zram, 0, 0, GFP_KERNEL);
+ device_id = ret;
+ } else {
+ /* use specific device_id */
+ ret = idr_alloc(&zram_index_idr, zram, device_id,
device_id + 1, GFP_KERNEL);
+ }
if (ret < 0)
goto out_free_dev;
--
2.3.1.167.g7f4ba4b
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists