diff mbox series

[f2fs-dev,24/31] rnbd-srv: replace sess->open_flags with a "bool readonly"

Message ID 20230606073950.225178-25-hch@lst.de (mailing list archive)
State Superseded
Headers show
Series [f2fs-dev,01/31] block: also call ->open for incremental partition opens | expand

Commit Message

Christoph Hellwig June 6, 2023, 7:39 a.m. UTC
Stop passing the fmode_t around and just use a simple bool to track if
an export is read-only.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/rnbd/rnbd-srv-sysfs.c |  3 +--
 drivers/block/rnbd/rnbd-srv.c       | 15 +++++++--------
 drivers/block/rnbd/rnbd-srv.h       |  2 +-
 3 files changed, 9 insertions(+), 11 deletions(-)

Comments

Christian Brauner June 7, 2023, 9:01 a.m. UTC | #1
On Tue, Jun 06, 2023 at 09:39:43AM +0200, Christoph Hellwig wrote:
> Stop passing the fmode_t around and just use a simple bool to track if
> an export is read-only.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---

Looks good to me,
Acked-by: Christian Brauner <brauner@kernel.org>
Jinpu Wang June 7, 2023, 9:43 a.m. UTC | #2
On Tue, Jun 6, 2023 at 9:41 AM Christoph Hellwig <hch@lst.de> wrote:
>
> Stop passing the fmode_t around and just use a simple bool to track if
> an export is read-only.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jack Wang <jinpu.wang@ionos.com>
> ---
>  drivers/block/rnbd/rnbd-srv-sysfs.c |  3 +--
>  drivers/block/rnbd/rnbd-srv.c       | 15 +++++++--------
>  drivers/block/rnbd/rnbd-srv.h       |  2 +-
>  3 files changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c
> index d5d9267e1fa5e4..ebd95771c85ec7 100644
> --- a/drivers/block/rnbd/rnbd-srv-sysfs.c
> +++ b/drivers/block/rnbd/rnbd-srv-sysfs.c
> @@ -88,8 +88,7 @@ static ssize_t read_only_show(struct kobject *kobj, struct kobj_attribute *attr,
>
>         sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj);
>
> -       return sysfs_emit(page, "%d\n",
> -                         !(sess_dev->open_flags & FMODE_WRITE));
> +       return sysfs_emit(page, "%d\n", sess_dev->readonly);
>  }
>
>  static struct kobj_attribute rnbd_srv_dev_session_ro_attr =
> diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c
> index 29d560472d05ba..b680071342b898 100644
> --- a/drivers/block/rnbd/rnbd-srv.c
> +++ b/drivers/block/rnbd/rnbd-srv.c
> @@ -222,7 +222,7 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id)
>         blkdev_put(sess_dev->bdev, NULL);
>         mutex_lock(&sess_dev->dev->lock);
>         list_del(&sess_dev->dev_list);
> -       if (sess_dev->open_flags & FMODE_WRITE)
> +       if (!sess_dev->readonly)
>                 sess_dev->dev->open_write_cnt--;
>         mutex_unlock(&sess_dev->dev->lock);
>
> @@ -561,7 +561,7 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
>  static struct rnbd_srv_sess_dev *
>  rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
>                               const struct rnbd_msg_open *open_msg,
> -                             struct block_device *bdev, fmode_t open_flags,
> +                             struct block_device *bdev, bool readonly,
>                               struct rnbd_srv_dev *srv_dev)
>  {
>         struct rnbd_srv_sess_dev *sdev = rnbd_sess_dev_alloc(srv_sess);
> @@ -576,7 +576,7 @@ rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
>         sdev->bdev              = bdev;
>         sdev->sess              = srv_sess;
>         sdev->dev               = srv_dev;
> -       sdev->open_flags        = open_flags;
> +       sdev->readonly          = readonly;
>         sdev->access_mode       = open_msg->access_mode;
>
>         return sdev;
> @@ -681,13 +681,12 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
>         struct rnbd_srv_sess_dev *srv_sess_dev;
>         const struct rnbd_msg_open *open_msg = msg;
>         struct block_device *bdev;
> -       fmode_t open_flags;
> +       fmode_t open_flags = FMODE_READ;
>         char *full_path;
>         struct rnbd_msg_open_rsp *rsp = data;
>
>         trace_process_msg_open(srv_sess, open_msg);
>
> -       open_flags = FMODE_READ;
>         if (open_msg->access_mode != RNBD_ACCESS_RO)
>                 open_flags |= FMODE_WRITE;
>
> @@ -736,9 +735,9 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,
>                 goto blkdev_put;
>         }
>
> -       srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg,
> -                                                    bdev, open_flags,
> -                                                    srv_dev);
> +       srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg, bdev,
> +                               open_msg->access_mode == RNBD_ACCESS_RO,
> +                               srv_dev);
>         if (IS_ERR(srv_sess_dev)) {
>                 pr_err("Opening device '%s' on session %s failed, creating sess_dev failed, err: %ld\n",
>                        full_path, srv_sess->sessname, PTR_ERR(srv_sess_dev));
> diff --git a/drivers/block/rnbd/rnbd-srv.h b/drivers/block/rnbd/rnbd-srv.h
> index f5962fd31d62e4..76077a9db3dd55 100644
> --- a/drivers/block/rnbd/rnbd-srv.h
> +++ b/drivers/block/rnbd/rnbd-srv.h
> @@ -52,7 +52,7 @@ struct rnbd_srv_sess_dev {
>         struct kobject                  kobj;
>         u32                             device_id;
>         bool                            keep_id;
> -       fmode_t                         open_flags;
> +       bool                            readonly;
>         struct kref                     kref;
>         struct completion               *destroy_comp;
>         char                            pathname[NAME_MAX];
> --
> 2.39.2
>
Hannes Reinecke June 7, 2023, 1:07 p.m. UTC | #3
On 6/6/23 09:39, Christoph Hellwig wrote:
> Stop passing the fmode_t around and just use a simple bool to track if
> an export is read-only.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   drivers/block/rnbd/rnbd-srv-sysfs.c |  3 +--
>   drivers/block/rnbd/rnbd-srv.c       | 15 +++++++--------
>   drivers/block/rnbd/rnbd-srv.h       |  2 +-
>   3 files changed, 9 insertions(+), 11 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
diff mbox series

Patch

diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c
index d5d9267e1fa5e4..ebd95771c85ec7 100644
--- a/drivers/block/rnbd/rnbd-srv-sysfs.c
+++ b/drivers/block/rnbd/rnbd-srv-sysfs.c
@@ -88,8 +88,7 @@  static ssize_t read_only_show(struct kobject *kobj, struct kobj_attribute *attr,
 
 	sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj);
 
-	return sysfs_emit(page, "%d\n",
-			  !(sess_dev->open_flags & FMODE_WRITE));
+	return sysfs_emit(page, "%d\n", sess_dev->readonly);
 }
 
 static struct kobj_attribute rnbd_srv_dev_session_ro_attr =
diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c
index 29d560472d05ba..b680071342b898 100644
--- a/drivers/block/rnbd/rnbd-srv.c
+++ b/drivers/block/rnbd/rnbd-srv.c
@@ -222,7 +222,7 @@  void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id)
 	blkdev_put(sess_dev->bdev, NULL);
 	mutex_lock(&sess_dev->dev->lock);
 	list_del(&sess_dev->dev_list);
-	if (sess_dev->open_flags & FMODE_WRITE)
+	if (!sess_dev->readonly)
 		sess_dev->dev->open_write_cnt--;
 	mutex_unlock(&sess_dev->dev->lock);
 
@@ -561,7 +561,7 @@  static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
 static struct rnbd_srv_sess_dev *
 rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
 			      const struct rnbd_msg_open *open_msg,
-			      struct block_device *bdev, fmode_t open_flags,
+			      struct block_device *bdev, bool readonly,
 			      struct rnbd_srv_dev *srv_dev)
 {
 	struct rnbd_srv_sess_dev *sdev = rnbd_sess_dev_alloc(srv_sess);
@@ -576,7 +576,7 @@  rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,
 	sdev->bdev		= bdev;
 	sdev->sess		= srv_sess;
 	sdev->dev		= srv_dev;
-	sdev->open_flags	= open_flags;
+	sdev->readonly		= readonly;
 	sdev->access_mode	= open_msg->access_mode;
 
 	return sdev;
@@ -681,13 +681,12 @@  static int process_msg_open(struct rnbd_srv_session *srv_sess,
 	struct rnbd_srv_sess_dev *srv_sess_dev;
 	const struct rnbd_msg_open *open_msg = msg;
 	struct block_device *bdev;
-	fmode_t open_flags;
+	fmode_t open_flags = FMODE_READ;
 	char *full_path;
 	struct rnbd_msg_open_rsp *rsp = data;
 
 	trace_process_msg_open(srv_sess, open_msg);
 
-	open_flags = FMODE_READ;
 	if (open_msg->access_mode != RNBD_ACCESS_RO)
 		open_flags |= FMODE_WRITE;
 
@@ -736,9 +735,9 @@  static int process_msg_open(struct rnbd_srv_session *srv_sess,
 		goto blkdev_put;
 	}
 
-	srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg,
-						     bdev, open_flags,
-						     srv_dev);
+	srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg, bdev,
+				open_msg->access_mode == RNBD_ACCESS_RO,
+				srv_dev);
 	if (IS_ERR(srv_sess_dev)) {
 		pr_err("Opening device '%s' on session %s failed, creating sess_dev failed, err: %ld\n",
 		       full_path, srv_sess->sessname, PTR_ERR(srv_sess_dev));
diff --git a/drivers/block/rnbd/rnbd-srv.h b/drivers/block/rnbd/rnbd-srv.h
index f5962fd31d62e4..76077a9db3dd55 100644
--- a/drivers/block/rnbd/rnbd-srv.h
+++ b/drivers/block/rnbd/rnbd-srv.h
@@ -52,7 +52,7 @@  struct rnbd_srv_sess_dev {
 	struct kobject                  kobj;
 	u32                             device_id;
 	bool				keep_id;
-	fmode_t                         open_flags;
+	bool				readonly;
 	struct kref			kref;
 	struct completion               *destroy_comp;
 	char				pathname[NAME_MAX];