diff options
author | Javier González <jg@lightnvm.io> | 2017-01-31 07:17:20 -0500 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2017-01-31 10:32:13 -0500 |
commit | 9a69b0ed6257ae5e71c99bf21ce53f98c558476a (patch) | |
tree | 8f414b478b2a105851af285af7f2861e1a77aa24 | |
parent | deccf5a52ea59843f5575cb49fe532c7cb8801e4 (diff) |
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 <javier@cnexlabs.com>
Added exit typedef and passed gendisk instead of void pointer for exit.
Signed-off-by: Matias Bjørling <matias@cnexlabs.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r-- | drivers/lightnvm/core.c | 9 | ||||
-rw-r--r-- | include/linux/lightnvm.h | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index b2cd3d6f2a31..9bfe0352d093 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c | |||
@@ -289,6 +289,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) | |||
289 | set_capacity(tdisk, tt->capacity(targetdata)); | 289 | set_capacity(tdisk, tt->capacity(targetdata)); |
290 | add_disk(tdisk); | 290 | add_disk(tdisk); |
291 | 291 | ||
292 | if (tt->sysfs_init && tt->sysfs_init(tdisk)) | ||
293 | goto err_sysfs; | ||
294 | |||
292 | t->type = tt; | 295 | t->type = tt; |
293 | t->disk = tdisk; | 296 | t->disk = tdisk; |
294 | t->dev = tgt_dev; | 297 | t->dev = tgt_dev; |
@@ -298,6 +301,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) | |||
298 | mutex_unlock(&dev->mlock); | 301 | mutex_unlock(&dev->mlock); |
299 | 302 | ||
300 | return 0; | 303 | return 0; |
304 | err_sysfs: | ||
305 | if (tt->exit) | ||
306 | tt->exit(targetdata); | ||
301 | err_init: | 307 | err_init: |
302 | put_disk(tdisk); | 308 | put_disk(tdisk); |
303 | err_queue: | 309 | err_queue: |
@@ -320,6 +326,9 @@ static void __nvm_remove_target(struct nvm_target *t) | |||
320 | del_gendisk(tdisk); | 326 | del_gendisk(tdisk); |
321 | blk_cleanup_queue(q); | 327 | blk_cleanup_queue(q); |
322 | 328 | ||
329 | if (tt->sysfs_exit) | ||
330 | tt->sysfs_exit(tdisk); | ||
331 | |||
323 | if (tt->exit) | 332 | if (tt->exit) |
324 | tt->exit(tdisk->private_data); | 333 | tt->exit(tdisk->private_data); |
325 | 334 | ||
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index bc282d26017a..ca45e4a088a9 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h | |||
@@ -440,6 +440,8 @@ typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *); | |||
440 | typedef sector_t (nvm_tgt_capacity_fn)(void *); | 440 | typedef sector_t (nvm_tgt_capacity_fn)(void *); |
441 | typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *); | 441 | typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *); |
442 | typedef void (nvm_tgt_exit_fn)(void *); | 442 | 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 *); | ||
443 | 445 | ||
444 | struct nvm_tgt_type { | 446 | struct nvm_tgt_type { |
445 | const char *name; | 447 | const char *name; |
@@ -453,6 +455,10 @@ struct nvm_tgt_type { | |||
453 | nvm_tgt_init_fn *init; | 455 | nvm_tgt_init_fn *init; |
454 | nvm_tgt_exit_fn *exit; | 456 | nvm_tgt_exit_fn *exit; |
455 | 457 | ||
458 | /* sysfs */ | ||
459 | nvm_tgt_sysfs_init_fn *sysfs_init; | ||
460 | nvm_tgt_sysfs_exit_fn *sysfs_exit; | ||
461 | |||
456 | /* For internal use */ | 462 | /* For internal use */ |
457 | struct list_head list; | 463 | struct list_head list; |
458 | }; | 464 | }; |