mirror of
https://github.com/ericonr/util-linux.git
synced 2024-04-21 09:12:35 -05:00
lib/sysfs: make possible to call sysfs_blkdev_deinit_path() in loop
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
d5878cabe6
commit
866ac74f97
@ -143,7 +143,7 @@ int ul_path_set_dialect(struct path_cxt *pc, void *data, void free_data(struct p
|
|||||||
{
|
{
|
||||||
pc->dialect = data;
|
pc->dialect = data;
|
||||||
pc->free_dialect = free_data;
|
pc->free_dialect = free_data;
|
||||||
DBG(CXT, ul_debugobj(pc, "new dialect"));
|
DBG(CXT, ul_debugobj(pc, "(re)set dialect"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
lib/sysfs.c
24
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.
|
* 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)
|
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;
|
return rc;
|
||||||
|
|
||||||
/* initialize sysfs blkdev specific stuff */
|
/* initialize sysfs blkdev specific stuff */
|
||||||
blk = calloc(1, sizeof(struct sysfs_blkdev));
|
blk = ul_path_get_dialect(pc);
|
||||||
if (!blk)
|
if (!blk) {
|
||||||
return -ENOMEM;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
DBG(CXT, ul_debugobj(pc, "init sysfs stuff"));
|
||||||
|
|
||||||
blk->devno = devno;
|
blk->devno = devno;
|
||||||
ul_path_set_dialect(pc, blk, sysfs_blkdev_deinit_path);
|
|
||||||
|
|
||||||
sysfs_blkdev_set_parent(pc, parent);
|
sysfs_blkdev_set_parent(pc, parent);
|
||||||
|
|
||||||
ul_path_set_enoent_redirect(pc, sysfs_blkdev_enoent_redirect);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +122,8 @@ static void sysfs_blkdev_deinit_path(struct path_cxt *pc)
|
|||||||
|
|
||||||
ul_ref_path(blk->parent);
|
ul_ref_path(blk->parent);
|
||||||
free(blk);
|
free(blk);
|
||||||
|
|
||||||
|
ul_path_set_dialect(pc, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sysfs_blkdev_set_parent(struct path_cxt *pc, struct path_cxt *parent)
|
int sysfs_blkdev_set_parent(struct path_cxt *pc, struct path_cxt *parent)
|
||||||
|
Loading…
Reference in New Issue
Block a user