mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Minchan Kim <minchan@kernel.org>
Cc: Jerome Marchand <jmarchan@redhat.com>,
	Nitin Gupta <ngupta@vflare.org>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	linux-kernel@vger.kernel.org,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: [PATCH 5/8] zram: return zram device_id value from zram_add()
Date: Thu, 26 Feb 2015 23:10:40 +0900	[thread overview]
Message-ID: <1424959843-20409-6-git-send-email-sergey.senozhatsky@gmail.com> (raw)
In-Reply-To: <1424959843-20409-1-git-send-email-sergey.senozhatsky@gmail.com>

ZRAM_CTL_ADD ioctl requires valid device_id to be provided, that can be a
bit inconvenient. Change zram_add() to return negative value upon new device
creation failure, and device_id (>= 0) value otherwise.

This prepares ZRAM_CTL_ADD to perform automatic device_id assignment. New
device_id will be returned back to user-space (so user can reference that
device as zram%d device_id).

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 drivers/block/zram/zram_drv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 4f87d1e..0154c2d4 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1078,6 +1078,8 @@ static struct zram *zram_lookup(int dev_id)
 	return ERR_PTR(-ENODEV);
 }
 
+/* allocate and initialize new zram device. the function returns >= 0
+ * device_id value upon success, and negative value otherwise. */
 static int zram_add(int device_id)
 {
 	struct zram *zram;
@@ -1161,7 +1163,7 @@ static int zram_add(int device_id)
 	strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));
 	zram->meta = NULL;
 	zram->max_comp_streams = 1;
-	return 0;
+	return device_id;
 
 out_free_disk:
 	del_gendisk(zram->disk);
@@ -1303,7 +1305,7 @@ static int __init zram_init(void)
 		mutex_lock(&zram_index_mutex);
 		ret = zram_add(dev_id);
 		mutex_unlock(&zram_index_mutex);
-		if (ret != 0)
+		if (ret < 0)
 			goto out_error;
 	}
 
-- 
2.3.1.167.g7f4ba4b


  parent reply	other threads:[~2015-02-26 14:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-26 14:10 [PATCH 0/8] introduce dynamic device creation/removal Sergey Senozhatsky
2015-02-26 14:10 ` [PATCH 1/8] zram: cosmetic ZRAM_ATTR_RO code formatting tweak Sergey Senozhatsky
2015-02-26 14:10 ` [PATCH 2/8] zram: use idr instead of `zram_devices' array Sergey Senozhatsky
2015-02-26 14:10 ` [PATCH 3/8] zram: factor out device reset from reset_store() Sergey Senozhatsky
2015-02-26 14:10 ` [PATCH 4/8] zram: add dynamic device add/remove functionality Sergey Senozhatsky
2015-02-26 14:10 ` Sergey Senozhatsky [this message]
2015-02-26 14:10 ` [PATCH 6/8] zram: allow automatic new zram device_id assignment Sergey Senozhatsky
2015-02-26 14:10 ` [PATCH 7/8] zram: remove max_num_devices limitation Sergey Senozhatsky
2015-02-26 14:10 ` [PATCH 8/8] zram: report every added and removed device Sergey Senozhatsky
2015-02-27 22:51 ` [PATCH 0/8] introduce dynamic device creation/removal Andrew Morton
2015-02-28  1:33   ` Sergey Senozhatsky
2015-02-28  1:50     ` Sergey Senozhatsky
2015-02-28  3:34   ` Sergey Senozhatsky
2015-02-28  4:29     ` Andrew Morton
2015-03-02 14:18   ` Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424959843-20409-6-git-send-email-sergey.senozhatsky@gmail.com \
    --to=sergey.senozhatsky@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jmarchan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®