diff options
author | Karel Zak | 2018-05-16 12:52:47 +0200 |
---|---|---|
committer | Karel Zak | 2018-06-21 13:07:46 +0200 |
commit | 866ac74f972063474dc26dfd1c58a145d7ac61a9 (patch) | |
tree | 71e7544bad6211e7e46d6b51781320b9113b77dc /lib | |
parent | lib/path: fix read string to be backwardly compatible (diff) | |
download | kernel-qcow2-util-linux-866ac74f972063474dc26dfd1c58a145d7ac61a9.tar.gz kernel-qcow2-util-linux-866ac74f972063474dc26dfd1c58a145d7ac61a9.tar.xz kernel-qcow2-util-linux-866ac74f972063474dc26dfd1c58a145d7ac61a9.zip |
lib/sysfs: make possible to call sysfs_blkdev_deinit_path() in loop
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/path.c | 2 | ||||
-rw-r--r-- | lib/sysfs.c | 24 |
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/path.c b/lib/path.c index c665196a9..983524ef4 100644 --- a/lib/path.c +++ b/lib/path.c @@ -143,7 +143,7 @@ int ul_path_set_dialect(struct path_cxt *pc, void *data, void free_data(struct p { pc->dialect = data; pc->free_dialect = free_data; - DBG(CXT, ul_debugobj(pc, "new dialect")); + DBG(CXT, ul_debugobj(pc, "(re)set dialect")); return 0; } diff --git a/lib/sysfs.c b/lib/sysfs.c index 3fe771449..5b4031e00 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -64,6 +64,9 @@ struct path_cxt *ul_new_sysfs_path(dev_t devno, struct path_cxt *parent, const c /* * sysfs_blkdev_* is sysfs extension to ul_path_* API for block devices. * + * The function is possible to call in loop and without sysfs_blkdev_deinit_path(). + * The sysfs_blkdev_deinit_path() is automatically called by ul_unref_path(). + * */ int sysfs_blkdev_init_path(struct path_cxt *pc, dev_t devno, struct path_cxt *parent) { @@ -85,19 +88,22 @@ int sysfs_blkdev_init_path(struct path_cxt *pc, dev_t devno, struct path_cxt *pa return rc; /* initialize sysfs blkdev specific stuff */ - blk = calloc(1, sizeof(struct sysfs_blkdev)); - if (!blk) - return -ENOMEM; + blk = ul_path_get_dialect(pc); + if (!blk) { + DBG(CXT, ul_debugobj(pc, "alloc new sysfs handler")); + blk = calloc(1, sizeof(struct sysfs_blkdev)); + if (!blk) + return -ENOMEM; - DBG(CXT, ul_debugobj(pc, "init for sysfs")); + ul_path_set_dialect(pc, blk, sysfs_blkdev_deinit_path); + ul_path_set_enoent_redirect(pc, sysfs_blkdev_enoent_redirect); + } - blk->devno = devno; - ul_path_set_dialect(pc, blk, sysfs_blkdev_deinit_path); + DBG(CXT, ul_debugobj(pc, "init sysfs stuff")); + blk->devno = devno; sysfs_blkdev_set_parent(pc, parent); - ul_path_set_enoent_redirect(pc, sysfs_blkdev_enoent_redirect); - return 0; } @@ -116,6 +122,8 @@ static void sysfs_blkdev_deinit_path(struct path_cxt *pc) ul_ref_path(blk->parent); free(blk); + + ul_path_set_dialect(pc, NULL, NULL); } int sysfs_blkdev_set_parent(struct path_cxt *pc, struct path_cxt *parent) |