lkml.org 
[lkml]   [2015]   [Feb]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 6/8] zram: allow automatic new zram device_id assignment
Date
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@gmail.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


\
 
 \ /
  Last update: 2015-02-26 15:21    [W:0.059 / U:0.848 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site