From: Jinpu Wang <jinpu.wang@cloud.ionos.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: Jack Wang <jinpuwang@gmail.com>,
linux-block@vger.kernel.org, linux-rdma@vger.kernel.org,
Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@infradead.org>,
Sagi Grimberg <sagi@grimberg.me>,
Bart Van Assche <bvanassche@acm.org>,
Doug Ledford <dledford@redhat.com>,
Danil Kipnis <danil.kipnis@cloud.ionos.com>,
rpenyaev@suse.de
Subject: Re: [PATCH v5 22/25] rnbd: server: sysfs interface functions
Date: Mon, 23 Dec 2019 09:33:49 +0100 [thread overview]
Message-ID: <CAMGffEnnS_HZVo_5D9O-v=6QYJXoaJ63u39cwFu+aiaNTNXTyA@mail.gmail.com> (raw)
In-Reply-To: <20191223081412.GM13335@unreal>
On Mon, Dec 23, 2019 at 9:14 AM Leon Romanovsky <leon@kernel.org> wrote:
>
> On Fri, Dec 20, 2019 at 04:51:06PM +0100, Jack Wang wrote:
> > From: Jack Wang <jinpu.wang@cloud.ionos.com>
> >
> > This is the sysfs interface to rnbd mapped devices on server side:
> >
> > /sys/devices/virtual/rnbd-server/ctl/devices/<device_name>/
> > |- block_dev
> > | *** link pointing to the corresponding block device sysfs entry
> > |
> > |- sessions/<session-name>/
> > | *** sessions directory
> > |
> > |- read_only
> > | *** is devices mapped as read only
> > |
> > |- mapping_path
> > *** relative device path provided by the client during mapping
> >
> > Signed-off-by: Danil Kipnis <danil.kipnis@cloud.ionos.com>
> > Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com>
> > ---
> > drivers/block/rnbd/rnbd-srv-sysfs.c | 234 ++++++++++++++++++++++++++++
> > 1 file changed, 234 insertions(+)
> > create mode 100644 drivers/block/rnbd/rnbd-srv-sysfs.c
> >
> > diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c
> > new file mode 100644
> > index 000000000000..17258156cdf2
> > --- /dev/null
> > +++ b/drivers/block/rnbd/rnbd-srv-sysfs.c
> > @@ -0,0 +1,234 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * InfiniBand Network Block Driver
> > + *
> > + * Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved.
> > + * Authors: Fabian Holler <mail@fholler.de>
> > + * Jack Wang <jinpu.wang@profitbricks.com>
> > + * Kleber Souza <kleber.souza@profitbricks.com>
> > + * Danil Kipnis <danil.kipnis@profitbricks.com>
> > + * Roman Penyaev <roman.penyaev@profitbricks.com>
> > + * Milind Dumbare <Milind.dumbare@gmail.com>
> > + *
> > + * Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved.
> > + * Authors: Danil Kipnis <danil.kipnis@profitbricks.com>
> > + * Roman Penyaev <roman.penyaev@profitbricks.com>
> > + *
> > + * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
> > + * Authors: Roman Penyaev <roman.penyaev@profitbricks.com>
> > + * Jack Wang <jinpu.wang@cloud.ionos.com>
> > + * Danil Kipnis <danil.kipnis@cloud.ionos.com>
> > + */
> > +
> > +/* Copyright (c) 2019 1&1 IONOS SE. All rights reserved.
> > + * Authors: Jack Wang <jinpu.wang@cloud.ionos.com>
> > + * Danil Kipnis <danil.kipnis@cloud.ionos.com>
> > + * Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
> > + * Lutz Pogrell <lutz.pogrell@cloud.ionos.com>
> > + */
> > +#undef pr_fmt
> > +#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt
> > +
> > +#include <uapi/linux/limits.h>
> > +#include <linux/kobject.h>
> > +#include <linux/sysfs.h>
> > +#include <linux/stat.h>
> > +#include <linux/genhd.h>
> > +#include <linux/list.h>
> > +#include <linux/moduleparam.h>
> > +#include <linux/device.h>
> > +
> > +#include "rnbd-srv.h"
> > +
> > +static struct device *rnbd_dev;
> > +static struct class *rnbd_dev_class;
> > +static struct kobject *rnbd_devs_kobj;
> > +
> > +static struct kobj_type ktype = {
> > + .sysfs_ops = &kobj_sysfs_ops,
> > +};
> > +
> > +int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev,
> > + struct block_device *bdev,
> > + const char *dir_name)
> > +{
> > + struct kobject *bdev_kobj;
> > + int ret;
> > +
> > + ret = kobject_init_and_add(&dev->dev_kobj, &ktype,
> > + rnbd_devs_kobj, dir_name);
> > + if (ret)
> > + return ret;
> > +
> > + ret = kobject_init_and_add(&dev->dev_sessions_kobj,
> > + &ktype,
> > + &dev->dev_kobj, "sessions");
> > + if (ret)
> > + goto err;
> > +
> > + bdev_kobj = &disk_to_dev(bdev->bd_disk)->kobj;
> > + ret = sysfs_create_link(&dev->dev_kobj, bdev_kobj, "block_dev");
> > + if (ret)
> > + goto err2;
> > +
> > + return 0;
> > +
> > +err2:
> > + kobject_del(&dev->dev_sessions_kobj);
> > + kobject_put(&dev->dev_sessions_kobj);
> > +err:
> > + kobject_del(&dev->dev_kobj);
> > + kobject_put(&dev->dev_kobj);
>
> You are using this _del/_put pattern a lot, from what I see
> kobject_put() is the only is needed.
>
> Thanks
Yes, you're right, for these 2 cases, kobject_put is enough, although
kobject_del is harmless here, which will unregister the kobject from
sysfs, and makes the kobject "invisible" to
user.
Will remove them next round.
Thanks
next prev parent reply other threads:[~2019-12-23 8:34 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-20 15:50 [PATCH v5 00/25] RTRS (former IBTRS) rdma transport library and the corresponding RNBD (former IBNBD) rdma network block device Jack Wang
2019-12-20 15:50 ` [PATCH v5 01/25] sysfs: export sysfs_remove_file_self() Jack Wang
2019-12-20 16:26 ` Jinpu Wang
2019-12-20 15:50 ` [PATCH v5 02/25] rtrs: public interface header to establish RDMA connections Jack Wang
2019-12-21 10:15 ` Leon Romanovsky
2019-12-21 14:27 ` Danil Kipnis
2019-12-22 7:36 ` Leon Romanovsky
2019-12-23 7:38 ` Jinpu Wang
2019-12-23 8:04 ` Leon Romanovsky
2019-12-23 10:31 ` Jinpu Wang
2019-12-20 15:50 ` [PATCH v5 03/25] rtrs: private headers with rtrs protocol structs and helpers Jack Wang
2019-12-20 15:50 ` [PATCH v5 04/25] rtrs: core: lib functions shared between client and server modules Jack Wang
2019-12-20 15:50 ` [PATCH v5 05/25] rtrs: client: private header with client structs and functions Jack Wang
2019-12-20 15:50 ` [PATCH v5 06/25] rtrs: client: main functionality Jack Wang
2019-12-20 15:50 ` [PATCH v5 07/25] rtrs: client: statistics functions Jack Wang
2019-12-20 15:50 ` [PATCH v5 08/25] rtrs: client: sysfs interface functions Jack Wang
2019-12-20 15:50 ` [PATCH v5 09/25] rtrs: server: private header with server structs and functions Jack Wang
2019-12-20 15:50 ` [PATCH v5 10/25] rtrs: server: main functionality Jack Wang
2019-12-20 15:50 ` [PATCH v5 11/25] rtrs: server: statistics functions Jack Wang
2019-12-20 15:50 ` [PATCH v5 12/25] rtrs: server: sysfs interface functions Jack Wang
2019-12-20 15:50 ` [PATCH v5 13/25] rtrs: include client and server modules into kernel compilation Jack Wang
2019-12-20 15:50 ` [PATCH v5 14/25] rtrs: a bit of documentation Jack Wang
2019-12-20 15:50 ` [PATCH v5 15/25] rnbd: private headers with rnbd protocol structs and helpers Jack Wang
2019-12-20 15:51 ` [PATCH v5 16/25] rnbd: client: private header with client structs and functions Jack Wang
2019-12-20 15:51 ` [PATCH v5 17/25] rnbd: client: main functionality Jack Wang
2019-12-20 15:51 ` [PATCH v5 18/25] rnbd: client: sysfs interface functions Jack Wang
2019-12-20 15:51 ` [PATCH v5 19/25] rnbd: server: private header with server structs and functions Jack Wang
2019-12-20 15:51 ` [PATCH v5 20/25] rnbd: server: main functionality Jack Wang
2019-12-20 15:51 ` [PATCH v5 21/25] rnbd: server: functionality for IO submission to file or block dev Jack Wang
2019-12-20 15:51 ` [PATCH v5 22/25] rnbd: server: sysfs interface functions Jack Wang
2019-12-23 8:14 ` Leon Romanovsky
2019-12-23 8:33 ` Jinpu Wang [this message]
2019-12-20 15:51 ` [PATCH v5 23/25] rnbd: include client and server modules into kernel compilation Jack Wang
2019-12-20 15:51 ` [PATCH v5 24/25] rnbd: a bit of documentation Jack Wang
2019-12-20 15:51 ` [PATCH v5 25/25] MAINTAINERS: Add maintainers for RNBD/RTRS modules Jack Wang
2019-12-22 9:55 ` Gal Pressman
2019-12-23 7:20 ` Jinpu Wang
2019-12-21 10:17 ` [PATCH v5 00/25] RTRS (former IBTRS) rdma transport library and the corresponding RNBD (former IBNBD) rdma network block device Leon Romanovsky
2020-01-02 18:18 ` Jason Gunthorpe
2020-01-03 12:39 ` Jinpu Wang
2020-01-03 16:28 ` Bart Van Assche
2020-01-06 17:07 ` Jinpu Wang
2020-01-07 10:56 ` Jinpu Wang
2020-01-16 16:41 ` Bart Van Assche
2020-01-16 16:46 ` Jinpu Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMGffEnnS_HZVo_5D9O-v=6QYJXoaJ63u39cwFu+aiaNTNXTyA@mail.gmail.com' \
--to=jinpu.wang@cloud.ionos.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=danil.kipnis@cloud.ionos.com \
--cc=dledford@redhat.com \
--cc=hch@infradead.org \
--cc=jinpuwang@gmail.com \
--cc=leon@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=rpenyaev@suse.de \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).