Skip to content

Commit

Permalink
lkl: make get_virtio_blkdev a public library function
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Zimmermann <[email protected]>
  • Loading branch information
M1cha committed Oct 8, 2016
1 parent 75def1f commit f922487
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 11 additions & 0 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ int lkl_disk_add(struct lkl_disk *disk);
*/
int lkl_disk_remove(struct lkl_disk disk);

/**
* lkl_get_virtio_blkdev - get device id of a disk
*
* This function returns the device id for the given disk.
*
* @disk_id - the disk id identifying the disk
* @pdevid - pointer to memory where dev id will be returned
* @returns - 0 on success, a negative value on error
*/
int lkl_get_virtio_blkdev(int disk_id, uint32_t *pdevid);

/**
* lkl_mount_dev - mount a disk
*
Expand Down
17 changes: 12 additions & 5 deletions tools/lkl/lib/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static char *get_node_with_prefix(const char *path, const char *prefix,
return result;
}

static long get_virtio_blkdev(int disk_id)
int lkl_get_virtio_blkdev(int disk_id, uint32_t *pdevid)
{
char sysfs_path[LKL_PATH_MAX];
int sysfs_path_len = 0;
Expand All @@ -77,6 +77,7 @@ static long get_virtio_blkdev(int disk_id)
int opendir_ret;
char *virtio_name = NULL;
char *disk_name = NULL;
uint32_t device_id;

if (disk_id < 0)
return -LKL_EINVAL;
Expand Down Expand Up @@ -136,12 +137,14 @@ static long get_virtio_blkdev(int disk_id)
goto out_close;
}

ret = new_encode_dev(major, minor);
device_id = new_encode_dev(major, minor);

out_close:
lkl_sys_close(fd);

return ret;
*pdevid = device_id;

return 0;
}

long lkl_mount_dev(unsigned int disk_id, const char *fs_type, int flags,
Expand All @@ -155,7 +158,9 @@ long lkl_mount_dev(unsigned int disk_id, const char *fs_type, int flags,
if (mnt_str_len < sizeof(dev_str))
return -LKL_ENOMEM;

dev = get_virtio_blkdev(disk_id);
err = lkl_get_virtio_blkdev(disk_id, &dev);
if (err < 0)
return err;

snprintf(dev_str, sizeof(dev_str), "/dev/%08x", dev);
snprintf(mnt_str, mnt_str_len, "/mnt/%08x", dev);
Expand Down Expand Up @@ -231,7 +236,9 @@ long lkl_umount_dev(unsigned int disk_id, int flags, long timeout_ms)
unsigned int dev;
int err;

dev = get_virtio_blkdev(disk_id);
err = lkl_get_virtio_blkdev(disk_id, &dev);
if (err < 0)
return err;

snprintf(dev_str, sizeof(dev_str), "/dev/%08x", dev);
snprintf(mnt_str, sizeof(mnt_str), "/mnt/%08x", dev);
Expand Down

0 comments on commit f922487

Please sign in to comment.