On Tue, May 23, 2023 at 9:53 AM Guoqing Jiang <guoqing.jiang@xxxxxxxxx> wrote: > > Add one new array (marked with __maybe_unused to prevent gcc warning about > "defined but not used" with W=1), then we can remove rnbd_access_mode_str > and rnbd-common.c accordingly. > > Signed-off-by: Guoqing Jiang <guoqing.jiang@xxxxxxxxx> > --- > drivers/block/rnbd/Makefile | 6 ++---- > drivers/block/rnbd/rnbd-clt-sysfs.c | 4 ++-- > drivers/block/rnbd/rnbd-common.c | 23 ----------------------- > drivers/block/rnbd/rnbd-proto.h | 9 +++++++++ > drivers/block/rnbd/rnbd-srv-sysfs.c | 2 +- > drivers/block/rnbd/rnbd-srv.c | 4 ++-- > 6 files changed, 16 insertions(+), 32 deletions(-) > delete mode 100644 drivers/block/rnbd/rnbd-common.c > > diff --git a/drivers/block/rnbd/Makefile b/drivers/block/rnbd/Makefile > index 40b31630822c..208e5f865497 100644 > --- a/drivers/block/rnbd/Makefile > +++ b/drivers/block/rnbd/Makefile > @@ -3,13 +3,11 @@ > ccflags-y := -I$(srctree)/drivers/infiniband/ulp/rtrs > > rnbd-client-y := rnbd-clt.o \ > - rnbd-clt-sysfs.o \ > - rnbd-common.o > + rnbd-clt-sysfs.o > > CFLAGS_rnbd-srv-trace.o = -I$(src) > > -rnbd-server-y := rnbd-common.o \ > - rnbd-srv.o \ > +rnbd-server-y := rnbd-srv.o \ > rnbd-srv-sysfs.o \ > rnbd-srv-trace.o > > diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c > index 8c6087949794..a0b49a0c0bdd 100644 > --- a/drivers/block/rnbd/rnbd-clt-sysfs.c > +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c > @@ -278,7 +278,7 @@ static ssize_t access_mode_show(struct kobject *kobj, > > dev = container_of(kobj, struct rnbd_clt_dev, kobj); > > - return sysfs_emit(page, "%s\n", rnbd_access_mode_str(dev->access_mode)); > + return sysfs_emit(page, "%s\n", rnbd_access_modes[dev->access_mode].str); > } > > static struct kobj_attribute rnbd_clt_access_mode = > @@ -596,7 +596,7 @@ static ssize_t rnbd_clt_map_device_store(struct kobject *kobj, > > pr_info("Mapping device %s on session %s, (access_mode: %s, nr_poll_queues: %d)\n", > pathname, sessname, > - rnbd_access_mode_str(access_mode), > + rnbd_access_modes[access_mode].str, > nr_poll_queues); > > dev = rnbd_clt_map_device(sessname, paths, path_cnt, port_nr, pathname, > diff --git a/drivers/block/rnbd/rnbd-common.c b/drivers/block/rnbd/rnbd-common.c > deleted file mode 100644 > index 596c3f732403..000000000000 > --- a/drivers/block/rnbd/rnbd-common.c > +++ /dev/null > @@ -1,23 +0,0 @@ > -// SPDX-License-Identifier: GPL-2.0-or-later > -/* > - * RDMA Network Block Driver > - * > - * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved. > - * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved. > - * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved. > - */ > -#include "rnbd-proto.h" > - > -const char *rnbd_access_mode_str(enum rnbd_access_mode mode) > -{ > - switch (mode) { > - case RNBD_ACCESS_RO: > - return "ro"; > - case RNBD_ACCESS_RW: > - return "rw"; > - case RNBD_ACCESS_MIGRATION: > - return "migration"; > - default: > - return "unknown"; > - } > -} > diff --git a/drivers/block/rnbd/rnbd-proto.h b/drivers/block/rnbd/rnbd-proto.h > index 84fd69844b7d..185e24eaf2bf 100644 > --- a/drivers/block/rnbd/rnbd-proto.h > +++ b/drivers/block/rnbd/rnbd-proto.h > @@ -61,6 +61,15 @@ enum rnbd_access_mode { > RNBD_ACCESS_MIGRATION, > }; > > +static const __maybe_unused struct { > + int mode; why not enum rnbd_access_mode? > + const char *str; > +} rnbd_access_modes[] = { > + [RNBD_ACCESS_RO] = {RNBD_ACCESS_RO, "ro"}, > + [RNBD_ACCESS_RW] = {RNBD_ACCESS_RW, "rw"}, > + [RNBD_ACCESS_MIGRATION] = {RNBD_ACCESS_MIGRATION, "migration"}, > +}; > + > /** > * struct rnbd_msg_sess_info - initial session info from client to server > * @hdr: message header > diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c > index 9fe7d9e0ab63..4962826e9639 100644 > --- a/drivers/block/rnbd/rnbd-srv-sysfs.c > +++ b/drivers/block/rnbd/rnbd-srv-sysfs.c > @@ -103,7 +103,7 @@ static ssize_t access_mode_show(struct kobject *kobj, > sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj); > > return sysfs_emit(page, "%s\n", > - rnbd_access_mode_str(sess_dev->access_mode)); > + rnbd_access_modes[sess_dev->access_mode].str); > } > > static struct kobj_attribute rnbd_srv_dev_session_access_mode_attr = > diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c > index 2cfed2e58d64..e9ef6bd4b50c 100644 > --- a/drivers/block/rnbd/rnbd-srv.c > +++ b/drivers/block/rnbd/rnbd-srv.c > @@ -483,7 +483,7 @@ static int rnbd_srv_check_update_open_perm(struct rnbd_srv_dev *srv_dev, > pr_err("Mapping device '%s' for session %s with RW permissions failed. Device already opened as 'RW' by %d client(s), access mode %s.\n", > srv_dev->id, srv_sess->sessname, > srv_dev->open_write_cnt, > - rnbd_access_mode_str(access_mode)); > + rnbd_access_modes[access_mode].str); > } > break; > case RNBD_ACCESS_MIGRATION: > @@ -494,7 +494,7 @@ static int rnbd_srv_check_update_open_perm(struct rnbd_srv_dev *srv_dev, > pr_err("Mapping device '%s' for session %s with migration permissions failed. Device already opened as 'RW' by %d client(s), access mode %s.\n", > srv_dev->id, srv_sess->sessname, > srv_dev->open_write_cnt, > - rnbd_access_mode_str(access_mode)); > + rnbd_access_modes[access_mode].str); > } > break; > default: > -- > 2.35.3 >