Skip to content

Commit 9a69b0e

Browse files
Javier Gonzálezaxboe
authored andcommitted
lightnvm: allow targets to use sysfs
In order to register through the sysfs interface, a driver needs to know its kobject. On a disk structure, this happens when the partition information is added (device_add_disk), which for lightnvm takes place after the target has been initialized. This means that on target initialization, the kboject has not been created yet. This patch adds a target function to let targets initialize their own kboject as a child of the disk kobject. Signed-off-by: Javier González <[email protected]> Added exit typedef and passed gendisk instead of void pointer for exit. Signed-off-by: Matias Bjørling <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent deccf5a commit 9a69b0e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

drivers/lightnvm/core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
289289
set_capacity(tdisk, tt->capacity(targetdata));
290290
add_disk(tdisk);
291291

292+
if (tt->sysfs_init && tt->sysfs_init(tdisk))
293+
goto err_sysfs;
294+
292295
t->type = tt;
293296
t->disk = tdisk;
294297
t->dev = tgt_dev;
@@ -298,6 +301,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
298301
mutex_unlock(&dev->mlock);
299302

300303
return 0;
304+
err_sysfs:
305+
if (tt->exit)
306+
tt->exit(targetdata);
301307
err_init:
302308
put_disk(tdisk);
303309
err_queue:
@@ -320,6 +326,9 @@ static void __nvm_remove_target(struct nvm_target *t)
320326
del_gendisk(tdisk);
321327
blk_cleanup_queue(q);
322328

329+
if (tt->sysfs_exit)
330+
tt->sysfs_exit(tdisk);
331+
323332
if (tt->exit)
324333
tt->exit(tdisk->private_data);
325334

include/linux/lightnvm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
440440
typedef sector_t (nvm_tgt_capacity_fn)(void *);
441441
typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *);
442442
typedef void (nvm_tgt_exit_fn)(void *);
443+
typedef int (nvm_tgt_sysfs_init_fn)(struct gendisk *);
444+
typedef void (nvm_tgt_sysfs_exit_fn)(struct gendisk *);
443445

444446
struct nvm_tgt_type {
445447
const char *name;
@@ -453,6 +455,10 @@ struct nvm_tgt_type {
453455
nvm_tgt_init_fn *init;
454456
nvm_tgt_exit_fn *exit;
455457

458+
/* sysfs */
459+
nvm_tgt_sysfs_init_fn *sysfs_init;
460+
nvm_tgt_sysfs_exit_fn *sysfs_exit;
461+
456462
/* For internal use */
457463
struct list_head list;
458464
};

0 commit comments

Comments
 (0)