From c61cab09a2aecf221761482dc71782dc8189e4e2 Mon Sep 17 00:00:00 2001 From: Xiaojun Ji Date: Wed, 6 Dec 2023 13:50:52 +0800 Subject: [PATCH] moto_swap: Add reset_bdev to close backing dev for ramboost2.0 reboot process will write 1 to /sys/block/zram0/reset to close backing device fd Change-Id: Id11caf26c3edff89a0bf64fc706799c1d54901ee Reviewed-on: https://gerrit.mot.com/2816017 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Wang Wang Submit-Approved: Jira Key --- .../moto_swap/hybridswap/hybridswap_eswap.c | 9 +++++++++ drivers/moto_swap/zram-5.10/zram_drv.c | 20 +++++++++++++++++++ drivers/moto_swap/zram-5.15/zram_drv.c | 17 ++++++++++++++++ drivers/moto_swap/zram-5.4/zram_drv.c | 20 +++++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/drivers/moto_swap/hybridswap/hybridswap_eswap.c b/drivers/moto_swap/hybridswap/hybridswap_eswap.c index 8a67a1437c6b..9bad6d608ef8 100644 --- a/drivers/moto_swap/hybridswap/hybridswap_eswap.c +++ b/drivers/moto_swap/hybridswap/hybridswap_eswap.c @@ -4400,6 +4400,15 @@ ssize_t hybridswap_loop_device_show(struct device *dev, struct device_attribute *attr, char *buf) { int len = 0; + struct zram *zram = dev_to_zram(dev); + + down_read(&zram->init_lock); + if (!zram->backing_dev) { + memcpy(buf, "none\n", 5); + up_read(&zram->init_lock); + return 5; + } + up_read(&zram->init_lock); len = sprintf(buf, "%s\n", loop_device); diff --git a/drivers/moto_swap/zram-5.10/zram_drv.c b/drivers/moto_swap/zram-5.10/zram_drv.c index 56112f2d2e13..e25cb6134120 100644 --- a/drivers/moto_swap/zram-5.10/zram_drv.c +++ b/drivers/moto_swap/zram-5.10/zram_drv.c @@ -791,7 +791,27 @@ static int read_from_bdev(struct zram *zram, struct bio_vec *bvec, return read_from_bdev_async(zram, bvec, entry, parent); } #else +#ifdef CONFIG_HYBRIDSWAP_CORE +static void reset_bdev(struct zram *zram) +{ + struct block_device *bdev; + + if (!zram->backing_dev) + return; + + bdev = zram->bdev; + if (zram->old_block_size) + set_blocksize(bdev, zram->old_block_size); + blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); + /* hope filp_close flush all of IO */ + filp_close(zram->backing_dev, NULL); + zram->backing_dev = NULL; + zram->old_block_size = 0; + zram->bdev = NULL; +} +#else static inline void reset_bdev(struct zram *zram) {}; +#endif static int read_from_bdev(struct zram *zram, struct bio_vec *bvec, unsigned long entry, struct bio *parent, bool sync) { diff --git a/drivers/moto_swap/zram-5.15/zram_drv.c b/drivers/moto_swap/zram-5.15/zram_drv.c index fed6596b5815..ee4dc91f8559 100644 --- a/drivers/moto_swap/zram-5.15/zram_drv.c +++ b/drivers/moto_swap/zram-5.15/zram_drv.c @@ -782,7 +782,24 @@ static int read_from_bdev(struct zram *zram, struct bio_vec *bvec, return read_from_bdev_async(zram, bvec, entry, parent); } #else +#ifdef CONFIG_HYBRIDSWAP_CORE +static void reset_bdev(struct zram *zram) +{ + struct block_device *bdev; + + if (!zram->backing_dev) + return; + + bdev = zram->bdev; + blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); + /* hope filp_close flush all of IO */ + filp_close(zram->backing_dev, NULL); + zram->backing_dev = NULL; + zram->bdev = NULL; +} +#else static inline void reset_bdev(struct zram *zram) {}; +#endif static int read_from_bdev(struct zram *zram, struct bio_vec *bvec, unsigned long entry, struct bio *parent, bool sync) { diff --git a/drivers/moto_swap/zram-5.4/zram_drv.c b/drivers/moto_swap/zram-5.4/zram_drv.c index 7abdf6e8823b..aaccc68e91ce 100644 --- a/drivers/moto_swap/zram-5.4/zram_drv.c +++ b/drivers/moto_swap/zram-5.4/zram_drv.c @@ -776,7 +776,27 @@ static int read_from_bdev(struct zram *zram, struct bio_vec *bvec, return read_from_bdev_async(zram, bvec, entry, parent); } #else +#ifdef CONFIG_HYBRIDSWAP_CORE +static void reset_bdev(struct zram *zram) +{ + struct block_device *bdev; + + if (!zram->backing_dev) + return; + + bdev = zram->bdev; + if (zram->old_block_size) + set_blocksize(bdev, zram->old_block_size); + blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); + /* hope filp_close flush all of IO */ + filp_close(zram->backing_dev, NULL); + zram->backing_dev = NULL; + zram->old_block_size = 0; + zram->bdev = NULL; +} +#else static inline void reset_bdev(struct zram *zram) {}; +#endif static int read_from_bdev(struct zram *zram, struct bio_vec *bvec, unsigned long entry, struct bio *parent, bool sync) {