Skip to contentSkip to conversation

Staging: zram: make ZRAM depends on SYSFS

PATCH In review Jerome Marchand 4 participants 12 messages Dec 17, 2010 – Jan 24, 2011 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Staging: zram: make ZRAM depends on SYSFS

We can not configure zram device without sysfs anyway, so make zram depends on it.

---
 Kconfig      |    2 +-
 zram_drv.c   |    4 ----
 zram_sysfs.c |    4 ----
 3 files changed, 1 insertion(+), 9 deletions(-)
drivers/staging/zram/Kconfig +1 -1
index da079f8..d3982e6 100644
@@ -1,6 +1,6 @@
 config ZRAM
 	tristate "Compressed RAM block device support"
-	depends on BLOCK
+	depends on BLOCK && SYSFS
 	select LZO_COMPRESS
 	select LZO_DECOMPRESS
 	default n
drivers/staging/zram/zram_drv.c +0 -4
index 8c3c057..d649b3e 100644
@@ -633,14 +633,12 @@ static int create_device(struct zram *zram, int device_id)
 
 	add_disk(zram->disk);
 
-#ifdef CONFIG_SYSFS
 	ret = sysfs_create_group(&disk_to_dev(zram->disk)->kobj,
 				&zram_disk_attr_group);
 	if (ret < 0) {
 		pr_warning("Error creating sysfs group");
 		goto out;
 	}
-#endif
 
 	zram->init_done = 0;
 
@@ -650,10 +648,8 @@ out:
 
 static void destroy_device(struct zram *zram)
 {
-#ifdef CONFIG_SYSFS
 	sysfs_remove_group(&disk_to_dev(zram->disk)->kobj,
 			&zram_disk_attr_group);
-#endif
 
 	if (zram->disk) {
 		del_gendisk(zram->disk);
drivers/staging/zram/zram_sysfs.c +0 -4
index 6b3cf00..ad62db2 100644
@@ -17,8 +17,6 @@
 
 #include "zram_drv.h"
 
-#ifdef CONFIG_SYSFS
-
 static u64 zram_stat64_read(struct zram *zram, u64 *v)
 {
 	u64 val;
@@ -220,5 +218,3 @@ static struct attribute *zram_disk_attrs[] = {
 struct attribute_group zram_disk_attr_group = {
 	.attrs = zram_disk_attrs,
 };
-
-#endif	/* CONFIG_SYSFS */
#1 lore raw

PATCH 2/4 Staging: zram: round up the disk size provided by user

Currently disksize_store() round down the disk size provided by user. This is probably not what one would expect, so round up instead.

---
 zram_sysfs.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/zram/zram_sysfs.c +2 -1
index ad62db2..a70cc01 100644
@@ -14,6 +14,7 @@
 
 #include <linux/device.h>
 #include <linux/genhd.h>
+#include <linux/mm.h>
 
 #include "zram_drv.h"
 
@@ -65,7 +66,7 @@ static ssize_t disksize_store(struct device *dev,
 	if (ret)
 		return ret;
 
-	zram->disksize &= PAGE_MASK;
+	zram->disksize = PAGE_ALIGN(zram->disksize);
 	set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
 
 	return len;
#3 lore raw

PATCH 3/4 Staging: zram: make zram_read return a bio error if the device is not initialized

In reply to Jerome Marchand

Make zram_read() return a bio error if the device is not initialized instead of pretending nothing happened.

---
 zram_drv.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/zram/zram_drv.c +1 -2
index d649b3e..4085958 100644
@@ -208,8 +208,7 @@ static int zram_read(struct zram *zram, struct bio *bio)
 	struct bio_vec *bvec;
 
 	if (unlikely(!zram->init_done)) {
-		set_bit(BIO_UPTODATE, &bio->bi_flags);
-		bio_endio(bio, 0);
+		bio_endio(bio, -ENXIO);
 		return 0;
 	}
 
#5 lore raw

PATCH 4/4 Staging: zram: simplify zram_make_request

In reply to Jerome Marchand

zram_read() and zram_write() always return zero, so make them return void to simplify the code.

---
 zram_drv.c |   19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/staging/zram/zram_drv.c +8 -11
index 4085958..54577b0 100644
@@ -200,7 +200,7 @@ static void handle_uncompressed_page(struct zram *zram,
 	flush_dcache_page(page);
 }
 
-static int zram_read(struct zram *zram, struct bio *bio)
+static void zram_read(struct zram *zram, struct bio *bio)
 {
 
 	int i;
@@ -209,7 +209,7 @@ static int zram_read(struct zram *zram, struct bio *bio)
 
 	if (unlikely(!zram->init_done)) {
 		bio_endio(bio, -ENXIO);
-		return 0;
+		return;
 	}
 
 	zram_stat64_inc(zram, &zram->stats.num_reads);
@@ -271,14 +271,13 @@ static int zram_read(struct zram *zram, struct bio *bio)
 
 	set_bit(BIO_UPTODATE, &bio->bi_flags);
 	bio_endio(bio, 0);
-	return 0;
+	return;
 
 out:
 	bio_io_error(bio);
-	return 0;
 }
 
-static int zram_write(struct zram *zram, struct bio *bio)
+static void zram_write(struct zram *zram, struct bio *bio)
 {
 	int i, ret;
 	u32 index;
@@ -402,11 +401,10 @@ memstore:
 
 	set_bit(BIO_UPTODATE, &bio->bi_flags);
 	bio_endio(bio, 0);
-	return 0;
+	return;
 
 out:
 	bio_io_error(bio);
-	return 0;
 }
 
 /*
@@ -431,7 +429,6 @@ static inline int valid_io_request(struct zram *zram, struct bio *bio)
  */
 static int zram_make_request(struct request_queue *queue, struct bio *bio)
 {
-	int ret = 0;
 	struct zram *zram = queue->queuedata;
 
 	if (unlikely(!zram->init_done)) {
@@ -448,15 +445,15 @@ static int zram_make_request(struct request_queue *queue, struct bio *bio)
 
 	switch (bio_data_dir(bio)) {
 	case READ:
-		ret = zram_read(zram, bio);
+		zram_read(zram, bio);
 		break;
 
 	case WRITE:
-		ret = zram_write(zram, bio);
+		zram_write(zram, bio);
 		break;
 	}
 
-	return ret;
+	return 0;
 }
 
 void zram_reset_device(struct zram *zram)
Acked-by Jeff Moyer on v1 4/4
#8 lore raw

Re: [PATCH 4/4] [resend] Staging: zram: simplify zram_make_request

In reply to Jerome Marchand

zram_read() and zram_write() always return zero, so make them return void to simplify the code.

---
 drivers/staging/zram/zram_drv.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)
drivers/staging/zram/zram_drv.c +8 -11
index 01d6dd9..5ed4e75 100644
@@ -200,7 +200,7 @@ static void handle_uncompressed_page(struct zram *zram,
 	flush_dcache_page(page);
 }
 
-static int zram_read(struct zram *zram, struct bio *bio)
+static void zram_read(struct zram *zram, struct bio *bio)
 {
 
 	int i;
@@ -209,7 +209,7 @@ static int zram_read(struct zram *zram, struct bio *bio)
 
 	if (unlikely(!zram->init_done)) {
 		bio_endio(bio, -ENXIO);
-		return 0;
+		return;
 	}
 
 	zram_stat64_inc(zram, &zram->stats.num_reads);
@@ -271,14 +271,13 @@ static int zram_read(struct zram *zram, struct bio *bio)
 
 	set_bit(BIO_UPTODATE, &bio->bi_flags);
 	bio_endio(bio, 0);
-	return 0;
+	return;
 
 out:
 	bio_io_error(bio);
-	return 0;
 }
 
-static int zram_write(struct zram *zram, struct bio *bio)
+static void zram_write(struct zram *zram, struct bio *bio)
 {
 	int i, ret;
 	u32 index;
@@ -402,11 +401,10 @@ memstore:
 
 	set_bit(BIO_UPTODATE, &bio->bi_flags);
 	bio_endio(bio, 0);
-	return 0;
+	return;
 
 out:
 	bio_io_error(bio);
-	return 0;
 }
 
 /*
@@ -431,7 +429,6 @@ static inline int valid_io_request(struct zram *zram, struct bio *bio)
  */
 static int zram_make_request(struct request_queue *queue, struct bio *bio)
 {
-	int ret = 0;
 	struct zram *zram = queue->queuedata;
 
 	if (!valid_io_request(zram, bio)) {
@@ -442,15 +439,15 @@ static int zram_make_request(struct request_queue *queue, struct bio *bio)
 
 	switch (bio_data_dir(bio)) {
 	case READ:
-		ret = zram_read(zram, bio);
+		zram_read(zram, bio);
 		break;
 
 	case WRITE:
-		ret = zram_write(zram, bio);
+		zram_write(zram, bio);
 		break;
 	}
 
-	return ret;
+	return 0;
 }
 
 void zram_reset_device(struct zram *zram)
Signature · 1 line
1.7.3.5
#9 lore raw

Re: Staging: zram: simplify zram_make_request

Quoted 6 lines · Nitin Gupta

zram_read() and zram_write() always return zero, so make them return void to simplify the code.

Ick, this patch is line-wrapped and extra spaces are in every line making it impossible to apply, unless I edit it by hand, which I really don't want to do.

Care to fix this and resend?

thanks,

greg k-h

#10 lore raw

PATCH RESEND 4/4 Staging: zram: simplify zram_make_request

zram_read() and zram_write() always return zero, so make them return void to simplify the code.

---
 zram_drv.c |   19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/staging/zram/zram_drv.c +8 -11
index 01d6dd9..5ed4e75 100644
@@ -200,7 +200,7 @@ static void handle_uncompressed_page(struct zram *zram,
 	flush_dcache_page(page);
 }
 
-static int zram_read(struct zram *zram, struct bio *bio)
+static void zram_read(struct zram *zram, struct bio *bio)
 {
 
 	int i;
@@ -209,7 +209,7 @@ static int zram_read(struct zram *zram, struct bio *bio)
 
 	if (unlikely(!zram->init_done)) {
 		bio_endio(bio, -ENXIO);
-		return 0;
+		return;
 	}
 
 	zram_stat64_inc(zram, &zram->stats.num_reads);
@@ -271,14 +271,13 @@ static int zram_read(struct zram *zram, struct bio *bio)
 
 	set_bit(BIO_UPTODATE, &bio->bi_flags);
 	bio_endio(bio, 0);
-	return 0;
+	return;
 
 out:
 	bio_io_error(bio);
-	return 0;
 }
 
-static int zram_write(struct zram *zram, struct bio *bio)
+static void zram_write(struct zram *zram, struct bio *bio)
 {
 	int i, ret;
 	u32 index;
@@ -402,11 +401,10 @@ memstore:
 
 	set_bit(BIO_UPTODATE, &bio->bi_flags);
 	bio_endio(bio, 0);
-	return 0;
+	return;
 
 out:
 	bio_io_error(bio);
-	return 0;
 }
 
 /*
@@ -431,7 +429,6 @@ static inline int valid_io_request(struct zram *zram, struct bio *bio)
  */
 static int zram_make_request(struct request_queue *queue, struct bio *bio)
 {
-	int ret = 0;
 	struct zram *zram = queue->queuedata;
 
 	if (!valid_io_request(zram, bio)) {
@@ -442,15 +439,15 @@ static int zram_make_request(struct request_queue *queue, struct bio *bio)
 
 	switch (bio_data_dir(bio)) {
 	case READ:
-		ret = zram_read(zram, bio);
+		zram_read(zram, bio);
 		break;
 
 	case WRITE:
-		ret = zram_write(zram, bio);
+		zram_write(zram, bio);
 		break;
 	}
 
-	return ret;
+	return 0;
 }
 
 void zram_reset_device(struct zram *zram)