On Fri, Dec 20, 2019 at 04:51:06PM +0100, Jack Wang wrote: > From: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxx> > > 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@xxxxxxxxxxxxxxx> > Signed-off-by: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxx> > --- > 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@xxxxxxxxxx> > + * Jack Wang <jinpu.wang@xxxxxxxxxxxxxxxx> > + * Kleber Souza <kleber.souza@xxxxxxxxxxxxxxxx> > + * Danil Kipnis <danil.kipnis@xxxxxxxxxxxxxxxx> > + * Roman Penyaev <roman.penyaev@xxxxxxxxxxxxxxxx> > + * Milind Dumbare <Milind.dumbare@xxxxxxxxx> > + * > + * Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved. > + * Authors: Danil Kipnis <danil.kipnis@xxxxxxxxxxxxxxxx> > + * Roman Penyaev <roman.penyaev@xxxxxxxxxxxxxxxx> > + * > + * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved. > + * Authors: Roman Penyaev <roman.penyaev@xxxxxxxxxxxxxxxx> > + * Jack Wang <jinpu.wang@xxxxxxxxxxxxxxx> > + * Danil Kipnis <danil.kipnis@xxxxxxxxxxxxxxx> > + */ > + > +/* Copyright (c) 2019 1&1 IONOS SE. All rights reserved. > + * Authors: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxx> > + * Danil Kipnis <danil.kipnis@xxxxxxxxxxxxxxx> > + * Guoqing Jiang <guoqing.jiang@xxxxxxxxxxxxxxx> > + * Lutz Pogrell <lutz.pogrell@xxxxxxxxxxxxxxx> > + */ > +#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