diff mbox series

[11/14] PM: rewrite is_hibernate_resume_dev to not require an inode

Message ID 20200917165720.3285256-12-hch@lst.de
State New, archived
Headers show
Series [01/14] block: move the NEED_PART_SCAN flag to struct gendisk | expand

Commit Message

Christoph Hellwig Sept. 17, 2020, 4:57 p.m. UTC
Just check the dev_t to help simplifying the code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/block_dev.c          |  2 +-
 include/linux/suspend.h |  4 ++--
 kernel/power/user.c     | 12 ++++++------
 3 files changed, 9 insertions(+), 9 deletions(-)

Comments

Rafael J. Wysocki Sept. 17, 2020, 5:26 p.m. UTC | #1
On Thu, Sep 17, 2020 at 7:24 PM Christoph Hellwig <hch@lst.de> wrote:
>
> Just check the dev_t to help simplifying the code.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> ---
>  fs/block_dev.c          |  2 +-
>  include/linux/suspend.h |  4 ++--
>  kernel/power/user.c     | 12 ++++++------
>  3 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 1a9325f4315769..2898d69be6b3e4 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -1885,7 +1885,7 @@ ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
>         if (bdev_read_only(I_BDEV(bd_inode)))
>                 return -EPERM;
>
> -       if (IS_SWAPFILE(bd_inode) && !is_hibernate_resume_dev(bd_inode))
> +       if (IS_SWAPFILE(bd_inode) && !is_hibernate_resume_dev(bd_inode->i_rdev))
>                 return -ETXTBSY;
>
>         if (!iov_iter_count(from))
> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
> index cb9afad82a90c8..8af13ba60c7e45 100644
> --- a/include/linux/suspend.h
> +++ b/include/linux/suspend.h
> @@ -473,9 +473,9 @@ static inline int hibernate_quiet_exec(int (*func)(void *data), void *data) {
>  #endif /* CONFIG_HIBERNATION */
>
>  #ifdef CONFIG_HIBERNATION_SNAPSHOT_DEV
> -int is_hibernate_resume_dev(const struct inode *);
> +int is_hibernate_resume_dev(dev_t dev);
>  #else
> -static inline int is_hibernate_resume_dev(const struct inode *i) { return 0; }
> +static inline int is_hibernate_resume_dev(dev_t dev) { return 0; }
>  #endif
>
>  /* Hibernation and suspend events */
> diff --git a/kernel/power/user.c b/kernel/power/user.c
> index d5eedc2baa2a10..b5815685b944fe 100644
> --- a/kernel/power/user.c
> +++ b/kernel/power/user.c
> @@ -35,12 +35,12 @@ static struct snapshot_data {
>         bool ready;
>         bool platform_support;
>         bool free_bitmaps;
> -       struct inode *bd_inode;
> +       dev_t dev;
>  } snapshot_state;
>
> -int is_hibernate_resume_dev(const struct inode *bd_inode)
> +int is_hibernate_resume_dev(dev_t dev)
>  {
> -       return hibernation_available() && snapshot_state.bd_inode == bd_inode;
> +       return hibernation_available() && snapshot_state.dev == dev;
>  }
>
>  static int snapshot_open(struct inode *inode, struct file *filp)
> @@ -101,7 +101,7 @@ static int snapshot_open(struct inode *inode, struct file *filp)
>         data->frozen = false;
>         data->ready = false;
>         data->platform_support = false;
> -       data->bd_inode = NULL;
> +       data->dev = 0;
>
>   Unlock:
>         unlock_system_sleep();
> @@ -117,7 +117,7 @@ static int snapshot_release(struct inode *inode, struct file *filp)
>
>         swsusp_free();
>         data = filp->private_data;
> -       data->bd_inode = NULL;
> +       data->dev = 0;
>         free_all_swap_pages(data->swap);
>         if (data->frozen) {
>                 pm_restore_gfp_mask();
> @@ -245,7 +245,7 @@ static int snapshot_set_swap_area(struct snapshot_data *data,
>         if (data->swap < 0)
>                 return -ENODEV;
>
> -       data->bd_inode = bdev->bd_inode;
> +       data->dev = bdev->bd_dev;
>         bdput(bdev);
>         return 0;
>  }
> --
> 2.28.0
>
Pavel Machek Sept. 19, 2020, 9:06 a.m. UTC | #2
On Thu 2020-09-17 18:57:17, Christoph Hellwig wrote:
> Just check the dev_t to help simplifying the code.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Pavel Machek <pavel@ucw.cz>
diff mbox series

Patch

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 1a9325f4315769..2898d69be6b3e4 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1885,7 +1885,7 @@  ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	if (bdev_read_only(I_BDEV(bd_inode)))
 		return -EPERM;
 
-	if (IS_SWAPFILE(bd_inode) && !is_hibernate_resume_dev(bd_inode))
+	if (IS_SWAPFILE(bd_inode) && !is_hibernate_resume_dev(bd_inode->i_rdev))
 		return -ETXTBSY;
 
 	if (!iov_iter_count(from))
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index cb9afad82a90c8..8af13ba60c7e45 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -473,9 +473,9 @@  static inline int hibernate_quiet_exec(int (*func)(void *data), void *data) {
 #endif /* CONFIG_HIBERNATION */
 
 #ifdef CONFIG_HIBERNATION_SNAPSHOT_DEV
-int is_hibernate_resume_dev(const struct inode *);
+int is_hibernate_resume_dev(dev_t dev);
 #else
-static inline int is_hibernate_resume_dev(const struct inode *i) { return 0; }
+static inline int is_hibernate_resume_dev(dev_t dev) { return 0; }
 #endif
 
 /* Hibernation and suspend events */
diff --git a/kernel/power/user.c b/kernel/power/user.c
index d5eedc2baa2a10..b5815685b944fe 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -35,12 +35,12 @@  static struct snapshot_data {
 	bool ready;
 	bool platform_support;
 	bool free_bitmaps;
-	struct inode *bd_inode;
+	dev_t dev;
 } snapshot_state;
 
-int is_hibernate_resume_dev(const struct inode *bd_inode)
+int is_hibernate_resume_dev(dev_t dev)
 {
-	return hibernation_available() && snapshot_state.bd_inode == bd_inode;
+	return hibernation_available() && snapshot_state.dev == dev;
 }
 
 static int snapshot_open(struct inode *inode, struct file *filp)
@@ -101,7 +101,7 @@  static int snapshot_open(struct inode *inode, struct file *filp)
 	data->frozen = false;
 	data->ready = false;
 	data->platform_support = false;
-	data->bd_inode = NULL;
+	data->dev = 0;
 
  Unlock:
 	unlock_system_sleep();
@@ -117,7 +117,7 @@  static int snapshot_release(struct inode *inode, struct file *filp)
 
 	swsusp_free();
 	data = filp->private_data;
-	data->bd_inode = NULL;
+	data->dev = 0;
 	free_all_swap_pages(data->swap);
 	if (data->frozen) {
 		pm_restore_gfp_mask();
@@ -245,7 +245,7 @@  static int snapshot_set_swap_area(struct snapshot_data *data,
 	if (data->swap < 0)
 		return -ENODEV;
 
-	data->bd_inode = bdev->bd_inode;
+	data->dev = bdev->bd_dev;
 	bdput(bdev);
 	return 0;
 }