Skip to content

Commit

Permalink
Merge pull request torvalds#303 from petrosagg/custom-blk-dev-ops
Browse files Browse the repository at this point in the history
Proposal: Add support for disks with custom block ops
  • Loading branch information
tavip authored Jan 26, 2017
2 parents 9e18f18 + bdc15ae commit 44336b1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tools/lkl/cptofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ int main(int argc, char **argv)
goto out;
}

disk.ops = NULL;

ret = lkl_disk_add(&disk);
if (ret < 0) {
fprintf(stderr, "can't add disk: %s\n", lkl_strerror(ret));
Expand Down
2 changes: 2 additions & 0 deletions tools/lkl/fs2tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ int main(int argc, char **argv)
goto out;
}

disk.ops = NULL;

ret = lkl_disk_add(&disk);
if (ret < 0) {
fprintf(stderr, "can't add disk: %s\n", lkl_strerror(ret));
Expand Down
6 changes: 6 additions & 0 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ const char *lkl_strerror(int err);
*/
void lkl_perror(char *msg, int err);

/**
* struct lkl_dev_blk_ops - block device host operations, defined in lkl_host.h.
*/
struct lkl_dev_blk_ops;

/**
* lkl_disk - host disk handle
*
Expand All @@ -97,6 +102,7 @@ struct lkl_disk {
int fd;
void *handle;
};
struct lkl_dev_blk_ops *ops;
};

/**
Expand Down
5 changes: 4 additions & 1 deletion tools/lkl/lib/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ int lkl_disk_add(struct lkl_disk *disk)
dev->dev.config_data = &dev->config;
dev->dev.config_len = sizeof(dev->config);
dev->dev.ops = &blk_ops;
dev->ops = &lkl_dev_blk_ops;
if (disk->ops)
dev->ops = disk->ops;
else
dev->ops = &lkl_dev_blk_ops;
dev->disk = *disk;

ret = dev->ops->get_capacity(*disk, &capacity);
Expand Down
2 changes: 2 additions & 0 deletions tools/lkl/tests/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ int test_disk_add(char *str, int len)
#endif
goto out_unlink;

disk.ops = NULL;

disk_id = lkl_disk_add(&disk);
if (disk_id < 0)
goto out_close;
Expand Down

0 comments on commit 44336b1

Please sign in to comment.